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