2 * Copyright © 2015 Intel Corporation
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:
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
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
28 #include <sys/sysinfo.h>
32 #include "drm-uapi/drm_fourcc.h"
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"
45 #include "common/gen_aux_map.h"
46 #include "common/gen_defines.h"
47 #include "compiler/glsl_types.h"
49 #include "genxml/gen7_pack.h"
51 static const char anv_dri_options_xml
[] =
53 DRI_CONF_SECTION_PERFORMANCE
54 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
55 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
58 DRI_CONF_SECTION_DEBUG
59 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
60 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
64 /* This is probably far to big but it reflects the max size used for messages
65 * in OpenGLs KHR_debug.
67 #define MAX_DEBUG_MESSAGE_LENGTH 4096
69 /* Render engine timestamp register */
70 #define TIMESTAMP 0x2358
73 compiler_debug_log(void *data
, const char *fmt
, ...)
75 char str
[MAX_DEBUG_MESSAGE_LENGTH
];
76 struct anv_device
*device
= (struct anv_device
*)data
;
77 struct anv_instance
*instance
= device
->physical
->instance
;
79 if (list_is_empty(&instance
->debug_report_callbacks
.callbacks
))
84 (void) vsnprintf(str
, MAX_DEBUG_MESSAGE_LENGTH
, fmt
, args
);
87 vk_debug_report(&instance
->debug_report_callbacks
,
88 VK_DEBUG_REPORT_DEBUG_BIT_EXT
,
89 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT
,
94 compiler_perf_log(void *data
, const char *fmt
, ...)
99 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
100 intel_logd_v(fmt
, args
);
106 anv_compute_heap_size(int fd
, uint64_t gtt_size
)
108 /* Query the total ram from the system */
112 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
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.
117 uint64_t available_ram
;
118 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
119 available_ram
= total_ram
/ 2;
121 available_ram
= total_ram
* 3 / 4;
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.
126 uint64_t available_gtt
= gtt_size
* 3 / 4;
128 return MIN2(available_ram
, available_gtt
);
132 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
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.
139 anv_perf_warn(NULL
, NULL
,
140 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
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");
149 /* We only allow 48-bit addresses with softpin because knowing the actual
150 * address is required for the vertex cache flush workaround.
152 device
->supports_48bit_addresses
= (device
->info
.gen
>= 8) &&
153 device
->has_softpin
&&
154 device
->gtt_size
> (4ULL << 30 /* GiB */);
156 uint64_t heap_size
= anv_compute_heap_size(fd
, device
->gtt_size
);
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.
164 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
165 "not support for 48-bit addresses",
167 heap_size
= 2ull << 30;
170 device
->memory
.heap_count
= 1;
171 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
173 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
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.
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
,
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).
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
,
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
,
209 device
->memory
.type_count
= type_count
;
215 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
217 const struct build_id_note
*note
=
218 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
220 return vk_errorfi(device
->instance
, NULL
,
221 VK_ERROR_INITIALIZATION_FAILED
,
222 "Failed to find build-id");
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");
232 memcpy(device
->driver_build_sha1
, build_id_data(note
), 20);
234 struct mesa_sha1 sha1_ctx
;
236 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
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.
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
);
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.
261 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
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.
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
);
281 anv_physical_device_init_disk_cache(struct anv_physical_device
*device
)
283 #ifdef ENABLE_SHADER_CACHE
285 ASSERTED
int len
= snprintf(renderer
, sizeof(renderer
), "anv_%04x",
286 device
->info
.chipset_id
);
287 assert(len
== sizeof(renderer
) - 2);
290 _mesa_sha1_format(timestamp
, device
->driver_build_sha1
);
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
);
296 device
->disk_cache
= NULL
;
301 anv_physical_device_free_disk_cache(struct anv_physical_device
*device
)
303 #ifdef ENABLE_SHADER_CACHE
304 if (device
->disk_cache
)
305 disk_cache_destroy(device
->disk_cache
);
307 assert(device
->disk_cache
== NULL
);
312 get_available_system_memory()
314 char *meminfo
= os_read_file("/proc/meminfo", NULL
);
318 char *str
= strstr(meminfo
, "MemAvailable:");
324 uint64_t kb_mem_available
;
325 if (sscanf(str
, "MemAvailable: %" PRIx64
, &kb_mem_available
) == 1) {
327 return kb_mem_available
<< 10;
335 anv_physical_device_try_create(struct anv_instance
*instance
,
336 drmDevicePtr drm_device
,
337 struct anv_physical_device
**device_out
)
339 const char *primary_path
= drm_device
->nodes
[DRM_NODE_PRIMARY
];
340 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
345 brw_process_intel_debug_variable();
347 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
349 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
351 struct gen_device_info devinfo
;
352 if (!gen_get_device_info_from_fd(fd
, &devinfo
)) {
353 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
357 const char *device_name
= gen_get_device_name(devinfo
.chipset_id
);
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");
370 result
= vk_errorfi(instance
, NULL
, VK_ERROR_INCOMPATIBLE_DRIVER
,
371 "Vulkan not yet supported on %s", device_name
);
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
);
383 vk_object_base_init(NULL
, &device
->base
, VK_OBJECT_TYPE_PHYSICAL_DEVICE
);
384 device
->instance
= instance
;
386 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
387 snprintf(device
->path
, ARRAY_SIZE(device
->path
), "%s", path
);
389 device
->info
= devinfo
;
390 device
->name
= device_name
;
392 device
->no_hw
= device
->info
.no_hw
;
393 if (getenv("INTEL_NO_HW") != NULL
)
394 device
->no_hw
= true;
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
;
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");
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");
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");
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");
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
);
444 result
= anv_physical_device_init_heaps(device
, fd
);
445 if (result
!= VK_SUCCESS
)
448 device
->use_softpin
= device
->has_softpin
&&
449 device
->supports_48bit_addresses
;
451 device
->has_context_isolation
=
452 anv_gem_get_param(fd
, I915_PARAM_HAS_CONTEXT_ISOLATION
);
454 device
->always_use_bindless
=
455 env_var_as_boolean("ANV_ALWAYS_BINDLESS", false);
457 device
->use_call_secondary
=
458 device
->use_softpin
&&
459 !env_var_as_boolean("ANV_DISABLE_SECONDARY_CMD_BUFFER_CALLS", false);
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.
464 device
->has_a64_buffer_access
= device
->info
.gen
>= 8 &&
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.
470 device
->has_bindless_images
= device
->info
.gen
>= 9 &&
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.
478 device
->has_bindless_samplers
= device
->info
.gen
>= 8;
480 device
->has_implicit_ccs
= device
->info
.has_aux_map
;
482 /* Check if we can read the GPU timestamp register from the CPU */
484 device
->has_reg_timestamp
= anv_gem_reg_read(fd
, TIMESTAMP
| I915_REG_READ_8B_WA
,
487 device
->has_mem_available
= get_available_system_memory() != 0;
489 device
->always_flush_cache
=
490 driQueryOptionb(&instance
->dri_options
, "always_flush_cache");
492 device
->has_mmap_offset
=
493 anv_gem_get_param(fd
, I915_PARAM_MMAP_GTT_VERSION
) >= 4;
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
);
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.
504 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
505 intel_logw("Kernel 4.1 required to properly query GPU properties");
507 } else if (device
->info
.gen
== 7) {
508 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
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
;
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
;
522 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
523 if (device
->compiler
== NULL
) {
524 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
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;
535 /* Broadwell PRM says:
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].
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."
547 device
->info
.gen
< 8 && anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
549 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
551 result
= anv_physical_device_init_uuids(device
);
552 if (result
!= VK_SUCCESS
)
555 anv_physical_device_init_disk_cache(device
);
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
563 if (anv_gem_get_param(master_fd
, I915_PARAM_CHIPSET_ID
) == 0) {
569 device
->master_fd
= master_fd
;
571 result
= anv_init_wsi(device
);
572 if (result
!= VK_SUCCESS
)
573 goto fail_disk_cache
;
575 device
->perf
= anv_get_perf(&device
->info
, fd
);
577 anv_physical_device_get_supported_extensions(device
,
578 &device
->supported_extensions
);
581 device
->local_fd
= fd
;
583 *device_out
= device
;
588 anv_physical_device_free_disk_cache(device
);
590 ralloc_free(device
->compiler
);
592 vk_free(&instance
->alloc
, device
);
601 anv_physical_device_destroy(struct anv_physical_device
*device
)
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
);
615 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
616 VkSystemAllocationScope allocationScope
)
622 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
623 size_t align
, VkSystemAllocationScope allocationScope
)
625 return realloc(pOriginal
, size
);
629 default_free_func(void *pUserData
, void *pMemory
)
634 static const VkAllocationCallbacks default_alloc
= {
636 .pfnAllocation
= default_alloc_func
,
637 .pfnReallocation
= default_realloc_func
,
638 .pfnFree
= default_free_func
,
641 VkResult
anv_EnumerateInstanceExtensionProperties(
642 const char* pLayerName
,
643 uint32_t* pPropertyCount
,
644 VkExtensionProperties
* pProperties
)
646 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
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
];
656 return vk_outarray_status(&out
);
659 VkResult
anv_CreateInstance(
660 const VkInstanceCreateInfo
* pCreateInfo
,
661 const VkAllocationCallbacks
* pAllocator
,
662 VkInstance
* pInstance
)
664 struct anv_instance
*instance
;
667 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
669 struct anv_instance_extension_table enabled_extensions
= {};
670 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
672 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
673 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
674 anv_instance_extensions
[idx
].extensionName
) == 0)
678 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
679 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
681 if (!anv_instance_extensions_supported
.extensions
[idx
])
682 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
684 enabled_extensions
.extensions
[idx
] = true;
687 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
688 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
690 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
692 vk_object_base_init(NULL
, &instance
->base
, VK_OBJECT_TYPE_INSTANCE
);
695 instance
->alloc
= *pAllocator
;
697 instance
->alloc
= default_alloc
;
699 instance
->app_info
= (struct anv_app_info
) { .api_version
= 0 };
700 if (pCreateInfo
->pApplicationInfo
) {
701 const VkApplicationInfo
*app
= pCreateInfo
->pApplicationInfo
;
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
;
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
;
713 instance
->app_info
.api_version
= app
->apiVersion
;
716 if (instance
->app_info
.api_version
== 0)
717 instance
->app_info
.api_version
= VK_API_VERSION_1_0
;
719 instance
->enabled_extensions
= enabled_extensions
;
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.
725 if (!anv_instance_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
726 &instance
->enabled_extensions
)) {
727 instance
->dispatch
.entrypoints
[i
] = NULL
;
729 instance
->dispatch
.entrypoints
[i
] =
730 anv_instance_dispatch_table
.entrypoints
[i
];
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.
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
;
742 instance
->physical_device_dispatch
.entrypoints
[i
] =
743 anv_physical_device_dispatch_table
.entrypoints
[i
];
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.
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
;
755 instance
->device_dispatch
.entrypoints
[i
] =
756 anv_device_dispatch_table
.entrypoints
[i
];
760 instance
->physical_devices_enumerated
= false;
761 list_inithead(&instance
->physical_devices
);
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
);
769 instance
->pipeline_cache_enabled
=
770 env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true);
772 glsl_type_singleton_init_or_ref();
774 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
776 driParseOptionInfo(&instance
->available_dri_options
, anv_dri_options_xml
);
777 driParseConfigFiles(&instance
->dri_options
, &instance
->available_dri_options
,
779 instance
->app_info
.engine_name
,
780 instance
->app_info
.engine_version
);
782 *pInstance
= anv_instance_to_handle(instance
);
787 void anv_DestroyInstance(
788 VkInstance _instance
,
789 const VkAllocationCallbacks
* pAllocator
)
791 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
796 list_for_each_entry_safe(struct anv_physical_device
, pdevice
,
797 &instance
->physical_devices
, link
)
798 anv_physical_device_destroy(pdevice
);
800 vk_free(&instance
->alloc
, (char *)instance
->app_info
.app_name
);
801 vk_free(&instance
->alloc
, (char *)instance
->app_info
.engine_name
);
803 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
805 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
807 glsl_type_singleton_decref();
809 driDestroyOptionCache(&instance
->dri_options
);
810 driDestroyOptionInfo(&instance
->available_dri_options
);
812 vk_object_base_finish(&instance
->base
);
813 vk_free(&instance
->alloc
, instance
);
817 anv_enumerate_physical_devices(struct anv_instance
*instance
)
819 if (instance
->physical_devices_enumerated
)
822 instance
->physical_devices_enumerated
= true;
824 /* TODO: Check for more devices ? */
825 drmDevicePtr devices
[8];
828 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
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) {
838 struct anv_physical_device
*pdevice
;
839 result
= anv_physical_device_try_create(instance
, devices
[i
],
841 /* Incompatible DRM device, skip. */
842 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
847 /* Error creating the physical device, report the error. */
848 if (result
!= VK_SUCCESS
)
851 list_addtail(&pdevice
->link
, &instance
->physical_devices
);
854 drmFreeDevices(devices
, max_devices
);
856 /* If we successfully enumerated any devices, call it success */
860 VkResult
anv_EnumeratePhysicalDevices(
861 VkInstance _instance
,
862 uint32_t* pPhysicalDeviceCount
,
863 VkPhysicalDevice
* pPhysicalDevices
)
865 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
866 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
868 VkResult result
= anv_enumerate_physical_devices(instance
);
869 if (result
!= VK_SUCCESS
)
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
);
879 return vk_outarray_status(&out
);
882 VkResult
anv_EnumeratePhysicalDeviceGroups(
883 VkInstance _instance
,
884 uint32_t* pPhysicalDeviceGroupCount
,
885 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
887 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
888 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
889 pPhysicalDeviceGroupCount
);
891 VkResult result
= anv_enumerate_physical_devices(instance
);
892 if (result
!= VK_SUCCESS
)
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;
903 vk_foreach_struct(ext
, p
->pNext
)
904 anv_debug_ignored_stype(ext
->sType
);
908 return vk_outarray_status(&out
);
911 void anv_GetPhysicalDeviceFeatures(
912 VkPhysicalDevice physicalDevice
,
913 VkPhysicalDeviceFeatures
* pFeatures
)
915 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
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,
927 .multiDrawIndirect
= true,
928 .drawIndirectFirstInstance
= true,
930 .depthBiasClamp
= true,
931 .fillModeNonSolid
= true,
932 .depthBounds
= pdevice
->info
.gen
>= 12,
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,
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
];
972 struct anv_app_info
*app_info
= &pdevice
->instance
->app_info
;
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.
978 if (app_info
->engine_name
&& strcmp(app_info
->engine_name
, "idTech") == 0)
979 pFeatures
->depthBounds
= true;
983 anv_get_physical_device_features_1_1(struct anv_physical_device
*pdevice
,
984 VkPhysicalDeviceVulkan11Features
*f
)
986 assert(f
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
);
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;
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;
1003 anv_get_physical_device_features_1_2(struct anv_physical_device
*pdevice
,
1004 VkPhysicalDeviceVulkan12Features
*f
)
1006 assert(f
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
);
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;
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
;
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;
1062 void anv_GetPhysicalDeviceFeatures2(
1063 VkPhysicalDevice physicalDevice
,
1064 VkPhysicalDeviceFeatures2
* pFeatures
)
1066 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1067 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1069 VkPhysicalDeviceVulkan11Features core_1_1
= {
1070 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
,
1072 anv_get_physical_device_features_1_1(pdevice
, &core_1_1
);
1074 VkPhysicalDeviceVulkan12Features core_1_2
= {
1075 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
,
1077 anv_get_physical_device_features_1_2(pdevice
, &core_1_2
);
1079 #define CORE_FEATURE(major, minor, feature) \
1080 features->feature = core_##major##_##minor.feature
1083 vk_foreach_struct(ext
, pFeatures
->pNext
) {
1084 switch (ext
->sType
) {
1085 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
1086 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
1087 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
1088 CORE_FEATURE(1, 2, storageBuffer8BitAccess
);
1089 CORE_FEATURE(1, 2, uniformAndStorageBuffer8BitAccess
);
1090 CORE_FEATURE(1, 2, storagePushConstant8
);
1094 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
1095 VkPhysicalDevice16BitStorageFeatures
*features
=
1096 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
1097 CORE_FEATURE(1, 1, storageBuffer16BitAccess
);
1098 CORE_FEATURE(1, 1, uniformAndStorageBuffer16BitAccess
);
1099 CORE_FEATURE(1, 1, storagePushConstant16
);
1100 CORE_FEATURE(1, 1, storageInputOutput16
);
1104 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1105 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
= (void *)ext
;
1106 features
->bufferDeviceAddress
= pdevice
->has_a64_buffer_access
;
1107 features
->bufferDeviceAddressCaptureReplay
= false;
1108 features
->bufferDeviceAddressMultiDevice
= false;
1112 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR
: {
1113 VkPhysicalDeviceBufferDeviceAddressFeaturesKHR
*features
= (void *)ext
;
1114 CORE_FEATURE(1, 2, bufferDeviceAddress
);
1115 CORE_FEATURE(1, 2, bufferDeviceAddressCaptureReplay
);
1116 CORE_FEATURE(1, 2, bufferDeviceAddressMultiDevice
);
1120 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1121 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1122 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1123 features
->computeDerivativeGroupQuads
= true;
1124 features
->computeDerivativeGroupLinear
= true;
1128 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
1129 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
1130 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
1131 features
->conditionalRendering
= pdevice
->info
.gen
>= 8 ||
1132 pdevice
->info
.is_haswell
;
1133 features
->inheritedConditionalRendering
= pdevice
->info
.gen
>= 8 ||
1134 pdevice
->info
.is_haswell
;
1138 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT
: {
1139 VkPhysicalDeviceCustomBorderColorFeaturesEXT
*features
=
1140 (VkPhysicalDeviceCustomBorderColorFeaturesEXT
*)ext
;
1141 features
->customBorderColors
= pdevice
->info
.gen
>= 8;
1142 features
->customBorderColorWithoutFormat
= pdevice
->info
.gen
>= 8;
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1147 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1148 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1149 features
->depthClipEnable
= true;
1153 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
1154 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
= (void *)ext
;
1155 CORE_FEATURE(1, 2, shaderFloat16
);
1156 CORE_FEATURE(1, 2, shaderInt8
);
1160 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT
: {
1161 VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*features
=
1162 (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*)ext
;
1163 features
->fragmentShaderSampleInterlock
= pdevice
->info
.gen
>= 9;
1164 features
->fragmentShaderPixelInterlock
= pdevice
->info
.gen
>= 9;
1165 features
->fragmentShaderShadingRateInterlock
= false;
1169 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
1170 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
1171 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
1172 CORE_FEATURE(1, 2, hostQueryReset
);
1176 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
1177 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
1178 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
1179 CORE_FEATURE(1, 2, shaderInputAttachmentArrayDynamicIndexing
);
1180 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayDynamicIndexing
);
1181 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayDynamicIndexing
);
1182 CORE_FEATURE(1, 2, shaderUniformBufferArrayNonUniformIndexing
);
1183 CORE_FEATURE(1, 2, shaderSampledImageArrayNonUniformIndexing
);
1184 CORE_FEATURE(1, 2, shaderStorageBufferArrayNonUniformIndexing
);
1185 CORE_FEATURE(1, 2, shaderStorageImageArrayNonUniformIndexing
);
1186 CORE_FEATURE(1, 2, shaderInputAttachmentArrayNonUniformIndexing
);
1187 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayNonUniformIndexing
);
1188 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayNonUniformIndexing
);
1189 CORE_FEATURE(1, 2, descriptorBindingUniformBufferUpdateAfterBind
);
1190 CORE_FEATURE(1, 2, descriptorBindingSampledImageUpdateAfterBind
);
1191 CORE_FEATURE(1, 2, descriptorBindingStorageImageUpdateAfterBind
);
1192 CORE_FEATURE(1, 2, descriptorBindingStorageBufferUpdateAfterBind
);
1193 CORE_FEATURE(1, 2, descriptorBindingUniformTexelBufferUpdateAfterBind
);
1194 CORE_FEATURE(1, 2, descriptorBindingStorageTexelBufferUpdateAfterBind
);
1195 CORE_FEATURE(1, 2, descriptorBindingUpdateUnusedWhilePending
);
1196 CORE_FEATURE(1, 2, descriptorBindingPartiallyBound
);
1197 CORE_FEATURE(1, 2, descriptorBindingVariableDescriptorCount
);
1198 CORE_FEATURE(1, 2, runtimeDescriptorArray
);
1202 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES_EXT
: {
1203 VkPhysicalDeviceImageRobustnessFeaturesEXT
*features
=
1204 (VkPhysicalDeviceImageRobustnessFeaturesEXT
*)ext
;
1205 features
->robustImageAccess
= true;
1209 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1210 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1211 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1212 features
->indexTypeUint8
= true;
1216 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1217 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1218 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1219 features
->inlineUniformBlock
= true;
1220 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1224 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1225 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1226 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1227 features
->rectangularLines
= true;
1228 features
->bresenhamLines
= true;
1229 /* Support for Smooth lines with MSAA was removed on gen11. From the
1230 * BSpec section "Multisample ModesState" table for "AA Line Support
1233 * GEN10:BUG:######## NUM_MULTISAMPLES == 1
1235 * Fortunately, this isn't a case most people care about.
1237 features
->smoothLines
= pdevice
->info
.gen
< 10;
1238 features
->stippledRectangularLines
= false;
1239 features
->stippledBresenhamLines
= true;
1240 features
->stippledSmoothLines
= false;
1244 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
1245 VkPhysicalDeviceMultiviewFeatures
*features
=
1246 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
1247 CORE_FEATURE(1, 1, multiview
);
1248 CORE_FEATURE(1, 1, multiviewGeometryShader
);
1249 CORE_FEATURE(1, 1, multiviewTessellationShader
);
1253 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1254 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1255 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1256 CORE_FEATURE(1, 2, imagelessFramebuffer
);
1260 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_FEATURES_KHR
: {
1261 VkPhysicalDevicePerformanceQueryFeaturesKHR
*feature
=
1262 (VkPhysicalDevicePerformanceQueryFeaturesKHR
*)ext
;
1263 feature
->performanceCounterQueryPools
= true;
1264 /* HW only supports a single configuration at a time. */
1265 feature
->performanceCounterMultipleQueryPools
= false;
1269 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES_EXT
: {
1270 VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT
*features
=
1271 (VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT
*)ext
;
1272 features
->pipelineCreationCacheControl
= true;
1276 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1277 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1278 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1279 features
->pipelineExecutableInfo
= true;
1283 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT
: {
1284 VkPhysicalDevicePrivateDataFeaturesEXT
*features
= (void *)ext
;
1285 features
->privateData
= true;
1289 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
1290 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
1291 CORE_FEATURE(1, 1, protectedMemory
);
1295 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT
: {
1296 VkPhysicalDeviceRobustness2FeaturesEXT
*features
= (void *)ext
;
1297 features
->robustBufferAccess2
= true;
1298 features
->robustImageAccess2
= true;
1299 features
->nullDescriptor
= true;
1303 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
1304 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
1305 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
1306 CORE_FEATURE(1, 1, samplerYcbcrConversion
);
1310 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
1311 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
1312 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
1313 CORE_FEATURE(1, 2, scalarBlockLayout
);
1317 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES_KHR
: {
1318 VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*features
=
1319 (VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*)ext
;
1320 CORE_FEATURE(1, 2, separateDepthStencilLayouts
);
1324 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
1325 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
= (void *)ext
;
1326 CORE_FEATURE(1, 2, shaderBufferInt64Atomics
);
1327 CORE_FEATURE(1, 2, shaderSharedInt64Atomics
);
1331 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1332 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
= (void *)ext
;
1333 features
->shaderDemoteToHelperInvocation
= true;
1337 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1338 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1339 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1340 features
->shaderSubgroupClock
= true;
1341 features
->shaderDeviceClock
= false;
1345 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
1346 VkPhysicalDeviceShaderDrawParametersFeatures
*features
= (void *)ext
;
1347 CORE_FEATURE(1, 1, shaderDrawParameters
);
1351 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES_KHR
: {
1352 VkPhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR
*features
=
1353 (VkPhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR
*)ext
;
1354 CORE_FEATURE(1, 2, shaderSubgroupExtendedTypes
);
1358 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1359 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1360 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1361 features
->subgroupSizeControl
= true;
1362 features
->computeFullSubgroups
= true;
1366 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1367 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1368 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1369 features
->texelBufferAlignment
= true;
1373 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR
: {
1374 VkPhysicalDeviceTimelineSemaphoreFeaturesKHR
*features
=
1375 (VkPhysicalDeviceTimelineSemaphoreFeaturesKHR
*) ext
;
1376 CORE_FEATURE(1, 2, timelineSemaphore
);
1380 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
1381 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
1382 CORE_FEATURE(1, 1, variablePointersStorageBuffer
);
1383 CORE_FEATURE(1, 1, variablePointers
);
1387 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1388 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1389 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1390 features
->transformFeedback
= true;
1391 features
->geometryStreams
= true;
1395 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1396 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1397 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1398 CORE_FEATURE(1, 2, uniformBufferStandardLayout
);
1402 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
1403 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1404 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1405 features
->vertexAttributeInstanceRateDivisor
= true;
1406 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1410 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
:
1411 anv_get_physical_device_features_1_1(pdevice
, (void *)ext
);
1414 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
:
1415 anv_get_physical_device_features_1_2(pdevice
, (void *)ext
);
1418 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES_KHR
: {
1419 VkPhysicalDeviceVulkanMemoryModelFeaturesKHR
*features
= (void *)ext
;
1420 CORE_FEATURE(1, 2, vulkanMemoryModel
);
1421 CORE_FEATURE(1, 2, vulkanMemoryModelDeviceScope
);
1422 CORE_FEATURE(1, 2, vulkanMemoryModelAvailabilityVisibilityChains
);
1426 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1427 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1428 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1429 features
->ycbcrImageArrays
= true;
1434 anv_debug_ignored_stype(ext
->sType
);
1442 #define MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS 64
1444 #define MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS 64
1445 #define MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS 256
1447 #define MAX_CUSTOM_BORDER_COLORS 4096
1449 void anv_GetPhysicalDeviceProperties(
1450 VkPhysicalDevice physicalDevice
,
1451 VkPhysicalDeviceProperties
* pProperties
)
1453 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1454 const struct gen_device_info
*devinfo
= &pdevice
->info
;
1456 /* See assertions made when programming the buffer surface state. */
1457 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
1458 (1ul << 30) : (1ul << 27);
1460 const uint32_t max_ssbos
= pdevice
->has_a64_buffer_access
? UINT16_MAX
: 64;
1461 const uint32_t max_textures
=
1462 pdevice
->has_bindless_images
? UINT16_MAX
: 128;
1463 const uint32_t max_samplers
=
1464 pdevice
->has_bindless_samplers
? UINT16_MAX
:
1465 (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ? 128 : 16;
1466 const uint32_t max_images
=
1467 pdevice
->has_bindless_images
? UINT16_MAX
: MAX_IMAGES
;
1469 /* If we can use bindless for everything, claim a high per-stage limit,
1470 * otherwise use the binding table size, minus the slots reserved for
1471 * render targets and one slot for the descriptor buffer. */
1472 const uint32_t max_per_stage
=
1473 pdevice
->has_bindless_images
&& pdevice
->has_a64_buffer_access
1474 ? UINT32_MAX
: MAX_BINDING_TABLE_SIZE
- MAX_RTS
- 1;
1476 /* Limit max_threads to 64 for the GPGPU_WALKER command */
1477 const uint32_t max_workgroup_size
= 32 * MIN2(64, devinfo
->max_cs_threads
);
1479 VkSampleCountFlags sample_counts
=
1480 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1483 VkPhysicalDeviceLimits limits
= {
1484 .maxImageDimension1D
= (1 << 14),
1485 .maxImageDimension2D
= (1 << 14),
1486 .maxImageDimension3D
= (1 << 11),
1487 .maxImageDimensionCube
= (1 << 14),
1488 .maxImageArrayLayers
= (1 << 11),
1489 .maxTexelBufferElements
= 128 * 1024 * 1024,
1490 .maxUniformBufferRange
= (1ul << 27),
1491 .maxStorageBufferRange
= max_raw_buffer_sz
,
1492 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1493 .maxMemoryAllocationCount
= UINT32_MAX
,
1494 .maxSamplerAllocationCount
= 64 * 1024,
1495 .bufferImageGranularity
= 64, /* A cache line */
1496 .sparseAddressSpaceSize
= 0,
1497 .maxBoundDescriptorSets
= MAX_SETS
,
1498 .maxPerStageDescriptorSamplers
= max_samplers
,
1499 .maxPerStageDescriptorUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
,
1500 .maxPerStageDescriptorStorageBuffers
= max_ssbos
,
1501 .maxPerStageDescriptorSampledImages
= max_textures
,
1502 .maxPerStageDescriptorStorageImages
= max_images
,
1503 .maxPerStageDescriptorInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
,
1504 .maxPerStageResources
= max_per_stage
,
1505 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
1506 .maxDescriptorSetUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
, /* number of stages * maxPerStageDescriptorUniformBuffers */
1507 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1508 .maxDescriptorSetStorageBuffers
= 6 * max_ssbos
, /* number of stages * maxPerStageDescriptorStorageBuffers */
1509 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1510 .maxDescriptorSetSampledImages
= 6 * max_textures
, /* number of stages * maxPerStageDescriptorSampledImages */
1511 .maxDescriptorSetStorageImages
= 6 * max_images
, /* number of stages * maxPerStageDescriptorStorageImages */
1512 .maxDescriptorSetInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
,
1513 .maxVertexInputAttributes
= MAX_VBS
,
1514 .maxVertexInputBindings
= MAX_VBS
,
1515 .maxVertexInputAttributeOffset
= 2047,
1516 .maxVertexInputBindingStride
= 2048,
1517 .maxVertexOutputComponents
= 128,
1518 .maxTessellationGenerationLevel
= 64,
1519 .maxTessellationPatchSize
= 32,
1520 .maxTessellationControlPerVertexInputComponents
= 128,
1521 .maxTessellationControlPerVertexOutputComponents
= 128,
1522 .maxTessellationControlPerPatchOutputComponents
= 128,
1523 .maxTessellationControlTotalOutputComponents
= 2048,
1524 .maxTessellationEvaluationInputComponents
= 128,
1525 .maxTessellationEvaluationOutputComponents
= 128,
1526 .maxGeometryShaderInvocations
= 32,
1527 .maxGeometryInputComponents
= 64,
1528 .maxGeometryOutputComponents
= 128,
1529 .maxGeometryOutputVertices
= 256,
1530 .maxGeometryTotalOutputComponents
= 1024,
1531 .maxFragmentInputComponents
= 116, /* 128 components - (PSIZ, CLIP_DIST0, CLIP_DIST1) */
1532 .maxFragmentOutputAttachments
= 8,
1533 .maxFragmentDualSrcAttachments
= 1,
1534 .maxFragmentCombinedOutputResources
= 8,
1535 .maxComputeSharedMemorySize
= 64 * 1024,
1536 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1537 .maxComputeWorkGroupInvocations
= max_workgroup_size
,
1538 .maxComputeWorkGroupSize
= {
1543 .subPixelPrecisionBits
= 8,
1544 .subTexelPrecisionBits
= 8,
1545 .mipmapPrecisionBits
= 8,
1546 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1547 .maxDrawIndirectCount
= UINT32_MAX
,
1548 .maxSamplerLodBias
= 16,
1549 .maxSamplerAnisotropy
= 16,
1550 .maxViewports
= MAX_VIEWPORTS
,
1551 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1552 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1553 .viewportSubPixelBits
= 13, /* We take a float? */
1554 .minMemoryMapAlignment
= 4096, /* A page */
1555 /* The dataport requires texel alignment so we need to assume a worst
1556 * case of R32G32B32A32 which is 16 bytes.
1558 .minTexelBufferOffsetAlignment
= 16,
1559 .minUniformBufferOffsetAlignment
= ANV_UBO_ALIGNMENT
,
1560 .minStorageBufferOffsetAlignment
= 4,
1561 .minTexelOffset
= -8,
1562 .maxTexelOffset
= 7,
1563 .minTexelGatherOffset
= -32,
1564 .maxTexelGatherOffset
= 31,
1565 .minInterpolationOffset
= -0.5,
1566 .maxInterpolationOffset
= 0.4375,
1567 .subPixelInterpolationOffsetBits
= 4,
1568 .maxFramebufferWidth
= (1 << 14),
1569 .maxFramebufferHeight
= (1 << 14),
1570 .maxFramebufferLayers
= (1 << 11),
1571 .framebufferColorSampleCounts
= sample_counts
,
1572 .framebufferDepthSampleCounts
= sample_counts
,
1573 .framebufferStencilSampleCounts
= sample_counts
,
1574 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1575 .maxColorAttachments
= MAX_RTS
,
1576 .sampledImageColorSampleCounts
= sample_counts
,
1577 .sampledImageIntegerSampleCounts
= sample_counts
,
1578 .sampledImageDepthSampleCounts
= sample_counts
,
1579 .sampledImageStencilSampleCounts
= sample_counts
,
1580 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1581 .maxSampleMaskWords
= 1,
1582 .timestampComputeAndGraphics
= true,
1583 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
1584 .maxClipDistances
= 8,
1585 .maxCullDistances
= 8,
1586 .maxCombinedClipAndCullDistances
= 8,
1587 .discreteQueuePriorities
= 2,
1588 .pointSizeRange
= { 0.125, 255.875 },
1591 (devinfo
->gen
>= 9 || devinfo
->is_cherryview
) ?
1592 2047.9921875 : 7.9921875,
1594 .pointSizeGranularity
= (1.0 / 8.0),
1595 .lineWidthGranularity
= (1.0 / 128.0),
1596 .strictLines
= false,
1597 .standardSampleLocations
= true,
1598 .optimalBufferCopyOffsetAlignment
= 128,
1599 .optimalBufferCopyRowPitchAlignment
= 128,
1600 .nonCoherentAtomSize
= 64,
1603 *pProperties
= (VkPhysicalDeviceProperties
) {
1604 .apiVersion
= anv_physical_device_api_version(pdevice
),
1605 .driverVersion
= vk_get_driver_version(),
1607 .deviceID
= pdevice
->info
.chipset_id
,
1608 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1610 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
1613 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
1614 "%s", pdevice
->name
);
1615 memcpy(pProperties
->pipelineCacheUUID
,
1616 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
1620 anv_get_physical_device_properties_1_1(struct anv_physical_device
*pdevice
,
1621 VkPhysicalDeviceVulkan11Properties
*p
)
1623 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
);
1625 memcpy(p
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1626 memcpy(p
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1627 memset(p
->deviceLUID
, 0, VK_LUID_SIZE
);
1628 p
->deviceNodeMask
= 0;
1629 p
->deviceLUIDValid
= false;
1631 p
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1632 VkShaderStageFlags scalar_stages
= 0;
1633 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1634 if (pdevice
->compiler
->scalar_stage
[stage
])
1635 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1637 p
->subgroupSupportedStages
= scalar_stages
;
1638 p
->subgroupSupportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1639 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1640 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1641 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1642 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1643 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1644 if (pdevice
->info
.gen
>= 8) {
1645 /* TODO: There's no technical reason why these can't be made to
1646 * work on gen7 but they don't at the moment so it's best to leave
1647 * the feature disabled than enabled and broken.
1649 p
->subgroupSupportedOperations
|= VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1650 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
;
1652 p
->subgroupQuadOperationsInAllStages
= pdevice
->info
.gen
>= 8;
1654 p
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY
;
1655 p
->maxMultiviewViewCount
= 16;
1656 p
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1657 p
->protectedNoFault
= false;
1658 /* This value doesn't matter for us today as our per-stage descriptors are
1661 p
->maxPerSetDescriptors
= 1024;
1662 p
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1666 anv_get_physical_device_properties_1_2(struct anv_physical_device
*pdevice
,
1667 VkPhysicalDeviceVulkan12Properties
*p
)
1669 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
);
1671 p
->driverID
= VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR
;
1672 memset(p
->driverName
, 0, sizeof(p
->driverName
));
1673 snprintf(p
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
,
1674 "Intel open-source Mesa driver");
1675 memset(p
->driverInfo
, 0, sizeof(p
->driverInfo
));
1676 snprintf(p
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1677 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
);
1678 p
->conformanceVersion
= (VkConformanceVersionKHR
) {
1685 p
->denormBehaviorIndependence
=
1686 VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1687 p
->roundingModeIndependence
=
1688 VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE_KHR
;
1690 /* Broadwell does not support HF denorms and there are restrictions
1691 * other gens. According to Kabylake's PRM:
1693 * "math - Extended Math Function
1695 * Restriction : Half-float denorms are always retained."
1697 p
->shaderDenormFlushToZeroFloat16
= false;
1698 p
->shaderDenormPreserveFloat16
= pdevice
->info
.gen
> 8;
1699 p
->shaderRoundingModeRTEFloat16
= true;
1700 p
->shaderRoundingModeRTZFloat16
= true;
1701 p
->shaderSignedZeroInfNanPreserveFloat16
= true;
1703 p
->shaderDenormFlushToZeroFloat32
= true;
1704 p
->shaderDenormPreserveFloat32
= true;
1705 p
->shaderRoundingModeRTEFloat32
= true;
1706 p
->shaderRoundingModeRTZFloat32
= true;
1707 p
->shaderSignedZeroInfNanPreserveFloat32
= true;
1709 p
->shaderDenormFlushToZeroFloat64
= true;
1710 p
->shaderDenormPreserveFloat64
= true;
1711 p
->shaderRoundingModeRTEFloat64
= true;
1712 p
->shaderRoundingModeRTZFloat64
= true;
1713 p
->shaderSignedZeroInfNanPreserveFloat64
= true;
1715 /* It's a bit hard to exactly map our implementation to the limits
1716 * described here. The bindless surface handle in the extended
1717 * message descriptors is 20 bits and it's an index into the table of
1718 * RENDER_SURFACE_STATE structs that starts at bindless surface base
1719 * address. Given that most things consume two surface states per
1720 * view (general/sampled for textures and write-only/read-write for
1721 * images), we claim 2^19 things.
1723 * For SSBOs, we just use A64 messages so there is no real limit
1724 * there beyond the limit on the total size of a descriptor set.
1726 const unsigned max_bindless_views
= 1 << 19;
1727 p
->maxUpdateAfterBindDescriptorsInAllPools
= max_bindless_views
;
1728 p
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1729 p
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1730 p
->shaderStorageBufferArrayNonUniformIndexingNative
= true;
1731 p
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1732 p
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1733 p
->robustBufferAccessUpdateAfterBind
= true;
1734 p
->quadDivergentImplicitLod
= false;
1735 p
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_bindless_views
;
1736 p
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1737 p
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1738 p
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_bindless_views
;
1739 p
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_bindless_views
;
1740 p
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
;
1741 p
->maxPerStageUpdateAfterBindResources
= UINT32_MAX
;
1742 p
->maxDescriptorSetUpdateAfterBindSamplers
= max_bindless_views
;
1743 p
->maxDescriptorSetUpdateAfterBindUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1744 p
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1745 p
->maxDescriptorSetUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1746 p
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1747 p
->maxDescriptorSetUpdateAfterBindSampledImages
= max_bindless_views
;
1748 p
->maxDescriptorSetUpdateAfterBindStorageImages
= max_bindless_views
;
1749 p
->maxDescriptorSetUpdateAfterBindInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
;
1751 /* We support all of the depth resolve modes */
1752 p
->supportedDepthResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1753 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1754 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1755 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1756 /* Average doesn't make sense for stencil so we don't support that */
1757 p
->supportedStencilResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
;
1758 if (pdevice
->info
.gen
>= 8) {
1759 /* The advanced stencil resolve modes currently require stencil
1760 * sampling be supported by the hardware.
1762 p
->supportedStencilResolveModes
|= VK_RESOLVE_MODE_MIN_BIT_KHR
|
1763 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1765 p
->independentResolveNone
= true;
1766 p
->independentResolve
= true;
1768 p
->filterMinmaxSingleComponentFormats
= pdevice
->info
.gen
>= 9;
1769 p
->filterMinmaxImageComponentMapping
= pdevice
->info
.gen
>= 9;
1771 p
->maxTimelineSemaphoreValueDifference
= UINT64_MAX
;
1773 p
->framebufferIntegerColorSampleCounts
=
1774 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1777 void anv_GetPhysicalDeviceProperties2(
1778 VkPhysicalDevice physicalDevice
,
1779 VkPhysicalDeviceProperties2
* pProperties
)
1781 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1783 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1785 VkPhysicalDeviceVulkan11Properties core_1_1
= {
1786 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
,
1788 anv_get_physical_device_properties_1_1(pdevice
, &core_1_1
);
1790 VkPhysicalDeviceVulkan12Properties core_1_2
= {
1791 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
,
1793 anv_get_physical_device_properties_1_2(pdevice
, &core_1_2
);
1795 #define CORE_RENAMED_PROPERTY(major, minor, ext_property, core_property) \
1796 memcpy(&properties->ext_property, &core_##major##_##minor.core_property, \
1797 sizeof(core_##major##_##minor.core_property))
1799 #define CORE_PROPERTY(major, minor, property) \
1800 CORE_RENAMED_PROPERTY(major, minor, property, property)
1802 vk_foreach_struct(ext
, pProperties
->pNext
) {
1803 switch (ext
->sType
) {
1804 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT
: {
1805 VkPhysicalDeviceCustomBorderColorPropertiesEXT
*properties
=
1806 (VkPhysicalDeviceCustomBorderColorPropertiesEXT
*)ext
;
1807 properties
->maxCustomBorderColorSamplers
= MAX_CUSTOM_BORDER_COLORS
;
1811 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1812 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1813 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1814 CORE_PROPERTY(1, 2, supportedDepthResolveModes
);
1815 CORE_PROPERTY(1, 2, supportedStencilResolveModes
);
1816 CORE_PROPERTY(1, 2, independentResolveNone
);
1817 CORE_PROPERTY(1, 2, independentResolve
);
1821 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1822 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1823 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1824 CORE_PROPERTY(1, 2, maxUpdateAfterBindDescriptorsInAllPools
);
1825 CORE_PROPERTY(1, 2, shaderUniformBufferArrayNonUniformIndexingNative
);
1826 CORE_PROPERTY(1, 2, shaderSampledImageArrayNonUniformIndexingNative
);
1827 CORE_PROPERTY(1, 2, shaderStorageBufferArrayNonUniformIndexingNative
);
1828 CORE_PROPERTY(1, 2, shaderStorageImageArrayNonUniformIndexingNative
);
1829 CORE_PROPERTY(1, 2, shaderInputAttachmentArrayNonUniformIndexingNative
);
1830 CORE_PROPERTY(1, 2, robustBufferAccessUpdateAfterBind
);
1831 CORE_PROPERTY(1, 2, quadDivergentImplicitLod
);
1832 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSamplers
);
1833 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindUniformBuffers
);
1834 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageBuffers
);
1835 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSampledImages
);
1836 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageImages
);
1837 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindInputAttachments
);
1838 CORE_PROPERTY(1, 2, maxPerStageUpdateAfterBindResources
);
1839 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSamplers
);
1840 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffers
);
1841 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
);
1842 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffers
);
1843 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
);
1844 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSampledImages
);
1845 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageImages
);
1846 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindInputAttachments
);
1850 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1851 VkPhysicalDeviceDriverPropertiesKHR
*properties
=
1852 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1853 CORE_PROPERTY(1, 2, driverID
);
1854 CORE_PROPERTY(1, 2, driverName
);
1855 CORE_PROPERTY(1, 2, driverInfo
);
1856 CORE_PROPERTY(1, 2, conformanceVersion
);
1860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1861 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*props
=
1862 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1863 /* Userptr needs page aligned memory. */
1864 props
->minImportedHostPointerAlignment
= 4096;
1868 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1869 VkPhysicalDeviceIDProperties
*properties
=
1870 (VkPhysicalDeviceIDProperties
*)ext
;
1871 CORE_PROPERTY(1, 1, deviceUUID
);
1872 CORE_PROPERTY(1, 1, driverUUID
);
1873 CORE_PROPERTY(1, 1, deviceLUID
);
1874 CORE_PROPERTY(1, 1, deviceLUIDValid
);
1878 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1879 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1880 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1881 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1882 props
->maxPerStageDescriptorInlineUniformBlocks
=
1883 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1884 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
=
1885 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1886 props
->maxDescriptorSetInlineUniformBlocks
=
1887 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1888 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
=
1889 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1893 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1894 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1895 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1896 /* In the Skylake PRM Vol. 7, subsection titled "GIQ (Diamond)
1897 * Sampling Rules - Legacy Mode", it says the following:
1899 * "Note that the device divides a pixel into a 16x16 array of
1900 * subpixels, referenced by their upper left corners."
1902 * This is the only known reference in the PRMs to the subpixel
1903 * precision of line rasterization and a "16x16 array of subpixels"
1904 * implies 4 subpixel precision bits. Empirical testing has shown
1905 * that 4 subpixel precision bits applies to all line rasterization
1908 props
->lineSubPixelPrecisionBits
= 4;
1912 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1913 VkPhysicalDeviceMaintenance3Properties
*properties
=
1914 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1915 /* This value doesn't matter for us today as our per-stage
1916 * descriptors are the real limit.
1918 CORE_PROPERTY(1, 1, maxPerSetDescriptors
);
1919 CORE_PROPERTY(1, 1, maxMemoryAllocationSize
);
1923 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1924 VkPhysicalDeviceMultiviewProperties
*properties
=
1925 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1926 CORE_PROPERTY(1, 1, maxMultiviewViewCount
);
1927 CORE_PROPERTY(1, 1, maxMultiviewInstanceIndex
);
1931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1932 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1933 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1934 properties
->pciDomain
= pdevice
->pci_info
.domain
;
1935 properties
->pciBus
= pdevice
->pci_info
.bus
;
1936 properties
->pciDevice
= pdevice
->pci_info
.device
;
1937 properties
->pciFunction
= pdevice
->pci_info
.function
;
1941 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_PROPERTIES_KHR
: {
1942 VkPhysicalDevicePerformanceQueryPropertiesKHR
*properties
=
1943 (VkPhysicalDevicePerformanceQueryPropertiesKHR
*)ext
;
1944 /* We could support this by spawning a shader to do the equation
1947 properties
->allowCommandBufferQueryCopies
= false;
1951 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1952 VkPhysicalDevicePointClippingProperties
*properties
=
1953 (VkPhysicalDevicePointClippingProperties
*) ext
;
1954 CORE_PROPERTY(1, 1, pointClippingBehavior
);
1958 #pragma GCC diagnostic push
1959 #pragma GCC diagnostic ignored "-Wswitch"
1960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
: {
1961 VkPhysicalDevicePresentationPropertiesANDROID
*props
=
1962 (VkPhysicalDevicePresentationPropertiesANDROID
*)ext
;
1963 props
->sharedImage
= VK_FALSE
;
1966 #pragma GCC diagnostic pop
1968 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1969 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1970 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1971 CORE_PROPERTY(1, 1, protectedNoFault
);
1975 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1976 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1977 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1978 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1982 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_PROPERTIES_EXT
: {
1983 VkPhysicalDeviceRobustness2PropertiesEXT
*properties
= (void *)ext
;
1984 properties
->robustStorageBufferAccessSizeAlignment
=
1985 ANV_SSBO_BOUNDS_CHECK_ALIGNMENT
;
1986 properties
->robustUniformBufferAccessSizeAlignment
=
1991 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1992 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1993 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1994 CORE_PROPERTY(1, 2, filterMinmaxImageComponentMapping
);
1995 CORE_PROPERTY(1, 2, filterMinmaxSingleComponentFormats
);
1999 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
2000 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
2001 CORE_PROPERTY(1, 1, subgroupSize
);
2002 CORE_RENAMED_PROPERTY(1, 1, supportedStages
,
2003 subgroupSupportedStages
);
2004 CORE_RENAMED_PROPERTY(1, 1, supportedOperations
,
2005 subgroupSupportedOperations
);
2006 CORE_RENAMED_PROPERTY(1, 1, quadOperationsInAllStages
,
2007 subgroupQuadOperationsInAllStages
);
2011 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
2012 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
2013 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
2014 STATIC_ASSERT(8 <= BRW_SUBGROUP_SIZE
&& BRW_SUBGROUP_SIZE
<= 32);
2015 props
->minSubgroupSize
= 8;
2016 props
->maxSubgroupSize
= 32;
2017 props
->maxComputeWorkgroupSubgroups
= pdevice
->info
.max_cs_threads
;
2018 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
2021 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR
: {
2022 VkPhysicalDeviceFloatControlsPropertiesKHR
*properties
= (void *)ext
;
2023 CORE_PROPERTY(1, 2, denormBehaviorIndependence
);
2024 CORE_PROPERTY(1, 2, roundingModeIndependence
);
2025 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat16
);
2026 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat16
);
2027 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat16
);
2028 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat16
);
2029 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat16
);
2030 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat32
);
2031 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat32
);
2032 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat32
);
2033 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat32
);
2034 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat32
);
2035 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat64
);
2036 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat64
);
2037 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat64
);
2038 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat64
);
2039 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat64
);
2043 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
2044 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*props
=
2045 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
2047 /* From the SKL PRM Vol. 2d, docs for RENDER_SURFACE_STATE::Surface
2050 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field
2051 * specifies the base address of the first element of the surface,
2052 * computed in software by adding the surface base address to the
2053 * byte offset of the element in the buffer. The base address must
2054 * be aligned to element size."
2056 * The typed dataport messages require that things be texel aligned.
2057 * Otherwise, we may just load/store the wrong data or, in the worst
2058 * case, there may be hangs.
2060 props
->storageTexelBufferOffsetAlignmentBytes
= 16;
2061 props
->storageTexelBufferOffsetSingleTexelAlignment
= true;
2063 /* The sampler, however, is much more forgiving and it can handle
2064 * arbitrary byte alignment for linear and buffer surfaces. It's
2065 * hard to find a good PRM citation for this but years of empirical
2066 * experience demonstrate that this is true.
2068 props
->uniformTexelBufferOffsetAlignmentBytes
= 1;
2069 props
->uniformTexelBufferOffsetSingleTexelAlignment
= false;
2073 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES_KHR
: {
2074 VkPhysicalDeviceTimelineSemaphorePropertiesKHR
*properties
=
2075 (VkPhysicalDeviceTimelineSemaphorePropertiesKHR
*) ext
;
2076 CORE_PROPERTY(1, 2, maxTimelineSemaphoreValueDifference
);
2080 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
2081 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*props
=
2082 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
2084 props
->maxTransformFeedbackStreams
= MAX_XFB_STREAMS
;
2085 props
->maxTransformFeedbackBuffers
= MAX_XFB_BUFFERS
;
2086 props
->maxTransformFeedbackBufferSize
= (1ull << 32);
2087 props
->maxTransformFeedbackStreamDataSize
= 128 * 4;
2088 props
->maxTransformFeedbackBufferDataSize
= 128 * 4;
2089 props
->maxTransformFeedbackBufferDataStride
= 2048;
2090 props
->transformFeedbackQueries
= true;
2091 props
->transformFeedbackStreamsLinesTriangles
= false;
2092 props
->transformFeedbackRasterizationStreamSelect
= false;
2093 props
->transformFeedbackDraw
= true;
2097 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
2098 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
2099 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
2100 /* We have to restrict this a bit for multiview */
2101 props
->maxVertexAttribDivisor
= UINT32_MAX
/ 16;
2105 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
:
2106 anv_get_physical_device_properties_1_1(pdevice
, (void *)ext
);
2109 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
:
2110 anv_get_physical_device_properties_1_2(pdevice
, (void *)ext
);
2114 anv_debug_ignored_stype(ext
->sType
);
2119 #undef CORE_RENAMED_PROPERTY
2120 #undef CORE_PROPERTY
2123 /* We support exactly one queue family. */
2124 static const VkQueueFamilyProperties
2125 anv_queue_family_properties
= {
2126 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
2127 VK_QUEUE_COMPUTE_BIT
|
2128 VK_QUEUE_TRANSFER_BIT
,
2130 .timestampValidBits
= 36, /* XXX: Real value here */
2131 .minImageTransferGranularity
= { 1, 1, 1 },
2134 void anv_GetPhysicalDeviceQueueFamilyProperties(
2135 VkPhysicalDevice physicalDevice
,
2137 VkQueueFamilyProperties
* pQueueFamilyProperties
)
2139 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
2141 vk_outarray_append(&out
, p
) {
2142 *p
= anv_queue_family_properties
;
2146 void anv_GetPhysicalDeviceQueueFamilyProperties2(
2147 VkPhysicalDevice physicalDevice
,
2148 uint32_t* pQueueFamilyPropertyCount
,
2149 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
2152 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
2154 vk_outarray_append(&out
, p
) {
2155 p
->queueFamilyProperties
= anv_queue_family_properties
;
2157 vk_foreach_struct(s
, p
->pNext
) {
2158 anv_debug_ignored_stype(s
->sType
);
2163 void anv_GetPhysicalDeviceMemoryProperties(
2164 VkPhysicalDevice physicalDevice
,
2165 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
2167 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
2169 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
2170 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
2171 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
2172 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
2173 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
2177 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
2178 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
2179 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
2180 .size
= physical_device
->memory
.heaps
[i
].size
,
2181 .flags
= physical_device
->memory
.heaps
[i
].flags
,
2187 anv_get_memory_budget(VkPhysicalDevice physicalDevice
,
2188 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
2190 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
2191 uint64_t sys_available
= get_available_system_memory();
2192 assert(sys_available
> 0);
2194 VkDeviceSize total_heaps_size
= 0;
2195 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++)
2196 total_heaps_size
+= device
->memory
.heaps
[i
].size
;
2198 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++) {
2199 VkDeviceSize heap_size
= device
->memory
.heaps
[i
].size
;
2200 VkDeviceSize heap_used
= device
->memory
.heaps
[i
].used
;
2201 VkDeviceSize heap_budget
;
2203 double heap_proportion
= (double) heap_size
/ total_heaps_size
;
2204 VkDeviceSize sys_available_prop
= sys_available
* heap_proportion
;
2207 * Let's not incite the app to starve the system: report at most 90% of
2208 * available system memory.
2210 uint64_t heap_available
= sys_available_prop
* 9 / 10;
2211 heap_budget
= MIN2(heap_size
, heap_used
+ heap_available
);
2214 * Round down to the nearest MB
2216 heap_budget
&= ~((1ull << 20) - 1);
2219 * The heapBudget value must be non-zero for array elements less than
2220 * VkPhysicalDeviceMemoryProperties::memoryHeapCount. The heapBudget
2221 * value must be less than or equal to VkMemoryHeap::size for each heap.
2223 assert(0 < heap_budget
&& heap_budget
<= heap_size
);
2225 memoryBudget
->heapUsage
[i
] = heap_used
;
2226 memoryBudget
->heapBudget
[i
] = heap_budget
;
2229 /* The heapBudget and heapUsage values must be zero for array elements
2230 * greater than or equal to VkPhysicalDeviceMemoryProperties::memoryHeapCount
2232 for (uint32_t i
= device
->memory
.heap_count
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
2233 memoryBudget
->heapBudget
[i
] = 0;
2234 memoryBudget
->heapUsage
[i
] = 0;
2238 void anv_GetPhysicalDeviceMemoryProperties2(
2239 VkPhysicalDevice physicalDevice
,
2240 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
2242 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
2243 &pMemoryProperties
->memoryProperties
);
2245 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
2246 switch (ext
->sType
) {
2247 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
:
2248 anv_get_memory_budget(physicalDevice
, (void*)ext
);
2251 anv_debug_ignored_stype(ext
->sType
);
2258 anv_GetDeviceGroupPeerMemoryFeatures(
2261 uint32_t localDeviceIndex
,
2262 uint32_t remoteDeviceIndex
,
2263 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
2265 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
2266 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2267 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2268 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2269 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
2272 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
2273 VkInstance _instance
,
2276 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2278 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
2279 * when we have to return valid function pointers, NULL, or it's left
2280 * undefined. See the table for exact details.
2285 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
2286 if (strcmp(pName, "vk" #entrypoint) == 0) \
2287 return (PFN_vkVoidFunction)anv_##entrypoint
2289 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
2290 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
2291 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
2292 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
2294 /* GetInstanceProcAddr() can also be called with a NULL instance.
2295 * See https://gitlab.khronos.org/vulkan/vulkan/issues/2057
2297 LOOKUP_ANV_ENTRYPOINT(GetInstanceProcAddr
);
2299 #undef LOOKUP_ANV_ENTRYPOINT
2301 if (instance
== NULL
)
2304 int idx
= anv_get_instance_entrypoint_index(pName
);
2306 return instance
->dispatch
.entrypoints
[idx
];
2308 idx
= anv_get_physical_device_entrypoint_index(pName
);
2310 return instance
->physical_device_dispatch
.entrypoints
[idx
];
2312 idx
= anv_get_device_entrypoint_index(pName
);
2314 return instance
->device_dispatch
.entrypoints
[idx
];
2319 /* With version 1+ of the loader interface the ICD should expose
2320 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
2323 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2324 VkInstance instance
,
2328 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2329 VkInstance instance
,
2332 return anv_GetInstanceProcAddr(instance
, pName
);
2335 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
2339 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2341 if (!device
|| !pName
)
2344 int idx
= anv_get_device_entrypoint_index(pName
);
2348 return device
->dispatch
.entrypoints
[idx
];
2351 /* With version 4+ of the loader interface the ICD should expose
2352 * vk_icdGetPhysicalDeviceProcAddr()
2355 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
2356 VkInstance _instance
,
2359 PFN_vkVoidFunction
vk_icdGetPhysicalDeviceProcAddr(
2360 VkInstance _instance
,
2363 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2365 if (!pName
|| !instance
)
2368 int idx
= anv_get_physical_device_entrypoint_index(pName
);
2372 return instance
->physical_device_dispatch
.entrypoints
[idx
];
2377 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
2378 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
2379 const VkAllocationCallbacks
* pAllocator
,
2380 VkDebugReportCallbackEXT
* pCallback
)
2382 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2383 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2384 pCreateInfo
, pAllocator
, &instance
->alloc
,
2389 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2390 VkDebugReportCallbackEXT _callback
,
2391 const VkAllocationCallbacks
* pAllocator
)
2393 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2394 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2395 _callback
, pAllocator
, &instance
->alloc
);
2399 anv_DebugReportMessageEXT(VkInstance _instance
,
2400 VkDebugReportFlagsEXT flags
,
2401 VkDebugReportObjectTypeEXT objectType
,
2404 int32_t messageCode
,
2405 const char* pLayerPrefix
,
2406 const char* pMessage
)
2408 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2409 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2410 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2413 static struct anv_state
2414 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
2416 struct anv_state state
;
2418 state
= anv_state_pool_alloc(pool
, size
, align
);
2419 memcpy(state
.map
, p
, size
);
2425 anv_device_init_border_colors(struct anv_device
*device
)
2427 if (device
->info
.is_haswell
) {
2428 static const struct hsw_border_color border_colors
[] = {
2429 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2430 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2431 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2432 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2433 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2434 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2437 device
->border_colors
=
2438 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2439 sizeof(border_colors
), 512, border_colors
);
2441 static const struct gen8_border_color border_colors
[] = {
2442 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2443 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2444 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2445 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2446 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2447 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2450 device
->border_colors
=
2451 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2452 sizeof(border_colors
), 64, border_colors
);
2457 anv_device_init_trivial_batch(struct anv_device
*device
)
2459 VkResult result
= anv_device_alloc_bo(device
, 4096,
2460 ANV_BO_ALLOC_MAPPED
,
2461 0 /* explicit_address */,
2462 &device
->trivial_batch_bo
);
2463 if (result
!= VK_SUCCESS
)
2466 struct anv_batch batch
= {
2467 .start
= device
->trivial_batch_bo
->map
,
2468 .next
= device
->trivial_batch_bo
->map
,
2469 .end
= device
->trivial_batch_bo
->map
+ 4096,
2472 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2473 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2475 if (!device
->info
.has_llc
)
2476 gen_clflush_range(batch
.start
, batch
.next
- batch
.start
);
2481 VkResult
anv_EnumerateDeviceExtensionProperties(
2482 VkPhysicalDevice physicalDevice
,
2483 const char* pLayerName
,
2484 uint32_t* pPropertyCount
,
2485 VkExtensionProperties
* pProperties
)
2487 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
2488 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2490 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
2491 if (device
->supported_extensions
.extensions
[i
]) {
2492 vk_outarray_append(&out
, prop
) {
2493 *prop
= anv_device_extensions
[i
];
2498 return vk_outarray_status(&out
);
2502 vk_priority_to_gen(int priority
)
2505 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2506 return GEN_CONTEXT_LOW_PRIORITY
;
2507 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2508 return GEN_CONTEXT_MEDIUM_PRIORITY
;
2509 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2510 return GEN_CONTEXT_HIGH_PRIORITY
;
2511 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2512 return GEN_CONTEXT_REALTIME_PRIORITY
;
2514 unreachable("Invalid priority");
2519 anv_device_init_hiz_clear_value_bo(struct anv_device
*device
)
2521 VkResult result
= anv_device_alloc_bo(device
, 4096,
2522 ANV_BO_ALLOC_MAPPED
,
2523 0 /* explicit_address */,
2524 &device
->hiz_clear_bo
);
2525 if (result
!= VK_SUCCESS
)
2528 union isl_color_value hiz_clear
= { .u32
= { 0, } };
2529 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
2531 memcpy(device
->hiz_clear_bo
->map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
2533 if (!device
->info
.has_llc
)
2534 gen_clflush_range(device
->hiz_clear_bo
->map
, sizeof(hiz_clear
.u32
));
2540 get_bo_from_pool(struct gen_batch_decode_bo
*ret
,
2541 struct anv_block_pool
*pool
,
2544 anv_block_pool_foreach_bo(bo
, pool
) {
2545 uint64_t bo_address
= gen_48b_address(bo
->offset
);
2546 if (address
>= bo_address
&& address
< (bo_address
+ bo
->size
)) {
2547 *ret
= (struct gen_batch_decode_bo
) {
2558 /* Finding a buffer for batch decoding */
2559 static struct gen_batch_decode_bo
2560 decode_get_bo(void *v_batch
, bool ppgtt
, uint64_t address
)
2562 struct anv_device
*device
= v_batch
;
2563 struct gen_batch_decode_bo ret_bo
= {};
2567 if (get_bo_from_pool(&ret_bo
, &device
->dynamic_state_pool
.block_pool
, address
))
2569 if (get_bo_from_pool(&ret_bo
, &device
->instruction_state_pool
.block_pool
, address
))
2571 if (get_bo_from_pool(&ret_bo
, &device
->binding_table_pool
.block_pool
, address
))
2573 if (get_bo_from_pool(&ret_bo
, &device
->surface_state_pool
.block_pool
, address
))
2576 if (!device
->cmd_buffer_being_decoded
)
2577 return (struct gen_batch_decode_bo
) { };
2579 struct anv_batch_bo
**bo
;
2581 u_vector_foreach(bo
, &device
->cmd_buffer_being_decoded
->seen_bbos
) {
2582 /* The decoder zeroes out the top 16 bits, so we need to as well */
2583 uint64_t bo_address
= (*bo
)->bo
->offset
& (~0ull >> 16);
2585 if (address
>= bo_address
&& address
< bo_address
+ (*bo
)->bo
->size
) {
2586 return (struct gen_batch_decode_bo
) {
2588 .size
= (*bo
)->bo
->size
,
2589 .map
= (*bo
)->bo
->map
,
2594 return (struct gen_batch_decode_bo
) { };
2597 struct gen_aux_map_buffer
{
2598 struct gen_buffer base
;
2599 struct anv_state state
;
2602 static struct gen_buffer
*
2603 gen_aux_map_buffer_alloc(void *driver_ctx
, uint32_t size
)
2605 struct gen_aux_map_buffer
*buf
= malloc(sizeof(struct gen_aux_map_buffer
));
2609 struct anv_device
*device
= (struct anv_device
*)driver_ctx
;
2610 assert(device
->physical
->supports_48bit_addresses
&&
2611 device
->physical
->use_softpin
);
2613 struct anv_state_pool
*pool
= &device
->dynamic_state_pool
;
2614 buf
->state
= anv_state_pool_alloc(pool
, size
, size
);
2616 buf
->base
.gpu
= pool
->block_pool
.bo
->offset
+ buf
->state
.offset
;
2617 buf
->base
.gpu_end
= buf
->base
.gpu
+ buf
->state
.alloc_size
;
2618 buf
->base
.map
= buf
->state
.map
;
2619 buf
->base
.driver_bo
= &buf
->state
;
2624 gen_aux_map_buffer_free(void *driver_ctx
, struct gen_buffer
*buffer
)
2626 struct gen_aux_map_buffer
*buf
= (struct gen_aux_map_buffer
*)buffer
;
2627 struct anv_device
*device
= (struct anv_device
*)driver_ctx
;
2628 struct anv_state_pool
*pool
= &device
->dynamic_state_pool
;
2629 anv_state_pool_free(pool
, buf
->state
);
2633 static struct gen_mapped_pinned_buffer_alloc aux_map_allocator
= {
2634 .alloc
= gen_aux_map_buffer_alloc
,
2635 .free
= gen_aux_map_buffer_free
,
2639 check_physical_device_features(VkPhysicalDevice physicalDevice
,
2640 const VkPhysicalDeviceFeatures
*features
)
2642 VkPhysicalDeviceFeatures supported_features
;
2643 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2644 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2645 VkBool32
*enabled_feature
= (VkBool32
*)features
;
2646 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2647 for (uint32_t i
= 0; i
< num_features
; i
++) {
2648 if (enabled_feature
[i
] && !supported_feature
[i
])
2649 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2655 VkResult
anv_CreateDevice(
2656 VkPhysicalDevice physicalDevice
,
2657 const VkDeviceCreateInfo
* pCreateInfo
,
2658 const VkAllocationCallbacks
* pAllocator
,
2661 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
2663 struct anv_device
*device
;
2665 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
2667 struct anv_device_extension_table enabled_extensions
= { };
2668 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
2670 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
2671 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
2672 anv_device_extensions
[idx
].extensionName
) == 0)
2676 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
2677 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2679 if (!physical_device
->supported_extensions
.extensions
[idx
])
2680 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2682 enabled_extensions
.extensions
[idx
] = true;
2685 /* Check enabled features */
2686 bool robust_buffer_access
= false;
2687 if (pCreateInfo
->pEnabledFeatures
) {
2688 result
= check_physical_device_features(physicalDevice
,
2689 pCreateInfo
->pEnabledFeatures
);
2690 if (result
!= VK_SUCCESS
)
2693 if (pCreateInfo
->pEnabledFeatures
->robustBufferAccess
)
2694 robust_buffer_access
= true;
2697 vk_foreach_struct_const(ext
, pCreateInfo
->pNext
) {
2698 switch (ext
->sType
) {
2699 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2
: {
2700 const VkPhysicalDeviceFeatures2
*features
= (const void *)ext
;
2701 result
= check_physical_device_features(physicalDevice
,
2702 &features
->features
);
2703 if (result
!= VK_SUCCESS
)
2706 if (features
->features
.robustBufferAccess
)
2707 robust_buffer_access
= true;
2717 /* Check requested queues and fail if we are requested to create any
2718 * queues with flags we don't support.
2720 assert(pCreateInfo
->queueCreateInfoCount
> 0);
2721 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
2722 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
2723 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2726 /* Check if client specified queue priority. */
2727 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
2728 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
2729 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
2731 VkQueueGlobalPriorityEXT priority
=
2732 queue_priority
? queue_priority
->globalPriority
:
2733 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
2735 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
2737 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2739 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2741 vk_device_init(&device
->vk
, pCreateInfo
,
2742 &physical_device
->instance
->alloc
, pAllocator
);
2744 if (INTEL_DEBUG
& DEBUG_BATCH
) {
2745 const unsigned decode_flags
=
2746 GEN_BATCH_DECODE_FULL
|
2747 ((INTEL_DEBUG
& DEBUG_COLOR
) ? GEN_BATCH_DECODE_IN_COLOR
: 0) |
2748 GEN_BATCH_DECODE_OFFSETS
|
2749 GEN_BATCH_DECODE_FLOATS
;
2751 gen_batch_decode_ctx_init(&device
->decoder_ctx
,
2752 &physical_device
->info
,
2753 stderr
, decode_flags
, NULL
,
2754 decode_get_bo
, NULL
, device
);
2757 device
->physical
= physical_device
;
2758 device
->no_hw
= physical_device
->no_hw
;
2759 device
->_lost
= false;
2761 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
2762 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
2763 if (device
->fd
== -1) {
2764 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2768 device
->context_id
= anv_gem_create_context(device
);
2769 if (device
->context_id
== -1) {
2770 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2774 result
= anv_queue_init(device
, &device
->queue
);
2775 if (result
!= VK_SUCCESS
)
2776 goto fail_context_id
;
2778 if (physical_device
->use_softpin
) {
2779 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
2780 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2784 /* keep the page with address zero out of the allocator */
2785 util_vma_heap_init(&device
->vma_lo
,
2786 LOW_HEAP_MIN_ADDRESS
, LOW_HEAP_SIZE
);
2788 util_vma_heap_init(&device
->vma_cva
, CLIENT_VISIBLE_HEAP_MIN_ADDRESS
,
2789 CLIENT_VISIBLE_HEAP_SIZE
);
2791 /* Leave the last 4GiB out of the high vma range, so that no state
2792 * base address + size can overflow 48 bits. For more information see
2793 * the comment about Wa32bitGeneralStateOffset in anv_allocator.c
2795 util_vma_heap_init(&device
->vma_hi
, HIGH_HEAP_MIN_ADDRESS
,
2796 physical_device
->gtt_size
- (1ull << 32) -
2797 HIGH_HEAP_MIN_ADDRESS
);
2800 list_inithead(&device
->memory_objects
);
2802 /* As per spec, the driver implementation may deny requests to acquire
2803 * a priority above the default priority (MEDIUM) if the caller does not
2804 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
2807 if (physical_device
->has_context_priority
) {
2808 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
2809 I915_CONTEXT_PARAM_PRIORITY
,
2810 vk_priority_to_gen(priority
));
2811 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
2812 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
2817 device
->info
= physical_device
->info
;
2818 device
->isl_dev
= physical_device
->isl_dev
;
2820 /* On Broadwell and later, we can use batch chaining to more efficiently
2821 * implement growing command buffers. Prior to Haswell, the kernel
2822 * command parser gets in the way and we have to fall back to growing
2825 device
->can_chain_batches
= device
->info
.gen
>= 8;
2827 device
->robust_buffer_access
= robust_buffer_access
;
2828 device
->enabled_extensions
= enabled_extensions
;
2830 const struct anv_instance
*instance
= physical_device
->instance
;
2831 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2832 /* Vulkan requires that entrypoints for extensions which have not been
2833 * enabled must not be advertised.
2835 if (!anv_device_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
2836 &instance
->enabled_extensions
,
2837 &device
->enabled_extensions
)) {
2838 device
->dispatch
.entrypoints
[i
] = NULL
;
2840 device
->dispatch
.entrypoints
[i
] =
2841 anv_resolve_device_entrypoint(&device
->info
, i
);
2845 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
2846 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2850 pthread_condattr_t condattr
;
2851 if (pthread_condattr_init(&condattr
) != 0) {
2852 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2855 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
2856 pthread_condattr_destroy(&condattr
);
2857 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2860 if (pthread_cond_init(&device
->queue_submit
, &condattr
) != 0) {
2861 pthread_condattr_destroy(&condattr
);
2862 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2865 pthread_condattr_destroy(&condattr
);
2867 result
= anv_bo_cache_init(&device
->bo_cache
);
2868 if (result
!= VK_SUCCESS
)
2869 goto fail_queue_cond
;
2871 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
2873 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
2874 DYNAMIC_STATE_POOL_MIN_ADDRESS
, 0, 16384);
2875 if (result
!= VK_SUCCESS
)
2876 goto fail_batch_bo_pool
;
2878 if (device
->info
.gen
>= 8) {
2879 /* The border color pointer is limited to 24 bits, so we need to make
2880 * sure that any such color used at any point in the program doesn't
2881 * exceed that limit.
2882 * We achieve that by reserving all the custom border colors we support
2883 * right off the bat, so they are close to the base address.
2885 anv_state_reserved_pool_init(&device
->custom_border_colors
,
2886 &device
->dynamic_state_pool
,
2887 sizeof(struct gen8_border_color
),
2888 MAX_CUSTOM_BORDER_COLORS
, 64);
2891 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
2892 INSTRUCTION_STATE_POOL_MIN_ADDRESS
, 0, 16384);
2893 if (result
!= VK_SUCCESS
)
2894 goto fail_dynamic_state_pool
;
2896 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
2897 SURFACE_STATE_POOL_MIN_ADDRESS
, 0, 4096);
2898 if (result
!= VK_SUCCESS
)
2899 goto fail_instruction_state_pool
;
2901 if (physical_device
->use_softpin
) {
2902 int64_t bt_pool_offset
= (int64_t)BINDING_TABLE_POOL_MIN_ADDRESS
-
2903 (int64_t)SURFACE_STATE_POOL_MIN_ADDRESS
;
2904 assert(INT32_MIN
< bt_pool_offset
&& bt_pool_offset
< 0);
2905 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
2906 SURFACE_STATE_POOL_MIN_ADDRESS
,
2907 bt_pool_offset
, 4096);
2908 if (result
!= VK_SUCCESS
)
2909 goto fail_surface_state_pool
;
2912 if (device
->info
.has_aux_map
) {
2913 device
->aux_map_ctx
= gen_aux_map_init(device
, &aux_map_allocator
,
2914 &physical_device
->info
);
2915 if (!device
->aux_map_ctx
)
2916 goto fail_binding_table_pool
;
2919 result
= anv_device_alloc_bo(device
, 4096,
2920 ANV_BO_ALLOC_CAPTURE
| ANV_BO_ALLOC_MAPPED
/* flags */,
2921 0 /* explicit_address */,
2922 &device
->workaround_bo
);
2923 if (result
!= VK_SUCCESS
)
2924 goto fail_surface_aux_map_pool
;
2926 device
->workaround_address
= (struct anv_address
) {
2927 .bo
= device
->workaround_bo
,
2928 .offset
= align_u32(
2929 intel_debug_write_identifiers(device
->workaround_bo
->map
,
2930 device
->workaround_bo
->size
,
2934 if (!device
->info
.has_llc
) {
2935 gen_clflush_range(device
->workaround_bo
->map
,
2936 device
->workaround_address
.offset
);
2939 result
= anv_device_init_trivial_batch(device
);
2940 if (result
!= VK_SUCCESS
)
2941 goto fail_workaround_bo
;
2943 /* Allocate a null surface state at surface state offset 0. This makes
2944 * NULL descriptor handling trivial because we can just memset structures
2945 * to zero and they have a valid descriptor.
2947 device
->null_surface_state
=
2948 anv_state_pool_alloc(&device
->surface_state_pool
,
2949 device
->isl_dev
.ss
.size
,
2950 device
->isl_dev
.ss
.align
);
2951 isl_null_fill_state(&device
->isl_dev
, device
->null_surface_state
.map
,
2952 isl_extent3d(1, 1, 1) /* This shouldn't matter */);
2953 assert(device
->null_surface_state
.offset
== 0);
2955 if (device
->info
.gen
>= 10) {
2956 result
= anv_device_init_hiz_clear_value_bo(device
);
2957 if (result
!= VK_SUCCESS
)
2958 goto fail_trivial_batch_bo
;
2961 anv_scratch_pool_init(device
, &device
->scratch_pool
);
2963 switch (device
->info
.gen
) {
2965 if (!device
->info
.is_haswell
)
2966 result
= gen7_init_device_state(device
);
2968 result
= gen75_init_device_state(device
);
2971 result
= gen8_init_device_state(device
);
2974 result
= gen9_init_device_state(device
);
2977 result
= gen10_init_device_state(device
);
2980 result
= gen11_init_device_state(device
);
2983 result
= gen12_init_device_state(device
);
2986 /* Shouldn't get here as we don't create physical devices for any other
2988 unreachable("unhandled gen");
2990 if (result
!= VK_SUCCESS
)
2991 goto fail_clear_value_bo
;
2993 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
,
2994 true /* cache_enabled */, false /* external_sync */);
2996 anv_device_init_blorp(device
);
2998 anv_device_init_border_colors(device
);
3000 anv_device_perf_init(device
);
3002 *pDevice
= anv_device_to_handle(device
);
3006 fail_clear_value_bo
:
3007 if (device
->info
.gen
>= 10)
3008 anv_device_release_bo(device
, device
->hiz_clear_bo
);
3009 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
3010 fail_trivial_batch_bo
:
3011 anv_device_release_bo(device
, device
->trivial_batch_bo
);
3013 anv_device_release_bo(device
, device
->workaround_bo
);
3014 fail_surface_aux_map_pool
:
3015 if (device
->info
.has_aux_map
) {
3016 gen_aux_map_finish(device
->aux_map_ctx
);
3017 device
->aux_map_ctx
= NULL
;
3019 fail_binding_table_pool
:
3020 if (physical_device
->use_softpin
)
3021 anv_state_pool_finish(&device
->binding_table_pool
);
3022 fail_surface_state_pool
:
3023 anv_state_pool_finish(&device
->surface_state_pool
);
3024 fail_instruction_state_pool
:
3025 anv_state_pool_finish(&device
->instruction_state_pool
);
3026 fail_dynamic_state_pool
:
3027 if (device
->info
.gen
>= 8)
3028 anv_state_reserved_pool_finish(&device
->custom_border_colors
);
3029 anv_state_pool_finish(&device
->dynamic_state_pool
);
3031 anv_bo_pool_finish(&device
->batch_bo_pool
);
3032 anv_bo_cache_finish(&device
->bo_cache
);
3034 pthread_cond_destroy(&device
->queue_submit
);
3036 pthread_mutex_destroy(&device
->mutex
);
3038 if (physical_device
->use_softpin
) {
3039 util_vma_heap_finish(&device
->vma_hi
);
3040 util_vma_heap_finish(&device
->vma_cva
);
3041 util_vma_heap_finish(&device
->vma_lo
);
3044 anv_queue_finish(&device
->queue
);
3046 anv_gem_destroy_context(device
, device
->context_id
);
3050 vk_free(&device
->vk
.alloc
, device
);
3055 void anv_DestroyDevice(
3057 const VkAllocationCallbacks
* pAllocator
)
3059 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3064 anv_device_finish_blorp(device
);
3066 anv_pipeline_cache_finish(&device
->default_pipeline_cache
);
3068 anv_queue_finish(&device
->queue
);
3070 #ifdef HAVE_VALGRIND
3071 /* We only need to free these to prevent valgrind errors. The backing
3072 * BO will go away in a couple of lines so we don't actually leak.
3074 if (device
->info
.gen
>= 8)
3075 anv_state_reserved_pool_finish(&device
->custom_border_colors
);
3076 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
3077 anv_state_pool_free(&device
->dynamic_state_pool
, device
->slice_hash
);
3080 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
3082 anv_device_release_bo(device
, device
->workaround_bo
);
3083 anv_device_release_bo(device
, device
->trivial_batch_bo
);
3084 if (device
->info
.gen
>= 10)
3085 anv_device_release_bo(device
, device
->hiz_clear_bo
);
3087 if (device
->info
.has_aux_map
) {
3088 gen_aux_map_finish(device
->aux_map_ctx
);
3089 device
->aux_map_ctx
= NULL
;
3092 if (device
->physical
->use_softpin
)
3093 anv_state_pool_finish(&device
->binding_table_pool
);
3094 anv_state_pool_finish(&device
->surface_state_pool
);
3095 anv_state_pool_finish(&device
->instruction_state_pool
);
3096 anv_state_pool_finish(&device
->dynamic_state_pool
);
3098 anv_bo_pool_finish(&device
->batch_bo_pool
);
3100 anv_bo_cache_finish(&device
->bo_cache
);
3102 if (device
->physical
->use_softpin
) {
3103 util_vma_heap_finish(&device
->vma_hi
);
3104 util_vma_heap_finish(&device
->vma_cva
);
3105 util_vma_heap_finish(&device
->vma_lo
);
3108 pthread_cond_destroy(&device
->queue_submit
);
3109 pthread_mutex_destroy(&device
->mutex
);
3111 anv_gem_destroy_context(device
, device
->context_id
);
3113 if (INTEL_DEBUG
& DEBUG_BATCH
)
3114 gen_batch_decode_ctx_finish(&device
->decoder_ctx
);
3118 vk_device_finish(&device
->vk
);
3119 vk_free(&device
->vk
.alloc
, device
);
3122 VkResult
anv_EnumerateInstanceLayerProperties(
3123 uint32_t* pPropertyCount
,
3124 VkLayerProperties
* pProperties
)
3126 if (pProperties
== NULL
) {
3127 *pPropertyCount
= 0;
3131 /* None supported at this time */
3132 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
3135 VkResult
anv_EnumerateDeviceLayerProperties(
3136 VkPhysicalDevice physicalDevice
,
3137 uint32_t* pPropertyCount
,
3138 VkLayerProperties
* pProperties
)
3140 if (pProperties
== NULL
) {
3141 *pPropertyCount
= 0;
3145 /* None supported at this time */
3146 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
3149 void anv_GetDeviceQueue(
3151 uint32_t queueNodeIndex
,
3152 uint32_t queueIndex
,
3155 const VkDeviceQueueInfo2 info
= {
3156 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
3159 .queueFamilyIndex
= queueNodeIndex
,
3160 .queueIndex
= queueIndex
,
3163 anv_GetDeviceQueue2(_device
, &info
, pQueue
);
3166 void anv_GetDeviceQueue2(
3168 const VkDeviceQueueInfo2
* pQueueInfo
,
3171 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3173 assert(pQueueInfo
->queueIndex
== 0);
3175 if (pQueueInfo
->flags
== device
->queue
.flags
)
3176 *pQueue
= anv_queue_to_handle(&device
->queue
);
3182 _anv_device_set_lost(struct anv_device
*device
,
3183 const char *file
, int line
,
3184 const char *msg
, ...)
3189 p_atomic_inc(&device
->_lost
);
3192 err
= __vk_errorv(device
->physical
->instance
, device
,
3193 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
3194 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
3197 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
3204 _anv_queue_set_lost(struct anv_queue
*queue
,
3205 const char *file
, int line
,
3206 const char *msg
, ...)
3211 p_atomic_inc(&queue
->device
->_lost
);
3214 err
= __vk_errorv(queue
->device
->physical
->instance
, queue
->device
,
3215 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
3216 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
3219 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
3226 anv_device_query_status(struct anv_device
*device
)
3228 /* This isn't likely as most of the callers of this function already check
3229 * for it. However, it doesn't hurt to check and it potentially lets us
3232 if (anv_device_is_lost(device
))
3233 return VK_ERROR_DEVICE_LOST
;
3235 uint32_t active
, pending
;
3236 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
3238 /* We don't know the real error. */
3239 return anv_device_set_lost(device
, "get_reset_stats failed: %m");
3243 return anv_device_set_lost(device
, "GPU hung on one of our command buffers");
3244 } else if (pending
) {
3245 return anv_device_set_lost(device
, "GPU hung with commands in-flight");
3252 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
3254 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
3255 * Other usages of the BO (such as on different hardware) will not be
3256 * flagged as "busy" by this ioctl. Use with care.
3258 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
3260 return VK_NOT_READY
;
3261 } else if (ret
== -1) {
3262 /* We don't know the real error. */
3263 return anv_device_set_lost(device
, "gem wait failed: %m");
3266 /* Query for device status after the busy call. If the BO we're checking
3267 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
3268 * client because it clearly doesn't have valid data. Yes, this most
3269 * likely means an ioctl, but we just did an ioctl to query the busy status
3270 * so it's no great loss.
3272 return anv_device_query_status(device
);
3276 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
3279 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
3280 if (ret
== -1 && errno
== ETIME
) {
3282 } else if (ret
== -1) {
3283 /* We don't know the real error. */
3284 return anv_device_set_lost(device
, "gem wait failed: %m");
3287 /* Query for device status after the wait. If the BO we're waiting on got
3288 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
3289 * because it clearly doesn't have valid data. Yes, this most likely means
3290 * an ioctl, but we just did an ioctl to wait so it's no great loss.
3292 return anv_device_query_status(device
);
3295 VkResult
anv_DeviceWaitIdle(
3298 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3300 if (anv_device_is_lost(device
))
3301 return VK_ERROR_DEVICE_LOST
;
3303 return anv_queue_submit_simple_batch(&device
->queue
, NULL
);
3307 anv_vma_alloc(struct anv_device
*device
,
3308 uint64_t size
, uint64_t align
,
3309 enum anv_bo_alloc_flags alloc_flags
,
3310 uint64_t client_address
)
3312 pthread_mutex_lock(&device
->vma_mutex
);
3316 if (alloc_flags
& ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS
) {
3317 if (client_address
) {
3318 if (util_vma_heap_alloc_addr(&device
->vma_cva
,
3319 client_address
, size
)) {
3320 addr
= client_address
;
3323 addr
= util_vma_heap_alloc(&device
->vma_cva
, size
, align
);
3325 /* We don't want to fall back to other heaps */
3329 assert(client_address
== 0);
3331 if (!(alloc_flags
& ANV_BO_ALLOC_32BIT_ADDRESS
))
3332 addr
= util_vma_heap_alloc(&device
->vma_hi
, size
, align
);
3335 addr
= util_vma_heap_alloc(&device
->vma_lo
, size
, align
);
3338 pthread_mutex_unlock(&device
->vma_mutex
);
3340 assert(addr
== gen_48b_address(addr
));
3341 return gen_canonical_address(addr
);
3345 anv_vma_free(struct anv_device
*device
,
3346 uint64_t address
, uint64_t size
)
3348 const uint64_t addr_48b
= gen_48b_address(address
);
3350 pthread_mutex_lock(&device
->vma_mutex
);
3352 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
3353 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
3354 util_vma_heap_free(&device
->vma_lo
, addr_48b
, size
);
3355 } else if (addr_48b
>= CLIENT_VISIBLE_HEAP_MIN_ADDRESS
&&
3356 addr_48b
<= CLIENT_VISIBLE_HEAP_MAX_ADDRESS
) {
3357 util_vma_heap_free(&device
->vma_cva
, addr_48b
, size
);
3359 assert(addr_48b
>= HIGH_HEAP_MIN_ADDRESS
);
3360 util_vma_heap_free(&device
->vma_hi
, addr_48b
, size
);
3363 pthread_mutex_unlock(&device
->vma_mutex
);
3366 VkResult
anv_AllocateMemory(
3368 const VkMemoryAllocateInfo
* pAllocateInfo
,
3369 const VkAllocationCallbacks
* pAllocator
,
3370 VkDeviceMemory
* pMem
)
3372 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3373 struct anv_physical_device
*pdevice
= device
->physical
;
3374 struct anv_device_memory
*mem
;
3375 VkResult result
= VK_SUCCESS
;
3377 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3379 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
3380 assert(pAllocateInfo
->allocationSize
> 0);
3382 VkDeviceSize aligned_alloc_size
=
3383 align_u64(pAllocateInfo
->allocationSize
, 4096);
3385 if (aligned_alloc_size
> MAX_MEMORY_ALLOCATION_SIZE
)
3386 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3388 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
3389 struct anv_memory_type
*mem_type
=
3390 &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
3391 assert(mem_type
->heapIndex
< pdevice
->memory
.heap_count
);
3392 struct anv_memory_heap
*mem_heap
=
3393 &pdevice
->memory
.heaps
[mem_type
->heapIndex
];
3395 uint64_t mem_heap_used
= p_atomic_read(&mem_heap
->used
);
3396 if (mem_heap_used
+ aligned_alloc_size
> mem_heap
->size
)
3397 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3399 mem
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*mem
), 8,
3400 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3402 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3404 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
3405 vk_object_base_init(&device
->vk
, &mem
->base
, VK_OBJECT_TYPE_DEVICE_MEMORY
);
3406 mem
->type
= mem_type
;
3410 mem
->host_ptr
= NULL
;
3412 enum anv_bo_alloc_flags alloc_flags
= 0;
3414 const VkExportMemoryAllocateInfo
*export_info
= NULL
;
3415 const VkImportAndroidHardwareBufferInfoANDROID
*ahw_import_info
= NULL
;
3416 const VkImportMemoryFdInfoKHR
*fd_info
= NULL
;
3417 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
= NULL
;
3418 const VkMemoryDedicatedAllocateInfo
*dedicated_info
= NULL
;
3419 VkMemoryAllocateFlags vk_flags
= 0;
3420 uint64_t client_address
= 0;
3422 vk_foreach_struct_const(ext
, pAllocateInfo
->pNext
) {
3423 switch (ext
->sType
) {
3424 case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO
:
3425 export_info
= (void *)ext
;
3428 case VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
:
3429 ahw_import_info
= (void *)ext
;
3432 case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR
:
3433 fd_info
= (void *)ext
;
3436 case VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT
:
3437 host_ptr_info
= (void *)ext
;
3440 case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO
: {
3441 const VkMemoryAllocateFlagsInfo
*flags_info
= (void *)ext
;
3442 vk_flags
= flags_info
->flags
;
3446 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO
:
3447 dedicated_info
= (void *)ext
;
3450 case VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO_KHR
: {
3451 const VkMemoryOpaqueCaptureAddressAllocateInfoKHR
*addr_info
=
3452 (const VkMemoryOpaqueCaptureAddressAllocateInfoKHR
*)ext
;
3453 client_address
= addr_info
->opaqueCaptureAddress
;
3458 anv_debug_ignored_stype(ext
->sType
);
3463 /* By default, we want all VkDeviceMemory objects to support CCS */
3464 if (device
->physical
->has_implicit_ccs
)
3465 alloc_flags
|= ANV_BO_ALLOC_IMPLICIT_CCS
;
3467 if (vk_flags
& VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR
)
3468 alloc_flags
|= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS
;
3470 if ((export_info
&& export_info
->handleTypes
) ||
3471 (fd_info
&& fd_info
->handleType
) ||
3472 (host_ptr_info
&& host_ptr_info
->handleType
)) {
3473 /* Anything imported or exported is EXTERNAL */
3474 alloc_flags
|= ANV_BO_ALLOC_EXTERNAL
;
3476 /* We can't have implicit CCS on external memory with an AUX-table.
3477 * Doing so would require us to sync the aux tables across processes
3478 * which is impractical.
3480 if (device
->info
.has_aux_map
)
3481 alloc_flags
&= ~ANV_BO_ALLOC_IMPLICIT_CCS
;
3484 /* Check if we need to support Android HW buffer export. If so,
3485 * create AHardwareBuffer and import memory from it.
3487 bool android_export
= false;
3488 if (export_info
&& export_info
->handleTypes
&
3489 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)
3490 android_export
= true;
3492 if (ahw_import_info
) {
3493 result
= anv_import_ahw_memory(_device
, mem
, ahw_import_info
);
3494 if (result
!= VK_SUCCESS
)
3498 } else if (android_export
) {
3499 result
= anv_create_ahw_memory(_device
, mem
, pAllocateInfo
);
3500 if (result
!= VK_SUCCESS
)
3503 const VkImportAndroidHardwareBufferInfoANDROID import_info
= {
3506 result
= anv_import_ahw_memory(_device
, mem
, &import_info
);
3507 if (result
!= VK_SUCCESS
)
3513 /* The Vulkan spec permits handleType to be 0, in which case the struct is
3516 if (fd_info
&& fd_info
->handleType
) {
3517 /* At the moment, we support only the below handle types. */
3518 assert(fd_info
->handleType
==
3519 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3520 fd_info
->handleType
==
3521 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3523 result
= anv_device_import_bo(device
, fd_info
->fd
, alloc_flags
,
3524 client_address
, &mem
->bo
);
3525 if (result
!= VK_SUCCESS
)
3528 /* For security purposes, we reject importing the bo if it's smaller
3529 * than the requested allocation size. This prevents a malicious client
3530 * from passing a buffer to a trusted client, lying about the size, and
3531 * telling the trusted client to try and texture from an image that goes
3532 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
3533 * in the trusted client. The trusted client can protect itself against
3534 * this sort of attack but only if it can trust the buffer size.
3536 if (mem
->bo
->size
< aligned_alloc_size
) {
3537 result
= vk_errorf(device
, device
, VK_ERROR_INVALID_EXTERNAL_HANDLE
,
3538 "aligned allocationSize too large for "
3539 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: "
3540 "%"PRIu64
"B > %"PRIu64
"B",
3541 aligned_alloc_size
, mem
->bo
->size
);
3542 anv_device_release_bo(device
, mem
->bo
);
3546 /* From the Vulkan spec:
3548 * "Importing memory from a file descriptor transfers ownership of
3549 * the file descriptor from the application to the Vulkan
3550 * implementation. The application must not perform any operations on
3551 * the file descriptor after a successful import."
3553 * If the import fails, we leave the file descriptor open.
3559 if (host_ptr_info
&& host_ptr_info
->handleType
) {
3560 if (host_ptr_info
->handleType
==
3561 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT
) {
3562 result
= vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3566 assert(host_ptr_info
->handleType
==
3567 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3569 result
= anv_device_import_bo_from_host_ptr(device
,
3570 host_ptr_info
->pHostPointer
,
3571 pAllocateInfo
->allocationSize
,
3575 if (result
!= VK_SUCCESS
)
3578 mem
->host_ptr
= host_ptr_info
->pHostPointer
;
3582 /* Regular allocate (not importing memory). */
3584 result
= anv_device_alloc_bo(device
, pAllocateInfo
->allocationSize
,
3585 alloc_flags
, client_address
, &mem
->bo
);
3586 if (result
!= VK_SUCCESS
)
3589 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
3590 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
3592 /* Some legacy (non-modifiers) consumers need the tiling to be set on
3593 * the BO. In this case, we have a dedicated allocation.
3595 if (image
->needs_set_tiling
) {
3596 const uint32_t i915_tiling
=
3597 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
3598 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
3599 image
->planes
[0].surface
.isl
.row_pitch_B
,
3602 anv_device_release_bo(device
, mem
->bo
);
3603 result
= vk_errorf(device
, device
, VK_ERROR_OUT_OF_DEVICE_MEMORY
,
3604 "failed to set BO tiling: %m");
3611 mem_heap_used
= p_atomic_add_return(&mem_heap
->used
, mem
->bo
->size
);
3612 if (mem_heap_used
> mem_heap
->size
) {
3613 p_atomic_add(&mem_heap
->used
, -mem
->bo
->size
);
3614 anv_device_release_bo(device
, mem
->bo
);
3615 result
= vk_errorf(device
, device
, VK_ERROR_OUT_OF_DEVICE_MEMORY
,
3616 "Out of heap memory");
3620 pthread_mutex_lock(&device
->mutex
);
3621 list_addtail(&mem
->link
, &device
->memory_objects
);
3622 pthread_mutex_unlock(&device
->mutex
);
3624 *pMem
= anv_device_memory_to_handle(mem
);
3629 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);
3634 VkResult
anv_GetMemoryFdKHR(
3636 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
3639 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
3640 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
3642 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3644 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3645 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3647 return anv_device_export_bo(dev
, mem
->bo
, pFd
);
3650 VkResult
anv_GetMemoryFdPropertiesKHR(
3652 VkExternalMemoryHandleTypeFlagBits handleType
,
3654 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
3656 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3658 switch (handleType
) {
3659 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
3660 /* dma-buf can be imported as any memory type */
3661 pMemoryFdProperties
->memoryTypeBits
=
3662 (1 << device
->physical
->memory
.type_count
) - 1;
3666 /* The valid usage section for this function says:
3668 * "handleType must not be one of the handle types defined as
3671 * So opaque handle types fall into the default "unsupported" case.
3673 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3677 VkResult
anv_GetMemoryHostPointerPropertiesEXT(
3679 VkExternalMemoryHandleTypeFlagBits handleType
,
3680 const void* pHostPointer
,
3681 VkMemoryHostPointerPropertiesEXT
* pMemoryHostPointerProperties
)
3683 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3685 assert(pMemoryHostPointerProperties
->sType
==
3686 VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT
);
3688 switch (handleType
) {
3689 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
3690 /* Host memory can be imported as any memory type. */
3691 pMemoryHostPointerProperties
->memoryTypeBits
=
3692 (1ull << device
->physical
->memory
.type_count
) - 1;
3697 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3701 void anv_FreeMemory(
3703 VkDeviceMemory _mem
,
3704 const VkAllocationCallbacks
* pAllocator
)
3706 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3707 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
3712 pthread_mutex_lock(&device
->mutex
);
3713 list_del(&mem
->link
);
3714 pthread_mutex_unlock(&device
->mutex
);
3717 anv_UnmapMemory(_device
, _mem
);
3719 p_atomic_add(&device
->physical
->memory
.heaps
[mem
->type
->heapIndex
].used
,
3722 anv_device_release_bo(device
, mem
->bo
);
3724 #if defined(ANDROID) && ANDROID_API_LEVEL >= 26
3726 AHardwareBuffer_release(mem
->ahw
);
3729 vk_object_base_finish(&mem
->base
);
3730 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);
3733 VkResult
anv_MapMemory(
3735 VkDeviceMemory _memory
,
3736 VkDeviceSize offset
,
3738 VkMemoryMapFlags flags
,
3741 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3742 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3749 if (mem
->host_ptr
) {
3750 *ppData
= mem
->host_ptr
+ offset
;
3754 if (size
== VK_WHOLE_SIZE
)
3755 size
= mem
->bo
->size
- offset
;
3757 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
3759 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
3760 * assert(size != 0);
3761 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
3762 * equal to the size of the memory minus offset
3765 assert(offset
+ size
<= mem
->bo
->size
);
3767 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
3768 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
3769 * at a time is valid. We could just mmap up front and return an offset
3770 * pointer here, but that may exhaust virtual memory on 32 bit
3773 uint32_t gem_flags
= 0;
3775 if (!device
->info
.has_llc
&&
3776 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
3777 gem_flags
|= I915_MMAP_WC
;
3779 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
3780 uint64_t map_offset
;
3781 if (!device
->physical
->has_mmap_offset
)
3782 map_offset
= offset
& ~4095ull;
3785 assert(offset
>= map_offset
);
3786 uint64_t map_size
= (offset
+ size
) - map_offset
;
3788 /* Let's map whole pages */
3789 map_size
= align_u64(map_size
, 4096);
3791 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
3792 map_offset
, map_size
, gem_flags
);
3793 if (map
== MAP_FAILED
)
3794 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
3797 mem
->map_size
= map_size
;
3799 *ppData
= mem
->map
+ (offset
- map_offset
);
3804 void anv_UnmapMemory(
3806 VkDeviceMemory _memory
)
3808 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3809 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3811 if (mem
== NULL
|| mem
->host_ptr
)
3814 anv_gem_munmap(device
, mem
->map
, mem
->map_size
);
3821 clflush_mapped_ranges(struct anv_device
*device
,
3823 const VkMappedMemoryRange
*ranges
)
3825 for (uint32_t i
= 0; i
< count
; i
++) {
3826 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
3827 if (ranges
[i
].offset
>= mem
->map_size
)
3830 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
3831 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
3835 VkResult
anv_FlushMappedMemoryRanges(
3837 uint32_t memoryRangeCount
,
3838 const VkMappedMemoryRange
* pMemoryRanges
)
3840 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3842 if (device
->info
.has_llc
)
3845 /* Make sure the writes we're flushing have landed. */
3846 __builtin_ia32_mfence();
3848 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3853 VkResult
anv_InvalidateMappedMemoryRanges(
3855 uint32_t memoryRangeCount
,
3856 const VkMappedMemoryRange
* pMemoryRanges
)
3858 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3860 if (device
->info
.has_llc
)
3863 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3865 /* Make sure no reads get moved up above the invalidate. */
3866 __builtin_ia32_mfence();
3871 void anv_GetBufferMemoryRequirements(
3874 VkMemoryRequirements
* pMemoryRequirements
)
3876 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3877 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3879 /* The Vulkan spec (git aaed022) says:
3881 * memoryTypeBits is a bitfield and contains one bit set for every
3882 * supported memory type for the resource. The bit `1<<i` is set if and
3883 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3884 * structure for the physical device is supported.
3886 uint32_t memory_types
= (1ull << device
->physical
->memory
.type_count
) - 1;
3888 /* Base alignment requirement of a cache line */
3889 uint32_t alignment
= 16;
3891 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
3892 alignment
= MAX2(alignment
, ANV_UBO_ALIGNMENT
);
3894 pMemoryRequirements
->size
= buffer
->size
;
3895 pMemoryRequirements
->alignment
= alignment
;
3897 /* Storage and Uniform buffers should have their size aligned to
3898 * 32-bits to avoid boundary checks when last DWord is not complete.
3899 * This would ensure that not internal padding would be needed for
3902 if (device
->robust_buffer_access
&&
3903 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
3904 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
3905 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
3907 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3910 void anv_GetBufferMemoryRequirements2(
3912 const VkBufferMemoryRequirementsInfo2
* pInfo
,
3913 VkMemoryRequirements2
* pMemoryRequirements
)
3915 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
3916 &pMemoryRequirements
->memoryRequirements
);
3918 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3919 switch (ext
->sType
) {
3920 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3921 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
3922 requirements
->prefersDedicatedAllocation
= false;
3923 requirements
->requiresDedicatedAllocation
= false;
3928 anv_debug_ignored_stype(ext
->sType
);
3934 void anv_GetImageMemoryRequirements(
3937 VkMemoryRequirements
* pMemoryRequirements
)
3939 ANV_FROM_HANDLE(anv_image
, image
, _image
);
3940 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3942 /* The Vulkan spec (git aaed022) says:
3944 * memoryTypeBits is a bitfield and contains one bit set for every
3945 * supported memory type for the resource. The bit `1<<i` is set if and
3946 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3947 * structure for the physical device is supported.
3949 * All types are currently supported for images.
3951 uint32_t memory_types
= (1ull << device
->physical
->memory
.type_count
) - 1;
3953 pMemoryRequirements
->size
= image
->size
;
3954 pMemoryRequirements
->alignment
= image
->alignment
;
3955 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3958 void anv_GetImageMemoryRequirements2(
3960 const VkImageMemoryRequirementsInfo2
* pInfo
,
3961 VkMemoryRequirements2
* pMemoryRequirements
)
3963 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3964 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
3966 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
3967 &pMemoryRequirements
->memoryRequirements
);
3969 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
3970 switch (ext
->sType
) {
3971 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
3972 const VkImagePlaneMemoryRequirementsInfo
*plane_reqs
=
3973 (const VkImagePlaneMemoryRequirementsInfo
*) ext
;
3974 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
3975 plane_reqs
->planeAspect
);
3977 assert(image
->planes
[plane
].offset
== 0);
3979 /* The Vulkan spec (git aaed022) says:
3981 * memoryTypeBits is a bitfield and contains one bit set for every
3982 * supported memory type for the resource. The bit `1<<i` is set
3983 * if and only if the memory type `i` in the
3984 * VkPhysicalDeviceMemoryProperties structure for the physical
3985 * device is supported.
3987 * All types are currently supported for images.
3989 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
3990 (1ull << device
->physical
->memory
.type_count
) - 1;
3992 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
3993 pMemoryRequirements
->memoryRequirements
.alignment
=
3994 image
->planes
[plane
].alignment
;
3999 anv_debug_ignored_stype(ext
->sType
);
4004 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
4005 switch (ext
->sType
) {
4006 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
4007 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
4008 if (image
->needs_set_tiling
|| image
->external_format
) {
4009 /* If we need to set the tiling for external consumers, we need a
4010 * dedicated allocation.
4012 * See also anv_AllocateMemory.
4014 requirements
->prefersDedicatedAllocation
= true;
4015 requirements
->requiresDedicatedAllocation
= true;
4017 requirements
->prefersDedicatedAllocation
= false;
4018 requirements
->requiresDedicatedAllocation
= false;
4024 anv_debug_ignored_stype(ext
->sType
);
4030 void anv_GetImageSparseMemoryRequirements(
4033 uint32_t* pSparseMemoryRequirementCount
,
4034 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
4036 *pSparseMemoryRequirementCount
= 0;
4039 void anv_GetImageSparseMemoryRequirements2(
4041 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
4042 uint32_t* pSparseMemoryRequirementCount
,
4043 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
4045 *pSparseMemoryRequirementCount
= 0;
4048 void anv_GetDeviceMemoryCommitment(
4050 VkDeviceMemory memory
,
4051 VkDeviceSize
* pCommittedMemoryInBytes
)
4053 *pCommittedMemoryInBytes
= 0;
4057 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
4059 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
4060 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
4062 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
4065 buffer
->address
= (struct anv_address
) {
4067 .offset
= pBindInfo
->memoryOffset
,
4070 buffer
->address
= ANV_NULL_ADDRESS
;
4074 VkResult
anv_BindBufferMemory(
4077 VkDeviceMemory memory
,
4078 VkDeviceSize memoryOffset
)
4080 anv_bind_buffer_memory(
4081 &(VkBindBufferMemoryInfo
) {
4082 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
4085 .memoryOffset
= memoryOffset
,
4091 VkResult
anv_BindBufferMemory2(
4093 uint32_t bindInfoCount
,
4094 const VkBindBufferMemoryInfo
* pBindInfos
)
4096 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
4097 anv_bind_buffer_memory(&pBindInfos
[i
]);
4102 VkResult
anv_QueueBindSparse(
4104 uint32_t bindInfoCount
,
4105 const VkBindSparseInfo
* pBindInfo
,
4108 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
4109 if (anv_device_is_lost(queue
->device
))
4110 return VK_ERROR_DEVICE_LOST
;
4112 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
4117 VkResult
anv_CreateEvent(
4119 const VkEventCreateInfo
* pCreateInfo
,
4120 const VkAllocationCallbacks
* pAllocator
,
4123 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4124 struct anv_event
*event
;
4126 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
4128 event
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*event
), 8,
4129 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4131 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4133 vk_object_base_init(&device
->vk
, &event
->base
, VK_OBJECT_TYPE_EVENT
);
4134 event
->state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
4135 sizeof(uint64_t), 8);
4136 *(uint64_t *)event
->state
.map
= VK_EVENT_RESET
;
4138 *pEvent
= anv_event_to_handle(event
);
4143 void anv_DestroyEvent(
4146 const VkAllocationCallbacks
* pAllocator
)
4148 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4149 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4154 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
4156 vk_object_base_finish(&event
->base
);
4157 vk_free2(&device
->vk
.alloc
, pAllocator
, event
);
4160 VkResult
anv_GetEventStatus(
4164 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4165 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4167 if (anv_device_is_lost(device
))
4168 return VK_ERROR_DEVICE_LOST
;
4170 return *(uint64_t *)event
->state
.map
;
4173 VkResult
anv_SetEvent(
4177 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4179 *(uint64_t *)event
->state
.map
= VK_EVENT_SET
;
4184 VkResult
anv_ResetEvent(
4188 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4190 *(uint64_t *)event
->state
.map
= VK_EVENT_RESET
;
4197 VkResult
anv_CreateBuffer(
4199 const VkBufferCreateInfo
* pCreateInfo
,
4200 const VkAllocationCallbacks
* pAllocator
,
4203 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4204 struct anv_buffer
*buffer
;
4206 /* Don't allow creating buffers bigger than our address space. The real
4207 * issue here is that we may align up the buffer size and we don't want
4208 * doing so to cause roll-over. However, no one has any business
4209 * allocating a buffer larger than our GTT size.
4211 if (pCreateInfo
->size
> device
->physical
->gtt_size
)
4212 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4214 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4216 buffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*buffer
), 8,
4217 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4219 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4221 vk_object_base_init(&device
->vk
, &buffer
->base
, VK_OBJECT_TYPE_BUFFER
);
4222 buffer
->size
= pCreateInfo
->size
;
4223 buffer
->usage
= pCreateInfo
->usage
;
4224 buffer
->address
= ANV_NULL_ADDRESS
;
4226 *pBuffer
= anv_buffer_to_handle(buffer
);
4231 void anv_DestroyBuffer(
4234 const VkAllocationCallbacks
* pAllocator
)
4236 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4237 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
4242 vk_object_base_finish(&buffer
->base
);
4243 vk_free2(&device
->vk
.alloc
, pAllocator
, buffer
);
4246 VkDeviceAddress
anv_GetBufferDeviceAddress(
4248 const VkBufferDeviceAddressInfoKHR
* pInfo
)
4250 ANV_FROM_HANDLE(anv_buffer
, buffer
, pInfo
->buffer
);
4252 assert(!anv_address_is_null(buffer
->address
));
4253 assert(buffer
->address
.bo
->flags
& EXEC_OBJECT_PINNED
);
4255 return anv_address_physical(buffer
->address
);
4258 uint64_t anv_GetBufferOpaqueCaptureAddress(
4260 const VkBufferDeviceAddressInfoKHR
* pInfo
)
4265 uint64_t anv_GetDeviceMemoryOpaqueCaptureAddress(
4267 const VkDeviceMemoryOpaqueCaptureAddressInfoKHR
* pInfo
)
4269 ANV_FROM_HANDLE(anv_device_memory
, memory
, pInfo
->memory
);
4271 assert(memory
->bo
->flags
& EXEC_OBJECT_PINNED
);
4272 assert(memory
->bo
->has_client_visible_address
);
4274 return gen_48b_address(memory
->bo
->offset
);
4278 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
4279 enum isl_format format
,
4280 struct anv_address address
,
4281 uint32_t range
, uint32_t stride
)
4283 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
4284 .address
= anv_address_physical(address
),
4285 .mocs
= device
->isl_dev
.mocs
.internal
,
4288 .swizzle
= ISL_SWIZZLE_IDENTITY
,
4289 .stride_B
= stride
);
4292 void anv_DestroySampler(
4295 const VkAllocationCallbacks
* pAllocator
)
4297 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4298 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
4303 if (sampler
->bindless_state
.map
) {
4304 anv_state_pool_free(&device
->dynamic_state_pool
,
4305 sampler
->bindless_state
);
4308 if (sampler
->custom_border_color
.map
) {
4309 anv_state_reserved_pool_free(&device
->custom_border_colors
,
4310 sampler
->custom_border_color
);
4313 vk_object_base_finish(&sampler
->base
);
4314 vk_free2(&device
->vk
.alloc
, pAllocator
, sampler
);
4317 VkResult
anv_CreateFramebuffer(
4319 const VkFramebufferCreateInfo
* pCreateInfo
,
4320 const VkAllocationCallbacks
* pAllocator
,
4321 VkFramebuffer
* pFramebuffer
)
4323 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4324 struct anv_framebuffer
*framebuffer
;
4326 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4328 size_t size
= sizeof(*framebuffer
);
4330 /* VK_KHR_imageless_framebuffer extension says:
4332 * If flags includes VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR,
4333 * parameter pAttachments is ignored.
4335 if (!(pCreateInfo
->flags
& VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR
)) {
4336 size
+= sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
4337 framebuffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
4338 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4339 if (framebuffer
== NULL
)
4340 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4342 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4343 ANV_FROM_HANDLE(anv_image_view
, iview
, pCreateInfo
->pAttachments
[i
]);
4344 framebuffer
->attachments
[i
] = iview
;
4346 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4348 framebuffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
4349 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4350 if (framebuffer
== NULL
)
4351 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4353 framebuffer
->attachment_count
= 0;
4356 vk_object_base_init(&device
->vk
, &framebuffer
->base
,
4357 VK_OBJECT_TYPE_FRAMEBUFFER
);
4359 framebuffer
->width
= pCreateInfo
->width
;
4360 framebuffer
->height
= pCreateInfo
->height
;
4361 framebuffer
->layers
= pCreateInfo
->layers
;
4363 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
4368 void anv_DestroyFramebuffer(
4371 const VkAllocationCallbacks
* pAllocator
)
4373 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4374 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
4379 vk_object_base_finish(&fb
->base
);
4380 vk_free2(&device
->vk
.alloc
, pAllocator
, fb
);
4383 static const VkTimeDomainEXT anv_time_domains
[] = {
4384 VK_TIME_DOMAIN_DEVICE_EXT
,
4385 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
4386 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
4389 VkResult
anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
4390 VkPhysicalDevice physicalDevice
,
4391 uint32_t *pTimeDomainCount
,
4392 VkTimeDomainEXT
*pTimeDomains
)
4395 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
4397 for (d
= 0; d
< ARRAY_SIZE(anv_time_domains
); d
++) {
4398 vk_outarray_append(&out
, i
) {
4399 *i
= anv_time_domains
[d
];
4403 return vk_outarray_status(&out
);
4407 anv_clock_gettime(clockid_t clock_id
)
4409 struct timespec current
;
4412 ret
= clock_gettime(clock_id
, ¤t
);
4413 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
4414 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
4418 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
4421 VkResult
anv_GetCalibratedTimestampsEXT(
4423 uint32_t timestampCount
,
4424 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
4425 uint64_t *pTimestamps
,
4426 uint64_t *pMaxDeviation
)
4428 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4429 uint64_t timestamp_frequency
= device
->info
.timestamp_frequency
;
4432 uint64_t begin
, end
;
4433 uint64_t max_clock_period
= 0;
4435 begin
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
4437 for (d
= 0; d
< timestampCount
; d
++) {
4438 switch (pTimestampInfos
[d
].timeDomain
) {
4439 case VK_TIME_DOMAIN_DEVICE_EXT
:
4440 ret
= anv_gem_reg_read(device
->fd
, TIMESTAMP
| I915_REG_READ_8B_WA
,
4444 return anv_device_set_lost(device
, "Failed to read the TIMESTAMP "
4447 uint64_t device_period
= DIV_ROUND_UP(1000000000, timestamp_frequency
);
4448 max_clock_period
= MAX2(max_clock_period
, device_period
);
4450 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
4451 pTimestamps
[d
] = anv_clock_gettime(CLOCK_MONOTONIC
);
4452 max_clock_period
= MAX2(max_clock_period
, 1);
4455 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
4456 pTimestamps
[d
] = begin
;
4464 end
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
4467 * The maximum deviation is the sum of the interval over which we
4468 * perform the sampling and the maximum period of any sampled
4469 * clock. That's because the maximum skew between any two sampled
4470 * clock edges is when the sampled clock with the largest period is
4471 * sampled at the end of that period but right at the beginning of the
4472 * sampling interval and some other clock is sampled right at the
4473 * begining of its sampling period and right at the end of the
4474 * sampling interval. Let's assume the GPU has the longest clock
4475 * period and that the application is sampling GPU and monotonic:
4478 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
4479 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
4483 * GPU -----_____-----_____-----_____-----_____
4486 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
4487 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
4489 * Interval <----------------->
4490 * Deviation <-------------------------->
4494 * m = read(monotonic) 2
4497 * We round the sample interval up by one tick to cover sampling error
4498 * in the interval clock
4501 uint64_t sample_interval
= end
- begin
+ 1;
4503 *pMaxDeviation
= sample_interval
+ max_clock_period
;
4508 /* vk_icd.h does not declare this function, so we declare it here to
4509 * suppress Wmissing-prototypes.
4511 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4512 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
4514 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4515 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
4517 /* For the full details on loader interface versioning, see
4518 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4519 * What follows is a condensed summary, to help you navigate the large and
4520 * confusing official doc.
4522 * - Loader interface v0 is incompatible with later versions. We don't
4525 * - In loader interface v1:
4526 * - The first ICD entrypoint called by the loader is
4527 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4529 * - The ICD must statically expose no other Vulkan symbol unless it is
4530 * linked with -Bsymbolic.
4531 * - Each dispatchable Vulkan handle created by the ICD must be
4532 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4533 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4534 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4535 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4536 * such loader-managed surfaces.
4538 * - Loader interface v2 differs from v1 in:
4539 * - The first ICD entrypoint called by the loader is
4540 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4541 * statically expose this entrypoint.
4543 * - Loader interface v3 differs from v2 in:
4544 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4545 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4546 * because the loader no longer does so.
4548 * - Loader interface v4 differs from v3 in:
4549 * - The ICD must implement vk_icdGetPhysicalDeviceProcAddr().
4551 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
4555 VkResult
anv_CreatePrivateDataSlotEXT(
4557 const VkPrivateDataSlotCreateInfoEXT
* pCreateInfo
,
4558 const VkAllocationCallbacks
* pAllocator
,
4559 VkPrivateDataSlotEXT
* pPrivateDataSlot
)
4561 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4562 return vk_private_data_slot_create(&device
->vk
, pCreateInfo
, pAllocator
,
4566 void anv_DestroyPrivateDataSlotEXT(
4568 VkPrivateDataSlotEXT privateDataSlot
,
4569 const VkAllocationCallbacks
* pAllocator
)
4571 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4572 vk_private_data_slot_destroy(&device
->vk
, privateDataSlot
, pAllocator
);
4575 VkResult
anv_SetPrivateDataEXT(
4577 VkObjectType objectType
,
4578 uint64_t objectHandle
,
4579 VkPrivateDataSlotEXT privateDataSlot
,
4582 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4583 return vk_object_base_set_private_data(&device
->vk
,
4584 objectType
, objectHandle
,
4585 privateDataSlot
, data
);
4588 void anv_GetPrivateDataEXT(
4590 VkObjectType objectType
,
4591 uint64_t objectHandle
,
4592 VkPrivateDataSlotEXT privateDataSlot
,
4595 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4596 vk_object_base_get_private_data(&device
->vk
,
4597 objectType
, objectHandle
,
4598 privateDataSlot
, pData
);