Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
Emil Velikov | 83548e1 | 2016-11-24 20:30:39 +0000 | [diff] [blame] | 24 | #include <dlfcn.h> |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 25 | #include <assert.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <string.h> |
Jason Ekstrand | 920f34a | 2016-11-07 17:24:24 -0800 | [diff] [blame] | 28 | #include <sys/mman.h> |
Emil Velikov | 83548e1 | 2016-11-24 20:30:39 +0000 | [diff] [blame] | 29 | #include <sys/stat.h> |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 30 | #include <unistd.h> |
| 31 | #include <fcntl.h> |
| 32 | |
Chad Versace | 2c2233e | 2015-07-17 15:04:27 -0700 | [diff] [blame] | 33 | #include "anv_private.h" |
Jason Ekstrand | 6a7ca4e | 2015-08-14 17:25:04 -0700 | [diff] [blame] | 34 | #include "util/strtod.h" |
Jason Ekstrand | e45748b | 2016-01-20 11:16:44 -0800 | [diff] [blame] | 35 | #include "util/debug.h" |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 36 | |
Jason Ekstrand | f6d9587 | 2016-02-18 10:19:02 -0800 | [diff] [blame] | 37 | #include "genxml/gen7_pack.h" |
Jason Ekstrand | de54b4b | 2015-11-16 12:29:07 -0800 | [diff] [blame] | 38 | |
Jason Ekstrand | a95f51c | 2015-09-24 14:20:35 -0700 | [diff] [blame] | 39 | struct anv_dispatch_table dtable; |
| 40 | |
Jason Ekstrand | a71e614 | 2015-10-19 22:06:59 -0700 | [diff] [blame] | 41 | static void |
| 42 | compiler_debug_log(void *data, const char *fmt, ...) |
| 43 | { } |
| 44 | |
| 45 | static void |
| 46 | compiler_perf_log(void *data, const char *fmt, ...) |
| 47 | { |
| 48 | va_list args; |
| 49 | va_start(args, fmt); |
| 50 | |
| 51 | if (unlikely(INTEL_DEBUG & DEBUG_PERF)) |
| 52 | vfprintf(stderr, fmt, args); |
| 53 | |
| 54 | va_end(args); |
| 55 | } |
| 56 | |
Emil Velikov | 83548e1 | 2016-11-24 20:30:39 +0000 | [diff] [blame] | 57 | static bool |
| 58 | anv_get_function_timestamp(void *ptr, uint32_t* timestamp) |
| 59 | { |
| 60 | Dl_info info; |
| 61 | struct stat st; |
| 62 | if (!dladdr(ptr, &info) || !info.dli_fname) |
| 63 | return false; |
| 64 | |
| 65 | if (stat(info.dli_fname, &st)) |
| 66 | return false; |
| 67 | |
| 68 | *timestamp = st.st_mtim.tv_sec; |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | static bool |
Emil Velikov | de138e9 | 2016-11-24 20:30:38 +0000 | [diff] [blame] | 73 | anv_device_get_cache_uuid(void *uuid) |
| 74 | { |
Emil Velikov | 83548e1 | 2016-11-24 20:30:39 +0000 | [diff] [blame] | 75 | uint32_t timestamp; |
| 76 | |
Emil Velikov | de138e9 | 2016-11-24 20:30:38 +0000 | [diff] [blame] | 77 | memset(uuid, 0, VK_UUID_SIZE); |
Kenneth Graunke | 15d3fc1 | 2016-11-28 13:37:44 -0800 | [diff] [blame] | 78 | if (!anv_get_function_timestamp(anv_device_get_cache_uuid, ×tamp)) |
| 79 | return false; |
Emil Velikov | 83548e1 | 2016-11-24 20:30:39 +0000 | [diff] [blame] | 80 | |
| 81 | snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp); |
| 82 | return true; |
Emil Velikov | de138e9 | 2016-11-24 20:30:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 85 | static VkResult |
Chad Versace | 4422bd4 | 2015-07-09 16:22:18 -0700 | [diff] [blame] | 86 | anv_physical_device_init(struct anv_physical_device *device, |
| 87 | struct anv_instance *instance, |
| 88 | const char *path) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 89 | { |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 90 | VkResult result; |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 91 | int fd; |
| 92 | |
| 93 | fd = open(path, O_RDWR | O_CLOEXEC); |
| 94 | if (fd < 0) |
Jason Ekstrand | 34ff4fb | 2016-08-22 18:10:14 -0700 | [diff] [blame] | 95 | return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 96 | |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 97 | device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 98 | device->instance = instance; |
Jason Ekstrand | e023c10 | 2016-05-24 11:02:18 -0700 | [diff] [blame] | 99 | |
| 100 | assert(strlen(path) < ARRAY_SIZE(device->path)); |
| 101 | strncpy(device->path, path, ARRAY_SIZE(device->path)); |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 102 | |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 103 | device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID); |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 104 | if (!device->chipset_id) { |
Jason Ekstrand | 34ff4fb | 2016-08-22 18:10:14 -0700 | [diff] [blame] | 105 | result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 106 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 107 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 108 | |
Jason Ekstrand | 979d0ac | 2016-08-25 16:22:58 -0700 | [diff] [blame] | 109 | device->name = gen_get_device_name(device->chipset_id); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 110 | if (!gen_get_device_info(device->chipset_id, &device->info)) { |
Jason Ekstrand | 34ff4fb | 2016-08-22 18:10:14 -0700 | [diff] [blame] | 111 | result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 112 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 113 | } |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 114 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 115 | if (device->info.is_haswell) { |
Jason Ekstrand | f0390bc | 2015-11-17 07:07:02 -0800 | [diff] [blame] | 116 | fprintf(stderr, "WARNING: Haswell Vulkan support is incomplete\n"); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 117 | } else if (device->info.gen == 7 && !device->info.is_baytrail) { |
Jason Ekstrand | 862da6a | 2015-11-09 12:18:12 -0800 | [diff] [blame] | 118 | fprintf(stderr, "WARNING: Ivy Bridge Vulkan support is incomplete\n"); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 119 | } else if (device->info.gen == 7 && device->info.is_baytrail) { |
Kristian Høgsberg | dac5775 | 2015-12-01 15:39:30 -0800 | [diff] [blame] | 120 | fprintf(stderr, "WARNING: Bay Trail Vulkan support is incomplete\n"); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 121 | } else if (device->info.gen >= 8) { |
Kristian Høgsberg Kristensen | 7c5e1fd | 2016-01-08 22:24:58 -0800 | [diff] [blame] | 122 | /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully |
| 123 | * supported as anything */ |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 124 | } else { |
Jason Ekstrand | fed3586 | 2015-12-02 16:14:58 -0800 | [diff] [blame] | 125 | result = vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER, |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 126 | "Vulkan not yet supported on %s", device->name); |
| 127 | goto fail; |
| 128 | } |
| 129 | |
Jordan Justen | 1a3adae | 2016-03-28 14:45:24 -0700 | [diff] [blame] | 130 | device->cmd_parser_version = -1; |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 131 | if (device->info.gen == 7) { |
Jordan Justen | 1a3adae | 2016-03-28 14:45:24 -0700 | [diff] [blame] | 132 | device->cmd_parser_version = |
| 133 | anv_gem_get_param(fd, I915_PARAM_CMD_PARSER_VERSION); |
| 134 | if (device->cmd_parser_version == -1) { |
| 135 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 136 | "failed to get command parser version"); |
| 137 | goto fail; |
| 138 | } |
| 139 | } |
| 140 | |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 141 | if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 142 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 143 | "failed to get aperture size: %m"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 144 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 145 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 146 | |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 147 | if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 148 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 149 | "kernel missing gem wait"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 150 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 151 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 152 | |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 153 | if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 154 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 155 | "kernel missing execbuf2"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 156 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 157 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 158 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 159 | if (!device->info.has_llc && |
Kristian Høgsberg Kristensen | 220ac93 | 2015-12-19 22:25:57 -0800 | [diff] [blame] | 160 | anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) { |
Kristian Høgsberg Kristensen | bbb6875 | 2015-12-03 23:58:05 -0800 | [diff] [blame] | 161 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 162 | "kernel missing wc mmap"); |
| 163 | goto fail; |
| 164 | } |
| 165 | |
Emil Velikov | 83548e1 | 2016-11-24 20:30:39 +0000 | [diff] [blame] | 166 | if (!anv_device_get_cache_uuid(device->uuid)) { |
| 167 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 168 | "cannot generate UUID"); |
| 169 | goto fail; |
| 170 | } |
Jason Ekstrand | 580b2e8 | 2016-01-05 13:53:05 -0800 | [diff] [blame] | 171 | bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X); |
| 172 | |
Lionel Landwerlin | 09394ee | 2016-09-07 17:19:35 +0100 | [diff] [blame] | 173 | /* GENs prior to 8 do not support EU/Subslice info */ |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 174 | if (device->info.gen >= 8) { |
Lionel Landwerlin | 09394ee | 2016-09-07 17:19:35 +0100 | [diff] [blame] | 175 | device->subslice_total = anv_gem_get_param(fd, I915_PARAM_SUBSLICE_TOTAL); |
| 176 | device->eu_total = anv_gem_get_param(fd, I915_PARAM_EU_TOTAL); |
| 177 | |
| 178 | /* Without this information, we cannot get the right Braswell |
| 179 | * brandstrings, and we have to use conservative numbers for GPGPU on |
| 180 | * many platforms, but otherwise, things will just work. |
| 181 | */ |
| 182 | if (device->subslice_total < 1 || device->eu_total < 1) { |
| 183 | fprintf(stderr, "WARNING: Kernel 4.1 required to properly" |
| 184 | " query GPU properties.\n"); |
| 185 | } |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 186 | } else if (device->info.gen == 7) { |
| 187 | device->subslice_total = 1 << (device->info.gt - 1); |
Lionel Landwerlin | 09394ee | 2016-09-07 17:19:35 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 190 | if (device->info.is_cherryview && |
Lionel Landwerlin | 09394ee | 2016-09-07 17:19:35 +0100 | [diff] [blame] | 191 | device->subslice_total > 0 && device->eu_total > 0) { |
| 192 | /* Logical CS threads = EUs per subslice * 7 threads per EU */ |
Lionel Landwerlin | 6b21728 | 2016-09-23 01:04:25 +0300 | [diff] [blame] | 193 | uint32_t max_cs_threads = device->eu_total / device->subslice_total * 7; |
Lionel Landwerlin | 09394ee | 2016-09-07 17:19:35 +0100 | [diff] [blame] | 194 | |
| 195 | /* Fuse configurations may give more threads than expected, never less. */ |
Lionel Landwerlin | 6b21728 | 2016-09-23 01:04:25 +0300 | [diff] [blame] | 196 | if (max_cs_threads > device->info.max_cs_threads) |
| 197 | device->info.max_cs_threads = max_cs_threads; |
Lionel Landwerlin | 09394ee | 2016-09-07 17:19:35 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Jason Ekstrand | a71e614 | 2015-10-19 22:06:59 -0700 | [diff] [blame] | 200 | brw_process_intel_debug_variable(); |
| 201 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 202 | device->compiler = brw_compiler_create(NULL, &device->info); |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 203 | if (device->compiler == NULL) { |
| 204 | result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 205 | goto fail; |
| 206 | } |
Jason Ekstrand | a71e614 | 2015-10-19 22:06:59 -0700 | [diff] [blame] | 207 | device->compiler->shader_debug_log = compiler_debug_log; |
| 208 | device->compiler->shader_perf_log = compiler_perf_log; |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 209 | |
Emil Velikov | ace5403 | 2016-05-28 20:03:34 +0100 | [diff] [blame] | 210 | result = anv_init_wsi(device); |
Emil Velikov | a1cf494 | 2016-11-24 20:30:43 +0000 | [diff] [blame] | 211 | if (result != VK_SUCCESS) { |
| 212 | ralloc_free(device->compiler); |
| 213 | goto fail; |
| 214 | } |
Jason Ekstrand | eb6baa3 | 2016-05-15 22:21:24 -0700 | [diff] [blame] | 215 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 216 | isl_device_init(&device->isl_dev, &device->info, swizzled); |
Chad Versace | af39291 | 2015-11-13 10:12:51 -0800 | [diff] [blame] | 217 | |
Emil Velikov | 3af8171 | 2016-11-24 20:30:42 +0000 | [diff] [blame] | 218 | close(fd); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 219 | return VK_SUCCESS; |
Chad Versace | 477383e | 2015-11-13 10:12:18 -0800 | [diff] [blame] | 220 | |
Chad Versace | 8cda3e9 | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 221 | fail: |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 222 | close(fd); |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 223 | return result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 226 | static void |
| 227 | anv_physical_device_finish(struct anv_physical_device *device) |
| 228 | { |
Jason Ekstrand | eb6baa3 | 2016-05-15 22:21:24 -0700 | [diff] [blame] | 229 | anv_finish_wsi(device); |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 230 | ralloc_free(device->compiler); |
| 231 | } |
| 232 | |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 233 | static const VkExtensionProperties global_extensions[] = { |
| 234 | { |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 235 | .extensionName = VK_KHR_SURFACE_EXTENSION_NAME, |
Jason Ekstrand | c688e4d | 2016-01-28 15:34:22 -0800 | [diff] [blame] | 236 | .specVersion = 25, |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 237 | }, |
Emil Velikov | 6dc169e | 2016-04-20 19:15:18 +0100 | [diff] [blame] | 238 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 239 | { |
| 240 | .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME, |
Emil Velikov | f373a91 | 2016-11-09 18:10:46 +0000 | [diff] [blame] | 241 | .specVersion = 6, |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 242 | }, |
Emil Velikov | 6dc169e | 2016-04-20 19:15:18 +0100 | [diff] [blame] | 243 | #endif |
Kevin Strasser | 71258e9 | 2016-08-12 14:17:20 -0700 | [diff] [blame] | 244 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 245 | { |
| 246 | .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_NAME, |
Emil Velikov | f373a91 | 2016-11-09 18:10:46 +0000 | [diff] [blame] | 247 | .specVersion = 6, |
Kevin Strasser | 71258e9 | 2016-08-12 14:17:20 -0700 | [diff] [blame] | 248 | }, |
| 249 | #endif |
Emil Velikov | cbc4837 | 2016-04-20 19:01:00 +0100 | [diff] [blame] | 250 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 251 | { |
| 252 | .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, |
Emil Velikov | f373a91 | 2016-11-09 18:10:46 +0000 | [diff] [blame] | 253 | .specVersion = 5, |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 254 | }, |
| 255 | #endif |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | static const VkExtensionProperties device_extensions[] = { |
| 259 | { |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 260 | .extensionName = VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
Emil Velikov | f373a91 | 2016-11-09 18:10:46 +0000 | [diff] [blame] | 261 | .specVersion = 68, |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 262 | }, |
| 263 | }; |
| 264 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 265 | static void * |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 266 | default_alloc_func(void *pUserData, size_t size, size_t align, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 267 | VkSystemAllocationScope allocationScope) |
| 268 | { |
| 269 | return malloc(size); |
| 270 | } |
| 271 | |
| 272 | static void * |
| 273 | default_realloc_func(void *pUserData, void *pOriginal, size_t size, |
| 274 | size_t align, VkSystemAllocationScope allocationScope) |
| 275 | { |
| 276 | return realloc(pOriginal, size); |
| 277 | } |
| 278 | |
| 279 | static void |
| 280 | default_free_func(void *pUserData, void *pMemory) |
| 281 | { |
| 282 | free(pMemory); |
| 283 | } |
| 284 | |
| 285 | static const VkAllocationCallbacks default_alloc = { |
| 286 | .pUserData = NULL, |
| 287 | .pfnAllocation = default_alloc_func, |
| 288 | .pfnReallocation = default_realloc_func, |
| 289 | .pfnFree = default_free_func, |
| 290 | }; |
| 291 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 292 | VkResult anv_CreateInstance( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 293 | const VkInstanceCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 294 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 295 | VkInstance* pInstance) |
| 296 | { |
| 297 | struct anv_instance *instance; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 298 | |
| 299 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); |
| 300 | |
Jason Ekstrand | c32273d | 2016-02-25 08:52:35 -0800 | [diff] [blame] | 301 | uint32_t client_version; |
| 302 | if (pCreateInfo->pApplicationInfo && |
| 303 | pCreateInfo->pApplicationInfo->apiVersion != 0) { |
| 304 | client_version = pCreateInfo->pApplicationInfo->apiVersion; |
| 305 | } else { |
| 306 | client_version = VK_MAKE_VERSION(1, 0, 0); |
| 307 | } |
| 308 | |
Jason Ekstrand | a19ceee | 2016-01-28 15:43:44 -0800 | [diff] [blame] | 309 | if (VK_MAKE_VERSION(1, 0, 0) > client_version || |
Jason Ekstrand | 204d937 | 2016-03-22 16:17:09 -0700 | [diff] [blame] | 310 | client_version > VK_MAKE_VERSION(1, 0, 0xfff)) { |
Jason Ekstrand | fd99f3d | 2016-02-02 13:15:18 -0800 | [diff] [blame] | 311 | return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER, |
| 312 | "Client requested version %d.%d.%d", |
| 313 | VK_VERSION_MAJOR(client_version), |
| 314 | VK_VERSION_MINOR(client_version), |
| 315 | VK_VERSION_PATCH(client_version)); |
Jason Ekstrand | 608b411 | 2016-01-28 08:18:50 -0800 | [diff] [blame] | 316 | } |
Jason Ekstrand | e21ecb8 | 2015-10-12 18:25:19 -0700 | [diff] [blame] | 317 | |
Jason Ekstrand | aab9517 | 2016-01-14 07:41:45 -0800 | [diff] [blame] | 318 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 319 | bool found = false; |
| 320 | for (uint32_t j = 0; j < ARRAY_SIZE(global_extensions); j++) { |
| 321 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 322 | global_extensions[j].extensionName) == 0) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 323 | found = true; |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | if (!found) |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 328 | return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 331 | instance = vk_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8, |
Jason Ekstrand | 45d17fc | 2016-01-18 14:04:13 -0800 | [diff] [blame] | 332 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 333 | if (!instance) |
| 334 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 335 | |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 336 | instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 337 | |
| 338 | if (pAllocator) |
| 339 | instance->alloc = *pAllocator; |
| 340 | else |
| 341 | instance->alloc = default_alloc; |
| 342 | |
Philipp Zabel | ecd1d94 | 2016-02-16 22:55:33 +0100 | [diff] [blame] | 343 | instance->apiVersion = client_version; |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 344 | instance->physicalDeviceCount = -1; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 345 | |
Jason Ekstrand | 6a7ca4e | 2015-08-14 17:25:04 -0700 | [diff] [blame] | 346 | _mesa_locale_init(); |
| 347 | |
Jason Ekstrand | 930598a | 2015-07-31 10:18:00 -0700 | [diff] [blame] | 348 | VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); |
| 349 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 350 | *pInstance = anv_instance_to_handle(instance); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 351 | |
| 352 | return VK_SUCCESS; |
| 353 | } |
| 354 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 355 | void anv_DestroyInstance( |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 356 | VkInstance _instance, |
| 357 | const VkAllocationCallbacks* pAllocator) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 358 | { |
Jason Ekstrand | 73f9187 | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 359 | ANV_FROM_HANDLE(anv_instance, instance, _instance); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 360 | |
Chad Versace | 0ab926d | 2015-10-21 11:36:39 -0700 | [diff] [blame] | 361 | if (instance->physicalDeviceCount > 0) { |
| 362 | /* We support at most one physical device. */ |
| 363 | assert(instance->physicalDeviceCount == 1); |
| 364 | anv_physical_device_finish(&instance->physicalDevice); |
| 365 | } |
| 366 | |
Jason Ekstrand | 930598a | 2015-07-31 10:18:00 -0700 | [diff] [blame] | 367 | VG(VALGRIND_DESTROY_MEMPOOL(instance)); |
| 368 | |
Jason Ekstrand | 6a7ca4e | 2015-08-14 17:25:04 -0700 | [diff] [blame] | 369 | _mesa_locale_fini(); |
| 370 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 371 | vk_free(&instance->alloc, instance); |
Jason Ekstrand | e40bdce | 2015-07-31 10:13:24 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 374 | VkResult anv_EnumeratePhysicalDevices( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 375 | VkInstance _instance, |
| 376 | uint32_t* pPhysicalDeviceCount, |
| 377 | VkPhysicalDevice* pPhysicalDevices) |
| 378 | { |
Jason Ekstrand | 73f9187 | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 379 | ANV_FROM_HANDLE(anv_instance, instance, _instance); |
Chad Versace | fa915b6 | 2015-07-09 15:38:58 -0700 | [diff] [blame] | 380 | VkResult result; |
| 381 | |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 382 | if (instance->physicalDeviceCount < 0) { |
Jason Ekstrand | b93b593 | 2016-05-24 12:06:35 -0700 | [diff] [blame] | 383 | char path[20]; |
| 384 | for (unsigned i = 0; i < 8; i++) { |
| 385 | snprintf(path, sizeof(path), "/dev/dri/renderD%d", 128 + i); |
| 386 | result = anv_physical_device_init(&instance->physicalDevice, |
| 387 | instance, path); |
Jason Ekstrand | a5f8ff6 | 2016-11-01 17:51:56 -0700 | [diff] [blame] | 388 | if (result != VK_ERROR_INCOMPATIBLE_DRIVER) |
Jason Ekstrand | b93b593 | 2016-05-24 12:06:35 -0700 | [diff] [blame] | 389 | break; |
| 390 | } |
| 391 | |
Jason Ekstrand | fed3586 | 2015-12-02 16:14:58 -0800 | [diff] [blame] | 392 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 393 | instance->physicalDeviceCount = 0; |
| 394 | } else if (result == VK_SUCCESS) { |
| 395 | instance->physicalDeviceCount = 1; |
| 396 | } else { |
Chad Versace | fa915b6 | 2015-07-09 15:38:58 -0700 | [diff] [blame] | 397 | return result; |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 398 | } |
Chad Versace | fa915b6 | 2015-07-09 15:38:58 -0700 | [diff] [blame] | 399 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 400 | |
Chad Versace | 5b75dff | 2015-07-09 15:51:06 -0700 | [diff] [blame] | 401 | /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL; |
| 402 | * otherwise it's an inout parameter. |
| 403 | * |
| 404 | * The Vulkan spec (git aaed022) says: |
| 405 | * |
| 406 | * pPhysicalDeviceCount is a pointer to an unsigned integer variable |
| 407 | * that is initialized with the number of devices the application is |
| 408 | * prepared to receive handles to. pname:pPhysicalDevices is pointer to |
| 409 | * an array of at least this many VkPhysicalDevice handles [...]. |
| 410 | * |
| 411 | * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices |
| 412 | * overwrites the contents of the variable pointed to by |
| 413 | * pPhysicalDeviceCount with the number of physical devices in in the |
| 414 | * instance; otherwise, vkEnumeratePhysicalDevices overwrites |
| 415 | * pPhysicalDeviceCount with the number of physical handles written to |
| 416 | * pPhysicalDevices. |
| 417 | */ |
| 418 | if (!pPhysicalDevices) { |
| 419 | *pPhysicalDeviceCount = instance->physicalDeviceCount; |
| 420 | } else if (*pPhysicalDeviceCount >= 1) { |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 421 | pPhysicalDevices[0] = anv_physical_device_to_handle(&instance->physicalDevice); |
Chad Versace | 5b75dff | 2015-07-09 15:51:06 -0700 | [diff] [blame] | 422 | *pPhysicalDeviceCount = 1; |
Nicolas Koch | fd27d5f | 2016-10-06 21:21:32 +0200 | [diff] [blame] | 423 | } else if (*pPhysicalDeviceCount < instance->physicalDeviceCount) { |
| 424 | return VK_INCOMPLETE; |
Chad Versace | 5b75dff | 2015-07-09 15:51:06 -0700 | [diff] [blame] | 425 | } else { |
| 426 | *pPhysicalDeviceCount = 0; |
| 427 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 428 | |
| 429 | return VK_SUCCESS; |
| 430 | } |
| 431 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 432 | void anv_GetPhysicalDeviceFeatures( |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 433 | VkPhysicalDevice physicalDevice, |
| 434 | VkPhysicalDeviceFeatures* pFeatures) |
| 435 | { |
Kristian Høgsberg Kristensen | 4a2d17f | 2016-02-15 21:24:40 -0800 | [diff] [blame] | 436 | ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 437 | |
| 438 | *pFeatures = (VkPhysicalDeviceFeatures) { |
Kristian Høgsberg Kristensen | dc5fdcd | 2016-02-01 11:54:40 -0800 | [diff] [blame] | 439 | .robustBufferAccess = true, |
Kristian Høgsberg Kristensen | 4a2d17f | 2016-02-15 21:24:40 -0800 | [diff] [blame] | 440 | .fullDrawIndexUint32 = true, |
Ilia Mirkin | a34f89c | 2016-11-27 14:41:42 -0500 | [diff] [blame] | 441 | .imageCubeArray = true, |
Jason Ekstrand | f124f4a | 2016-07-14 18:01:29 -0700 | [diff] [blame] | 442 | .independentBlend = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 443 | .geometryShader = true, |
| 444 | .tessellationShader = false, |
Anuj Phogat | c4cd0e8 | 2016-08-08 16:10:00 -0700 | [diff] [blame] | 445 | .sampleRateShading = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 446 | .dualSrcBlend = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 447 | .logicOp = true, |
Jason Ekstrand | 802f002 | 2016-01-14 06:58:11 -0800 | [diff] [blame] | 448 | .multiDrawIndirect = false, |
| 449 | .drawIndirectFirstInstance = false, |
Jason Ekstrand | eb6764c | 2016-06-14 08:40:49 -0700 | [diff] [blame] | 450 | .depthClamp = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 451 | .depthBiasClamp = false, |
| 452 | .fillModeNonSolid = true, |
| 453 | .depthBounds = false, |
| 454 | .wideLines = true, |
| 455 | .largePoints = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 456 | .alphaToOne = true, |
| 457 | .multiViewport = true, |
Lionel Landwerlin | 014bd4a | 2016-10-07 13:53:04 +0100 | [diff] [blame] | 458 | .samplerAnisotropy = true, |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 459 | .textureCompressionETC2 = pdevice->info.gen >= 8 || |
| 460 | pdevice->info.is_baytrail, |
| 461 | .textureCompressionASTC_LDR = pdevice->info.gen >= 9, /* FINISHME CHV */ |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 462 | .textureCompressionBC = true, |
Kristian Høgsberg Kristensen | 4a2d17f | 2016-02-15 21:24:40 -0800 | [diff] [blame] | 463 | .occlusionQueryPrecise = true, |
Kristian Høgsberg Kristensen | 9d8bae6 | 2016-02-29 10:55:39 -0800 | [diff] [blame] | 464 | .pipelineStatisticsQuery = false, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 465 | .fragmentStoresAndAtomics = true, |
| 466 | .shaderTessellationAndGeometryPointSize = true, |
Jason Ekstrand | 5186545 | 2016-05-12 10:56:58 -0700 | [diff] [blame] | 467 | .shaderImageGatherExtended = false, |
Ilia Mirkin | 76b97d5 | 2016-11-27 16:37:17 -0500 | [diff] [blame^] | 468 | .shaderStorageImageExtendedFormats = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 469 | .shaderStorageImageMultisample = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 470 | .shaderUniformBufferArrayDynamicIndexing = true, |
Kristian Høgsberg Kristensen | 4a2d17f | 2016-02-15 21:24:40 -0800 | [diff] [blame] | 471 | .shaderSampledImageArrayDynamicIndexing = true, |
| 472 | .shaderStorageBufferArrayDynamicIndexing = true, |
| 473 | .shaderStorageImageArrayDynamicIndexing = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 474 | .shaderStorageImageReadWithoutFormat = false, |
| 475 | .shaderStorageImageWriteWithoutFormat = true, |
Kenneth Graunke | a4d7a5b | 2016-10-03 20:44:38 -0700 | [diff] [blame] | 476 | .shaderClipDistance = true, |
| 477 | .shaderCullDistance = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 478 | .shaderFloat64 = false, |
| 479 | .shaderInt64 = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 480 | .shaderInt16 = false, |
Chad Versace | 545f5cc | 2015-10-07 10:05:02 -0700 | [diff] [blame] | 481 | .alphaToOne = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 482 | .variableMultisampleRate = false, |
Jason Ekstrand | 802f002 | 2016-01-14 06:58:11 -0800 | [diff] [blame] | 483 | .inheritedQueries = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 484 | }; |
Jason Ekstrand | 5ec4ecc | 2016-04-15 14:53:16 -0700 | [diff] [blame] | 485 | |
| 486 | /* We can't do image stores in vec4 shaders */ |
| 487 | pFeatures->vertexPipelineStoresAndAtomics = |
Jason Ekstrand | 93db828 | 2016-04-15 16:39:17 -0700 | [diff] [blame] | 488 | pdevice->compiler->scalar_stage[MESA_SHADER_VERTEX] && |
| 489 | pdevice->compiler->scalar_stage[MESA_SHADER_GEOMETRY]; |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 492 | void anv_GetPhysicalDeviceProperties( |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 493 | VkPhysicalDevice physicalDevice, |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 494 | VkPhysicalDeviceProperties* pProperties) |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 495 | { |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 496 | ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 497 | const struct gen_device_info *devinfo = &pdevice->info; |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 498 | |
Kristian Høgsberg Kristensen | dae800d | 2016-01-09 00:50:04 -0800 | [diff] [blame] | 499 | const float time_stamp_base = devinfo->gen >= 9 ? 83.333 : 80.0; |
| 500 | |
Nanley Chery | a5748cb | 2016-07-06 11:13:48 -0700 | [diff] [blame] | 501 | /* See assertions made when programming the buffer surface state. */ |
| 502 | const uint32_t max_raw_buffer_sz = devinfo->gen >= 7 ? |
| 503 | (1ul << 30) : (1ul << 27); |
| 504 | |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 505 | VkSampleCountFlags sample_counts = |
Chad Versace | 1c5d7b3 | 2016-01-20 16:04:28 -0800 | [diff] [blame] | 506 | isl_device_get_sample_counts(&pdevice->isl_dev); |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 507 | |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 508 | VkPhysicalDeviceLimits limits = { |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 509 | .maxImageDimension1D = (1 << 14), |
| 510 | .maxImageDimension2D = (1 << 14), |
Nanley Chery | 181b142 | 2016-03-05 15:17:00 -0800 | [diff] [blame] | 511 | .maxImageDimension3D = (1 << 11), |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 512 | .maxImageDimensionCube = (1 << 14), |
Nanley Chery | 181b142 | 2016-03-05 15:17:00 -0800 | [diff] [blame] | 513 | .maxImageArrayLayers = (1 << 11), |
Kenneth Graunke | 38a3a53 | 2016-01-26 23:09:45 -0800 | [diff] [blame] | 514 | .maxTexelBufferElements = 128 * 1024 * 1024, |
Nanley Chery | a5748cb | 2016-07-06 11:13:48 -0700 | [diff] [blame] | 515 | .maxUniformBufferRange = (1ul << 27), |
| 516 | .maxStorageBufferRange = max_raw_buffer_sz, |
Jason Ekstrand | 5446bf3 | 2015-08-26 15:01:38 -0700 | [diff] [blame] | 517 | .maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 518 | .maxMemoryAllocationCount = UINT32_MAX, |
Kristian Høgsberg Kristensen | 7b7a7c2 | 2016-01-20 14:36:52 -0800 | [diff] [blame] | 519 | .maxSamplerAllocationCount = 64 * 1024, |
Jason Ekstrand | e5db209 | 2015-07-14 17:10:37 -0700 | [diff] [blame] | 520 | .bufferImageGranularity = 64, /* A cache line */ |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 521 | .sparseAddressSpaceSize = 0, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 522 | .maxBoundDescriptorSets = MAX_SETS, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 523 | .maxPerStageDescriptorSamplers = 64, |
| 524 | .maxPerStageDescriptorUniformBuffers = 64, |
| 525 | .maxPerStageDescriptorStorageBuffers = 64, |
| 526 | .maxPerStageDescriptorSampledImages = 64, |
| 527 | .maxPerStageDescriptorStorageImages = 64, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 528 | .maxPerStageDescriptorInputAttachments = 64, |
| 529 | .maxPerStageResources = 128, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 530 | .maxDescriptorSetSamplers = 256, |
| 531 | .maxDescriptorSetUniformBuffers = 256, |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 532 | .maxDescriptorSetUniformBuffersDynamic = 256, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 533 | .maxDescriptorSetStorageBuffers = 256, |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 534 | .maxDescriptorSetStorageBuffersDynamic = 256, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 535 | .maxDescriptorSetSampledImages = 256, |
| 536 | .maxDescriptorSetStorageImages = 256, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 537 | .maxDescriptorSetInputAttachments = 256, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 538 | .maxVertexInputAttributes = 32, |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 539 | .maxVertexInputBindings = 32, |
Kenneth Graunke | 38a3a53 | 2016-01-26 23:09:45 -0800 | [diff] [blame] | 540 | .maxVertexInputAttributeOffset = 2047, |
| 541 | .maxVertexInputBindingStride = 2048, |
| 542 | .maxVertexOutputComponents = 128, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 543 | .maxTessellationGenerationLevel = 0, |
| 544 | .maxTessellationPatchSize = 0, |
| 545 | .maxTessellationControlPerVertexInputComponents = 0, |
| 546 | .maxTessellationControlPerVertexOutputComponents = 0, |
| 547 | .maxTessellationControlPerPatchOutputComponents = 0, |
| 548 | .maxTessellationControlTotalOutputComponents = 0, |
| 549 | .maxTessellationEvaluationInputComponents = 0, |
| 550 | .maxTessellationEvaluationOutputComponents = 0, |
Kenneth Graunke | 38a3a53 | 2016-01-26 23:09:45 -0800 | [diff] [blame] | 551 | .maxGeometryShaderInvocations = 32, |
| 552 | .maxGeometryInputComponents = 64, |
| 553 | .maxGeometryOutputComponents = 128, |
| 554 | .maxGeometryOutputVertices = 256, |
| 555 | .maxGeometryTotalOutputComponents = 1024, |
| 556 | .maxFragmentInputComponents = 128, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 557 | .maxFragmentOutputAttachments = 8, |
Dave Airlie | eaf0768 | 2016-11-29 11:16:56 +1000 | [diff] [blame] | 558 | .maxFragmentDualSrcAttachments = 1, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 559 | .maxFragmentCombinedOutputResources = 8, |
Kenneth Graunke | 38a3a53 | 2016-01-26 23:09:45 -0800 | [diff] [blame] | 560 | .maxComputeSharedMemorySize = 32768, |
| 561 | .maxComputeWorkGroupCount = { 65535, 65535, 65535 }, |
Lionel Landwerlin | 6b21728 | 2016-09-23 01:04:25 +0300 | [diff] [blame] | 562 | .maxComputeWorkGroupInvocations = 16 * devinfo->max_cs_threads, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 563 | .maxComputeWorkGroupSize = { |
Lionel Landwerlin | 6b21728 | 2016-09-23 01:04:25 +0300 | [diff] [blame] | 564 | 16 * devinfo->max_cs_threads, |
| 565 | 16 * devinfo->max_cs_threads, |
| 566 | 16 * devinfo->max_cs_threads, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 567 | }, |
| 568 | .subPixelPrecisionBits = 4 /* FIXME */, |
| 569 | .subTexelPrecisionBits = 4 /* FIXME */, |
| 570 | .mipmapPrecisionBits = 4 /* FIXME */, |
| 571 | .maxDrawIndexedIndexValue = UINT32_MAX, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 572 | .maxDrawIndirectCount = UINT32_MAX, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 573 | .maxSamplerLodBias = 16, |
| 574 | .maxSamplerAnisotropy = 16, |
Jason Ekstrand | daf68a9 | 2015-10-06 17:21:44 -0700 | [diff] [blame] | 575 | .maxViewports = MAX_VIEWPORTS, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 576 | .maxViewportDimensions = { (1 << 14), (1 << 14) }, |
Nanley Chery | 7ac08ad | 2016-05-17 15:28:01 -0700 | [diff] [blame] | 577 | .viewportBoundsRange = { INT16_MIN, INT16_MAX }, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 578 | .viewportSubPixelBits = 13, /* We take a float? */ |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 579 | .minMemoryMapAlignment = 4096, /* A page */ |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 580 | .minTexelBufferOffsetAlignment = 1, |
| 581 | .minUniformBufferOffsetAlignment = 1, |
| 582 | .minStorageBufferOffsetAlignment = 1, |
Kenneth Graunke | 38a3a53 | 2016-01-26 23:09:45 -0800 | [diff] [blame] | 583 | .minTexelOffset = -8, |
| 584 | .maxTexelOffset = 7, |
| 585 | .minTexelGatherOffset = -8, |
| 586 | .maxTexelGatherOffset = 7, |
Anuj Phogat | 0bf531a | 2016-07-28 17:37:20 -0700 | [diff] [blame] | 587 | .minInterpolationOffset = -0.5, |
| 588 | .maxInterpolationOffset = 0.4375, |
| 589 | .subPixelInterpolationOffsetBits = 4, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 590 | .maxFramebufferWidth = (1 << 14), |
| 591 | .maxFramebufferHeight = (1 << 14), |
| 592 | .maxFramebufferLayers = (1 << 10), |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 593 | .framebufferColorSampleCounts = sample_counts, |
| 594 | .framebufferDepthSampleCounts = sample_counts, |
| 595 | .framebufferStencilSampleCounts = sample_counts, |
| 596 | .framebufferNoAttachmentsSampleCounts = sample_counts, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 597 | .maxColorAttachments = MAX_RTS, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 598 | .sampledImageColorSampleCounts = sample_counts, |
| 599 | .sampledImageIntegerSampleCounts = VK_SAMPLE_COUNT_1_BIT, |
| 600 | .sampledImageDepthSampleCounts = sample_counts, |
| 601 | .sampledImageStencilSampleCounts = sample_counts, |
| 602 | .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 603 | .maxSampleMaskWords = 1, |
Jason Ekstrand | 802f002 | 2016-01-14 06:58:11 -0800 | [diff] [blame] | 604 | .timestampComputeAndGraphics = false, |
Philipp Zabel | 0408d50 | 2016-10-06 01:48:04 +0200 | [diff] [blame] | 605 | .timestampPeriod = time_stamp_base, |
Kenneth Graunke | a4d7a5b | 2016-10-03 20:44:38 -0700 | [diff] [blame] | 606 | .maxClipDistances = 8, |
| 607 | .maxCullDistances = 8, |
| 608 | .maxCombinedClipAndCullDistances = 8, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 609 | .discreteQueuePriorities = 1, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 610 | .pointSizeRange = { 0.125, 255.875 }, |
| 611 | .lineWidthRange = { 0.0, 7.9921875 }, |
| 612 | .pointSizeGranularity = (1.0 / 8.0), |
| 613 | .lineWidthGranularity = (1.0 / 128.0), |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 614 | .strictLines = false, /* FINISHME */ |
Chad Versace | 8cc6f05 | 2016-01-26 10:56:06 -0800 | [diff] [blame] | 615 | .standardSampleLocations = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 616 | .optimalBufferCopyOffsetAlignment = 128, |
| 617 | .optimalBufferCopyRowPitchAlignment = 128, |
| 618 | .nonCoherentAtomSize = 64, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 619 | }; |
| 620 | |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 621 | *pProperties = (VkPhysicalDeviceProperties) { |
Jason Ekstrand | 20417b2 | 2016-03-22 16:21:21 -0700 | [diff] [blame] | 622 | .apiVersion = VK_MAKE_VERSION(1, 0, 5), |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 623 | .driverVersion = 1, |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 624 | .vendorID = 0x8086, |
| 625 | .deviceID = pdevice->chipset_id, |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 626 | .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 627 | .limits = limits, |
| 628 | .sparseProperties = {0}, /* Broadwell doesn't do sparse. */ |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 629 | }; |
| 630 | |
| 631 | strcpy(pProperties->deviceName, pdevice->name); |
Emil Velikov | de138e9 | 2016-11-24 20:30:38 +0000 | [diff] [blame] | 632 | memcpy(pProperties->pipelineCacheUUID, pdevice->uuid, VK_UUID_SIZE); |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 635 | void anv_GetPhysicalDeviceQueueFamilyProperties( |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 636 | VkPhysicalDevice physicalDevice, |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 637 | uint32_t* pCount, |
| 638 | VkQueueFamilyProperties* pQueueFamilyProperties) |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 639 | { |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 640 | if (pQueueFamilyProperties == NULL) { |
| 641 | *pCount = 1; |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 642 | return; |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 643 | } |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 644 | |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 645 | assert(*pCount >= 1); |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 646 | |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 647 | *pQueueFamilyProperties = (VkQueueFamilyProperties) { |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 648 | .queueFlags = VK_QUEUE_GRAPHICS_BIT | |
| 649 | VK_QUEUE_COMPUTE_BIT | |
Jason Ekstrand | 6a8a542 | 2015-11-30 11:12:44 -0800 | [diff] [blame] | 650 | VK_QUEUE_TRANSFER_BIT, |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 651 | .queueCount = 1, |
Kristian Høgsberg Kristensen | 925ad84 | 2016-01-09 00:51:14 -0800 | [diff] [blame] | 652 | .timestampValidBits = 36, /* XXX: Real value here */ |
Jason Ekstrand | 74c4c4a | 2015-12-02 16:20:40 -0800 | [diff] [blame] | 653 | .minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 }, |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 654 | }; |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 657 | void anv_GetPhysicalDeviceMemoryProperties( |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 658 | VkPhysicalDevice physicalDevice, |
| 659 | VkPhysicalDeviceMemoryProperties* pMemoryProperties) |
| 660 | { |
| 661 | ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 662 | VkDeviceSize heap_size; |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 663 | |
| 664 | /* Reserve some wiggle room for the driver by exposing only 75% of the |
| 665 | * aperture to the heap. |
| 666 | */ |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 667 | heap_size = 3 * physical_device->aperture_size / 4; |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 668 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 669 | if (physical_device->info.has_llc) { |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 670 | /* Big core GPUs share LLC with the CPU and thus one memory type can be |
| 671 | * both cached and coherent at the same time. |
| 672 | */ |
| 673 | pMemoryProperties->memoryTypeCount = 1; |
| 674 | pMemoryProperties->memoryTypes[0] = (VkMemoryType) { |
| 675 | .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 676 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 677 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | |
| 678 | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, |
Jason Ekstrand | 3421ba1 | 2015-12-30 19:32:41 -0800 | [diff] [blame] | 679 | .heapIndex = 0, |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 680 | }; |
| 681 | } else { |
| 682 | /* The spec requires that we expose a host-visible, coherent memory |
| 683 | * type, but Atom GPUs don't share LLC. Thus we offer two memory types |
| 684 | * to give the application a choice between cached, but not coherent and |
| 685 | * coherent but uncached (WC though). |
| 686 | */ |
| 687 | pMemoryProperties->memoryTypeCount = 2; |
| 688 | pMemoryProperties->memoryTypes[0] = (VkMemoryType) { |
| 689 | .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 690 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 691 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, |
Jason Ekstrand | 3421ba1 | 2015-12-30 19:32:41 -0800 | [diff] [blame] | 692 | .heapIndex = 0, |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 693 | }; |
| 694 | pMemoryProperties->memoryTypes[1] = (VkMemoryType) { |
| 695 | .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 696 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 697 | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, |
Jason Ekstrand | 3421ba1 | 2015-12-30 19:32:41 -0800 | [diff] [blame] | 698 | .heapIndex = 0, |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 699 | }; |
| 700 | } |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 701 | |
| 702 | pMemoryProperties->memoryHeapCount = 1; |
| 703 | pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) { |
| 704 | .size = heap_size, |
Jason Ekstrand | e6ab06a | 2015-12-02 10:39:15 -0800 | [diff] [blame] | 705 | .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 706 | }; |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Jason Ekstrand | e7acdda | 2015-07-07 18:51:53 -0700 | [diff] [blame] | 709 | PFN_vkVoidFunction anv_GetInstanceProcAddr( |
| 710 | VkInstance instance, |
| 711 | const char* pName) |
| 712 | { |
Jason Ekstrand | 6d557ae | 2016-10-07 15:47:45 -0700 | [diff] [blame] | 713 | return anv_lookup_entrypoint(NULL, pName); |
Jason Ekstrand | e7acdda | 2015-07-07 18:51:53 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Emil Velikov | 40e4fff | 2016-07-28 14:40:08 +0100 | [diff] [blame] | 716 | /* With version 1+ of the loader interface the ICD should expose |
| 717 | * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps. |
Jason Ekstrand | 3a2b23a | 2016-02-11 21:18:02 -0800 | [diff] [blame] | 718 | */ |
Emil Velikov | 40e4fff | 2016-07-28 14:40:08 +0100 | [diff] [blame] | 719 | PUBLIC |
Jason Ekstrand | 3a2b23a | 2016-02-11 21:18:02 -0800 | [diff] [blame] | 720 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr( |
| 721 | VkInstance instance, |
| 722 | const char* pName); |
| 723 | |
Emil Velikov | 40e4fff | 2016-07-28 14:40:08 +0100 | [diff] [blame] | 724 | PUBLIC |
Jason Ekstrand | 3a2b23a | 2016-02-11 21:18:02 -0800 | [diff] [blame] | 725 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr( |
| 726 | VkInstance instance, |
| 727 | const char* pName) |
| 728 | { |
| 729 | return anv_GetInstanceProcAddr(instance, pName); |
| 730 | } |
| 731 | |
Jason Ekstrand | e7acdda | 2015-07-07 18:51:53 -0700 | [diff] [blame] | 732 | PFN_vkVoidFunction anv_GetDeviceProcAddr( |
Jason Ekstrand | 6d557ae | 2016-10-07 15:47:45 -0700 | [diff] [blame] | 733 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 734 | const char* pName) |
| 735 | { |
Jason Ekstrand | 6d557ae | 2016-10-07 15:47:45 -0700 | [diff] [blame] | 736 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 737 | return anv_lookup_entrypoint(&device->info, pName); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Gwan-gyeong Mun | ca47069 | 2016-11-25 23:34:43 +0900 | [diff] [blame] | 740 | static void |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 741 | anv_queue_init(struct anv_device *device, struct anv_queue *queue) |
| 742 | { |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 743 | queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 744 | queue->device = device; |
| 745 | queue->pool = &device->surface_state_pool; |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static void |
| 749 | anv_queue_finish(struct anv_queue *queue) |
| 750 | { |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 753 | static struct anv_state |
| 754 | anv_state_pool_emit_data(struct anv_state_pool *pool, size_t size, size_t align, const void *p) |
| 755 | { |
| 756 | struct anv_state state; |
| 757 | |
| 758 | state = anv_state_pool_alloc(pool, size, align); |
| 759 | memcpy(state.map, p, size); |
| 760 | |
| 761 | if (!pool->block_pool->device->info.has_llc) |
| 762 | anv_state_clflush(state); |
| 763 | |
| 764 | return state; |
| 765 | } |
| 766 | |
Jason Ekstrand | d49298c | 2016-01-18 12:16:31 -0800 | [diff] [blame] | 767 | struct gen8_border_color { |
| 768 | union { |
| 769 | float float32[4]; |
| 770 | uint32_t uint32[4]; |
| 771 | }; |
| 772 | /* Pad out to 64 bytes */ |
| 773 | uint32_t _pad[12]; |
| 774 | }; |
| 775 | |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 776 | static void |
| 777 | anv_device_init_border_colors(struct anv_device *device) |
| 778 | { |
Jason Ekstrand | d49298c | 2016-01-18 12:16:31 -0800 | [diff] [blame] | 779 | static const struct gen8_border_color border_colors[] = { |
Jason Ekstrand | bd4cde7 | 2015-10-06 10:07:47 -0700 | [diff] [blame] | 780 | [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 0.0 } }, |
| 781 | [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 1.0 } }, |
| 782 | [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] = { .float32 = { 1.0, 1.0, 1.0, 1.0 } }, |
| 783 | [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] = { .uint32 = { 0, 0, 0, 0 } }, |
| 784 | [VK_BORDER_COLOR_INT_OPAQUE_BLACK] = { .uint32 = { 0, 0, 0, 1 } }, |
| 785 | [VK_BORDER_COLOR_INT_OPAQUE_WHITE] = { .uint32 = { 1, 1, 1, 1 } }, |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 786 | }; |
| 787 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 788 | device->border_colors = anv_state_pool_emit_data(&device->dynamic_state_pool, |
Jason Ekstrand | d49298c | 2016-01-18 12:16:31 -0800 | [diff] [blame] | 789 | sizeof(border_colors), 64, |
| 790 | border_colors); |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Kristian Høgsberg Kristensen | 6cdada0 | 2016-02-05 16:11:12 -0800 | [diff] [blame] | 793 | VkResult |
| 794 | anv_device_submit_simple_batch(struct anv_device *device, |
| 795 | struct anv_batch *batch) |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 796 | { |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 797 | struct drm_i915_gem_execbuffer2 execbuf; |
| 798 | struct drm_i915_gem_exec_object2 exec2_objects[1]; |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 799 | struct anv_bo bo, *exec_bos[1]; |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 800 | VkResult result = VK_SUCCESS; |
| 801 | uint32_t size; |
| 802 | int64_t timeout; |
| 803 | int ret; |
| 804 | |
Kristian Høgsberg Kristensen | 6cdada0 | 2016-02-05 16:11:12 -0800 | [diff] [blame] | 805 | /* Kernel driver requires 8 byte aligned batch length */ |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 806 | size = align_u32(batch->next - batch->start, 8); |
Jason Ekstrand | ecfb074 | 2016-03-18 13:06:08 -0700 | [diff] [blame] | 807 | result = anv_bo_pool_alloc(&device->batch_bo_pool, &bo, size); |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 808 | if (result != VK_SUCCESS) |
| 809 | return result; |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 810 | |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 811 | memcpy(bo.map, batch->start, size); |
Jason Ekstrand | 699f212 | 2016-02-12 11:00:42 -0800 | [diff] [blame] | 812 | if (!device->info.has_llc) |
| 813 | anv_clflush_range(bo.map, size); |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 814 | |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 815 | exec_bos[0] = &bo; |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 816 | exec2_objects[0].handle = bo.gem_handle; |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 817 | exec2_objects[0].relocation_count = 0; |
| 818 | exec2_objects[0].relocs_ptr = 0; |
| 819 | exec2_objects[0].alignment = 0; |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 820 | exec2_objects[0].offset = bo.offset; |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 821 | exec2_objects[0].flags = 0; |
| 822 | exec2_objects[0].rsvd1 = 0; |
| 823 | exec2_objects[0].rsvd2 = 0; |
| 824 | |
| 825 | execbuf.buffers_ptr = (uintptr_t) exec2_objects; |
| 826 | execbuf.buffer_count = 1; |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 827 | execbuf.batch_start_offset = 0; |
Kristian Høgsberg Kristensen | 6cdada0 | 2016-02-05 16:11:12 -0800 | [diff] [blame] | 828 | execbuf.batch_len = size; |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 829 | execbuf.cliprects_ptr = 0; |
| 830 | execbuf.num_cliprects = 0; |
| 831 | execbuf.DR1 = 0; |
| 832 | execbuf.DR4 = 0; |
| 833 | |
| 834 | execbuf.flags = |
| 835 | I915_EXEC_HANDLE_LUT | I915_EXEC_NO_RELOC | I915_EXEC_RENDER; |
| 836 | execbuf.rsvd1 = device->context_id; |
| 837 | execbuf.rsvd2 = 0; |
| 838 | |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 839 | result = anv_device_execbuf(device, &execbuf, exec_bos); |
| 840 | if (result != VK_SUCCESS) |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 841 | goto fail; |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 842 | |
| 843 | timeout = INT64_MAX; |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 844 | ret = anv_gem_wait(device, bo.gem_handle, &timeout); |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 845 | if (ret != 0) { |
| 846 | /* We don't know the real error. */ |
Jason Ekstrand | c41ec16 | 2016-10-31 16:33:43 -0700 | [diff] [blame] | 847 | result = vk_errorf(VK_ERROR_DEVICE_LOST, "execbuf2 failed: %m"); |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 848 | goto fail; |
| 849 | } |
| 850 | |
| 851 | fail: |
Jason Ekstrand | ea93041 | 2016-02-11 18:41:04 -0800 | [diff] [blame] | 852 | anv_bo_pool_free(&device->batch_bo_pool, &bo); |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 853 | |
| 854 | return result; |
| 855 | } |
| 856 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 857 | VkResult anv_CreateDevice( |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 858 | VkPhysicalDevice physicalDevice, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 859 | const VkDeviceCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 860 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 861 | VkDevice* pDevice) |
| 862 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 863 | ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 864 | VkResult result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 865 | struct anv_device *device; |
| 866 | |
| 867 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); |
| 868 | |
Jason Ekstrand | aab9517 | 2016-01-14 07:41:45 -0800 | [diff] [blame] | 869 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 870 | bool found = false; |
| 871 | for (uint32_t j = 0; j < ARRAY_SIZE(device_extensions); j++) { |
| 872 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 873 | device_extensions[j].extensionName) == 0) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 874 | found = true; |
| 875 | break; |
| 876 | } |
| 877 | } |
| 878 | if (!found) |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 879 | return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 882 | device = vk_alloc2(&physical_device->instance->alloc, pAllocator, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 883 | sizeof(*device), 8, |
Jason Ekstrand | 45d17fc | 2016-01-18 14:04:13 -0800 | [diff] [blame] | 884 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 885 | if (!device) |
| 886 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 887 | |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 888 | device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 889 | device->instance = physical_device->instance; |
Kristian Høgsberg Kristensen | 39a120a | 2016-02-10 09:43:03 -0800 | [diff] [blame] | 890 | device->chipset_id = physical_device->chipset_id; |
Chad Versace | 8cda3e9 | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 891 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 892 | if (pAllocator) |
| 893 | device->alloc = *pAllocator; |
| 894 | else |
| 895 | device->alloc = physical_device->instance->alloc; |
| 896 | |
Chad Versace | 8cda3e9 | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 897 | /* XXX(chadv): Can we dup() physicalDevice->fd here? */ |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 898 | device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC); |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 899 | if (device->fd == -1) { |
| 900 | result = vk_error(VK_ERROR_INITIALIZATION_FAILED); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 901 | goto fail_device; |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 902 | } |
Chad Versace | 477383e | 2015-11-13 10:12:18 -0800 | [diff] [blame] | 903 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 904 | device->context_id = anv_gem_create_context(device); |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 905 | if (device->context_id == -1) { |
| 906 | result = vk_error(VK_ERROR_INITIALIZATION_FAILED); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 907 | goto fail_fd; |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 908 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 909 | |
Lionel Landwerlin | bc24590 | 2016-09-22 14:58:11 +0300 | [diff] [blame] | 910 | device->info = physical_device->info; |
Jason Ekstrand | 9c84b6c | 2015-12-28 13:26:49 -0800 | [diff] [blame] | 911 | device->isl_dev = physical_device->isl_dev; |
| 912 | |
Jason Ekstrand | 869e393 | 2016-03-18 16:32:46 -0700 | [diff] [blame] | 913 | /* On Broadwell and later, we can use batch chaining to more efficiently |
| 914 | * implement growing command buffers. Prior to Haswell, the kernel |
| 915 | * command parser gets in the way and we have to fall back to growing |
| 916 | * the batch. |
| 917 | */ |
| 918 | device->can_chain_batches = device->info.gen >= 8; |
| 919 | |
Jason Ekstrand | c29ffea | 2016-05-14 14:52:36 -0700 | [diff] [blame] | 920 | device->robust_buffer_access = pCreateInfo->pEnabledFeatures && |
| 921 | pCreateInfo->pEnabledFeatures->robustBufferAccess; |
| 922 | |
Jason Ekstrand | a788e7c | 2015-09-17 18:23:21 -0700 | [diff] [blame] | 923 | pthread_mutex_init(&device->mutex, NULL); |
| 924 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 925 | pthread_condattr_t condattr; |
| 926 | pthread_condattr_init(&condattr); |
| 927 | pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); |
| 928 | pthread_cond_init(&device->queue_submit, NULL); |
| 929 | pthread_condattr_destroy(&condattr); |
| 930 | |
Jason Ekstrand | ecfb074 | 2016-03-18 13:06:08 -0700 | [diff] [blame] | 931 | anv_bo_pool_init(&device->batch_bo_pool, device); |
Jason Ekstrand | 5ef81f0 | 2015-05-25 15:46:48 -0700 | [diff] [blame] | 932 | |
Jordan Justen | c7f6e42 | 2016-01-08 12:15:29 -0800 | [diff] [blame] | 933 | anv_block_pool_init(&device->dynamic_state_block_pool, device, 16384); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 934 | |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 935 | anv_state_pool_init(&device->dynamic_state_pool, |
| 936 | &device->dynamic_state_block_pool); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 937 | |
Jason Ekstrand | aee970c | 2016-01-12 13:48:32 -0800 | [diff] [blame] | 938 | anv_block_pool_init(&device->instruction_block_pool, device, 128 * 1024); |
Jason Ekstrand | 6899718 | 2016-08-24 23:48:32 -0700 | [diff] [blame] | 939 | anv_state_pool_init(&device->instruction_state_pool, |
| 940 | &device->instruction_block_pool); |
Kristian Høgsberg Kristensen | 30521fb | 2016-01-05 12:00:54 -0800 | [diff] [blame] | 941 | |
Jason Ekstrand | 0e94446 | 2015-09-22 16:36:00 -0700 | [diff] [blame] | 942 | anv_block_pool_init(&device->surface_state_block_pool, device, 4096); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 943 | |
| 944 | anv_state_pool_init(&device->surface_state_pool, |
| 945 | &device->surface_state_block_pool); |
| 946 | |
Jason Ekstrand | 3a3d79b | 2015-11-10 16:42:34 -0800 | [diff] [blame] | 947 | anv_bo_init_new(&device->workaround_bo, device, 1024); |
| 948 | |
Jason Ekstrand | c2f2c8e | 2016-06-16 15:26:54 -0700 | [diff] [blame] | 949 | anv_scratch_pool_init(device, &device->scratch_pool); |
Kristian Høgsberg Kristensen | 9b9f973 | 2015-06-19 15:41:30 -0700 | [diff] [blame] | 950 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 951 | anv_queue_init(device, &device->queue); |
| 952 | |
Kristian Høgsberg Kristensen | 6cdada0 | 2016-02-05 16:11:12 -0800 | [diff] [blame] | 953 | switch (device->info.gen) { |
| 954 | case 7: |
| 955 | if (!device->info.is_haswell) |
| 956 | result = gen7_init_device_state(device); |
| 957 | else |
| 958 | result = gen75_init_device_state(device); |
| 959 | break; |
| 960 | case 8: |
| 961 | result = gen8_init_device_state(device); |
| 962 | break; |
| 963 | case 9: |
| 964 | result = gen9_init_device_state(device); |
| 965 | break; |
Kristian Høgsberg Kristensen | 5d72d7b | 2016-02-14 13:20:06 -0800 | [diff] [blame] | 966 | default: |
| 967 | /* Shouldn't get here as we don't create physical devices for any other |
| 968 | * gens. */ |
| 969 | unreachable("unhandled gen"); |
Kristian Høgsberg Kristensen | 6cdada0 | 2016-02-05 16:11:12 -0800 | [diff] [blame] | 970 | } |
| 971 | if (result != VK_SUCCESS) |
| 972 | goto fail_fd; |
| 973 | |
Jason Ekstrand | 8f780af | 2016-08-22 21:37:28 -0700 | [diff] [blame] | 974 | anv_device_init_blorp(device); |
| 975 | |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 976 | anv_device_init_border_colors(device); |
| 977 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 978 | *pDevice = anv_device_to_handle(device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 979 | |
| 980 | return VK_SUCCESS; |
| 981 | |
| 982 | fail_fd: |
| 983 | close(device->fd); |
| 984 | fail_device: |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 985 | vk_free(&device->alloc, device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 986 | |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 987 | return result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 990 | void anv_DestroyDevice( |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 991 | VkDevice _device, |
| 992 | const VkAllocationCallbacks* pAllocator) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 993 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 994 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 995 | |
Jason Ekstrand | 8f780af | 2016-08-22 21:37:28 -0700 | [diff] [blame] | 996 | anv_device_finish_blorp(device); |
| 997 | |
Gwan-gyeong Mun | b178652 | 2016-11-25 23:34:46 +0900 | [diff] [blame] | 998 | anv_queue_finish(&device->queue); |
| 999 | |
Jason Ekstrand | 38f5eef | 2015-06-09 11:41:31 -0700 | [diff] [blame] | 1000 | #ifdef HAVE_VALGRIND |
| 1001 | /* We only need to free these to prevent valgrind errors. The backing |
| 1002 | * BO will go away in a couple of lines so we don't actually leak. |
| 1003 | */ |
Jason Ekstrand | 522ab83 | 2015-07-08 11:44:52 -0700 | [diff] [blame] | 1004 | anv_state_pool_free(&device->dynamic_state_pool, device->border_colors); |
Jason Ekstrand | 38f5eef | 2015-06-09 11:41:31 -0700 | [diff] [blame] | 1005 | #endif |
| 1006 | |
Gwan-gyeong Mun | b178652 | 2016-11-25 23:34:46 +0900 | [diff] [blame] | 1007 | anv_scratch_pool_finish(device, &device->scratch_pool); |
| 1008 | |
Jason Ekstrand | 3a3d79b | 2015-11-10 16:42:34 -0800 | [diff] [blame] | 1009 | anv_gem_munmap(device->workaround_bo.map, device->workaround_bo.size); |
| 1010 | anv_gem_close(device, device->workaround_bo.gem_handle); |
| 1011 | |
Jason Ekstrand | 1920ef9 | 2015-07-31 10:30:57 -0700 | [diff] [blame] | 1012 | anv_state_pool_finish(&device->surface_state_pool); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1013 | anv_block_pool_finish(&device->surface_state_block_pool); |
Gwan-gyeong Mun | b178652 | 2016-11-25 23:34:46 +0900 | [diff] [blame] | 1014 | anv_state_pool_finish(&device->instruction_state_pool); |
| 1015 | anv_block_pool_finish(&device->instruction_block_pool); |
| 1016 | anv_state_pool_finish(&device->dynamic_state_pool); |
| 1017 | anv_block_pool_finish(&device->dynamic_state_block_pool); |
| 1018 | |
| 1019 | anv_bo_pool_finish(&device->batch_bo_pool); |
| 1020 | |
| 1021 | pthread_cond_destroy(&device->queue_submit); |
| 1022 | pthread_mutex_destroy(&device->mutex); |
| 1023 | |
| 1024 | anv_gem_destroy_context(device, device->context_id); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1025 | |
| 1026 | close(device->fd); |
| 1027 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1028 | vk_free(&device->alloc, device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 1031 | VkResult anv_EnumerateInstanceExtensionProperties( |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1032 | const char* pLayerName, |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1033 | uint32_t* pPropertyCount, |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 1034 | VkExtensionProperties* pProperties) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1035 | { |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1036 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1037 | *pPropertyCount = ARRAY_SIZE(global_extensions); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1038 | return VK_SUCCESS; |
| 1039 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1040 | |
Emil Velikov | 5cc07d8 | 2016-10-06 14:12:27 +0100 | [diff] [blame] | 1041 | *pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(global_extensions)); |
| 1042 | typed_memcpy(pProperties, global_extensions, *pPropertyCount); |
Kristian Høgsberg | 783e621 | 2015-05-17 19:22:52 -0700 | [diff] [blame] | 1043 | |
Emil Velikov | 5cc07d8 | 2016-10-06 14:12:27 +0100 | [diff] [blame] | 1044 | if (*pPropertyCount < ARRAY_SIZE(global_extensions)) |
| 1045 | return VK_INCOMPLETE; |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 1046 | |
| 1047 | return VK_SUCCESS; |
| 1048 | } |
| 1049 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 1050 | VkResult anv_EnumerateDeviceExtensionProperties( |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 1051 | VkPhysicalDevice physicalDevice, |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1052 | const char* pLayerName, |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1053 | uint32_t* pPropertyCount, |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 1054 | VkExtensionProperties* pProperties) |
| 1055 | { |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1056 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1057 | *pPropertyCount = ARRAY_SIZE(device_extensions); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1058 | return VK_SUCCESS; |
| 1059 | } |
| 1060 | |
Emil Velikov | 5cc07d8 | 2016-10-06 14:12:27 +0100 | [diff] [blame] | 1061 | *pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(device_extensions)); |
| 1062 | typed_memcpy(pProperties, device_extensions, *pPropertyCount); |
Jason Ekstrand | 9a7600c | 2015-09-01 16:44:42 -0700 | [diff] [blame] | 1063 | |
Emil Velikov | 5cc07d8 | 2016-10-06 14:12:27 +0100 | [diff] [blame] | 1064 | if (*pPropertyCount < ARRAY_SIZE(device_extensions)) |
| 1065 | return VK_INCOMPLETE; |
Jason Ekstrand | 9a7600c | 2015-09-01 16:44:42 -0700 | [diff] [blame] | 1066 | |
| 1067 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 1070 | VkResult anv_EnumerateInstanceLayerProperties( |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1071 | uint32_t* pPropertyCount, |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1072 | VkLayerProperties* pProperties) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1073 | { |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1074 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1075 | *pPropertyCount = 0; |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1076 | return VK_SUCCESS; |
| 1077 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1078 | |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1079 | /* None supported at this time */ |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1080 | return vk_error(VK_ERROR_LAYER_NOT_PRESENT); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 1083 | VkResult anv_EnumerateDeviceLayerProperties( |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1084 | VkPhysicalDevice physicalDevice, |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1085 | uint32_t* pPropertyCount, |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1086 | VkLayerProperties* pProperties) |
| 1087 | { |
| 1088 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 1089 | *pPropertyCount = 0; |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 1090 | return VK_SUCCESS; |
| 1091 | } |
| 1092 | |
| 1093 | /* None supported at this time */ |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1094 | return vk_error(VK_ERROR_LAYER_NOT_PRESENT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1097 | void anv_GetDeviceQueue( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1098 | VkDevice _device, |
| 1099 | uint32_t queueNodeIndex, |
| 1100 | uint32_t queueIndex, |
| 1101 | VkQueue* pQueue) |
| 1102 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1103 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1104 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 1105 | assert(queueIndex == 0); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1106 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1107 | *pQueue = anv_queue_to_handle(&device->queue); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 1110 | VkResult |
| 1111 | anv_device_execbuf(struct anv_device *device, |
| 1112 | struct drm_i915_gem_execbuffer2 *execbuf, |
| 1113 | struct anv_bo **execbuf_bos) |
| 1114 | { |
| 1115 | int ret = anv_gem_execbuffer(device, execbuf); |
| 1116 | if (ret != 0) { |
| 1117 | /* We don't know the real error. */ |
| 1118 | return vk_errorf(VK_ERROR_DEVICE_LOST, "execbuf2 failed: %m"); |
| 1119 | } |
| 1120 | |
Jason Ekstrand | 1826624 | 2016-11-09 18:45:21 -0800 | [diff] [blame] | 1121 | struct drm_i915_gem_exec_object2 *objects = |
| 1122 | (void *)(uintptr_t)execbuf->buffers_ptr; |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 1123 | for (uint32_t k = 0; k < execbuf->buffer_count; k++) |
| 1124 | execbuf_bos[k]->offset = objects[k].offset; |
| 1125 | |
| 1126 | return VK_SUCCESS; |
| 1127 | } |
| 1128 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1129 | VkResult anv_QueueSubmit( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1130 | VkQueue _queue, |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 1131 | uint32_t submitCount, |
| 1132 | const VkSubmitInfo* pSubmits, |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1133 | VkFence _fence) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1134 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1135 | ANV_FROM_HANDLE(anv_queue, queue, _queue); |
| 1136 | ANV_FROM_HANDLE(anv_fence, fence, _fence); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1137 | struct anv_device *device = queue->device; |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 1138 | VkResult result = VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1139 | |
Kristian Høgsberg Kristensen | b3a29f2 | 2016-03-08 15:31:47 -0800 | [diff] [blame] | 1140 | /* We lock around QueueSubmit for three main reasons: |
Jason Ekstrand | 8b61c57 | 2016-11-05 19:47:33 -0700 | [diff] [blame] | 1141 | * |
| 1142 | * 1) When a block pool is resized, we create a new gem handle with a |
| 1143 | * different size and, in the case of surface states, possibly a |
| 1144 | * different center offset but we re-use the same anv_bo struct when |
| 1145 | * we do so. If this happens in the middle of setting up an execbuf, |
| 1146 | * we could end up with our list of BOs out of sync with our list of |
| 1147 | * gem handles. |
| 1148 | * |
| 1149 | * 2) The algorithm we use for building the list of unique buffers isn't |
| 1150 | * thread-safe. While the client is supposed to syncronize around |
| 1151 | * QueueSubmit, this would be extremely difficult to debug if it ever |
| 1152 | * came up in the wild due to a broken app. It's better to play it |
| 1153 | * safe and just lock around QueueSubmit. |
| 1154 | * |
Kristian Høgsberg Kristensen | b3a29f2 | 2016-03-08 15:31:47 -0800 | [diff] [blame] | 1155 | * 3) The anv_cmd_buffer_execbuf function may perform relocations in |
| 1156 | * userspace. Due to the fact that the surface state buffer is shared |
| 1157 | * between batches, we can't afford to have that happen from multiple |
| 1158 | * threads at the same time. Even though the user is supposed to |
| 1159 | * ensure this doesn't happen, we play it safe as in (2) above. |
| 1160 | * |
Jason Ekstrand | 8b61c57 | 2016-11-05 19:47:33 -0700 | [diff] [blame] | 1161 | * Since the only other things that ever take the device lock such as block |
| 1162 | * pool resize only rarely happen, this will almost never be contended so |
| 1163 | * taking a lock isn't really an expensive operation in this case. |
| 1164 | */ |
| 1165 | pthread_mutex_lock(&device->mutex); |
| 1166 | |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 1167 | for (uint32_t i = 0; i < submitCount; i++) { |
| 1168 | for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) { |
| 1169 | ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, |
| 1170 | pSubmits[i].pCommandBuffers[j]); |
| 1171 | assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1172 | |
Jason Ekstrand | db9f4b2 | 2016-11-02 10:33:54 -0700 | [diff] [blame] | 1173 | result = anv_cmd_buffer_execbuf(device, cmd_buffer); |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 1174 | if (result != VK_SUCCESS) |
Jason Ekstrand | 8b61c57 | 2016-11-05 19:47:33 -0700 | [diff] [blame] | 1175 | goto out; |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 1176 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
Kristian Høgsberg Kristensen | b0c30b7 | 2016-02-12 15:08:09 -0800 | [diff] [blame] | 1179 | if (fence) { |
Jason Ekstrand | 07798c9 | 2016-10-31 20:36:26 -0700 | [diff] [blame] | 1180 | struct anv_bo *fence_bo = &fence->bo; |
| 1181 | result = anv_device_execbuf(device, &fence->execbuf, &fence_bo); |
| 1182 | if (result != VK_SUCCESS) |
Jason Ekstrand | 8b61c57 | 2016-11-05 19:47:33 -0700 | [diff] [blame] | 1183 | goto out; |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1184 | |
| 1185 | /* Update the fence and wake up any waiters */ |
| 1186 | assert(fence->state == ANV_FENCE_STATE_RESET); |
| 1187 | fence->state = ANV_FENCE_STATE_SUBMITTED; |
| 1188 | pthread_cond_broadcast(&device->queue_submit); |
Kristian Høgsberg Kristensen | b0c30b7 | 2016-02-12 15:08:09 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
Jason Ekstrand | 8b61c57 | 2016-11-05 19:47:33 -0700 | [diff] [blame] | 1191 | out: |
| 1192 | pthread_mutex_unlock(&device->mutex); |
| 1193 | |
| 1194 | return result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1197 | VkResult anv_QueueWaitIdle( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1198 | VkQueue _queue) |
| 1199 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1200 | ANV_FROM_HANDLE(anv_queue, queue, _queue); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1201 | |
Jason Ekstrand | 4c9dec8 | 2016-10-07 15:41:17 -0700 | [diff] [blame] | 1202 | return anv_DeviceWaitIdle(anv_device_to_handle(queue->device)); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1205 | VkResult anv_DeviceWaitIdle( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1206 | VkDevice _device) |
| 1207 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1208 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1209 | struct anv_batch batch; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1210 | |
Kristian Høgsberg Kristensen | c9c3344 | 2016-02-05 15:23:38 -0800 | [diff] [blame] | 1211 | uint32_t cmds[8]; |
| 1212 | batch.start = batch.next = cmds; |
| 1213 | batch.end = (void *) cmds + sizeof(cmds); |
| 1214 | |
Jason Ekstrand | 5001852 | 2016-04-18 17:03:00 -0700 | [diff] [blame] | 1215 | anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END, bbe); |
| 1216 | anv_batch_emit(&batch, GEN7_MI_NOOP, noop); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1217 | |
Kristian Høgsberg Kristensen | 6cdada0 | 2016-02-05 16:11:12 -0800 | [diff] [blame] | 1218 | return anv_device_submit_simple_batch(device, &batch); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1221 | VkResult |
| 1222 | anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size) |
| 1223 | { |
Jason Ekstrand | 6283b6d | 2016-11-01 13:09:36 -0700 | [diff] [blame] | 1224 | uint32_t gem_handle = anv_gem_create(device, size); |
| 1225 | if (!gem_handle) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1226 | return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
| 1227 | |
Jason Ekstrand | 6283b6d | 2016-11-01 13:09:36 -0700 | [diff] [blame] | 1228 | anv_bo_init(bo, gem_handle, size); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1229 | |
| 1230 | return VK_SUCCESS; |
| 1231 | } |
| 1232 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1233 | VkResult anv_AllocateMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1234 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1235 | const VkMemoryAllocateInfo* pAllocateInfo, |
| 1236 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1237 | VkDeviceMemory* pMem) |
| 1238 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1239 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1240 | struct anv_device_memory *mem; |
| 1241 | VkResult result; |
| 1242 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1243 | assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1244 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1245 | if (pAllocateInfo->allocationSize == 0) { |
| 1246 | /* Apparently, this is allowed */ |
| 1247 | *pMem = VK_NULL_HANDLE; |
| 1248 | return VK_SUCCESS; |
| 1249 | } |
| 1250 | |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1251 | /* We support exactly one memory heap. */ |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 1252 | assert(pAllocateInfo->memoryTypeIndex == 0 || |
| 1253 | (!device->info.has_llc && pAllocateInfo->memoryTypeIndex < 2)); |
Chad Versace | f43a304 | 2015-07-09 19:59:44 -0700 | [diff] [blame] | 1254 | |
| 1255 | /* FINISHME: Fail if allocation request exceeds heap size. */ |
| 1256 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1257 | mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1258 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1259 | if (mem == NULL) |
| 1260 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1261 | |
Jason Ekstrand | 6b0b572 | 2016-01-02 07:52:22 -0800 | [diff] [blame] | 1262 | /* The kernel is going to give us whole pages anyway */ |
| 1263 | uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096); |
| 1264 | |
| 1265 | result = anv_bo_init_new(&mem->bo, device, alloc_size); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1266 | if (result != VK_SUCCESS) |
| 1267 | goto fail; |
| 1268 | |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 1269 | mem->type_index = pAllocateInfo->memoryTypeIndex; |
| 1270 | |
Jason Ekstrand | b1217ea | 2016-11-07 17:25:07 -0800 | [diff] [blame] | 1271 | mem->map = NULL; |
| 1272 | mem->map_size = 0; |
| 1273 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1274 | *pMem = anv_device_memory_to_handle(mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1275 | |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1276 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1277 | |
| 1278 | fail: |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1279 | vk_free2(&device->alloc, pAllocator, mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1280 | |
| 1281 | return result; |
| 1282 | } |
| 1283 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1284 | void anv_FreeMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1285 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1286 | VkDeviceMemory _mem, |
| 1287 | const VkAllocationCallbacks* pAllocator) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1288 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1289 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1290 | ANV_FROM_HANDLE(anv_device_memory, mem, _mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1291 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1292 | if (mem == NULL) |
| 1293 | return; |
| 1294 | |
Jason Ekstrand | b1217ea | 2016-11-07 17:25:07 -0800 | [diff] [blame] | 1295 | if (mem->map) |
| 1296 | anv_UnmapMemory(_device, _mem); |
| 1297 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1298 | if (mem->bo.map) |
| 1299 | anv_gem_munmap(mem->bo.map, mem->bo.size); |
| 1300 | |
| 1301 | if (mem->bo.gem_handle != 0) |
| 1302 | anv_gem_close(device, mem->bo.gem_handle); |
| 1303 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1304 | vk_free2(&device->alloc, pAllocator, mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1307 | VkResult anv_MapMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1308 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1309 | VkDeviceMemory _memory, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1310 | VkDeviceSize offset, |
| 1311 | VkDeviceSize size, |
| 1312 | VkMemoryMapFlags flags, |
| 1313 | void** ppData) |
| 1314 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1315 | ANV_FROM_HANDLE(anv_device, device, _device); |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1316 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1317 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1318 | if (mem == NULL) { |
| 1319 | *ppData = NULL; |
| 1320 | return VK_SUCCESS; |
| 1321 | } |
| 1322 | |
Jason Ekstrand | 56dbf13 | 2016-01-19 15:01:10 -0800 | [diff] [blame] | 1323 | if (size == VK_WHOLE_SIZE) |
| 1324 | size = mem->bo.size - offset; |
| 1325 | |
Jason Ekstrand | 73ef9c8 | 2016-11-07 17:23:44 -0800 | [diff] [blame] | 1326 | /* From the Vulkan spec version 1.0.32 docs for MapMemory: |
| 1327 | * |
| 1328 | * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0 |
| 1329 | * assert(size != 0); |
| 1330 | * * If size is not equal to VK_WHOLE_SIZE, size must be less than or |
| 1331 | * equal to the size of the memory minus offset |
| 1332 | */ |
| 1333 | assert(size > 0); |
| 1334 | assert(offset + size <= mem->bo.size); |
| 1335 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1336 | /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only |
| 1337 | * takes a VkDeviceMemory pointer, it seems like only one map of the memory |
| 1338 | * at a time is valid. We could just mmap up front and return an offset |
| 1339 | * pointer here, but that may exhaust virtual memory on 32 bit |
| 1340 | * userspace. */ |
| 1341 | |
Kristian Høgsberg Kristensen | bbb6875 | 2015-12-03 23:58:05 -0800 | [diff] [blame] | 1342 | uint32_t gem_flags = 0; |
| 1343 | if (!device->info.has_llc && mem->type_index == 0) |
| 1344 | gem_flags |= I915_MMAP_WC; |
| 1345 | |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1346 | /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */ |
| 1347 | uint64_t map_offset = offset & ~4095ull; |
| 1348 | assert(offset >= map_offset); |
| 1349 | uint64_t map_size = (offset + size) - map_offset; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1350 | |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1351 | /* Let's map whole pages */ |
Jason Ekstrand | 6b0b572 | 2016-01-02 07:52:22 -0800 | [diff] [blame] | 1352 | map_size = align_u64(map_size, 4096); |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1353 | |
Jason Ekstrand | 920f34a | 2016-11-07 17:24:24 -0800 | [diff] [blame] | 1354 | void *map = anv_gem_mmap(device, mem->bo.gem_handle, |
| 1355 | map_offset, map_size, gem_flags); |
| 1356 | if (map == MAP_FAILED) |
| 1357 | return vk_error(VK_ERROR_MEMORY_MAP_FAILED); |
| 1358 | |
| 1359 | mem->map = map; |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1360 | mem->map_size = map_size; |
| 1361 | |
| 1362 | *ppData = mem->map + (offset - map_offset); |
Chad Versace | 477383e | 2015-11-13 10:12:18 -0800 | [diff] [blame] | 1363 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1364 | return VK_SUCCESS; |
| 1365 | } |
| 1366 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1367 | void anv_UnmapMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1368 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1369 | VkDeviceMemory _memory) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1370 | { |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1371 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1372 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1373 | if (mem == NULL) |
| 1374 | return; |
| 1375 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1376 | anv_gem_munmap(mem->map, mem->map_size); |
Jason Ekstrand | b1217ea | 2016-11-07 17:25:07 -0800 | [diff] [blame] | 1377 | |
| 1378 | mem->map = NULL; |
| 1379 | mem->map_size = 0; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1382 | static void |
| 1383 | clflush_mapped_ranges(struct anv_device *device, |
| 1384 | uint32_t count, |
| 1385 | const VkMappedMemoryRange *ranges) |
| 1386 | { |
| 1387 | for (uint32_t i = 0; i < count; i++) { |
| 1388 | ANV_FROM_HANDLE(anv_device_memory, mem, ranges[i].memory); |
| 1389 | void *p = mem->map + (ranges[i].offset & ~CACHELINE_MASK); |
Kristian Høgsberg Kristensen | 31d3486 | 2016-01-29 12:07:34 -0800 | [diff] [blame] | 1390 | void *end; |
| 1391 | |
| 1392 | if (ranges[i].offset + ranges[i].size > mem->map_size) |
| 1393 | end = mem->map + mem->map_size; |
| 1394 | else |
| 1395 | end = mem->map + ranges[i].offset + ranges[i].size; |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1396 | |
| 1397 | while (p < end) { |
| 1398 | __builtin_ia32_clflush(p); |
| 1399 | p += CACHELINE_SIZE; |
| 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | |
Jason Ekstrand | d9c2cae | 2015-07-07 17:22:29 -0700 | [diff] [blame] | 1404 | VkResult anv_FlushMappedMemoryRanges( |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1405 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1406 | uint32_t memoryRangeCount, |
| 1407 | const VkMappedMemoryRange* pMemoryRanges) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1408 | { |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1409 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1410 | |
| 1411 | if (device->info.has_llc) |
| 1412 | return VK_SUCCESS; |
| 1413 | |
| 1414 | /* Make sure the writes we're flushing have landed. */ |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1415 | __builtin_ia32_mfence(); |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1416 | |
| 1417 | clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1418 | |
| 1419 | return VK_SUCCESS; |
| 1420 | } |
| 1421 | |
Jason Ekstrand | d9c2cae | 2015-07-07 17:22:29 -0700 | [diff] [blame] | 1422 | VkResult anv_InvalidateMappedMemoryRanges( |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1423 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1424 | uint32_t memoryRangeCount, |
| 1425 | const VkMappedMemoryRange* pMemoryRanges) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1426 | { |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1427 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1428 | |
| 1429 | if (device->info.has_llc) |
| 1430 | return VK_SUCCESS; |
| 1431 | |
| 1432 | clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges); |
| 1433 | |
| 1434 | /* Make sure no reads get moved up above the invalidate. */ |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1435 | __builtin_ia32_mfence(); |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1436 | |
| 1437 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1440 | void anv_GetBufferMemoryRequirements( |
Jason Ekstrand | ef8980e | 2015-07-07 18:16:42 -0700 | [diff] [blame] | 1441 | VkDevice device, |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1442 | VkBuffer _buffer, |
Jason Ekstrand | ef8980e | 2015-07-07 18:16:42 -0700 | [diff] [blame] | 1443 | VkMemoryRequirements* pMemoryRequirements) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1444 | { |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1445 | ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1446 | |
Chad Versace | f43a304 | 2015-07-09 19:59:44 -0700 | [diff] [blame] | 1447 | /* The Vulkan spec (git aaed022) says: |
| 1448 | * |
| 1449 | * memoryTypeBits is a bitfield and contains one bit set for every |
| 1450 | * supported memory type for the resource. The bit `1<<i` is set if and |
| 1451 | * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties |
| 1452 | * structure for the physical device is supported. |
| 1453 | * |
| 1454 | * We support exactly one memory type. |
| 1455 | */ |
| 1456 | pMemoryRequirements->memoryTypeBits = 1; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1457 | |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1458 | pMemoryRequirements->size = buffer->size; |
| 1459 | pMemoryRequirements->alignment = 16; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1462 | void anv_GetImageMemoryRequirements( |
Jason Ekstrand | bb6567f | 2015-07-08 09:04:16 -0700 | [diff] [blame] | 1463 | VkDevice device, |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1464 | VkImage _image, |
| 1465 | VkMemoryRequirements* pMemoryRequirements) |
| 1466 | { |
| 1467 | ANV_FROM_HANDLE(anv_image, image, _image); |
| 1468 | |
| 1469 | /* The Vulkan spec (git aaed022) says: |
| 1470 | * |
| 1471 | * memoryTypeBits is a bitfield and contains one bit set for every |
| 1472 | * supported memory type for the resource. The bit `1<<i` is set if and |
| 1473 | * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties |
| 1474 | * structure for the physical device is supported. |
| 1475 | * |
| 1476 | * We support exactly one memory type. |
| 1477 | */ |
| 1478 | pMemoryRequirements->memoryTypeBits = 1; |
| 1479 | |
| 1480 | pMemoryRequirements->size = image->size; |
| 1481 | pMemoryRequirements->alignment = image->alignment; |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1484 | void anv_GetImageSparseMemoryRequirements( |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1485 | VkDevice device, |
| 1486 | VkImage image, |
Jason Ekstrand | 5a02441 | 2015-12-02 03:34:43 -0800 | [diff] [blame] | 1487 | uint32_t* pSparseMemoryRequirementCount, |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1488 | VkSparseImageMemoryRequirements* pSparseMemoryRequirements) |
| 1489 | { |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1490 | stub(); |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1493 | void anv_GetDeviceMemoryCommitment( |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1494 | VkDevice device, |
| 1495 | VkDeviceMemory memory, |
| 1496 | VkDeviceSize* pCommittedMemoryInBytes) |
| 1497 | { |
| 1498 | *pCommittedMemoryInBytes = 0; |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1501 | VkResult anv_BindBufferMemory( |
| 1502 | VkDevice device, |
| 1503 | VkBuffer _buffer, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1504 | VkDeviceMemory _memory, |
| 1505 | VkDeviceSize memoryOffset) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1506 | { |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1507 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1508 | ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1509 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1510 | if (mem) { |
| 1511 | buffer->bo = &mem->bo; |
| 1512 | buffer->offset = memoryOffset; |
| 1513 | } else { |
| 1514 | buffer->bo = NULL; |
| 1515 | buffer->offset = 0; |
| 1516 | } |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1517 | |
| 1518 | return VK_SUCCESS; |
| 1519 | } |
| 1520 | |
Jason Ekstrand | fd53603 | 2015-11-30 16:42:12 -0800 | [diff] [blame] | 1521 | VkResult anv_QueueBindSparse( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1522 | VkQueue queue, |
Jason Ekstrand | fd53603 | 2015-11-30 16:42:12 -0800 | [diff] [blame] | 1523 | uint32_t bindInfoCount, |
| 1524 | const VkBindSparseInfo* pBindInfo, |
| 1525 | VkFence fence) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1526 | { |
Jason Ekstrand | fed3586 | 2015-12-02 16:14:58 -0800 | [diff] [blame] | 1527 | stub_return(VK_ERROR_INCOMPATIBLE_DRIVER); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1530 | VkResult anv_CreateFence( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1531 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1532 | const VkFenceCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1533 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1534 | VkFence* pFence) |
| 1535 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1536 | ANV_FROM_HANDLE(anv_device, device, _device); |
Jason Ekstrand | 2308891 | 2016-03-07 13:45:25 -0800 | [diff] [blame] | 1537 | struct anv_bo fence_bo; |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1538 | struct anv_fence *fence; |
| 1539 | struct anv_batch batch; |
| 1540 | VkResult result; |
| 1541 | |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1542 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO); |
| 1543 | |
Jason Ekstrand | b1c5d45 | 2016-03-18 11:50:53 -0700 | [diff] [blame] | 1544 | result = anv_bo_pool_alloc(&device->batch_bo_pool, &fence_bo, 4096); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1545 | if (result != VK_SUCCESS) |
Jason Ekstrand | 2308891 | 2016-03-07 13:45:25 -0800 | [diff] [blame] | 1546 | return result; |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1547 | |
Jason Ekstrand | 2308891 | 2016-03-07 13:45:25 -0800 | [diff] [blame] | 1548 | /* Fences are small. Just store the CPU data structure in the BO. */ |
| 1549 | fence = fence_bo.map; |
| 1550 | fence->bo = fence_bo; |
| 1551 | |
| 1552 | /* Place the batch after the CPU data but on its own cache line. */ |
| 1553 | const uint32_t batch_offset = align_u32(sizeof(*fence), CACHELINE_SIZE); |
| 1554 | batch.next = batch.start = fence->bo.map + batch_offset; |
Jason Ekstrand | da8f148 | 2015-05-27 11:42:55 -0700 | [diff] [blame] | 1555 | batch.end = fence->bo.map + fence->bo.size; |
Jason Ekstrand | 5001852 | 2016-04-18 17:03:00 -0700 | [diff] [blame] | 1556 | anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END, bbe); |
| 1557 | anv_batch_emit(&batch, GEN7_MI_NOOP, noop); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1558 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 1559 | if (!device->info.has_llc) { |
Jason Ekstrand | 2308891 | 2016-03-07 13:45:25 -0800 | [diff] [blame] | 1560 | assert(((uintptr_t) batch.start & CACHELINE_MASK) == 0); |
| 1561 | assert(batch.next - batch.start <= CACHELINE_SIZE); |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1562 | __builtin_ia32_mfence(); |
Jason Ekstrand | abaa3be | 2016-03-15 15:24:24 -0700 | [diff] [blame] | 1563 | __builtin_ia32_clflush(batch.start); |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1566 | fence->exec2_objects[0].handle = fence->bo.gem_handle; |
| 1567 | fence->exec2_objects[0].relocation_count = 0; |
| 1568 | fence->exec2_objects[0].relocs_ptr = 0; |
| 1569 | fence->exec2_objects[0].alignment = 0; |
| 1570 | fence->exec2_objects[0].offset = fence->bo.offset; |
| 1571 | fence->exec2_objects[0].flags = 0; |
| 1572 | fence->exec2_objects[0].rsvd1 = 0; |
| 1573 | fence->exec2_objects[0].rsvd2 = 0; |
| 1574 | |
| 1575 | fence->execbuf.buffers_ptr = (uintptr_t) fence->exec2_objects; |
| 1576 | fence->execbuf.buffer_count = 1; |
Jason Ekstrand | 2308891 | 2016-03-07 13:45:25 -0800 | [diff] [blame] | 1577 | fence->execbuf.batch_start_offset = batch.start - fence->bo.map; |
| 1578 | fence->execbuf.batch_len = batch.next - batch.start; |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1579 | fence->execbuf.cliprects_ptr = 0; |
| 1580 | fence->execbuf.num_cliprects = 0; |
| 1581 | fence->execbuf.DR1 = 0; |
| 1582 | fence->execbuf.DR4 = 0; |
| 1583 | |
| 1584 | fence->execbuf.flags = |
| 1585 | I915_EXEC_HANDLE_LUT | I915_EXEC_NO_RELOC | I915_EXEC_RENDER; |
| 1586 | fence->execbuf.rsvd1 = device->context_id; |
| 1587 | fence->execbuf.rsvd2 = 0; |
| 1588 | |
Jason Ekstrand | 1c97432 | 2016-11-10 21:46:13 -0800 | [diff] [blame] | 1589 | if (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) { |
| 1590 | fence->state = ANV_FENCE_STATE_SIGNALED; |
| 1591 | } else { |
| 1592 | fence->state = ANV_FENCE_STATE_RESET; |
| 1593 | } |
Jason Ekstrand | 0d2145b | 2016-02-02 12:22:00 -0800 | [diff] [blame] | 1594 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1595 | *pFence = anv_fence_to_handle(fence); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1596 | |
| 1597 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1600 | void anv_DestroyFence( |
Chad Versace | ebb191f | 2015-07-14 09:29:35 -0700 | [diff] [blame] | 1601 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1602 | VkFence _fence, |
| 1603 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | ebb191f | 2015-07-14 09:29:35 -0700 | [diff] [blame] | 1604 | { |
| 1605 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1606 | ANV_FROM_HANDLE(anv_fence, fence, _fence); |
| 1607 | |
Jason Ekstrand | 49f08ad | 2016-11-10 21:32:32 -0800 | [diff] [blame] | 1608 | if (!fence) |
| 1609 | return; |
| 1610 | |
Jason Ekstrand | 2308891 | 2016-03-07 13:45:25 -0800 | [diff] [blame] | 1611 | assert(fence->bo.map == fence); |
Jason Ekstrand | 23de787 | 2016-03-06 14:16:51 -0800 | [diff] [blame] | 1612 | anv_bo_pool_free(&device->batch_bo_pool, &fence->bo); |
Chad Versace | ebb191f | 2015-07-14 09:29:35 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1615 | VkResult anv_ResetFences( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1616 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1617 | uint32_t fenceCount, |
Jason Ekstrand | d5349b1 | 2015-07-07 17:18:00 -0700 | [diff] [blame] | 1618 | const VkFence* pFences) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1619 | { |
Chad Versace | 169251b | 2015-07-17 13:59:48 -0700 | [diff] [blame] | 1620 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 1621 | ANV_FROM_HANDLE(anv_fence, fence, pFences[i]); |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1622 | fence->state = ANV_FENCE_STATE_RESET; |
Chad Versace | 169251b | 2015-07-17 13:59:48 -0700 | [diff] [blame] | 1623 | } |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1624 | |
| 1625 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1628 | VkResult anv_GetFenceStatus( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1629 | VkDevice _device, |
| 1630 | VkFence _fence) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1631 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1632 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1633 | ANV_FROM_HANDLE(anv_fence, fence, _fence); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1634 | int64_t t = 0; |
| 1635 | int ret; |
| 1636 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1637 | switch (fence->state) { |
| 1638 | case ANV_FENCE_STATE_RESET: |
| 1639 | /* If it hasn't even been sent off to the GPU yet, it's not ready */ |
| 1640 | return VK_NOT_READY; |
| 1641 | |
| 1642 | case ANV_FENCE_STATE_SIGNALED: |
| 1643 | /* It's been signaled, return success */ |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1644 | return VK_SUCCESS; |
| 1645 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1646 | case ANV_FENCE_STATE_SUBMITTED: |
| 1647 | /* It's been submitted to the GPU but we don't know if it's done yet. */ |
| 1648 | ret = anv_gem_wait(device, fence->bo.gem_handle, &t); |
| 1649 | if (ret == 0) { |
| 1650 | fence->state = ANV_FENCE_STATE_SIGNALED; |
| 1651 | return VK_SUCCESS; |
| 1652 | } else { |
| 1653 | return VK_NOT_READY; |
| 1654 | } |
| 1655 | default: |
| 1656 | unreachable("Invalid fence status"); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1657 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1660 | #define NSEC_PER_SEC 1000000000 |
| 1661 | #define INT_TYPE_MAX(type) ((1ull << (sizeof(type) * 8 - 1)) - 1) |
| 1662 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1663 | VkResult anv_WaitForFences( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1664 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1665 | uint32_t fenceCount, |
| 1666 | const VkFence* pFences, |
Chad Versace | 8f3b218 | 2015-07-13 12:59:42 -0700 | [diff] [blame] | 1667 | VkBool32 waitAll, |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1668 | uint64_t _timeout) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1669 | { |
Jason Ekstrand | c8577b5 | 2015-07-08 14:24:12 -0700 | [diff] [blame] | 1670 | ANV_FROM_HANDLE(anv_device, device, _device); |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1671 | int ret; |
Jason Ekstrand | aafc874 | 2015-11-10 11:24:08 -0800 | [diff] [blame] | 1672 | |
| 1673 | /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed |
| 1674 | * to block indefinitely timeouts <= 0. Unfortunately, this was broken |
| 1675 | * for a couple of kernel releases. Since there's no way to know |
| 1676 | * whether or not the kernel we're using is one of the broken ones, the |
| 1677 | * best we can do is to clamp the timeout to INT64_MAX. This limits the |
| 1678 | * maximum timeout from 584 years to 292 years - likely not a big deal. |
| 1679 | */ |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1680 | int64_t timeout = MIN2(_timeout, INT64_MAX); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1681 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1682 | uint32_t pending_fences = fenceCount; |
| 1683 | while (pending_fences) { |
| 1684 | pending_fences = 0; |
| 1685 | bool signaled_fences = false; |
| 1686 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 1687 | ANV_FROM_HANDLE(anv_fence, fence, pFences[i]); |
| 1688 | switch (fence->state) { |
| 1689 | case ANV_FENCE_STATE_RESET: |
| 1690 | /* This fence hasn't been submitted yet, we'll catch it the next |
| 1691 | * time around. Yes, this may mean we dead-loop but, short of |
| 1692 | * lots of locking and a condition variable, there's not much that |
| 1693 | * we can do about that. |
| 1694 | */ |
| 1695 | pending_fences++; |
| 1696 | continue; |
Jason Ekstrand | 427978d | 2015-11-10 15:02:52 -0800 | [diff] [blame] | 1697 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1698 | case ANV_FENCE_STATE_SIGNALED: |
| 1699 | /* This fence is not pending. If waitAll isn't set, we can return |
| 1700 | * early. Otherwise, we have to keep going. |
| 1701 | */ |
| 1702 | if (!waitAll) |
| 1703 | return VK_SUCCESS; |
| 1704 | continue; |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1705 | |
Jason Ekstrand | 843775b | 2016-11-02 09:11:11 -0700 | [diff] [blame] | 1706 | case ANV_FENCE_STATE_SUBMITTED: |
| 1707 | /* These are the fences we really care about. Go ahead and wait |
| 1708 | * on it until we hit a timeout. |
| 1709 | */ |
| 1710 | ret = anv_gem_wait(device, fence->bo.gem_handle, &timeout); |
| 1711 | if (ret == -1 && errno == ETIME) { |
| 1712 | return VK_TIMEOUT; |
| 1713 | } else if (ret == -1) { |
| 1714 | /* We don't know the real error. */ |
| 1715 | return vk_errorf(VK_ERROR_DEVICE_LOST, "gem wait failed: %m"); |
| 1716 | } else { |
| 1717 | fence->state = ANV_FENCE_STATE_SIGNALED; |
| 1718 | signaled_fences = true; |
| 1719 | if (!waitAll) |
| 1720 | return VK_SUCCESS; |
| 1721 | continue; |
| 1722 | } |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | if (pending_fences && !signaled_fences) { |
| 1727 | /* If we've hit this then someone decided to vkWaitForFences before |
| 1728 | * they've actually submitted any of them to a queue. This is a |
| 1729 | * fairly pessimal case, so it's ok to lock here and use a standard |
| 1730 | * pthreads condition variable. |
| 1731 | */ |
| 1732 | pthread_mutex_lock(&device->mutex); |
| 1733 | |
| 1734 | /* It's possible that some of the fences have changed state since the |
| 1735 | * last time we checked. Now that we have the lock, check for |
| 1736 | * pending fences again and don't wait if it's changed. |
| 1737 | */ |
| 1738 | uint32_t now_pending_fences = 0; |
| 1739 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 1740 | ANV_FROM_HANDLE(anv_fence, fence, pFences[i]); |
| 1741 | if (fence->state == ANV_FENCE_STATE_RESET) |
| 1742 | now_pending_fences++; |
| 1743 | } |
| 1744 | assert(now_pending_fences <= pending_fences); |
| 1745 | |
| 1746 | if (now_pending_fences == pending_fences) { |
| 1747 | struct timespec before; |
| 1748 | clock_gettime(CLOCK_MONOTONIC, &before); |
| 1749 | |
| 1750 | uint32_t abs_nsec = before.tv_nsec + timeout % NSEC_PER_SEC; |
| 1751 | uint64_t abs_sec = before.tv_sec + (abs_nsec / NSEC_PER_SEC) + |
| 1752 | (timeout / NSEC_PER_SEC); |
| 1753 | abs_nsec %= NSEC_PER_SEC; |
| 1754 | |
| 1755 | /* Avoid roll-over in tv_sec on 32-bit systems if the user |
| 1756 | * provided timeout is UINT64_MAX |
| 1757 | */ |
| 1758 | struct timespec abstime; |
| 1759 | abstime.tv_nsec = abs_nsec; |
| 1760 | abstime.tv_sec = MIN2(abs_sec, INT_TYPE_MAX(abstime.tv_sec)); |
| 1761 | |
| 1762 | ret = pthread_cond_timedwait(&device->queue_submit, |
| 1763 | &device->mutex, &abstime); |
| 1764 | assert(ret != EINVAL); |
| 1765 | |
| 1766 | struct timespec after; |
| 1767 | clock_gettime(CLOCK_MONOTONIC, &after); |
| 1768 | uint64_t time_elapsed = |
| 1769 | ((uint64_t)after.tv_sec * NSEC_PER_SEC + after.tv_nsec) - |
| 1770 | ((uint64_t)before.tv_sec * NSEC_PER_SEC + before.tv_nsec); |
| 1771 | |
| 1772 | if (time_elapsed >= timeout) { |
| 1773 | pthread_mutex_unlock(&device->mutex); |
| 1774 | return VK_TIMEOUT; |
| 1775 | } |
| 1776 | |
| 1777 | timeout -= time_elapsed; |
| 1778 | } |
| 1779 | |
| 1780 | pthread_mutex_unlock(&device->mutex); |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1781 | } |
Jason Ekstrand | 5c49730 | 2015-07-09 18:20:28 -0700 | [diff] [blame] | 1782 | } |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1783 | |
| 1784 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | // Queue semaphore functions |
| 1788 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1789 | VkResult anv_CreateSemaphore( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1790 | VkDevice device, |
| 1791 | const VkSemaphoreCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1792 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1793 | VkSemaphore* pSemaphore) |
| 1794 | { |
Kristian Høgsberg Kristensen | a00524a | 2015-12-20 22:58:38 -0800 | [diff] [blame] | 1795 | /* The DRM execbuffer ioctl always execute in-oder, even between different |
| 1796 | * rings. As such, there's nothing to do for the user space semaphore. |
| 1797 | */ |
| 1798 | |
Jason Ekstrand | 3db43e8 | 2015-11-30 10:31:44 -0800 | [diff] [blame] | 1799 | *pSemaphore = (VkSemaphore)1; |
Kristian Høgsberg Kristensen | a00524a | 2015-12-20 22:58:38 -0800 | [diff] [blame] | 1800 | |
| 1801 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1804 | void anv_DestroySemaphore( |
Chad Versace | 549070b | 2015-07-14 09:31:34 -0700 | [diff] [blame] | 1805 | VkDevice device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1806 | VkSemaphore semaphore, |
| 1807 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | 549070b | 2015-07-14 09:31:34 -0700 | [diff] [blame] | 1808 | { |
Chad Versace | 549070b | 2015-07-14 09:31:34 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1811 | // Event functions |
| 1812 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1813 | VkResult anv_CreateEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1814 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1815 | const VkEventCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1816 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1817 | VkEvent* pEvent) |
| 1818 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1819 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1820 | struct anv_state state; |
| 1821 | struct anv_event *event; |
| 1822 | |
| 1823 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO); |
| 1824 | |
| 1825 | state = anv_state_pool_alloc(&device->dynamic_state_pool, |
Jason Ekstrand | 25b09d1 | 2016-02-11 18:57:37 -0800 | [diff] [blame] | 1826 | sizeof(*event), 8); |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1827 | event = state.map; |
| 1828 | event->state = state; |
| 1829 | event->semaphore = VK_EVENT_RESET; |
| 1830 | |
| 1831 | if (!device->info.has_llc) { |
| 1832 | /* Make sure the writes we're flushing have landed. */ |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1833 | __builtin_ia32_mfence(); |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1834 | __builtin_ia32_clflush(event); |
| 1835 | } |
| 1836 | |
| 1837 | *pEvent = anv_event_to_handle(event); |
| 1838 | |
| 1839 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1842 | void anv_DestroyEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1843 | VkDevice _device, |
| 1844 | VkEvent _event, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1845 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | 68c7ef5 | 2015-07-14 09:33:47 -0700 | [diff] [blame] | 1846 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1847 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1848 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1849 | |
Jason Ekstrand | 49f08ad | 2016-11-10 21:32:32 -0800 | [diff] [blame] | 1850 | if (!event) |
| 1851 | return; |
| 1852 | |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1853 | anv_state_pool_free(&device->dynamic_state_pool, event->state); |
Chad Versace | 68c7ef5 | 2015-07-14 09:33:47 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1856 | VkResult anv_GetEventStatus( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1857 | VkDevice _device, |
| 1858 | VkEvent _event) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1859 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1860 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1861 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1862 | |
| 1863 | if (!device->info.has_llc) { |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1864 | /* Invalidate read cache before reading event written by GPU. */ |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1865 | __builtin_ia32_clflush(event); |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1866 | __builtin_ia32_mfence(); |
| 1867 | |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | return event->semaphore; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1873 | VkResult anv_SetEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1874 | VkDevice _device, |
| 1875 | VkEvent _event) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1876 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1877 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1878 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1879 | |
| 1880 | event->semaphore = VK_EVENT_SET; |
| 1881 | |
| 1882 | if (!device->info.has_llc) { |
| 1883 | /* Make sure the writes we're flushing have landed. */ |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1884 | __builtin_ia32_mfence(); |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1885 | __builtin_ia32_clflush(event); |
| 1886 | } |
| 1887 | |
| 1888 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1891 | VkResult anv_ResetEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1892 | VkDevice _device, |
| 1893 | VkEvent _event) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1894 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1895 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1896 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1897 | |
| 1898 | event->semaphore = VK_EVENT_RESET; |
| 1899 | |
| 1900 | if (!device->info.has_llc) { |
| 1901 | /* Make sure the writes we're flushing have landed. */ |
Kristian Høgsberg Kristensen | 0c4ef36 | 2016-01-29 12:10:12 -0800 | [diff] [blame] | 1902 | __builtin_ia32_mfence(); |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1903 | __builtin_ia32_clflush(event); |
| 1904 | } |
| 1905 | |
| 1906 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1909 | // Buffer functions |
| 1910 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1911 | VkResult anv_CreateBuffer( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1912 | VkDevice _device, |
| 1913 | const VkBufferCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1914 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1915 | VkBuffer* pBuffer) |
| 1916 | { |
Jason Ekstrand | c8577b5 | 2015-07-08 14:24:12 -0700 | [diff] [blame] | 1917 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1918 | struct anv_buffer *buffer; |
| 1919 | |
| 1920 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO); |
| 1921 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1922 | buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1923 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1924 | if (buffer == NULL) |
| 1925 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1926 | |
| 1927 | buffer->size = pCreateInfo->size; |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 1928 | buffer->usage = pCreateInfo->usage; |
Kristian Høgsberg | 099faa1 | 2015-05-11 22:19:58 -0700 | [diff] [blame] | 1929 | buffer->bo = NULL; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1930 | buffer->offset = 0; |
| 1931 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1932 | *pBuffer = anv_buffer_to_handle(buffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1933 | |
| 1934 | return VK_SUCCESS; |
| 1935 | } |
| 1936 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1937 | void anv_DestroyBuffer( |
Chad Versace | e93b6d8 | 2015-07-14 09:47:45 -0700 | [diff] [blame] | 1938 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1939 | VkBuffer _buffer, |
| 1940 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | e93b6d8 | 2015-07-14 09:47:45 -0700 | [diff] [blame] | 1941 | { |
| 1942 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1943 | ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); |
| 1944 | |
Jason Ekstrand | 49f08ad | 2016-11-10 21:32:32 -0800 | [diff] [blame] | 1945 | if (!buffer) |
| 1946 | return; |
| 1947 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1948 | vk_free2(&device->alloc, pAllocator, buffer); |
Chad Versace | e93b6d8 | 2015-07-14 09:47:45 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1951 | void |
Francisco Jerez | 6840cc1 | 2016-01-26 14:50:52 -0800 | [diff] [blame] | 1952 | anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state, |
Jason Ekstrand | 1f98bf8 | 2015-12-14 16:14:20 -0800 | [diff] [blame] | 1953 | enum isl_format format, |
Jason Ekstrand | 399d531 | 2015-11-06 15:14:10 -0800 | [diff] [blame] | 1954 | uint32_t offset, uint32_t range, uint32_t stride) |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1955 | { |
Jason Ekstrand | eb19d64 | 2016-02-22 16:54:25 -0800 | [diff] [blame] | 1956 | isl_buffer_fill_state(&device->isl_dev, state.map, |
| 1957 | .address = offset, |
| 1958 | .mocs = device->default_mocs, |
| 1959 | .size = range, |
| 1960 | .format = format, |
| 1961 | .stride = stride); |
Francisco Jerez | 6840cc1 | 2016-01-26 14:50:52 -0800 | [diff] [blame] | 1962 | |
| 1963 | if (!device->info.has_llc) |
| 1964 | anv_state_clflush(state); |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1967 | void anv_DestroySampler( |
Chad Versace | ec5e2f4 | 2015-07-14 10:34:00 -0700 | [diff] [blame] | 1968 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1969 | VkSampler _sampler, |
| 1970 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | ec5e2f4 | 2015-07-14 10:34:00 -0700 | [diff] [blame] | 1971 | { |
| 1972 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1973 | ANV_FROM_HANDLE(anv_sampler, sampler, _sampler); |
| 1974 | |
Jason Ekstrand | 49f08ad | 2016-11-10 21:32:32 -0800 | [diff] [blame] | 1975 | if (!sampler) |
| 1976 | return; |
| 1977 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1978 | vk_free2(&device->alloc, pAllocator, sampler); |
Chad Versace | ec5e2f4 | 2015-07-14 10:34:00 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1981 | VkResult anv_CreateFramebuffer( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1982 | VkDevice _device, |
| 1983 | const VkFramebufferCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1984 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1985 | VkFramebuffer* pFramebuffer) |
| 1986 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1987 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1988 | struct anv_framebuffer *framebuffer; |
| 1989 | |
| 1990 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO); |
| 1991 | |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 1992 | size_t size = sizeof(*framebuffer) + |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 1993 | sizeof(struct anv_image_view *) * pCreateInfo->attachmentCount; |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 1994 | framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1995 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1996 | if (framebuffer == NULL) |
| 1997 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1998 | |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 1999 | framebuffer->attachment_count = pCreateInfo->attachmentCount; |
| 2000 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) { |
Chad Versace | 6dea1a9 | 2015-10-07 07:30:52 -0700 | [diff] [blame] | 2001 | VkImageView _iview = pCreateInfo->pAttachments[i]; |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 2002 | framebuffer->attachments[i] = anv_image_view_from_handle(_iview); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 2005 | framebuffer->width = pCreateInfo->width; |
| 2006 | framebuffer->height = pCreateInfo->height; |
| 2007 | framebuffer->layers = pCreateInfo->layers; |
| 2008 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 2009 | *pFramebuffer = anv_framebuffer_to_handle(framebuffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 2010 | |
| 2011 | return VK_SUCCESS; |
| 2012 | } |
| 2013 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 2014 | void anv_DestroyFramebuffer( |
Chad Versace | 08f7731 | 2015-07-14 10:59:30 -0700 | [diff] [blame] | 2015 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 2016 | VkFramebuffer _fb, |
| 2017 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | 08f7731 | 2015-07-14 10:59:30 -0700 | [diff] [blame] | 2018 | { |
| 2019 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 2020 | ANV_FROM_HANDLE(anv_framebuffer, fb, _fb); |
| 2021 | |
Jason Ekstrand | 49f08ad | 2016-11-10 21:32:32 -0800 | [diff] [blame] | 2022 | if (!fb) |
| 2023 | return; |
| 2024 | |
Dave Airlie | 1ae6ece | 2016-10-14 13:31:35 +1000 | [diff] [blame] | 2025 | vk_free2(&device->alloc, pAllocator, fb); |
Chad Versace | 08f7731 | 2015-07-14 10:59:30 -0700 | [diff] [blame] | 2026 | } |