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>
31 #include "drm-uapi/drm_fourcc.h"
32 #include "drm-uapi/drm.h"
35 #include "anv_private.h"
36 #include "util/debug.h"
37 #include "util/build_id.h"
38 #include "util/disk_cache.h"
39 #include "util/mesa-sha1.h"
40 #include "util/os_file.h"
41 #include "util/u_atomic.h"
42 #include "util/u_string.h"
43 #include "util/driconf.h"
46 #include "common/gen_aux_map.h"
47 #include "common/gen_defines.h"
48 #include "compiler/glsl_types.h"
50 #include "genxml/gen7_pack.h"
52 static const char anv_dri_options_xml
[] =
54 DRI_CONF_SECTION_PERFORMANCE
55 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
56 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
59 DRI_CONF_SECTION_DEBUG
60 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
61 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
65 /* This is probably far to big but it reflects the max size used for messages
66 * in OpenGLs KHR_debug.
68 #define MAX_DEBUG_MESSAGE_LENGTH 4096
70 /* Render engine timestamp register */
71 #define TIMESTAMP 0x2358
74 compiler_debug_log(void *data
, const char *fmt
, ...)
76 char str
[MAX_DEBUG_MESSAGE_LENGTH
];
77 struct anv_device
*device
= (struct anv_device
*)data
;
78 struct anv_instance
*instance
= device
->physical
->instance
;
80 if (list_is_empty(&instance
->debug_report_callbacks
.callbacks
))
85 (void) vsnprintf(str
, MAX_DEBUG_MESSAGE_LENGTH
, fmt
, args
);
88 vk_debug_report(&instance
->debug_report_callbacks
,
89 VK_DEBUG_REPORT_DEBUG_BIT_EXT
,
90 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT
,
95 compiler_perf_log(void *data
, const char *fmt
, ...)
100 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
101 intel_logd_v(fmt
, args
);
107 anv_compute_heap_size(int fd
, uint64_t gtt_size
)
109 /* Query the total ram from the system */
113 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
115 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
116 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
118 uint64_t available_ram
;
119 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
120 available_ram
= total_ram
/ 2;
122 available_ram
= total_ram
* 3 / 4;
124 /* We also want to leave some padding for things we allocate in the driver,
125 * so don't go over 3/4 of the GTT either.
127 uint64_t available_gtt
= gtt_size
* 3 / 4;
129 return MIN2(available_ram
, available_gtt
);
133 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
135 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
136 &device
->gtt_size
) == -1) {
137 /* If, for whatever reason, we can't actually get the GTT size from the
138 * kernel (too old?) fall back to the aperture size.
140 anv_perf_warn(NULL
, NULL
,
141 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
143 if (gen_get_aperture_size(fd
, &device
->gtt_size
) == -1) {
144 return vk_errorfi(device
->instance
, NULL
,
145 VK_ERROR_INITIALIZATION_FAILED
,
146 "failed to get aperture size: %m");
150 /* We only allow 48-bit addresses with softpin because knowing the actual
151 * address is required for the vertex cache flush workaround.
153 device
->supports_48bit_addresses
= (device
->info
.gen
>= 8) &&
154 device
->has_softpin
&&
155 device
->gtt_size
> (4ULL << 30 /* GiB */);
157 uint64_t heap_size
= anv_compute_heap_size(fd
, device
->gtt_size
);
159 if (heap_size
> (2ull << 30) && !device
->supports_48bit_addresses
) {
160 /* When running with an overridden PCI ID, we may get a GTT size from
161 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
162 * address support can still fail. Just clamp the address space size to
163 * 2 GiB if we don't have 48-bit support.
165 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
166 "not support for 48-bit addresses",
168 heap_size
= 2ull << 30;
171 device
->memory
.heap_count
= 1;
172 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
174 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
177 uint32_t type_count
= 0;
178 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
179 if (device
->info
.has_llc
) {
180 /* Big core GPUs share LLC with the CPU and thus one memory type can be
181 * both cached and coherent at the same time.
183 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
184 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
185 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
186 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
187 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
191 /* The spec requires that we expose a host-visible, coherent memory
192 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
193 * to give the application a choice between cached, but not coherent and
194 * coherent but uncached (WC though).
196 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
197 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
198 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
199 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
202 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
203 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
204 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
205 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
210 device
->memory
.type_count
= type_count
;
216 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
218 const struct build_id_note
*note
=
219 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
221 return vk_errorfi(device
->instance
, NULL
,
222 VK_ERROR_INITIALIZATION_FAILED
,
223 "Failed to find build-id");
226 unsigned build_id_len
= build_id_length(note
);
227 if (build_id_len
< 20) {
228 return vk_errorfi(device
->instance
, NULL
,
229 VK_ERROR_INITIALIZATION_FAILED
,
230 "build-id too short. It needs to be a SHA");
233 memcpy(device
->driver_build_sha1
, build_id_data(note
), 20);
235 struct mesa_sha1 sha1_ctx
;
237 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
239 /* The pipeline cache UUID is used for determining when a pipeline cache is
240 * invalid. It needs both a driver build and the PCI ID of the device.
242 _mesa_sha1_init(&sha1_ctx
);
243 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
244 _mesa_sha1_update(&sha1_ctx
, &device
->info
.chipset_id
,
245 sizeof(device
->info
.chipset_id
));
246 _mesa_sha1_update(&sha1_ctx
, &device
->always_use_bindless
,
247 sizeof(device
->always_use_bindless
));
248 _mesa_sha1_update(&sha1_ctx
, &device
->has_a64_buffer_access
,
249 sizeof(device
->has_a64_buffer_access
));
250 _mesa_sha1_update(&sha1_ctx
, &device
->has_bindless_images
,
251 sizeof(device
->has_bindless_images
));
252 _mesa_sha1_update(&sha1_ctx
, &device
->has_bindless_samplers
,
253 sizeof(device
->has_bindless_samplers
));
254 _mesa_sha1_final(&sha1_ctx
, sha1
);
255 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
257 /* The driver UUID is used for determining sharability of images and memory
258 * between two Vulkan instances in separate processes. People who want to
259 * share memory need to also check the device UUID (below) so all this
260 * needs to be is the build-id.
262 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
264 /* The device UUID uniquely identifies the given device within the machine.
265 * Since we never have more than one device, this doesn't need to be a real
266 * UUID. However, on the off-chance that someone tries to use this to
267 * cache pre-tiled images or something of the like, we use the PCI ID and
268 * some bits of ISL info to ensure that this is safe.
270 _mesa_sha1_init(&sha1_ctx
);
271 _mesa_sha1_update(&sha1_ctx
, &device
->info
.chipset_id
,
272 sizeof(device
->info
.chipset_id
));
273 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
274 sizeof(device
->isl_dev
.has_bit6_swizzling
));
275 _mesa_sha1_final(&sha1_ctx
, sha1
);
276 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
282 anv_physical_device_init_disk_cache(struct anv_physical_device
*device
)
284 #ifdef ENABLE_SHADER_CACHE
286 ASSERTED
int len
= snprintf(renderer
, sizeof(renderer
), "anv_%04x",
287 device
->info
.chipset_id
);
288 assert(len
== sizeof(renderer
) - 2);
291 _mesa_sha1_format(timestamp
, device
->driver_build_sha1
);
293 const uint64_t driver_flags
=
294 brw_get_compiler_config_value(device
->compiler
);
295 device
->disk_cache
= disk_cache_create(renderer
, timestamp
, driver_flags
);
297 device
->disk_cache
= NULL
;
302 anv_physical_device_free_disk_cache(struct anv_physical_device
*device
)
304 #ifdef ENABLE_SHADER_CACHE
305 if (device
->disk_cache
)
306 disk_cache_destroy(device
->disk_cache
);
308 assert(device
->disk_cache
== NULL
);
313 get_available_system_memory()
315 char *meminfo
= os_read_file("/proc/meminfo", NULL
);
319 char *str
= strstr(meminfo
, "MemAvailable:");
325 uint64_t kb_mem_available
;
326 if (sscanf(str
, "MemAvailable: %" PRIx64
, &kb_mem_available
) == 1) {
328 return kb_mem_available
<< 10;
336 anv_physical_device_try_create(struct anv_instance
*instance
,
337 drmDevicePtr drm_device
,
338 struct anv_physical_device
**device_out
)
340 const char *primary_path
= drm_device
->nodes
[DRM_NODE_PRIMARY
];
341 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
346 brw_process_intel_debug_variable();
348 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
350 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
352 struct gen_device_info devinfo
;
353 if (!gen_get_device_info_from_fd(fd
, &devinfo
)) {
354 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
358 const char *device_name
= gen_get_device_name(devinfo
.chipset_id
);
360 if (devinfo
.is_haswell
) {
361 intel_logw("Haswell Vulkan support is incomplete");
362 } else if (devinfo
.gen
== 7 && !devinfo
.is_baytrail
) {
363 intel_logw("Ivy Bridge Vulkan support is incomplete");
364 } else if (devinfo
.gen
== 7 && devinfo
.is_baytrail
) {
365 intel_logw("Bay Trail Vulkan support is incomplete");
366 } else if (devinfo
.gen
>= 8 && devinfo
.gen
<= 11) {
367 /* Gen8-11 fully supported */
368 } else if (devinfo
.gen
== 12) {
369 intel_logw("Vulkan is not yet fully supported on gen12");
371 result
= vk_errorfi(instance
, NULL
, VK_ERROR_INCOMPATIBLE_DRIVER
,
372 "Vulkan not yet supported on %s", device_name
);
376 struct anv_physical_device
*device
=
377 vk_alloc(&instance
->alloc
, sizeof(*device
), 8,
378 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
379 if (device
== NULL
) {
380 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
384 vk_object_base_init(NULL
, &device
->base
, VK_OBJECT_TYPE_PHYSICAL_DEVICE
);
385 device
->instance
= instance
;
387 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
388 snprintf(device
->path
, ARRAY_SIZE(device
->path
), "%s", path
);
390 device
->info
= devinfo
;
391 device
->name
= device_name
;
393 device
->no_hw
= device
->info
.no_hw
;
394 if (getenv("INTEL_NO_HW") != NULL
)
395 device
->no_hw
= true;
397 device
->pci_info
.domain
= drm_device
->businfo
.pci
->domain
;
398 device
->pci_info
.bus
= drm_device
->businfo
.pci
->bus
;
399 device
->pci_info
.device
= drm_device
->businfo
.pci
->dev
;
400 device
->pci_info
.function
= drm_device
->businfo
.pci
->func
;
402 device
->cmd_parser_version
= -1;
403 if (device
->info
.gen
== 7) {
404 device
->cmd_parser_version
=
405 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
406 if (device
->cmd_parser_version
== -1) {
407 result
= vk_errorfi(device
->instance
, NULL
,
408 VK_ERROR_INITIALIZATION_FAILED
,
409 "failed to get command parser version");
414 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
415 result
= vk_errorfi(device
->instance
, NULL
,
416 VK_ERROR_INITIALIZATION_FAILED
,
417 "kernel missing gem wait");
421 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
422 result
= vk_errorfi(device
->instance
, NULL
,
423 VK_ERROR_INITIALIZATION_FAILED
,
424 "kernel missing execbuf2");
428 if (!device
->info
.has_llc
&&
429 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
430 result
= vk_errorfi(device
->instance
, NULL
,
431 VK_ERROR_INITIALIZATION_FAILED
,
432 "kernel missing wc mmap");
436 device
->has_softpin
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_SOFTPIN
);
437 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
438 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
439 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
440 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
441 device
->has_syncobj_wait
= device
->has_syncobj
&&
442 anv_gem_supports_syncobj_wait(fd
);
443 device
->has_syncobj_wait_available
=
444 anv_gem_get_drm_cap(fd
, DRM_CAP_SYNCOBJ_TIMELINE
) != 0;
446 device
->has_context_priority
= anv_gem_has_context_priority(fd
);
448 result
= anv_physical_device_init_heaps(device
, fd
);
449 if (result
!= VK_SUCCESS
)
452 device
->use_softpin
= device
->has_softpin
&&
453 device
->supports_48bit_addresses
;
455 device
->has_context_isolation
=
456 anv_gem_get_param(fd
, I915_PARAM_HAS_CONTEXT_ISOLATION
);
458 device
->has_exec_timeline
=
459 anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_TIMELINE_FENCES
);
460 if (env_var_as_boolean("ANV_QUEUE_THREAD_DISABLE", false))
461 device
->has_exec_timeline
= false;
463 device
->always_use_bindless
=
464 env_var_as_boolean("ANV_ALWAYS_BINDLESS", false);
466 device
->use_call_secondary
=
467 device
->use_softpin
&&
468 !env_var_as_boolean("ANV_DISABLE_SECONDARY_CMD_BUFFER_CALLS", false);
470 /* We first got the A64 messages on broadwell and we can only use them if
471 * we can pass addresses directly into the shader which requires softpin.
473 device
->has_a64_buffer_access
= device
->info
.gen
>= 8 &&
476 /* We first get bindless image access on Skylake and we can only really do
477 * it if we don't have any relocations so we need softpin.
479 device
->has_bindless_images
= device
->info
.gen
>= 9 &&
482 /* We've had bindless samplers since Ivy Bridge (forever in Vulkan terms)
483 * because it's just a matter of setting the sampler address in the sample
484 * message header. However, we've not bothered to wire it up for vec4 so
485 * we leave it disabled on gen7.
487 device
->has_bindless_samplers
= device
->info
.gen
>= 8;
489 device
->has_implicit_ccs
= device
->info
.has_aux_map
;
491 /* Check if we can read the GPU timestamp register from the CPU */
493 device
->has_reg_timestamp
= anv_gem_reg_read(fd
, TIMESTAMP
| I915_REG_READ_8B_WA
,
496 device
->has_mem_available
= get_available_system_memory() != 0;
498 device
->always_flush_cache
=
499 driQueryOptionb(&instance
->dri_options
, "always_flush_cache");
501 device
->has_mmap_offset
=
502 anv_gem_get_param(fd
, I915_PARAM_MMAP_GTT_VERSION
) >= 4;
504 /* GENs prior to 8 do not support EU/Subslice info */
505 if (device
->info
.gen
>= 8) {
506 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
507 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
509 /* Without this information, we cannot get the right Braswell
510 * brandstrings, and we have to use conservative numbers for GPGPU on
511 * many platforms, but otherwise, things will just work.
513 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
514 intel_logw("Kernel 4.1 required to properly query GPU properties");
516 } else if (device
->info
.gen
== 7) {
517 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
520 if (device
->info
.is_cherryview
&&
521 device
->subslice_total
> 0 && device
->eu_total
> 0) {
522 /* Logical CS threads = EUs per subslice * num threads per EU */
523 uint32_t max_cs_threads
=
524 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
526 /* Fuse configurations may give more threads than expected, never less. */
527 if (max_cs_threads
> device
->info
.max_cs_threads
)
528 device
->info
.max_cs_threads
= max_cs_threads
;
531 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
532 if (device
->compiler
== NULL
) {
533 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
536 device
->compiler
->shader_debug_log
= compiler_debug_log
;
537 device
->compiler
->shader_perf_log
= compiler_perf_log
;
538 device
->compiler
->supports_pull_constants
= false;
539 device
->compiler
->constant_buffer_0_is_relative
=
540 device
->info
.gen
< 8 || !device
->has_context_isolation
;
541 device
->compiler
->supports_shader_constants
= true;
542 device
->compiler
->compact_params
= false;
544 /* Broadwell PRM says:
546 * "Before Gen8, there was a historical configuration control field to
547 * swizzle address bit[6] for in X/Y tiling modes. This was set in three
548 * different places: TILECTL[1:0], ARB_MODE[5:4], and
549 * DISP_ARB_CTL[14:13].
551 * For Gen8 and subsequent generations, the swizzle fields are all
552 * reserved, and the CPU's memory controller performs all address
553 * swizzling modifications."
556 device
->info
.gen
< 8 && anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
558 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
560 result
= anv_physical_device_init_uuids(device
);
561 if (result
!= VK_SUCCESS
)
564 anv_physical_device_init_disk_cache(device
);
566 if (instance
->enabled_extensions
.KHR_display
) {
567 master_fd
= open(primary_path
, O_RDWR
| O_CLOEXEC
);
568 if (master_fd
>= 0) {
569 /* prod the device with a GETPARAM call which will fail if
570 * we don't have permission to even render on this device
572 if (anv_gem_get_param(master_fd
, I915_PARAM_CHIPSET_ID
) == 0) {
578 device
->master_fd
= master_fd
;
580 result
= anv_init_wsi(device
);
581 if (result
!= VK_SUCCESS
)
582 goto fail_disk_cache
;
584 device
->perf
= anv_get_perf(&device
->info
, fd
);
586 anv_physical_device_get_supported_extensions(device
,
587 &device
->supported_extensions
);
590 device
->local_fd
= fd
;
592 *device_out
= device
;
597 anv_physical_device_free_disk_cache(device
);
599 ralloc_free(device
->compiler
);
601 vk_free(&instance
->alloc
, device
);
610 anv_physical_device_destroy(struct anv_physical_device
*device
)
612 anv_finish_wsi(device
);
613 anv_physical_device_free_disk_cache(device
);
614 ralloc_free(device
->compiler
);
615 ralloc_free(device
->perf
);
616 close(device
->local_fd
);
617 if (device
->master_fd
>= 0)
618 close(device
->master_fd
);
619 vk_object_base_finish(&device
->base
);
620 vk_free(&device
->instance
->alloc
, device
);
624 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
625 VkSystemAllocationScope allocationScope
)
631 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
632 size_t align
, VkSystemAllocationScope allocationScope
)
634 return realloc(pOriginal
, size
);
638 default_free_func(void *pUserData
, void *pMemory
)
643 static const VkAllocationCallbacks default_alloc
= {
645 .pfnAllocation
= default_alloc_func
,
646 .pfnReallocation
= default_realloc_func
,
647 .pfnFree
= default_free_func
,
650 VkResult
anv_EnumerateInstanceExtensionProperties(
651 const char* pLayerName
,
652 uint32_t* pPropertyCount
,
653 VkExtensionProperties
* pProperties
)
655 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
657 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
658 if (anv_instance_extensions_supported
.extensions
[i
]) {
659 vk_outarray_append(&out
, prop
) {
660 *prop
= anv_instance_extensions
[i
];
665 return vk_outarray_status(&out
);
668 VkResult
anv_CreateInstance(
669 const VkInstanceCreateInfo
* pCreateInfo
,
670 const VkAllocationCallbacks
* pAllocator
,
671 VkInstance
* pInstance
)
673 struct anv_instance
*instance
;
676 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
678 struct anv_instance_extension_table enabled_extensions
= {};
679 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
681 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
682 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
683 anv_instance_extensions
[idx
].extensionName
) == 0)
687 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
688 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
690 if (!anv_instance_extensions_supported
.extensions
[idx
])
691 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
693 enabled_extensions
.extensions
[idx
] = true;
696 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
697 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
699 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
701 vk_object_base_init(NULL
, &instance
->base
, VK_OBJECT_TYPE_INSTANCE
);
704 instance
->alloc
= *pAllocator
;
706 instance
->alloc
= default_alloc
;
708 instance
->app_info
= (struct anv_app_info
) { .api_version
= 0 };
709 if (pCreateInfo
->pApplicationInfo
) {
710 const VkApplicationInfo
*app
= pCreateInfo
->pApplicationInfo
;
712 instance
->app_info
.app_name
=
713 vk_strdup(&instance
->alloc
, app
->pApplicationName
,
714 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
715 instance
->app_info
.app_version
= app
->applicationVersion
;
717 instance
->app_info
.engine_name
=
718 vk_strdup(&instance
->alloc
, app
->pEngineName
,
719 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
720 instance
->app_info
.engine_version
= app
->engineVersion
;
722 instance
->app_info
.api_version
= app
->apiVersion
;
725 if (instance
->app_info
.api_version
== 0)
726 instance
->app_info
.api_version
= VK_API_VERSION_1_0
;
728 instance
->enabled_extensions
= enabled_extensions
;
730 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
731 /* Vulkan requires that entrypoints for extensions which have not been
732 * enabled must not be advertised.
734 if (!anv_instance_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
735 &instance
->enabled_extensions
)) {
736 instance
->dispatch
.entrypoints
[i
] = NULL
;
738 instance
->dispatch
.entrypoints
[i
] =
739 anv_instance_dispatch_table
.entrypoints
[i
];
743 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->physical_device_dispatch
.entrypoints
); i
++) {
744 /* Vulkan requires that entrypoints for extensions which have not been
745 * enabled must not be advertised.
747 if (!anv_physical_device_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
748 &instance
->enabled_extensions
)) {
749 instance
->physical_device_dispatch
.entrypoints
[i
] = NULL
;
751 instance
->physical_device_dispatch
.entrypoints
[i
] =
752 anv_physical_device_dispatch_table
.entrypoints
[i
];
756 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->device_dispatch
.entrypoints
); i
++) {
757 /* Vulkan requires that entrypoints for extensions which have not been
758 * enabled must not be advertised.
760 if (!anv_device_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
761 &instance
->enabled_extensions
, NULL
)) {
762 instance
->device_dispatch
.entrypoints
[i
] = NULL
;
764 instance
->device_dispatch
.entrypoints
[i
] =
765 anv_device_dispatch_table
.entrypoints
[i
];
769 instance
->physical_devices_enumerated
= false;
770 list_inithead(&instance
->physical_devices
);
772 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
773 if (result
!= VK_SUCCESS
) {
774 vk_free2(&default_alloc
, pAllocator
, instance
);
775 return vk_error(result
);
778 instance
->pipeline_cache_enabled
=
779 env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true);
781 glsl_type_singleton_init_or_ref();
783 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
785 driParseOptionInfo(&instance
->available_dri_options
, anv_dri_options_xml
);
786 driParseConfigFiles(&instance
->dri_options
, &instance
->available_dri_options
,
788 instance
->app_info
.app_name
,
789 instance
->app_info
.app_version
,
790 instance
->app_info
.engine_name
,
791 instance
->app_info
.engine_version
);
793 *pInstance
= anv_instance_to_handle(instance
);
798 void anv_DestroyInstance(
799 VkInstance _instance
,
800 const VkAllocationCallbacks
* pAllocator
)
802 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
807 list_for_each_entry_safe(struct anv_physical_device
, pdevice
,
808 &instance
->physical_devices
, link
)
809 anv_physical_device_destroy(pdevice
);
811 vk_free(&instance
->alloc
, (char *)instance
->app_info
.app_name
);
812 vk_free(&instance
->alloc
, (char *)instance
->app_info
.engine_name
);
814 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
816 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
818 glsl_type_singleton_decref();
820 driDestroyOptionCache(&instance
->dri_options
);
821 driDestroyOptionInfo(&instance
->available_dri_options
);
823 vk_object_base_finish(&instance
->base
);
824 vk_free(&instance
->alloc
, instance
);
828 anv_enumerate_physical_devices(struct anv_instance
*instance
)
830 if (instance
->physical_devices_enumerated
)
833 instance
->physical_devices_enumerated
= true;
835 /* TODO: Check for more devices ? */
836 drmDevicePtr devices
[8];
839 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
843 VkResult result
= VK_SUCCESS
;
844 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
845 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
846 devices
[i
]->bustype
== DRM_BUS_PCI
&&
847 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
849 struct anv_physical_device
*pdevice
;
850 result
= anv_physical_device_try_create(instance
, devices
[i
],
852 /* Incompatible DRM device, skip. */
853 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
858 /* Error creating the physical device, report the error. */
859 if (result
!= VK_SUCCESS
)
862 list_addtail(&pdevice
->link
, &instance
->physical_devices
);
865 drmFreeDevices(devices
, max_devices
);
867 /* If we successfully enumerated any devices, call it success */
871 VkResult
anv_EnumeratePhysicalDevices(
872 VkInstance _instance
,
873 uint32_t* pPhysicalDeviceCount
,
874 VkPhysicalDevice
* pPhysicalDevices
)
876 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
877 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
879 VkResult result
= anv_enumerate_physical_devices(instance
);
880 if (result
!= VK_SUCCESS
)
883 list_for_each_entry(struct anv_physical_device
, pdevice
,
884 &instance
->physical_devices
, link
) {
885 vk_outarray_append(&out
, i
) {
886 *i
= anv_physical_device_to_handle(pdevice
);
890 return vk_outarray_status(&out
);
893 VkResult
anv_EnumeratePhysicalDeviceGroups(
894 VkInstance _instance
,
895 uint32_t* pPhysicalDeviceGroupCount
,
896 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
898 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
899 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
900 pPhysicalDeviceGroupCount
);
902 VkResult result
= anv_enumerate_physical_devices(instance
);
903 if (result
!= VK_SUCCESS
)
906 list_for_each_entry(struct anv_physical_device
, pdevice
,
907 &instance
->physical_devices
, link
) {
908 vk_outarray_append(&out
, p
) {
909 p
->physicalDeviceCount
= 1;
910 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
911 p
->physicalDevices
[0] = anv_physical_device_to_handle(pdevice
);
912 p
->subsetAllocation
= false;
914 vk_foreach_struct(ext
, p
->pNext
)
915 anv_debug_ignored_stype(ext
->sType
);
919 return vk_outarray_status(&out
);
922 void anv_GetPhysicalDeviceFeatures(
923 VkPhysicalDevice physicalDevice
,
924 VkPhysicalDeviceFeatures
* pFeatures
)
926 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
928 *pFeatures
= (VkPhysicalDeviceFeatures
) {
929 .robustBufferAccess
= true,
930 .fullDrawIndexUint32
= true,
931 .imageCubeArray
= true,
932 .independentBlend
= true,
933 .geometryShader
= true,
934 .tessellationShader
= true,
935 .sampleRateShading
= true,
936 .dualSrcBlend
= true,
938 .multiDrawIndirect
= true,
939 .drawIndirectFirstInstance
= true,
941 .depthBiasClamp
= true,
942 .fillModeNonSolid
= true,
943 .depthBounds
= pdevice
->info
.gen
>= 12,
947 .multiViewport
= true,
948 .samplerAnisotropy
= true,
949 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
950 pdevice
->info
.is_baytrail
,
951 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
952 .textureCompressionBC
= true,
953 .occlusionQueryPrecise
= true,
954 .pipelineStatisticsQuery
= true,
955 .fragmentStoresAndAtomics
= true,
956 .shaderTessellationAndGeometryPointSize
= true,
957 .shaderImageGatherExtended
= true,
958 .shaderStorageImageExtendedFormats
= true,
959 .shaderStorageImageMultisample
= false,
960 .shaderStorageImageReadWithoutFormat
= false,
961 .shaderStorageImageWriteWithoutFormat
= true,
962 .shaderUniformBufferArrayDynamicIndexing
= true,
963 .shaderSampledImageArrayDynamicIndexing
= true,
964 .shaderStorageBufferArrayDynamicIndexing
= true,
965 .shaderStorageImageArrayDynamicIndexing
= true,
966 .shaderClipDistance
= true,
967 .shaderCullDistance
= true,
968 .shaderFloat64
= pdevice
->info
.gen
>= 8 &&
969 pdevice
->info
.has_64bit_float
,
970 .shaderInt64
= pdevice
->info
.gen
>= 8 &&
971 pdevice
->info
.has_64bit_int
,
972 .shaderInt16
= pdevice
->info
.gen
>= 8,
973 .shaderResourceMinLod
= pdevice
->info
.gen
>= 9,
974 .variableMultisampleRate
= true,
975 .inheritedQueries
= true,
978 /* We can't do image stores in vec4 shaders */
979 pFeatures
->vertexPipelineStoresAndAtomics
=
980 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
981 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
983 struct anv_app_info
*app_info
= &pdevice
->instance
->app_info
;
985 /* The new DOOM and Wolfenstein games require depthBounds without
986 * checking for it. They seem to run fine without it so just claim it's
987 * there and accept the consequences.
989 if (app_info
->engine_name
&& strcmp(app_info
->engine_name
, "idTech") == 0)
990 pFeatures
->depthBounds
= true;
994 anv_get_physical_device_features_1_1(struct anv_physical_device
*pdevice
,
995 VkPhysicalDeviceVulkan11Features
*f
)
997 assert(f
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
);
999 f
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
1000 f
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
1001 f
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
1002 f
->storageInputOutput16
= false;
1003 f
->multiview
= true;
1004 f
->multiviewGeometryShader
= true;
1005 f
->multiviewTessellationShader
= true;
1006 f
->variablePointersStorageBuffer
= true;
1007 f
->variablePointers
= true;
1008 f
->protectedMemory
= false;
1009 f
->samplerYcbcrConversion
= true;
1010 f
->shaderDrawParameters
= true;
1014 anv_get_physical_device_features_1_2(struct anv_physical_device
*pdevice
,
1015 VkPhysicalDeviceVulkan12Features
*f
)
1017 assert(f
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
);
1019 f
->samplerMirrorClampToEdge
= true;
1020 f
->drawIndirectCount
= true;
1021 f
->storageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
1022 f
->uniformAndStorageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
1023 f
->storagePushConstant8
= pdevice
->info
.gen
>= 8;
1024 f
->shaderBufferInt64Atomics
= pdevice
->info
.gen
>= 9 &&
1025 pdevice
->use_softpin
;
1026 f
->shaderSharedInt64Atomics
= false;
1027 f
->shaderFloat16
= pdevice
->info
.gen
>= 8;
1028 f
->shaderInt8
= pdevice
->info
.gen
>= 8;
1030 bool descIndexing
= pdevice
->has_a64_buffer_access
&&
1031 pdevice
->has_bindless_images
;
1032 f
->descriptorIndexing
= descIndexing
;
1033 f
->shaderInputAttachmentArrayDynamicIndexing
= false;
1034 f
->shaderUniformTexelBufferArrayDynamicIndexing
= descIndexing
;
1035 f
->shaderStorageTexelBufferArrayDynamicIndexing
= descIndexing
;
1036 f
->shaderUniformBufferArrayNonUniformIndexing
= false;
1037 f
->shaderSampledImageArrayNonUniformIndexing
= descIndexing
;
1038 f
->shaderStorageBufferArrayNonUniformIndexing
= descIndexing
;
1039 f
->shaderStorageImageArrayNonUniformIndexing
= descIndexing
;
1040 f
->shaderInputAttachmentArrayNonUniformIndexing
= false;
1041 f
->shaderUniformTexelBufferArrayNonUniformIndexing
= descIndexing
;
1042 f
->shaderStorageTexelBufferArrayNonUniformIndexing
= descIndexing
;
1043 f
->descriptorBindingUniformBufferUpdateAfterBind
= false;
1044 f
->descriptorBindingSampledImageUpdateAfterBind
= descIndexing
;
1045 f
->descriptorBindingStorageImageUpdateAfterBind
= descIndexing
;
1046 f
->descriptorBindingStorageBufferUpdateAfterBind
= descIndexing
;
1047 f
->descriptorBindingUniformTexelBufferUpdateAfterBind
= descIndexing
;
1048 f
->descriptorBindingStorageTexelBufferUpdateAfterBind
= descIndexing
;
1049 f
->descriptorBindingUpdateUnusedWhilePending
= descIndexing
;
1050 f
->descriptorBindingPartiallyBound
= descIndexing
;
1051 f
->descriptorBindingVariableDescriptorCount
= false;
1052 f
->runtimeDescriptorArray
= descIndexing
;
1054 f
->samplerFilterMinmax
= pdevice
->info
.gen
>= 9;
1055 f
->scalarBlockLayout
= true;
1056 f
->imagelessFramebuffer
= true;
1057 f
->uniformBufferStandardLayout
= true;
1058 f
->shaderSubgroupExtendedTypes
= true;
1059 f
->separateDepthStencilLayouts
= true;
1060 f
->hostQueryReset
= true;
1061 f
->timelineSemaphore
= true;
1062 f
->bufferDeviceAddress
= pdevice
->has_a64_buffer_access
;
1063 f
->bufferDeviceAddressCaptureReplay
= pdevice
->has_a64_buffer_access
;
1064 f
->bufferDeviceAddressMultiDevice
= false;
1065 f
->vulkanMemoryModel
= true;
1066 f
->vulkanMemoryModelDeviceScope
= true;
1067 f
->vulkanMemoryModelAvailabilityVisibilityChains
= true;
1068 f
->shaderOutputViewportIndex
= true;
1069 f
->shaderOutputLayer
= true;
1070 f
->subgroupBroadcastDynamicId
= true;
1073 void anv_GetPhysicalDeviceFeatures2(
1074 VkPhysicalDevice physicalDevice
,
1075 VkPhysicalDeviceFeatures2
* pFeatures
)
1077 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1078 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1080 VkPhysicalDeviceVulkan11Features core_1_1
= {
1081 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
,
1083 anv_get_physical_device_features_1_1(pdevice
, &core_1_1
);
1085 VkPhysicalDeviceVulkan12Features core_1_2
= {
1086 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
,
1088 anv_get_physical_device_features_1_2(pdevice
, &core_1_2
);
1090 #define CORE_FEATURE(major, minor, feature) \
1091 features->feature = core_##major##_##minor.feature
1094 vk_foreach_struct(ext
, pFeatures
->pNext
) {
1095 switch (ext
->sType
) {
1096 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT
: {
1097 VkPhysicalDevice4444FormatsFeaturesEXT
*features
=
1098 (VkPhysicalDevice4444FormatsFeaturesEXT
*)ext
;
1099 features
->formatA4R4G4B4
= true;
1100 features
->formatA4B4G4R4
= false;
1104 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
1105 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
1106 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
1107 CORE_FEATURE(1, 2, storageBuffer8BitAccess
);
1108 CORE_FEATURE(1, 2, uniformAndStorageBuffer8BitAccess
);
1109 CORE_FEATURE(1, 2, storagePushConstant8
);
1113 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
1114 VkPhysicalDevice16BitStorageFeatures
*features
=
1115 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
1116 CORE_FEATURE(1, 1, storageBuffer16BitAccess
);
1117 CORE_FEATURE(1, 1, uniformAndStorageBuffer16BitAccess
);
1118 CORE_FEATURE(1, 1, storagePushConstant16
);
1119 CORE_FEATURE(1, 1, storageInputOutput16
);
1123 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1124 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
= (void *)ext
;
1125 features
->bufferDeviceAddress
= pdevice
->has_a64_buffer_access
;
1126 features
->bufferDeviceAddressCaptureReplay
= false;
1127 features
->bufferDeviceAddressMultiDevice
= false;
1131 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR
: {
1132 VkPhysicalDeviceBufferDeviceAddressFeaturesKHR
*features
= (void *)ext
;
1133 CORE_FEATURE(1, 2, bufferDeviceAddress
);
1134 CORE_FEATURE(1, 2, bufferDeviceAddressCaptureReplay
);
1135 CORE_FEATURE(1, 2, bufferDeviceAddressMultiDevice
);
1139 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1140 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1141 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1142 features
->computeDerivativeGroupQuads
= true;
1143 features
->computeDerivativeGroupLinear
= true;
1147 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
1148 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
1149 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
1150 features
->conditionalRendering
= pdevice
->info
.gen
>= 8 ||
1151 pdevice
->info
.is_haswell
;
1152 features
->inheritedConditionalRendering
= pdevice
->info
.gen
>= 8 ||
1153 pdevice
->info
.is_haswell
;
1157 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT
: {
1158 VkPhysicalDeviceCustomBorderColorFeaturesEXT
*features
=
1159 (VkPhysicalDeviceCustomBorderColorFeaturesEXT
*)ext
;
1160 features
->customBorderColors
= pdevice
->info
.gen
>= 8;
1161 features
->customBorderColorWithoutFormat
= pdevice
->info
.gen
>= 8;
1165 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1166 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1167 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1168 features
->depthClipEnable
= true;
1172 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
1173 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
= (void *)ext
;
1174 CORE_FEATURE(1, 2, shaderFloat16
);
1175 CORE_FEATURE(1, 2, shaderInt8
);
1179 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT
: {
1180 VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*features
=
1181 (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*)ext
;
1182 features
->fragmentShaderSampleInterlock
= pdevice
->info
.gen
>= 9;
1183 features
->fragmentShaderPixelInterlock
= pdevice
->info
.gen
>= 9;
1184 features
->fragmentShaderShadingRateInterlock
= false;
1188 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
1189 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
1190 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
1191 CORE_FEATURE(1, 2, hostQueryReset
);
1195 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
1196 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
1197 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
1198 CORE_FEATURE(1, 2, shaderInputAttachmentArrayDynamicIndexing
);
1199 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayDynamicIndexing
);
1200 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayDynamicIndexing
);
1201 CORE_FEATURE(1, 2, shaderUniformBufferArrayNonUniformIndexing
);
1202 CORE_FEATURE(1, 2, shaderSampledImageArrayNonUniformIndexing
);
1203 CORE_FEATURE(1, 2, shaderStorageBufferArrayNonUniformIndexing
);
1204 CORE_FEATURE(1, 2, shaderStorageImageArrayNonUniformIndexing
);
1205 CORE_FEATURE(1, 2, shaderInputAttachmentArrayNonUniformIndexing
);
1206 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayNonUniformIndexing
);
1207 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayNonUniformIndexing
);
1208 CORE_FEATURE(1, 2, descriptorBindingUniformBufferUpdateAfterBind
);
1209 CORE_FEATURE(1, 2, descriptorBindingSampledImageUpdateAfterBind
);
1210 CORE_FEATURE(1, 2, descriptorBindingStorageImageUpdateAfterBind
);
1211 CORE_FEATURE(1, 2, descriptorBindingStorageBufferUpdateAfterBind
);
1212 CORE_FEATURE(1, 2, descriptorBindingUniformTexelBufferUpdateAfterBind
);
1213 CORE_FEATURE(1, 2, descriptorBindingStorageTexelBufferUpdateAfterBind
);
1214 CORE_FEATURE(1, 2, descriptorBindingUpdateUnusedWhilePending
);
1215 CORE_FEATURE(1, 2, descriptorBindingPartiallyBound
);
1216 CORE_FEATURE(1, 2, descriptorBindingVariableDescriptorCount
);
1217 CORE_FEATURE(1, 2, runtimeDescriptorArray
);
1221 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES_EXT
: {
1222 VkPhysicalDeviceImageRobustnessFeaturesEXT
*features
=
1223 (VkPhysicalDeviceImageRobustnessFeaturesEXT
*)ext
;
1224 features
->robustImageAccess
= true;
1228 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1229 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1230 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1231 features
->indexTypeUint8
= true;
1235 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1236 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1237 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1238 features
->inlineUniformBlock
= true;
1239 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1243 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1244 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1245 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1246 features
->rectangularLines
= true;
1247 features
->bresenhamLines
= true;
1248 /* Support for Smooth lines with MSAA was removed on gen11. From the
1249 * BSpec section "Multisample ModesState" table for "AA Line Support
1252 * GEN10:BUG:######## NUM_MULTISAMPLES == 1
1254 * Fortunately, this isn't a case most people care about.
1256 features
->smoothLines
= pdevice
->info
.gen
< 10;
1257 features
->stippledRectangularLines
= false;
1258 features
->stippledBresenhamLines
= true;
1259 features
->stippledSmoothLines
= false;
1263 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
1264 VkPhysicalDeviceMultiviewFeatures
*features
=
1265 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
1266 CORE_FEATURE(1, 1, multiview
);
1267 CORE_FEATURE(1, 1, multiviewGeometryShader
);
1268 CORE_FEATURE(1, 1, multiviewTessellationShader
);
1272 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1273 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1274 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1275 CORE_FEATURE(1, 2, imagelessFramebuffer
);
1279 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_FEATURES_KHR
: {
1280 VkPhysicalDevicePerformanceQueryFeaturesKHR
*feature
=
1281 (VkPhysicalDevicePerformanceQueryFeaturesKHR
*)ext
;
1282 feature
->performanceCounterQueryPools
= true;
1283 /* HW only supports a single configuration at a time. */
1284 feature
->performanceCounterMultipleQueryPools
= false;
1288 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES_EXT
: {
1289 VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT
*features
=
1290 (VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT
*)ext
;
1291 features
->pipelineCreationCacheControl
= true;
1295 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1296 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1297 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1298 features
->pipelineExecutableInfo
= true;
1302 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT
: {
1303 VkPhysicalDevicePrivateDataFeaturesEXT
*features
= (void *)ext
;
1304 features
->privateData
= true;
1308 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
1309 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
1310 CORE_FEATURE(1, 1, protectedMemory
);
1314 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT
: {
1315 VkPhysicalDeviceRobustness2FeaturesEXT
*features
= (void *)ext
;
1316 features
->robustBufferAccess2
= true;
1317 features
->robustImageAccess2
= true;
1318 features
->nullDescriptor
= true;
1322 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
1323 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
1324 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
1325 CORE_FEATURE(1, 1, samplerYcbcrConversion
);
1329 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
1330 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
1331 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
1332 CORE_FEATURE(1, 2, scalarBlockLayout
);
1336 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES_KHR
: {
1337 VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*features
=
1338 (VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*)ext
;
1339 CORE_FEATURE(1, 2, separateDepthStencilLayouts
);
1343 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT
: {
1344 VkPhysicalDeviceShaderAtomicFloatFeaturesEXT
*features
= (void *)ext
;
1345 features
->shaderBufferFloat32Atomics
= true;
1346 features
->shaderBufferFloat32AtomicAdd
= false;
1347 features
->shaderBufferFloat64Atomics
= false;
1348 features
->shaderBufferFloat64AtomicAdd
= false;
1349 features
->shaderSharedFloat32Atomics
= true;
1350 features
->shaderSharedFloat32AtomicAdd
= false;
1351 features
->shaderSharedFloat64Atomics
= false;
1352 features
->shaderSharedFloat64AtomicAdd
= false;
1353 features
->shaderImageFloat32Atomics
= true;
1354 features
->shaderImageFloat32AtomicAdd
= false;
1355 features
->sparseImageFloat32Atomics
= false;
1356 features
->sparseImageFloat32AtomicAdd
= false;
1360 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
1361 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
= (void *)ext
;
1362 CORE_FEATURE(1, 2, shaderBufferInt64Atomics
);
1363 CORE_FEATURE(1, 2, shaderSharedInt64Atomics
);
1367 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1368 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
= (void *)ext
;
1369 features
->shaderDemoteToHelperInvocation
= true;
1373 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1374 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1375 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1376 features
->shaderSubgroupClock
= true;
1377 features
->shaderDeviceClock
= false;
1381 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
1382 VkPhysicalDeviceShaderDrawParametersFeatures
*features
= (void *)ext
;
1383 CORE_FEATURE(1, 1, shaderDrawParameters
);
1387 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL
: {
1388 VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL
*features
=
1389 (VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL
*)ext
;
1390 features
->shaderIntegerFunctions2
= true;
1394 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES_KHR
: {
1395 VkPhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR
*features
=
1396 (VkPhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR
*)ext
;
1397 CORE_FEATURE(1, 2, shaderSubgroupExtendedTypes
);
1401 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1402 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1403 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1404 features
->subgroupSizeControl
= true;
1405 features
->computeFullSubgroups
= true;
1409 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1410 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1411 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1412 features
->texelBufferAlignment
= true;
1416 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR
: {
1417 VkPhysicalDeviceTimelineSemaphoreFeaturesKHR
*features
=
1418 (VkPhysicalDeviceTimelineSemaphoreFeaturesKHR
*) ext
;
1419 CORE_FEATURE(1, 2, timelineSemaphore
);
1423 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
1424 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
1425 CORE_FEATURE(1, 1, variablePointersStorageBuffer
);
1426 CORE_FEATURE(1, 1, variablePointers
);
1430 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1431 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1432 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1433 features
->transformFeedback
= true;
1434 features
->geometryStreams
= true;
1438 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1439 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1440 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1441 CORE_FEATURE(1, 2, uniformBufferStandardLayout
);
1445 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
1446 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1447 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1448 features
->vertexAttributeInstanceRateDivisor
= true;
1449 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1453 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
:
1454 anv_get_physical_device_features_1_1(pdevice
, (void *)ext
);
1457 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
:
1458 anv_get_physical_device_features_1_2(pdevice
, (void *)ext
);
1461 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES_KHR
: {
1462 VkPhysicalDeviceVulkanMemoryModelFeaturesKHR
*features
= (void *)ext
;
1463 CORE_FEATURE(1, 2, vulkanMemoryModel
);
1464 CORE_FEATURE(1, 2, vulkanMemoryModelDeviceScope
);
1465 CORE_FEATURE(1, 2, vulkanMemoryModelAvailabilityVisibilityChains
);
1469 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1470 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1471 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1472 features
->ycbcrImageArrays
= true;
1476 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT
: {
1477 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT
*features
=
1478 (VkPhysicalDeviceExtendedDynamicStateFeaturesEXT
*)ext
;
1479 features
->extendedDynamicState
= true;
1484 anv_debug_ignored_stype(ext
->sType
);
1492 #define MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS 64
1494 #define MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS 64
1495 #define MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS 256
1497 #define MAX_CUSTOM_BORDER_COLORS 4096
1499 void anv_GetPhysicalDeviceProperties(
1500 VkPhysicalDevice physicalDevice
,
1501 VkPhysicalDeviceProperties
* pProperties
)
1503 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1504 const struct gen_device_info
*devinfo
= &pdevice
->info
;
1506 /* See assertions made when programming the buffer surface state. */
1507 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
1508 (1ul << 30) : (1ul << 27);
1510 const uint32_t max_ssbos
= pdevice
->has_a64_buffer_access
? UINT16_MAX
: 64;
1511 const uint32_t max_textures
=
1512 pdevice
->has_bindless_images
? UINT16_MAX
: 128;
1513 const uint32_t max_samplers
=
1514 pdevice
->has_bindless_samplers
? UINT16_MAX
:
1515 (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ? 128 : 16;
1516 const uint32_t max_images
=
1517 pdevice
->has_bindless_images
? UINT16_MAX
: MAX_IMAGES
;
1519 /* If we can use bindless for everything, claim a high per-stage limit,
1520 * otherwise use the binding table size, minus the slots reserved for
1521 * render targets and one slot for the descriptor buffer. */
1522 const uint32_t max_per_stage
=
1523 pdevice
->has_bindless_images
&& pdevice
->has_a64_buffer_access
1524 ? UINT32_MAX
: MAX_BINDING_TABLE_SIZE
- MAX_RTS
- 1;
1526 /* Limit max_threads to 64 for the GPGPU_WALKER command */
1527 const uint32_t max_workgroup_size
= 32 * MIN2(64, devinfo
->max_cs_threads
);
1529 VkSampleCountFlags sample_counts
=
1530 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1533 VkPhysicalDeviceLimits limits
= {
1534 .maxImageDimension1D
= (1 << 14),
1535 .maxImageDimension2D
= (1 << 14),
1536 .maxImageDimension3D
= (1 << 11),
1537 .maxImageDimensionCube
= (1 << 14),
1538 .maxImageArrayLayers
= (1 << 11),
1539 .maxTexelBufferElements
= 128 * 1024 * 1024,
1540 .maxUniformBufferRange
= (1ul << 27),
1541 .maxStorageBufferRange
= max_raw_buffer_sz
,
1542 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1543 .maxMemoryAllocationCount
= UINT32_MAX
,
1544 .maxSamplerAllocationCount
= 64 * 1024,
1545 .bufferImageGranularity
= 64, /* A cache line */
1546 .sparseAddressSpaceSize
= 0,
1547 .maxBoundDescriptorSets
= MAX_SETS
,
1548 .maxPerStageDescriptorSamplers
= max_samplers
,
1549 .maxPerStageDescriptorUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
,
1550 .maxPerStageDescriptorStorageBuffers
= max_ssbos
,
1551 .maxPerStageDescriptorSampledImages
= max_textures
,
1552 .maxPerStageDescriptorStorageImages
= max_images
,
1553 .maxPerStageDescriptorInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
,
1554 .maxPerStageResources
= max_per_stage
,
1555 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
1556 .maxDescriptorSetUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
, /* number of stages * maxPerStageDescriptorUniformBuffers */
1557 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1558 .maxDescriptorSetStorageBuffers
= 6 * max_ssbos
, /* number of stages * maxPerStageDescriptorStorageBuffers */
1559 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1560 .maxDescriptorSetSampledImages
= 6 * max_textures
, /* number of stages * maxPerStageDescriptorSampledImages */
1561 .maxDescriptorSetStorageImages
= 6 * max_images
, /* number of stages * maxPerStageDescriptorStorageImages */
1562 .maxDescriptorSetInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
,
1563 .maxVertexInputAttributes
= MAX_VBS
,
1564 .maxVertexInputBindings
= MAX_VBS
,
1565 .maxVertexInputAttributeOffset
= 2047,
1566 .maxVertexInputBindingStride
= 2048,
1567 .maxVertexOutputComponents
= 128,
1568 .maxTessellationGenerationLevel
= 64,
1569 .maxTessellationPatchSize
= 32,
1570 .maxTessellationControlPerVertexInputComponents
= 128,
1571 .maxTessellationControlPerVertexOutputComponents
= 128,
1572 .maxTessellationControlPerPatchOutputComponents
= 128,
1573 .maxTessellationControlTotalOutputComponents
= 2048,
1574 .maxTessellationEvaluationInputComponents
= 128,
1575 .maxTessellationEvaluationOutputComponents
= 128,
1576 .maxGeometryShaderInvocations
= 32,
1577 .maxGeometryInputComponents
= 64,
1578 .maxGeometryOutputComponents
= 128,
1579 .maxGeometryOutputVertices
= 256,
1580 .maxGeometryTotalOutputComponents
= 1024,
1581 .maxFragmentInputComponents
= 116, /* 128 components - (PSIZ, CLIP_DIST0, CLIP_DIST1) */
1582 .maxFragmentOutputAttachments
= 8,
1583 .maxFragmentDualSrcAttachments
= 1,
1584 .maxFragmentCombinedOutputResources
= 8,
1585 .maxComputeSharedMemorySize
= 64 * 1024,
1586 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1587 .maxComputeWorkGroupInvocations
= max_workgroup_size
,
1588 .maxComputeWorkGroupSize
= {
1593 .subPixelPrecisionBits
= 8,
1594 .subTexelPrecisionBits
= 8,
1595 .mipmapPrecisionBits
= 8,
1596 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1597 .maxDrawIndirectCount
= UINT32_MAX
,
1598 .maxSamplerLodBias
= 16,
1599 .maxSamplerAnisotropy
= 16,
1600 .maxViewports
= MAX_VIEWPORTS
,
1601 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1602 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1603 .viewportSubPixelBits
= 13, /* We take a float? */
1604 .minMemoryMapAlignment
= 4096, /* A page */
1605 /* The dataport requires texel alignment so we need to assume a worst
1606 * case of R32G32B32A32 which is 16 bytes.
1608 .minTexelBufferOffsetAlignment
= 16,
1609 .minUniformBufferOffsetAlignment
= ANV_UBO_ALIGNMENT
,
1610 .minStorageBufferOffsetAlignment
= 4,
1611 .minTexelOffset
= -8,
1612 .maxTexelOffset
= 7,
1613 .minTexelGatherOffset
= -32,
1614 .maxTexelGatherOffset
= 31,
1615 .minInterpolationOffset
= -0.5,
1616 .maxInterpolationOffset
= 0.4375,
1617 .subPixelInterpolationOffsetBits
= 4,
1618 .maxFramebufferWidth
= (1 << 14),
1619 .maxFramebufferHeight
= (1 << 14),
1620 .maxFramebufferLayers
= (1 << 11),
1621 .framebufferColorSampleCounts
= sample_counts
,
1622 .framebufferDepthSampleCounts
= sample_counts
,
1623 .framebufferStencilSampleCounts
= sample_counts
,
1624 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1625 .maxColorAttachments
= MAX_RTS
,
1626 .sampledImageColorSampleCounts
= sample_counts
,
1627 .sampledImageIntegerSampleCounts
= sample_counts
,
1628 .sampledImageDepthSampleCounts
= sample_counts
,
1629 .sampledImageStencilSampleCounts
= sample_counts
,
1630 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1631 .maxSampleMaskWords
= 1,
1632 .timestampComputeAndGraphics
= true,
1633 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
1634 .maxClipDistances
= 8,
1635 .maxCullDistances
= 8,
1636 .maxCombinedClipAndCullDistances
= 8,
1637 .discreteQueuePriorities
= 2,
1638 .pointSizeRange
= { 0.125, 255.875 },
1641 (devinfo
->gen
>= 9 || devinfo
->is_cherryview
) ?
1642 2047.9921875 : 7.9921875,
1644 .pointSizeGranularity
= (1.0 / 8.0),
1645 .lineWidthGranularity
= (1.0 / 128.0),
1646 .strictLines
= false,
1647 .standardSampleLocations
= true,
1648 .optimalBufferCopyOffsetAlignment
= 128,
1649 .optimalBufferCopyRowPitchAlignment
= 128,
1650 .nonCoherentAtomSize
= 64,
1653 *pProperties
= (VkPhysicalDeviceProperties
) {
1654 .apiVersion
= anv_physical_device_api_version(pdevice
),
1655 .driverVersion
= vk_get_driver_version(),
1657 .deviceID
= pdevice
->info
.chipset_id
,
1658 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1660 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
1663 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
1664 "%s", pdevice
->name
);
1665 memcpy(pProperties
->pipelineCacheUUID
,
1666 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
1670 anv_get_physical_device_properties_1_1(struct anv_physical_device
*pdevice
,
1671 VkPhysicalDeviceVulkan11Properties
*p
)
1673 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
);
1675 memcpy(p
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1676 memcpy(p
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1677 memset(p
->deviceLUID
, 0, VK_LUID_SIZE
);
1678 p
->deviceNodeMask
= 0;
1679 p
->deviceLUIDValid
= false;
1681 p
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1682 VkShaderStageFlags scalar_stages
= 0;
1683 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1684 if (pdevice
->compiler
->scalar_stage
[stage
])
1685 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1687 p
->subgroupSupportedStages
= scalar_stages
;
1688 p
->subgroupSupportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1689 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1690 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1691 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1692 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1693 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1694 if (pdevice
->info
.gen
>= 8) {
1695 /* TODO: There's no technical reason why these can't be made to
1696 * work on gen7 but they don't at the moment so it's best to leave
1697 * the feature disabled than enabled and broken.
1699 p
->subgroupSupportedOperations
|= VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1700 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
;
1702 p
->subgroupQuadOperationsInAllStages
= pdevice
->info
.gen
>= 8;
1704 p
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY
;
1705 p
->maxMultiviewViewCount
= 16;
1706 p
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1707 p
->protectedNoFault
= false;
1708 /* This value doesn't matter for us today as our per-stage descriptors are
1711 p
->maxPerSetDescriptors
= 1024;
1712 p
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1716 anv_get_physical_device_properties_1_2(struct anv_physical_device
*pdevice
,
1717 VkPhysicalDeviceVulkan12Properties
*p
)
1719 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
);
1721 p
->driverID
= VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR
;
1722 memset(p
->driverName
, 0, sizeof(p
->driverName
));
1723 snprintf(p
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
,
1724 "Intel open-source Mesa driver");
1725 memset(p
->driverInfo
, 0, sizeof(p
->driverInfo
));
1726 snprintf(p
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1727 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
);
1728 p
->conformanceVersion
= (VkConformanceVersionKHR
) {
1735 p
->denormBehaviorIndependence
=
1736 VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1737 p
->roundingModeIndependence
=
1738 VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE_KHR
;
1740 /* Broadwell does not support HF denorms and there are restrictions
1741 * other gens. According to Kabylake's PRM:
1743 * "math - Extended Math Function
1745 * Restriction : Half-float denorms are always retained."
1747 p
->shaderDenormFlushToZeroFloat16
= false;
1748 p
->shaderDenormPreserveFloat16
= pdevice
->info
.gen
> 8;
1749 p
->shaderRoundingModeRTEFloat16
= true;
1750 p
->shaderRoundingModeRTZFloat16
= true;
1751 p
->shaderSignedZeroInfNanPreserveFloat16
= true;
1753 p
->shaderDenormFlushToZeroFloat32
= true;
1754 p
->shaderDenormPreserveFloat32
= true;
1755 p
->shaderRoundingModeRTEFloat32
= true;
1756 p
->shaderRoundingModeRTZFloat32
= true;
1757 p
->shaderSignedZeroInfNanPreserveFloat32
= true;
1759 p
->shaderDenormFlushToZeroFloat64
= true;
1760 p
->shaderDenormPreserveFloat64
= true;
1761 p
->shaderRoundingModeRTEFloat64
= true;
1762 p
->shaderRoundingModeRTZFloat64
= true;
1763 p
->shaderSignedZeroInfNanPreserveFloat64
= true;
1765 /* It's a bit hard to exactly map our implementation to the limits
1766 * described here. The bindless surface handle in the extended
1767 * message descriptors is 20 bits and it's an index into the table of
1768 * RENDER_SURFACE_STATE structs that starts at bindless surface base
1769 * address. Given that most things consume two surface states per
1770 * view (general/sampled for textures and write-only/read-write for
1771 * images), we claim 2^19 things.
1773 * For SSBOs, we just use A64 messages so there is no real limit
1774 * there beyond the limit on the total size of a descriptor set.
1776 const unsigned max_bindless_views
= 1 << 19;
1777 p
->maxUpdateAfterBindDescriptorsInAllPools
= max_bindless_views
;
1778 p
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1779 p
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1780 p
->shaderStorageBufferArrayNonUniformIndexingNative
= true;
1781 p
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1782 p
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1783 p
->robustBufferAccessUpdateAfterBind
= true;
1784 p
->quadDivergentImplicitLod
= false;
1785 p
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_bindless_views
;
1786 p
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1787 p
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1788 p
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_bindless_views
;
1789 p
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_bindless_views
;
1790 p
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
;
1791 p
->maxPerStageUpdateAfterBindResources
= UINT32_MAX
;
1792 p
->maxDescriptorSetUpdateAfterBindSamplers
= max_bindless_views
;
1793 p
->maxDescriptorSetUpdateAfterBindUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1794 p
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1795 p
->maxDescriptorSetUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1796 p
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1797 p
->maxDescriptorSetUpdateAfterBindSampledImages
= max_bindless_views
;
1798 p
->maxDescriptorSetUpdateAfterBindStorageImages
= max_bindless_views
;
1799 p
->maxDescriptorSetUpdateAfterBindInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
;
1801 /* We support all of the depth resolve modes */
1802 p
->supportedDepthResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1803 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1804 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1805 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1806 /* Average doesn't make sense for stencil so we don't support that */
1807 p
->supportedStencilResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
;
1808 if (pdevice
->info
.gen
>= 8) {
1809 /* The advanced stencil resolve modes currently require stencil
1810 * sampling be supported by the hardware.
1812 p
->supportedStencilResolveModes
|= VK_RESOLVE_MODE_MIN_BIT_KHR
|
1813 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1815 p
->independentResolveNone
= true;
1816 p
->independentResolve
= true;
1818 p
->filterMinmaxSingleComponentFormats
= pdevice
->info
.gen
>= 9;
1819 p
->filterMinmaxImageComponentMapping
= pdevice
->info
.gen
>= 9;
1821 p
->maxTimelineSemaphoreValueDifference
= UINT64_MAX
;
1823 p
->framebufferIntegerColorSampleCounts
=
1824 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1827 void anv_GetPhysicalDeviceProperties2(
1828 VkPhysicalDevice physicalDevice
,
1829 VkPhysicalDeviceProperties2
* pProperties
)
1831 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1833 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1835 VkPhysicalDeviceVulkan11Properties core_1_1
= {
1836 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
,
1838 anv_get_physical_device_properties_1_1(pdevice
, &core_1_1
);
1840 VkPhysicalDeviceVulkan12Properties core_1_2
= {
1841 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
,
1843 anv_get_physical_device_properties_1_2(pdevice
, &core_1_2
);
1845 #define CORE_RENAMED_PROPERTY(major, minor, ext_property, core_property) \
1846 memcpy(&properties->ext_property, &core_##major##_##minor.core_property, \
1847 sizeof(core_##major##_##minor.core_property))
1849 #define CORE_PROPERTY(major, minor, property) \
1850 CORE_RENAMED_PROPERTY(major, minor, property, property)
1852 vk_foreach_struct(ext
, pProperties
->pNext
) {
1853 switch (ext
->sType
) {
1854 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT
: {
1855 VkPhysicalDeviceCustomBorderColorPropertiesEXT
*properties
=
1856 (VkPhysicalDeviceCustomBorderColorPropertiesEXT
*)ext
;
1857 properties
->maxCustomBorderColorSamplers
= MAX_CUSTOM_BORDER_COLORS
;
1861 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1862 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1863 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1864 CORE_PROPERTY(1, 2, supportedDepthResolveModes
);
1865 CORE_PROPERTY(1, 2, supportedStencilResolveModes
);
1866 CORE_PROPERTY(1, 2, independentResolveNone
);
1867 CORE_PROPERTY(1, 2, independentResolve
);
1871 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1872 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1873 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1874 CORE_PROPERTY(1, 2, maxUpdateAfterBindDescriptorsInAllPools
);
1875 CORE_PROPERTY(1, 2, shaderUniformBufferArrayNonUniformIndexingNative
);
1876 CORE_PROPERTY(1, 2, shaderSampledImageArrayNonUniformIndexingNative
);
1877 CORE_PROPERTY(1, 2, shaderStorageBufferArrayNonUniformIndexingNative
);
1878 CORE_PROPERTY(1, 2, shaderStorageImageArrayNonUniformIndexingNative
);
1879 CORE_PROPERTY(1, 2, shaderInputAttachmentArrayNonUniformIndexingNative
);
1880 CORE_PROPERTY(1, 2, robustBufferAccessUpdateAfterBind
);
1881 CORE_PROPERTY(1, 2, quadDivergentImplicitLod
);
1882 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSamplers
);
1883 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindUniformBuffers
);
1884 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageBuffers
);
1885 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSampledImages
);
1886 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageImages
);
1887 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindInputAttachments
);
1888 CORE_PROPERTY(1, 2, maxPerStageUpdateAfterBindResources
);
1889 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSamplers
);
1890 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffers
);
1891 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
);
1892 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffers
);
1893 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
);
1894 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSampledImages
);
1895 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageImages
);
1896 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindInputAttachments
);
1900 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1901 VkPhysicalDeviceDriverPropertiesKHR
*properties
=
1902 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1903 CORE_PROPERTY(1, 2, driverID
);
1904 CORE_PROPERTY(1, 2, driverName
);
1905 CORE_PROPERTY(1, 2, driverInfo
);
1906 CORE_PROPERTY(1, 2, conformanceVersion
);
1910 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1911 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*props
=
1912 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1913 /* Userptr needs page aligned memory. */
1914 props
->minImportedHostPointerAlignment
= 4096;
1918 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1919 VkPhysicalDeviceIDProperties
*properties
=
1920 (VkPhysicalDeviceIDProperties
*)ext
;
1921 CORE_PROPERTY(1, 1, deviceUUID
);
1922 CORE_PROPERTY(1, 1, driverUUID
);
1923 CORE_PROPERTY(1, 1, deviceLUID
);
1924 CORE_PROPERTY(1, 1, deviceLUIDValid
);
1928 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1929 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1930 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1931 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1932 props
->maxPerStageDescriptorInlineUniformBlocks
=
1933 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1934 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
=
1935 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1936 props
->maxDescriptorSetInlineUniformBlocks
=
1937 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1938 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
=
1939 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1943 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1944 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1945 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1946 /* In the Skylake PRM Vol. 7, subsection titled "GIQ (Diamond)
1947 * Sampling Rules - Legacy Mode", it says the following:
1949 * "Note that the device divides a pixel into a 16x16 array of
1950 * subpixels, referenced by their upper left corners."
1952 * This is the only known reference in the PRMs to the subpixel
1953 * precision of line rasterization and a "16x16 array of subpixels"
1954 * implies 4 subpixel precision bits. Empirical testing has shown
1955 * that 4 subpixel precision bits applies to all line rasterization
1958 props
->lineSubPixelPrecisionBits
= 4;
1962 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1963 VkPhysicalDeviceMaintenance3Properties
*properties
=
1964 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1965 /* This value doesn't matter for us today as our per-stage
1966 * descriptors are the real limit.
1968 CORE_PROPERTY(1, 1, maxPerSetDescriptors
);
1969 CORE_PROPERTY(1, 1, maxMemoryAllocationSize
);
1973 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1974 VkPhysicalDeviceMultiviewProperties
*properties
=
1975 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1976 CORE_PROPERTY(1, 1, maxMultiviewViewCount
);
1977 CORE_PROPERTY(1, 1, maxMultiviewInstanceIndex
);
1981 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1982 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1983 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1984 properties
->pciDomain
= pdevice
->pci_info
.domain
;
1985 properties
->pciBus
= pdevice
->pci_info
.bus
;
1986 properties
->pciDevice
= pdevice
->pci_info
.device
;
1987 properties
->pciFunction
= pdevice
->pci_info
.function
;
1991 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PERFORMANCE_QUERY_PROPERTIES_KHR
: {
1992 VkPhysicalDevicePerformanceQueryPropertiesKHR
*properties
=
1993 (VkPhysicalDevicePerformanceQueryPropertiesKHR
*)ext
;
1994 /* We could support this by spawning a shader to do the equation
1997 properties
->allowCommandBufferQueryCopies
= false;
2001 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
2002 VkPhysicalDevicePointClippingProperties
*properties
=
2003 (VkPhysicalDevicePointClippingProperties
*) ext
;
2004 CORE_PROPERTY(1, 1, pointClippingBehavior
);
2008 #pragma GCC diagnostic push
2009 #pragma GCC diagnostic ignored "-Wswitch"
2010 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
: {
2011 VkPhysicalDevicePresentationPropertiesANDROID
*props
=
2012 (VkPhysicalDevicePresentationPropertiesANDROID
*)ext
;
2013 props
->sharedImage
= VK_FALSE
;
2016 #pragma GCC diagnostic pop
2018 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
2019 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
2020 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
2021 CORE_PROPERTY(1, 1, protectedNoFault
);
2025 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
2026 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
2027 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
2028 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
2032 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_PROPERTIES_EXT
: {
2033 VkPhysicalDeviceRobustness2PropertiesEXT
*properties
= (void *)ext
;
2034 properties
->robustStorageBufferAccessSizeAlignment
=
2035 ANV_SSBO_BOUNDS_CHECK_ALIGNMENT
;
2036 properties
->robustUniformBufferAccessSizeAlignment
=
2041 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
2042 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
2043 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
2044 CORE_PROPERTY(1, 2, filterMinmaxImageComponentMapping
);
2045 CORE_PROPERTY(1, 2, filterMinmaxSingleComponentFormats
);
2049 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
2050 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
2051 CORE_PROPERTY(1, 1, subgroupSize
);
2052 CORE_RENAMED_PROPERTY(1, 1, supportedStages
,
2053 subgroupSupportedStages
);
2054 CORE_RENAMED_PROPERTY(1, 1, supportedOperations
,
2055 subgroupSupportedOperations
);
2056 CORE_RENAMED_PROPERTY(1, 1, quadOperationsInAllStages
,
2057 subgroupQuadOperationsInAllStages
);
2061 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
2062 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
2063 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
2064 STATIC_ASSERT(8 <= BRW_SUBGROUP_SIZE
&& BRW_SUBGROUP_SIZE
<= 32);
2065 props
->minSubgroupSize
= 8;
2066 props
->maxSubgroupSize
= 32;
2067 props
->maxComputeWorkgroupSubgroups
= pdevice
->info
.max_cs_threads
;
2068 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
2071 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR
: {
2072 VkPhysicalDeviceFloatControlsPropertiesKHR
*properties
= (void *)ext
;
2073 CORE_PROPERTY(1, 2, denormBehaviorIndependence
);
2074 CORE_PROPERTY(1, 2, roundingModeIndependence
);
2075 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat16
);
2076 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat16
);
2077 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat16
);
2078 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat16
);
2079 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat16
);
2080 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat32
);
2081 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat32
);
2082 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat32
);
2083 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat32
);
2084 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat32
);
2085 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat64
);
2086 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat64
);
2087 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat64
);
2088 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat64
);
2089 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat64
);
2093 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
2094 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*props
=
2095 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
2097 /* From the SKL PRM Vol. 2d, docs for RENDER_SURFACE_STATE::Surface
2100 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field
2101 * specifies the base address of the first element of the surface,
2102 * computed in software by adding the surface base address to the
2103 * byte offset of the element in the buffer. The base address must
2104 * be aligned to element size."
2106 * The typed dataport messages require that things be texel aligned.
2107 * Otherwise, we may just load/store the wrong data or, in the worst
2108 * case, there may be hangs.
2110 props
->storageTexelBufferOffsetAlignmentBytes
= 16;
2111 props
->storageTexelBufferOffsetSingleTexelAlignment
= true;
2113 /* The sampler, however, is much more forgiving and it can handle
2114 * arbitrary byte alignment for linear and buffer surfaces. It's
2115 * hard to find a good PRM citation for this but years of empirical
2116 * experience demonstrate that this is true.
2118 props
->uniformTexelBufferOffsetAlignmentBytes
= 1;
2119 props
->uniformTexelBufferOffsetSingleTexelAlignment
= false;
2123 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES_KHR
: {
2124 VkPhysicalDeviceTimelineSemaphorePropertiesKHR
*properties
=
2125 (VkPhysicalDeviceTimelineSemaphorePropertiesKHR
*) ext
;
2126 CORE_PROPERTY(1, 2, maxTimelineSemaphoreValueDifference
);
2130 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
2131 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*props
=
2132 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
2134 props
->maxTransformFeedbackStreams
= MAX_XFB_STREAMS
;
2135 props
->maxTransformFeedbackBuffers
= MAX_XFB_BUFFERS
;
2136 props
->maxTransformFeedbackBufferSize
= (1ull << 32);
2137 props
->maxTransformFeedbackStreamDataSize
= 128 * 4;
2138 props
->maxTransformFeedbackBufferDataSize
= 128 * 4;
2139 props
->maxTransformFeedbackBufferDataStride
= 2048;
2140 props
->transformFeedbackQueries
= true;
2141 props
->transformFeedbackStreamsLinesTriangles
= false;
2142 props
->transformFeedbackRasterizationStreamSelect
= false;
2143 props
->transformFeedbackDraw
= true;
2147 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
2148 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
2149 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
2150 /* We have to restrict this a bit for multiview */
2151 props
->maxVertexAttribDivisor
= UINT32_MAX
/ 16;
2155 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
:
2156 anv_get_physical_device_properties_1_1(pdevice
, (void *)ext
);
2159 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
:
2160 anv_get_physical_device_properties_1_2(pdevice
, (void *)ext
);
2164 anv_debug_ignored_stype(ext
->sType
);
2169 #undef CORE_RENAMED_PROPERTY
2170 #undef CORE_PROPERTY
2173 /* We support exactly one queue family. */
2174 static const VkQueueFamilyProperties
2175 anv_queue_family_properties
= {
2176 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
2177 VK_QUEUE_COMPUTE_BIT
|
2178 VK_QUEUE_TRANSFER_BIT
,
2180 .timestampValidBits
= 36, /* XXX: Real value here */
2181 .minImageTransferGranularity
= { 1, 1, 1 },
2184 void anv_GetPhysicalDeviceQueueFamilyProperties(
2185 VkPhysicalDevice physicalDevice
,
2187 VkQueueFamilyProperties
* pQueueFamilyProperties
)
2189 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
2191 vk_outarray_append(&out
, p
) {
2192 *p
= anv_queue_family_properties
;
2196 void anv_GetPhysicalDeviceQueueFamilyProperties2(
2197 VkPhysicalDevice physicalDevice
,
2198 uint32_t* pQueueFamilyPropertyCount
,
2199 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
2202 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
2204 vk_outarray_append(&out
, p
) {
2205 p
->queueFamilyProperties
= anv_queue_family_properties
;
2207 vk_foreach_struct(s
, p
->pNext
) {
2208 anv_debug_ignored_stype(s
->sType
);
2213 void anv_GetPhysicalDeviceMemoryProperties(
2214 VkPhysicalDevice physicalDevice
,
2215 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
2217 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
2219 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
2220 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
2221 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
2222 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
2223 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
2227 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
2228 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
2229 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
2230 .size
= physical_device
->memory
.heaps
[i
].size
,
2231 .flags
= physical_device
->memory
.heaps
[i
].flags
,
2237 anv_get_memory_budget(VkPhysicalDevice physicalDevice
,
2238 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
2240 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
2241 uint64_t sys_available
= get_available_system_memory();
2242 assert(sys_available
> 0);
2244 VkDeviceSize total_heaps_size
= 0;
2245 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++)
2246 total_heaps_size
+= device
->memory
.heaps
[i
].size
;
2248 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++) {
2249 VkDeviceSize heap_size
= device
->memory
.heaps
[i
].size
;
2250 VkDeviceSize heap_used
= device
->memory
.heaps
[i
].used
;
2251 VkDeviceSize heap_budget
;
2253 double heap_proportion
= (double) heap_size
/ total_heaps_size
;
2254 VkDeviceSize sys_available_prop
= sys_available
* heap_proportion
;
2257 * Let's not incite the app to starve the system: report at most 90% of
2258 * available system memory.
2260 uint64_t heap_available
= sys_available_prop
* 9 / 10;
2261 heap_budget
= MIN2(heap_size
, heap_used
+ heap_available
);
2264 * Round down to the nearest MB
2266 heap_budget
&= ~((1ull << 20) - 1);
2269 * The heapBudget value must be non-zero for array elements less than
2270 * VkPhysicalDeviceMemoryProperties::memoryHeapCount. The heapBudget
2271 * value must be less than or equal to VkMemoryHeap::size for each heap.
2273 assert(0 < heap_budget
&& heap_budget
<= heap_size
);
2275 memoryBudget
->heapUsage
[i
] = heap_used
;
2276 memoryBudget
->heapBudget
[i
] = heap_budget
;
2279 /* The heapBudget and heapUsage values must be zero for array elements
2280 * greater than or equal to VkPhysicalDeviceMemoryProperties::memoryHeapCount
2282 for (uint32_t i
= device
->memory
.heap_count
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
2283 memoryBudget
->heapBudget
[i
] = 0;
2284 memoryBudget
->heapUsage
[i
] = 0;
2288 void anv_GetPhysicalDeviceMemoryProperties2(
2289 VkPhysicalDevice physicalDevice
,
2290 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
2292 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
2293 &pMemoryProperties
->memoryProperties
);
2295 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
2296 switch (ext
->sType
) {
2297 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
:
2298 anv_get_memory_budget(physicalDevice
, (void*)ext
);
2301 anv_debug_ignored_stype(ext
->sType
);
2308 anv_GetDeviceGroupPeerMemoryFeatures(
2311 uint32_t localDeviceIndex
,
2312 uint32_t remoteDeviceIndex
,
2313 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
2315 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
2316 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2317 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2318 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2319 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
2322 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
2323 VkInstance _instance
,
2326 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2328 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
2329 * when we have to return valid function pointers, NULL, or it's left
2330 * undefined. See the table for exact details.
2335 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
2336 if (strcmp(pName, "vk" #entrypoint) == 0) \
2337 return (PFN_vkVoidFunction)anv_##entrypoint
2339 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
2340 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
2341 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
2342 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
2344 /* GetInstanceProcAddr() can also be called with a NULL instance.
2345 * See https://gitlab.khronos.org/vulkan/vulkan/issues/2057
2347 LOOKUP_ANV_ENTRYPOINT(GetInstanceProcAddr
);
2349 #undef LOOKUP_ANV_ENTRYPOINT
2351 if (instance
== NULL
)
2354 int idx
= anv_get_instance_entrypoint_index(pName
);
2356 return instance
->dispatch
.entrypoints
[idx
];
2358 idx
= anv_get_physical_device_entrypoint_index(pName
);
2360 return instance
->physical_device_dispatch
.entrypoints
[idx
];
2362 idx
= anv_get_device_entrypoint_index(pName
);
2364 return instance
->device_dispatch
.entrypoints
[idx
];
2369 /* With version 1+ of the loader interface the ICD should expose
2370 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
2373 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2374 VkInstance instance
,
2378 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2379 VkInstance instance
,
2382 return anv_GetInstanceProcAddr(instance
, pName
);
2385 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
2389 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2391 if (!device
|| !pName
)
2394 int idx
= anv_get_device_entrypoint_index(pName
);
2398 return device
->dispatch
.entrypoints
[idx
];
2401 /* With version 4+ of the loader interface the ICD should expose
2402 * vk_icdGetPhysicalDeviceProcAddr()
2405 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
2406 VkInstance _instance
,
2409 PFN_vkVoidFunction
vk_icdGetPhysicalDeviceProcAddr(
2410 VkInstance _instance
,
2413 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2415 if (!pName
|| !instance
)
2418 int idx
= anv_get_physical_device_entrypoint_index(pName
);
2422 return instance
->physical_device_dispatch
.entrypoints
[idx
];
2427 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
2428 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
2429 const VkAllocationCallbacks
* pAllocator
,
2430 VkDebugReportCallbackEXT
* pCallback
)
2432 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2433 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2434 pCreateInfo
, pAllocator
, &instance
->alloc
,
2439 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2440 VkDebugReportCallbackEXT _callback
,
2441 const VkAllocationCallbacks
* pAllocator
)
2443 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2444 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2445 _callback
, pAllocator
, &instance
->alloc
);
2449 anv_DebugReportMessageEXT(VkInstance _instance
,
2450 VkDebugReportFlagsEXT flags
,
2451 VkDebugReportObjectTypeEXT objectType
,
2454 int32_t messageCode
,
2455 const char* pLayerPrefix
,
2456 const char* pMessage
)
2458 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2459 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2460 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2463 static struct anv_state
2464 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
2466 struct anv_state state
;
2468 state
= anv_state_pool_alloc(pool
, size
, align
);
2469 memcpy(state
.map
, p
, size
);
2475 anv_device_init_border_colors(struct anv_device
*device
)
2477 if (device
->info
.is_haswell
) {
2478 static const struct hsw_border_color border_colors
[] = {
2479 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2480 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2481 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2482 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2483 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2484 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2487 device
->border_colors
=
2488 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2489 sizeof(border_colors
), 512, border_colors
);
2491 static const struct gen8_border_color border_colors
[] = {
2492 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2493 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2494 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2495 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2496 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2497 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2500 device
->border_colors
=
2501 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2502 sizeof(border_colors
), 64, border_colors
);
2507 anv_device_init_trivial_batch(struct anv_device
*device
)
2509 VkResult result
= anv_device_alloc_bo(device
, 4096,
2510 ANV_BO_ALLOC_MAPPED
,
2511 0 /* explicit_address */,
2512 &device
->trivial_batch_bo
);
2513 if (result
!= VK_SUCCESS
)
2516 struct anv_batch batch
= {
2517 .start
= device
->trivial_batch_bo
->map
,
2518 .next
= device
->trivial_batch_bo
->map
,
2519 .end
= device
->trivial_batch_bo
->map
+ 4096,
2522 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2523 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2525 if (!device
->info
.has_llc
)
2526 gen_clflush_range(batch
.start
, batch
.next
- batch
.start
);
2531 VkResult
anv_EnumerateDeviceExtensionProperties(
2532 VkPhysicalDevice physicalDevice
,
2533 const char* pLayerName
,
2534 uint32_t* pPropertyCount
,
2535 VkExtensionProperties
* pProperties
)
2537 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
2538 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2540 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
2541 if (device
->supported_extensions
.extensions
[i
]) {
2542 vk_outarray_append(&out
, prop
) {
2543 *prop
= anv_device_extensions
[i
];
2548 return vk_outarray_status(&out
);
2552 vk_priority_to_gen(int priority
)
2555 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2556 return GEN_CONTEXT_LOW_PRIORITY
;
2557 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2558 return GEN_CONTEXT_MEDIUM_PRIORITY
;
2559 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2560 return GEN_CONTEXT_HIGH_PRIORITY
;
2561 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2562 return GEN_CONTEXT_REALTIME_PRIORITY
;
2564 unreachable("Invalid priority");
2569 anv_device_init_hiz_clear_value_bo(struct anv_device
*device
)
2571 VkResult result
= anv_device_alloc_bo(device
, 4096,
2572 ANV_BO_ALLOC_MAPPED
,
2573 0 /* explicit_address */,
2574 &device
->hiz_clear_bo
);
2575 if (result
!= VK_SUCCESS
)
2578 union isl_color_value hiz_clear
= { .u32
= { 0, } };
2579 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
2581 memcpy(device
->hiz_clear_bo
->map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
2583 if (!device
->info
.has_llc
)
2584 gen_clflush_range(device
->hiz_clear_bo
->map
, sizeof(hiz_clear
.u32
));
2590 get_bo_from_pool(struct gen_batch_decode_bo
*ret
,
2591 struct anv_block_pool
*pool
,
2594 anv_block_pool_foreach_bo(bo
, pool
) {
2595 uint64_t bo_address
= gen_48b_address(bo
->offset
);
2596 if (address
>= bo_address
&& address
< (bo_address
+ bo
->size
)) {
2597 *ret
= (struct gen_batch_decode_bo
) {
2608 /* Finding a buffer for batch decoding */
2609 static struct gen_batch_decode_bo
2610 decode_get_bo(void *v_batch
, bool ppgtt
, uint64_t address
)
2612 struct anv_device
*device
= v_batch
;
2613 struct gen_batch_decode_bo ret_bo
= {};
2617 if (get_bo_from_pool(&ret_bo
, &device
->dynamic_state_pool
.block_pool
, address
))
2619 if (get_bo_from_pool(&ret_bo
, &device
->instruction_state_pool
.block_pool
, address
))
2621 if (get_bo_from_pool(&ret_bo
, &device
->binding_table_pool
.block_pool
, address
))
2623 if (get_bo_from_pool(&ret_bo
, &device
->surface_state_pool
.block_pool
, address
))
2626 if (!device
->cmd_buffer_being_decoded
)
2627 return (struct gen_batch_decode_bo
) { };
2629 struct anv_batch_bo
**bo
;
2631 u_vector_foreach(bo
, &device
->cmd_buffer_being_decoded
->seen_bbos
) {
2632 /* The decoder zeroes out the top 16 bits, so we need to as well */
2633 uint64_t bo_address
= (*bo
)->bo
->offset
& (~0ull >> 16);
2635 if (address
>= bo_address
&& address
< bo_address
+ (*bo
)->bo
->size
) {
2636 return (struct gen_batch_decode_bo
) {
2638 .size
= (*bo
)->bo
->size
,
2639 .map
= (*bo
)->bo
->map
,
2644 return (struct gen_batch_decode_bo
) { };
2647 struct gen_aux_map_buffer
{
2648 struct gen_buffer base
;
2649 struct anv_state state
;
2652 static struct gen_buffer
*
2653 gen_aux_map_buffer_alloc(void *driver_ctx
, uint32_t size
)
2655 struct gen_aux_map_buffer
*buf
= malloc(sizeof(struct gen_aux_map_buffer
));
2659 struct anv_device
*device
= (struct anv_device
*)driver_ctx
;
2660 assert(device
->physical
->supports_48bit_addresses
&&
2661 device
->physical
->use_softpin
);
2663 struct anv_state_pool
*pool
= &device
->dynamic_state_pool
;
2664 buf
->state
= anv_state_pool_alloc(pool
, size
, size
);
2666 buf
->base
.gpu
= pool
->block_pool
.bo
->offset
+ buf
->state
.offset
;
2667 buf
->base
.gpu_end
= buf
->base
.gpu
+ buf
->state
.alloc_size
;
2668 buf
->base
.map
= buf
->state
.map
;
2669 buf
->base
.driver_bo
= &buf
->state
;
2674 gen_aux_map_buffer_free(void *driver_ctx
, struct gen_buffer
*buffer
)
2676 struct gen_aux_map_buffer
*buf
= (struct gen_aux_map_buffer
*)buffer
;
2677 struct anv_device
*device
= (struct anv_device
*)driver_ctx
;
2678 struct anv_state_pool
*pool
= &device
->dynamic_state_pool
;
2679 anv_state_pool_free(pool
, buf
->state
);
2683 static struct gen_mapped_pinned_buffer_alloc aux_map_allocator
= {
2684 .alloc
= gen_aux_map_buffer_alloc
,
2685 .free
= gen_aux_map_buffer_free
,
2689 check_physical_device_features(VkPhysicalDevice physicalDevice
,
2690 const VkPhysicalDeviceFeatures
*features
)
2692 VkPhysicalDeviceFeatures supported_features
;
2693 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2694 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2695 VkBool32
*enabled_feature
= (VkBool32
*)features
;
2696 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2697 for (uint32_t i
= 0; i
< num_features
; i
++) {
2698 if (enabled_feature
[i
] && !supported_feature
[i
])
2699 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2705 VkResult
anv_CreateDevice(
2706 VkPhysicalDevice physicalDevice
,
2707 const VkDeviceCreateInfo
* pCreateInfo
,
2708 const VkAllocationCallbacks
* pAllocator
,
2711 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
2713 struct anv_device
*device
;
2715 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
2717 struct anv_device_extension_table enabled_extensions
= { };
2718 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
2720 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
2721 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
2722 anv_device_extensions
[idx
].extensionName
) == 0)
2726 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
2727 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2729 if (!physical_device
->supported_extensions
.extensions
[idx
])
2730 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2732 enabled_extensions
.extensions
[idx
] = true;
2735 /* Check enabled features */
2736 bool robust_buffer_access
= false;
2737 if (pCreateInfo
->pEnabledFeatures
) {
2738 result
= check_physical_device_features(physicalDevice
,
2739 pCreateInfo
->pEnabledFeatures
);
2740 if (result
!= VK_SUCCESS
)
2743 if (pCreateInfo
->pEnabledFeatures
->robustBufferAccess
)
2744 robust_buffer_access
= true;
2747 vk_foreach_struct_const(ext
, pCreateInfo
->pNext
) {
2748 switch (ext
->sType
) {
2749 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2
: {
2750 const VkPhysicalDeviceFeatures2
*features
= (const void *)ext
;
2751 result
= check_physical_device_features(physicalDevice
,
2752 &features
->features
);
2753 if (result
!= VK_SUCCESS
)
2756 if (features
->features
.robustBufferAccess
)
2757 robust_buffer_access
= true;
2767 /* Check requested queues and fail if we are requested to create any
2768 * queues with flags we don't support.
2770 assert(pCreateInfo
->queueCreateInfoCount
> 0);
2771 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
2772 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
2773 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2776 /* Check if client specified queue priority. */
2777 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
2778 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
2779 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
2781 VkQueueGlobalPriorityEXT priority
=
2782 queue_priority
? queue_priority
->globalPriority
:
2783 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
2785 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
2787 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2789 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2791 vk_device_init(&device
->vk
, pCreateInfo
,
2792 &physical_device
->instance
->alloc
, pAllocator
);
2794 if (INTEL_DEBUG
& DEBUG_BATCH
) {
2795 const unsigned decode_flags
=
2796 GEN_BATCH_DECODE_FULL
|
2797 ((INTEL_DEBUG
& DEBUG_COLOR
) ? GEN_BATCH_DECODE_IN_COLOR
: 0) |
2798 GEN_BATCH_DECODE_OFFSETS
|
2799 GEN_BATCH_DECODE_FLOATS
;
2801 gen_batch_decode_ctx_init(&device
->decoder_ctx
,
2802 &physical_device
->info
,
2803 stderr
, decode_flags
, NULL
,
2804 decode_get_bo
, NULL
, device
);
2807 device
->physical
= physical_device
;
2808 device
->no_hw
= physical_device
->no_hw
;
2809 device
->_lost
= false;
2811 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
2812 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
2813 if (device
->fd
== -1) {
2814 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2818 device
->context_id
= anv_gem_create_context(device
);
2819 if (device
->context_id
== -1) {
2820 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2824 result
= anv_queue_init(device
, &device
->queue
);
2825 if (result
!= VK_SUCCESS
)
2826 goto fail_context_id
;
2828 if (physical_device
->use_softpin
) {
2829 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
2830 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2834 /* keep the page with address zero out of the allocator */
2835 util_vma_heap_init(&device
->vma_lo
,
2836 LOW_HEAP_MIN_ADDRESS
, LOW_HEAP_SIZE
);
2838 util_vma_heap_init(&device
->vma_cva
, CLIENT_VISIBLE_HEAP_MIN_ADDRESS
,
2839 CLIENT_VISIBLE_HEAP_SIZE
);
2841 /* Leave the last 4GiB out of the high vma range, so that no state
2842 * base address + size can overflow 48 bits. For more information see
2843 * the comment about Wa32bitGeneralStateOffset in anv_allocator.c
2845 util_vma_heap_init(&device
->vma_hi
, HIGH_HEAP_MIN_ADDRESS
,
2846 physical_device
->gtt_size
- (1ull << 32) -
2847 HIGH_HEAP_MIN_ADDRESS
);
2850 list_inithead(&device
->memory_objects
);
2852 /* As per spec, the driver implementation may deny requests to acquire
2853 * a priority above the default priority (MEDIUM) if the caller does not
2854 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
2857 if (physical_device
->has_context_priority
) {
2858 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
2859 I915_CONTEXT_PARAM_PRIORITY
,
2860 vk_priority_to_gen(priority
));
2861 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
2862 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
2867 device
->info
= physical_device
->info
;
2868 device
->isl_dev
= physical_device
->isl_dev
;
2870 /* On Broadwell and later, we can use batch chaining to more efficiently
2871 * implement growing command buffers. Prior to Haswell, the kernel
2872 * command parser gets in the way and we have to fall back to growing
2875 device
->can_chain_batches
= device
->info
.gen
>= 8;
2877 device
->robust_buffer_access
= robust_buffer_access
;
2878 device
->enabled_extensions
= enabled_extensions
;
2880 const struct anv_instance
*instance
= physical_device
->instance
;
2881 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2882 /* Vulkan requires that entrypoints for extensions which have not been
2883 * enabled must not be advertised.
2885 if (!anv_device_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
2886 &instance
->enabled_extensions
,
2887 &device
->enabled_extensions
)) {
2888 device
->dispatch
.entrypoints
[i
] = NULL
;
2890 device
->dispatch
.entrypoints
[i
] =
2891 anv_resolve_device_entrypoint(&device
->info
, i
);
2895 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
2896 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2900 pthread_condattr_t condattr
;
2901 if (pthread_condattr_init(&condattr
) != 0) {
2902 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2905 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
2906 pthread_condattr_destroy(&condattr
);
2907 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2910 if (pthread_cond_init(&device
->queue_submit
, &condattr
) != 0) {
2911 pthread_condattr_destroy(&condattr
);
2912 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2915 pthread_condattr_destroy(&condattr
);
2917 result
= anv_bo_cache_init(&device
->bo_cache
);
2918 if (result
!= VK_SUCCESS
)
2919 goto fail_queue_cond
;
2921 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
2923 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
2924 DYNAMIC_STATE_POOL_MIN_ADDRESS
, 0, 16384);
2925 if (result
!= VK_SUCCESS
)
2926 goto fail_batch_bo_pool
;
2928 if (device
->info
.gen
>= 8) {
2929 /* The border color pointer is limited to 24 bits, so we need to make
2930 * sure that any such color used at any point in the program doesn't
2931 * exceed that limit.
2932 * We achieve that by reserving all the custom border colors we support
2933 * right off the bat, so they are close to the base address.
2935 anv_state_reserved_pool_init(&device
->custom_border_colors
,
2936 &device
->dynamic_state_pool
,
2937 MAX_CUSTOM_BORDER_COLORS
,
2938 sizeof(struct gen8_border_color
), 64);
2941 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
2942 INSTRUCTION_STATE_POOL_MIN_ADDRESS
, 0, 16384);
2943 if (result
!= VK_SUCCESS
)
2944 goto fail_dynamic_state_pool
;
2946 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
2947 SURFACE_STATE_POOL_MIN_ADDRESS
, 0, 4096);
2948 if (result
!= VK_SUCCESS
)
2949 goto fail_instruction_state_pool
;
2951 if (physical_device
->use_softpin
) {
2952 int64_t bt_pool_offset
= (int64_t)BINDING_TABLE_POOL_MIN_ADDRESS
-
2953 (int64_t)SURFACE_STATE_POOL_MIN_ADDRESS
;
2954 assert(INT32_MIN
< bt_pool_offset
&& bt_pool_offset
< 0);
2955 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
2956 SURFACE_STATE_POOL_MIN_ADDRESS
,
2957 bt_pool_offset
, 4096);
2958 if (result
!= VK_SUCCESS
)
2959 goto fail_surface_state_pool
;
2962 if (device
->info
.has_aux_map
) {
2963 device
->aux_map_ctx
= gen_aux_map_init(device
, &aux_map_allocator
,
2964 &physical_device
->info
);
2965 if (!device
->aux_map_ctx
)
2966 goto fail_binding_table_pool
;
2969 result
= anv_device_alloc_bo(device
, 4096,
2970 ANV_BO_ALLOC_CAPTURE
| ANV_BO_ALLOC_MAPPED
/* flags */,
2971 0 /* explicit_address */,
2972 &device
->workaround_bo
);
2973 if (result
!= VK_SUCCESS
)
2974 goto fail_surface_aux_map_pool
;
2976 device
->workaround_address
= (struct anv_address
) {
2977 .bo
= device
->workaround_bo
,
2978 .offset
= align_u32(
2979 intel_debug_write_identifiers(device
->workaround_bo
->map
,
2980 device
->workaround_bo
->size
,
2984 device
->debug_frame_desc
=
2985 intel_debug_get_identifier_block(device
->workaround_bo
->map
,
2986 device
->workaround_bo
->size
,
2987 GEN_DEBUG_BLOCK_TYPE_FRAME
);
2989 result
= anv_device_init_trivial_batch(device
);
2990 if (result
!= VK_SUCCESS
)
2991 goto fail_workaround_bo
;
2993 /* Allocate a null surface state at surface state offset 0. This makes
2994 * NULL descriptor handling trivial because we can just memset structures
2995 * to zero and they have a valid descriptor.
2997 device
->null_surface_state
=
2998 anv_state_pool_alloc(&device
->surface_state_pool
,
2999 device
->isl_dev
.ss
.size
,
3000 device
->isl_dev
.ss
.align
);
3001 isl_null_fill_state(&device
->isl_dev
, device
->null_surface_state
.map
,
3002 isl_extent3d(1, 1, 1) /* This shouldn't matter */);
3003 assert(device
->null_surface_state
.offset
== 0);
3005 if (device
->info
.gen
>= 10) {
3006 result
= anv_device_init_hiz_clear_value_bo(device
);
3007 if (result
!= VK_SUCCESS
)
3008 goto fail_trivial_batch_bo
;
3011 anv_scratch_pool_init(device
, &device
->scratch_pool
);
3013 switch (device
->info
.gen
) {
3015 if (!device
->info
.is_haswell
)
3016 result
= gen7_init_device_state(device
);
3018 result
= gen75_init_device_state(device
);
3021 result
= gen8_init_device_state(device
);
3024 result
= gen9_init_device_state(device
);
3027 result
= gen10_init_device_state(device
);
3030 result
= gen11_init_device_state(device
);
3033 result
= gen12_init_device_state(device
);
3036 /* Shouldn't get here as we don't create physical devices for any other
3038 unreachable("unhandled gen");
3040 if (result
!= VK_SUCCESS
)
3041 goto fail_clear_value_bo
;
3043 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
,
3044 true /* cache_enabled */, false /* external_sync */);
3046 anv_device_init_blorp(device
);
3048 anv_device_init_border_colors(device
);
3050 anv_device_perf_init(device
);
3052 *pDevice
= anv_device_to_handle(device
);
3056 fail_clear_value_bo
:
3057 if (device
->info
.gen
>= 10)
3058 anv_device_release_bo(device
, device
->hiz_clear_bo
);
3059 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
3060 fail_trivial_batch_bo
:
3061 anv_device_release_bo(device
, device
->trivial_batch_bo
);
3063 anv_device_release_bo(device
, device
->workaround_bo
);
3064 fail_surface_aux_map_pool
:
3065 if (device
->info
.has_aux_map
) {
3066 gen_aux_map_finish(device
->aux_map_ctx
);
3067 device
->aux_map_ctx
= NULL
;
3069 fail_binding_table_pool
:
3070 if (physical_device
->use_softpin
)
3071 anv_state_pool_finish(&device
->binding_table_pool
);
3072 fail_surface_state_pool
:
3073 anv_state_pool_finish(&device
->surface_state_pool
);
3074 fail_instruction_state_pool
:
3075 anv_state_pool_finish(&device
->instruction_state_pool
);
3076 fail_dynamic_state_pool
:
3077 if (device
->info
.gen
>= 8)
3078 anv_state_reserved_pool_finish(&device
->custom_border_colors
);
3079 anv_state_pool_finish(&device
->dynamic_state_pool
);
3081 anv_bo_pool_finish(&device
->batch_bo_pool
);
3082 anv_bo_cache_finish(&device
->bo_cache
);
3084 pthread_cond_destroy(&device
->queue_submit
);
3086 pthread_mutex_destroy(&device
->mutex
);
3088 if (physical_device
->use_softpin
) {
3089 util_vma_heap_finish(&device
->vma_hi
);
3090 util_vma_heap_finish(&device
->vma_cva
);
3091 util_vma_heap_finish(&device
->vma_lo
);
3094 anv_queue_finish(&device
->queue
);
3096 anv_gem_destroy_context(device
, device
->context_id
);
3100 vk_free(&device
->vk
.alloc
, device
);
3105 void anv_DestroyDevice(
3107 const VkAllocationCallbacks
* pAllocator
)
3109 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3114 anv_device_finish_blorp(device
);
3116 anv_pipeline_cache_finish(&device
->default_pipeline_cache
);
3118 anv_queue_finish(&device
->queue
);
3120 #ifdef HAVE_VALGRIND
3121 /* We only need to free these to prevent valgrind errors. The backing
3122 * BO will go away in a couple of lines so we don't actually leak.
3124 if (device
->info
.gen
>= 8)
3125 anv_state_reserved_pool_finish(&device
->custom_border_colors
);
3126 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
3127 anv_state_pool_free(&device
->dynamic_state_pool
, device
->slice_hash
);
3130 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
3132 anv_device_release_bo(device
, device
->workaround_bo
);
3133 anv_device_release_bo(device
, device
->trivial_batch_bo
);
3134 if (device
->info
.gen
>= 10)
3135 anv_device_release_bo(device
, device
->hiz_clear_bo
);
3137 if (device
->info
.has_aux_map
) {
3138 gen_aux_map_finish(device
->aux_map_ctx
);
3139 device
->aux_map_ctx
= NULL
;
3142 if (device
->physical
->use_softpin
)
3143 anv_state_pool_finish(&device
->binding_table_pool
);
3144 anv_state_pool_finish(&device
->surface_state_pool
);
3145 anv_state_pool_finish(&device
->instruction_state_pool
);
3146 anv_state_pool_finish(&device
->dynamic_state_pool
);
3148 anv_bo_pool_finish(&device
->batch_bo_pool
);
3150 anv_bo_cache_finish(&device
->bo_cache
);
3152 if (device
->physical
->use_softpin
) {
3153 util_vma_heap_finish(&device
->vma_hi
);
3154 util_vma_heap_finish(&device
->vma_cva
);
3155 util_vma_heap_finish(&device
->vma_lo
);
3158 pthread_cond_destroy(&device
->queue_submit
);
3159 pthread_mutex_destroy(&device
->mutex
);
3161 anv_gem_destroy_context(device
, device
->context_id
);
3163 if (INTEL_DEBUG
& DEBUG_BATCH
)
3164 gen_batch_decode_ctx_finish(&device
->decoder_ctx
);
3168 vk_device_finish(&device
->vk
);
3169 vk_free(&device
->vk
.alloc
, device
);
3172 VkResult
anv_EnumerateInstanceLayerProperties(
3173 uint32_t* pPropertyCount
,
3174 VkLayerProperties
* pProperties
)
3176 if (pProperties
== NULL
) {
3177 *pPropertyCount
= 0;
3181 /* None supported at this time */
3182 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
3185 VkResult
anv_EnumerateDeviceLayerProperties(
3186 VkPhysicalDevice physicalDevice
,
3187 uint32_t* pPropertyCount
,
3188 VkLayerProperties
* pProperties
)
3190 if (pProperties
== NULL
) {
3191 *pPropertyCount
= 0;
3195 /* None supported at this time */
3196 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
3199 void anv_GetDeviceQueue(
3201 uint32_t queueNodeIndex
,
3202 uint32_t queueIndex
,
3205 const VkDeviceQueueInfo2 info
= {
3206 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
3209 .queueFamilyIndex
= queueNodeIndex
,
3210 .queueIndex
= queueIndex
,
3213 anv_GetDeviceQueue2(_device
, &info
, pQueue
);
3216 void anv_GetDeviceQueue2(
3218 const VkDeviceQueueInfo2
* pQueueInfo
,
3221 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3223 assert(pQueueInfo
->queueIndex
== 0);
3225 if (pQueueInfo
->flags
== device
->queue
.flags
)
3226 *pQueue
= anv_queue_to_handle(&device
->queue
);
3232 _anv_device_set_lost(struct anv_device
*device
,
3233 const char *file
, int line
,
3234 const char *msg
, ...)
3239 p_atomic_inc(&device
->_lost
);
3242 err
= __vk_errorv(device
->physical
->instance
, device
,
3243 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
3244 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
3247 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
3254 _anv_queue_set_lost(struct anv_queue
*queue
,
3255 const char *file
, int line
,
3256 const char *msg
, ...)
3261 p_atomic_inc(&queue
->device
->_lost
);
3264 err
= __vk_errorv(queue
->device
->physical
->instance
, queue
->device
,
3265 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
3266 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
3269 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
3276 anv_device_query_status(struct anv_device
*device
)
3278 /* This isn't likely as most of the callers of this function already check
3279 * for it. However, it doesn't hurt to check and it potentially lets us
3282 if (anv_device_is_lost(device
))
3283 return VK_ERROR_DEVICE_LOST
;
3285 uint32_t active
, pending
;
3286 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
3288 /* We don't know the real error. */
3289 return anv_device_set_lost(device
, "get_reset_stats failed: %m");
3293 return anv_device_set_lost(device
, "GPU hung on one of our command buffers");
3294 } else if (pending
) {
3295 return anv_device_set_lost(device
, "GPU hung with commands in-flight");
3302 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
3304 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
3305 * Other usages of the BO (such as on different hardware) will not be
3306 * flagged as "busy" by this ioctl. Use with care.
3308 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
3310 return VK_NOT_READY
;
3311 } else if (ret
== -1) {
3312 /* We don't know the real error. */
3313 return anv_device_set_lost(device
, "gem wait failed: %m");
3316 /* Query for device status after the busy call. If the BO we're checking
3317 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
3318 * client because it clearly doesn't have valid data. Yes, this most
3319 * likely means an ioctl, but we just did an ioctl to query the busy status
3320 * so it's no great loss.
3322 return anv_device_query_status(device
);
3326 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
3329 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
3330 if (ret
== -1 && errno
== ETIME
) {
3332 } else if (ret
== -1) {
3333 /* We don't know the real error. */
3334 return anv_device_set_lost(device
, "gem wait failed: %m");
3337 /* Query for device status after the wait. If the BO we're waiting on got
3338 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
3339 * because it clearly doesn't have valid data. Yes, this most likely means
3340 * an ioctl, but we just did an ioctl to wait so it's no great loss.
3342 return anv_device_query_status(device
);
3345 VkResult
anv_DeviceWaitIdle(
3348 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3350 if (anv_device_is_lost(device
))
3351 return VK_ERROR_DEVICE_LOST
;
3353 return anv_queue_submit_simple_batch(&device
->queue
, NULL
);
3357 anv_vma_alloc(struct anv_device
*device
,
3358 uint64_t size
, uint64_t align
,
3359 enum anv_bo_alloc_flags alloc_flags
,
3360 uint64_t client_address
)
3362 pthread_mutex_lock(&device
->vma_mutex
);
3366 if (alloc_flags
& ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS
) {
3367 if (client_address
) {
3368 if (util_vma_heap_alloc_addr(&device
->vma_cva
,
3369 client_address
, size
)) {
3370 addr
= client_address
;
3373 addr
= util_vma_heap_alloc(&device
->vma_cva
, size
, align
);
3375 /* We don't want to fall back to other heaps */
3379 assert(client_address
== 0);
3381 if (!(alloc_flags
& ANV_BO_ALLOC_32BIT_ADDRESS
))
3382 addr
= util_vma_heap_alloc(&device
->vma_hi
, size
, align
);
3385 addr
= util_vma_heap_alloc(&device
->vma_lo
, size
, align
);
3388 pthread_mutex_unlock(&device
->vma_mutex
);
3390 assert(addr
== gen_48b_address(addr
));
3391 return gen_canonical_address(addr
);
3395 anv_vma_free(struct anv_device
*device
,
3396 uint64_t address
, uint64_t size
)
3398 const uint64_t addr_48b
= gen_48b_address(address
);
3400 pthread_mutex_lock(&device
->vma_mutex
);
3402 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
3403 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
3404 util_vma_heap_free(&device
->vma_lo
, addr_48b
, size
);
3405 } else if (addr_48b
>= CLIENT_VISIBLE_HEAP_MIN_ADDRESS
&&
3406 addr_48b
<= CLIENT_VISIBLE_HEAP_MAX_ADDRESS
) {
3407 util_vma_heap_free(&device
->vma_cva
, addr_48b
, size
);
3409 assert(addr_48b
>= HIGH_HEAP_MIN_ADDRESS
);
3410 util_vma_heap_free(&device
->vma_hi
, addr_48b
, size
);
3413 pthread_mutex_unlock(&device
->vma_mutex
);
3416 VkResult
anv_AllocateMemory(
3418 const VkMemoryAllocateInfo
* pAllocateInfo
,
3419 const VkAllocationCallbacks
* pAllocator
,
3420 VkDeviceMemory
* pMem
)
3422 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3423 struct anv_physical_device
*pdevice
= device
->physical
;
3424 struct anv_device_memory
*mem
;
3425 VkResult result
= VK_SUCCESS
;
3427 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3429 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
3430 assert(pAllocateInfo
->allocationSize
> 0);
3432 VkDeviceSize aligned_alloc_size
=
3433 align_u64(pAllocateInfo
->allocationSize
, 4096);
3435 if (aligned_alloc_size
> MAX_MEMORY_ALLOCATION_SIZE
)
3436 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3438 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
3439 struct anv_memory_type
*mem_type
=
3440 &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
3441 assert(mem_type
->heapIndex
< pdevice
->memory
.heap_count
);
3442 struct anv_memory_heap
*mem_heap
=
3443 &pdevice
->memory
.heaps
[mem_type
->heapIndex
];
3445 uint64_t mem_heap_used
= p_atomic_read(&mem_heap
->used
);
3446 if (mem_heap_used
+ aligned_alloc_size
> mem_heap
->size
)
3447 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3449 mem
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*mem
), 8,
3450 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3452 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3454 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
3455 vk_object_base_init(&device
->vk
, &mem
->base
, VK_OBJECT_TYPE_DEVICE_MEMORY
);
3456 mem
->type
= mem_type
;
3460 mem
->host_ptr
= NULL
;
3462 enum anv_bo_alloc_flags alloc_flags
= 0;
3464 const VkExportMemoryAllocateInfo
*export_info
= NULL
;
3465 const VkImportAndroidHardwareBufferInfoANDROID
*ahw_import_info
= NULL
;
3466 const VkImportMemoryFdInfoKHR
*fd_info
= NULL
;
3467 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
= NULL
;
3468 const VkMemoryDedicatedAllocateInfo
*dedicated_info
= NULL
;
3469 VkMemoryAllocateFlags vk_flags
= 0;
3470 uint64_t client_address
= 0;
3472 vk_foreach_struct_const(ext
, pAllocateInfo
->pNext
) {
3473 switch (ext
->sType
) {
3474 case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO
:
3475 export_info
= (void *)ext
;
3478 case VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
:
3479 ahw_import_info
= (void *)ext
;
3482 case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR
:
3483 fd_info
= (void *)ext
;
3486 case VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT
:
3487 host_ptr_info
= (void *)ext
;
3490 case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO
: {
3491 const VkMemoryAllocateFlagsInfo
*flags_info
= (void *)ext
;
3492 vk_flags
= flags_info
->flags
;
3496 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO
:
3497 dedicated_info
= (void *)ext
;
3500 case VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO_KHR
: {
3501 const VkMemoryOpaqueCaptureAddressAllocateInfoKHR
*addr_info
=
3502 (const VkMemoryOpaqueCaptureAddressAllocateInfoKHR
*)ext
;
3503 client_address
= addr_info
->opaqueCaptureAddress
;
3508 anv_debug_ignored_stype(ext
->sType
);
3513 /* By default, we want all VkDeviceMemory objects to support CCS */
3514 if (device
->physical
->has_implicit_ccs
)
3515 alloc_flags
|= ANV_BO_ALLOC_IMPLICIT_CCS
;
3517 if (vk_flags
& VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR
)
3518 alloc_flags
|= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS
;
3520 if ((export_info
&& export_info
->handleTypes
) ||
3521 (fd_info
&& fd_info
->handleType
) ||
3522 (host_ptr_info
&& host_ptr_info
->handleType
)) {
3523 /* Anything imported or exported is EXTERNAL */
3524 alloc_flags
|= ANV_BO_ALLOC_EXTERNAL
;
3526 /* We can't have implicit CCS on external memory with an AUX-table.
3527 * Doing so would require us to sync the aux tables across processes
3528 * which is impractical.
3530 if (device
->info
.has_aux_map
)
3531 alloc_flags
&= ~ANV_BO_ALLOC_IMPLICIT_CCS
;
3534 /* Check if we need to support Android HW buffer export. If so,
3535 * create AHardwareBuffer and import memory from it.
3537 bool android_export
= false;
3538 if (export_info
&& export_info
->handleTypes
&
3539 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)
3540 android_export
= true;
3542 if (ahw_import_info
) {
3543 result
= anv_import_ahw_memory(_device
, mem
, ahw_import_info
);
3544 if (result
!= VK_SUCCESS
)
3548 } else if (android_export
) {
3549 result
= anv_create_ahw_memory(_device
, mem
, pAllocateInfo
);
3550 if (result
!= VK_SUCCESS
)
3553 const VkImportAndroidHardwareBufferInfoANDROID import_info
= {
3556 result
= anv_import_ahw_memory(_device
, mem
, &import_info
);
3557 if (result
!= VK_SUCCESS
)
3563 /* The Vulkan spec permits handleType to be 0, in which case the struct is
3566 if (fd_info
&& fd_info
->handleType
) {
3567 /* At the moment, we support only the below handle types. */
3568 assert(fd_info
->handleType
==
3569 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3570 fd_info
->handleType
==
3571 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3573 result
= anv_device_import_bo(device
, fd_info
->fd
, alloc_flags
,
3574 client_address
, &mem
->bo
);
3575 if (result
!= VK_SUCCESS
)
3578 /* For security purposes, we reject importing the bo if it's smaller
3579 * than the requested allocation size. This prevents a malicious client
3580 * from passing a buffer to a trusted client, lying about the size, and
3581 * telling the trusted client to try and texture from an image that goes
3582 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
3583 * in the trusted client. The trusted client can protect itself against
3584 * this sort of attack but only if it can trust the buffer size.
3586 if (mem
->bo
->size
< aligned_alloc_size
) {
3587 result
= vk_errorf(device
, device
, VK_ERROR_INVALID_EXTERNAL_HANDLE
,
3588 "aligned allocationSize too large for "
3589 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: "
3590 "%"PRIu64
"B > %"PRIu64
"B",
3591 aligned_alloc_size
, mem
->bo
->size
);
3592 anv_device_release_bo(device
, mem
->bo
);
3596 /* From the Vulkan spec:
3598 * "Importing memory from a file descriptor transfers ownership of
3599 * the file descriptor from the application to the Vulkan
3600 * implementation. The application must not perform any operations on
3601 * the file descriptor after a successful import."
3603 * If the import fails, we leave the file descriptor open.
3609 if (host_ptr_info
&& host_ptr_info
->handleType
) {
3610 if (host_ptr_info
->handleType
==
3611 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT
) {
3612 result
= vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3616 assert(host_ptr_info
->handleType
==
3617 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3619 result
= anv_device_import_bo_from_host_ptr(device
,
3620 host_ptr_info
->pHostPointer
,
3621 pAllocateInfo
->allocationSize
,
3625 if (result
!= VK_SUCCESS
)
3628 mem
->host_ptr
= host_ptr_info
->pHostPointer
;
3632 /* Regular allocate (not importing memory). */
3634 result
= anv_device_alloc_bo(device
, pAllocateInfo
->allocationSize
,
3635 alloc_flags
, client_address
, &mem
->bo
);
3636 if (result
!= VK_SUCCESS
)
3639 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
3640 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
3642 /* Some legacy (non-modifiers) consumers need the tiling to be set on
3643 * the BO. In this case, we have a dedicated allocation.
3645 if (image
->needs_set_tiling
) {
3646 const uint32_t i915_tiling
=
3647 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
3648 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
3649 image
->planes
[0].surface
.isl
.row_pitch_B
,
3652 anv_device_release_bo(device
, mem
->bo
);
3653 result
= vk_errorf(device
, device
, VK_ERROR_OUT_OF_DEVICE_MEMORY
,
3654 "failed to set BO tiling: %m");
3661 mem_heap_used
= p_atomic_add_return(&mem_heap
->used
, mem
->bo
->size
);
3662 if (mem_heap_used
> mem_heap
->size
) {
3663 p_atomic_add(&mem_heap
->used
, -mem
->bo
->size
);
3664 anv_device_release_bo(device
, mem
->bo
);
3665 result
= vk_errorf(device
, device
, VK_ERROR_OUT_OF_DEVICE_MEMORY
,
3666 "Out of heap memory");
3670 pthread_mutex_lock(&device
->mutex
);
3671 list_addtail(&mem
->link
, &device
->memory_objects
);
3672 pthread_mutex_unlock(&device
->mutex
);
3674 *pMem
= anv_device_memory_to_handle(mem
);
3679 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);
3684 VkResult
anv_GetMemoryFdKHR(
3686 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
3689 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
3690 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
3692 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3694 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3695 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3697 return anv_device_export_bo(dev
, mem
->bo
, pFd
);
3700 VkResult
anv_GetMemoryFdPropertiesKHR(
3702 VkExternalMemoryHandleTypeFlagBits handleType
,
3704 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
3706 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3708 switch (handleType
) {
3709 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
3710 /* dma-buf can be imported as any memory type */
3711 pMemoryFdProperties
->memoryTypeBits
=
3712 (1 << device
->physical
->memory
.type_count
) - 1;
3716 /* The valid usage section for this function says:
3718 * "handleType must not be one of the handle types defined as
3721 * So opaque handle types fall into the default "unsupported" case.
3723 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3727 VkResult
anv_GetMemoryHostPointerPropertiesEXT(
3729 VkExternalMemoryHandleTypeFlagBits handleType
,
3730 const void* pHostPointer
,
3731 VkMemoryHostPointerPropertiesEXT
* pMemoryHostPointerProperties
)
3733 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3735 assert(pMemoryHostPointerProperties
->sType
==
3736 VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT
);
3738 switch (handleType
) {
3739 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
3740 /* Host memory can be imported as any memory type. */
3741 pMemoryHostPointerProperties
->memoryTypeBits
=
3742 (1ull << device
->physical
->memory
.type_count
) - 1;
3747 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3751 void anv_FreeMemory(
3753 VkDeviceMemory _mem
,
3754 const VkAllocationCallbacks
* pAllocator
)
3756 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3757 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
3762 pthread_mutex_lock(&device
->mutex
);
3763 list_del(&mem
->link
);
3764 pthread_mutex_unlock(&device
->mutex
);
3767 anv_UnmapMemory(_device
, _mem
);
3769 p_atomic_add(&device
->physical
->memory
.heaps
[mem
->type
->heapIndex
].used
,
3772 anv_device_release_bo(device
, mem
->bo
);
3774 #if defined(ANDROID) && ANDROID_API_LEVEL >= 26
3776 AHardwareBuffer_release(mem
->ahw
);
3779 vk_object_base_finish(&mem
->base
);
3780 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);
3783 VkResult
anv_MapMemory(
3785 VkDeviceMemory _memory
,
3786 VkDeviceSize offset
,
3788 VkMemoryMapFlags flags
,
3791 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3792 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3799 if (mem
->host_ptr
) {
3800 *ppData
= mem
->host_ptr
+ offset
;
3804 if (size
== VK_WHOLE_SIZE
)
3805 size
= mem
->bo
->size
- offset
;
3807 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
3809 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
3810 * assert(size != 0);
3811 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
3812 * equal to the size of the memory minus offset
3815 assert(offset
+ size
<= mem
->bo
->size
);
3817 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
3818 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
3819 * at a time is valid. We could just mmap up front and return an offset
3820 * pointer here, but that may exhaust virtual memory on 32 bit
3823 uint32_t gem_flags
= 0;
3825 if (!device
->info
.has_llc
&&
3826 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
3827 gem_flags
|= I915_MMAP_WC
;
3829 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
3830 uint64_t map_offset
;
3831 if (!device
->physical
->has_mmap_offset
)
3832 map_offset
= offset
& ~4095ull;
3835 assert(offset
>= map_offset
);
3836 uint64_t map_size
= (offset
+ size
) - map_offset
;
3838 /* Let's map whole pages */
3839 map_size
= align_u64(map_size
, 4096);
3841 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
3842 map_offset
, map_size
, gem_flags
);
3843 if (map
== MAP_FAILED
)
3844 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
3847 mem
->map_size
= map_size
;
3849 *ppData
= mem
->map
+ (offset
- map_offset
);
3854 void anv_UnmapMemory(
3856 VkDeviceMemory _memory
)
3858 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3859 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3861 if (mem
== NULL
|| mem
->host_ptr
)
3864 anv_gem_munmap(device
, mem
->map
, mem
->map_size
);
3871 clflush_mapped_ranges(struct anv_device
*device
,
3873 const VkMappedMemoryRange
*ranges
)
3875 for (uint32_t i
= 0; i
< count
; i
++) {
3876 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
3877 if (ranges
[i
].offset
>= mem
->map_size
)
3880 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
3881 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
3885 VkResult
anv_FlushMappedMemoryRanges(
3887 uint32_t memoryRangeCount
,
3888 const VkMappedMemoryRange
* pMemoryRanges
)
3890 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3892 if (device
->info
.has_llc
)
3895 /* Make sure the writes we're flushing have landed. */
3896 __builtin_ia32_mfence();
3898 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3903 VkResult
anv_InvalidateMappedMemoryRanges(
3905 uint32_t memoryRangeCount
,
3906 const VkMappedMemoryRange
* pMemoryRanges
)
3908 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3910 if (device
->info
.has_llc
)
3913 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3915 /* Make sure no reads get moved up above the invalidate. */
3916 __builtin_ia32_mfence();
3921 void anv_GetBufferMemoryRequirements(
3924 VkMemoryRequirements
* pMemoryRequirements
)
3926 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3927 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3929 /* The Vulkan spec (git aaed022) says:
3931 * memoryTypeBits is a bitfield and contains one bit set for every
3932 * supported memory type for the resource. The bit `1<<i` is set if and
3933 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3934 * structure for the physical device is supported.
3936 uint32_t memory_types
= (1ull << device
->physical
->memory
.type_count
) - 1;
3938 /* Base alignment requirement of a cache line */
3939 uint32_t alignment
= 16;
3941 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
3942 alignment
= MAX2(alignment
, ANV_UBO_ALIGNMENT
);
3944 pMemoryRequirements
->size
= buffer
->size
;
3945 pMemoryRequirements
->alignment
= alignment
;
3947 /* Storage and Uniform buffers should have their size aligned to
3948 * 32-bits to avoid boundary checks when last DWord is not complete.
3949 * This would ensure that not internal padding would be needed for
3952 if (device
->robust_buffer_access
&&
3953 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
3954 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
3955 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
3957 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3960 void anv_GetBufferMemoryRequirements2(
3962 const VkBufferMemoryRequirementsInfo2
* pInfo
,
3963 VkMemoryRequirements2
* pMemoryRequirements
)
3965 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
3966 &pMemoryRequirements
->memoryRequirements
);
3968 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3969 switch (ext
->sType
) {
3970 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3971 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
3972 requirements
->prefersDedicatedAllocation
= false;
3973 requirements
->requiresDedicatedAllocation
= false;
3978 anv_debug_ignored_stype(ext
->sType
);
3984 void anv_GetImageMemoryRequirements(
3987 VkMemoryRequirements
* pMemoryRequirements
)
3989 ANV_FROM_HANDLE(anv_image
, image
, _image
);
3990 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3992 /* The Vulkan spec (git aaed022) says:
3994 * memoryTypeBits is a bitfield and contains one bit set for every
3995 * supported memory type for the resource. The bit `1<<i` is set if and
3996 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3997 * structure for the physical device is supported.
3999 * All types are currently supported for images.
4001 uint32_t memory_types
= (1ull << device
->physical
->memory
.type_count
) - 1;
4003 pMemoryRequirements
->size
= image
->size
;
4004 pMemoryRequirements
->alignment
= image
->alignment
;
4005 pMemoryRequirements
->memoryTypeBits
= memory_types
;
4008 void anv_GetImageMemoryRequirements2(
4010 const VkImageMemoryRequirementsInfo2
* pInfo
,
4011 VkMemoryRequirements2
* pMemoryRequirements
)
4013 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4014 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
4016 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
4017 &pMemoryRequirements
->memoryRequirements
);
4019 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
4020 switch (ext
->sType
) {
4021 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
4022 const VkImagePlaneMemoryRequirementsInfo
*plane_reqs
=
4023 (const VkImagePlaneMemoryRequirementsInfo
*) ext
;
4024 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
4025 plane_reqs
->planeAspect
);
4027 assert(image
->planes
[plane
].offset
== 0);
4029 /* The Vulkan spec (git aaed022) says:
4031 * memoryTypeBits is a bitfield and contains one bit set for every
4032 * supported memory type for the resource. The bit `1<<i` is set
4033 * if and only if the memory type `i` in the
4034 * VkPhysicalDeviceMemoryProperties structure for the physical
4035 * device is supported.
4037 * All types are currently supported for images.
4039 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
4040 (1ull << device
->physical
->memory
.type_count
) - 1;
4042 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
4043 pMemoryRequirements
->memoryRequirements
.alignment
=
4044 image
->planes
[plane
].alignment
;
4049 anv_debug_ignored_stype(ext
->sType
);
4054 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
4055 switch (ext
->sType
) {
4056 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
4057 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
4058 if (image
->needs_set_tiling
|| image
->external_format
) {
4059 /* If we need to set the tiling for external consumers, we need a
4060 * dedicated allocation.
4062 * See also anv_AllocateMemory.
4064 requirements
->prefersDedicatedAllocation
= true;
4065 requirements
->requiresDedicatedAllocation
= true;
4067 requirements
->prefersDedicatedAllocation
= false;
4068 requirements
->requiresDedicatedAllocation
= false;
4074 anv_debug_ignored_stype(ext
->sType
);
4080 void anv_GetImageSparseMemoryRequirements(
4083 uint32_t* pSparseMemoryRequirementCount
,
4084 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
4086 *pSparseMemoryRequirementCount
= 0;
4089 void anv_GetImageSparseMemoryRequirements2(
4091 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
4092 uint32_t* pSparseMemoryRequirementCount
,
4093 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
4095 *pSparseMemoryRequirementCount
= 0;
4098 void anv_GetDeviceMemoryCommitment(
4100 VkDeviceMemory memory
,
4101 VkDeviceSize
* pCommittedMemoryInBytes
)
4103 *pCommittedMemoryInBytes
= 0;
4107 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
4109 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
4110 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
4112 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
4115 buffer
->address
= (struct anv_address
) {
4117 .offset
= pBindInfo
->memoryOffset
,
4120 buffer
->address
= ANV_NULL_ADDRESS
;
4124 VkResult
anv_BindBufferMemory(
4127 VkDeviceMemory memory
,
4128 VkDeviceSize memoryOffset
)
4130 anv_bind_buffer_memory(
4131 &(VkBindBufferMemoryInfo
) {
4132 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
4135 .memoryOffset
= memoryOffset
,
4141 VkResult
anv_BindBufferMemory2(
4143 uint32_t bindInfoCount
,
4144 const VkBindBufferMemoryInfo
* pBindInfos
)
4146 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
4147 anv_bind_buffer_memory(&pBindInfos
[i
]);
4152 VkResult
anv_QueueBindSparse(
4154 uint32_t bindInfoCount
,
4155 const VkBindSparseInfo
* pBindInfo
,
4158 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
4159 if (anv_device_is_lost(queue
->device
))
4160 return VK_ERROR_DEVICE_LOST
;
4162 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
4167 VkResult
anv_CreateEvent(
4169 const VkEventCreateInfo
* pCreateInfo
,
4170 const VkAllocationCallbacks
* pAllocator
,
4173 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4174 struct anv_event
*event
;
4176 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
4178 event
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*event
), 8,
4179 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4181 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4183 vk_object_base_init(&device
->vk
, &event
->base
, VK_OBJECT_TYPE_EVENT
);
4184 event
->state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
4185 sizeof(uint64_t), 8);
4186 *(uint64_t *)event
->state
.map
= VK_EVENT_RESET
;
4188 *pEvent
= anv_event_to_handle(event
);
4193 void anv_DestroyEvent(
4196 const VkAllocationCallbacks
* pAllocator
)
4198 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4199 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4204 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
4206 vk_object_base_finish(&event
->base
);
4207 vk_free2(&device
->vk
.alloc
, pAllocator
, event
);
4210 VkResult
anv_GetEventStatus(
4214 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4215 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4217 if (anv_device_is_lost(device
))
4218 return VK_ERROR_DEVICE_LOST
;
4220 return *(uint64_t *)event
->state
.map
;
4223 VkResult
anv_SetEvent(
4227 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4229 *(uint64_t *)event
->state
.map
= VK_EVENT_SET
;
4234 VkResult
anv_ResetEvent(
4238 ANV_FROM_HANDLE(anv_event
, event
, _event
);
4240 *(uint64_t *)event
->state
.map
= VK_EVENT_RESET
;
4247 VkResult
anv_CreateBuffer(
4249 const VkBufferCreateInfo
* pCreateInfo
,
4250 const VkAllocationCallbacks
* pAllocator
,
4253 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4254 struct anv_buffer
*buffer
;
4256 /* Don't allow creating buffers bigger than our address space. The real
4257 * issue here is that we may align up the buffer size and we don't want
4258 * doing so to cause roll-over. However, no one has any business
4259 * allocating a buffer larger than our GTT size.
4261 if (pCreateInfo
->size
> device
->physical
->gtt_size
)
4262 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4264 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4266 buffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*buffer
), 8,
4267 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4269 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4271 vk_object_base_init(&device
->vk
, &buffer
->base
, VK_OBJECT_TYPE_BUFFER
);
4272 buffer
->size
= pCreateInfo
->size
;
4273 buffer
->usage
= pCreateInfo
->usage
;
4274 buffer
->address
= ANV_NULL_ADDRESS
;
4276 *pBuffer
= anv_buffer_to_handle(buffer
);
4281 void anv_DestroyBuffer(
4284 const VkAllocationCallbacks
* pAllocator
)
4286 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4287 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
4292 vk_object_base_finish(&buffer
->base
);
4293 vk_free2(&device
->vk
.alloc
, pAllocator
, buffer
);
4296 VkDeviceAddress
anv_GetBufferDeviceAddress(
4298 const VkBufferDeviceAddressInfoKHR
* pInfo
)
4300 ANV_FROM_HANDLE(anv_buffer
, buffer
, pInfo
->buffer
);
4302 assert(!anv_address_is_null(buffer
->address
));
4303 assert(buffer
->address
.bo
->flags
& EXEC_OBJECT_PINNED
);
4305 return anv_address_physical(buffer
->address
);
4308 uint64_t anv_GetBufferOpaqueCaptureAddress(
4310 const VkBufferDeviceAddressInfoKHR
* pInfo
)
4315 uint64_t anv_GetDeviceMemoryOpaqueCaptureAddress(
4317 const VkDeviceMemoryOpaqueCaptureAddressInfoKHR
* pInfo
)
4319 ANV_FROM_HANDLE(anv_device_memory
, memory
, pInfo
->memory
);
4321 assert(memory
->bo
->flags
& EXEC_OBJECT_PINNED
);
4322 assert(memory
->bo
->has_client_visible_address
);
4324 return gen_48b_address(memory
->bo
->offset
);
4328 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
4329 enum isl_format format
,
4330 struct anv_address address
,
4331 uint32_t range
, uint32_t stride
)
4333 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
4334 .address
= anv_address_physical(address
),
4335 .mocs
= device
->isl_dev
.mocs
.internal
,
4338 .swizzle
= ISL_SWIZZLE_IDENTITY
,
4339 .stride_B
= stride
);
4342 void anv_DestroySampler(
4345 const VkAllocationCallbacks
* pAllocator
)
4347 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4348 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
4353 if (sampler
->bindless_state
.map
) {
4354 anv_state_pool_free(&device
->dynamic_state_pool
,
4355 sampler
->bindless_state
);
4358 if (sampler
->custom_border_color
.map
) {
4359 anv_state_reserved_pool_free(&device
->custom_border_colors
,
4360 sampler
->custom_border_color
);
4363 vk_object_base_finish(&sampler
->base
);
4364 vk_free2(&device
->vk
.alloc
, pAllocator
, sampler
);
4367 VkResult
anv_CreateFramebuffer(
4369 const VkFramebufferCreateInfo
* pCreateInfo
,
4370 const VkAllocationCallbacks
* pAllocator
,
4371 VkFramebuffer
* pFramebuffer
)
4373 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4374 struct anv_framebuffer
*framebuffer
;
4376 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4378 size_t size
= sizeof(*framebuffer
);
4380 /* VK_KHR_imageless_framebuffer extension says:
4382 * If flags includes VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR,
4383 * parameter pAttachments is ignored.
4385 if (!(pCreateInfo
->flags
& VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR
)) {
4386 size
+= sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
4387 framebuffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
4388 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4389 if (framebuffer
== NULL
)
4390 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4392 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4393 ANV_FROM_HANDLE(anv_image_view
, iview
, pCreateInfo
->pAttachments
[i
]);
4394 framebuffer
->attachments
[i
] = iview
;
4396 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4398 framebuffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
4399 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4400 if (framebuffer
== NULL
)
4401 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4403 framebuffer
->attachment_count
= 0;
4406 vk_object_base_init(&device
->vk
, &framebuffer
->base
,
4407 VK_OBJECT_TYPE_FRAMEBUFFER
);
4409 framebuffer
->width
= pCreateInfo
->width
;
4410 framebuffer
->height
= pCreateInfo
->height
;
4411 framebuffer
->layers
= pCreateInfo
->layers
;
4413 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
4418 void anv_DestroyFramebuffer(
4421 const VkAllocationCallbacks
* pAllocator
)
4423 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4424 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
4429 vk_object_base_finish(&fb
->base
);
4430 vk_free2(&device
->vk
.alloc
, pAllocator
, fb
);
4433 static const VkTimeDomainEXT anv_time_domains
[] = {
4434 VK_TIME_DOMAIN_DEVICE_EXT
,
4435 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
4436 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
4439 VkResult
anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
4440 VkPhysicalDevice physicalDevice
,
4441 uint32_t *pTimeDomainCount
,
4442 VkTimeDomainEXT
*pTimeDomains
)
4445 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
4447 for (d
= 0; d
< ARRAY_SIZE(anv_time_domains
); d
++) {
4448 vk_outarray_append(&out
, i
) {
4449 *i
= anv_time_domains
[d
];
4453 return vk_outarray_status(&out
);
4457 anv_clock_gettime(clockid_t clock_id
)
4459 struct timespec current
;
4462 ret
= clock_gettime(clock_id
, ¤t
);
4463 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
4464 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
4468 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
4471 VkResult
anv_GetCalibratedTimestampsEXT(
4473 uint32_t timestampCount
,
4474 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
4475 uint64_t *pTimestamps
,
4476 uint64_t *pMaxDeviation
)
4478 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4479 uint64_t timestamp_frequency
= device
->info
.timestamp_frequency
;
4482 uint64_t begin
, end
;
4483 uint64_t max_clock_period
= 0;
4485 begin
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
4487 for (d
= 0; d
< timestampCount
; d
++) {
4488 switch (pTimestampInfos
[d
].timeDomain
) {
4489 case VK_TIME_DOMAIN_DEVICE_EXT
:
4490 ret
= anv_gem_reg_read(device
->fd
, TIMESTAMP
| I915_REG_READ_8B_WA
,
4494 return anv_device_set_lost(device
, "Failed to read the TIMESTAMP "
4497 uint64_t device_period
= DIV_ROUND_UP(1000000000, timestamp_frequency
);
4498 max_clock_period
= MAX2(max_clock_period
, device_period
);
4500 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
4501 pTimestamps
[d
] = anv_clock_gettime(CLOCK_MONOTONIC
);
4502 max_clock_period
= MAX2(max_clock_period
, 1);
4505 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
4506 pTimestamps
[d
] = begin
;
4514 end
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
4517 * The maximum deviation is the sum of the interval over which we
4518 * perform the sampling and the maximum period of any sampled
4519 * clock. That's because the maximum skew between any two sampled
4520 * clock edges is when the sampled clock with the largest period is
4521 * sampled at the end of that period but right at the beginning of the
4522 * sampling interval and some other clock is sampled right at the
4523 * begining of its sampling period and right at the end of the
4524 * sampling interval. Let's assume the GPU has the longest clock
4525 * period and that the application is sampling GPU and monotonic:
4528 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
4529 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
4533 * GPU -----_____-----_____-----_____-----_____
4536 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
4537 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
4539 * Interval <----------------->
4540 * Deviation <-------------------------->
4544 * m = read(monotonic) 2
4547 * We round the sample interval up by one tick to cover sampling error
4548 * in the interval clock
4551 uint64_t sample_interval
= end
- begin
+ 1;
4553 *pMaxDeviation
= sample_interval
+ max_clock_period
;
4558 /* vk_icd.h does not declare this function, so we declare it here to
4559 * suppress Wmissing-prototypes.
4561 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4562 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
4564 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4565 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
4567 /* For the full details on loader interface versioning, see
4568 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4569 * What follows is a condensed summary, to help you navigate the large and
4570 * confusing official doc.
4572 * - Loader interface v0 is incompatible with later versions. We don't
4575 * - In loader interface v1:
4576 * - The first ICD entrypoint called by the loader is
4577 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4579 * - The ICD must statically expose no other Vulkan symbol unless it is
4580 * linked with -Bsymbolic.
4581 * - Each dispatchable Vulkan handle created by the ICD must be
4582 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4583 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4584 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4585 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4586 * such loader-managed surfaces.
4588 * - Loader interface v2 differs from v1 in:
4589 * - The first ICD entrypoint called by the loader is
4590 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4591 * statically expose this entrypoint.
4593 * - Loader interface v3 differs from v2 in:
4594 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4595 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4596 * because the loader no longer does so.
4598 * - Loader interface v4 differs from v3 in:
4599 * - The ICD must implement vk_icdGetPhysicalDeviceProcAddr().
4601 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
4605 VkResult
anv_CreatePrivateDataSlotEXT(
4607 const VkPrivateDataSlotCreateInfoEXT
* pCreateInfo
,
4608 const VkAllocationCallbacks
* pAllocator
,
4609 VkPrivateDataSlotEXT
* pPrivateDataSlot
)
4611 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4612 return vk_private_data_slot_create(&device
->vk
, pCreateInfo
, pAllocator
,
4616 void anv_DestroyPrivateDataSlotEXT(
4618 VkPrivateDataSlotEXT privateDataSlot
,
4619 const VkAllocationCallbacks
* pAllocator
)
4621 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4622 vk_private_data_slot_destroy(&device
->vk
, privateDataSlot
, pAllocator
);
4625 VkResult
anv_SetPrivateDataEXT(
4627 VkObjectType objectType
,
4628 uint64_t objectHandle
,
4629 VkPrivateDataSlotEXT privateDataSlot
,
4632 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4633 return vk_object_base_set_private_data(&device
->vk
,
4634 objectType
, objectHandle
,
4635 privateDataSlot
, data
);
4638 void anv_GetPrivateDataEXT(
4640 VkObjectType objectType
,
4641 uint64_t objectHandle
,
4642 VkPrivateDataSlotEXT privateDataSlot
,
4645 ANV_FROM_HANDLE(anv_device
, device
, _device
);
4646 vk_object_base_get_private_data(&device
->vk
,
4647 objectType
, objectHandle
,
4648 privateDataSlot
, pData
);