anv: track the current frame and write it into the driver identifier BO
[mesa.git] / src / intel / vulkan / anv_device.c
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 <sys/mman.h>
28 #include <sys/sysinfo.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <xf86drm.h>
32 #include "drm-uapi/drm_fourcc.h"
33
34 #include "anv_private.h"
35 #include "util/debug.h"
36 #include "util/build_id.h"
37 #include "util/disk_cache.h"
38 #include "util/mesa-sha1.h"
39 #include "util/os_file.h"
40 #include "util/u_atomic.h"
41 #include "util/u_string.h"
42 #include "util/driconf.h"
43 #include "git_sha1.h"
44 #include "vk_util.h"
45 #include "common/gen_aux_map.h"
46 #include "common/gen_defines.h"
47 #include "compiler/glsl_types.h"
48
49 #include "genxml/gen7_pack.h"
50
51 static const char anv_dri_options_xml[] =
52 DRI_CONF_BEGIN
53 DRI_CONF_SECTION_PERFORMANCE
54 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
55 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
56 DRI_CONF_SECTION_END
57
58 DRI_CONF_SECTION_DEBUG
59 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
60 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
61 DRI_CONF_SECTION_END
62 DRI_CONF_END;
63
64 /* This is probably far to big but it reflects the max size used for messages
65 * in OpenGLs KHR_debug.
66 */
67 #define MAX_DEBUG_MESSAGE_LENGTH 4096
68
69 /* Render engine timestamp register */
70 #define TIMESTAMP 0x2358
71
72 static void
73 compiler_debug_log(void *data, const char *fmt, ...)
74 {
75 char str[MAX_DEBUG_MESSAGE_LENGTH];
76 struct anv_device *device = (struct anv_device *)data;
77 struct anv_instance *instance = device->physical->instance;
78
79 if (list_is_empty(&instance->debug_report_callbacks.callbacks))
80 return;
81
82 va_list args;
83 va_start(args, fmt);
84 (void) vsnprintf(str, MAX_DEBUG_MESSAGE_LENGTH, fmt, args);
85 va_end(args);
86
87 vk_debug_report(&instance->debug_report_callbacks,
88 VK_DEBUG_REPORT_DEBUG_BIT_EXT,
89 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
90 0, 0, 0, "anv", str);
91 }
92
93 static void
94 compiler_perf_log(void *data, const char *fmt, ...)
95 {
96 va_list args;
97 va_start(args, fmt);
98
99 if (unlikely(INTEL_DEBUG & DEBUG_PERF))
100 intel_logd_v(fmt, args);
101
102 va_end(args);
103 }
104
105 static uint64_t
106 anv_compute_heap_size(int fd, uint64_t gtt_size)
107 {
108 /* Query the total ram from the system */
109 struct sysinfo info;
110 sysinfo(&info);
111
112 uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
113
114 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
115 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
116 */
117 uint64_t available_ram;
118 if (total_ram <= 4ull * 1024ull * 1024ull * 1024ull)
119 available_ram = total_ram / 2;
120 else
121 available_ram = total_ram * 3 / 4;
122
123 /* We also want to leave some padding for things we allocate in the driver,
124 * so don't go over 3/4 of the GTT either.
125 */
126 uint64_t available_gtt = gtt_size * 3 / 4;
127
128 return MIN2(available_ram, available_gtt);
129 }
130
131 static VkResult
132 anv_physical_device_init_heaps(struct anv_physical_device *device, int fd)
133 {
134 if (anv_gem_get_context_param(fd, 0, I915_CONTEXT_PARAM_GTT_SIZE,
135 &device->gtt_size) == -1) {
136 /* If, for whatever reason, we can't actually get the GTT size from the
137 * kernel (too old?) fall back to the aperture size.
138 */
139 anv_perf_warn(NULL, NULL,
140 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
141
142 if (gen_get_aperture_size(fd, &device->gtt_size) == -1) {
143 return vk_errorfi(device->instance, NULL,
144 VK_ERROR_INITIALIZATION_FAILED,
145 "failed to get aperture size: %m");
146 }
147 }
148
149 /* We only allow 48-bit addresses with softpin because knowing the actual
150 * address is required for the vertex cache flush workaround.
151 */
152 device->supports_48bit_addresses = (device->info.gen >= 8) &&
153 device->has_softpin &&
154 device->gtt_size > (4ULL << 30 /* GiB */);
155
156 uint64_t heap_size = anv_compute_heap_size(fd, device->gtt_size);
157
158 if (heap_size > (2ull << 30) && !device->supports_48bit_addresses) {
159 /* When running with an overridden PCI ID, we may get a GTT size from
160 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
161 * address support can still fail. Just clamp the address space size to
162 * 2 GiB if we don't have 48-bit support.
163 */
164 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
165 "not support for 48-bit addresses",
166 __FILE__, __LINE__);
167 heap_size = 2ull << 30;
168 }
169
170 device->memory.heap_count = 1;
171 device->memory.heaps[0] = (struct anv_memory_heap) {
172 .size = heap_size,
173 .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
174 };
175
176 uint32_t type_count = 0;
177 for (uint32_t heap = 0; heap < device->memory.heap_count; heap++) {
178 if (device->info.has_llc) {
179 /* Big core GPUs share LLC with the CPU and thus one memory type can be
180 * both cached and coherent at the same time.
181 */
182 device->memory.types[type_count++] = (struct anv_memory_type) {
183 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
184 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
185 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
186 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
187 .heapIndex = heap,
188 };
189 } else {
190 /* The spec requires that we expose a host-visible, coherent memory
191 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
192 * to give the application a choice between cached, but not coherent and
193 * coherent but uncached (WC though).
194 */
195 device->memory.types[type_count++] = (struct anv_memory_type) {
196 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
197 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
198 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
199 .heapIndex = heap,
200 };
201 device->memory.types[type_count++] = (struct anv_memory_type) {
202 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
203 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
204 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
205 .heapIndex = heap,
206 };
207 }
208 }
209 device->memory.type_count = type_count;
210
211 return VK_SUCCESS;
212 }
213
214 static VkResult
215 anv_physical_device_init_uuids(struct anv_physical_device *device)
216 {
217 const struct build_id_note *note =
218 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids);
219 if (!note) {
220 return vk_errorfi(device->instance, NULL,
221 VK_ERROR_INITIALIZATION_FAILED,
222 "Failed to find build-id");
223 }
224
225 unsigned build_id_len = build_id_length(note);
226 if (build_id_len < 20) {
227 return vk_errorfi(device->instance, NULL,
228 VK_ERROR_INITIALIZATION_FAILED,
229 "build-id too short. It needs to be a SHA");
230 }
231
232 memcpy(device->driver_build_sha1, build_id_data(note), 20);
233
234 struct mesa_sha1 sha1_ctx;
235 uint8_t sha1[20];
236 STATIC_ASSERT(VK_UUID_SIZE <= sizeof(sha1));
237
238 /* The pipeline cache UUID is used for determining when a pipeline cache is
239 * invalid. It needs both a driver build and the PCI ID of the device.
240 */
241 _mesa_sha1_init(&sha1_ctx);
242 _mesa_sha1_update(&sha1_ctx, build_id_data(note), build_id_len);
243 _mesa_sha1_update(&sha1_ctx, &device->info.chipset_id,
244 sizeof(device->info.chipset_id));
245 _mesa_sha1_update(&sha1_ctx, &device->always_use_bindless,
246 sizeof(device->always_use_bindless));
247 _mesa_sha1_update(&sha1_ctx, &device->has_a64_buffer_access,
248 sizeof(device->has_a64_buffer_access));
249 _mesa_sha1_update(&sha1_ctx, &device->has_bindless_images,
250 sizeof(device->has_bindless_images));
251 _mesa_sha1_update(&sha1_ctx, &device->has_bindless_samplers,
252 sizeof(device->has_bindless_samplers));
253 _mesa_sha1_final(&sha1_ctx, sha1);
254 memcpy(device->pipeline_cache_uuid, sha1, VK_UUID_SIZE);
255
256 /* The driver UUID is used for determining sharability of images and memory
257 * between two Vulkan instances in separate processes. People who want to
258 * share memory need to also check the device UUID (below) so all this
259 * needs to be is the build-id.
260 */
261 memcpy(device->driver_uuid, build_id_data(note), VK_UUID_SIZE);
262
263 /* The device UUID uniquely identifies the given device within the machine.
264 * Since we never have more than one device, this doesn't need to be a real
265 * UUID. However, on the off-chance that someone tries to use this to
266 * cache pre-tiled images or something of the like, we use the PCI ID and
267 * some bits of ISL info to ensure that this is safe.
268 */
269 _mesa_sha1_init(&sha1_ctx);
270 _mesa_sha1_update(&sha1_ctx, &device->info.chipset_id,
271 sizeof(device->info.chipset_id));
272 _mesa_sha1_update(&sha1_ctx, &device->isl_dev.has_bit6_swizzling,
273 sizeof(device->isl_dev.has_bit6_swizzling));
274 _mesa_sha1_final(&sha1_ctx, sha1);
275 memcpy(device->device_uuid, sha1, VK_UUID_SIZE);
276
277 return VK_SUCCESS;
278 }
279
280 static void
281 anv_physical_device_init_disk_cache(struct anv_physical_device *device)
282 {
283 #ifdef ENABLE_SHADER_CACHE
284 char renderer[10];
285 ASSERTED int len = snprintf(renderer, sizeof(renderer), "anv_%04x",
286 device->info.chipset_id);
287 assert(len == sizeof(renderer) - 2);
288
289 char timestamp[41];
290 _mesa_sha1_format(timestamp, device->driver_build_sha1);
291
292 const uint64_t driver_flags =
293 brw_get_compiler_config_value(device->compiler);
294 device->disk_cache = disk_cache_create(renderer, timestamp, driver_flags);
295 #else
296 device->disk_cache = NULL;
297 #endif
298 }
299
300 static void
301 anv_physical_device_free_disk_cache(struct anv_physical_device *device)
302 {
303 #ifdef ENABLE_SHADER_CACHE
304 if (device->disk_cache)
305 disk_cache_destroy(device->disk_cache);
306 #else
307 assert(device->disk_cache == NULL);
308 #endif
309 }
310
311 static uint64_t
312 get_available_system_memory()
313 {
314 char *meminfo = os_read_file("/proc/meminfo", NULL);
315 if (!meminfo)
316 return 0;
317
318 char *str = strstr(meminfo, "MemAvailable:");
319 if (!str) {
320 free(meminfo);
321 return 0;
322 }
323
324 uint64_t kb_mem_available;
325 if (sscanf(str, "MemAvailable: %" PRIx64, &kb_mem_available) == 1) {
326 free(meminfo);
327 return kb_mem_available << 10;
328 }
329
330 free(meminfo);
331 return 0;
332 }
333
334 static VkResult
335 anv_physical_device_try_create(struct anv_instance *instance,
336 drmDevicePtr drm_device,
337 struct anv_physical_device **device_out)
338 {
339 const char *primary_path = drm_device->nodes[DRM_NODE_PRIMARY];
340 const char *path = drm_device->nodes[DRM_NODE_RENDER];
341 VkResult result;
342 int fd;
343 int master_fd = -1;
344
345 brw_process_intel_debug_variable();
346
347 fd = open(path, O_RDWR | O_CLOEXEC);
348 if (fd < 0)
349 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
350
351 struct gen_device_info devinfo;
352 if (!gen_get_device_info_from_fd(fd, &devinfo)) {
353 result = vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
354 goto fail_fd;
355 }
356
357 const char *device_name = gen_get_device_name(devinfo.chipset_id);
358
359 if (devinfo.is_haswell) {
360 intel_logw("Haswell Vulkan support is incomplete");
361 } else if (devinfo.gen == 7 && !devinfo.is_baytrail) {
362 intel_logw("Ivy Bridge Vulkan support is incomplete");
363 } else if (devinfo.gen == 7 && devinfo.is_baytrail) {
364 intel_logw("Bay Trail Vulkan support is incomplete");
365 } else if (devinfo.gen >= 8 && devinfo.gen <= 11) {
366 /* Gen8-11 fully supported */
367 } else if (devinfo.gen == 12) {
368 intel_logw("Vulkan is not yet fully supported on gen12");
369 } else {
370 result = vk_errorfi(instance, NULL, VK_ERROR_INCOMPATIBLE_DRIVER,
371 "Vulkan not yet supported on %s", device_name);
372 goto fail_fd;
373 }
374
375 struct anv_physical_device *device =
376 vk_alloc(&instance->alloc, sizeof(*device), 8,
377 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
378 if (device == NULL) {
379 result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
380 goto fail_fd;
381 }
382
383 vk_object_base_init(NULL, &device->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE);
384 device->instance = instance;
385
386 assert(strlen(path) < ARRAY_SIZE(device->path));
387 snprintf(device->path, ARRAY_SIZE(device->path), "%s", path);
388
389 device->info = devinfo;
390 device->name = device_name;
391
392 device->no_hw = device->info.no_hw;
393 if (getenv("INTEL_NO_HW") != NULL)
394 device->no_hw = true;
395
396 device->pci_info.domain = drm_device->businfo.pci->domain;
397 device->pci_info.bus = drm_device->businfo.pci->bus;
398 device->pci_info.device = drm_device->businfo.pci->dev;
399 device->pci_info.function = drm_device->businfo.pci->func;
400
401 device->cmd_parser_version = -1;
402 if (device->info.gen == 7) {
403 device->cmd_parser_version =
404 anv_gem_get_param(fd, I915_PARAM_CMD_PARSER_VERSION);
405 if (device->cmd_parser_version == -1) {
406 result = vk_errorfi(device->instance, NULL,
407 VK_ERROR_INITIALIZATION_FAILED,
408 "failed to get command parser version");
409 goto fail_alloc;
410 }
411 }
412
413 if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) {
414 result = vk_errorfi(device->instance, NULL,
415 VK_ERROR_INITIALIZATION_FAILED,
416 "kernel missing gem wait");
417 goto fail_alloc;
418 }
419
420 if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) {
421 result = vk_errorfi(device->instance, NULL,
422 VK_ERROR_INITIALIZATION_FAILED,
423 "kernel missing execbuf2");
424 goto fail_alloc;
425 }
426
427 if (!device->info.has_llc &&
428 anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) {
429 result = vk_errorfi(device->instance, NULL,
430 VK_ERROR_INITIALIZATION_FAILED,
431 "kernel missing wc mmap");
432 goto fail_alloc;
433 }
434
435 device->has_softpin = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_SOFTPIN);
436 device->has_exec_async = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_ASYNC);
437 device->has_exec_capture = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CAPTURE);
438 device->has_exec_fence = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_FENCE);
439 device->has_syncobj = anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_FENCE_ARRAY);
440 device->has_syncobj_wait = device->has_syncobj &&
441 anv_gem_supports_syncobj_wait(fd);
442 device->has_context_priority = anv_gem_has_context_priority(fd);
443
444 result = anv_physical_device_init_heaps(device, fd);
445 if (result != VK_SUCCESS)
446 goto fail_alloc;
447
448 device->use_softpin = device->has_softpin &&
449 device->supports_48bit_addresses;
450
451 device->has_context_isolation =
452 anv_gem_get_param(fd, I915_PARAM_HAS_CONTEXT_ISOLATION);
453
454 device->always_use_bindless =
455 env_var_as_boolean("ANV_ALWAYS_BINDLESS", false);
456
457 device->use_call_secondary =
458 device->use_softpin &&
459 !env_var_as_boolean("ANV_DISABLE_SECONDARY_CMD_BUFFER_CALLS", false);
460
461 /* We first got the A64 messages on broadwell and we can only use them if
462 * we can pass addresses directly into the shader which requires softpin.
463 */
464 device->has_a64_buffer_access = device->info.gen >= 8 &&
465 device->use_softpin;
466
467 /* We first get bindless image access on Skylake and we can only really do
468 * it if we don't have any relocations so we need softpin.
469 */
470 device->has_bindless_images = device->info.gen >= 9 &&
471 device->use_softpin;
472
473 /* We've had bindless samplers since Ivy Bridge (forever in Vulkan terms)
474 * because it's just a matter of setting the sampler address in the sample
475 * message header. However, we've not bothered to wire it up for vec4 so
476 * we leave it disabled on gen7.
477 */
478 device->has_bindless_samplers = device->info.gen >= 8;
479
480 device->has_implicit_ccs = device->info.has_aux_map;
481
482 /* Check if we can read the GPU timestamp register from the CPU */
483 uint64_t u64_ignore;
484 device->has_reg_timestamp = anv_gem_reg_read(fd, TIMESTAMP | I915_REG_READ_8B_WA,
485 &u64_ignore) == 0;
486
487 device->has_mem_available = get_available_system_memory() != 0;
488
489 device->always_flush_cache =
490 driQueryOptionb(&instance->dri_options, "always_flush_cache");
491
492 device->has_mmap_offset =
493 anv_gem_get_param(fd, I915_PARAM_MMAP_GTT_VERSION) >= 4;
494
495 /* GENs prior to 8 do not support EU/Subslice info */
496 if (device->info.gen >= 8) {
497 device->subslice_total = anv_gem_get_param(fd, I915_PARAM_SUBSLICE_TOTAL);
498 device->eu_total = anv_gem_get_param(fd, I915_PARAM_EU_TOTAL);
499
500 /* Without this information, we cannot get the right Braswell
501 * brandstrings, and we have to use conservative numbers for GPGPU on
502 * many platforms, but otherwise, things will just work.
503 */
504 if (device->subslice_total < 1 || device->eu_total < 1) {
505 intel_logw("Kernel 4.1 required to properly query GPU properties");
506 }
507 } else if (device->info.gen == 7) {
508 device->subslice_total = 1 << (device->info.gt - 1);
509 }
510
511 if (device->info.is_cherryview &&
512 device->subslice_total > 0 && device->eu_total > 0) {
513 /* Logical CS threads = EUs per subslice * num threads per EU */
514 uint32_t max_cs_threads =
515 device->eu_total / device->subslice_total * device->info.num_thread_per_eu;
516
517 /* Fuse configurations may give more threads than expected, never less. */
518 if (max_cs_threads > device->info.max_cs_threads)
519 device->info.max_cs_threads = max_cs_threads;
520 }
521
522 device->compiler = brw_compiler_create(NULL, &device->info);
523 if (device->compiler == NULL) {
524 result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
525 goto fail_alloc;
526 }
527 device->compiler->shader_debug_log = compiler_debug_log;
528 device->compiler->shader_perf_log = compiler_perf_log;
529 device->compiler->supports_pull_constants = false;
530 device->compiler->constant_buffer_0_is_relative =
531 device->info.gen < 8 || !device->has_context_isolation;
532 device->compiler->supports_shader_constants = true;
533 device->compiler->compact_params = false;
534
535 /* Broadwell PRM says:
536 *
537 * "Before Gen8, there was a historical configuration control field to
538 * swizzle address bit[6] for in X/Y tiling modes. This was set in three
539 * different places: TILECTL[1:0], ARB_MODE[5:4], and
540 * DISP_ARB_CTL[14:13].
541 *
542 * For Gen8 and subsequent generations, the swizzle fields are all
543 * reserved, and the CPU's memory controller performs all address
544 * swizzling modifications."
545 */
546 bool swizzled =
547 device->info.gen < 8 && anv_gem_get_bit6_swizzle(fd, I915_TILING_X);
548
549 isl_device_init(&device->isl_dev, &device->info, swizzled);
550
551 result = anv_physical_device_init_uuids(device);
552 if (result != VK_SUCCESS)
553 goto fail_compiler;
554
555 anv_physical_device_init_disk_cache(device);
556
557 if (instance->enabled_extensions.KHR_display) {
558 master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
559 if (master_fd >= 0) {
560 /* prod the device with a GETPARAM call which will fail if
561 * we don't have permission to even render on this device
562 */
563 if (anv_gem_get_param(master_fd, I915_PARAM_CHIPSET_ID) == 0) {
564 close(master_fd);
565 master_fd = -1;
566 }
567 }
568 }
569 device->master_fd = master_fd;
570
571 result = anv_init_wsi(device);
572 if (result != VK_SUCCESS)
573 goto fail_disk_cache;
574
575 device->perf = anv_get_perf(&device->info, fd);
576
577 anv_physical_device_get_supported_extensions(device,
578 &device->supported_extensions);
579
580
581 device->local_fd = fd;
582
583 *device_out = device;
584
585 return VK_SUCCESS;
586
587 fail_disk_cache:
588 anv_physical_device_free_disk_cache(device);
589 fail_compiler:
590 ralloc_free(device->compiler);
591 fail_alloc:
592 vk_free(&instance->alloc, device);
593 fail_fd:
594 close(fd);
595 if (master_fd != -1)
596 close(master_fd);
597 return result;
598 }
599
600 static void
601 anv_physical_device_destroy(struct anv_physical_device *device)
602 {
603 anv_finish_wsi(device);
604 anv_physical_device_free_disk_cache(device);
605 ralloc_free(device->compiler);
606 ralloc_free(device->perf);
607 close(device->local_fd);
608 if (device->master_fd >= 0)
609 close(device->master_fd);
610 vk_object_base_finish(&device->base);
611 vk_free(&device->instance->alloc, device);
612 }
613
614 static void *
615 default_alloc_func(void *pUserData, size_t size, size_t align,
616 VkSystemAllocationScope allocationScope)
617 {
618 return malloc(size);
619 }
620
621 static void *
622 default_realloc_func(void *pUserData, void *pOriginal, size_t size,
623 size_t align, VkSystemAllocationScope allocationScope)
624 {
625 return realloc(pOriginal, size);
626 }
627
628 static void
629 default_free_func(void *pUserData, void *pMemory)
630 {
631 free(pMemory);
632 }
633
634 static const VkAllocationCallbacks default_alloc = {
635 .pUserData = NULL,
636 .pfnAllocation = default_alloc_func,
637 .pfnReallocation = default_realloc_func,
638 .pfnFree = default_free_func,
639 };
640
641 VkResult anv_EnumerateInstanceExtensionProperties(
642 const char* pLayerName,
643 uint32_t* pPropertyCount,
644 VkExtensionProperties* pProperties)
645 {
646 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
647
648 for (int i = 0; i < ANV_INSTANCE_EXTENSION_COUNT; i++) {
649 if (anv_instance_extensions_supported.extensions[i]) {
650 vk_outarray_append(&out, prop) {
651 *prop = anv_instance_extensions[i];
652 }
653 }
654 }
655
656 return vk_outarray_status(&out);
657 }
658
659 VkResult anv_CreateInstance(
660 const VkInstanceCreateInfo* pCreateInfo,
661 const VkAllocationCallbacks* pAllocator,
662 VkInstance* pInstance)
663 {
664 struct anv_instance *instance;
665 VkResult result;
666
667 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
668
669 struct anv_instance_extension_table enabled_extensions = {};
670 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
671 int idx;
672 for (idx = 0; idx < ANV_INSTANCE_EXTENSION_COUNT; idx++) {
673 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
674 anv_instance_extensions[idx].extensionName) == 0)
675 break;
676 }
677
678 if (idx >= ANV_INSTANCE_EXTENSION_COUNT)
679 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
680
681 if (!anv_instance_extensions_supported.extensions[idx])
682 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
683
684 enabled_extensions.extensions[idx] = true;
685 }
686
687 instance = vk_alloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
688 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
689 if (!instance)
690 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
691
692 vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE);
693
694 if (pAllocator)
695 instance->alloc = *pAllocator;
696 else
697 instance->alloc = default_alloc;
698
699 instance->app_info = (struct anv_app_info) { .api_version = 0 };
700 if (pCreateInfo->pApplicationInfo) {
701 const VkApplicationInfo *app = pCreateInfo->pApplicationInfo;
702
703 instance->app_info.app_name =
704 vk_strdup(&instance->alloc, app->pApplicationName,
705 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
706 instance->app_info.app_version = app->applicationVersion;
707
708 instance->app_info.engine_name =
709 vk_strdup(&instance->alloc, app->pEngineName,
710 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
711 instance->app_info.engine_version = app->engineVersion;
712
713 instance->app_info.api_version = app->apiVersion;
714 }
715
716 if (instance->app_info.api_version == 0)
717 instance->app_info.api_version = VK_API_VERSION_1_0;
718
719 instance->enabled_extensions = enabled_extensions;
720
721 for (unsigned i = 0; i < ARRAY_SIZE(instance->dispatch.entrypoints); i++) {
722 /* Vulkan requires that entrypoints for extensions which have not been
723 * enabled must not be advertised.
724 */
725 if (!anv_instance_entrypoint_is_enabled(i, instance->app_info.api_version,
726 &instance->enabled_extensions)) {
727 instance->dispatch.entrypoints[i] = NULL;
728 } else {
729 instance->dispatch.entrypoints[i] =
730 anv_instance_dispatch_table.entrypoints[i];
731 }
732 }
733
734 for (unsigned i = 0; i < ARRAY_SIZE(instance->physical_device_dispatch.entrypoints); i++) {
735 /* Vulkan requires that entrypoints for extensions which have not been
736 * enabled must not be advertised.
737 */
738 if (!anv_physical_device_entrypoint_is_enabled(i, instance->app_info.api_version,
739 &instance->enabled_extensions)) {
740 instance->physical_device_dispatch.entrypoints[i] = NULL;
741 } else {
742 instance->physical_device_dispatch.entrypoints[i] =
743 anv_physical_device_dispatch_table.entrypoints[i];
744 }
745 }
746
747 for (unsigned i = 0; i < ARRAY_SIZE(instance->device_dispatch.entrypoints); i++) {
748 /* Vulkan requires that entrypoints for extensions which have not been
749 * enabled must not be advertised.
750 */
751 if (!anv_device_entrypoint_is_enabled(i, instance->app_info.api_version,
752 &instance->enabled_extensions, NULL)) {
753 instance->device_dispatch.entrypoints[i] = NULL;
754 } else {
755 instance->device_dispatch.entrypoints[i] =
756 anv_device_dispatch_table.entrypoints[i];
757 }
758 }
759
760 instance->physical_devices_enumerated = false;
761 list_inithead(&instance->physical_devices);
762
763 result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
764 if (result != VK_SUCCESS) {
765 vk_free2(&default_alloc, pAllocator, instance);
766 return vk_error(result);
767 }
768
769 instance->pipeline_cache_enabled =
770 env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true);
771
772 glsl_type_singleton_init_or_ref();
773
774 VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
775
776 driParseOptionInfo(&instance->available_dri_options, anv_dri_options_xml);
777 driParseConfigFiles(&instance->dri_options, &instance->available_dri_options,
778 0, "anv", NULL,
779 instance->app_info.engine_name,
780 instance->app_info.engine_version);
781
782 *pInstance = anv_instance_to_handle(instance);
783
784 return VK_SUCCESS;
785 }
786
787 void anv_DestroyInstance(
788 VkInstance _instance,
789 const VkAllocationCallbacks* pAllocator)
790 {
791 ANV_FROM_HANDLE(anv_instance, instance, _instance);
792
793 if (!instance)
794 return;
795
796 list_for_each_entry_safe(struct anv_physical_device, pdevice,
797 &instance->physical_devices, link)
798 anv_physical_device_destroy(pdevice);
799
800 vk_free(&instance->alloc, (char *)instance->app_info.app_name);
801 vk_free(&instance->alloc, (char *)instance->app_info.engine_name);
802
803 VG(VALGRIND_DESTROY_MEMPOOL(instance));
804
805 vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
806
807 glsl_type_singleton_decref();
808
809 driDestroyOptionCache(&instance->dri_options);
810 driDestroyOptionInfo(&instance->available_dri_options);
811
812 vk_object_base_finish(&instance->base);
813 vk_free(&instance->alloc, instance);
814 }
815
816 static VkResult
817 anv_enumerate_physical_devices(struct anv_instance *instance)
818 {
819 if (instance->physical_devices_enumerated)
820 return VK_SUCCESS;
821
822 instance->physical_devices_enumerated = true;
823
824 /* TODO: Check for more devices ? */
825 drmDevicePtr devices[8];
826 int max_devices;
827
828 max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
829 if (max_devices < 1)
830 return VK_SUCCESS;
831
832 VkResult result = VK_SUCCESS;
833 for (unsigned i = 0; i < (unsigned)max_devices; i++) {
834 if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
835 devices[i]->bustype == DRM_BUS_PCI &&
836 devices[i]->deviceinfo.pci->vendor_id == 0x8086) {
837
838 struct anv_physical_device *pdevice;
839 result = anv_physical_device_try_create(instance, devices[i],
840 &pdevice);
841 /* Incompatible DRM device, skip. */
842 if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
843 result = VK_SUCCESS;
844 continue;
845 }
846
847 /* Error creating the physical device, report the error. */
848 if (result != VK_SUCCESS)
849 break;
850
851 list_addtail(&pdevice->link, &instance->physical_devices);
852 }
853 }
854 drmFreeDevices(devices, max_devices);
855
856 /* If we successfully enumerated any devices, call it success */
857 return result;
858 }
859
860 VkResult anv_EnumeratePhysicalDevices(
861 VkInstance _instance,
862 uint32_t* pPhysicalDeviceCount,
863 VkPhysicalDevice* pPhysicalDevices)
864 {
865 ANV_FROM_HANDLE(anv_instance, instance, _instance);
866 VK_OUTARRAY_MAKE(out, pPhysicalDevices, pPhysicalDeviceCount);
867
868 VkResult result = anv_enumerate_physical_devices(instance);
869 if (result != VK_SUCCESS)
870 return result;
871
872 list_for_each_entry(struct anv_physical_device, pdevice,
873 &instance->physical_devices, link) {
874 vk_outarray_append(&out, i) {
875 *i = anv_physical_device_to_handle(pdevice);
876 }
877 }
878
879 return vk_outarray_status(&out);
880 }
881
882 VkResult anv_EnumeratePhysicalDeviceGroups(
883 VkInstance _instance,
884 uint32_t* pPhysicalDeviceGroupCount,
885 VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
886 {
887 ANV_FROM_HANDLE(anv_instance, instance, _instance);
888 VK_OUTARRAY_MAKE(out, pPhysicalDeviceGroupProperties,
889 pPhysicalDeviceGroupCount);
890
891 VkResult result = anv_enumerate_physical_devices(instance);
892 if (result != VK_SUCCESS)
893 return result;
894
895 list_for_each_entry(struct anv_physical_device, pdevice,
896 &instance->physical_devices, link) {
897 vk_outarray_append(&out, p) {
898 p->physicalDeviceCount = 1;
899 memset(p->physicalDevices, 0, sizeof(p->physicalDevices));
900 p->physicalDevices[0] = anv_physical_device_to_handle(pdevice);
901 p->subsetAllocation = false;
902
903 vk_foreach_struct(ext, p->pNext)
904 anv_debug_ignored_stype(ext->sType);
905 }
906 }
907
908 return vk_outarray_status(&out);
909 }
910
911 void anv_GetPhysicalDeviceFeatures(
912 VkPhysicalDevice physicalDevice,
913 VkPhysicalDeviceFeatures* pFeatures)
914 {
915 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
916
917 *pFeatures = (VkPhysicalDeviceFeatures) {
918 .robustBufferAccess = true,
919 .fullDrawIndexUint32 = true,
920 .imageCubeArray = true,
921 .independentBlend = true,
922 .geometryShader = true,
923 .tessellationShader = true,
924 .sampleRateShading = true,
925 .dualSrcBlend = true,
926 .logicOp = true,
927 .multiDrawIndirect = true,
928 .drawIndirectFirstInstance = true,
929 .depthClamp = true,
930 .depthBiasClamp = true,
931 .fillModeNonSolid = true,
932 .depthBounds = pdevice->info.gen >= 12,
933 .wideLines = true,
934 .largePoints = true,
935 .alphaToOne = true,
936 .multiViewport = true,
937 .samplerAnisotropy = true,
938 .textureCompressionETC2 = pdevice->info.gen >= 8 ||
939 pdevice->info.is_baytrail,
940 .textureCompressionASTC_LDR = pdevice->info.gen >= 9, /* FINISHME CHV */
941 .textureCompressionBC = true,
942 .occlusionQueryPrecise = true,
943 .pipelineStatisticsQuery = true,
944 .fragmentStoresAndAtomics = true,
945 .shaderTessellationAndGeometryPointSize = true,
946 .shaderImageGatherExtended = true,
947 .shaderStorageImageExtendedFormats = true,
948 .shaderStorageImageMultisample = false,
949 .shaderStorageImageReadWithoutFormat = false,
950 .shaderStorageImageWriteWithoutFormat = true,
951 .shaderUniformBufferArrayDynamicIndexing = true,
952 .shaderSampledImageArrayDynamicIndexing = true,
953 .shaderStorageBufferArrayDynamicIndexing = true,
954 .shaderStorageImageArrayDynamicIndexing = true,
955 .shaderClipDistance = true,
956 .shaderCullDistance = true,
957 .shaderFloat64 = pdevice->info.gen >= 8 &&
958 pdevice->info.has_64bit_float,
959 .shaderInt64 = pdevice->info.gen >= 8 &&
960 pdevice->info.has_64bit_int,
961 .shaderInt16 = pdevice->info.gen >= 8,
962 .shaderResourceMinLod = pdevice->info.gen >= 9,
963 .variableMultisampleRate = true,
964 .inheritedQueries = true,
965 };
966
967 /* We can't do image stores in vec4 shaders */
968 pFeatures->vertexPipelineStoresAndAtomics =
969 pdevice->compiler->scalar_stage[MESA_SHADER_VERTEX] &&
970 pdevice->compiler->scalar_stage[MESA_SHADER_GEOMETRY];
971
972 struct anv_app_info *app_info = &pdevice->instance->app_info;
973
974 /* The new DOOM and Wolfenstein games require depthBounds without
975 * checking for it. They seem to run fine without it so just claim it's
976 * there and accept the consequences.
977 */
978 if (app_info->engine_name && strcmp(app_info->engine_name, "idTech") == 0)
979 pFeatures->depthBounds = true;
980 }
981
982 static void
983 anv_get_physical_device_features_1_1(struct anv_physical_device *pdevice,
984 VkPhysicalDeviceVulkan11Features *f)
985 {
986 assert(f->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES);
987
988 f->storageBuffer16BitAccess = pdevice->info.gen >= 8;
989 f->uniformAndStorageBuffer16BitAccess = pdevice->info.gen >= 8;
990 f->storagePushConstant16 = pdevice->info.gen >= 8;
991 f->storageInputOutput16 = false;
992 f->multiview = true;
993 f->multiviewGeometryShader = true;
994 f->multiviewTessellationShader = true;
995 f->variablePointersStorageBuffer = true;
996 f->variablePointers = true;
997 f->protectedMemory = false;
998 f->samplerYcbcrConversion = true;
999 f->shaderDrawParameters = true;
1000 }
1001
1002 static void
1003 anv_get_physical_device_features_1_2(struct anv_physical_device *pdevice,
1004 VkPhysicalDeviceVulkan12Features *f)
1005 {
1006 assert(f->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES);
1007
1008 f->samplerMirrorClampToEdge = true;
1009 f->drawIndirectCount = true;
1010 f->storageBuffer8BitAccess = pdevice->info.gen >= 8;
1011 f->uniformAndStorageBuffer8BitAccess = pdevice->info.gen >= 8;
1012 f->storagePushConstant8 = pdevice->info.gen >= 8;
1013 f->shaderBufferInt64Atomics = pdevice->info.gen >= 9 &&
1014 pdevice->use_softpin;
1015 f->shaderSharedInt64Atomics = false;
1016 f->shaderFloat16 = pdevice->info.gen >= 8;
1017 f->shaderInt8 = pdevice->info.gen >= 8;
1018
1019 bool descIndexing = pdevice->has_a64_buffer_access &&
1020 pdevice->has_bindless_images;
1021 f->descriptorIndexing = descIndexing;
1022 f->shaderInputAttachmentArrayDynamicIndexing = false;
1023 f->shaderUniformTexelBufferArrayDynamicIndexing = descIndexing;
1024 f->shaderStorageTexelBufferArrayDynamicIndexing = descIndexing;
1025 f->shaderUniformBufferArrayNonUniformIndexing = false;
1026 f->shaderSampledImageArrayNonUniformIndexing = descIndexing;
1027 f->shaderStorageBufferArrayNonUniformIndexing = descIndexing;
1028 f->shaderStorageImageArrayNonUniformIndexing = descIndexing;
1029 f->shaderInputAttachmentArrayNonUniformIndexing = false;
1030 f->shaderUniformTexelBufferArrayNonUniformIndexing = descIndexing;
1031 f->shaderStorageTexelBufferArrayNonUniformIndexing = descIndexing;
1032 f->descriptorBindingUniformBufferUpdateAfterBind = false;
1033 f->descriptorBindingSampledImageUpdateAfterBind = descIndexing;
1034 f->descriptorBindingStorageImageUpdateAfterBind = descIndexing;
1035 f->descriptorBindingStorageBufferUpdateAfterBind = descIndexing;
1036 f->descriptorBindingUniformTexelBufferUpdateAfterBind = descIndexing;
1037 f->descriptorBindingStorageTexelBufferUpdateAfterBind = descIndexing;
1038 f->descriptorBindingUpdateUnusedWhilePending = descIndexing;
1039 f->descriptorBindingPartiallyBound = descIndexing;
1040 f->descriptorBindingVariableDescriptorCount = false;
1041 f->runtimeDescriptorArray = descIndexing;
1042
1043 f->samplerFilterMinmax = pdevice->info.gen >= 9;
1044 f->scalarBlockLayout = true;
1045 f->imagelessFramebuffer = true;
1046 f->uniformBufferStandardLayout = true;
1047 f->shaderSubgroupExtendedTypes = true;
1048 f->separateDepthStencilLayouts = true;
1049 f->hostQueryReset = true;
1050 f->timelineSemaphore = true;
1051 f->bufferDeviceAddress = pdevice->has_a64_buffer_access;
1052 f->bufferDeviceAddressCaptureReplay = pdevice->has_a64_buffer_access;
1053 f->bufferDeviceAddressMultiDevice = false;
1054 f->vulkanMemoryModel = true;
1055 f->vulkanMemoryModelDeviceScope = true;
1056 f->vulkanMemoryModelAvailabilityVisibilityChains = true;
1057 f->shaderOutputViewportIndex = true;
1058 f->shaderOutputLayer = true;
1059 f->subgroupBroadcastDynamicId = true;
1060 }
1061
1062 void anv_GetPhysicalDeviceFeatures2(
1063 VkPhysicalDevice physicalDevice,
1064 VkPhysicalDeviceFeatures2* pFeatures)
1065 {
1066 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
1067 anv_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
1068
1069 VkPhysicalDeviceVulkan11Features core_1_1 = {
1070 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES,
1071 };
1072 anv_get_physical_device_features_1_1(pdevice, &core_1_1);
1073
1074 VkPhysicalDeviceVulkan12Features core_1_2 = {
1075 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
1076 };
1077 anv_get_physical_device_features_1_2(pdevice, &core_1_2);
1078
1079 #define CORE_FEATURE(major, minor, feature) \
1080 features->feature = core_##major##_##minor.feature
1081
1082
1083 vk_foreach_struct(ext, pFeatures->pNext) {
1084 switch (ext->sType) {
1085 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT: {
1086 VkPhysicalDevice4444FormatsFeaturesEXT *features =
1087 (VkPhysicalDevice4444FormatsFeaturesEXT *)ext;
1088 features->formatA4R4G4B4 = true;
1089 features->formatA4B4G4R4 = false;
1090 break;
1091 }
1092
1093 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR: {
1094 VkPhysicalDevice8BitStorageFeaturesKHR *features =
1095 (VkPhysicalDevice8BitStorageFeaturesKHR *)ext;
1096 CORE_FEATURE(1, 2, storageBuffer8BitAccess);
1097 CORE_FEATURE(1, 2, uniformAndStorageBuffer8BitAccess);
1098 CORE_FEATURE(1, 2, storagePushConstant8);
1099 break;
1100 }
1101
1102 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
1103 VkPhysicalDevice16BitStorageFeatures *features =
1104 (VkPhysicalDevice16BitStorageFeatures *)ext;
1105 CORE_FEATURE(1, 1, storageBuffer16BitAccess);
1106 CORE_FEATURE(1, 1, uniformAndStorageBuffer16BitAccess);
1107 CORE_FEATURE(1, 1, storagePushConstant16);
1108 CORE_FEATURE(1, 1, storageInputOutput16);
1109 break;
1110 }
1111
1112 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT: {
1113 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT *features = (void *)ext;
1114 features->bufferDeviceAddress = pdevice->has_a64_buffer_access;
1115 features->bufferDeviceAddressCaptureReplay = false;
1116 features->bufferDeviceAddressMultiDevice = false;
1117 break;
1118 }
1119
1120 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR: {
1121 VkPhysicalDeviceBufferDeviceAddressFeaturesKHR *features = (void *)ext;
1122 CORE_FEATURE(1, 2, bufferDeviceAddress);
1123 CORE_FEATURE(1, 2, bufferDeviceAddressCaptureReplay);
1124 CORE_FEATURE(1, 2, bufferDeviceAddressMultiDevice);
1125 break;
1126 }
1127
1128 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV: {
1129 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *features =
1130 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *)ext;
1131 features->computeDerivativeGroupQuads = true;
1132 features->computeDerivativeGroupLinear = true;
1133 break;
1134 }
1135
1136 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT: {
1137 VkPhysicalDeviceConditionalRenderingFeaturesEXT *features =
1138 (VkPhysicalDeviceConditionalRenderingFeaturesEXT*)ext;
1139 features->conditionalRendering = pdevice->info.gen >= 8 ||
1140 pdevice->info.is_haswell;
1141 features->inheritedConditionalRendering = pdevice->info.gen >= 8 ||
1142 pdevice->info.is_haswell;
1143 break;
1144 }
1145
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT: {
1147 VkPhysicalDeviceCustomBorderColorFeaturesEXT *features =
1148 (VkPhysicalDeviceCustomBorderColorFeaturesEXT *)ext;
1149 features->customBorderColors = pdevice->info.gen >= 8;
1150 features->customBorderColorWithoutFormat = pdevice->info.gen >= 8;
1151 break;
1152 }
1153
1154 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT: {
1155 VkPhysicalDeviceDepthClipEnableFeaturesEXT *features =
1156 (VkPhysicalDeviceDepthClipEnableFeaturesEXT *)ext;
1157 features->depthClipEnable = true;
1158 break;
1159 }
1160
1161 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR: {
1162 VkPhysicalDeviceFloat16Int8FeaturesKHR *features = (void *)ext;
1163 CORE_FEATURE(1, 2, shaderFloat16);
1164 CORE_FEATURE(1, 2, shaderInt8);
1165 break;
1166 }
1167
1168 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT: {
1169 VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT *features =
1170 (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT *)ext;
1171 features->fragmentShaderSampleInterlock = pdevice->info.gen >= 9;
1172 features->fragmentShaderPixelInterlock = pdevice->info.gen >= 9;
1173 features->fragmentShaderShadingRateInterlock = false;
1174 break;
1175 }
1176
1177 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT: {
1178 VkPhysicalDeviceHostQueryResetFeaturesEXT *features =
1179 (VkPhysicalDeviceHostQueryResetFeaturesEXT *)ext;
1180 CORE_FEATURE(1, 2, hostQueryReset);
1181 break;
1182 }
1183
1184 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT: {
1185 VkPhysicalDeviceDescriptorIndexingFeaturesEXT *features =
1186 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT *)ext;
1187 CORE_FEATURE(1, 2, shaderInputAttachmentArrayDynamicIndexing);
1188 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayDynamicIndexing);
1189 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayDynamicIndexing);
1190 CORE_FEATURE(1, 2, shaderUniformBufferArrayNonUniformIndexing);
1191 CORE_FEATURE(1, 2, shaderSampledImageArrayNonUniformIndexing);
1192 CORE_FEATURE(1, 2, shaderStorageBufferArrayNonUniformIndexing);
1193 CORE_FEATURE(1, 2, shaderStorageImageArrayNonUniformIndexing);
1194 CORE_FEATURE(1, 2, shaderInputAttachmentArrayNonUniformIndexing);
1195 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayNonUniformIndexing);
1196 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayNonUniformIndexing);
1197 CORE_FEATURE(1, 2, descriptorBindingUniformBufferUpdateAfterBind);
1198 CORE_FEATURE(1, 2, descriptorBindingSampledImageUpdateAfterBind);
1199 CORE_FEATURE(1, 2, descriptorBindingStorageImageUpdateAfterBind);
1200 CORE_FEATURE(1, 2, descriptorBindingStorageBufferUpdateAfterBind);
1201 CORE_FEATURE(1, 2, descriptorBindingUniformTexelBufferUpdateAfterBind);
1202 CORE_FEATURE(1, 2, descriptorBindingStorageTexelBufferUpdateAfterBind);
1203 CORE_FEATURE(1, 2, descriptorBindingUpdateUnusedWhilePending);
1204 CORE_FEATURE(1, 2, descriptorBindingPartiallyBound);
1205 CORE_FEATURE(1, 2, descriptorBindingVariableDescriptorCount);
1206 CORE_FEATURE(1, 2, runtimeDescriptorArray);
1207 break;
1208 }
1209
1210 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES_EXT: {
1211 VkPhysicalDeviceImageRobustnessFeaturesEXT *features =
1212 (VkPhysicalDeviceImageRobustnessFeaturesEXT *)ext;
1213 features->robustImageAccess = true;
1214 break;
1215 }
1216
1217 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
1218 VkPhysicalDeviceIndexTypeUint8FeaturesEXT *features =
1219 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT *)ext;
1220 features->indexTypeUint8 = true;
1221 break;
1222 }
1223
1224 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: {
1225 VkPhysicalDeviceInlineUniformBlockFeaturesEXT *features =
1226 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT *)ext;
1227 features->inlineUniformBlock = true;
1228 features->descriptorBindingInlineUniformBlockUpdateAfterBind = true;
1229 break;
1230 }
1231
1232 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT: {
1233 VkPhysicalDeviceLineRasterizationFeaturesEXT *features =
1234 (VkPhysicalDeviceLineRasterizationFeaturesEXT *)ext;
1235 features->rectangularLines = true;
1236 features->bresenhamLines = true;
1237 /* Support for Smooth lines with MSAA was removed on gen11. From the
1238 * BSpec section "Multisample ModesState" table for "AA Line Support
1239 * Requirements":
1240 *
1241 * GEN10:BUG:######## NUM_MULTISAMPLES == 1
1242 *
1243 * Fortunately, this isn't a case most people care about.
1244 */
1245 features->smoothLines = pdevice->info.gen < 10;
1246 features->stippledRectangularLines = false;
1247 features->stippledBresenhamLines = true;
1248 features->stippledSmoothLines = false;
1249 break;
1250 }
1251
1252 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: {
1253 VkPhysicalDeviceMultiviewFeatures *features =
1254 (VkPhysicalDeviceMultiviewFeatures *)ext;
1255 CORE_FEATURE(1, 1, multiview);
1256 CORE_FEATURE(1, 1, multiviewGeometryShader);
1257 CORE_FEATURE(1, 1, multiviewTessellationShader);
1258 break;
1259 }
1260
1261 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR: {
1262 VkPhysicalDeviceImagelessFramebufferFeaturesKHR *features =
1263 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR *)ext;
1264 CORE_FEATURE(1, 2, imagelessFramebuffer);
1265 break;
1266 }
1267
1268 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_FEATURES_KHR: {
1269 VkPhysicalDevicePerformanceQueryFeaturesKHR *feature =
1270 (VkPhysicalDevicePerformanceQueryFeaturesKHR *)ext;
1271 feature->performanceCounterQueryPools = true;
1272 /* HW only supports a single configuration at a time. */
1273 feature->performanceCounterMultipleQueryPools = false;
1274 break;
1275 }
1276
1277 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES_EXT: {
1278 VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT *features =
1279 (VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT *)ext;
1280 features->pipelineCreationCacheControl = true;
1281 break;
1282 }
1283
1284 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR: {
1285 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR *features =
1286 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR *)ext;
1287 features->pipelineExecutableInfo = true;
1288 break;
1289 }
1290
1291 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT: {
1292 VkPhysicalDevicePrivateDataFeaturesEXT *features = (void *)ext;
1293 features->privateData = true;
1294 break;
1295 }
1296
1297 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
1298 VkPhysicalDeviceProtectedMemoryFeatures *features = (void *)ext;
1299 CORE_FEATURE(1, 1, protectedMemory);
1300 break;
1301 }
1302
1303 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT: {
1304 VkPhysicalDeviceRobustness2FeaturesEXT *features = (void *)ext;
1305 features->robustBufferAccess2 = true;
1306 features->robustImageAccess2 = true;
1307 features->nullDescriptor = true;
1308 break;
1309 }
1310
1311 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
1312 VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
1313 (VkPhysicalDeviceSamplerYcbcrConversionFeatures *) ext;
1314 CORE_FEATURE(1, 1, samplerYcbcrConversion);
1315 break;
1316 }
1317
1318 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT: {
1319 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT *features =
1320 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT *)ext;
1321 CORE_FEATURE(1, 2, scalarBlockLayout);
1322 break;
1323 }
1324
1325 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES_KHR: {
1326 VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR *features =
1327 (VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR *)ext;
1328 CORE_FEATURE(1, 2, separateDepthStencilLayouts);
1329 break;
1330 }
1331
1332 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT: {
1333 VkPhysicalDeviceShaderAtomicFloatFeaturesEXT *features = (void *)ext;
1334 features->shaderBufferFloat32Atomics = true;
1335 features->shaderBufferFloat32AtomicAdd = false;
1336 features->shaderBufferFloat64Atomics = false;
1337 features->shaderBufferFloat64AtomicAdd = false;
1338 features->shaderSharedFloat32Atomics = true;
1339 features->shaderSharedFloat32AtomicAdd = false;
1340 features->shaderSharedFloat64Atomics = false;
1341 features->shaderSharedFloat64AtomicAdd = false;
1342 features->shaderImageFloat32Atomics = true;
1343 features->shaderImageFloat32AtomicAdd = false;
1344 features->sparseImageFloat32Atomics = false;
1345 features->sparseImageFloat32AtomicAdd = false;
1346 break;
1347 }
1348
1349 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR: {
1350 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR *features = (void *)ext;
1351 CORE_FEATURE(1, 2, shaderBufferInt64Atomics);
1352 CORE_FEATURE(1, 2, shaderSharedInt64Atomics);
1353 break;
1354 }
1355
1356 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT: {
1357 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT *features = (void *)ext;
1358 features->shaderDemoteToHelperInvocation = true;
1359 break;
1360 }
1361
1362 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR: {
1363 VkPhysicalDeviceShaderClockFeaturesKHR *features =
1364 (VkPhysicalDeviceShaderClockFeaturesKHR *)ext;
1365 features->shaderSubgroupClock = true;
1366 features->shaderDeviceClock = false;
1367 break;
1368 }
1369
1370 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES: {
1371 VkPhysicalDeviceShaderDrawParametersFeatures *features = (void *)ext;
1372 CORE_FEATURE(1, 1, shaderDrawParameters);
1373 break;
1374 }
1375
1376 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL: {
1377 VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL *features =
1378 (VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL *)ext;
1379 features->shaderIntegerFunctions2 = true;
1380 break;
1381 }
1382
1383 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES_KHR: {
1384 VkPhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR *features =
1385 (VkPhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR *)ext;
1386 CORE_FEATURE(1, 2, shaderSubgroupExtendedTypes);
1387 break;
1388 }
1389
1390 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT: {
1391 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT *features =
1392 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT *)ext;
1393 features->subgroupSizeControl = true;
1394 features->computeFullSubgroups = true;
1395 break;
1396 }
1397
1398 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT: {
1399 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT *features =
1400 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT *)ext;
1401 features->texelBufferAlignment = true;
1402 break;
1403 }
1404
1405 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR: {
1406 VkPhysicalDeviceTimelineSemaphoreFeaturesKHR *features =
1407 (VkPhysicalDeviceTimelineSemaphoreFeaturesKHR *) ext;
1408 CORE_FEATURE(1, 2, timelineSemaphore);
1409 break;
1410 }
1411
1412 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES: {
1413 VkPhysicalDeviceVariablePointersFeatures *features = (void *)ext;
1414 CORE_FEATURE(1, 1, variablePointersStorageBuffer);
1415 CORE_FEATURE(1, 1, variablePointers);
1416 break;
1417 }
1418
1419 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT: {
1420 VkPhysicalDeviceTransformFeedbackFeaturesEXT *features =
1421 (VkPhysicalDeviceTransformFeedbackFeaturesEXT *)ext;
1422 features->transformFeedback = true;
1423 features->geometryStreams = true;
1424 break;
1425 }
1426
1427 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR: {
1428 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR *features =
1429 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR *)ext;
1430 CORE_FEATURE(1, 2, uniformBufferStandardLayout);
1431 break;
1432 }
1433
1434 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
1435 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *features =
1436 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *)ext;
1437 features->vertexAttributeInstanceRateDivisor = true;
1438 features->vertexAttributeInstanceRateZeroDivisor = true;
1439 break;
1440 }
1441
1442 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES:
1443 anv_get_physical_device_features_1_1(pdevice, (void *)ext);
1444 break;
1445
1446 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES:
1447 anv_get_physical_device_features_1_2(pdevice, (void *)ext);
1448 break;
1449
1450 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES_KHR: {
1451 VkPhysicalDeviceVulkanMemoryModelFeaturesKHR *features = (void *)ext;
1452 CORE_FEATURE(1, 2, vulkanMemoryModel);
1453 CORE_FEATURE(1, 2, vulkanMemoryModelDeviceScope);
1454 CORE_FEATURE(1, 2, vulkanMemoryModelAvailabilityVisibilityChains);
1455 break;
1456 }
1457
1458 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT: {
1459 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT *features =
1460 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT *)ext;
1461 features->ycbcrImageArrays = true;
1462 break;
1463 }
1464
1465 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT: {
1466 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *features =
1467 (VkPhysicalDeviceExtendedDynamicStateFeaturesEXT *)ext;
1468 features->extendedDynamicState = true;
1469 break;
1470 }
1471
1472 default:
1473 anv_debug_ignored_stype(ext->sType);
1474 break;
1475 }
1476 }
1477
1478 #undef CORE_FEATURE
1479 }
1480
1481 #define MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS 64
1482
1483 #define MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS 64
1484 #define MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS 256
1485
1486 #define MAX_CUSTOM_BORDER_COLORS 4096
1487
1488 void anv_GetPhysicalDeviceProperties(
1489 VkPhysicalDevice physicalDevice,
1490 VkPhysicalDeviceProperties* pProperties)
1491 {
1492 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
1493 const struct gen_device_info *devinfo = &pdevice->info;
1494
1495 /* See assertions made when programming the buffer surface state. */
1496 const uint32_t max_raw_buffer_sz = devinfo->gen >= 7 ?
1497 (1ul << 30) : (1ul << 27);
1498
1499 const uint32_t max_ssbos = pdevice->has_a64_buffer_access ? UINT16_MAX : 64;
1500 const uint32_t max_textures =
1501 pdevice->has_bindless_images ? UINT16_MAX : 128;
1502 const uint32_t max_samplers =
1503 pdevice->has_bindless_samplers ? UINT16_MAX :
1504 (devinfo->gen >= 8 || devinfo->is_haswell) ? 128 : 16;
1505 const uint32_t max_images =
1506 pdevice->has_bindless_images ? UINT16_MAX : MAX_IMAGES;
1507
1508 /* If we can use bindless for everything, claim a high per-stage limit,
1509 * otherwise use the binding table size, minus the slots reserved for
1510 * render targets and one slot for the descriptor buffer. */
1511 const uint32_t max_per_stage =
1512 pdevice->has_bindless_images && pdevice->has_a64_buffer_access
1513 ? UINT32_MAX : MAX_BINDING_TABLE_SIZE - MAX_RTS - 1;
1514
1515 /* Limit max_threads to 64 for the GPGPU_WALKER command */
1516 const uint32_t max_workgroup_size = 32 * MIN2(64, devinfo->max_cs_threads);
1517
1518 VkSampleCountFlags sample_counts =
1519 isl_device_get_sample_counts(&pdevice->isl_dev);
1520
1521
1522 VkPhysicalDeviceLimits limits = {
1523 .maxImageDimension1D = (1 << 14),
1524 .maxImageDimension2D = (1 << 14),
1525 .maxImageDimension3D = (1 << 11),
1526 .maxImageDimensionCube = (1 << 14),
1527 .maxImageArrayLayers = (1 << 11),
1528 .maxTexelBufferElements = 128 * 1024 * 1024,
1529 .maxUniformBufferRange = (1ul << 27),
1530 .maxStorageBufferRange = max_raw_buffer_sz,
1531 .maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE,
1532 .maxMemoryAllocationCount = UINT32_MAX,
1533 .maxSamplerAllocationCount = 64 * 1024,
1534 .bufferImageGranularity = 64, /* A cache line */
1535 .sparseAddressSpaceSize = 0,
1536 .maxBoundDescriptorSets = MAX_SETS,
1537 .maxPerStageDescriptorSamplers = max_samplers,
1538 .maxPerStageDescriptorUniformBuffers = MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS,
1539 .maxPerStageDescriptorStorageBuffers = max_ssbos,
1540 .maxPerStageDescriptorSampledImages = max_textures,
1541 .maxPerStageDescriptorStorageImages = max_images,
1542 .maxPerStageDescriptorInputAttachments = MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS,
1543 .maxPerStageResources = max_per_stage,
1544 .maxDescriptorSetSamplers = 6 * max_samplers, /* number of stages * maxPerStageDescriptorSamplers */
1545 .maxDescriptorSetUniformBuffers = 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS, /* number of stages * maxPerStageDescriptorUniformBuffers */
1546 .maxDescriptorSetUniformBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2,
1547 .maxDescriptorSetStorageBuffers = 6 * max_ssbos, /* number of stages * maxPerStageDescriptorStorageBuffers */
1548 .maxDescriptorSetStorageBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2,
1549 .maxDescriptorSetSampledImages = 6 * max_textures, /* number of stages * maxPerStageDescriptorSampledImages */
1550 .maxDescriptorSetStorageImages = 6 * max_images, /* number of stages * maxPerStageDescriptorStorageImages */
1551 .maxDescriptorSetInputAttachments = MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS,
1552 .maxVertexInputAttributes = MAX_VBS,
1553 .maxVertexInputBindings = MAX_VBS,
1554 .maxVertexInputAttributeOffset = 2047,
1555 .maxVertexInputBindingStride = 2048,
1556 .maxVertexOutputComponents = 128,
1557 .maxTessellationGenerationLevel = 64,
1558 .maxTessellationPatchSize = 32,
1559 .maxTessellationControlPerVertexInputComponents = 128,
1560 .maxTessellationControlPerVertexOutputComponents = 128,
1561 .maxTessellationControlPerPatchOutputComponents = 128,
1562 .maxTessellationControlTotalOutputComponents = 2048,
1563 .maxTessellationEvaluationInputComponents = 128,
1564 .maxTessellationEvaluationOutputComponents = 128,
1565 .maxGeometryShaderInvocations = 32,
1566 .maxGeometryInputComponents = 64,
1567 .maxGeometryOutputComponents = 128,
1568 .maxGeometryOutputVertices = 256,
1569 .maxGeometryTotalOutputComponents = 1024,
1570 .maxFragmentInputComponents = 116, /* 128 components - (PSIZ, CLIP_DIST0, CLIP_DIST1) */
1571 .maxFragmentOutputAttachments = 8,
1572 .maxFragmentDualSrcAttachments = 1,
1573 .maxFragmentCombinedOutputResources = 8,
1574 .maxComputeSharedMemorySize = 64 * 1024,
1575 .maxComputeWorkGroupCount = { 65535, 65535, 65535 },
1576 .maxComputeWorkGroupInvocations = max_workgroup_size,
1577 .maxComputeWorkGroupSize = {
1578 max_workgroup_size,
1579 max_workgroup_size,
1580 max_workgroup_size,
1581 },
1582 .subPixelPrecisionBits = 8,
1583 .subTexelPrecisionBits = 8,
1584 .mipmapPrecisionBits = 8,
1585 .maxDrawIndexedIndexValue = UINT32_MAX,
1586 .maxDrawIndirectCount = UINT32_MAX,
1587 .maxSamplerLodBias = 16,
1588 .maxSamplerAnisotropy = 16,
1589 .maxViewports = MAX_VIEWPORTS,
1590 .maxViewportDimensions = { (1 << 14), (1 << 14) },
1591 .viewportBoundsRange = { INT16_MIN, INT16_MAX },
1592 .viewportSubPixelBits = 13, /* We take a float? */
1593 .minMemoryMapAlignment = 4096, /* A page */
1594 /* The dataport requires texel alignment so we need to assume a worst
1595 * case of R32G32B32A32 which is 16 bytes.
1596 */
1597 .minTexelBufferOffsetAlignment = 16,
1598 .minUniformBufferOffsetAlignment = ANV_UBO_ALIGNMENT,
1599 .minStorageBufferOffsetAlignment = 4,
1600 .minTexelOffset = -8,
1601 .maxTexelOffset = 7,
1602 .minTexelGatherOffset = -32,
1603 .maxTexelGatherOffset = 31,
1604 .minInterpolationOffset = -0.5,
1605 .maxInterpolationOffset = 0.4375,
1606 .subPixelInterpolationOffsetBits = 4,
1607 .maxFramebufferWidth = (1 << 14),
1608 .maxFramebufferHeight = (1 << 14),
1609 .maxFramebufferLayers = (1 << 11),
1610 .framebufferColorSampleCounts = sample_counts,
1611 .framebufferDepthSampleCounts = sample_counts,
1612 .framebufferStencilSampleCounts = sample_counts,
1613 .framebufferNoAttachmentsSampleCounts = sample_counts,
1614 .maxColorAttachments = MAX_RTS,
1615 .sampledImageColorSampleCounts = sample_counts,
1616 .sampledImageIntegerSampleCounts = sample_counts,
1617 .sampledImageDepthSampleCounts = sample_counts,
1618 .sampledImageStencilSampleCounts = sample_counts,
1619 .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT,
1620 .maxSampleMaskWords = 1,
1621 .timestampComputeAndGraphics = true,
1622 .timestampPeriod = 1000000000.0 / devinfo->timestamp_frequency,
1623 .maxClipDistances = 8,
1624 .maxCullDistances = 8,
1625 .maxCombinedClipAndCullDistances = 8,
1626 .discreteQueuePriorities = 2,
1627 .pointSizeRange = { 0.125, 255.875 },
1628 .lineWidthRange = {
1629 0.0,
1630 (devinfo->gen >= 9 || devinfo->is_cherryview) ?
1631 2047.9921875 : 7.9921875,
1632 },
1633 .pointSizeGranularity = (1.0 / 8.0),
1634 .lineWidthGranularity = (1.0 / 128.0),
1635 .strictLines = false,
1636 .standardSampleLocations = true,
1637 .optimalBufferCopyOffsetAlignment = 128,
1638 .optimalBufferCopyRowPitchAlignment = 128,
1639 .nonCoherentAtomSize = 64,
1640 };
1641
1642 *pProperties = (VkPhysicalDeviceProperties) {
1643 .apiVersion = anv_physical_device_api_version(pdevice),
1644 .driverVersion = vk_get_driver_version(),
1645 .vendorID = 0x8086,
1646 .deviceID = pdevice->info.chipset_id,
1647 .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
1648 .limits = limits,
1649 .sparseProperties = {0}, /* Broadwell doesn't do sparse. */
1650 };
1651
1652 snprintf(pProperties->deviceName, sizeof(pProperties->deviceName),
1653 "%s", pdevice->name);
1654 memcpy(pProperties->pipelineCacheUUID,
1655 pdevice->pipeline_cache_uuid, VK_UUID_SIZE);
1656 }
1657
1658 static void
1659 anv_get_physical_device_properties_1_1(struct anv_physical_device *pdevice,
1660 VkPhysicalDeviceVulkan11Properties *p)
1661 {
1662 assert(p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES);
1663
1664 memcpy(p->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
1665 memcpy(p->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
1666 memset(p->deviceLUID, 0, VK_LUID_SIZE);
1667 p->deviceNodeMask = 0;
1668 p->deviceLUIDValid = false;
1669
1670 p->subgroupSize = BRW_SUBGROUP_SIZE;
1671 VkShaderStageFlags scalar_stages = 0;
1672 for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) {
1673 if (pdevice->compiler->scalar_stage[stage])
1674 scalar_stages |= mesa_to_vk_shader_stage(stage);
1675 }
1676 p->subgroupSupportedStages = scalar_stages;
1677 p->subgroupSupportedOperations = VK_SUBGROUP_FEATURE_BASIC_BIT |
1678 VK_SUBGROUP_FEATURE_VOTE_BIT |
1679 VK_SUBGROUP_FEATURE_BALLOT_BIT |
1680 VK_SUBGROUP_FEATURE_SHUFFLE_BIT |
1681 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT |
1682 VK_SUBGROUP_FEATURE_QUAD_BIT;
1683 if (pdevice->info.gen >= 8) {
1684 /* TODO: There's no technical reason why these can't be made to
1685 * work on gen7 but they don't at the moment so it's best to leave
1686 * the feature disabled than enabled and broken.
1687 */
1688 p->subgroupSupportedOperations |= VK_SUBGROUP_FEATURE_ARITHMETIC_BIT |
1689 VK_SUBGROUP_FEATURE_CLUSTERED_BIT;
1690 }
1691 p->subgroupQuadOperationsInAllStages = pdevice->info.gen >= 8;
1692
1693 p->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY;
1694 p->maxMultiviewViewCount = 16;
1695 p->maxMultiviewInstanceIndex = UINT32_MAX / 16;
1696 p->protectedNoFault = false;
1697 /* This value doesn't matter for us today as our per-stage descriptors are
1698 * the real limit.
1699 */
1700 p->maxPerSetDescriptors = 1024;
1701 p->maxMemoryAllocationSize = MAX_MEMORY_ALLOCATION_SIZE;
1702 }
1703
1704 static void
1705 anv_get_physical_device_properties_1_2(struct anv_physical_device *pdevice,
1706 VkPhysicalDeviceVulkan12Properties *p)
1707 {
1708 assert(p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES);
1709
1710 p->driverID = VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR;
1711 memset(p->driverName, 0, sizeof(p->driverName));
1712 snprintf(p->driverName, VK_MAX_DRIVER_NAME_SIZE_KHR,
1713 "Intel open-source Mesa driver");
1714 memset(p->driverInfo, 0, sizeof(p->driverInfo));
1715 snprintf(p->driverInfo, VK_MAX_DRIVER_INFO_SIZE_KHR,
1716 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1);
1717 p->conformanceVersion = (VkConformanceVersionKHR) {
1718 .major = 1,
1719 .minor = 2,
1720 .subminor = 0,
1721 .patch = 0,
1722 };
1723
1724 p->denormBehaviorIndependence =
1725 VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR;
1726 p->roundingModeIndependence =
1727 VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE_KHR;
1728
1729 /* Broadwell does not support HF denorms and there are restrictions
1730 * other gens. According to Kabylake's PRM:
1731 *
1732 * "math - Extended Math Function
1733 * [...]
1734 * Restriction : Half-float denorms are always retained."
1735 */
1736 p->shaderDenormFlushToZeroFloat16 = false;
1737 p->shaderDenormPreserveFloat16 = pdevice->info.gen > 8;
1738 p->shaderRoundingModeRTEFloat16 = true;
1739 p->shaderRoundingModeRTZFloat16 = true;
1740 p->shaderSignedZeroInfNanPreserveFloat16 = true;
1741
1742 p->shaderDenormFlushToZeroFloat32 = true;
1743 p->shaderDenormPreserveFloat32 = true;
1744 p->shaderRoundingModeRTEFloat32 = true;
1745 p->shaderRoundingModeRTZFloat32 = true;
1746 p->shaderSignedZeroInfNanPreserveFloat32 = true;
1747
1748 p->shaderDenormFlushToZeroFloat64 = true;
1749 p->shaderDenormPreserveFloat64 = true;
1750 p->shaderRoundingModeRTEFloat64 = true;
1751 p->shaderRoundingModeRTZFloat64 = true;
1752 p->shaderSignedZeroInfNanPreserveFloat64 = true;
1753
1754 /* It's a bit hard to exactly map our implementation to the limits
1755 * described here. The bindless surface handle in the extended
1756 * message descriptors is 20 bits and it's an index into the table of
1757 * RENDER_SURFACE_STATE structs that starts at bindless surface base
1758 * address. Given that most things consume two surface states per
1759 * view (general/sampled for textures and write-only/read-write for
1760 * images), we claim 2^19 things.
1761 *
1762 * For SSBOs, we just use A64 messages so there is no real limit
1763 * there beyond the limit on the total size of a descriptor set.
1764 */
1765 const unsigned max_bindless_views = 1 << 19;
1766 p->maxUpdateAfterBindDescriptorsInAllPools = max_bindless_views;
1767 p->shaderUniformBufferArrayNonUniformIndexingNative = false;
1768 p->shaderSampledImageArrayNonUniformIndexingNative = false;
1769 p->shaderStorageBufferArrayNonUniformIndexingNative = true;
1770 p->shaderStorageImageArrayNonUniformIndexingNative = false;
1771 p->shaderInputAttachmentArrayNonUniformIndexingNative = false;
1772 p->robustBufferAccessUpdateAfterBind = true;
1773 p->quadDivergentImplicitLod = false;
1774 p->maxPerStageDescriptorUpdateAfterBindSamplers = max_bindless_views;
1775 p->maxPerStageDescriptorUpdateAfterBindUniformBuffers = MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS;
1776 p->maxPerStageDescriptorUpdateAfterBindStorageBuffers = UINT32_MAX;
1777 p->maxPerStageDescriptorUpdateAfterBindSampledImages = max_bindless_views;
1778 p->maxPerStageDescriptorUpdateAfterBindStorageImages = max_bindless_views;
1779 p->maxPerStageDescriptorUpdateAfterBindInputAttachments = MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS;
1780 p->maxPerStageUpdateAfterBindResources = UINT32_MAX;
1781 p->maxDescriptorSetUpdateAfterBindSamplers = max_bindless_views;
1782 p->maxDescriptorSetUpdateAfterBindUniformBuffers = 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS;
1783 p->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2;
1784 p->maxDescriptorSetUpdateAfterBindStorageBuffers = UINT32_MAX;
1785 p->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = MAX_DYNAMIC_BUFFERS / 2;
1786 p->maxDescriptorSetUpdateAfterBindSampledImages = max_bindless_views;
1787 p->maxDescriptorSetUpdateAfterBindStorageImages = max_bindless_views;
1788 p->maxDescriptorSetUpdateAfterBindInputAttachments = MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS;
1789
1790 /* We support all of the depth resolve modes */
1791 p->supportedDepthResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR |
1792 VK_RESOLVE_MODE_AVERAGE_BIT_KHR |
1793 VK_RESOLVE_MODE_MIN_BIT_KHR |
1794 VK_RESOLVE_MODE_MAX_BIT_KHR;
1795 /* Average doesn't make sense for stencil so we don't support that */
1796 p->supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1797 if (pdevice->info.gen >= 8) {
1798 /* The advanced stencil resolve modes currently require stencil
1799 * sampling be supported by the hardware.
1800 */
1801 p->supportedStencilResolveModes |= VK_RESOLVE_MODE_MIN_BIT_KHR |
1802 VK_RESOLVE_MODE_MAX_BIT_KHR;
1803 }
1804 p->independentResolveNone = true;
1805 p->independentResolve = true;
1806
1807 p->filterMinmaxSingleComponentFormats = pdevice->info.gen >= 9;
1808 p->filterMinmaxImageComponentMapping = pdevice->info.gen >= 9;
1809
1810 p->maxTimelineSemaphoreValueDifference = UINT64_MAX;
1811
1812 p->framebufferIntegerColorSampleCounts =
1813 isl_device_get_sample_counts(&pdevice->isl_dev);
1814 }
1815
1816 void anv_GetPhysicalDeviceProperties2(
1817 VkPhysicalDevice physicalDevice,
1818 VkPhysicalDeviceProperties2* pProperties)
1819 {
1820 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
1821
1822 anv_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
1823
1824 VkPhysicalDeviceVulkan11Properties core_1_1 = {
1825 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES,
1826 };
1827 anv_get_physical_device_properties_1_1(pdevice, &core_1_1);
1828
1829 VkPhysicalDeviceVulkan12Properties core_1_2 = {
1830 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES,
1831 };
1832 anv_get_physical_device_properties_1_2(pdevice, &core_1_2);
1833
1834 #define CORE_RENAMED_PROPERTY(major, minor, ext_property, core_property) \
1835 memcpy(&properties->ext_property, &core_##major##_##minor.core_property, \
1836 sizeof(core_##major##_##minor.core_property))
1837
1838 #define CORE_PROPERTY(major, minor, property) \
1839 CORE_RENAMED_PROPERTY(major, minor, property, property)
1840
1841 vk_foreach_struct(ext, pProperties->pNext) {
1842 switch (ext->sType) {
1843 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT: {
1844 VkPhysicalDeviceCustomBorderColorPropertiesEXT *properties =
1845 (VkPhysicalDeviceCustomBorderColorPropertiesEXT *)ext;
1846 properties->maxCustomBorderColorSamplers = MAX_CUSTOM_BORDER_COLORS;
1847 break;
1848 }
1849
1850 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR: {
1851 VkPhysicalDeviceDepthStencilResolvePropertiesKHR *properties =
1852 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR *)ext;
1853 CORE_PROPERTY(1, 2, supportedDepthResolveModes);
1854 CORE_PROPERTY(1, 2, supportedStencilResolveModes);
1855 CORE_PROPERTY(1, 2, independentResolveNone);
1856 CORE_PROPERTY(1, 2, independentResolve);
1857 break;
1858 }
1859
1860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT: {
1861 VkPhysicalDeviceDescriptorIndexingPropertiesEXT *properties =
1862 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT *)ext;
1863 CORE_PROPERTY(1, 2, maxUpdateAfterBindDescriptorsInAllPools);
1864 CORE_PROPERTY(1, 2, shaderUniformBufferArrayNonUniformIndexingNative);
1865 CORE_PROPERTY(1, 2, shaderSampledImageArrayNonUniformIndexingNative);
1866 CORE_PROPERTY(1, 2, shaderStorageBufferArrayNonUniformIndexingNative);
1867 CORE_PROPERTY(1, 2, shaderStorageImageArrayNonUniformIndexingNative);
1868 CORE_PROPERTY(1, 2, shaderInputAttachmentArrayNonUniformIndexingNative);
1869 CORE_PROPERTY(1, 2, robustBufferAccessUpdateAfterBind);
1870 CORE_PROPERTY(1, 2, quadDivergentImplicitLod);
1871 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSamplers);
1872 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindUniformBuffers);
1873 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageBuffers);
1874 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSampledImages);
1875 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageImages);
1876 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindInputAttachments);
1877 CORE_PROPERTY(1, 2, maxPerStageUpdateAfterBindResources);
1878 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSamplers);
1879 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffers);
1880 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffersDynamic);
1881 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffers);
1882 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffersDynamic);
1883 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSampledImages);
1884 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageImages);
1885 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindInputAttachments);
1886 break;
1887 }
1888
1889 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR: {
1890 VkPhysicalDeviceDriverPropertiesKHR *properties =
1891 (VkPhysicalDeviceDriverPropertiesKHR *) ext;
1892 CORE_PROPERTY(1, 2, driverID);
1893 CORE_PROPERTY(1, 2, driverName);
1894 CORE_PROPERTY(1, 2, driverInfo);
1895 CORE_PROPERTY(1, 2, conformanceVersion);
1896 break;
1897 }
1898
1899 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT: {
1900 VkPhysicalDeviceExternalMemoryHostPropertiesEXT *props =
1901 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT *) ext;
1902 /* Userptr needs page aligned memory. */
1903 props->minImportedHostPointerAlignment = 4096;
1904 break;
1905 }
1906
1907 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: {
1908 VkPhysicalDeviceIDProperties *properties =
1909 (VkPhysicalDeviceIDProperties *)ext;
1910 CORE_PROPERTY(1, 1, deviceUUID);
1911 CORE_PROPERTY(1, 1, driverUUID);
1912 CORE_PROPERTY(1, 1, deviceLUID);
1913 CORE_PROPERTY(1, 1, deviceLUIDValid);
1914 break;
1915 }
1916
1917 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT: {
1918 VkPhysicalDeviceInlineUniformBlockPropertiesEXT *props =
1919 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT *)ext;
1920 props->maxInlineUniformBlockSize = MAX_INLINE_UNIFORM_BLOCK_SIZE;
1921 props->maxPerStageDescriptorInlineUniformBlocks =
1922 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS;
1923 props->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks =
1924 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS;
1925 props->maxDescriptorSetInlineUniformBlocks =
1926 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS;
1927 props->maxDescriptorSetUpdateAfterBindInlineUniformBlocks =
1928 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS;
1929 break;
1930 }
1931
1932 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT: {
1933 VkPhysicalDeviceLineRasterizationPropertiesEXT *props =
1934 (VkPhysicalDeviceLineRasterizationPropertiesEXT *)ext;
1935 /* In the Skylake PRM Vol. 7, subsection titled "GIQ (Diamond)
1936 * Sampling Rules - Legacy Mode", it says the following:
1937 *
1938 * "Note that the device divides a pixel into a 16x16 array of
1939 * subpixels, referenced by their upper left corners."
1940 *
1941 * This is the only known reference in the PRMs to the subpixel
1942 * precision of line rasterization and a "16x16 array of subpixels"
1943 * implies 4 subpixel precision bits. Empirical testing has shown
1944 * that 4 subpixel precision bits applies to all line rasterization
1945 * types.
1946 */
1947 props->lineSubPixelPrecisionBits = 4;
1948 break;
1949 }
1950
1951 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
1952 VkPhysicalDeviceMaintenance3Properties *properties =
1953 (VkPhysicalDeviceMaintenance3Properties *)ext;
1954 /* This value doesn't matter for us today as our per-stage
1955 * descriptors are the real limit.
1956 */
1957 CORE_PROPERTY(1, 1, maxPerSetDescriptors);
1958 CORE_PROPERTY(1, 1, maxMemoryAllocationSize);
1959 break;
1960 }
1961
1962 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES: {
1963 VkPhysicalDeviceMultiviewProperties *properties =
1964 (VkPhysicalDeviceMultiviewProperties *)ext;
1965 CORE_PROPERTY(1, 1, maxMultiviewViewCount);
1966 CORE_PROPERTY(1, 1, maxMultiviewInstanceIndex);
1967 break;
1968 }
1969
1970 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT: {
1971 VkPhysicalDevicePCIBusInfoPropertiesEXT *properties =
1972 (VkPhysicalDevicePCIBusInfoPropertiesEXT *)ext;
1973 properties->pciDomain = pdevice->pci_info.domain;
1974 properties->pciBus = pdevice->pci_info.bus;
1975 properties->pciDevice = pdevice->pci_info.device;
1976 properties->pciFunction = pdevice->pci_info.function;
1977 break;
1978 }
1979
1980 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_PROPERTIES_KHR: {
1981 VkPhysicalDevicePerformanceQueryPropertiesKHR *properties =
1982 (VkPhysicalDevicePerformanceQueryPropertiesKHR *)ext;
1983 /* We could support this by spawning a shader to do the equation
1984 * normalization.
1985 */
1986 properties->allowCommandBufferQueryCopies = false;
1987 break;
1988 }
1989
1990 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES: {
1991 VkPhysicalDevicePointClippingProperties *properties =
1992 (VkPhysicalDevicePointClippingProperties *) ext;
1993 CORE_PROPERTY(1, 1, pointClippingBehavior);
1994 break;
1995 }
1996
1997 #pragma GCC diagnostic push
1998 #pragma GCC diagnostic ignored "-Wswitch"
1999 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID: {
2000 VkPhysicalDevicePresentationPropertiesANDROID *props =
2001 (VkPhysicalDevicePresentationPropertiesANDROID *)ext;
2002 props->sharedImage = VK_FALSE;
2003 break;
2004 }
2005 #pragma GCC diagnostic pop
2006
2007 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES: {
2008 VkPhysicalDeviceProtectedMemoryProperties *properties =
2009 (VkPhysicalDeviceProtectedMemoryProperties *)ext;
2010 CORE_PROPERTY(1, 1, protectedNoFault);
2011 break;
2012 }
2013
2014 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
2015 VkPhysicalDevicePushDescriptorPropertiesKHR *properties =
2016 (VkPhysicalDevicePushDescriptorPropertiesKHR *) ext;
2017 properties->maxPushDescriptors = MAX_PUSH_DESCRIPTORS;
2018 break;
2019 }
2020
2021 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_PROPERTIES_EXT: {
2022 VkPhysicalDeviceRobustness2PropertiesEXT *properties = (void *)ext;
2023 properties->robustStorageBufferAccessSizeAlignment =
2024 ANV_SSBO_BOUNDS_CHECK_ALIGNMENT;
2025 properties->robustUniformBufferAccessSizeAlignment =
2026 ANV_UBO_ALIGNMENT;
2027 break;
2028 }
2029
2030 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT: {
2031 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT *properties =
2032 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT *)ext;
2033 CORE_PROPERTY(1, 2, filterMinmaxImageComponentMapping);
2034 CORE_PROPERTY(1, 2, filterMinmaxSingleComponentFormats);
2035 break;
2036 }
2037
2038 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES: {
2039 VkPhysicalDeviceSubgroupProperties *properties = (void *)ext;
2040 CORE_PROPERTY(1, 1, subgroupSize);
2041 CORE_RENAMED_PROPERTY(1, 1, supportedStages,
2042 subgroupSupportedStages);
2043 CORE_RENAMED_PROPERTY(1, 1, supportedOperations,
2044 subgroupSupportedOperations);
2045 CORE_RENAMED_PROPERTY(1, 1, quadOperationsInAllStages,
2046 subgroupQuadOperationsInAllStages);
2047 break;
2048 }
2049
2050 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT: {
2051 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT *props =
2052 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT *)ext;
2053 STATIC_ASSERT(8 <= BRW_SUBGROUP_SIZE && BRW_SUBGROUP_SIZE <= 32);
2054 props->minSubgroupSize = 8;
2055 props->maxSubgroupSize = 32;
2056 props->maxComputeWorkgroupSubgroups = pdevice->info.max_cs_threads;
2057 props->requiredSubgroupSizeStages = VK_SHADER_STAGE_COMPUTE_BIT;
2058 break;
2059 }
2060 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR : {
2061 VkPhysicalDeviceFloatControlsPropertiesKHR *properties = (void *)ext;
2062 CORE_PROPERTY(1, 2, denormBehaviorIndependence);
2063 CORE_PROPERTY(1, 2, roundingModeIndependence);
2064 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat16);
2065 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat16);
2066 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat16);
2067 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat16);
2068 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat16);
2069 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat32);
2070 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat32);
2071 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat32);
2072 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat32);
2073 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat32);
2074 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat64);
2075 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat64);
2076 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat64);
2077 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat64);
2078 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat64);
2079 break;
2080 }
2081
2082 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT: {
2083 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT *props =
2084 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT *)ext;
2085
2086 /* From the SKL PRM Vol. 2d, docs for RENDER_SURFACE_STATE::Surface
2087 * Base Address:
2088 *
2089 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field
2090 * specifies the base address of the first element of the surface,
2091 * computed in software by adding the surface base address to the
2092 * byte offset of the element in the buffer. The base address must
2093 * be aligned to element size."
2094 *
2095 * The typed dataport messages require that things be texel aligned.
2096 * Otherwise, we may just load/store the wrong data or, in the worst
2097 * case, there may be hangs.
2098 */
2099 props->storageTexelBufferOffsetAlignmentBytes = 16;
2100 props->storageTexelBufferOffsetSingleTexelAlignment = true;
2101
2102 /* The sampler, however, is much more forgiving and it can handle
2103 * arbitrary byte alignment for linear and buffer surfaces. It's
2104 * hard to find a good PRM citation for this but years of empirical
2105 * experience demonstrate that this is true.
2106 */
2107 props->uniformTexelBufferOffsetAlignmentBytes = 1;
2108 props->uniformTexelBufferOffsetSingleTexelAlignment = false;
2109 break;
2110 }
2111
2112 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES_KHR: {
2113 VkPhysicalDeviceTimelineSemaphorePropertiesKHR *properties =
2114 (VkPhysicalDeviceTimelineSemaphorePropertiesKHR *) ext;
2115 CORE_PROPERTY(1, 2, maxTimelineSemaphoreValueDifference);
2116 break;
2117 }
2118
2119 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT: {
2120 VkPhysicalDeviceTransformFeedbackPropertiesEXT *props =
2121 (VkPhysicalDeviceTransformFeedbackPropertiesEXT *)ext;
2122
2123 props->maxTransformFeedbackStreams = MAX_XFB_STREAMS;
2124 props->maxTransformFeedbackBuffers = MAX_XFB_BUFFERS;
2125 props->maxTransformFeedbackBufferSize = (1ull << 32);
2126 props->maxTransformFeedbackStreamDataSize = 128 * 4;
2127 props->maxTransformFeedbackBufferDataSize = 128 * 4;
2128 props->maxTransformFeedbackBufferDataStride = 2048;
2129 props->transformFeedbackQueries = true;
2130 props->transformFeedbackStreamsLinesTriangles = false;
2131 props->transformFeedbackRasterizationStreamSelect = false;
2132 props->transformFeedbackDraw = true;
2133 break;
2134 }
2135
2136 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
2137 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *props =
2138 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *)ext;
2139 /* We have to restrict this a bit for multiview */
2140 props->maxVertexAttribDivisor = UINT32_MAX / 16;
2141 break;
2142 }
2143
2144 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES:
2145 anv_get_physical_device_properties_1_1(pdevice, (void *)ext);
2146 break;
2147
2148 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES:
2149 anv_get_physical_device_properties_1_2(pdevice, (void *)ext);
2150 break;
2151
2152 default:
2153 anv_debug_ignored_stype(ext->sType);
2154 break;
2155 }
2156 }
2157
2158 #undef CORE_RENAMED_PROPERTY
2159 #undef CORE_PROPERTY
2160 }
2161
2162 /* We support exactly one queue family. */
2163 static const VkQueueFamilyProperties
2164 anv_queue_family_properties = {
2165 .queueFlags = VK_QUEUE_GRAPHICS_BIT |
2166 VK_QUEUE_COMPUTE_BIT |
2167 VK_QUEUE_TRANSFER_BIT,
2168 .queueCount = 1,
2169 .timestampValidBits = 36, /* XXX: Real value here */
2170 .minImageTransferGranularity = { 1, 1, 1 },
2171 };
2172
2173 void anv_GetPhysicalDeviceQueueFamilyProperties(
2174 VkPhysicalDevice physicalDevice,
2175 uint32_t* pCount,
2176 VkQueueFamilyProperties* pQueueFamilyProperties)
2177 {
2178 VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pCount);
2179
2180 vk_outarray_append(&out, p) {
2181 *p = anv_queue_family_properties;
2182 }
2183 }
2184
2185 void anv_GetPhysicalDeviceQueueFamilyProperties2(
2186 VkPhysicalDevice physicalDevice,
2187 uint32_t* pQueueFamilyPropertyCount,
2188 VkQueueFamilyProperties2* pQueueFamilyProperties)
2189 {
2190
2191 VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount);
2192
2193 vk_outarray_append(&out, p) {
2194 p->queueFamilyProperties = anv_queue_family_properties;
2195
2196 vk_foreach_struct(s, p->pNext) {
2197 anv_debug_ignored_stype(s->sType);
2198 }
2199 }
2200 }
2201
2202 void anv_GetPhysicalDeviceMemoryProperties(
2203 VkPhysicalDevice physicalDevice,
2204 VkPhysicalDeviceMemoryProperties* pMemoryProperties)
2205 {
2206 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
2207
2208 pMemoryProperties->memoryTypeCount = physical_device->memory.type_count;
2209 for (uint32_t i = 0; i < physical_device->memory.type_count; i++) {
2210 pMemoryProperties->memoryTypes[i] = (VkMemoryType) {
2211 .propertyFlags = physical_device->memory.types[i].propertyFlags,
2212 .heapIndex = physical_device->memory.types[i].heapIndex,
2213 };
2214 }
2215
2216 pMemoryProperties->memoryHeapCount = physical_device->memory.heap_count;
2217 for (uint32_t i = 0; i < physical_device->memory.heap_count; i++) {
2218 pMemoryProperties->memoryHeaps[i] = (VkMemoryHeap) {
2219 .size = physical_device->memory.heaps[i].size,
2220 .flags = physical_device->memory.heaps[i].flags,
2221 };
2222 }
2223 }
2224
2225 static void
2226 anv_get_memory_budget(VkPhysicalDevice physicalDevice,
2227 VkPhysicalDeviceMemoryBudgetPropertiesEXT *memoryBudget)
2228 {
2229 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
2230 uint64_t sys_available = get_available_system_memory();
2231 assert(sys_available > 0);
2232
2233 VkDeviceSize total_heaps_size = 0;
2234 for (size_t i = 0; i < device->memory.heap_count; i++)
2235 total_heaps_size += device->memory.heaps[i].size;
2236
2237 for (size_t i = 0; i < device->memory.heap_count; i++) {
2238 VkDeviceSize heap_size = device->memory.heaps[i].size;
2239 VkDeviceSize heap_used = device->memory.heaps[i].used;
2240 VkDeviceSize heap_budget;
2241
2242 double heap_proportion = (double) heap_size / total_heaps_size;
2243 VkDeviceSize sys_available_prop = sys_available * heap_proportion;
2244
2245 /*
2246 * Let's not incite the app to starve the system: report at most 90% of
2247 * available system memory.
2248 */
2249 uint64_t heap_available = sys_available_prop * 9 / 10;
2250 heap_budget = MIN2(heap_size, heap_used + heap_available);
2251
2252 /*
2253 * Round down to the nearest MB
2254 */
2255 heap_budget &= ~((1ull << 20) - 1);
2256
2257 /*
2258 * The heapBudget value must be non-zero for array elements less than
2259 * VkPhysicalDeviceMemoryProperties::memoryHeapCount. The heapBudget
2260 * value must be less than or equal to VkMemoryHeap::size for each heap.
2261 */
2262 assert(0 < heap_budget && heap_budget <= heap_size);
2263
2264 memoryBudget->heapUsage[i] = heap_used;
2265 memoryBudget->heapBudget[i] = heap_budget;
2266 }
2267
2268 /* The heapBudget and heapUsage values must be zero for array elements
2269 * greater than or equal to VkPhysicalDeviceMemoryProperties::memoryHeapCount
2270 */
2271 for (uint32_t i = device->memory.heap_count; i < VK_MAX_MEMORY_HEAPS; i++) {
2272 memoryBudget->heapBudget[i] = 0;
2273 memoryBudget->heapUsage[i] = 0;
2274 }
2275 }
2276
2277 void anv_GetPhysicalDeviceMemoryProperties2(
2278 VkPhysicalDevice physicalDevice,
2279 VkPhysicalDeviceMemoryProperties2* pMemoryProperties)
2280 {
2281 anv_GetPhysicalDeviceMemoryProperties(physicalDevice,
2282 &pMemoryProperties->memoryProperties);
2283
2284 vk_foreach_struct(ext, pMemoryProperties->pNext) {
2285 switch (ext->sType) {
2286 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT:
2287 anv_get_memory_budget(physicalDevice, (void*)ext);
2288 break;
2289 default:
2290 anv_debug_ignored_stype(ext->sType);
2291 break;
2292 }
2293 }
2294 }
2295
2296 void
2297 anv_GetDeviceGroupPeerMemoryFeatures(
2298 VkDevice device,
2299 uint32_t heapIndex,
2300 uint32_t localDeviceIndex,
2301 uint32_t remoteDeviceIndex,
2302 VkPeerMemoryFeatureFlags* pPeerMemoryFeatures)
2303 {
2304 assert(localDeviceIndex == 0 && remoteDeviceIndex == 0);
2305 *pPeerMemoryFeatures = VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT |
2306 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT |
2307 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT |
2308 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT;
2309 }
2310
2311 PFN_vkVoidFunction anv_GetInstanceProcAddr(
2312 VkInstance _instance,
2313 const char* pName)
2314 {
2315 ANV_FROM_HANDLE(anv_instance, instance, _instance);
2316
2317 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
2318 * when we have to return valid function pointers, NULL, or it's left
2319 * undefined. See the table for exact details.
2320 */
2321 if (pName == NULL)
2322 return NULL;
2323
2324 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
2325 if (strcmp(pName, "vk" #entrypoint) == 0) \
2326 return (PFN_vkVoidFunction)anv_##entrypoint
2327
2328 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties);
2329 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties);
2330 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion);
2331 LOOKUP_ANV_ENTRYPOINT(CreateInstance);
2332
2333 /* GetInstanceProcAddr() can also be called with a NULL instance.
2334 * See https://gitlab.khronos.org/vulkan/vulkan/issues/2057
2335 */
2336 LOOKUP_ANV_ENTRYPOINT(GetInstanceProcAddr);
2337
2338 #undef LOOKUP_ANV_ENTRYPOINT
2339
2340 if (instance == NULL)
2341 return NULL;
2342
2343 int idx = anv_get_instance_entrypoint_index(pName);
2344 if (idx >= 0)
2345 return instance->dispatch.entrypoints[idx];
2346
2347 idx = anv_get_physical_device_entrypoint_index(pName);
2348 if (idx >= 0)
2349 return instance->physical_device_dispatch.entrypoints[idx];
2350
2351 idx = anv_get_device_entrypoint_index(pName);
2352 if (idx >= 0)
2353 return instance->device_dispatch.entrypoints[idx];
2354
2355 return NULL;
2356 }
2357
2358 /* With version 1+ of the loader interface the ICD should expose
2359 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
2360 */
2361 PUBLIC
2362 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
2363 VkInstance instance,
2364 const char* pName);
2365
2366 PUBLIC
2367 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
2368 VkInstance instance,
2369 const char* pName)
2370 {
2371 return anv_GetInstanceProcAddr(instance, pName);
2372 }
2373
2374 PFN_vkVoidFunction anv_GetDeviceProcAddr(
2375 VkDevice _device,
2376 const char* pName)
2377 {
2378 ANV_FROM_HANDLE(anv_device, device, _device);
2379
2380 if (!device || !pName)
2381 return NULL;
2382
2383 int idx = anv_get_device_entrypoint_index(pName);
2384 if (idx < 0)
2385 return NULL;
2386
2387 return device->dispatch.entrypoints[idx];
2388 }
2389
2390 /* With version 4+ of the loader interface the ICD should expose
2391 * vk_icdGetPhysicalDeviceProcAddr()
2392 */
2393 PUBLIC
2394 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(
2395 VkInstance _instance,
2396 const char* pName);
2397
2398 PFN_vkVoidFunction vk_icdGetPhysicalDeviceProcAddr(
2399 VkInstance _instance,
2400 const char* pName)
2401 {
2402 ANV_FROM_HANDLE(anv_instance, instance, _instance);
2403
2404 if (!pName || !instance)
2405 return NULL;
2406
2407 int idx = anv_get_physical_device_entrypoint_index(pName);
2408 if (idx < 0)
2409 return NULL;
2410
2411 return instance->physical_device_dispatch.entrypoints[idx];
2412 }
2413
2414
2415 VkResult
2416 anv_CreateDebugReportCallbackEXT(VkInstance _instance,
2417 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
2418 const VkAllocationCallbacks* pAllocator,
2419 VkDebugReportCallbackEXT* pCallback)
2420 {
2421 ANV_FROM_HANDLE(anv_instance, instance, _instance);
2422 return vk_create_debug_report_callback(&instance->debug_report_callbacks,
2423 pCreateInfo, pAllocator, &instance->alloc,
2424 pCallback);
2425 }
2426
2427 void
2428 anv_DestroyDebugReportCallbackEXT(VkInstance _instance,
2429 VkDebugReportCallbackEXT _callback,
2430 const VkAllocationCallbacks* pAllocator)
2431 {
2432 ANV_FROM_HANDLE(anv_instance, instance, _instance);
2433 vk_destroy_debug_report_callback(&instance->debug_report_callbacks,
2434 _callback, pAllocator, &instance->alloc);
2435 }
2436
2437 void
2438 anv_DebugReportMessageEXT(VkInstance _instance,
2439 VkDebugReportFlagsEXT flags,
2440 VkDebugReportObjectTypeEXT objectType,
2441 uint64_t object,
2442 size_t location,
2443 int32_t messageCode,
2444 const char* pLayerPrefix,
2445 const char* pMessage)
2446 {
2447 ANV_FROM_HANDLE(anv_instance, instance, _instance);
2448 vk_debug_report(&instance->debug_report_callbacks, flags, objectType,
2449 object, location, messageCode, pLayerPrefix, pMessage);
2450 }
2451
2452 static struct anv_state
2453 anv_state_pool_emit_data(struct anv_state_pool *pool, size_t size, size_t align, const void *p)
2454 {
2455 struct anv_state state;
2456
2457 state = anv_state_pool_alloc(pool, size, align);
2458 memcpy(state.map, p, size);
2459
2460 return state;
2461 }
2462
2463 static void
2464 anv_device_init_border_colors(struct anv_device *device)
2465 {
2466 if (device->info.is_haswell) {
2467 static const struct hsw_border_color border_colors[] = {
2468 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 0.0 } },
2469 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 1.0 } },
2470 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] = { .float32 = { 1.0, 1.0, 1.0, 1.0 } },
2471 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] = { .uint32 = { 0, 0, 0, 0 } },
2472 [VK_BORDER_COLOR_INT_OPAQUE_BLACK] = { .uint32 = { 0, 0, 0, 1 } },
2473 [VK_BORDER_COLOR_INT_OPAQUE_WHITE] = { .uint32 = { 1, 1, 1, 1 } },
2474 };
2475
2476 device->border_colors =
2477 anv_state_pool_emit_data(&device->dynamic_state_pool,
2478 sizeof(border_colors), 512, border_colors);
2479 } else {
2480 static const struct gen8_border_color border_colors[] = {
2481 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 0.0 } },
2482 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK] = { .float32 = { 0.0, 0.0, 0.0, 1.0 } },
2483 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE] = { .float32 = { 1.0, 1.0, 1.0, 1.0 } },
2484 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK] = { .uint32 = { 0, 0, 0, 0 } },
2485 [VK_BORDER_COLOR_INT_OPAQUE_BLACK] = { .uint32 = { 0, 0, 0, 1 } },
2486 [VK_BORDER_COLOR_INT_OPAQUE_WHITE] = { .uint32 = { 1, 1, 1, 1 } },
2487 };
2488
2489 device->border_colors =
2490 anv_state_pool_emit_data(&device->dynamic_state_pool,
2491 sizeof(border_colors), 64, border_colors);
2492 }
2493 }
2494
2495 static VkResult
2496 anv_device_init_trivial_batch(struct anv_device *device)
2497 {
2498 VkResult result = anv_device_alloc_bo(device, 4096,
2499 ANV_BO_ALLOC_MAPPED,
2500 0 /* explicit_address */,
2501 &device->trivial_batch_bo);
2502 if (result != VK_SUCCESS)
2503 return result;
2504
2505 struct anv_batch batch = {
2506 .start = device->trivial_batch_bo->map,
2507 .next = device->trivial_batch_bo->map,
2508 .end = device->trivial_batch_bo->map + 4096,
2509 };
2510
2511 anv_batch_emit(&batch, GEN7_MI_BATCH_BUFFER_END, bbe);
2512 anv_batch_emit(&batch, GEN7_MI_NOOP, noop);
2513
2514 if (!device->info.has_llc)
2515 gen_clflush_range(batch.start, batch.next - batch.start);
2516
2517 return VK_SUCCESS;
2518 }
2519
2520 VkResult anv_EnumerateDeviceExtensionProperties(
2521 VkPhysicalDevice physicalDevice,
2522 const char* pLayerName,
2523 uint32_t* pPropertyCount,
2524 VkExtensionProperties* pProperties)
2525 {
2526 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
2527 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
2528
2529 for (int i = 0; i < ANV_DEVICE_EXTENSION_COUNT; i++) {
2530 if (device->supported_extensions.extensions[i]) {
2531 vk_outarray_append(&out, prop) {
2532 *prop = anv_device_extensions[i];
2533 }
2534 }
2535 }
2536
2537 return vk_outarray_status(&out);
2538 }
2539
2540 static int
2541 vk_priority_to_gen(int priority)
2542 {
2543 switch (priority) {
2544 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT:
2545 return GEN_CONTEXT_LOW_PRIORITY;
2546 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT:
2547 return GEN_CONTEXT_MEDIUM_PRIORITY;
2548 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT:
2549 return GEN_CONTEXT_HIGH_PRIORITY;
2550 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT:
2551 return GEN_CONTEXT_REALTIME_PRIORITY;
2552 default:
2553 unreachable("Invalid priority");
2554 }
2555 }
2556
2557 static VkResult
2558 anv_device_init_hiz_clear_value_bo(struct anv_device *device)
2559 {
2560 VkResult result = anv_device_alloc_bo(device, 4096,
2561 ANV_BO_ALLOC_MAPPED,
2562 0 /* explicit_address */,
2563 &device->hiz_clear_bo);
2564 if (result != VK_SUCCESS)
2565 return result;
2566
2567 union isl_color_value hiz_clear = { .u32 = { 0, } };
2568 hiz_clear.f32[0] = ANV_HZ_FC_VAL;
2569
2570 memcpy(device->hiz_clear_bo->map, hiz_clear.u32, sizeof(hiz_clear.u32));
2571
2572 if (!device->info.has_llc)
2573 gen_clflush_range(device->hiz_clear_bo->map, sizeof(hiz_clear.u32));
2574
2575 return VK_SUCCESS;
2576 }
2577
2578 static bool
2579 get_bo_from_pool(struct gen_batch_decode_bo *ret,
2580 struct anv_block_pool *pool,
2581 uint64_t address)
2582 {
2583 anv_block_pool_foreach_bo(bo, pool) {
2584 uint64_t bo_address = gen_48b_address(bo->offset);
2585 if (address >= bo_address && address < (bo_address + bo->size)) {
2586 *ret = (struct gen_batch_decode_bo) {
2587 .addr = bo_address,
2588 .size = bo->size,
2589 .map = bo->map,
2590 };
2591 return true;
2592 }
2593 }
2594 return false;
2595 }
2596
2597 /* Finding a buffer for batch decoding */
2598 static struct gen_batch_decode_bo
2599 decode_get_bo(void *v_batch, bool ppgtt, uint64_t address)
2600 {
2601 struct anv_device *device = v_batch;
2602 struct gen_batch_decode_bo ret_bo = {};
2603
2604 assert(ppgtt);
2605
2606 if (get_bo_from_pool(&ret_bo, &device->dynamic_state_pool.block_pool, address))
2607 return ret_bo;
2608 if (get_bo_from_pool(&ret_bo, &device->instruction_state_pool.block_pool, address))
2609 return ret_bo;
2610 if (get_bo_from_pool(&ret_bo, &device->binding_table_pool.block_pool, address))
2611 return ret_bo;
2612 if (get_bo_from_pool(&ret_bo, &device->surface_state_pool.block_pool, address))
2613 return ret_bo;
2614
2615 if (!device->cmd_buffer_being_decoded)
2616 return (struct gen_batch_decode_bo) { };
2617
2618 struct anv_batch_bo **bo;
2619
2620 u_vector_foreach(bo, &device->cmd_buffer_being_decoded->seen_bbos) {
2621 /* The decoder zeroes out the top 16 bits, so we need to as well */
2622 uint64_t bo_address = (*bo)->bo->offset & (~0ull >> 16);
2623
2624 if (address >= bo_address && address < bo_address + (*bo)->bo->size) {
2625 return (struct gen_batch_decode_bo) {
2626 .addr = bo_address,
2627 .size = (*bo)->bo->size,
2628 .map = (*bo)->bo->map,
2629 };
2630 }
2631 }
2632
2633 return (struct gen_batch_decode_bo) { };
2634 }
2635
2636 struct gen_aux_map_buffer {
2637 struct gen_buffer base;
2638 struct anv_state state;
2639 };
2640
2641 static struct gen_buffer *
2642 gen_aux_map_buffer_alloc(void *driver_ctx, uint32_t size)
2643 {
2644 struct gen_aux_map_buffer *buf = malloc(sizeof(struct gen_aux_map_buffer));
2645 if (!buf)
2646 return NULL;
2647
2648 struct anv_device *device = (struct anv_device*)driver_ctx;
2649 assert(device->physical->supports_48bit_addresses &&
2650 device->physical->use_softpin);
2651
2652 struct anv_state_pool *pool = &device->dynamic_state_pool;
2653 buf->state = anv_state_pool_alloc(pool, size, size);
2654
2655 buf->base.gpu = pool->block_pool.bo->offset + buf->state.offset;
2656 buf->base.gpu_end = buf->base.gpu + buf->state.alloc_size;
2657 buf->base.map = buf->state.map;
2658 buf->base.driver_bo = &buf->state;
2659 return &buf->base;
2660 }
2661
2662 static void
2663 gen_aux_map_buffer_free(void *driver_ctx, struct gen_buffer *buffer)
2664 {
2665 struct gen_aux_map_buffer *buf = (struct gen_aux_map_buffer*)buffer;
2666 struct anv_device *device = (struct anv_device*)driver_ctx;
2667 struct anv_state_pool *pool = &device->dynamic_state_pool;
2668 anv_state_pool_free(pool, buf->state);
2669 free(buf);
2670 }
2671
2672 static struct gen_mapped_pinned_buffer_alloc aux_map_allocator = {
2673 .alloc = gen_aux_map_buffer_alloc,
2674 .free = gen_aux_map_buffer_free,
2675 };
2676
2677 static VkResult
2678 check_physical_device_features(VkPhysicalDevice physicalDevice,
2679 const VkPhysicalDeviceFeatures *features)
2680 {
2681 VkPhysicalDeviceFeatures supported_features;
2682 anv_GetPhysicalDeviceFeatures(physicalDevice, &supported_features);
2683 VkBool32 *supported_feature = (VkBool32 *)&supported_features;
2684 VkBool32 *enabled_feature = (VkBool32 *)features;
2685 unsigned num_features = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
2686 for (uint32_t i = 0; i < num_features; i++) {
2687 if (enabled_feature[i] && !supported_feature[i])
2688 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT);
2689 }
2690
2691 return VK_SUCCESS;
2692 }
2693
2694 VkResult anv_CreateDevice(
2695 VkPhysicalDevice physicalDevice,
2696 const VkDeviceCreateInfo* pCreateInfo,
2697 const VkAllocationCallbacks* pAllocator,
2698 VkDevice* pDevice)
2699 {
2700 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
2701 VkResult result;
2702 struct anv_device *device;
2703
2704 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
2705
2706 struct anv_device_extension_table enabled_extensions = { };
2707 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
2708 int idx;
2709 for (idx = 0; idx < ANV_DEVICE_EXTENSION_COUNT; idx++) {
2710 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
2711 anv_device_extensions[idx].extensionName) == 0)
2712 break;
2713 }
2714
2715 if (idx >= ANV_DEVICE_EXTENSION_COUNT)
2716 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
2717
2718 if (!physical_device->supported_extensions.extensions[idx])
2719 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
2720
2721 enabled_extensions.extensions[idx] = true;
2722 }
2723
2724 /* Check enabled features */
2725 bool robust_buffer_access = false;
2726 if (pCreateInfo->pEnabledFeatures) {
2727 result = check_physical_device_features(physicalDevice,
2728 pCreateInfo->pEnabledFeatures);
2729 if (result != VK_SUCCESS)
2730 return result;
2731
2732 if (pCreateInfo->pEnabledFeatures->robustBufferAccess)
2733 robust_buffer_access = true;
2734 }
2735
2736 vk_foreach_struct_const(ext, pCreateInfo->pNext) {
2737 switch (ext->sType) {
2738 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2: {
2739 const VkPhysicalDeviceFeatures2 *features = (const void *)ext;
2740 result = check_physical_device_features(physicalDevice,
2741 &features->features);
2742 if (result != VK_SUCCESS)
2743 return result;
2744
2745 if (features->features.robustBufferAccess)
2746 robust_buffer_access = true;
2747 break;
2748 }
2749
2750 default:
2751 /* Don't warn */
2752 break;
2753 }
2754 }
2755
2756 /* Check requested queues and fail if we are requested to create any
2757 * queues with flags we don't support.
2758 */
2759 assert(pCreateInfo->queueCreateInfoCount > 0);
2760 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
2761 if (pCreateInfo->pQueueCreateInfos[i].flags != 0)
2762 return vk_error(VK_ERROR_INITIALIZATION_FAILED);
2763 }
2764
2765 /* Check if client specified queue priority. */
2766 const VkDeviceQueueGlobalPriorityCreateInfoEXT *queue_priority =
2767 vk_find_struct_const(pCreateInfo->pQueueCreateInfos[0].pNext,
2768 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT);
2769
2770 VkQueueGlobalPriorityEXT priority =
2771 queue_priority ? queue_priority->globalPriority :
2772 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
2773
2774 device = vk_alloc2(&physical_device->instance->alloc, pAllocator,
2775 sizeof(*device), 8,
2776 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
2777 if (!device)
2778 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
2779
2780 vk_device_init(&device->vk, pCreateInfo,
2781 &physical_device->instance->alloc, pAllocator);
2782
2783 if (INTEL_DEBUG & DEBUG_BATCH) {
2784 const unsigned decode_flags =
2785 GEN_BATCH_DECODE_FULL |
2786 ((INTEL_DEBUG & DEBUG_COLOR) ? GEN_BATCH_DECODE_IN_COLOR : 0) |
2787 GEN_BATCH_DECODE_OFFSETS |
2788 GEN_BATCH_DECODE_FLOATS;
2789
2790 gen_batch_decode_ctx_init(&device->decoder_ctx,
2791 &physical_device->info,
2792 stderr, decode_flags, NULL,
2793 decode_get_bo, NULL, device);
2794 }
2795
2796 device->physical = physical_device;
2797 device->no_hw = physical_device->no_hw;
2798 device->_lost = false;
2799
2800 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
2801 device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
2802 if (device->fd == -1) {
2803 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2804 goto fail_device;
2805 }
2806
2807 device->context_id = anv_gem_create_context(device);
2808 if (device->context_id == -1) {
2809 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2810 goto fail_fd;
2811 }
2812
2813 result = anv_queue_init(device, &device->queue);
2814 if (result != VK_SUCCESS)
2815 goto fail_context_id;
2816
2817 if (physical_device->use_softpin) {
2818 if (pthread_mutex_init(&device->vma_mutex, NULL) != 0) {
2819 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2820 goto fail_queue;
2821 }
2822
2823 /* keep the page with address zero out of the allocator */
2824 util_vma_heap_init(&device->vma_lo,
2825 LOW_HEAP_MIN_ADDRESS, LOW_HEAP_SIZE);
2826
2827 util_vma_heap_init(&device->vma_cva, CLIENT_VISIBLE_HEAP_MIN_ADDRESS,
2828 CLIENT_VISIBLE_HEAP_SIZE);
2829
2830 /* Leave the last 4GiB out of the high vma range, so that no state
2831 * base address + size can overflow 48 bits. For more information see
2832 * the comment about Wa32bitGeneralStateOffset in anv_allocator.c
2833 */
2834 util_vma_heap_init(&device->vma_hi, HIGH_HEAP_MIN_ADDRESS,
2835 physical_device->gtt_size - (1ull << 32) -
2836 HIGH_HEAP_MIN_ADDRESS);
2837 }
2838
2839 list_inithead(&device->memory_objects);
2840
2841 /* As per spec, the driver implementation may deny requests to acquire
2842 * a priority above the default priority (MEDIUM) if the caller does not
2843 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
2844 * is returned.
2845 */
2846 if (physical_device->has_context_priority) {
2847 int err = anv_gem_set_context_param(device->fd, device->context_id,
2848 I915_CONTEXT_PARAM_PRIORITY,
2849 vk_priority_to_gen(priority));
2850 if (err != 0 && priority > VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT) {
2851 result = vk_error(VK_ERROR_NOT_PERMITTED_EXT);
2852 goto fail_vmas;
2853 }
2854 }
2855
2856 device->info = physical_device->info;
2857 device->isl_dev = physical_device->isl_dev;
2858
2859 /* On Broadwell and later, we can use batch chaining to more efficiently
2860 * implement growing command buffers. Prior to Haswell, the kernel
2861 * command parser gets in the way and we have to fall back to growing
2862 * the batch.
2863 */
2864 device->can_chain_batches = device->info.gen >= 8;
2865
2866 device->robust_buffer_access = robust_buffer_access;
2867 device->enabled_extensions = enabled_extensions;
2868
2869 const struct anv_instance *instance = physical_device->instance;
2870 for (unsigned i = 0; i < ARRAY_SIZE(device->dispatch.entrypoints); i++) {
2871 /* Vulkan requires that entrypoints for extensions which have not been
2872 * enabled must not be advertised.
2873 */
2874 if (!anv_device_entrypoint_is_enabled(i, instance->app_info.api_version,
2875 &instance->enabled_extensions,
2876 &device->enabled_extensions)) {
2877 device->dispatch.entrypoints[i] = NULL;
2878 } else {
2879 device->dispatch.entrypoints[i] =
2880 anv_resolve_device_entrypoint(&device->info, i);
2881 }
2882 }
2883
2884 if (pthread_mutex_init(&device->mutex, NULL) != 0) {
2885 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2886 goto fail_queue;
2887 }
2888
2889 pthread_condattr_t condattr;
2890 if (pthread_condattr_init(&condattr) != 0) {
2891 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2892 goto fail_mutex;
2893 }
2894 if (pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC) != 0) {
2895 pthread_condattr_destroy(&condattr);
2896 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2897 goto fail_mutex;
2898 }
2899 if (pthread_cond_init(&device->queue_submit, &condattr) != 0) {
2900 pthread_condattr_destroy(&condattr);
2901 result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
2902 goto fail_mutex;
2903 }
2904 pthread_condattr_destroy(&condattr);
2905
2906 result = anv_bo_cache_init(&device->bo_cache);
2907 if (result != VK_SUCCESS)
2908 goto fail_queue_cond;
2909
2910 anv_bo_pool_init(&device->batch_bo_pool, device);
2911
2912 result = anv_state_pool_init(&device->dynamic_state_pool, device,
2913 DYNAMIC_STATE_POOL_MIN_ADDRESS, 0, 16384);
2914 if (result != VK_SUCCESS)
2915 goto fail_batch_bo_pool;
2916
2917 if (device->info.gen >= 8) {
2918 /* The border color pointer is limited to 24 bits, so we need to make
2919 * sure that any such color used at any point in the program doesn't
2920 * exceed that limit.
2921 * We achieve that by reserving all the custom border colors we support
2922 * right off the bat, so they are close to the base address.
2923 */
2924 anv_state_reserved_pool_init(&device->custom_border_colors,
2925 &device->dynamic_state_pool,
2926 MAX_CUSTOM_BORDER_COLORS,
2927 sizeof(struct gen8_border_color), 64);
2928 }
2929
2930 result = anv_state_pool_init(&device->instruction_state_pool, device,
2931 INSTRUCTION_STATE_POOL_MIN_ADDRESS, 0, 16384);
2932 if (result != VK_SUCCESS)
2933 goto fail_dynamic_state_pool;
2934
2935 result = anv_state_pool_init(&device->surface_state_pool, device,
2936 SURFACE_STATE_POOL_MIN_ADDRESS, 0, 4096);
2937 if (result != VK_SUCCESS)
2938 goto fail_instruction_state_pool;
2939
2940 if (physical_device->use_softpin) {
2941 int64_t bt_pool_offset = (int64_t)BINDING_TABLE_POOL_MIN_ADDRESS -
2942 (int64_t)SURFACE_STATE_POOL_MIN_ADDRESS;
2943 assert(INT32_MIN < bt_pool_offset && bt_pool_offset < 0);
2944 result = anv_state_pool_init(&device->binding_table_pool, device,
2945 SURFACE_STATE_POOL_MIN_ADDRESS,
2946 bt_pool_offset, 4096);
2947 if (result != VK_SUCCESS)
2948 goto fail_surface_state_pool;
2949 }
2950
2951 if (device->info.has_aux_map) {
2952 device->aux_map_ctx = gen_aux_map_init(device, &aux_map_allocator,
2953 &physical_device->info);
2954 if (!device->aux_map_ctx)
2955 goto fail_binding_table_pool;
2956 }
2957
2958 result = anv_device_alloc_bo(device, 4096,
2959 ANV_BO_ALLOC_CAPTURE | ANV_BO_ALLOC_MAPPED /* flags */,
2960 0 /* explicit_address */,
2961 &device->workaround_bo);
2962 if (result != VK_SUCCESS)
2963 goto fail_surface_aux_map_pool;
2964
2965 device->workaround_address = (struct anv_address) {
2966 .bo = device->workaround_bo,
2967 .offset = align_u32(
2968 intel_debug_write_identifiers(device->workaround_bo->map,
2969 device->workaround_bo->size,
2970 "Anv") + 8, 8),
2971 };
2972
2973 device->debug_frame_desc =
2974 intel_debug_get_identifier_block(device->workaround_bo->map,
2975 device->workaround_bo->size,
2976 GEN_DEBUG_BLOCK_TYPE_FRAME);
2977
2978 result = anv_device_init_trivial_batch(device);
2979 if (result != VK_SUCCESS)
2980 goto fail_workaround_bo;
2981
2982 /* Allocate a null surface state at surface state offset 0. This makes
2983 * NULL descriptor handling trivial because we can just memset structures
2984 * to zero and they have a valid descriptor.
2985 */
2986 device->null_surface_state =
2987 anv_state_pool_alloc(&device->surface_state_pool,
2988 device->isl_dev.ss.size,
2989 device->isl_dev.ss.align);
2990 isl_null_fill_state(&device->isl_dev, device->null_surface_state.map,
2991 isl_extent3d(1, 1, 1) /* This shouldn't matter */);
2992 assert(device->null_surface_state.offset == 0);
2993
2994 if (device->info.gen >= 10) {
2995 result = anv_device_init_hiz_clear_value_bo(device);
2996 if (result != VK_SUCCESS)
2997 goto fail_trivial_batch_bo;
2998 }
2999
3000 anv_scratch_pool_init(device, &device->scratch_pool);
3001
3002 switch (device->info.gen) {
3003 case 7:
3004 if (!device->info.is_haswell)
3005 result = gen7_init_device_state(device);
3006 else
3007 result = gen75_init_device_state(device);
3008 break;
3009 case 8:
3010 result = gen8_init_device_state(device);
3011 break;
3012 case 9:
3013 result = gen9_init_device_state(device);
3014 break;
3015 case 10:
3016 result = gen10_init_device_state(device);
3017 break;
3018 case 11:
3019 result = gen11_init_device_state(device);
3020 break;
3021 case 12:
3022 result = gen12_init_device_state(device);
3023 break;
3024 default:
3025 /* Shouldn't get here as we don't create physical devices for any other
3026 * gens. */
3027 unreachable("unhandled gen");
3028 }
3029 if (result != VK_SUCCESS)
3030 goto fail_clear_value_bo;
3031
3032 anv_pipeline_cache_init(&device->default_pipeline_cache, device,
3033 true /* cache_enabled */, false /* external_sync */);
3034
3035 anv_device_init_blorp(device);
3036
3037 anv_device_init_border_colors(device);
3038
3039 anv_device_perf_init(device);
3040
3041 *pDevice = anv_device_to_handle(device);
3042
3043 return VK_SUCCESS;
3044
3045 fail_clear_value_bo:
3046 if (device->info.gen >= 10)
3047 anv_device_release_bo(device, device->hiz_clear_bo);
3048 anv_scratch_pool_finish(device, &device->scratch_pool);
3049 fail_trivial_batch_bo:
3050 anv_device_release_bo(device, device->trivial_batch_bo);
3051 fail_workaround_bo:
3052 anv_device_release_bo(device, device->workaround_bo);
3053 fail_surface_aux_map_pool:
3054 if (device->info.has_aux_map) {
3055 gen_aux_map_finish(device->aux_map_ctx);
3056 device->aux_map_ctx = NULL;
3057 }
3058 fail_binding_table_pool:
3059 if (physical_device->use_softpin)
3060 anv_state_pool_finish(&device->binding_table_pool);
3061 fail_surface_state_pool:
3062 anv_state_pool_finish(&device->surface_state_pool);
3063 fail_instruction_state_pool:
3064 anv_state_pool_finish(&device->instruction_state_pool);
3065 fail_dynamic_state_pool:
3066 if (device->info.gen >= 8)
3067 anv_state_reserved_pool_finish(&device->custom_border_colors);
3068 anv_state_pool_finish(&device->dynamic_state_pool);
3069 fail_batch_bo_pool:
3070 anv_bo_pool_finish(&device->batch_bo_pool);
3071 anv_bo_cache_finish(&device->bo_cache);
3072 fail_queue_cond:
3073 pthread_cond_destroy(&device->queue_submit);
3074 fail_mutex:
3075 pthread_mutex_destroy(&device->mutex);
3076 fail_vmas:
3077 if (physical_device->use_softpin) {
3078 util_vma_heap_finish(&device->vma_hi);
3079 util_vma_heap_finish(&device->vma_cva);
3080 util_vma_heap_finish(&device->vma_lo);
3081 }
3082 fail_queue:
3083 anv_queue_finish(&device->queue);
3084 fail_context_id:
3085 anv_gem_destroy_context(device, device->context_id);
3086 fail_fd:
3087 close(device->fd);
3088 fail_device:
3089 vk_free(&device->vk.alloc, device);
3090
3091 return result;
3092 }
3093
3094 void anv_DestroyDevice(
3095 VkDevice _device,
3096 const VkAllocationCallbacks* pAllocator)
3097 {
3098 ANV_FROM_HANDLE(anv_device, device, _device);
3099
3100 if (!device)
3101 return;
3102
3103 anv_device_finish_blorp(device);
3104
3105 anv_pipeline_cache_finish(&device->default_pipeline_cache);
3106
3107 anv_queue_finish(&device->queue);
3108
3109 #ifdef HAVE_VALGRIND
3110 /* We only need to free these to prevent valgrind errors. The backing
3111 * BO will go away in a couple of lines so we don't actually leak.
3112 */
3113 if (device->info.gen >= 8)
3114 anv_state_reserved_pool_finish(&device->custom_border_colors);
3115 anv_state_pool_free(&device->dynamic_state_pool, device->border_colors);
3116 anv_state_pool_free(&device->dynamic_state_pool, device->slice_hash);
3117 #endif
3118
3119 anv_scratch_pool_finish(device, &device->scratch_pool);
3120
3121 anv_device_release_bo(device, device->workaround_bo);
3122 anv_device_release_bo(device, device->trivial_batch_bo);
3123 if (device->info.gen >= 10)
3124 anv_device_release_bo(device, device->hiz_clear_bo);
3125
3126 if (device->