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 | |
| 24 | #include <assert.h> |
| 25 | #include <stdbool.h> |
| 26 | #include <string.h> |
| 27 | #include <unistd.h> |
| 28 | #include <fcntl.h> |
| 29 | |
Chad Versace | 2c2233e | 2015-07-17 15:04:27 -0700 | [diff] [blame] | 30 | #include "anv_private.h" |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 31 | #include "mesa/main/git_sha1.h" |
Jason Ekstrand | 6a7ca4e | 2015-08-14 17:25:04 -0700 | [diff] [blame] | 32 | #include "util/strtod.h" |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 33 | |
Jason Ekstrand | de54b4b | 2015-11-16 12:29:07 -0800 | [diff] [blame] | 34 | #include "gen7_pack.h" |
| 35 | |
Jason Ekstrand | a95f51c | 2015-09-24 14:20:35 -0700 | [diff] [blame] | 36 | struct anv_dispatch_table dtable; |
| 37 | |
Jason Ekstrand | a71e614 | 2015-10-19 22:06:59 -0700 | [diff] [blame] | 38 | static void |
| 39 | compiler_debug_log(void *data, const char *fmt, ...) |
| 40 | { } |
| 41 | |
| 42 | static void |
| 43 | compiler_perf_log(void *data, const char *fmt, ...) |
| 44 | { |
| 45 | va_list args; |
| 46 | va_start(args, fmt); |
| 47 | |
| 48 | if (unlikely(INTEL_DEBUG & DEBUG_PERF)) |
| 49 | vfprintf(stderr, fmt, args); |
| 50 | |
| 51 | va_end(args); |
| 52 | } |
| 53 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 54 | static VkResult |
Chad Versace | 4422bd4 | 2015-07-09 16:22:18 -0700 | [diff] [blame] | 55 | anv_physical_device_init(struct anv_physical_device *device, |
| 56 | struct anv_instance *instance, |
| 57 | const char *path) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 58 | { |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 59 | VkResult result; |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 60 | int fd; |
| 61 | |
| 62 | fd = open(path, O_RDWR | O_CLOEXEC); |
| 63 | if (fd < 0) |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 64 | return vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 65 | "failed to open %s: %m", path); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 66 | |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 67 | device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 68 | device->instance = instance; |
| 69 | device->path = path; |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 70 | |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 71 | 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] | 72 | if (!device->chipset_id) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 73 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 74 | "failed to get chipset id: %m"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 75 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 76 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 77 | |
| 78 | device->name = brw_get_device_name(device->chipset_id); |
Jason Ekstrand | b00e3f2 | 2015-11-03 15:45:04 -0800 | [diff] [blame] | 79 | device->info = brw_get_device_info(device->chipset_id); |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 80 | if (!device->info) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 81 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 82 | "failed to get device info"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 83 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 84 | } |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 85 | |
Jason Ekstrand | f0390bc | 2015-11-17 07:07:02 -0800 | [diff] [blame] | 86 | if (device->info->is_haswell) { |
| 87 | fprintf(stderr, "WARNING: Haswell Vulkan support is incomplete\n"); |
| 88 | } else if (device->info->gen == 7 && !device->info->is_baytrail) { |
Jason Ekstrand | 862da6a | 2015-11-09 12:18:12 -0800 | [diff] [blame] | 89 | fprintf(stderr, "WARNING: Ivy Bridge Vulkan support is incomplete\n"); |
Kristian Høgsberg | dac5775 | 2015-12-01 15:39:30 -0800 | [diff] [blame] | 90 | } else if (device->info->gen == 7 && device->info->is_baytrail) { |
| 91 | fprintf(stderr, "WARNING: Bay Trail Vulkan support is incomplete\n"); |
| 92 | } else if (device->info->gen == 9 && !device->info->is_broxton) { |
Kristian Høgsberg Kristensen | cd4721c | 2015-11-25 22:27:01 -0800 | [diff] [blame] | 93 | fprintf(stderr, "WARNING: Skylake Vulkan support is incomplete\n"); |
Kristian Høgsberg | dac5775 | 2015-12-01 15:39:30 -0800 | [diff] [blame] | 94 | } else if (device->info->gen == 9 && device->info->is_broxton) { |
| 95 | fprintf(stderr, "WARNING: Broxton Vulkan support is incomplete\n"); |
| 96 | } else if (device->info->gen == 8) { |
| 97 | /* Broadwell/Cherryview is as fully supported as anything */ |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 98 | } else { |
Jason Ekstrand | fed3586 | 2015-12-02 16:14:58 -0800 | [diff] [blame] | 99 | result = vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER, |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 100 | "Vulkan not yet supported on %s", device->name); |
| 101 | goto fail; |
| 102 | } |
| 103 | |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 104 | if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 105 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 106 | "failed to get aperture size: %m"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 107 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 108 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 109 | |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 110 | if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 111 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 112 | "kernel missing gem wait"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 113 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 114 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 115 | |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 116 | if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 117 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 118 | "kernel missing execbuf2"); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 119 | goto fail; |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 120 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 121 | |
Kristian Høgsberg Kristensen | 220ac93 | 2015-12-19 22:25:57 -0800 | [diff] [blame] | 122 | if (!device->info->has_llc && |
| 123 | anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) { |
Kristian Høgsberg Kristensen | bbb6875 | 2015-12-03 23:58:05 -0800 | [diff] [blame] | 124 | result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, |
| 125 | "kernel missing wc mmap"); |
| 126 | goto fail; |
| 127 | } |
| 128 | |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 129 | close(fd); |
| 130 | |
Jason Ekstrand | a71e614 | 2015-10-19 22:06:59 -0700 | [diff] [blame] | 131 | brw_process_intel_debug_variable(); |
| 132 | |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 133 | device->compiler = brw_compiler_create(NULL, device->info); |
| 134 | if (device->compiler == NULL) { |
| 135 | result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 136 | goto fail; |
| 137 | } |
Jason Ekstrand | a71e614 | 2015-10-19 22:06:59 -0700 | [diff] [blame] | 138 | device->compiler->shader_debug_log = compiler_debug_log; |
| 139 | device->compiler->shader_perf_log = compiler_perf_log; |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 140 | |
Chad Versace | 738eaa8 | 2015-11-13 11:12:46 -0800 | [diff] [blame] | 141 | isl_device_init(&device->isl_dev, device->info); |
Chad Versace | af39291 | 2015-11-13 10:12:51 -0800 | [diff] [blame] | 142 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 143 | return VK_SUCCESS; |
Chad Versace | 477383e | 2015-11-13 10:12:18 -0800 | [diff] [blame] | 144 | |
Chad Versace | 8cda3e9 | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 145 | fail: |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 146 | close(fd); |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 147 | return result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jason Ekstrand | 6fb4469 | 2015-10-19 20:21:45 -0700 | [diff] [blame] | 150 | static void |
| 151 | anv_physical_device_finish(struct anv_physical_device *device) |
| 152 | { |
| 153 | ralloc_free(device->compiler); |
| 154 | } |
| 155 | |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 156 | static const VkExtensionProperties global_extensions[] = { |
| 157 | { |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 158 | .extensionName = VK_KHR_SURFACE_EXTENSION_NAME, |
| 159 | .specVersion = 24, |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 160 | }, |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 161 | { |
| 162 | .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME, |
| 163 | .specVersion = 5, |
| 164 | }, |
| 165 | #ifdef HAVE_WAYLAND_PLATFORM |
| 166 | { |
| 167 | .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, |
| 168 | .specVersion = 4, |
| 169 | }, |
| 170 | #endif |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | static const VkExtensionProperties device_extensions[] = { |
| 174 | { |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 175 | .extensionName = VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
| 176 | .specVersion = 67, |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 177 | }, |
| 178 | }; |
| 179 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 180 | static void * |
| 181 | default_alloc_func(void *pUserData, size_t size, size_t align, |
| 182 | VkSystemAllocationScope allocationScope) |
| 183 | { |
| 184 | return malloc(size); |
| 185 | } |
| 186 | |
| 187 | static void * |
| 188 | default_realloc_func(void *pUserData, void *pOriginal, size_t size, |
| 189 | size_t align, VkSystemAllocationScope allocationScope) |
| 190 | { |
| 191 | return realloc(pOriginal, size); |
| 192 | } |
| 193 | |
| 194 | static void |
| 195 | default_free_func(void *pUserData, void *pMemory) |
| 196 | { |
| 197 | free(pMemory); |
| 198 | } |
| 199 | |
| 200 | static const VkAllocationCallbacks default_alloc = { |
| 201 | .pUserData = NULL, |
| 202 | .pfnAllocation = default_alloc_func, |
| 203 | .pfnReallocation = default_realloc_func, |
| 204 | .pfnFree = default_free_func, |
| 205 | }; |
| 206 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 207 | VkResult anv_CreateInstance( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 208 | const VkInstanceCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 209 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 210 | VkInstance* pInstance) |
| 211 | { |
| 212 | struct anv_instance *instance; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 213 | |
| 214 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); |
| 215 | |
Jason Ekstrand | d666487 | 2015-12-02 16:28:36 -0800 | [diff] [blame] | 216 | if (pCreateInfo->pApplicationInfo->apiVersion != VK_MAKE_VERSION(0, 210, 1)) |
Jason Ekstrand | e21ecb8 | 2015-10-12 18:25:19 -0700 | [diff] [blame] | 217 | return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER); |
| 218 | |
Jason Ekstrand | 9349625 | 2015-12-01 13:58:25 -0800 | [diff] [blame] | 219 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 220 | bool found = false; |
| 221 | for (uint32_t j = 0; j < ARRAY_SIZE(global_extensions); j++) { |
| 222 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 223 | global_extensions[j].extensionName) == 0) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 224 | found = true; |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | if (!found) |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 229 | return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 232 | instance = anv_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8, |
| 233 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 234 | if (!instance) |
| 235 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 236 | |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 237 | instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 238 | |
| 239 | if (pAllocator) |
| 240 | instance->alloc = *pAllocator; |
| 241 | else |
| 242 | instance->alloc = default_alloc; |
| 243 | |
Jason Ekstrand | 9349625 | 2015-12-01 13:58:25 -0800 | [diff] [blame] | 244 | instance->apiVersion = pCreateInfo->pApplicationInfo->apiVersion; |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 245 | instance->physicalDeviceCount = -1; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 246 | |
Jason Ekstrand | 6a7ca4e | 2015-08-14 17:25:04 -0700 | [diff] [blame] | 247 | _mesa_locale_init(); |
| 248 | |
Jason Ekstrand | 930598a | 2015-07-31 10:18:00 -0700 | [diff] [blame] | 249 | VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); |
| 250 | |
Jason Ekstrand | 348cb29 | 2015-09-04 11:14:45 -0700 | [diff] [blame] | 251 | anv_init_wsi(instance); |
| 252 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 253 | *pInstance = anv_instance_to_handle(instance); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 254 | |
| 255 | return VK_SUCCESS; |
| 256 | } |
| 257 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 258 | void anv_DestroyInstance( |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 259 | VkInstance _instance, |
| 260 | const VkAllocationCallbacks* pAllocator) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 261 | { |
Jason Ekstrand | 73f9187 | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 262 | ANV_FROM_HANDLE(anv_instance, instance, _instance); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 263 | |
Chad Versace | 0ab926d | 2015-10-21 11:36:39 -0700 | [diff] [blame] | 264 | if (instance->physicalDeviceCount > 0) { |
| 265 | /* We support at most one physical device. */ |
| 266 | assert(instance->physicalDeviceCount == 1); |
| 267 | anv_physical_device_finish(&instance->physicalDevice); |
| 268 | } |
| 269 | |
Jason Ekstrand | 348cb29 | 2015-09-04 11:14:45 -0700 | [diff] [blame] | 270 | anv_finish_wsi(instance); |
| 271 | |
Jason Ekstrand | 930598a | 2015-07-31 10:18:00 -0700 | [diff] [blame] | 272 | VG(VALGRIND_DESTROY_MEMPOOL(instance)); |
| 273 | |
Jason Ekstrand | 6a7ca4e | 2015-08-14 17:25:04 -0700 | [diff] [blame] | 274 | _mesa_locale_fini(); |
| 275 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 276 | anv_free(&instance->alloc, instance); |
Jason Ekstrand | e40bdce | 2015-07-31 10:13:24 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 279 | VkResult anv_EnumeratePhysicalDevices( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 280 | VkInstance _instance, |
| 281 | uint32_t* pPhysicalDeviceCount, |
| 282 | VkPhysicalDevice* pPhysicalDevices) |
| 283 | { |
Jason Ekstrand | 73f9187 | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 284 | ANV_FROM_HANDLE(anv_instance, instance, _instance); |
Chad Versace | fa915b6 | 2015-07-09 15:38:58 -0700 | [diff] [blame] | 285 | VkResult result; |
| 286 | |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 287 | if (instance->physicalDeviceCount < 0) { |
Chad Versace | 4422bd4 | 2015-07-09 16:22:18 -0700 | [diff] [blame] | 288 | result = anv_physical_device_init(&instance->physicalDevice, |
| 289 | instance, "/dev/dri/renderD128"); |
Jason Ekstrand | fed3586 | 2015-12-02 16:14:58 -0800 | [diff] [blame] | 290 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 291 | instance->physicalDeviceCount = 0; |
| 292 | } else if (result == VK_SUCCESS) { |
| 293 | instance->physicalDeviceCount = 1; |
| 294 | } else { |
Chad Versace | fa915b6 | 2015-07-09 15:38:58 -0700 | [diff] [blame] | 295 | return result; |
Jason Ekstrand | 584f9d4 | 2015-11-02 12:14:37 -0800 | [diff] [blame] | 296 | } |
Chad Versace | fa915b6 | 2015-07-09 15:38:58 -0700 | [diff] [blame] | 297 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 298 | |
Chad Versace | 5b75dff | 2015-07-09 15:51:06 -0700 | [diff] [blame] | 299 | /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL; |
| 300 | * otherwise it's an inout parameter. |
| 301 | * |
| 302 | * The Vulkan spec (git aaed022) says: |
| 303 | * |
| 304 | * pPhysicalDeviceCount is a pointer to an unsigned integer variable |
| 305 | * that is initialized with the number of devices the application is |
| 306 | * prepared to receive handles to. pname:pPhysicalDevices is pointer to |
| 307 | * an array of at least this many VkPhysicalDevice handles [...]. |
| 308 | * |
| 309 | * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices |
| 310 | * overwrites the contents of the variable pointed to by |
| 311 | * pPhysicalDeviceCount with the number of physical devices in in the |
| 312 | * instance; otherwise, vkEnumeratePhysicalDevices overwrites |
| 313 | * pPhysicalDeviceCount with the number of physical handles written to |
| 314 | * pPhysicalDevices. |
| 315 | */ |
| 316 | if (!pPhysicalDevices) { |
| 317 | *pPhysicalDeviceCount = instance->physicalDeviceCount; |
| 318 | } else if (*pPhysicalDeviceCount >= 1) { |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 319 | pPhysicalDevices[0] = anv_physical_device_to_handle(&instance->physicalDevice); |
Chad Versace | 5b75dff | 2015-07-09 15:51:06 -0700 | [diff] [blame] | 320 | *pPhysicalDeviceCount = 1; |
| 321 | } else { |
| 322 | *pPhysicalDeviceCount = 0; |
| 323 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 324 | |
| 325 | return VK_SUCCESS; |
| 326 | } |
| 327 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 328 | void anv_GetPhysicalDeviceFeatures( |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 329 | VkPhysicalDevice physicalDevice, |
| 330 | VkPhysicalDeviceFeatures* pFeatures) |
| 331 | { |
| 332 | anv_finishme("Get correct values for PhysicalDeviceFeatures"); |
| 333 | |
| 334 | *pFeatures = (VkPhysicalDeviceFeatures) { |
| 335 | .robustBufferAccess = false, |
| 336 | .fullDrawIndexUint32 = false, |
| 337 | .imageCubeArray = false, |
| 338 | .independentBlend = false, |
| 339 | .geometryShader = true, |
| 340 | .tessellationShader = false, |
| 341 | .sampleRateShading = false, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 342 | .dualSrcBlend = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 343 | .logicOp = true, |
Chad Versace | 545f5cc | 2015-10-07 10:05:02 -0700 | [diff] [blame] | 344 | .multiDrawIndirect = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 345 | .depthClamp = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 346 | .depthBiasClamp = false, |
| 347 | .fillModeNonSolid = true, |
| 348 | .depthBounds = false, |
| 349 | .wideLines = true, |
| 350 | .largePoints = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 351 | .alphaToOne = true, |
| 352 | .multiViewport = true, |
| 353 | .samplerAnisotropy = false, /* FINISHME */ |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 354 | .textureCompressionETC2 = true, |
| 355 | .textureCompressionASTC_LDR = true, |
| 356 | .textureCompressionBC = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 357 | .occlusionQueryPrecise = false, /* FINISHME */ |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 358 | .pipelineStatisticsQuery = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 359 | .vertexPipelineStoresAndAtomics = false, |
| 360 | .fragmentStoresAndAtomics = true, |
| 361 | .shaderTessellationAndGeometryPointSize = true, |
Chad Versace | 545f5cc | 2015-10-07 10:05:02 -0700 | [diff] [blame] | 362 | .shaderImageGatherExtended = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 363 | .shaderStorageImageExtendedFormats = false, |
| 364 | .shaderStorageImageMultisample = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 365 | .shaderUniformBufferArrayDynamicIndexing = true, |
| 366 | .shaderSampledImageArrayDynamicIndexing = false, |
| 367 | .shaderStorageBufferArrayDynamicIndexing = false, |
| 368 | .shaderStorageImageArrayDynamicIndexing = false, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 369 | .shaderStorageImageReadWithoutFormat = false, |
| 370 | .shaderStorageImageWriteWithoutFormat = true, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 371 | .shaderClipDistance = false, |
| 372 | .shaderCullDistance = false, |
| 373 | .shaderFloat64 = false, |
| 374 | .shaderInt64 = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 375 | .shaderInt16 = false, |
Chad Versace | 545f5cc | 2015-10-07 10:05:02 -0700 | [diff] [blame] | 376 | .alphaToOne = true, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 377 | .variableMultisampleRate = false, |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 378 | }; |
Jason Ekstrand | f6d51f3 | 2015-07-09 13:54:08 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 381 | void anv_GetPhysicalDeviceProperties( |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 382 | VkPhysicalDevice physicalDevice, |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 383 | VkPhysicalDeviceProperties* pProperties) |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 384 | { |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 385 | ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice); |
| 386 | const struct brw_device_info *devinfo = pdevice->info; |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 387 | |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 388 | anv_finishme("Get correct values for VkPhysicalDeviceLimits"); |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 389 | |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 390 | VkSampleCountFlags sample_counts = |
| 391 | VK_SAMPLE_COUNT_1_BIT | |
| 392 | VK_SAMPLE_COUNT_2_BIT | |
| 393 | VK_SAMPLE_COUNT_4_BIT | |
| 394 | VK_SAMPLE_COUNT_8_BIT; |
| 395 | |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 396 | VkPhysicalDeviceLimits limits = { |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 397 | .maxImageDimension1D = (1 << 14), |
| 398 | .maxImageDimension2D = (1 << 14), |
| 399 | .maxImageDimension3D = (1 << 10), |
| 400 | .maxImageDimensionCube = (1 << 14), |
| 401 | .maxImageArrayLayers = (1 << 10), |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 402 | .maxTexelBufferElements = (1 << 14), |
| 403 | .maxUniformBufferRange = UINT32_MAX, |
| 404 | .maxStorageBufferRange = UINT32_MAX, |
Jason Ekstrand | 5446bf3 | 2015-08-26 15:01:38 -0700 | [diff] [blame] | 405 | .maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 406 | .maxMemoryAllocationCount = UINT32_MAX, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 407 | .maxSamplerAllocationCount = UINT32_MAX, |
Jason Ekstrand | e5db209 | 2015-07-14 17:10:37 -0700 | [diff] [blame] | 408 | .bufferImageGranularity = 64, /* A cache line */ |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 409 | .sparseAddressSpaceSize = 0, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 410 | .maxBoundDescriptorSets = MAX_SETS, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 411 | .maxPerStageDescriptorSamplers = 64, |
| 412 | .maxPerStageDescriptorUniformBuffers = 64, |
| 413 | .maxPerStageDescriptorStorageBuffers = 64, |
| 414 | .maxPerStageDescriptorSampledImages = 64, |
| 415 | .maxPerStageDescriptorStorageImages = 64, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 416 | .maxPerStageDescriptorInputAttachments = 64, |
| 417 | .maxPerStageResources = 128, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 418 | .maxDescriptorSetSamplers = 256, |
| 419 | .maxDescriptorSetUniformBuffers = 256, |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 420 | .maxDescriptorSetUniformBuffersDynamic = 256, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 421 | .maxDescriptorSetStorageBuffers = 256, |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 422 | .maxDescriptorSetStorageBuffersDynamic = 256, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 423 | .maxDescriptorSetSampledImages = 256, |
| 424 | .maxDescriptorSetStorageImages = 256, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 425 | .maxDescriptorSetInputAttachments = 256, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 426 | .maxVertexInputAttributes = 32, |
Chad Versace | 033a37f | 2015-10-07 09:57:51 -0700 | [diff] [blame] | 427 | .maxVertexInputBindings = 32, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 428 | .maxVertexInputAttributeOffset = 256, |
| 429 | .maxVertexInputBindingStride = 256, |
| 430 | .maxVertexOutputComponents = 32, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 431 | .maxTessellationGenerationLevel = 0, |
| 432 | .maxTessellationPatchSize = 0, |
| 433 | .maxTessellationControlPerVertexInputComponents = 0, |
| 434 | .maxTessellationControlPerVertexOutputComponents = 0, |
| 435 | .maxTessellationControlPerPatchOutputComponents = 0, |
| 436 | .maxTessellationControlTotalOutputComponents = 0, |
| 437 | .maxTessellationEvaluationInputComponents = 0, |
| 438 | .maxTessellationEvaluationOutputComponents = 0, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 439 | .maxGeometryShaderInvocations = 6, |
| 440 | .maxGeometryInputComponents = 16, |
| 441 | .maxGeometryOutputComponents = 16, |
| 442 | .maxGeometryOutputVertices = 16, |
| 443 | .maxGeometryTotalOutputComponents = 16, |
| 444 | .maxFragmentInputComponents = 16, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 445 | .maxFragmentOutputAttachments = 8, |
| 446 | .maxFragmentDualSrcAttachments = 2, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 447 | .maxFragmentCombinedOutputResources = 8, |
| 448 | .maxComputeSharedMemorySize = 1024, |
| 449 | .maxComputeWorkGroupCount = { |
| 450 | 16 * devinfo->max_cs_threads, |
| 451 | 16 * devinfo->max_cs_threads, |
| 452 | 16 * devinfo->max_cs_threads, |
| 453 | }, |
| 454 | .maxComputeWorkGroupInvocations = 16 * devinfo->max_cs_threads, |
| 455 | .maxComputeWorkGroupSize = { |
| 456 | 16 * devinfo->max_cs_threads, |
| 457 | 16 * devinfo->max_cs_threads, |
| 458 | 16 * devinfo->max_cs_threads, |
| 459 | }, |
| 460 | .subPixelPrecisionBits = 4 /* FIXME */, |
| 461 | .subTexelPrecisionBits = 4 /* FIXME */, |
| 462 | .mipmapPrecisionBits = 4 /* FIXME */, |
| 463 | .maxDrawIndexedIndexValue = UINT32_MAX, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 464 | .maxDrawIndirectCount = UINT32_MAX, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 465 | .maxSamplerLodBias = 16, |
| 466 | .maxSamplerAnisotropy = 16, |
Jason Ekstrand | daf68a9 | 2015-10-06 17:21:44 -0700 | [diff] [blame] | 467 | .maxViewports = MAX_VIEWPORTS, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 468 | .maxViewportDimensions = { (1 << 14), (1 << 14) }, |
| 469 | .viewportBoundsRange = { -1.0, 1.0 }, /* FIXME */ |
| 470 | .viewportSubPixelBits = 13, /* We take a float? */ |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 471 | .minMemoryMapAlignment = 4096, /* A page */ |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 472 | .minTexelBufferOffsetAlignment = 1, |
| 473 | .minUniformBufferOffsetAlignment = 1, |
| 474 | .minStorageBufferOffsetAlignment = 1, |
| 475 | .minTexelOffset = 0, /* FIXME */ |
| 476 | .maxTexelOffset = 0, /* FIXME */ |
| 477 | .minTexelGatherOffset = 0, /* FIXME */ |
| 478 | .maxTexelGatherOffset = 0, /* FIXME */ |
| 479 | .minInterpolationOffset = 0, /* FIXME */ |
| 480 | .maxInterpolationOffset = 0, /* FIXME */ |
| 481 | .subPixelInterpolationOffsetBits = 0, /* FIXME */ |
| 482 | .maxFramebufferWidth = (1 << 14), |
| 483 | .maxFramebufferHeight = (1 << 14), |
| 484 | .maxFramebufferLayers = (1 << 10), |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 485 | .framebufferColorSampleCounts = sample_counts, |
| 486 | .framebufferDepthSampleCounts = sample_counts, |
| 487 | .framebufferStencilSampleCounts = sample_counts, |
| 488 | .framebufferNoAttachmentsSampleCounts = sample_counts, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 489 | .maxColorAttachments = MAX_RTS, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 490 | .sampledImageColorSampleCounts = sample_counts, |
| 491 | .sampledImageIntegerSampleCounts = VK_SAMPLE_COUNT_1_BIT, |
| 492 | .sampledImageDepthSampleCounts = sample_counts, |
| 493 | .sampledImageStencilSampleCounts = sample_counts, |
| 494 | .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 495 | .maxSampleMaskWords = 1, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 496 | .timestampPeriod = 80.0 / (1000 * 1000 * 1000), |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 497 | .maxClipDistances = 0 /* FIXME */, |
| 498 | .maxCullDistances = 0 /* FIXME */, |
| 499 | .maxCombinedClipAndCullDistances = 0 /* FIXME */, |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 500 | .discreteQueuePriorities = 1, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 501 | .pointSizeRange = { 0.125, 255.875 }, |
| 502 | .lineWidthRange = { 0.0, 7.9921875 }, |
| 503 | .pointSizeGranularity = (1.0 / 8.0), |
| 504 | .lineWidthGranularity = (1.0 / 128.0), |
Jason Ekstrand | d689745 | 2015-12-02 16:58:54 -0800 | [diff] [blame] | 505 | .strictLines = false, /* FINISHME */ |
| 506 | .standardSampleLocations = true, /* FINISHME */ |
| 507 | .optimalBufferCopyOffsetAlignment = 128, |
| 508 | .optimalBufferCopyRowPitchAlignment = 128, |
| 509 | .nonCoherentAtomSize = 64, |
Jason Ekstrand | 65e0b30 | 2015-07-09 15:38:30 -0700 | [diff] [blame] | 510 | }; |
| 511 | |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 512 | *pProperties = (VkPhysicalDeviceProperties) { |
Jason Ekstrand | bfeaf67 | 2015-12-03 15:23:33 -0800 | [diff] [blame] | 513 | .apiVersion = VK_MAKE_VERSION(0, 210, 1), |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 514 | .driverVersion = 1, |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 515 | .vendorID = 0x8086, |
| 516 | .deviceID = pdevice->chipset_id, |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 517 | .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, |
Chad Versace | d48e71c | 2015-10-07 10:36:46 -0700 | [diff] [blame] | 518 | .limits = limits, |
| 519 | .sparseProperties = {0}, /* Broadwell doesn't do sparse. */ |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | strcpy(pProperties->deviceName, pdevice->name); |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 523 | snprintf((char *)pProperties->pipelineCacheUUID, VK_UUID_SIZE, |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 524 | "anv-%s", MESA_GIT_SHA1 + 4); |
Jason Ekstrand | 977a469 | 2015-07-09 15:53:03 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 527 | void anv_GetPhysicalDeviceQueueFamilyProperties( |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 528 | VkPhysicalDevice physicalDevice, |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 529 | uint32_t* pCount, |
| 530 | VkQueueFamilyProperties* pQueueFamilyProperties) |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 531 | { |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 532 | if (pQueueFamilyProperties == NULL) { |
| 533 | *pCount = 1; |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 534 | return; |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 535 | } |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 536 | |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 537 | assert(*pCount >= 1); |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 538 | |
Jason Ekstrand | a6eba40 | 2015-10-05 21:17:12 -0700 | [diff] [blame] | 539 | *pQueueFamilyProperties = (VkQueueFamilyProperties) { |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 540 | .queueFlags = VK_QUEUE_GRAPHICS_BIT | |
| 541 | VK_QUEUE_COMPUTE_BIT | |
Jason Ekstrand | 6a8a542 | 2015-11-30 11:12:44 -0800 | [diff] [blame] | 542 | VK_QUEUE_TRANSFER_BIT, |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 543 | .queueCount = 1, |
Jason Ekstrand | 74c4c4a | 2015-12-02 16:20:40 -0800 | [diff] [blame] | 544 | .timestampValidBits = 0, /* XXX: Real value here */ |
| 545 | .minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 }, |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 546 | }; |
Jason Ekstrand | 1f90701 | 2015-07-09 16:11:24 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 549 | void anv_GetPhysicalDeviceMemoryProperties( |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 550 | VkPhysicalDevice physicalDevice, |
| 551 | VkPhysicalDeviceMemoryProperties* pMemoryProperties) |
| 552 | { |
| 553 | ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 554 | VkDeviceSize heap_size; |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 555 | |
| 556 | /* Reserve some wiggle room for the driver by exposing only 75% of the |
| 557 | * aperture to the heap. |
| 558 | */ |
Kristian Høgsberg Kristensen | 9564dd3 | 2015-07-21 13:09:25 -0700 | [diff] [blame] | 559 | heap_size = 3 * physical_device->aperture_size / 4; |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 560 | |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 561 | if (physical_device->info->has_llc) { |
| 562 | /* Big core GPUs share LLC with the CPU and thus one memory type can be |
| 563 | * both cached and coherent at the same time. |
| 564 | */ |
| 565 | pMemoryProperties->memoryTypeCount = 1; |
| 566 | pMemoryProperties->memoryTypes[0] = (VkMemoryType) { |
| 567 | .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 568 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 569 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | |
| 570 | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, |
Jason Ekstrand | 3421ba1 | 2015-12-30 19:32:41 -0800 | [diff] [blame] | 571 | .heapIndex = 0, |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 572 | }; |
| 573 | } else { |
| 574 | /* The spec requires that we expose a host-visible, coherent memory |
| 575 | * type, but Atom GPUs don't share LLC. Thus we offer two memory types |
| 576 | * to give the application a choice between cached, but not coherent and |
| 577 | * coherent but uncached (WC though). |
| 578 | */ |
| 579 | pMemoryProperties->memoryTypeCount = 2; |
| 580 | pMemoryProperties->memoryTypes[0] = (VkMemoryType) { |
| 581 | .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 582 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 583 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, |
Jason Ekstrand | 3421ba1 | 2015-12-30 19:32:41 -0800 | [diff] [blame] | 584 | .heapIndex = 0, |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 585 | }; |
| 586 | pMemoryProperties->memoryTypes[1] = (VkMemoryType) { |
| 587 | .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 588 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 589 | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, |
Jason Ekstrand | 3421ba1 | 2015-12-30 19:32:41 -0800 | [diff] [blame] | 590 | .heapIndex = 0, |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 591 | }; |
| 592 | } |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 593 | |
| 594 | pMemoryProperties->memoryHeapCount = 1; |
| 595 | pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) { |
| 596 | .size = heap_size, |
Jason Ekstrand | e6ab06a | 2015-12-02 10:39:15 -0800 | [diff] [blame] | 597 | .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 598 | }; |
Chad Versace | df2a013 | 2015-07-09 19:49:19 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Jason Ekstrand | e7acdda | 2015-07-07 18:51:53 -0700 | [diff] [blame] | 601 | PFN_vkVoidFunction anv_GetInstanceProcAddr( |
| 602 | VkInstance instance, |
| 603 | const char* pName) |
| 604 | { |
| 605 | return anv_lookup_entrypoint(pName); |
| 606 | } |
| 607 | |
| 608 | PFN_vkVoidFunction anv_GetDeviceProcAddr( |
| 609 | VkDevice device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 610 | const char* pName) |
| 611 | { |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 612 | return anv_lookup_entrypoint(pName); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 615 | static VkResult |
| 616 | anv_queue_init(struct anv_device *device, struct anv_queue *queue) |
| 617 | { |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 618 | queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 619 | queue->device = device; |
| 620 | queue->pool = &device->surface_state_pool; |
| 621 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 622 | return VK_SUCCESS; |
| 623 | } |
| 624 | |
| 625 | static void |
| 626 | anv_queue_finish(struct anv_queue *queue) |
| 627 | { |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 630 | static struct anv_state |
| 631 | anv_state_pool_emit_data(struct anv_state_pool *pool, size_t size, size_t align, const void *p) |
| 632 | { |
| 633 | struct anv_state state; |
| 634 | |
| 635 | state = anv_state_pool_alloc(pool, size, align); |
| 636 | memcpy(state.map, p, size); |
| 637 | |
| 638 | if (!pool->block_pool->device->info.has_llc) |
| 639 | anv_state_clflush(state); |
| 640 | |
| 641 | return state; |
| 642 | } |
| 643 | |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 644 | static void |
| 645 | anv_device_init_border_colors(struct anv_device *device) |
| 646 | { |
Jason Ekstrand | 522ab83 | 2015-07-08 11:44:52 -0700 | [diff] [blame] | 647 | static const VkClearColorValue border_colors[] = { |
Jason Ekstrand | bd4cde7 | 2015-10-06 10:07:47 -0700 | [diff] [blame] | 648 | [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 0.0 } }, |
| 649 | [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 1.0 } }, |
| 650 | [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] = { .float32 = { 1.0, 1.0, 1.0, 1.0 } }, |
| 651 | [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] = { .uint32 = { 0, 0, 0, 0 } }, |
| 652 | [VK_BORDER_COLOR_INT_OPAQUE_BLACK] = { .uint32 = { 0, 0, 0, 1 } }, |
| 653 | [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] | 654 | }; |
| 655 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 656 | device->border_colors = anv_state_pool_emit_data(&device->dynamic_state_pool, |
| 657 | sizeof(border_colors), 32, border_colors); |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 660 | VkResult anv_CreateDevice( |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 661 | VkPhysicalDevice physicalDevice, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 662 | const VkDeviceCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 663 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 664 | VkDevice* pDevice) |
| 665 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 666 | ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 667 | VkResult result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 668 | struct anv_device *device; |
| 669 | |
| 670 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); |
| 671 | |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 672 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 673 | bool found = false; |
| 674 | for (uint32_t j = 0; j < ARRAY_SIZE(device_extensions); j++) { |
| 675 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
Jason Ekstrand | aadb7dc | 2015-11-30 21:10:14 -0800 | [diff] [blame] | 676 | device_extensions[j].extensionName) == 0) { |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 677 | found = true; |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | if (!found) |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 682 | return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); |
Jason Ekstrand | b5f6889 | 2015-09-17 11:19:16 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Jason Ekstrand | aa3002b | 2015-11-17 06:30:02 -0800 | [diff] [blame] | 685 | anv_set_dispatch_devinfo(physical_device->info); |
Kristian Høgsberg Kristensen | ee97889 | 2015-07-30 14:44:01 -0700 | [diff] [blame] | 686 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 687 | device = anv_alloc2(&physical_device->instance->alloc, pAllocator, |
| 688 | sizeof(*device), 8, |
| 689 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 690 | if (!device) |
| 691 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 692 | |
Jason Ekstrand | 39cd378 | 2015-09-24 13:51:40 -0700 | [diff] [blame] | 693 | device->_loader_data.loaderMagic = ICD_LOADER_MAGIC; |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 694 | device->instance = physical_device->instance; |
Chad Versace | 8cda3e9 | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 695 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 696 | if (pAllocator) |
| 697 | device->alloc = *pAllocator; |
| 698 | else |
| 699 | device->alloc = physical_device->instance->alloc; |
| 700 | |
Chad Versace | 8cda3e9 | 2015-07-09 16:31:39 -0700 | [diff] [blame] | 701 | /* XXX(chadv): Can we dup() physicalDevice->fd here? */ |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 702 | device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC); |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 703 | if (device->fd == -1) { |
| 704 | result = vk_error(VK_ERROR_INITIALIZATION_FAILED); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 705 | goto fail_device; |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 706 | } |
Chad Versace | 477383e | 2015-11-13 10:12:18 -0800 | [diff] [blame] | 707 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 708 | device->context_id = anv_gem_create_context(device); |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 709 | if (device->context_id == -1) { |
| 710 | result = vk_error(VK_ERROR_INITIALIZATION_FAILED); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 711 | goto fail_fd; |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 712 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 713 | |
Jason Ekstrand | 9c84b6c | 2015-12-28 13:26:49 -0800 | [diff] [blame] | 714 | device->info = *physical_device->info; |
| 715 | device->isl_dev = physical_device->isl_dev; |
| 716 | |
Jason Ekstrand | a788e7c | 2015-09-17 18:23:21 -0700 | [diff] [blame] | 717 | pthread_mutex_init(&device->mutex, NULL); |
| 718 | |
Jason Ekstrand | 0c4a2da | 2015-07-30 11:34:09 -0700 | [diff] [blame] | 719 | anv_bo_pool_init(&device->batch_bo_pool, device, ANV_CMD_BUFFER_BATCH_SIZE); |
Jason Ekstrand | 5ef81f0 | 2015-05-25 15:46:48 -0700 | [diff] [blame] | 720 | |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 721 | anv_block_pool_init(&device->dynamic_state_block_pool, device, 2048); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 722 | |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 723 | anv_state_pool_init(&device->dynamic_state_pool, |
| 724 | &device->dynamic_state_block_pool); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 725 | |
Jason Ekstrand | 28c4ef9 | 2015-12-15 11:49:26 -0800 | [diff] [blame] | 726 | anv_block_pool_init(&device->instruction_block_pool, device, 8192); |
Jason Ekstrand | 0e94446 | 2015-09-22 16:36:00 -0700 | [diff] [blame] | 727 | anv_block_pool_init(&device->surface_state_block_pool, device, 4096); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 728 | |
| 729 | anv_state_pool_init(&device->surface_state_pool, |
| 730 | &device->surface_state_block_pool); |
| 731 | |
Jason Ekstrand | 3a3d79b | 2015-11-10 16:42:34 -0800 | [diff] [blame] | 732 | anv_bo_init_new(&device->workaround_bo, device, 1024); |
| 733 | |
Kristian Høgsberg Kristensen | 9b9f973 | 2015-06-19 15:41:30 -0700 | [diff] [blame] | 734 | anv_block_pool_init(&device->scratch_block_pool, device, 0x10000); |
| 735 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 736 | anv_queue_init(device, &device->queue); |
| 737 | |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 738 | result = anv_device_init_meta(device); |
| 739 | if (result != VK_SUCCESS) |
| 740 | goto fail_fd; |
Kristian Høgsberg | d77c34d | 2015-05-11 23:25:06 -0700 | [diff] [blame] | 741 | |
Kristian Høgsberg Kristensen | dc56e4f | 2015-05-29 16:06:06 -0700 | [diff] [blame] | 742 | anv_device_init_border_colors(device); |
| 743 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 744 | *pDevice = anv_device_to_handle(device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 745 | |
| 746 | return VK_SUCCESS; |
| 747 | |
| 748 | fail_fd: |
| 749 | close(device->fd); |
| 750 | fail_device: |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 751 | anv_free(&device->alloc, device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 752 | |
Kristian Høgsberg Kristensen | 5526c17 | 2016-01-03 22:43:47 -0800 | [diff] [blame] | 753 | return result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 756 | void anv_DestroyDevice( |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 757 | VkDevice _device, |
| 758 | const VkAllocationCallbacks* pAllocator) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 759 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 760 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 761 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 762 | anv_queue_finish(&device->queue); |
| 763 | |
Jason Ekstrand | 3a38b0d | 2015-06-09 11:08:51 -0700 | [diff] [blame] | 764 | anv_device_finish_meta(device); |
Jason Ekstrand | 5ef81f0 | 2015-05-25 15:46:48 -0700 | [diff] [blame] | 765 | |
Jason Ekstrand | 38f5eef | 2015-06-09 11:41:31 -0700 | [diff] [blame] | 766 | #ifdef HAVE_VALGRIND |
| 767 | /* We only need to free these to prevent valgrind errors. The backing |
| 768 | * BO will go away in a couple of lines so we don't actually leak. |
| 769 | */ |
Jason Ekstrand | 522ab83 | 2015-07-08 11:44:52 -0700 | [diff] [blame] | 770 | anv_state_pool_free(&device->dynamic_state_pool, device->border_colors); |
Jason Ekstrand | 38f5eef | 2015-06-09 11:41:31 -0700 | [diff] [blame] | 771 | #endif |
| 772 | |
Jason Ekstrand | 3a3d79b | 2015-11-10 16:42:34 -0800 | [diff] [blame] | 773 | anv_gem_munmap(device->workaround_bo.map, device->workaround_bo.size); |
| 774 | anv_gem_close(device, device->workaround_bo.gem_handle); |
| 775 | |
Jason Ekstrand | 5ef81f0 | 2015-05-25 15:46:48 -0700 | [diff] [blame] | 776 | anv_bo_pool_finish(&device->batch_bo_pool); |
Jason Ekstrand | 1920ef9 | 2015-07-31 10:30:57 -0700 | [diff] [blame] | 777 | anv_state_pool_finish(&device->dynamic_state_pool); |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 778 | anv_block_pool_finish(&device->dynamic_state_block_pool); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 779 | anv_block_pool_finish(&device->instruction_block_pool); |
Jason Ekstrand | 1920ef9 | 2015-07-31 10:30:57 -0700 | [diff] [blame] | 780 | anv_state_pool_finish(&device->surface_state_pool); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 781 | anv_block_pool_finish(&device->surface_state_block_pool); |
Jason Ekstrand | 3460e6c | 2015-07-22 17:51:14 -0700 | [diff] [blame] | 782 | anv_block_pool_finish(&device->scratch_block_pool); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 783 | |
| 784 | close(device->fd); |
| 785 | |
Kristian Høgsberg Kristensen | f551047 | 2016-01-05 11:43:25 -0800 | [diff] [blame^] | 786 | pthread_mutex_destroy(&device->mutex); |
| 787 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 788 | anv_free(&device->alloc, device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 791 | VkResult anv_EnumerateInstanceExtensionProperties( |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 792 | const char* pLayerName, |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 793 | uint32_t* pPropertyCount, |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 794 | VkExtensionProperties* pProperties) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 795 | { |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 796 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 797 | *pPropertyCount = ARRAY_SIZE(global_extensions); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 798 | return VK_SUCCESS; |
| 799 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 800 | |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 801 | assert(*pPropertyCount >= ARRAY_SIZE(global_extensions)); |
Kristian Høgsberg | 783e621 | 2015-05-17 19:22:52 -0700 | [diff] [blame] | 802 | |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 803 | *pPropertyCount = ARRAY_SIZE(global_extensions); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 804 | memcpy(pProperties, global_extensions, sizeof(global_extensions)); |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 805 | |
| 806 | return VK_SUCCESS; |
| 807 | } |
| 808 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 809 | VkResult anv_EnumerateDeviceExtensionProperties( |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 810 | VkPhysicalDevice physicalDevice, |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 811 | const char* pLayerName, |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 812 | uint32_t* pPropertyCount, |
Jason Ekstrand | 8e05bbe | 2015-07-08 10:38:07 -0700 | [diff] [blame] | 813 | VkExtensionProperties* pProperties) |
| 814 | { |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 815 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 816 | *pPropertyCount = ARRAY_SIZE(device_extensions); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 817 | return VK_SUCCESS; |
| 818 | } |
| 819 | |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 820 | assert(*pPropertyCount >= ARRAY_SIZE(device_extensions)); |
Jason Ekstrand | 9a7600c | 2015-09-01 16:44:42 -0700 | [diff] [blame] | 821 | |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 822 | *pPropertyCount = ARRAY_SIZE(device_extensions); |
Jason Ekstrand | 9a7600c | 2015-09-01 16:44:42 -0700 | [diff] [blame] | 823 | memcpy(pProperties, device_extensions, sizeof(device_extensions)); |
| 824 | |
| 825 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 828 | VkResult anv_EnumerateInstanceLayerProperties( |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 829 | uint32_t* pPropertyCount, |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 830 | VkLayerProperties* pProperties) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 831 | { |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 832 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 833 | *pPropertyCount = 0; |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 834 | return VK_SUCCESS; |
| 835 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 836 | |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 837 | /* None supported at this time */ |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 838 | return vk_error(VK_ERROR_LAYER_NOT_PRESENT); |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Jason Ekstrand | 8ba684c | 2015-10-06 09:25:03 -0700 | [diff] [blame] | 841 | VkResult anv_EnumerateDeviceLayerProperties( |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 842 | VkPhysicalDevice physicalDevice, |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 843 | uint32_t* pPropertyCount, |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 844 | VkLayerProperties* pProperties) |
| 845 | { |
| 846 | if (pProperties == NULL) { |
Jason Ekstrand | fe64472 | 2015-11-30 16:28:36 -0800 | [diff] [blame] | 847 | *pPropertyCount = 0; |
Jason Ekstrand | 02db21a | 2015-07-14 16:11:21 -0700 | [diff] [blame] | 848 | return VK_SUCCESS; |
| 849 | } |
| 850 | |
| 851 | /* None supported at this time */ |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 852 | return vk_error(VK_ERROR_LAYER_NOT_PRESENT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 855 | void anv_GetDeviceQueue( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 856 | VkDevice _device, |
| 857 | uint32_t queueNodeIndex, |
| 858 | uint32_t queueIndex, |
| 859 | VkQueue* pQueue) |
| 860 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 861 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 862 | |
Jason Ekstrand | 66b00d5 | 2015-06-09 12:28:58 -0700 | [diff] [blame] | 863 | assert(queueIndex == 0); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 864 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 865 | *pQueue = anv_queue_to_handle(&device->queue); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 868 | VkResult anv_QueueSubmit( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 869 | VkQueue _queue, |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 870 | uint32_t submitCount, |
| 871 | const VkSubmitInfo* pSubmits, |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 872 | VkFence _fence) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 873 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 874 | ANV_FROM_HANDLE(anv_queue, queue, _queue); |
| 875 | ANV_FROM_HANDLE(anv_fence, fence, _fence); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 876 | struct anv_device *device = queue->device; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 877 | int ret; |
| 878 | |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 879 | for (uint32_t i = 0; i < submitCount; i++) { |
| 880 | for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) { |
| 881 | ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, |
| 882 | pSubmits[i].pCommandBuffers[j]); |
| 883 | assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 884 | |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 885 | ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf2.execbuf); |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 886 | if (ret != 0) { |
| 887 | /* We don't know the real error. */ |
| 888 | return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 889 | "execbuf2 failed: %m"); |
| 890 | } |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 891 | |
Jason Ekstrand | 4e904a0 | 2015-12-02 17:18:41 -0800 | [diff] [blame] | 892 | if (fence) { |
| 893 | ret = anv_gem_execbuffer(device, &fence->execbuf); |
| 894 | if (ret != 0) { |
| 895 | /* We don't know the real error. */ |
| 896 | return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 897 | "execbuf2 failed: %m"); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | for (uint32_t k = 0; k < cmd_buffer->execbuf2.bo_count; k++) |
| 902 | cmd_buffer->execbuf2.bos[k]->offset = cmd_buffer->execbuf2.objects[k].offset; |
| 903 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 909 | VkResult anv_QueueWaitIdle( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 910 | VkQueue _queue) |
| 911 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 912 | ANV_FROM_HANDLE(anv_queue, queue, _queue); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 913 | |
Jason Ekstrand | a95f51c | 2015-09-24 14:20:35 -0700 | [diff] [blame] | 914 | return ANV_CALL(DeviceWaitIdle)(anv_device_to_handle(queue->device)); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 917 | VkResult anv_DeviceWaitIdle( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 918 | VkDevice _device) |
| 919 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 920 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 921 | struct anv_state state; |
| 922 | struct anv_batch batch; |
| 923 | struct drm_i915_gem_execbuffer2 execbuf; |
| 924 | struct drm_i915_gem_exec_object2 exec2_objects[1]; |
| 925 | struct anv_bo *bo = NULL; |
| 926 | VkResult result; |
| 927 | int64_t timeout; |
| 928 | int ret; |
| 929 | |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 930 | state = anv_state_pool_alloc(&device->dynamic_state_pool, 32, 32); |
| 931 | bo = &device->dynamic_state_pool.block_pool->bo; |
Jason Ekstrand | da8f148 | 2015-05-27 11:42:55 -0700 | [diff] [blame] | 932 | batch.start = batch.next = state.map; |
| 933 | batch.end = state.map + 32; |
Kristian Høgsberg Kristensen | 74556b0 | 2015-08-13 21:05:47 -0700 | [diff] [blame] | 934 | anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END); |
| 935 | anv_batch_emit(&batch, GEN7_MI_NOOP); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 936 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 937 | if (!device->info.has_llc) |
| 938 | anv_state_clflush(state); |
| 939 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 940 | exec2_objects[0].handle = bo->gem_handle; |
| 941 | exec2_objects[0].relocation_count = 0; |
| 942 | exec2_objects[0].relocs_ptr = 0; |
| 943 | exec2_objects[0].alignment = 0; |
| 944 | exec2_objects[0].offset = bo->offset; |
| 945 | exec2_objects[0].flags = 0; |
| 946 | exec2_objects[0].rsvd1 = 0; |
| 947 | exec2_objects[0].rsvd2 = 0; |
| 948 | |
| 949 | execbuf.buffers_ptr = (uintptr_t) exec2_objects; |
| 950 | execbuf.buffer_count = 1; |
| 951 | execbuf.batch_start_offset = state.offset; |
| 952 | execbuf.batch_len = batch.next - state.map; |
| 953 | execbuf.cliprects_ptr = 0; |
| 954 | execbuf.num_cliprects = 0; |
| 955 | execbuf.DR1 = 0; |
| 956 | execbuf.DR4 = 0; |
| 957 | |
| 958 | execbuf.flags = |
| 959 | I915_EXEC_HANDLE_LUT | I915_EXEC_NO_RELOC | I915_EXEC_RENDER; |
| 960 | execbuf.rsvd1 = device->context_id; |
| 961 | execbuf.rsvd2 = 0; |
| 962 | |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 963 | ret = anv_gem_execbuffer(device, &execbuf); |
| 964 | if (ret != 0) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 965 | /* We don't know the real error. */ |
| 966 | result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, "execbuf2 failed: %m"); |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 967 | goto fail; |
| 968 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 969 | |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 970 | timeout = INT64_MAX; |
| 971 | ret = anv_gem_wait(device, bo->gem_handle, &timeout); |
| 972 | if (ret != 0) { |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 973 | /* We don't know the real error. */ |
| 974 | result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, "execbuf2 failed: %m"); |
Kristian Høgsberg Kristensen | aac6f7c | 2015-08-14 09:39:01 -0700 | [diff] [blame] | 975 | goto fail; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 978 | anv_state_pool_free(&device->dynamic_state_pool, state); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 979 | |
| 980 | return VK_SUCCESS; |
| 981 | |
| 982 | fail: |
Kristian Høgsberg | 0a775e1 | 2015-05-13 15:34:34 -0700 | [diff] [blame] | 983 | anv_state_pool_free(&device->dynamic_state_pool, state); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 984 | |
| 985 | return result; |
| 986 | } |
| 987 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 988 | VkResult |
| 989 | anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size) |
| 990 | { |
| 991 | bo->gem_handle = anv_gem_create(device, size); |
| 992 | if (!bo->gem_handle) |
| 993 | return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
| 994 | |
| 995 | bo->map = NULL; |
| 996 | bo->index = 0; |
| 997 | bo->offset = 0; |
| 998 | bo->size = size; |
| 999 | |
| 1000 | return VK_SUCCESS; |
| 1001 | } |
| 1002 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1003 | VkResult anv_AllocateMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1004 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1005 | const VkMemoryAllocateInfo* pAllocateInfo, |
| 1006 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1007 | VkDeviceMemory* pMem) |
| 1008 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1009 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1010 | struct anv_device_memory *mem; |
| 1011 | VkResult result; |
| 1012 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1013 | assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1014 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1015 | if (pAllocateInfo->allocationSize == 0) { |
| 1016 | /* Apparently, this is allowed */ |
| 1017 | *pMem = VK_NULL_HANDLE; |
| 1018 | return VK_SUCCESS; |
| 1019 | } |
| 1020 | |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1021 | /* We support exactly one memory heap. */ |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 1022 | assert(pAllocateInfo->memoryTypeIndex == 0 || |
| 1023 | (!device->info.has_llc && pAllocateInfo->memoryTypeIndex < 2)); |
Chad Versace | f43a304 | 2015-07-09 19:59:44 -0700 | [diff] [blame] | 1024 | |
| 1025 | /* FINISHME: Fail if allocation request exceeds heap size. */ |
| 1026 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1027 | mem = anv_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, |
| 1028 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1029 | if (mem == NULL) |
| 1030 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1031 | |
Jason Ekstrand | 6b0b572 | 2016-01-02 07:52:22 -0800 | [diff] [blame] | 1032 | /* The kernel is going to give us whole pages anyway */ |
| 1033 | uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096); |
| 1034 | |
| 1035 | result = anv_bo_init_new(&mem->bo, device, alloc_size); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1036 | if (result != VK_SUCCESS) |
| 1037 | goto fail; |
| 1038 | |
Kristian Høgsberg Kristensen | c3c61d2 | 2015-12-03 23:09:09 -0800 | [diff] [blame] | 1039 | mem->type_index = pAllocateInfo->memoryTypeIndex; |
| 1040 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1041 | *pMem = anv_device_memory_to_handle(mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1042 | |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1043 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1044 | |
| 1045 | fail: |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1046 | anv_free2(&device->alloc, pAllocator, mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1047 | |
| 1048 | return result; |
| 1049 | } |
| 1050 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1051 | void anv_FreeMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1052 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1053 | VkDeviceMemory _mem, |
| 1054 | const VkAllocationCallbacks* pAllocator) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1055 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1056 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1057 | ANV_FROM_HANDLE(anv_device_memory, mem, _mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1058 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1059 | if (mem == NULL) |
| 1060 | return; |
| 1061 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1062 | if (mem->bo.map) |
| 1063 | anv_gem_munmap(mem->bo.map, mem->bo.size); |
| 1064 | |
| 1065 | if (mem->bo.gem_handle != 0) |
| 1066 | anv_gem_close(device, mem->bo.gem_handle); |
| 1067 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1068 | anv_free2(&device->alloc, pAllocator, mem); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1071 | VkResult anv_MapMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1072 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1073 | VkDeviceMemory _memory, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1074 | VkDeviceSize offset, |
| 1075 | VkDeviceSize size, |
| 1076 | VkMemoryMapFlags flags, |
| 1077 | void** ppData) |
| 1078 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1079 | ANV_FROM_HANDLE(anv_device, device, _device); |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1080 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1081 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1082 | if (mem == NULL) { |
| 1083 | *ppData = NULL; |
| 1084 | return VK_SUCCESS; |
| 1085 | } |
| 1086 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1087 | /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only |
| 1088 | * takes a VkDeviceMemory pointer, it seems like only one map of the memory |
| 1089 | * at a time is valid. We could just mmap up front and return an offset |
| 1090 | * pointer here, but that may exhaust virtual memory on 32 bit |
| 1091 | * userspace. */ |
| 1092 | |
Kristian Høgsberg Kristensen | bbb6875 | 2015-12-03 23:58:05 -0800 | [diff] [blame] | 1093 | uint32_t gem_flags = 0; |
| 1094 | if (!device->info.has_llc && mem->type_index == 0) |
| 1095 | gem_flags |= I915_MMAP_WC; |
| 1096 | |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1097 | /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */ |
| 1098 | uint64_t map_offset = offset & ~4095ull; |
| 1099 | assert(offset >= map_offset); |
| 1100 | uint64_t map_size = (offset + size) - map_offset; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1101 | |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1102 | /* Let's map whole pages */ |
Jason Ekstrand | 6b0b572 | 2016-01-02 07:52:22 -0800 | [diff] [blame] | 1103 | map_size = align_u64(map_size, 4096); |
Jason Ekstrand | f076d53 | 2016-01-01 09:26:06 -0800 | [diff] [blame] | 1104 | |
| 1105 | mem->map = anv_gem_mmap(device, mem->bo.gem_handle, |
| 1106 | map_offset, map_size, gem_flags); |
| 1107 | mem->map_size = map_size; |
| 1108 | |
| 1109 | *ppData = mem->map + (offset - map_offset); |
Chad Versace | 477383e | 2015-11-13 10:12:18 -0800 | [diff] [blame] | 1110 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1111 | return VK_SUCCESS; |
| 1112 | } |
| 1113 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1114 | void anv_UnmapMemory( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1115 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1116 | VkDeviceMemory _memory) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1117 | { |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1118 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1119 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1120 | if (mem == NULL) |
| 1121 | return; |
| 1122 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1123 | anv_gem_munmap(mem->map, mem->map_size); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1126 | static void |
| 1127 | clflush_mapped_ranges(struct anv_device *device, |
| 1128 | uint32_t count, |
| 1129 | const VkMappedMemoryRange *ranges) |
| 1130 | { |
| 1131 | for (uint32_t i = 0; i < count; i++) { |
| 1132 | ANV_FROM_HANDLE(anv_device_memory, mem, ranges[i].memory); |
| 1133 | void *p = mem->map + (ranges[i].offset & ~CACHELINE_MASK); |
| 1134 | void *end = mem->map + ranges[i].offset + ranges[i].size; |
| 1135 | |
| 1136 | while (p < end) { |
| 1137 | __builtin_ia32_clflush(p); |
| 1138 | p += CACHELINE_SIZE; |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | |
Jason Ekstrand | d9c2cae | 2015-07-07 17:22:29 -0700 | [diff] [blame] | 1143 | VkResult anv_FlushMappedMemoryRanges( |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1144 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1145 | uint32_t memoryRangeCount, |
| 1146 | const VkMappedMemoryRange* pMemoryRanges) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1147 | { |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1148 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1149 | |
| 1150 | if (device->info.has_llc) |
| 1151 | return VK_SUCCESS; |
| 1152 | |
| 1153 | /* Make sure the writes we're flushing have landed. */ |
| 1154 | __builtin_ia32_sfence(); |
| 1155 | |
| 1156 | clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1157 | |
| 1158 | return VK_SUCCESS; |
| 1159 | } |
| 1160 | |
Jason Ekstrand | d9c2cae | 2015-07-07 17:22:29 -0700 | [diff] [blame] | 1161 | VkResult anv_InvalidateMappedMemoryRanges( |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1162 | VkDevice _device, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1163 | uint32_t memoryRangeCount, |
| 1164 | const VkMappedMemoryRange* pMemoryRanges) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1165 | { |
Kristian Høgsberg | e0b5f03 | 2015-12-01 15:25:07 -0800 | [diff] [blame] | 1166 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1167 | |
| 1168 | if (device->info.has_llc) |
| 1169 | return VK_SUCCESS; |
| 1170 | |
| 1171 | clflush_mapped_ranges(device, memoryRangeCount, pMemoryRanges); |
| 1172 | |
| 1173 | /* Make sure no reads get moved up above the invalidate. */ |
| 1174 | __builtin_ia32_lfence(); |
| 1175 | |
| 1176 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1179 | void anv_GetBufferMemoryRequirements( |
Jason Ekstrand | ef8980e | 2015-07-07 18:16:42 -0700 | [diff] [blame] | 1180 | VkDevice device, |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1181 | VkBuffer _buffer, |
Jason Ekstrand | ef8980e | 2015-07-07 18:16:42 -0700 | [diff] [blame] | 1182 | VkMemoryRequirements* pMemoryRequirements) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1183 | { |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1184 | ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1185 | |
Chad Versace | f43a304 | 2015-07-09 19:59:44 -0700 | [diff] [blame] | 1186 | /* The Vulkan spec (git aaed022) says: |
| 1187 | * |
| 1188 | * memoryTypeBits is a bitfield and contains one bit set for every |
| 1189 | * supported memory type for the resource. The bit `1<<i` is set if and |
| 1190 | * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties |
| 1191 | * structure for the physical device is supported. |
| 1192 | * |
| 1193 | * We support exactly one memory type. |
| 1194 | */ |
| 1195 | pMemoryRequirements->memoryTypeBits = 1; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1196 | |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1197 | pMemoryRequirements->size = buffer->size; |
| 1198 | pMemoryRequirements->alignment = 16; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1201 | void anv_GetImageMemoryRequirements( |
Jason Ekstrand | bb6567f | 2015-07-08 09:04:16 -0700 | [diff] [blame] | 1202 | VkDevice device, |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1203 | VkImage _image, |
| 1204 | VkMemoryRequirements* pMemoryRequirements) |
| 1205 | { |
| 1206 | ANV_FROM_HANDLE(anv_image, image, _image); |
| 1207 | |
| 1208 | /* The Vulkan spec (git aaed022) says: |
| 1209 | * |
| 1210 | * memoryTypeBits is a bitfield and contains one bit set for every |
| 1211 | * supported memory type for the resource. The bit `1<<i` is set if and |
| 1212 | * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties |
| 1213 | * structure for the physical device is supported. |
| 1214 | * |
| 1215 | * We support exactly one memory type. |
| 1216 | */ |
| 1217 | pMemoryRequirements->memoryTypeBits = 1; |
| 1218 | |
| 1219 | pMemoryRequirements->size = image->size; |
| 1220 | pMemoryRequirements->alignment = image->alignment; |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1223 | void anv_GetImageSparseMemoryRequirements( |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1224 | VkDevice device, |
| 1225 | VkImage image, |
Jason Ekstrand | 5a02441 | 2015-12-02 03:34:43 -0800 | [diff] [blame] | 1226 | uint32_t* pSparseMemoryRequirementCount, |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1227 | VkSparseImageMemoryRequirements* pSparseMemoryRequirements) |
| 1228 | { |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1229 | stub(); |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 1232 | void anv_GetDeviceMemoryCommitment( |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1233 | VkDevice device, |
| 1234 | VkDeviceMemory memory, |
| 1235 | VkDeviceSize* pCommittedMemoryInBytes) |
| 1236 | { |
| 1237 | *pCommittedMemoryInBytes = 0; |
Jason Ekstrand | c7fcfeb | 2015-07-14 17:06:11 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1240 | VkResult anv_BindBufferMemory( |
| 1241 | VkDevice device, |
| 1242 | VkBuffer _buffer, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1243 | VkDeviceMemory _memory, |
| 1244 | VkDeviceSize memoryOffset) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1245 | { |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1246 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1247 | ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1248 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1249 | if (mem) { |
| 1250 | buffer->bo = &mem->bo; |
| 1251 | buffer->offset = memoryOffset; |
| 1252 | } else { |
| 1253 | buffer->bo = NULL; |
| 1254 | buffer->offset = 0; |
| 1255 | } |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1256 | |
| 1257 | return VK_SUCCESS; |
| 1258 | } |
| 1259 | |
| 1260 | VkResult anv_BindImageMemory( |
| 1261 | VkDevice device, |
| 1262 | VkImage _image, |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1263 | VkDeviceMemory _memory, |
| 1264 | VkDeviceSize memoryOffset) |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1265 | { |
Jason Ekstrand | 6a6da54 | 2015-11-30 21:18:12 -0800 | [diff] [blame] | 1266 | ANV_FROM_HANDLE(anv_device_memory, mem, _memory); |
Jason Ekstrand | 55723e9 | 2015-07-14 14:59:39 -0700 | [diff] [blame] | 1267 | ANV_FROM_HANDLE(anv_image, image, _image); |
| 1268 | |
Jason Ekstrand | b132540 | 2015-12-17 11:00:38 -0800 | [diff] [blame] | 1269 | if (mem) { |
| 1270 | image->bo = &mem->bo; |
| 1271 | image->offset = memoryOffset; |
| 1272 | } else { |
| 1273 | image->bo = NULL; |
| 1274 | image->offset = 0; |
| 1275 | } |
Jason Ekstrand | bb6567f | 2015-07-08 09:04:16 -0700 | [diff] [blame] | 1276 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1277 | return VK_SUCCESS; |
| 1278 | } |
| 1279 | |
Jason Ekstrand | fd53603 | 2015-11-30 16:42:12 -0800 | [diff] [blame] | 1280 | VkResult anv_QueueBindSparse( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1281 | VkQueue queue, |
Jason Ekstrand | fd53603 | 2015-11-30 16:42:12 -0800 | [diff] [blame] | 1282 | uint32_t bindInfoCount, |
| 1283 | const VkBindSparseInfo* pBindInfo, |
| 1284 | VkFence fence) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1285 | { |
Jason Ekstrand | fed3586 | 2015-12-02 16:14:58 -0800 | [diff] [blame] | 1286 | stub_return(VK_ERROR_INCOMPATIBLE_DRIVER); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1289 | VkResult anv_CreateFence( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1290 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1291 | const VkFenceCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1292 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1293 | VkFence* pFence) |
| 1294 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1295 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1296 | struct anv_fence *fence; |
| 1297 | struct anv_batch batch; |
| 1298 | VkResult result; |
| 1299 | |
| 1300 | const uint32_t fence_size = 128; |
| 1301 | |
| 1302 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO); |
| 1303 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1304 | fence = anv_alloc2(&device->alloc, pAllocator, sizeof(*fence), 8, |
| 1305 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1306 | if (fence == NULL) |
| 1307 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1308 | |
| 1309 | result = anv_bo_init_new(&fence->bo, device, fence_size); |
| 1310 | if (result != VK_SUCCESS) |
| 1311 | goto fail; |
| 1312 | |
| 1313 | fence->bo.map = |
Kristian Høgsberg Kristensen | bbb6875 | 2015-12-03 23:58:05 -0800 | [diff] [blame] | 1314 | anv_gem_mmap(device, fence->bo.gem_handle, 0, fence->bo.size, 0); |
Jason Ekstrand | da8f148 | 2015-05-27 11:42:55 -0700 | [diff] [blame] | 1315 | batch.next = batch.start = fence->bo.map; |
| 1316 | batch.end = fence->bo.map + fence->bo.size; |
Kristian Høgsberg Kristensen | cff717c | 2015-08-18 11:04:19 -0700 | [diff] [blame] | 1317 | anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END); |
| 1318 | anv_batch_emit(&batch, GEN7_MI_NOOP); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1319 | |
Kristian Høgsberg | 7735920 | 2015-12-01 15:37:12 -0800 | [diff] [blame] | 1320 | if (!device->info.has_llc) { |
| 1321 | assert(((uintptr_t) fence->bo.map & CACHELINE_MASK) == 0); |
| 1322 | assert(batch.next - fence->bo.map <= CACHELINE_SIZE); |
| 1323 | __builtin_ia32_sfence(); |
| 1324 | __builtin_ia32_clflush(fence->bo.map); |
| 1325 | } |
| 1326 | |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1327 | fence->exec2_objects[0].handle = fence->bo.gem_handle; |
| 1328 | fence->exec2_objects[0].relocation_count = 0; |
| 1329 | fence->exec2_objects[0].relocs_ptr = 0; |
| 1330 | fence->exec2_objects[0].alignment = 0; |
| 1331 | fence->exec2_objects[0].offset = fence->bo.offset; |
| 1332 | fence->exec2_objects[0].flags = 0; |
| 1333 | fence->exec2_objects[0].rsvd1 = 0; |
| 1334 | fence->exec2_objects[0].rsvd2 = 0; |
| 1335 | |
| 1336 | fence->execbuf.buffers_ptr = (uintptr_t) fence->exec2_objects; |
| 1337 | fence->execbuf.buffer_count = 1; |
| 1338 | fence->execbuf.batch_start_offset = 0; |
| 1339 | fence->execbuf.batch_len = batch.next - fence->bo.map; |
| 1340 | fence->execbuf.cliprects_ptr = 0; |
| 1341 | fence->execbuf.num_cliprects = 0; |
| 1342 | fence->execbuf.DR1 = 0; |
| 1343 | fence->execbuf.DR4 = 0; |
| 1344 | |
| 1345 | fence->execbuf.flags = |
| 1346 | I915_EXEC_HANDLE_LUT | I915_EXEC_NO_RELOC | I915_EXEC_RENDER; |
| 1347 | fence->execbuf.rsvd1 = device->context_id; |
| 1348 | fence->execbuf.rsvd2 = 0; |
| 1349 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1350 | *pFence = anv_fence_to_handle(fence); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1351 | |
| 1352 | return VK_SUCCESS; |
| 1353 | |
| 1354 | fail: |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1355 | anv_free2(&device->alloc, pAllocator, fence); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1356 | |
| 1357 | return result; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1360 | void anv_DestroyFence( |
Chad Versace | ebb191f | 2015-07-14 09:29:35 -0700 | [diff] [blame] | 1361 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1362 | VkFence _fence, |
| 1363 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | ebb191f | 2015-07-14 09:29:35 -0700 | [diff] [blame] | 1364 | { |
| 1365 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1366 | ANV_FROM_HANDLE(anv_fence, fence, _fence); |
| 1367 | |
| 1368 | anv_gem_munmap(fence->bo.map, fence->bo.size); |
| 1369 | anv_gem_close(device, fence->bo.gem_handle); |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1370 | anv_free2(&device->alloc, pAllocator, fence); |
Chad Versace | ebb191f | 2015-07-14 09:29:35 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1373 | VkResult anv_ResetFences( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1374 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1375 | uint32_t fenceCount, |
Jason Ekstrand | d5349b1 | 2015-07-07 17:18:00 -0700 | [diff] [blame] | 1376 | const VkFence* pFences) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1377 | { |
Chad Versace | 169251b | 2015-07-17 13:59:48 -0700 | [diff] [blame] | 1378 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 1379 | ANV_FROM_HANDLE(anv_fence, fence, pFences[i]); |
| 1380 | fence->ready = false; |
| 1381 | } |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1382 | |
| 1383 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1386 | VkResult anv_GetFenceStatus( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1387 | VkDevice _device, |
| 1388 | VkFence _fence) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1389 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1390 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1391 | ANV_FROM_HANDLE(anv_fence, fence, _fence); |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1392 | int64_t t = 0; |
| 1393 | int ret; |
| 1394 | |
| 1395 | if (fence->ready) |
| 1396 | return VK_SUCCESS; |
| 1397 | |
| 1398 | ret = anv_gem_wait(device, fence->bo.gem_handle, &t); |
| 1399 | if (ret == 0) { |
| 1400 | fence->ready = true; |
| 1401 | return VK_SUCCESS; |
| 1402 | } |
Jason Ekstrand | 5c49730 | 2015-07-09 18:20:28 -0700 | [diff] [blame] | 1403 | |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1404 | return VK_NOT_READY; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1407 | VkResult anv_WaitForFences( |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1408 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1409 | uint32_t fenceCount, |
| 1410 | const VkFence* pFences, |
Chad Versace | 8f3b218 | 2015-07-13 12:59:42 -0700 | [diff] [blame] | 1411 | VkBool32 waitAll, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1412 | uint64_t timeout) |
| 1413 | { |
Jason Ekstrand | c8577b5 | 2015-07-08 14:24:12 -0700 | [diff] [blame] | 1414 | ANV_FROM_HANDLE(anv_device, device, _device); |
Jason Ekstrand | aafc874 | 2015-11-10 11:24:08 -0800 | [diff] [blame] | 1415 | |
| 1416 | /* DRM_IOCTL_I915_GEM_WAIT uses a signed 64 bit timeout and is supposed |
| 1417 | * to block indefinitely timeouts <= 0. Unfortunately, this was broken |
| 1418 | * for a couple of kernel releases. Since there's no way to know |
| 1419 | * whether or not the kernel we're using is one of the broken ones, the |
| 1420 | * best we can do is to clamp the timeout to INT64_MAX. This limits the |
| 1421 | * maximum timeout from 584 years to 292 years - likely not a big deal. |
| 1422 | */ |
| 1423 | if (timeout > INT64_MAX) |
| 1424 | timeout = INT64_MAX; |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1425 | |
Jason Ekstrand | 427978d | 2015-11-10 15:02:52 -0800 | [diff] [blame] | 1426 | int64_t t = timeout; |
| 1427 | |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1428 | /* FIXME: handle !waitAll */ |
| 1429 | |
| 1430 | for (uint32_t i = 0; i < fenceCount; i++) { |
Jason Ekstrand | c8577b5 | 2015-07-08 14:24:12 -0700 | [diff] [blame] | 1431 | ANV_FROM_HANDLE(anv_fence, fence, pFences[i]); |
Jason Ekstrand | 427978d | 2015-11-10 15:02:52 -0800 | [diff] [blame] | 1432 | int ret = anv_gem_wait(device, fence->bo.gem_handle, &t); |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1433 | if (ret == -1 && errno == ETIME) { |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1434 | return VK_TIMEOUT; |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 1435 | } else if (ret == -1) { |
| 1436 | /* We don't know the real error. */ |
| 1437 | return vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 1438 | "gem wait failed: %m"); |
| 1439 | } |
Jason Ekstrand | 5c49730 | 2015-07-09 18:20:28 -0700 | [diff] [blame] | 1440 | } |
Kristian Høgsberg | 6afb264 | 2015-05-18 08:49:15 -0700 | [diff] [blame] | 1441 | |
| 1442 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | // Queue semaphore functions |
| 1446 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1447 | VkResult anv_CreateSemaphore( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1448 | VkDevice device, |
| 1449 | const VkSemaphoreCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1450 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1451 | VkSemaphore* pSemaphore) |
| 1452 | { |
Kristian Høgsberg Kristensen | a00524a | 2015-12-20 22:58:38 -0800 | [diff] [blame] | 1453 | /* The DRM execbuffer ioctl always execute in-oder, even between different |
| 1454 | * rings. As such, there's nothing to do for the user space semaphore. |
| 1455 | */ |
| 1456 | |
Jason Ekstrand | 3db43e8 | 2015-11-30 10:31:44 -0800 | [diff] [blame] | 1457 | *pSemaphore = (VkSemaphore)1; |
Kristian Høgsberg Kristensen | a00524a | 2015-12-20 22:58:38 -0800 | [diff] [blame] | 1458 | |
| 1459 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1462 | void anv_DestroySemaphore( |
Chad Versace | 549070b | 2015-07-14 09:31:34 -0700 | [diff] [blame] | 1463 | VkDevice device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1464 | VkSemaphore semaphore, |
| 1465 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | 549070b | 2015-07-14 09:31:34 -0700 | [diff] [blame] | 1466 | { |
Chad Versace | 549070b | 2015-07-14 09:31:34 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1469 | // Event functions |
| 1470 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1471 | VkResult anv_CreateEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1472 | VkDevice _device, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1473 | const VkEventCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1474 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1475 | VkEvent* pEvent) |
| 1476 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1477 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1478 | struct anv_state state; |
| 1479 | struct anv_event *event; |
| 1480 | |
| 1481 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_EVENT_CREATE_INFO); |
| 1482 | |
| 1483 | state = anv_state_pool_alloc(&device->dynamic_state_pool, |
| 1484 | sizeof(*event), 4); |
| 1485 | event = state.map; |
| 1486 | event->state = state; |
| 1487 | event->semaphore = VK_EVENT_RESET; |
| 1488 | |
| 1489 | if (!device->info.has_llc) { |
| 1490 | /* Make sure the writes we're flushing have landed. */ |
| 1491 | __builtin_ia32_sfence(); |
| 1492 | __builtin_ia32_clflush(event); |
| 1493 | } |
| 1494 | |
| 1495 | *pEvent = anv_event_to_handle(event); |
| 1496 | |
| 1497 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1500 | void anv_DestroyEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1501 | VkDevice _device, |
| 1502 | VkEvent _event, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1503 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | 68c7ef5 | 2015-07-14 09:33:47 -0700 | [diff] [blame] | 1504 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1505 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1506 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1507 | |
| 1508 | anv_state_pool_free(&device->dynamic_state_pool, event->state); |
Chad Versace | 68c7ef5 | 2015-07-14 09:33:47 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1511 | VkResult anv_GetEventStatus( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1512 | VkDevice _device, |
| 1513 | VkEvent _event) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1514 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1515 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1516 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1517 | |
| 1518 | if (!device->info.has_llc) { |
| 1519 | /* Make sure the writes we're flushing have landed. */ |
| 1520 | __builtin_ia32_clflush(event); |
| 1521 | __builtin_ia32_lfence(); |
| 1522 | } |
| 1523 | |
| 1524 | return event->semaphore; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1527 | VkResult anv_SetEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1528 | VkDevice _device, |
| 1529 | VkEvent _event) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1530 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1531 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1532 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1533 | |
| 1534 | event->semaphore = VK_EVENT_SET; |
| 1535 | |
| 1536 | if (!device->info.has_llc) { |
| 1537 | /* Make sure the writes we're flushing have landed. */ |
| 1538 | __builtin_ia32_sfence(); |
| 1539 | __builtin_ia32_clflush(event); |
| 1540 | } |
| 1541 | |
| 1542 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1545 | VkResult anv_ResetEvent( |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1546 | VkDevice _device, |
| 1547 | VkEvent _event) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1548 | { |
Kristian Høgsberg Kristensen | c4802bc | 2015-12-19 22:17:19 -0800 | [diff] [blame] | 1549 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1550 | ANV_FROM_HANDLE(anv_event, event, _event); |
| 1551 | |
| 1552 | event->semaphore = VK_EVENT_RESET; |
| 1553 | |
| 1554 | if (!device->info.has_llc) { |
| 1555 | /* Make sure the writes we're flushing have landed. */ |
| 1556 | __builtin_ia32_sfence(); |
| 1557 | __builtin_ia32_clflush(event); |
| 1558 | } |
| 1559 | |
| 1560 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1563 | // Buffer functions |
| 1564 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1565 | VkResult anv_CreateBuffer( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1566 | VkDevice _device, |
| 1567 | const VkBufferCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1568 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1569 | VkBuffer* pBuffer) |
| 1570 | { |
Jason Ekstrand | c8577b5 | 2015-07-08 14:24:12 -0700 | [diff] [blame] | 1571 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1572 | struct anv_buffer *buffer; |
| 1573 | |
| 1574 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO); |
| 1575 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1576 | buffer = anv_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8, |
| 1577 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1578 | if (buffer == NULL) |
| 1579 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1580 | |
| 1581 | buffer->size = pCreateInfo->size; |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 1582 | buffer->usage = pCreateInfo->usage; |
Kristian Høgsberg | 099faa1 | 2015-05-11 22:19:58 -0700 | [diff] [blame] | 1583 | buffer->bo = NULL; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1584 | buffer->offset = 0; |
| 1585 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1586 | *pBuffer = anv_buffer_to_handle(buffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1587 | |
| 1588 | return VK_SUCCESS; |
| 1589 | } |
| 1590 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1591 | void anv_DestroyBuffer( |
Chad Versace | e93b6d8 | 2015-07-14 09:47:45 -0700 | [diff] [blame] | 1592 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1593 | VkBuffer _buffer, |
| 1594 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | e93b6d8 | 2015-07-14 09:47:45 -0700 | [diff] [blame] | 1595 | { |
| 1596 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1597 | ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); |
| 1598 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1599 | anv_free2(&device->alloc, pAllocator, buffer); |
Chad Versace | e93b6d8 | 2015-07-14 09:47:45 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1602 | void |
| 1603 | anv_fill_buffer_surface_state(struct anv_device *device, void *state, |
Jason Ekstrand | 1f98bf8 | 2015-12-14 16:14:20 -0800 | [diff] [blame] | 1604 | enum isl_format format, |
Jason Ekstrand | 399d531 | 2015-11-06 15:14:10 -0800 | [diff] [blame] | 1605 | uint32_t offset, uint32_t range, uint32_t stride) |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1606 | { |
| 1607 | switch (device->info.gen) { |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 1608 | case 7: |
Jason Ekstrand | f0390bc | 2015-11-17 07:07:02 -0800 | [diff] [blame] | 1609 | if (device->info.is_haswell) |
| 1610 | gen75_fill_buffer_surface_state(state, format, offset, range, stride); |
| 1611 | else |
| 1612 | gen7_fill_buffer_surface_state(state, format, offset, range, stride); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 1613 | break; |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1614 | case 8: |
Jason Ekstrand | 399d531 | 2015-11-06 15:14:10 -0800 | [diff] [blame] | 1615 | gen8_fill_buffer_surface_state(state, format, offset, range, stride); |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1616 | break; |
Kristian Høgsberg Kristensen | cd4721c | 2015-11-25 22:27:01 -0800 | [diff] [blame] | 1617 | case 9: |
| 1618 | gen9_fill_buffer_surface_state(state, format, offset, range, stride); |
| 1619 | break; |
Kristian Høgsberg Kristensen | 8fe74ec | 2015-08-19 16:01:33 -0700 | [diff] [blame] | 1620 | default: |
| 1621 | unreachable("unsupported gen\n"); |
| 1622 | } |
| 1623 | } |
| 1624 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1625 | void anv_DestroySampler( |
Chad Versace | ec5e2f4 | 2015-07-14 10:34:00 -0700 | [diff] [blame] | 1626 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1627 | VkSampler _sampler, |
| 1628 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | ec5e2f4 | 2015-07-14 10:34:00 -0700 | [diff] [blame] | 1629 | { |
| 1630 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1631 | ANV_FROM_HANDLE(anv_sampler, sampler, _sampler); |
| 1632 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1633 | anv_free2(&device->alloc, pAllocator, sampler); |
Chad Versace | ec5e2f4 | 2015-07-14 10:34:00 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Kristian Høgsberg | 454345d | 2015-05-17 16:33:48 -0700 | [diff] [blame] | 1636 | VkResult anv_CreateFramebuffer( |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1637 | VkDevice _device, |
| 1638 | const VkFramebufferCreateInfo* pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1639 | const VkAllocationCallbacks* pAllocator, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1640 | VkFramebuffer* pFramebuffer) |
| 1641 | { |
Jason Ekstrand | c95f9b6 | 2015-07-09 18:20:10 -0700 | [diff] [blame] | 1642 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1643 | struct anv_framebuffer *framebuffer; |
| 1644 | |
| 1645 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO); |
| 1646 | |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 1647 | size_t size = sizeof(*framebuffer) + |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 1648 | sizeof(struct anv_image_view *) * pCreateInfo->attachmentCount; |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1649 | framebuffer = anv_alloc2(&device->alloc, pAllocator, size, 8, |
| 1650 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1651 | if (framebuffer == NULL) |
| 1652 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1653 | |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 1654 | framebuffer->attachment_count = pCreateInfo->attachmentCount; |
| 1655 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) { |
Chad Versace | 6dea1a9 | 2015-10-07 07:30:52 -0700 | [diff] [blame] | 1656 | VkImageView _iview = pCreateInfo->pAttachments[i]; |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 1657 | framebuffer->attachments[i] = anv_image_view_from_handle(_iview); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1660 | framebuffer->width = pCreateInfo->width; |
| 1661 | framebuffer->height = pCreateInfo->height; |
| 1662 | framebuffer->layers = pCreateInfo->layers; |
| 1663 | |
Jason Ekstrand | 098209e | 2015-07-09 18:41:27 -0700 | [diff] [blame] | 1664 | *pFramebuffer = anv_framebuffer_to_handle(framebuffer); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1665 | |
| 1666 | return VK_SUCCESS; |
| 1667 | } |
| 1668 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 1669 | void anv_DestroyFramebuffer( |
Chad Versace | 08f7731 | 2015-07-14 10:59:30 -0700 | [diff] [blame] | 1670 | VkDevice _device, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1671 | VkFramebuffer _fb, |
| 1672 | const VkAllocationCallbacks* pAllocator) |
Chad Versace | 08f7731 | 2015-07-14 10:59:30 -0700 | [diff] [blame] | 1673 | { |
| 1674 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 1675 | ANV_FROM_HANDLE(anv_framebuffer, fb, _fb); |
| 1676 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 1677 | anv_free2(&device->alloc, pAllocator, fb); |
Chad Versace | 08f7731 | 2015-07-14 10:59:30 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Kristian Høgsberg | f886647 | 2015-05-15 22:04:15 -0700 | [diff] [blame] | 1680 | void vkCmdDbgMarkerBegin( |
Jason Ekstrand | a89a485 | 2015-11-30 11:48:08 -0800 | [diff] [blame] | 1681 | VkCommandBuffer commandBuffer, |
Kristian Høgsberg | f886647 | 2015-05-15 22:04:15 -0700 | [diff] [blame] | 1682 | const char* pMarker) |
| 1683 | __attribute__ ((visibility ("default"))); |
| 1684 | |
| 1685 | void vkCmdDbgMarkerEnd( |
Jason Ekstrand | a89a485 | 2015-11-30 11:48:08 -0800 | [diff] [blame] | 1686 | VkCommandBuffer commandBuffer) |
Kristian Høgsberg | f886647 | 2015-05-15 22:04:15 -0700 | [diff] [blame] | 1687 | __attribute__ ((visibility ("default"))); |
| 1688 | |
Kristian Høgsberg | f886647 | 2015-05-15 22:04:15 -0700 | [diff] [blame] | 1689 | void vkCmdDbgMarkerBegin( |
Jason Ekstrand | a89a485 | 2015-11-30 11:48:08 -0800 | [diff] [blame] | 1690 | VkCommandBuffer commandBuffer, |
Kristian Høgsberg | f886647 | 2015-05-15 22:04:15 -0700 | [diff] [blame] | 1691 | const char* pMarker) |
| 1692 | { |
| 1693 | } |
| 1694 | |
| 1695 | void vkCmdDbgMarkerEnd( |
Jason Ekstrand | a89a485 | 2015-11-30 11:48:08 -0800 | [diff] [blame] | 1696 | VkCommandBuffer commandBuffer) |
Kristian Høgsberg | f886647 | 2015-05-15 22:04:15 -0700 | [diff] [blame] | 1697 | { |
| 1698 | } |