2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include <sys/sysinfo.h>
32 #include "drm-uapi/drm_fourcc.h"
34 #include "anv_private.h"
35 #include "util/strtod.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/xmlpool.h"
46 #include "common/gen_defines.h"
47 #include "compiler/glsl_types.h"
49 #include "genxml/gen7_pack.h"
51 static const char anv_dri_options_xml
[] =
53 DRI_CONF_SECTION_PERFORMANCE
54 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
58 /* This is probably far to big but it reflects the max size used for messages
59 * in OpenGLs KHR_debug.
61 #define MAX_DEBUG_MESSAGE_LENGTH 4096
64 compiler_debug_log(void *data
, const char *fmt
, ...)
66 char str
[MAX_DEBUG_MESSAGE_LENGTH
];
67 struct anv_device
*device
= (struct anv_device
*)data
;
69 if (list_empty(&device
->instance
->debug_report_callbacks
.callbacks
))
74 (void) vsnprintf(str
, MAX_DEBUG_MESSAGE_LENGTH
, fmt
, args
);
77 vk_debug_report(&device
->instance
->debug_report_callbacks
,
78 VK_DEBUG_REPORT_DEBUG_BIT_EXT
,
79 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT
,
84 compiler_perf_log(void *data
, const char *fmt
, ...)
89 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
90 intel_logd_v(fmt
, args
);
96 anv_compute_heap_size(int fd
, uint64_t gtt_size
)
98 /* Query the total ram from the system */
102 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
104 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
105 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
107 uint64_t available_ram
;
108 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
109 available_ram
= total_ram
/ 2;
111 available_ram
= total_ram
* 3 / 4;
113 /* We also want to leave some padding for things we allocate in the driver,
114 * so don't go over 3/4 of the GTT either.
116 uint64_t available_gtt
= gtt_size
* 3 / 4;
118 return MIN2(available_ram
, available_gtt
);
122 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
125 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
127 /* If, for whatever reason, we can't actually get the GTT size from the
128 * kernel (too old?) fall back to the aperture size.
130 anv_perf_warn(NULL
, NULL
,
131 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
133 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
134 return vk_errorf(NULL
, NULL
, VK_ERROR_INITIALIZATION_FAILED
,
135 "failed to get aperture size: %m");
139 device
->supports_48bit_addresses
= (device
->info
.gen
>= 8) &&
140 gtt_size
> (4ULL << 30 /* GiB */);
142 uint64_t heap_size
= anv_compute_heap_size(fd
, gtt_size
);
144 if (heap_size
> (2ull << 30) && !device
->supports_48bit_addresses
) {
145 /* When running with an overridden PCI ID, we may get a GTT size from
146 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
147 * address support can still fail. Just clamp the address space size to
148 * 2 GiB if we don't have 48-bit support.
150 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
151 "not support for 48-bit addresses",
153 heap_size
= 2ull << 30;
156 if (heap_size
<= 3ull * (1ull << 30)) {
157 /* In this case, everything fits nicely into the 32-bit address space,
158 * so there's no need for supporting 48bit addresses on client-allocated
161 device
->memory
.heap_count
= 1;
162 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
163 .vma_start
= LOW_HEAP_MIN_ADDRESS
,
164 .vma_size
= LOW_HEAP_SIZE
,
166 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
167 .supports_48bit_addresses
= false,
170 /* Not everything will fit nicely into a 32-bit address space. In this
171 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
172 * larger 48-bit heap. If we're in this case, then we have a total heap
173 * size larger than 3GiB which most likely means they have 8 GiB of
174 * video memory and so carving off 1 GiB for the 32-bit heap should be
177 const uint64_t heap_size_32bit
= 1ull << 30;
178 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
180 assert(device
->supports_48bit_addresses
);
182 device
->memory
.heap_count
= 2;
183 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
184 .vma_start
= HIGH_HEAP_MIN_ADDRESS
,
185 /* Leave the last 4GiB out of the high vma range, so that no state
186 * base address + size can overflow 48 bits. For more information see
187 * the comment about Wa32bitGeneralStateOffset in anv_allocator.c
189 .vma_size
= gtt_size
- (1ull << 32) - HIGH_HEAP_MIN_ADDRESS
,
190 .size
= heap_size_48bit
,
191 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
192 .supports_48bit_addresses
= true,
194 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
195 .vma_start
= LOW_HEAP_MIN_ADDRESS
,
196 .vma_size
= LOW_HEAP_SIZE
,
197 .size
= heap_size_32bit
,
198 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
199 .supports_48bit_addresses
= false,
203 uint32_t type_count
= 0;
204 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
205 uint32_t valid_buffer_usage
= ~0;
207 /* There appears to be a hardware issue in the VF cache where it only
208 * considers the bottom 32 bits of memory addresses. If you happen to
209 * have two vertex buffers which get placed exactly 4 GiB apart and use
210 * them in back-to-back draw calls, you can get collisions. In order to
211 * solve this problem, we require vertex and index buffers be bound to
212 * memory allocated out of the 32-bit heap.
214 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
215 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
216 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
219 if (device
->info
.has_llc
) {
220 /* Big core GPUs share LLC with the CPU and thus one memory type can be
221 * both cached and coherent at the same time.
223 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
224 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
225 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
226 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
227 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
229 .valid_buffer_usage
= valid_buffer_usage
,
232 /* The spec requires that we expose a host-visible, coherent memory
233 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
234 * to give the application a choice between cached, but not coherent and
235 * coherent but uncached (WC though).
237 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
238 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
239 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
240 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
242 .valid_buffer_usage
= valid_buffer_usage
,
244 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
245 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
246 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
247 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
249 .valid_buffer_usage
= valid_buffer_usage
,
253 device
->memory
.type_count
= type_count
;
259 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
261 const struct build_id_note
*note
=
262 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
264 return vk_errorf(device
->instance
, device
,
265 VK_ERROR_INITIALIZATION_FAILED
,
266 "Failed to find build-id");
269 unsigned build_id_len
= build_id_length(note
);
270 if (build_id_len
< 20) {
271 return vk_errorf(device
->instance
, device
,
272 VK_ERROR_INITIALIZATION_FAILED
,
273 "build-id too short. It needs to be a SHA");
276 memcpy(device
->driver_build_sha1
, build_id_data(note
), 20);
278 struct mesa_sha1 sha1_ctx
;
280 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
282 /* The pipeline cache UUID is used for determining when a pipeline cache is
283 * invalid. It needs both a driver build and the PCI ID of the device.
285 _mesa_sha1_init(&sha1_ctx
);
286 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
287 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
288 sizeof(device
->chipset_id
));
289 _mesa_sha1_update(&sha1_ctx
, &device
->always_use_bindless
,
290 sizeof(device
->always_use_bindless
));
291 _mesa_sha1_update(&sha1_ctx
, &device
->has_a64_buffer_access
,
292 sizeof(device
->has_a64_buffer_access
));
293 _mesa_sha1_update(&sha1_ctx
, &device
->has_bindless_images
,
294 sizeof(device
->has_bindless_images
));
295 _mesa_sha1_update(&sha1_ctx
, &device
->has_bindless_samplers
,
296 sizeof(device
->has_bindless_samplers
));
297 _mesa_sha1_final(&sha1_ctx
, sha1
);
298 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
300 /* The driver UUID is used for determining sharability of images and memory
301 * between two Vulkan instances in separate processes. People who want to
302 * share memory need to also check the device UUID (below) so all this
303 * needs to be is the build-id.
305 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
307 /* The device UUID uniquely identifies the given device within the machine.
308 * Since we never have more than one device, this doesn't need to be a real
309 * UUID. However, on the off-chance that someone tries to use this to
310 * cache pre-tiled images or something of the like, we use the PCI ID and
311 * some bits of ISL info to ensure that this is safe.
313 _mesa_sha1_init(&sha1_ctx
);
314 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
315 sizeof(device
->chipset_id
));
316 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
317 sizeof(device
->isl_dev
.has_bit6_swizzling
));
318 _mesa_sha1_final(&sha1_ctx
, sha1
);
319 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
325 anv_physical_device_init_disk_cache(struct anv_physical_device
*device
)
327 #ifdef ENABLE_SHADER_CACHE
329 ASSERTED
int len
= snprintf(renderer
, sizeof(renderer
), "anv_%04x",
331 assert(len
== sizeof(renderer
) - 2);
334 _mesa_sha1_format(timestamp
, device
->driver_build_sha1
);
336 const uint64_t driver_flags
=
337 brw_get_compiler_config_value(device
->compiler
);
338 device
->disk_cache
= disk_cache_create(renderer
, timestamp
, driver_flags
);
340 device
->disk_cache
= NULL
;
345 anv_physical_device_free_disk_cache(struct anv_physical_device
*device
)
347 #ifdef ENABLE_SHADER_CACHE
348 if (device
->disk_cache
)
349 disk_cache_destroy(device
->disk_cache
);
351 assert(device
->disk_cache
== NULL
);
356 get_available_system_memory()
358 char *meminfo
= os_read_file("/proc/meminfo");
362 char *str
= strstr(meminfo
, "MemAvailable:");
368 uint64_t kb_mem_available
;
369 if (sscanf(str
, "MemAvailable: %" PRIx64
, &kb_mem_available
) == 1) {
371 return kb_mem_available
<< 10;
379 anv_physical_device_init(struct anv_physical_device
*device
,
380 struct anv_instance
*instance
,
381 drmDevicePtr drm_device
)
383 const char *primary_path
= drm_device
->nodes
[DRM_NODE_PRIMARY
];
384 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
389 brw_process_intel_debug_variable();
391 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
393 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
395 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
396 device
->instance
= instance
;
398 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
399 snprintf(device
->path
, ARRAY_SIZE(device
->path
), "%s", path
);
401 if (!gen_get_device_info_from_fd(fd
, &device
->info
)) {
402 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
405 device
->chipset_id
= device
->info
.chipset_id
;
406 device
->no_hw
= device
->info
.no_hw
;
408 if (getenv("INTEL_NO_HW") != NULL
)
409 device
->no_hw
= true;
411 device
->pci_info
.domain
= drm_device
->businfo
.pci
->domain
;
412 device
->pci_info
.bus
= drm_device
->businfo
.pci
->bus
;
413 device
->pci_info
.device
= drm_device
->businfo
.pci
->dev
;
414 device
->pci_info
.function
= drm_device
->businfo
.pci
->func
;
416 device
->name
= gen_get_device_name(device
->chipset_id
);
418 if (device
->info
.is_haswell
) {
419 intel_logw("Haswell Vulkan support is incomplete");
420 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
421 intel_logw("Ivy Bridge Vulkan support is incomplete");
422 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
423 intel_logw("Bay Trail Vulkan support is incomplete");
424 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 11) {
425 /* Gen8-11 fully supported */
426 } else if (device
->info
.gen
== 12) {
427 intel_logw("Vulkan is not yet fully supported on gen12");
429 result
= vk_errorf(device
->instance
, device
,
430 VK_ERROR_INCOMPATIBLE_DRIVER
,
431 "Vulkan not yet supported on %s", device
->name
);
435 device
->cmd_parser_version
= -1;
436 if (device
->info
.gen
== 7) {
437 device
->cmd_parser_version
=
438 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
439 if (device
->cmd_parser_version
== -1) {
440 result
= vk_errorf(device
->instance
, device
,
441 VK_ERROR_INITIALIZATION_FAILED
,
442 "failed to get command parser version");
447 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
448 result
= vk_errorf(device
->instance
, device
,
449 VK_ERROR_INITIALIZATION_FAILED
,
450 "kernel missing gem wait");
454 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
455 result
= vk_errorf(device
->instance
, device
,
456 VK_ERROR_INITIALIZATION_FAILED
,
457 "kernel missing execbuf2");
461 if (!device
->info
.has_llc
&&
462 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
463 result
= vk_errorf(device
->instance
, device
,
464 VK_ERROR_INITIALIZATION_FAILED
,
465 "kernel missing wc mmap");
469 result
= anv_physical_device_init_heaps(device
, fd
);
470 if (result
!= VK_SUCCESS
)
473 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
474 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
475 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
476 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
477 device
->has_syncobj_wait
= device
->has_syncobj
&&
478 anv_gem_supports_syncobj_wait(fd
);
479 device
->has_context_priority
= anv_gem_has_context_priority(fd
);
481 device
->use_softpin
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_SOFTPIN
)
482 && device
->supports_48bit_addresses
;
484 device
->has_context_isolation
=
485 anv_gem_get_param(fd
, I915_PARAM_HAS_CONTEXT_ISOLATION
);
487 device
->always_use_bindless
=
488 env_var_as_boolean("ANV_ALWAYS_BINDLESS", false);
490 /* We first got the A64 messages on broadwell and we can only use them if
491 * we can pass addresses directly into the shader which requires softpin.
493 device
->has_a64_buffer_access
= device
->info
.gen
>= 8 &&
496 /* We first get bindless image access on Skylake and we can only really do
497 * it if we don't have any relocations so we need softpin.
499 device
->has_bindless_images
= device
->info
.gen
>= 9 &&
502 /* We've had bindless samplers since Ivy Bridge (forever in Vulkan terms)
503 * because it's just a matter of setting the sampler address in the sample
504 * message header. However, we've not bothered to wire it up for vec4 so
505 * we leave it disabled on gen7.
507 device
->has_bindless_samplers
= device
->info
.gen
>= 8;
509 device
->has_mem_available
= get_available_system_memory() != 0;
511 /* Starting with Gen10, the timestamp frequency of the command streamer may
512 * vary from one part to another. We can query the value from the kernel.
514 if (device
->info
.gen
>= 10) {
515 int timestamp_frequency
=
516 anv_gem_get_param(fd
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
);
518 if (timestamp_frequency
< 0)
519 intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
521 device
->info
.timestamp_frequency
= timestamp_frequency
;
524 /* GENs prior to 8 do not support EU/Subslice info */
525 if (device
->info
.gen
>= 8) {
526 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
527 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
529 /* Without this information, we cannot get the right Braswell
530 * brandstrings, and we have to use conservative numbers for GPGPU on
531 * many platforms, but otherwise, things will just work.
533 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
534 intel_logw("Kernel 4.1 required to properly query GPU properties");
536 } else if (device
->info
.gen
== 7) {
537 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
540 if (device
->info
.is_cherryview
&&
541 device
->subslice_total
> 0 && device
->eu_total
> 0) {
542 /* Logical CS threads = EUs per subslice * num threads per EU */
543 uint32_t max_cs_threads
=
544 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
546 /* Fuse configurations may give more threads than expected, never less. */
547 if (max_cs_threads
> device
->info
.max_cs_threads
)
548 device
->info
.max_cs_threads
= max_cs_threads
;
551 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
552 if (device
->compiler
== NULL
) {
553 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
556 device
->compiler
->shader_debug_log
= compiler_debug_log
;
557 device
->compiler
->shader_perf_log
= compiler_perf_log
;
558 device
->compiler
->supports_pull_constants
= false;
559 device
->compiler
->constant_buffer_0_is_relative
=
560 device
->info
.gen
< 8 || !device
->has_context_isolation
;
561 device
->compiler
->supports_shader_constants
= true;
563 /* Broadwell PRM says:
565 * "Before Gen8, there was a historical configuration control field to
566 * swizzle address bit[6] for in X/Y tiling modes. This was set in three
567 * different places: TILECTL[1:0], ARB_MODE[5:4], and
568 * DISP_ARB_CTL[14:13].
570 * For Gen8 and subsequent generations, the swizzle fields are all
571 * reserved, and the CPU's memory controller performs all address
572 * swizzling modifications."
575 device
->info
.gen
< 8 && anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
577 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
579 result
= anv_physical_device_init_uuids(device
);
580 if (result
!= VK_SUCCESS
)
583 anv_physical_device_init_disk_cache(device
);
585 if (instance
->enabled_extensions
.KHR_display
) {
586 master_fd
= open(primary_path
, O_RDWR
| O_CLOEXEC
);
587 if (master_fd
>= 0) {
588 /* prod the device with a GETPARAM call which will fail if
589 * we don't have permission to even render on this device
591 if (anv_gem_get_param(master_fd
, I915_PARAM_CHIPSET_ID
) == 0) {
597 device
->master_fd
= master_fd
;
599 result
= anv_init_wsi(device
);
600 if (result
!= VK_SUCCESS
) {
601 ralloc_free(device
->compiler
);
602 anv_physical_device_free_disk_cache(device
);
606 anv_physical_device_get_supported_extensions(device
,
607 &device
->supported_extensions
);
610 device
->local_fd
= fd
;
622 anv_physical_device_finish(struct anv_physical_device
*device
)
624 anv_finish_wsi(device
);
625 anv_physical_device_free_disk_cache(device
);
626 ralloc_free(device
->compiler
);
627 close(device
->local_fd
);
628 if (device
->master_fd
>= 0)
629 close(device
->master_fd
);
633 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
634 VkSystemAllocationScope allocationScope
)
640 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
641 size_t align
, VkSystemAllocationScope allocationScope
)
643 return realloc(pOriginal
, size
);
647 default_free_func(void *pUserData
, void *pMemory
)
652 static const VkAllocationCallbacks default_alloc
= {
654 .pfnAllocation
= default_alloc_func
,
655 .pfnReallocation
= default_realloc_func
,
656 .pfnFree
= default_free_func
,
659 VkResult
anv_EnumerateInstanceExtensionProperties(
660 const char* pLayerName
,
661 uint32_t* pPropertyCount
,
662 VkExtensionProperties
* pProperties
)
664 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
666 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
667 if (anv_instance_extensions_supported
.extensions
[i
]) {
668 vk_outarray_append(&out
, prop
) {
669 *prop
= anv_instance_extensions
[i
];
674 return vk_outarray_status(&out
);
677 VkResult
anv_CreateInstance(
678 const VkInstanceCreateInfo
* pCreateInfo
,
679 const VkAllocationCallbacks
* pAllocator
,
680 VkInstance
* pInstance
)
682 struct anv_instance
*instance
;
685 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
687 struct anv_instance_extension_table enabled_extensions
= {};
688 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
690 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
691 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
692 anv_instance_extensions
[idx
].extensionName
) == 0)
696 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
697 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
699 if (!anv_instance_extensions_supported
.extensions
[idx
])
700 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
702 enabled_extensions
.extensions
[idx
] = true;
705 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
706 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
708 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
710 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
713 instance
->alloc
= *pAllocator
;
715 instance
->alloc
= default_alloc
;
717 instance
->app_info
= (struct anv_app_info
) { .api_version
= 0 };
718 if (pCreateInfo
->pApplicationInfo
) {
719 const VkApplicationInfo
*app
= pCreateInfo
->pApplicationInfo
;
721 instance
->app_info
.app_name
=
722 vk_strdup(&instance
->alloc
, app
->pApplicationName
,
723 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
724 instance
->app_info
.app_version
= app
->applicationVersion
;
726 instance
->app_info
.engine_name
=
727 vk_strdup(&instance
->alloc
, app
->pEngineName
,
728 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
729 instance
->app_info
.engine_version
= app
->engineVersion
;
731 instance
->app_info
.api_version
= app
->apiVersion
;
734 if (instance
->app_info
.api_version
== 0)
735 instance
->app_info
.api_version
= VK_API_VERSION_1_0
;
737 instance
->enabled_extensions
= enabled_extensions
;
739 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
740 /* Vulkan requires that entrypoints for extensions which have not been
741 * enabled must not be advertised.
743 if (!anv_instance_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
744 &instance
->enabled_extensions
)) {
745 instance
->dispatch
.entrypoints
[i
] = NULL
;
747 instance
->dispatch
.entrypoints
[i
] =
748 anv_instance_dispatch_table
.entrypoints
[i
];
752 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->device_dispatch
.entrypoints
); i
++) {
753 /* Vulkan requires that entrypoints for extensions which have not been
754 * enabled must not be advertised.
756 if (!anv_device_entrypoint_is_enabled(i
, instance
->app_info
.api_version
,
757 &instance
->enabled_extensions
, NULL
)) {
758 instance
->device_dispatch
.entrypoints
[i
] = NULL
;
760 instance
->device_dispatch
.entrypoints
[i
] =
761 anv_device_dispatch_table
.entrypoints
[i
];
765 instance
->physicalDeviceCount
= -1;
767 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
768 if (result
!= VK_SUCCESS
) {
769 vk_free2(&default_alloc
, pAllocator
, instance
);
770 return vk_error(result
);
773 instance
->pipeline_cache_enabled
=
774 env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true);
777 glsl_type_singleton_init_or_ref();
779 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
781 driParseOptionInfo(&instance
->available_dri_options
, anv_dri_options_xml
);
782 driParseConfigFiles(&instance
->dri_options
, &instance
->available_dri_options
,
784 instance
->app_info
.engine_name
,
785 instance
->app_info
.engine_version
);
787 *pInstance
= anv_instance_to_handle(instance
);
792 void anv_DestroyInstance(
793 VkInstance _instance
,
794 const VkAllocationCallbacks
* pAllocator
)
796 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
801 if (instance
->physicalDeviceCount
> 0) {
802 /* We support at most one physical device. */
803 assert(instance
->physicalDeviceCount
== 1);
804 anv_physical_device_finish(&instance
->physicalDevice
);
807 vk_free(&instance
->alloc
, (char *)instance
->app_info
.app_name
);
808 vk_free(&instance
->alloc
, (char *)instance
->app_info
.engine_name
);
810 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
812 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
814 glsl_type_singleton_decref();
817 driDestroyOptionCache(&instance
->dri_options
);
818 driDestroyOptionInfo(&instance
->available_dri_options
);
820 vk_free(&instance
->alloc
, instance
);
824 anv_enumerate_devices(struct anv_instance
*instance
)
826 /* TODO: Check for more devices ? */
827 drmDevicePtr devices
[8];
828 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
831 instance
->physicalDeviceCount
= 0;
833 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
835 return VK_ERROR_INCOMPATIBLE_DRIVER
;
837 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
838 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
839 devices
[i
]->bustype
== DRM_BUS_PCI
&&
840 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
842 result
= anv_physical_device_init(&instance
->physicalDevice
,
843 instance
, devices
[i
]);
844 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
848 drmFreeDevices(devices
, max_devices
);
850 if (result
== VK_SUCCESS
)
851 instance
->physicalDeviceCount
= 1;
857 anv_instance_ensure_physical_device(struct anv_instance
*instance
)
859 if (instance
->physicalDeviceCount
< 0) {
860 VkResult result
= anv_enumerate_devices(instance
);
861 if (result
!= VK_SUCCESS
&&
862 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
869 VkResult
anv_EnumeratePhysicalDevices(
870 VkInstance _instance
,
871 uint32_t* pPhysicalDeviceCount
,
872 VkPhysicalDevice
* pPhysicalDevices
)
874 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
875 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
877 VkResult result
= anv_instance_ensure_physical_device(instance
);
878 if (result
!= VK_SUCCESS
)
881 if (instance
->physicalDeviceCount
== 0)
884 assert(instance
->physicalDeviceCount
== 1);
885 vk_outarray_append(&out
, i
) {
886 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
889 return vk_outarray_status(&out
);
892 VkResult
anv_EnumeratePhysicalDeviceGroups(
893 VkInstance _instance
,
894 uint32_t* pPhysicalDeviceGroupCount
,
895 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
897 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
898 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
899 pPhysicalDeviceGroupCount
);
901 VkResult result
= anv_instance_ensure_physical_device(instance
);
902 if (result
!= VK_SUCCESS
)
905 if (instance
->physicalDeviceCount
== 0)
908 assert(instance
->physicalDeviceCount
== 1);
910 vk_outarray_append(&out
, p
) {
911 p
->physicalDeviceCount
= 1;
912 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
913 p
->physicalDevices
[0] =
914 anv_physical_device_to_handle(&instance
->physicalDevice
);
915 p
->subsetAllocation
= false;
917 vk_foreach_struct(ext
, p
->pNext
)
918 anv_debug_ignored_stype(ext
->sType
);
921 return vk_outarray_status(&out
);
924 void anv_GetPhysicalDeviceFeatures(
925 VkPhysicalDevice physicalDevice
,
926 VkPhysicalDeviceFeatures
* pFeatures
)
928 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
930 *pFeatures
= (VkPhysicalDeviceFeatures
) {
931 .robustBufferAccess
= true,
932 .fullDrawIndexUint32
= true,
933 .imageCubeArray
= true,
934 .independentBlend
= true,
935 .geometryShader
= true,
936 .tessellationShader
= true,
937 .sampleRateShading
= true,
938 .dualSrcBlend
= true,
940 .multiDrawIndirect
= true,
941 .drawIndirectFirstInstance
= true,
943 .depthBiasClamp
= true,
944 .fillModeNonSolid
= true,
945 .depthBounds
= false,
949 .multiViewport
= true,
950 .samplerAnisotropy
= true,
951 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
952 pdevice
->info
.is_baytrail
,
953 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
954 .textureCompressionBC
= true,
955 .occlusionQueryPrecise
= true,
956 .pipelineStatisticsQuery
= true,
957 .fragmentStoresAndAtomics
= true,
958 .shaderTessellationAndGeometryPointSize
= true,
959 .shaderImageGatherExtended
= true,
960 .shaderStorageImageExtendedFormats
= true,
961 .shaderStorageImageMultisample
= false,
962 .shaderStorageImageReadWithoutFormat
= false,
963 .shaderStorageImageWriteWithoutFormat
= true,
964 .shaderUniformBufferArrayDynamicIndexing
= true,
965 .shaderSampledImageArrayDynamicIndexing
= true,
966 .shaderStorageBufferArrayDynamicIndexing
= true,
967 .shaderStorageImageArrayDynamicIndexing
= true,
968 .shaderClipDistance
= true,
969 .shaderCullDistance
= true,
970 .shaderFloat64
= pdevice
->info
.gen
>= 8 &&
971 pdevice
->info
.has_64bit_types
,
972 .shaderInt64
= pdevice
->info
.gen
>= 8 &&
973 pdevice
->info
.has_64bit_types
,
974 .shaderInt16
= pdevice
->info
.gen
>= 8,
975 .shaderResourceMinLod
= pdevice
->info
.gen
>= 9,
976 .variableMultisampleRate
= true,
977 .inheritedQueries
= true,
980 /* We can't do image stores in vec4 shaders */
981 pFeatures
->vertexPipelineStoresAndAtomics
=
982 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
983 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
985 struct anv_app_info
*app_info
= &pdevice
->instance
->app_info
;
987 /* The new DOOM and Wolfenstein games require depthBounds without
988 * checking for it. They seem to run fine without it so just claim it's
989 * there and accept the consequences.
991 if (app_info
->engine_name
&& strcmp(app_info
->engine_name
, "idTech") == 0)
992 pFeatures
->depthBounds
= true;
995 void anv_GetPhysicalDeviceFeatures2(
996 VkPhysicalDevice physicalDevice
,
997 VkPhysicalDeviceFeatures2
* pFeatures
)
999 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1000 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1002 vk_foreach_struct(ext
, pFeatures
->pNext
) {
1003 switch (ext
->sType
) {
1004 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
1005 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
1006 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
1007 features
->storageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
1008 features
->uniformAndStorageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
1009 features
->storagePushConstant8
= pdevice
->info
.gen
>= 8;
1013 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
1014 VkPhysicalDevice16BitStorageFeatures
*features
=
1015 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
1016 features
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
1017 features
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
1018 features
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
1019 features
->storageInputOutput16
= false;
1023 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1024 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
= (void *)ext
;
1025 features
->bufferDeviceAddress
= pdevice
->has_a64_buffer_access
;
1026 features
->bufferDeviceAddressCaptureReplay
= false;
1027 features
->bufferDeviceAddressMultiDevice
= false;
1031 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1032 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1033 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1034 features
->computeDerivativeGroupQuads
= true;
1035 features
->computeDerivativeGroupLinear
= true;
1039 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
1040 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
1041 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
1042 features
->conditionalRendering
= pdevice
->info
.gen
>= 8 ||
1043 pdevice
->info
.is_haswell
;
1044 features
->inheritedConditionalRendering
= pdevice
->info
.gen
>= 8 ||
1045 pdevice
->info
.is_haswell
;
1049 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1050 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1051 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1052 features
->depthClipEnable
= true;
1056 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
1057 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
= (void *)ext
;
1058 features
->shaderFloat16
= pdevice
->info
.gen
>= 8;
1059 features
->shaderInt8
= pdevice
->info
.gen
>= 8;
1063 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT
: {
1064 VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*features
=
1065 (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*)ext
;
1066 features
->fragmentShaderSampleInterlock
= pdevice
->info
.gen
>= 9;
1067 features
->fragmentShaderPixelInterlock
= pdevice
->info
.gen
>= 9;
1068 features
->fragmentShaderShadingRateInterlock
= false;
1072 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
1073 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
1074 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
1075 features
->hostQueryReset
= true;
1079 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
1080 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
1081 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
1082 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
1083 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
1084 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
1085 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
1086 features
->shaderSampledImageArrayNonUniformIndexing
= true;
1087 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
1088 features
->shaderStorageImageArrayNonUniformIndexing
= true;
1089 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
1090 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
1091 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
1092 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
1093 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
1094 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
1095 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
1096 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
1097 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
1098 features
->descriptorBindingUpdateUnusedWhilePending
= true;
1099 features
->descriptorBindingPartiallyBound
= true;
1100 features
->descriptorBindingVariableDescriptorCount
= false;
1101 features
->runtimeDescriptorArray
= true;
1105 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1106 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1107 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1108 features
->indexTypeUint8
= true;
1112 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1113 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1114 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1115 features
->inlineUniformBlock
= true;
1116 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1120 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1121 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1122 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1123 features
->rectangularLines
= true;
1124 features
->bresenhamLines
= true;
1125 features
->smoothLines
= true;
1126 features
->stippledRectangularLines
= false;
1127 features
->stippledBresenhamLines
= true;
1128 features
->stippledSmoothLines
= false;
1132 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
1133 VkPhysicalDeviceMultiviewFeatures
*features
=
1134 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
1135 features
->multiview
= true;
1136 features
->multiviewGeometryShader
= true;
1137 features
->multiviewTessellationShader
= true;
1141 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1142 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1143 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1144 features
->imagelessFramebuffer
= true;
1148 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1149 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1150 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1151 features
->pipelineExecutableInfo
= true;
1155 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
1156 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
1157 features
->protectedMemory
= false;
1161 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
1162 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
1163 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
1164 features
->samplerYcbcrConversion
= true;
1168 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
1169 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
1170 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
1171 features
->scalarBlockLayout
= true;
1175 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
1176 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
= (void *)ext
;
1177 features
->shaderBufferInt64Atomics
=
1178 pdevice
->info
.gen
>= 9 && pdevice
->use_softpin
;
1179 features
->shaderSharedInt64Atomics
= VK_FALSE
;
1183 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1184 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
= (void *)ext
;
1185 features
->shaderDemoteToHelperInvocation
= true;
1189 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
1190 VkPhysicalDeviceShaderDrawParametersFeatures
*features
= (void *)ext
;
1191 features
->shaderDrawParameters
= true;
1195 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1196 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1197 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1198 features
->subgroupSizeControl
= true;
1199 features
->computeFullSubgroups
= true;
1203 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1204 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1205 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1206 features
->texelBufferAlignment
= true;
1210 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
1211 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
1212 features
->variablePointersStorageBuffer
= true;
1213 features
->variablePointers
= true;
1217 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1218 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1219 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1220 features
->transformFeedback
= true;
1221 features
->geometryStreams
= true;
1225 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1226 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1227 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1228 features
->uniformBufferStandardLayout
= true;
1232 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
1233 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1234 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1235 features
->vertexAttributeInstanceRateDivisor
= true;
1236 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1240 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1241 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1242 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1243 features
->ycbcrImageArrays
= true;
1248 anv_debug_ignored_stype(ext
->sType
);
1254 #define MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS 64
1256 #define MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS 64
1257 #define MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS 256
1259 void anv_GetPhysicalDeviceProperties(
1260 VkPhysicalDevice physicalDevice
,
1261 VkPhysicalDeviceProperties
* pProperties
)
1263 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1264 const struct gen_device_info
*devinfo
= &pdevice
->info
;
1266 /* See assertions made when programming the buffer surface state. */
1267 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
1268 (1ul << 30) : (1ul << 27);
1270 const uint32_t max_ssbos
= pdevice
->has_a64_buffer_access
? UINT16_MAX
: 64;
1271 const uint32_t max_textures
=
1272 pdevice
->has_bindless_images
? UINT16_MAX
: 128;
1273 const uint32_t max_samplers
=
1274 pdevice
->has_bindless_samplers
? UINT16_MAX
:
1275 (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ? 128 : 16;
1276 const uint32_t max_images
=
1277 pdevice
->has_bindless_images
? UINT16_MAX
: MAX_IMAGES
;
1279 /* The moment we have anything bindless, claim a high per-stage limit */
1280 const uint32_t max_per_stage
=
1281 pdevice
->has_a64_buffer_access
? UINT32_MAX
:
1282 MAX_BINDING_TABLE_SIZE
- MAX_RTS
;
1284 const uint32_t max_workgroup_size
= 32 * devinfo
->max_cs_threads
;
1286 VkSampleCountFlags sample_counts
=
1287 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1290 VkPhysicalDeviceLimits limits
= {
1291 .maxImageDimension1D
= (1 << 14),
1292 .maxImageDimension2D
= (1 << 14),
1293 .maxImageDimension3D
= (1 << 11),
1294 .maxImageDimensionCube
= (1 << 14),
1295 .maxImageArrayLayers
= (1 << 11),
1296 .maxTexelBufferElements
= 128 * 1024 * 1024,
1297 .maxUniformBufferRange
= (1ul << 27),
1298 .maxStorageBufferRange
= max_raw_buffer_sz
,
1299 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1300 .maxMemoryAllocationCount
= UINT32_MAX
,
1301 .maxSamplerAllocationCount
= 64 * 1024,
1302 .bufferImageGranularity
= 64, /* A cache line */
1303 .sparseAddressSpaceSize
= 0,
1304 .maxBoundDescriptorSets
= MAX_SETS
,
1305 .maxPerStageDescriptorSamplers
= max_samplers
,
1306 .maxPerStageDescriptorUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
,
1307 .maxPerStageDescriptorStorageBuffers
= max_ssbos
,
1308 .maxPerStageDescriptorSampledImages
= max_textures
,
1309 .maxPerStageDescriptorStorageImages
= max_images
,
1310 .maxPerStageDescriptorInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
,
1311 .maxPerStageResources
= max_per_stage
,
1312 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
1313 .maxDescriptorSetUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
, /* number of stages * maxPerStageDescriptorUniformBuffers */
1314 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1315 .maxDescriptorSetStorageBuffers
= 6 * max_ssbos
, /* number of stages * maxPerStageDescriptorStorageBuffers */
1316 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1317 .maxDescriptorSetSampledImages
= 6 * max_textures
, /* number of stages * maxPerStageDescriptorSampledImages */
1318 .maxDescriptorSetStorageImages
= 6 * max_images
, /* number of stages * maxPerStageDescriptorStorageImages */
1319 .maxDescriptorSetInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
,
1320 .maxVertexInputAttributes
= MAX_VBS
,
1321 .maxVertexInputBindings
= MAX_VBS
,
1322 .maxVertexInputAttributeOffset
= 2047,
1323 .maxVertexInputBindingStride
= 2048,
1324 .maxVertexOutputComponents
= 128,
1325 .maxTessellationGenerationLevel
= 64,
1326 .maxTessellationPatchSize
= 32,
1327 .maxTessellationControlPerVertexInputComponents
= 128,
1328 .maxTessellationControlPerVertexOutputComponents
= 128,
1329 .maxTessellationControlPerPatchOutputComponents
= 128,
1330 .maxTessellationControlTotalOutputComponents
= 2048,
1331 .maxTessellationEvaluationInputComponents
= 128,
1332 .maxTessellationEvaluationOutputComponents
= 128,
1333 .maxGeometryShaderInvocations
= 32,
1334 .maxGeometryInputComponents
= 64,
1335 .maxGeometryOutputComponents
= 128,
1336 .maxGeometryOutputVertices
= 256,
1337 .maxGeometryTotalOutputComponents
= 1024,
1338 .maxFragmentInputComponents
= 116, /* 128 components - (PSIZ, CLIP_DIST0, CLIP_DIST1) */
1339 .maxFragmentOutputAttachments
= 8,
1340 .maxFragmentDualSrcAttachments
= 1,
1341 .maxFragmentCombinedOutputResources
= 8,
1342 .maxComputeSharedMemorySize
= 64 * 1024,
1343 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1344 .maxComputeWorkGroupInvocations
= max_workgroup_size
,
1345 .maxComputeWorkGroupSize
= {
1350 .subPixelPrecisionBits
= 8,
1351 .subTexelPrecisionBits
= 8,
1352 .mipmapPrecisionBits
= 8,
1353 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1354 .maxDrawIndirectCount
= UINT32_MAX
,
1355 .maxSamplerLodBias
= 16,
1356 .maxSamplerAnisotropy
= 16,
1357 .maxViewports
= MAX_VIEWPORTS
,
1358 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1359 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1360 .viewportSubPixelBits
= 13, /* We take a float? */
1361 .minMemoryMapAlignment
= 4096, /* A page */
1362 /* The dataport requires texel alignment so we need to assume a worst
1363 * case of R32G32B32A32 which is 16 bytes.
1365 .minTexelBufferOffsetAlignment
= 16,
1366 /* We need 16 for UBO block reads to work and 32 for push UBOs */
1367 .minUniformBufferOffsetAlignment
= 32,
1368 .minStorageBufferOffsetAlignment
= 4,
1369 .minTexelOffset
= -8,
1370 .maxTexelOffset
= 7,
1371 .minTexelGatherOffset
= -32,
1372 .maxTexelGatherOffset
= 31,
1373 .minInterpolationOffset
= -0.5,
1374 .maxInterpolationOffset
= 0.4375,
1375 .subPixelInterpolationOffsetBits
= 4,
1376 .maxFramebufferWidth
= (1 << 14),
1377 .maxFramebufferHeight
= (1 << 14),
1378 .maxFramebufferLayers
= (1 << 11),
1379 .framebufferColorSampleCounts
= sample_counts
,
1380 .framebufferDepthSampleCounts
= sample_counts
,
1381 .framebufferStencilSampleCounts
= sample_counts
,
1382 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1383 .maxColorAttachments
= MAX_RTS
,
1384 .sampledImageColorSampleCounts
= sample_counts
,
1385 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1386 .sampledImageDepthSampleCounts
= sample_counts
,
1387 .sampledImageStencilSampleCounts
= sample_counts
,
1388 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1389 .maxSampleMaskWords
= 1,
1390 .timestampComputeAndGraphics
= true,
1391 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
1392 .maxClipDistances
= 8,
1393 .maxCullDistances
= 8,
1394 .maxCombinedClipAndCullDistances
= 8,
1395 .discreteQueuePriorities
= 2,
1396 .pointSizeRange
= { 0.125, 255.875 },
1399 (devinfo
->gen
>= 9 || devinfo
->is_cherryview
) ?
1400 2047.9921875 : 7.9921875,
1402 .pointSizeGranularity
= (1.0 / 8.0),
1403 .lineWidthGranularity
= (1.0 / 128.0),
1404 .strictLines
= false,
1405 .standardSampleLocations
= true,
1406 .optimalBufferCopyOffsetAlignment
= 128,
1407 .optimalBufferCopyRowPitchAlignment
= 128,
1408 .nonCoherentAtomSize
= 64,
1411 *pProperties
= (VkPhysicalDeviceProperties
) {
1412 .apiVersion
= anv_physical_device_api_version(pdevice
),
1413 .driverVersion
= vk_get_driver_version(),
1415 .deviceID
= pdevice
->chipset_id
,
1416 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1418 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
1421 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
1422 "%s", pdevice
->name
);
1423 memcpy(pProperties
->pipelineCacheUUID
,
1424 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
1427 void anv_GetPhysicalDeviceProperties2(
1428 VkPhysicalDevice physicalDevice
,
1429 VkPhysicalDeviceProperties2
* pProperties
)
1431 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1433 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1435 vk_foreach_struct(ext
, pProperties
->pNext
) {
1436 switch (ext
->sType
) {
1437 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1438 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*props
=
1439 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1441 /* We support all of the depth resolve modes */
1442 props
->supportedDepthResolveModes
=
1443 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1444 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1445 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1446 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1448 /* Average doesn't make sense for stencil so we don't support that */
1449 props
->supportedStencilResolveModes
=
1450 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
;
1451 if (pdevice
->info
.gen
>= 8) {
1452 /* The advanced stencil resolve modes currently require stencil
1453 * sampling be supported by the hardware.
1455 props
->supportedStencilResolveModes
|=
1456 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1457 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1460 props
->independentResolveNone
= true;
1461 props
->independentResolve
= true;
1465 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1466 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*props
=
1467 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1469 /* It's a bit hard to exactly map our implementation to the limits
1470 * described here. The bindless surface handle in the extended
1471 * message descriptors is 20 bits and it's an index into the table of
1472 * RENDER_SURFACE_STATE structs that starts at bindless surface base
1473 * address. Given that most things consume two surface states per
1474 * view (general/sampled for textures and write-only/read-write for
1475 * images), we claim 2^19 things.
1477 * For SSBOs, we just use A64 messages so there is no real limit
1478 * there beyond the limit on the total size of a descriptor set.
1480 const unsigned max_bindless_views
= 1 << 19;
1482 props
->maxUpdateAfterBindDescriptorsInAllPools
= max_bindless_views
;
1483 props
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1484 props
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1485 props
->shaderStorageBufferArrayNonUniformIndexingNative
= true;
1486 props
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1487 props
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1488 props
->robustBufferAccessUpdateAfterBind
= true;
1489 props
->quadDivergentImplicitLod
= false;
1490 props
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_bindless_views
;
1491 props
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1492 props
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1493 props
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_bindless_views
;
1494 props
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_bindless_views
;
1495 props
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
;
1496 props
->maxPerStageUpdateAfterBindResources
= UINT32_MAX
;
1497 props
->maxDescriptorSetUpdateAfterBindSamplers
= max_bindless_views
;
1498 props
->maxDescriptorSetUpdateAfterBindUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1499 props
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1500 props
->maxDescriptorSetUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1501 props
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1502 props
->maxDescriptorSetUpdateAfterBindSampledImages
= max_bindless_views
;
1503 props
->maxDescriptorSetUpdateAfterBindStorageImages
= max_bindless_views
;
1504 props
->maxDescriptorSetUpdateAfterBindInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
;
1508 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1509 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1510 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1512 driver_props
->driverID
= VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR
;
1513 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
,
1514 "Intel open-source Mesa driver");
1516 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1517 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
);
1519 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1528 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1529 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*props
=
1530 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1531 /* Userptr needs page aligned memory. */
1532 props
->minImportedHostPointerAlignment
= 4096;
1536 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1537 VkPhysicalDeviceIDProperties
*id_props
=
1538 (VkPhysicalDeviceIDProperties
*)ext
;
1539 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1540 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1541 /* The LUID is for Windows. */
1542 id_props
->deviceLUIDValid
= false;
1546 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1547 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1548 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1549 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1550 props
->maxPerStageDescriptorInlineUniformBlocks
=
1551 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1552 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
=
1553 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1554 props
->maxDescriptorSetInlineUniformBlocks
=
1555 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1556 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
=
1557 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1561 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1562 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1563 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1564 /* In the Skylake PRM Vol. 7, subsection titled "GIQ (Diamond)
1565 * Sampling Rules - Legacy Mode", it says the following:
1567 * "Note that the device divides a pixel into a 16x16 array of
1568 * subpixels, referenced by their upper left corners."
1570 * This is the only known reference in the PRMs to the subpixel
1571 * precision of line rasterization and a "16x16 array of subpixels"
1572 * implies 4 subpixel precision bits. Empirical testing has shown
1573 * that 4 subpixel precision bits applies to all line rasterization
1576 props
->lineSubPixelPrecisionBits
= 4;
1580 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1581 VkPhysicalDeviceMaintenance3Properties
*props
=
1582 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1583 /* This value doesn't matter for us today as our per-stage
1584 * descriptors are the real limit.
1586 props
->maxPerSetDescriptors
= 1024;
1587 props
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1591 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1592 VkPhysicalDeviceMultiviewProperties
*properties
=
1593 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1594 properties
->maxMultiviewViewCount
= 16;
1595 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1599 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1600 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1601 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1602 properties
->pciDomain
= pdevice
->pci_info
.domain
;
1603 properties
->pciBus
= pdevice
->pci_info
.bus
;
1604 properties
->pciDevice
= pdevice
->pci_info
.device
;
1605 properties
->pciFunction
= pdevice
->pci_info
.function
;
1609 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1610 VkPhysicalDevicePointClippingProperties
*properties
=
1611 (VkPhysicalDevicePointClippingProperties
*) ext
;
1612 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY
;
1616 #pragma GCC diagnostic push
1617 #pragma GCC diagnostic ignored "-Wswitch"
1618 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
: {
1619 VkPhysicalDevicePresentationPropertiesANDROID
*props
=
1620 (VkPhysicalDevicePresentationPropertiesANDROID
*)ext
;
1621 props
->sharedImage
= VK_FALSE
;
1624 #pragma GCC diagnostic pop
1626 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1627 VkPhysicalDeviceProtectedMemoryProperties
*props
=
1628 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1629 props
->protectedNoFault
= false;
1633 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1634 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1635 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1637 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1641 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1642 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1643 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1644 properties
->filterMinmaxImageComponentMapping
= pdevice
->info
.gen
>= 9;
1645 properties
->filterMinmaxSingleComponentFormats
= true;
1649 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1650 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
1652 properties
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1654 VkShaderStageFlags scalar_stages
= 0;
1655 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1656 if (pdevice
->compiler
->scalar_stage
[stage
])
1657 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1659 properties
->supportedStages
= scalar_stages
;
1661 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1662 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1663 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1664 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1665 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1666 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1667 if (pdevice
->info
.gen
>= 8) {
1668 /* TODO: There's no technical reason why these can't be made to
1669 * work on gen7 but they don't at the moment so it's best to leave
1670 * the feature disabled than enabled and broken.
1672 properties
->supportedOperations
|=
1673 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1674 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
;
1676 properties
->quadOperationsInAllStages
= pdevice
->info
.gen
>= 8;
1680 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
1681 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
1682 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
1683 STATIC_ASSERT(8 <= BRW_SUBGROUP_SIZE
&& BRW_SUBGROUP_SIZE
<= 32);
1684 props
->minSubgroupSize
= 8;
1685 props
->maxSubgroupSize
= 32;
1686 props
->maxComputeWorkgroupSubgroups
= pdevice
->info
.max_cs_threads
;
1687 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1691 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1692 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*props
=
1693 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1695 /* From the SKL PRM Vol. 2d, docs for RENDER_SURFACE_STATE::Surface
1698 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field
1699 * specifies the base address of the first element of the surface,
1700 * computed in software by adding the surface base address to the
1701 * byte offset of the element in the buffer. The base address must
1702 * be aligned to element size."
1704 * The typed dataport messages require that things be texel aligned.
1705 * Otherwise, we may just load/store the wrong data or, in the worst
1706 * case, there may be hangs.
1708 props
->storageTexelBufferOffsetAlignmentBytes
= 16;
1709 props
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1711 /* The sampler, however, is much more forgiving and it can handle
1712 * arbitrary byte alignment for linear and buffer surfaces. It's
1713 * hard to find a good PRM citation for this but years of empirical
1714 * experience demonstrate that this is true.
1716 props
->uniformTexelBufferOffsetAlignmentBytes
= 1;
1717 props
->uniformTexelBufferOffsetSingleTexelAlignment
= false;
1721 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1722 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*props
=
1723 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1725 props
->maxTransformFeedbackStreams
= MAX_XFB_STREAMS
;
1726 props
->maxTransformFeedbackBuffers
= MAX_XFB_BUFFERS
;
1727 props
->maxTransformFeedbackBufferSize
= (1ull << 32);
1728 props
->maxTransformFeedbackStreamDataSize
= 128 * 4;
1729 props
->maxTransformFeedbackBufferDataSize
= 128 * 4;
1730 props
->maxTransformFeedbackBufferDataStride
= 2048;
1731 props
->transformFeedbackQueries
= true;
1732 props
->transformFeedbackStreamsLinesTriangles
= false;
1733 props
->transformFeedbackRasterizationStreamSelect
= false;
1734 props
->transformFeedbackDraw
= true;
1738 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1739 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
1740 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1741 /* We have to restrict this a bit for multiview */
1742 props
->maxVertexAttribDivisor
= UINT32_MAX
/ 16;
1747 anv_debug_ignored_stype(ext
->sType
);
1753 /* We support exactly one queue family. */
1754 static const VkQueueFamilyProperties
1755 anv_queue_family_properties
= {
1756 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1757 VK_QUEUE_COMPUTE_BIT
|
1758 VK_QUEUE_TRANSFER_BIT
,
1760 .timestampValidBits
= 36, /* XXX: Real value here */
1761 .minImageTransferGranularity
= { 1, 1, 1 },
1764 void anv_GetPhysicalDeviceQueueFamilyProperties(
1765 VkPhysicalDevice physicalDevice
,
1767 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1769 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1771 vk_outarray_append(&out
, p
) {
1772 *p
= anv_queue_family_properties
;
1776 void anv_GetPhysicalDeviceQueueFamilyProperties2(
1777 VkPhysicalDevice physicalDevice
,
1778 uint32_t* pQueueFamilyPropertyCount
,
1779 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
1782 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1784 vk_outarray_append(&out
, p
) {
1785 p
->queueFamilyProperties
= anv_queue_family_properties
;
1787 vk_foreach_struct(s
, p
->pNext
) {
1788 anv_debug_ignored_stype(s
->sType
);
1793 void anv_GetPhysicalDeviceMemoryProperties(
1794 VkPhysicalDevice physicalDevice
,
1795 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1797 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1799 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1800 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1801 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1802 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1803 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1807 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1808 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1809 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1810 .size
= physical_device
->memory
.heaps
[i
].size
,
1811 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1817 anv_get_memory_budget(VkPhysicalDevice physicalDevice
,
1818 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1820 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1821 uint64_t sys_available
= get_available_system_memory();
1822 assert(sys_available
> 0);
1824 VkDeviceSize total_heaps_size
= 0;
1825 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++)
1826 total_heaps_size
+= device
->memory
.heaps
[i
].size
;
1828 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++) {
1829 VkDeviceSize heap_size
= device
->memory
.heaps
[i
].size
;
1830 VkDeviceSize heap_used
= device
->memory
.heaps
[i
].used
;
1831 VkDeviceSize heap_budget
;
1833 double heap_proportion
= (double) heap_size
/ total_heaps_size
;
1834 VkDeviceSize sys_available_prop
= sys_available
* heap_proportion
;
1837 * Let's not incite the app to starve the system: report at most 90% of
1838 * available system memory.
1840 uint64_t heap_available
= sys_available_prop
* 9 / 10;
1841 heap_budget
= MIN2(heap_size
, heap_used
+ heap_available
);
1844 * Round down to the nearest MB
1846 heap_budget
&= ~((1ull << 20) - 1);
1849 * The heapBudget value must be non-zero for array elements less than
1850 * VkPhysicalDeviceMemoryProperties::memoryHeapCount. The heapBudget
1851 * value must be less than or equal to VkMemoryHeap::size for each heap.
1853 assert(0 < heap_budget
&& heap_budget
<= heap_size
);
1855 memoryBudget
->heapUsage
[i
] = heap_used
;
1856 memoryBudget
->heapBudget
[i
] = heap_budget
;
1859 /* The heapBudget and heapUsage values must be zero for array elements
1860 * greater than or equal to VkPhysicalDeviceMemoryProperties::memoryHeapCount
1862 for (uint32_t i
= device
->memory
.heap_count
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1863 memoryBudget
->heapBudget
[i
] = 0;
1864 memoryBudget
->heapUsage
[i
] = 0;
1868 void anv_GetPhysicalDeviceMemoryProperties2(
1869 VkPhysicalDevice physicalDevice
,
1870 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
1872 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1873 &pMemoryProperties
->memoryProperties
);
1875 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1876 switch (ext
->sType
) {
1877 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
:
1878 anv_get_memory_budget(physicalDevice
, (void*)ext
);
1881 anv_debug_ignored_stype(ext
->sType
);
1888 anv_GetDeviceGroupPeerMemoryFeatures(
1891 uint32_t localDeviceIndex
,
1892 uint32_t remoteDeviceIndex
,
1893 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
1895 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
1896 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
1897 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
1898 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
1899 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
1902 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1903 VkInstance _instance
,
1906 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1908 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1909 * when we have to return valid function pointers, NULL, or it's left
1910 * undefined. See the table for exact details.
1915 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1916 if (strcmp(pName, "vk" #entrypoint) == 0) \
1917 return (PFN_vkVoidFunction)anv_##entrypoint
1919 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1920 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1921 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
1922 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1924 #undef LOOKUP_ANV_ENTRYPOINT
1926 if (instance
== NULL
)
1929 int idx
= anv_get_instance_entrypoint_index(pName
);
1931 return instance
->dispatch
.entrypoints
[idx
];
1933 idx
= anv_get_device_entrypoint_index(pName
);
1935 return instance
->device_dispatch
.entrypoints
[idx
];
1940 /* With version 1+ of the loader interface the ICD should expose
1941 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1944 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1945 VkInstance instance
,
1949 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1950 VkInstance instance
,
1953 return anv_GetInstanceProcAddr(instance
, pName
);
1956 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1960 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1962 if (!device
|| !pName
)
1965 int idx
= anv_get_device_entrypoint_index(pName
);
1969 return device
->dispatch
.entrypoints
[idx
];
1973 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1974 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1975 const VkAllocationCallbacks
* pAllocator
,
1976 VkDebugReportCallbackEXT
* pCallback
)
1978 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1979 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1980 pCreateInfo
, pAllocator
, &instance
->alloc
,
1985 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1986 VkDebugReportCallbackEXT _callback
,
1987 const VkAllocationCallbacks
* pAllocator
)
1989 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1990 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1991 _callback
, pAllocator
, &instance
->alloc
);
1995 anv_DebugReportMessageEXT(VkInstance _instance
,
1996 VkDebugReportFlagsEXT flags
,
1997 VkDebugReportObjectTypeEXT objectType
,
2000 int32_t messageCode
,
2001 const char* pLayerPrefix
,
2002 const char* pMessage
)
2004 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2005 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2006 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2010 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
2012 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2013 queue
->device
= device
;
2018 anv_queue_finish(struct anv_queue
*queue
)
2022 static struct anv_state
2023 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
2025 struct anv_state state
;
2027 state
= anv_state_pool_alloc(pool
, size
, align
);
2028 memcpy(state
.map
, p
, size
);
2033 /* Haswell border color is a bit of a disaster. Float and unorm formats use a
2034 * straightforward 32-bit float color in the first 64 bytes. Instead of using
2035 * a nice float/integer union like Gen8+, Haswell specifies the integer border
2036 * color as a separate entry /after/ the float color. The layout of this entry
2037 * also depends on the format's bpp (with extra hacks for RG32), and overlaps.
2039 * Since we don't know the format/bpp, we can't make any of the border colors
2040 * containing '1' work for all formats, as it would be in the wrong place for
2041 * some of them. We opt to make 32-bit integers work as this seems like the
2042 * most common option. Fortunately, transparent black works regardless, as
2043 * all zeroes is the same in every bit-size.
2045 struct hsw_border_color
{
2049 uint32_t _pad1
[108];
2052 struct gen8_border_color
{
2057 /* Pad out to 64 bytes */
2062 anv_device_init_border_colors(struct anv_device
*device
)
2064 if (device
->info
.is_haswell
) {
2065 static const struct hsw_border_color border_colors
[] = {
2066 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2067 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2068 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2069 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2070 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2071 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2074 device
->border_colors
=
2075 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2076 sizeof(border_colors
), 512, border_colors
);
2078 static const struct gen8_border_color border_colors
[] = {
2079 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2080 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2081 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2082 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2083 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2084 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2087 device
->border_colors
=
2088 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2089 sizeof(border_colors
), 64, border_colors
);
2094 anv_device_init_trivial_batch(struct anv_device
*device
)
2096 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
2098 if (device
->instance
->physicalDevice
.has_exec_async
)
2099 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
2101 if (device
->instance
->physicalDevice
.use_softpin
)
2102 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_PINNED
;
2104 anv_vma_alloc(device
, &device
->trivial_batch_bo
);
2106 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
2109 struct anv_batch batch
= {
2115 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2116 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2118 if (!device
->info
.has_llc
)
2119 gen_clflush_range(map
, batch
.next
- map
);
2121 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
2124 VkResult
anv_EnumerateDeviceExtensionProperties(
2125 VkPhysicalDevice physicalDevice
,
2126 const char* pLayerName
,
2127 uint32_t* pPropertyCount
,
2128 VkExtensionProperties
* pProperties
)
2130 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
2131 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2133 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
2134 if (device
->supported_extensions
.extensions
[i
]) {
2135 vk_outarray_append(&out
, prop
) {
2136 *prop
= anv_device_extensions
[i
];
2141 return vk_outarray_status(&out
);
2145 anv_device_init_dispatch(struct anv_device
*device
)
2147 const struct anv_device_dispatch_table
*genX_table
;
2148 switch (device
->info
.gen
) {
2150 genX_table
= &gen12_device_dispatch_table
;
2153 genX_table
= &gen11_device_dispatch_table
;
2156 genX_table
= &gen10_device_dispatch_table
;
2159 genX_table
= &gen9_device_dispatch_table
;
2162 genX_table
= &gen8_device_dispatch_table
;
2165 if (device
->info
.is_haswell
)
2166 genX_table
= &gen75_device_dispatch_table
;
2168 genX_table
= &gen7_device_dispatch_table
;
2171 unreachable("unsupported gen\n");
2174 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2175 /* Vulkan requires that entrypoints for extensions which have not been
2176 * enabled must not be advertised.
2178 if (!anv_device_entrypoint_is_enabled(i
, device
->instance
->app_info
.api_version
,
2179 &device
->instance
->enabled_extensions
,
2180 &device
->enabled_extensions
)) {
2181 device
->dispatch
.entrypoints
[i
] = NULL
;
2182 } else if (genX_table
->entrypoints
[i
]) {
2183 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
2185 device
->dispatch
.entrypoints
[i
] =
2186 anv_device_dispatch_table
.entrypoints
[i
];
2192 vk_priority_to_gen(int priority
)
2195 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2196 return GEN_CONTEXT_LOW_PRIORITY
;
2197 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2198 return GEN_CONTEXT_MEDIUM_PRIORITY
;
2199 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2200 return GEN_CONTEXT_HIGH_PRIORITY
;
2201 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2202 return GEN_CONTEXT_REALTIME_PRIORITY
;
2204 unreachable("Invalid priority");
2209 anv_device_init_hiz_clear_value_bo(struct anv_device
*device
)
2211 anv_bo_init_new(&device
->hiz_clear_bo
, device
, 4096);
2213 if (device
->instance
->physicalDevice
.has_exec_async
)
2214 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_ASYNC
;
2216 if (device
->instance
->physicalDevice
.use_softpin
)
2217 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_PINNED
;
2219 anv_vma_alloc(device
, &device
->hiz_clear_bo
);
2221 uint32_t *map
= anv_gem_mmap(device
, device
->hiz_clear_bo
.gem_handle
,
2224 union isl_color_value hiz_clear
= { .u32
= { 0, } };
2225 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
2227 memcpy(map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
2228 anv_gem_munmap(map
, device
->hiz_clear_bo
.size
);
2232 get_bo_from_pool(struct gen_batch_decode_bo
*ret
,
2233 struct anv_block_pool
*pool
,
2236 for (uint32_t i
= 0; i
< pool
->nbos
; i
++) {
2237 uint64_t bo_address
= pool
->bos
[i
].offset
& (~0ull >> 16);
2238 uint32_t bo_size
= pool
->bos
[i
].size
;
2239 if (address
>= bo_address
&& address
< (bo_address
+ bo_size
)) {
2240 *ret
= (struct gen_batch_decode_bo
) {
2243 .map
= pool
->bos
[i
].map
,
2251 /* Finding a buffer for batch decoding */
2252 static struct gen_batch_decode_bo
2253 decode_get_bo(void *v_batch
, bool ppgtt
, uint64_t address
)
2255 struct anv_device
*device
= v_batch
;
2256 struct gen_batch_decode_bo ret_bo
= {};
2260 if (get_bo_from_pool(&ret_bo
, &device
->dynamic_state_pool
.block_pool
, address
))
2262 if (get_bo_from_pool(&ret_bo
, &device
->instruction_state_pool
.block_pool
, address
))
2264 if (get_bo_from_pool(&ret_bo
, &device
->binding_table_pool
.block_pool
, address
))
2266 if (get_bo_from_pool(&ret_bo
, &device
->surface_state_pool
.block_pool
, address
))
2269 if (!device
->cmd_buffer_being_decoded
)
2270 return (struct gen_batch_decode_bo
) { };
2272 struct anv_batch_bo
**bo
;
2274 u_vector_foreach(bo
, &device
->cmd_buffer_being_decoded
->seen_bbos
) {
2275 /* The decoder zeroes out the top 16 bits, so we need to as well */
2276 uint64_t bo_address
= (*bo
)->bo
.offset
& (~0ull >> 16);
2278 if (address
>= bo_address
&& address
< bo_address
+ (*bo
)->bo
.size
) {
2279 return (struct gen_batch_decode_bo
) {
2281 .size
= (*bo
)->bo
.size
,
2282 .map
= (*bo
)->bo
.map
,
2287 return (struct gen_batch_decode_bo
) { };
2290 VkResult
anv_CreateDevice(
2291 VkPhysicalDevice physicalDevice
,
2292 const VkDeviceCreateInfo
* pCreateInfo
,
2293 const VkAllocationCallbacks
* pAllocator
,
2296 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
2298 struct anv_device
*device
;
2300 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
2302 struct anv_device_extension_table enabled_extensions
= { };
2303 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
2305 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
2306 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
2307 anv_device_extensions
[idx
].extensionName
) == 0)
2311 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
2312 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2314 if (!physical_device
->supported_extensions
.extensions
[idx
])
2315 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2317 enabled_extensions
.extensions
[idx
] = true;
2320 /* Check enabled features */
2321 if (pCreateInfo
->pEnabledFeatures
) {
2322 VkPhysicalDeviceFeatures supported_features
;
2323 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2324 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2325 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
2326 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2327 for (uint32_t i
= 0; i
< num_features
; i
++) {
2328 if (enabled_feature
[i
] && !supported_feature
[i
])
2329 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2333 /* Check requested queues and fail if we are requested to create any
2334 * queues with flags we don't support.
2336 assert(pCreateInfo
->queueCreateInfoCount
> 0);
2337 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
2338 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
2339 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2342 /* Check if client specified queue priority. */
2343 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
2344 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
2345 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
2347 VkQueueGlobalPriorityEXT priority
=
2348 queue_priority
? queue_priority
->globalPriority
:
2349 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
2351 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
2353 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2355 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2357 if (INTEL_DEBUG
& DEBUG_BATCH
) {
2358 const unsigned decode_flags
=
2359 GEN_BATCH_DECODE_FULL
|
2360 ((INTEL_DEBUG
& DEBUG_COLOR
) ? GEN_BATCH_DECODE_IN_COLOR
: 0) |
2361 GEN_BATCH_DECODE_OFFSETS
|
2362 GEN_BATCH_DECODE_FLOATS
;
2364 gen_batch_decode_ctx_init(&device
->decoder_ctx
,
2365 &physical_device
->info
,
2366 stderr
, decode_flags
, NULL
,
2367 decode_get_bo
, NULL
, device
);
2370 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2371 device
->instance
= physical_device
->instance
;
2372 device
->chipset_id
= physical_device
->chipset_id
;
2373 device
->no_hw
= physical_device
->no_hw
;
2374 device
->_lost
= false;
2377 device
->alloc
= *pAllocator
;
2379 device
->alloc
= physical_device
->instance
->alloc
;
2381 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
2382 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
2383 if (device
->fd
== -1) {
2384 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2388 device
->context_id
= anv_gem_create_context(device
);
2389 if (device
->context_id
== -1) {
2390 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2394 if (physical_device
->use_softpin
) {
2395 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
2396 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2400 /* keep the page with address zero out of the allocator */
2401 struct anv_memory_heap
*low_heap
=
2402 &physical_device
->memory
.heaps
[physical_device
->memory
.heap_count
- 1];
2403 util_vma_heap_init(&device
->vma_lo
, low_heap
->vma_start
, low_heap
->vma_size
);
2404 device
->vma_lo_available
= low_heap
->size
;
2406 struct anv_memory_heap
*high_heap
=
2407 &physical_device
->memory
.heaps
[0];
2408 util_vma_heap_init(&device
->vma_hi
, high_heap
->vma_start
, high_heap
->vma_size
);
2409 device
->vma_hi_available
= physical_device
->memory
.heap_count
== 1 ? 0 :
2413 list_inithead(&device
->memory_objects
);
2415 /* As per spec, the driver implementation may deny requests to acquire
2416 * a priority above the default priority (MEDIUM) if the caller does not
2417 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
2420 if (physical_device
->has_context_priority
) {
2421 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
2422 I915_CONTEXT_PARAM_PRIORITY
,
2423 vk_priority_to_gen(priority
));
2424 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
2425 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
2430 device
->info
= physical_device
->info
;
2431 device
->isl_dev
= physical_device
->isl_dev
;
2433 /* On Broadwell and later, we can use batch chaining to more efficiently
2434 * implement growing command buffers. Prior to Haswell, the kernel
2435 * command parser gets in the way and we have to fall back to growing
2438 device
->can_chain_batches
= device
->info
.gen
>= 8;
2440 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
2441 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
2442 device
->enabled_extensions
= enabled_extensions
;
2444 anv_device_init_dispatch(device
);
2446 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
2447 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2448 goto fail_context_id
;
2451 pthread_condattr_t condattr
;
2452 if (pthread_condattr_init(&condattr
) != 0) {
2453 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2456 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
2457 pthread_condattr_destroy(&condattr
);
2458 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2461 if (pthread_cond_init(&device
->queue_submit
, &condattr
) != 0) {
2462 pthread_condattr_destroy(&condattr
);
2463 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2466 pthread_condattr_destroy(&condattr
);
2469 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
2470 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
2471 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0) |
2472 (physical_device
->use_softpin
? EXEC_OBJECT_PINNED
: 0);
2474 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
2476 result
= anv_bo_cache_init(&device
->bo_cache
);
2477 if (result
!= VK_SUCCESS
)
2478 goto fail_batch_bo_pool
;
2480 if (!physical_device
->use_softpin
)
2481 bo_flags
&= ~EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2483 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
2484 DYNAMIC_STATE_POOL_MIN_ADDRESS
,
2487 if (result
!= VK_SUCCESS
)
2490 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
2491 INSTRUCTION_STATE_POOL_MIN_ADDRESS
,
2494 if (result
!= VK_SUCCESS
)
2495 goto fail_dynamic_state_pool
;
2497 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
2498 SURFACE_STATE_POOL_MIN_ADDRESS
,
2501 if (result
!= VK_SUCCESS
)
2502 goto fail_instruction_state_pool
;
2504 if (physical_device
->use_softpin
) {
2505 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
2506 BINDING_TABLE_POOL_MIN_ADDRESS
,
2509 if (result
!= VK_SUCCESS
)
2510 goto fail_surface_state_pool
;
2513 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 4096);
2514 if (result
!= VK_SUCCESS
)
2515 goto fail_binding_table_pool
;
2517 if (physical_device
->use_softpin
)
2518 device
->workaround_bo
.flags
|= EXEC_OBJECT_PINNED
;
2520 if (!anv_vma_alloc(device
, &device
->workaround_bo
))
2521 goto fail_workaround_bo
;
2523 anv_device_init_trivial_batch(device
);
2525 if (device
->info
.gen
>= 10)
2526 anv_device_init_hiz_clear_value_bo(device
);
2528 anv_scratch_pool_init(device
, &device
->scratch_pool
);
2530 anv_queue_init(device
, &device
->queue
);
2532 switch (device
->info
.gen
) {
2534 if (!device
->info
.is_haswell
)
2535 result
= gen7_init_device_state(device
);
2537 result
= gen75_init_device_state(device
);
2540 result
= gen8_init_device_state(device
);
2543 result
= gen9_init_device_state(device
);
2546 result
= gen10_init_device_state(device
);
2549 result
= gen11_init_device_state(device
);
2552 result
= gen12_init_device_state(device
);
2555 /* Shouldn't get here as we don't create physical devices for any other
2557 unreachable("unhandled gen");
2559 if (result
!= VK_SUCCESS
)
2560 goto fail_workaround_bo
;
2562 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
, true);
2564 anv_device_init_blorp(device
);
2566 anv_device_init_border_colors(device
);
2568 *pDevice
= anv_device_to_handle(device
);
2573 anv_queue_finish(&device
->queue
);
2574 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
2575 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
2576 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
2577 fail_binding_table_pool
:
2578 if (physical_device
->use_softpin
)
2579 anv_state_pool_finish(&device
->binding_table_pool
);
2580 fail_surface_state_pool
:
2581 anv_state_pool_finish(&device
->surface_state_pool
);
2582 fail_instruction_state_pool
:
2583 anv_state_pool_finish(&device
->instruction_state_pool
);
2584 fail_dynamic_state_pool
:
2585 anv_state_pool_finish(&device
->dynamic_state_pool
);
2587 anv_bo_cache_finish(&device
->bo_cache
);
2589 anv_bo_pool_finish(&device
->batch_bo_pool
);
2590 pthread_cond_destroy(&device
->queue_submit
);
2592 pthread_mutex_destroy(&device
->mutex
);
2594 anv_gem_destroy_context(device
, device
->context_id
);
2598 vk_free(&device
->alloc
, device
);
2603 void anv_DestroyDevice(
2605 const VkAllocationCallbacks
* pAllocator
)
2607 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2608 struct anv_physical_device
*physical_device
;
2613 physical_device
= &device
->instance
->physicalDevice
;
2615 anv_device_finish_blorp(device
);
2617 anv_pipeline_cache_finish(&device
->default_pipeline_cache
);
2619 anv_queue_finish(&device
->queue
);
2621 #ifdef HAVE_VALGRIND
2622 /* We only need to free these to prevent valgrind errors. The backing
2623 * BO will go away in a couple of lines so we don't actually leak.
2625 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
2626 anv_state_pool_free(&device
->dynamic_state_pool
, device
->slice_hash
);
2629 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
2631 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
2632 anv_vma_free(device
, &device
->workaround_bo
);
2633 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
2635 anv_vma_free(device
, &device
->trivial_batch_bo
);
2636 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
2637 if (device
->info
.gen
>= 10)
2638 anv_gem_close(device
, device
->hiz_clear_bo
.gem_handle
);
2640 if (physical_device
->use_softpin
)
2641 anv_state_pool_finish(&device
->binding_table_pool
);
2642 anv_state_pool_finish(&device
->surface_state_pool
);
2643 anv_state_pool_finish(&device
->instruction_state_pool
);
2644 anv_state_pool_finish(&device
->dynamic_state_pool
);
2646 anv_bo_cache_finish(&device
->bo_cache
);
2648 anv_bo_pool_finish(&device
->batch_bo_pool
);
2650 pthread_cond_destroy(&device
->queue_submit
);
2651 pthread_mutex_destroy(&device
->mutex
);
2653 anv_gem_destroy_context(device
, device
->context_id
);
2655 if (INTEL_DEBUG
& DEBUG_BATCH
)
2656 gen_batch_decode_ctx_finish(&device
->decoder_ctx
);
2660 vk_free(&device
->alloc
, device
);
2663 VkResult
anv_EnumerateInstanceLayerProperties(
2664 uint32_t* pPropertyCount
,
2665 VkLayerProperties
* pProperties
)
2667 if (pProperties
== NULL
) {
2668 *pPropertyCount
= 0;
2672 /* None supported at this time */
2673 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2676 VkResult
anv_EnumerateDeviceLayerProperties(
2677 VkPhysicalDevice physicalDevice
,
2678 uint32_t* pPropertyCount
,
2679 VkLayerProperties
* pProperties
)
2681 if (pProperties
== NULL
) {
2682 *pPropertyCount
= 0;
2686 /* None supported at this time */
2687 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2690 void anv_GetDeviceQueue(
2692 uint32_t queueNodeIndex
,
2693 uint32_t queueIndex
,
2696 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2698 assert(queueIndex
== 0);
2700 *pQueue
= anv_queue_to_handle(&device
->queue
);
2703 void anv_GetDeviceQueue2(
2705 const VkDeviceQueueInfo2
* pQueueInfo
,
2708 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2710 assert(pQueueInfo
->queueIndex
== 0);
2712 if (pQueueInfo
->flags
== device
->queue
.flags
)
2713 *pQueue
= anv_queue_to_handle(&device
->queue
);
2719 _anv_device_set_lost(struct anv_device
*device
,
2720 const char *file
, int line
,
2721 const char *msg
, ...)
2726 device
->_lost
= true;
2729 err
= __vk_errorv(device
->instance
, device
,
2730 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
2731 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
2734 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
2741 anv_device_query_status(struct anv_device
*device
)
2743 /* This isn't likely as most of the callers of this function already check
2744 * for it. However, it doesn't hurt to check and it potentially lets us
2747 if (anv_device_is_lost(device
))
2748 return VK_ERROR_DEVICE_LOST
;
2750 uint32_t active
, pending
;
2751 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
2753 /* We don't know the real error. */
2754 return anv_device_set_lost(device
, "get_reset_stats failed: %m");
2758 return anv_device_set_lost(device
, "GPU hung on one of our command buffers");
2759 } else if (pending
) {
2760 return anv_device_set_lost(device
, "GPU hung with commands in-flight");
2767 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
2769 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
2770 * Other usages of the BO (such as on different hardware) will not be
2771 * flagged as "busy" by this ioctl. Use with care.
2773 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
2775 return VK_NOT_READY
;
2776 } else if (ret
== -1) {
2777 /* We don't know the real error. */
2778 return anv_device_set_lost(device
, "gem wait failed: %m");
2781 /* Query for device status after the busy call. If the BO we're checking
2782 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
2783 * client because it clearly doesn't have valid data. Yes, this most
2784 * likely means an ioctl, but we just did an ioctl to query the busy status
2785 * so it's no great loss.
2787 return anv_device_query_status(device
);
2791 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
2794 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
2795 if (ret
== -1 && errno
== ETIME
) {
2797 } else if (ret
== -1) {
2798 /* We don't know the real error. */
2799 return anv_device_set_lost(device
, "gem wait failed: %m");
2802 /* Query for device status after the wait. If the BO we're waiting on got
2803 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
2804 * because it clearly doesn't have valid data. Yes, this most likely means
2805 * an ioctl, but we just did an ioctl to wait so it's no great loss.
2807 return anv_device_query_status(device
);
2810 VkResult
anv_DeviceWaitIdle(
2813 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2814 if (anv_device_is_lost(device
))
2815 return VK_ERROR_DEVICE_LOST
;
2817 struct anv_batch batch
;
2820 batch
.start
= batch
.next
= cmds
;
2821 batch
.end
= (void *) cmds
+ sizeof(cmds
);
2823 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2824 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2826 return anv_device_submit_simple_batch(device
, &batch
);
2830 anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
)
2832 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2835 pthread_mutex_lock(&device
->vma_mutex
);
2839 if (bo
->flags
& EXEC_OBJECT_SUPPORTS_48B_ADDRESS
&&
2840 device
->vma_hi_available
>= bo
->size
) {
2841 uint64_t addr
= util_vma_heap_alloc(&device
->vma_hi
, bo
->size
, 4096);
2843 bo
->offset
= gen_canonical_address(addr
);
2844 assert(addr
== gen_48b_address(bo
->offset
));
2845 device
->vma_hi_available
-= bo
->size
;
2849 if (bo
->offset
== 0 && device
->vma_lo_available
>= bo
->size
) {
2850 uint64_t addr
= util_vma_heap_alloc(&device
->vma_lo
, bo
->size
, 4096);
2852 bo
->offset
= gen_canonical_address(addr
);
2853 assert(addr
== gen_48b_address(bo
->offset
));
2854 device
->vma_lo_available
-= bo
->size
;
2858 pthread_mutex_unlock(&device
->vma_mutex
);
2860 return bo
->offset
!= 0;
2864 anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
)
2866 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2869 const uint64_t addr_48b
= gen_48b_address(bo
->offset
);
2871 pthread_mutex_lock(&device
->vma_mutex
);
2873 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
2874 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
2875 util_vma_heap_free(&device
->vma_lo
, addr_48b
, bo
->size
);
2876 device
->vma_lo_available
+= bo
->size
;
2878 ASSERTED
const struct anv_physical_device
*physical_device
=
2879 &device
->instance
->physicalDevice
;
2880 assert(addr_48b
>= physical_device
->memory
.heaps
[0].vma_start
&&
2881 addr_48b
< (physical_device
->memory
.heaps
[0].vma_start
+
2882 physical_device
->memory
.heaps
[0].vma_size
));
2883 util_vma_heap_free(&device
->vma_hi
, addr_48b
, bo
->size
);
2884 device
->vma_hi_available
+= bo
->size
;
2887 pthread_mutex_unlock(&device
->vma_mutex
);
2893 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
2895 uint32_t gem_handle
= anv_gem_create(device
, size
);
2897 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2899 anv_bo_init(bo
, gem_handle
, size
);
2904 VkResult
anv_AllocateMemory(
2906 const VkMemoryAllocateInfo
* pAllocateInfo
,
2907 const VkAllocationCallbacks
* pAllocator
,
2908 VkDeviceMemory
* pMem
)
2910 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2911 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2912 struct anv_device_memory
*mem
;
2913 VkResult result
= VK_SUCCESS
;
2915 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2917 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
2918 assert(pAllocateInfo
->allocationSize
> 0);
2920 if (pAllocateInfo
->allocationSize
> MAX_MEMORY_ALLOCATION_SIZE
)
2921 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2923 /* FINISHME: Fail if allocation request exceeds heap size. */
2925 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2926 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2928 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2930 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
2931 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
2935 mem
->host_ptr
= NULL
;
2937 uint64_t bo_flags
= 0;
2939 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
2940 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
2941 bo_flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2943 const struct wsi_memory_allocate_info
*wsi_info
=
2944 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2945 if (wsi_info
&& wsi_info
->implicit_sync
) {
2946 /* We need to set the WRITE flag on window system buffers so that GEM
2947 * will know we're writing to them and synchronize uses on other rings
2948 * (eg if the display server uses the blitter ring).
2950 bo_flags
|= EXEC_OBJECT_WRITE
;
2951 } else if (pdevice
->has_exec_async
) {
2952 bo_flags
|= EXEC_OBJECT_ASYNC
;
2955 if (pdevice
->use_softpin
)
2956 bo_flags
|= EXEC_OBJECT_PINNED
;
2958 const VkExportMemoryAllocateInfo
*export_info
=
2959 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
2961 /* Check if we need to support Android HW buffer export. If so,
2962 * create AHardwareBuffer and import memory from it.
2964 bool android_export
= false;
2965 if (export_info
&& export_info
->handleTypes
&
2966 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)
2967 android_export
= true;
2969 /* Android memory import. */
2970 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahw_import_info
=
2971 vk_find_struct_const(pAllocateInfo
->pNext
,
2972 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
2974 if (ahw_import_info
) {
2975 result
= anv_import_ahw_memory(_device
, mem
, ahw_import_info
);
2976 if (result
!= VK_SUCCESS
)
2980 } else if (android_export
) {
2981 result
= anv_create_ahw_memory(_device
, mem
, pAllocateInfo
);
2982 if (result
!= VK_SUCCESS
)
2985 const struct VkImportAndroidHardwareBufferInfoANDROID import_info
= {
2988 result
= anv_import_ahw_memory(_device
, mem
, &import_info
);
2989 if (result
!= VK_SUCCESS
)
2995 const VkImportMemoryFdInfoKHR
*fd_info
=
2996 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2998 /* The Vulkan spec permits handleType to be 0, in which case the struct is
3001 if (fd_info
&& fd_info
->handleType
) {
3002 /* At the moment, we support only the below handle types. */
3003 assert(fd_info
->handleType
==
3004 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3005 fd_info
->handleType
==
3006 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3008 result
= anv_bo_cache_import(device
, &device
->bo_cache
, fd_info
->fd
,
3009 bo_flags
| ANV_BO_EXTERNAL
, &mem
->bo
);
3010 if (result
!= VK_SUCCESS
)
3013 VkDeviceSize aligned_alloc_size
=
3014 align_u64(pAllocateInfo
->allocationSize
, 4096);
3016 /* For security purposes, we reject importing the bo if it's smaller
3017 * than the requested allocation size. This prevents a malicious client
3018 * from passing a buffer to a trusted client, lying about the size, and
3019 * telling the trusted client to try and texture from an image that goes
3020 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
3021 * in the trusted client. The trusted client can protect itself against
3022 * this sort of attack but only if it can trust the buffer size.
3024 if (mem
->bo
->size
< aligned_alloc_size
) {
3025 result
= vk_errorf(device
->instance
, device
,
3026 VK_ERROR_INVALID_EXTERNAL_HANDLE
,
3027 "aligned allocationSize too large for "
3028 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: "
3029 "%"PRIu64
"B > %"PRIu64
"B",
3030 aligned_alloc_size
, mem
->bo
->size
);
3031 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
3035 /* From the Vulkan spec:
3037 * "Importing memory from a file descriptor transfers ownership of
3038 * the file descriptor from the application to the Vulkan
3039 * implementation. The application must not perform any operations on
3040 * the file descriptor after a successful import."
3042 * If the import fails, we leave the file descriptor open.
3048 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3049 vk_find_struct_const(pAllocateInfo
->pNext
,
3050 IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3051 if (host_ptr_info
&& host_ptr_info
->handleType
) {
3052 if (host_ptr_info
->handleType
==
3053 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT
) {
3054 result
= vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3058 assert(host_ptr_info
->handleType
==
3059 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3061 result
= anv_bo_cache_import_host_ptr(
3062 device
, &device
->bo_cache
, host_ptr_info
->pHostPointer
,
3063 pAllocateInfo
->allocationSize
, bo_flags
, &mem
->bo
);
3065 if (result
!= VK_SUCCESS
)
3068 mem
->host_ptr
= host_ptr_info
->pHostPointer
;
3072 /* Regular allocate (not importing memory). */
3074 if (export_info
&& export_info
->handleTypes
)
3075 bo_flags
|= ANV_BO_EXTERNAL
;
3077 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
3078 pAllocateInfo
->allocationSize
, bo_flags
,
3080 if (result
!= VK_SUCCESS
)
3083 const VkMemoryDedicatedAllocateInfo
*dedicated_info
=
3084 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3085 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
3086 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
3088 /* Some legacy (non-modifiers) consumers need the tiling to be set on
3089 * the BO. In this case, we have a dedicated allocation.
3091 if (image
->needs_set_tiling
) {
3092 const uint32_t i915_tiling
=
3093 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
3094 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
3095 image
->planes
[0].surface
.isl
.row_pitch_B
,
3098 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
3099 return vk_errorf(device
->instance
, NULL
,
3100 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
3101 "failed to set BO tiling: %m");
3107 pthread_mutex_lock(&device
->mutex
);
3108 list_addtail(&mem
->link
, &device
->memory_objects
);
3109 pthread_mutex_unlock(&device
->mutex
);
3111 *pMem
= anv_device_memory_to_handle(mem
);
3113 p_atomic_add(&pdevice
->memory
.heaps
[mem
->type
->heapIndex
].used
,
3119 vk_free2(&device
->alloc
, pAllocator
, mem
);
3124 VkResult
anv_GetMemoryFdKHR(
3126 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
3129 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
3130 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
3132 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3134 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3135 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3137 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
3140 VkResult
anv_GetMemoryFdPropertiesKHR(
3142 VkExternalMemoryHandleTypeFlagBits handleType
,
3144 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
3146 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3147 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3149 switch (handleType
) {
3150 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
3151 /* dma-buf can be imported as any memory type */
3152 pMemoryFdProperties
->memoryTypeBits
=
3153 (1 << pdevice
->memory
.type_count
) - 1;
3157 /* The valid usage section for this function says:
3159 * "handleType must not be one of the handle types defined as
3162 * So opaque handle types fall into the default "unsupported" case.
3164 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3168 VkResult
anv_GetMemoryHostPointerPropertiesEXT(
3170 VkExternalMemoryHandleTypeFlagBits handleType
,
3171 const void* pHostPointer
,
3172 VkMemoryHostPointerPropertiesEXT
* pMemoryHostPointerProperties
)
3174 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3176 assert(pMemoryHostPointerProperties
->sType
==
3177 VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT
);
3179 switch (handleType
) {
3180 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
3181 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3183 /* Host memory can be imported as any memory type. */
3184 pMemoryHostPointerProperties
->memoryTypeBits
=
3185 (1ull << pdevice
->memory
.type_count
) - 1;
3190 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3194 void anv_FreeMemory(
3196 VkDeviceMemory _mem
,
3197 const VkAllocationCallbacks
* pAllocator
)
3199 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3200 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
3201 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3206 pthread_mutex_lock(&device
->mutex
);
3207 list_del(&mem
->link
);
3208 pthread_mutex_unlock(&device
->mutex
);
3211 anv_UnmapMemory(_device
, _mem
);
3213 p_atomic_add(&pdevice
->memory
.heaps
[mem
->type
->heapIndex
].used
,
3216 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
3218 #if defined(ANDROID) && ANDROID_API_LEVEL >= 26
3220 AHardwareBuffer_release(mem
->ahw
);
3223 vk_free2(&device
->alloc
, pAllocator
, mem
);
3226 VkResult
anv_MapMemory(
3228 VkDeviceMemory _memory
,
3229 VkDeviceSize offset
,
3231 VkMemoryMapFlags flags
,
3234 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3235 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3242 if (mem
->host_ptr
) {
3243 *ppData
= mem
->host_ptr
+ offset
;
3247 if (size
== VK_WHOLE_SIZE
)
3248 size
= mem
->bo
->size
- offset
;
3250 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
3252 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
3253 * assert(size != 0);
3254 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
3255 * equal to the size of the memory minus offset
3258 assert(offset
+ size
<= mem
->bo
->size
);
3260 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
3261 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
3262 * at a time is valid. We could just mmap up front and return an offset
3263 * pointer here, but that may exhaust virtual memory on 32 bit
3266 uint32_t gem_flags
= 0;
3268 if (!device
->info
.has_llc
&&
3269 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
3270 gem_flags
|= I915_MMAP_WC
;
3272 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
3273 uint64_t map_offset
= offset
& ~4095ull;
3274 assert(offset
>= map_offset
);
3275 uint64_t map_size
= (offset
+ size
) - map_offset
;
3277 /* Let's map whole pages */
3278 map_size
= align_u64(map_size
, 4096);
3280 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
3281 map_offset
, map_size
, gem_flags
);
3282 if (map
== MAP_FAILED
)
3283 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
3286 mem
->map_size
= map_size
;
3288 *ppData
= mem
->map
+ (offset
- map_offset
);
3293 void anv_UnmapMemory(
3295 VkDeviceMemory _memory
)
3297 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3299 if (mem
== NULL
|| mem
->host_ptr
)
3302 anv_gem_munmap(mem
->map
, mem
->map_size
);
3309 clflush_mapped_ranges(struct anv_device
*device
,
3311 const VkMappedMemoryRange
*ranges
)
3313 for (uint32_t i
= 0; i
< count
; i
++) {
3314 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
3315 if (ranges
[i
].offset
>= mem
->map_size
)
3318 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
3319 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
3323 VkResult
anv_FlushMappedMemoryRanges(
3325 uint32_t memoryRangeCount
,
3326 const VkMappedMemoryRange
* pMemoryRanges
)
3328 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3330 if (device
->info
.has_llc
)
3333 /* Make sure the writes we're flushing have landed. */
3334 __builtin_ia32_mfence();
3336 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3341 VkResult
anv_InvalidateMappedMemoryRanges(
3343 uint32_t memoryRangeCount
,
3344 const VkMappedMemoryRange
* pMemoryRanges
)
3346 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3348 if (device
->info
.has_llc
)
3351 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3353 /* Make sure no reads get moved up above the invalidate. */
3354 __builtin_ia32_mfence();
3359 void anv_GetBufferMemoryRequirements(
3362 VkMemoryRequirements
* pMemoryRequirements
)
3364 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3365 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3366 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3368 /* The Vulkan spec (git aaed022) says:
3370 * memoryTypeBits is a bitfield and contains one bit set for every
3371 * supported memory type for the resource. The bit `1<<i` is set if and
3372 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3373 * structure for the physical device is supported.
3375 uint32_t memory_types
= 0;
3376 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
3377 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
3378 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
3379 memory_types
|= (1u << i
);
3382 /* Base alignment requirement of a cache line */
3383 uint32_t alignment
= 16;
3385 /* We need an alignment of 32 for pushing UBOs */
3386 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
3387 alignment
= MAX2(alignment
, 32);
3389 pMemoryRequirements
->size
= buffer
->size
;
3390 pMemoryRequirements
->alignment
= alignment
;
3392 /* Storage and Uniform buffers should have their size aligned to
3393 * 32-bits to avoid boundary checks when last DWord is not complete.
3394 * This would ensure that not internal padding would be needed for
3397 if (device
->robust_buffer_access
&&
3398 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
3399 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
3400 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
3402 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3405 void anv_GetBufferMemoryRequirements2(
3407 const VkBufferMemoryRequirementsInfo2
* pInfo
,
3408 VkMemoryRequirements2
* pMemoryRequirements
)
3410 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
3411 &pMemoryRequirements
->memoryRequirements
);
3413 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3414 switch (ext
->sType
) {
3415 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3416 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
3417 requirements
->prefersDedicatedAllocation
= false;
3418 requirements
->requiresDedicatedAllocation
= false;
3423 anv_debug_ignored_stype(ext
->sType
);
3429 void anv_GetImageMemoryRequirements(
3432 VkMemoryRequirements
* pMemoryRequirements
)
3434 ANV_FROM_HANDLE(anv_image
, image
, _image
);
3435 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3436 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3438 /* The Vulkan spec (git aaed022) says:
3440 * memoryTypeBits is a bitfield and contains one bit set for every
3441 * supported memory type for the resource. The bit `1<<i` is set if and
3442 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3443 * structure for the physical device is supported.
3445 * All types are currently supported for images.
3447 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
3449 /* We must have image allocated or imported at this point. According to the
3450 * specification, external images must have been bound to memory before
3451 * calling GetImageMemoryRequirements.
3453 assert(image
->size
> 0);
3455 pMemoryRequirements
->size
= image
->size
;
3456 pMemoryRequirements
->alignment
= image
->alignment
;
3457 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3460 void anv_GetImageMemoryRequirements2(
3462 const VkImageMemoryRequirementsInfo2
* pInfo
,
3463 VkMemoryRequirements2
* pMemoryRequirements
)
3465 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3466 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
3468 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
3469 &pMemoryRequirements
->memoryRequirements
);
3471 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
3472 switch (ext
->sType
) {
3473 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
3474 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3475 const VkImagePlaneMemoryRequirementsInfo
*plane_reqs
=
3476 (const VkImagePlaneMemoryRequirementsInfo
*) ext
;
3477 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
3478 plane_reqs
->planeAspect
);
3480 assert(image
->planes
[plane
].offset
== 0);
3482 /* The Vulkan spec (git aaed022) says:
3484 * memoryTypeBits is a bitfield and contains one bit set for every
3485 * supported memory type for the resource. The bit `1<<i` is set
3486 * if and only if the memory type `i` in the
3487 * VkPhysicalDeviceMemoryProperties structure for the physical
3488 * device is supported.
3490 * All types are currently supported for images.
3492 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
3493 (1ull << pdevice
->memory
.type_count
) - 1;
3495 /* We must have image allocated or imported at this point. According to the
3496 * specification, external images must have been bound to memory before
3497 * calling GetImageMemoryRequirements.
3499 assert(image
->planes
[plane
].size
> 0);
3501 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
3502 pMemoryRequirements
->memoryRequirements
.alignment
=
3503 image
->planes
[plane
].alignment
;
3508 anv_debug_ignored_stype(ext
->sType
);
3513 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3514 switch (ext
->sType
) {
3515 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3516 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
3517 if (image
->needs_set_tiling
|| image
->external_format
) {
3518 /* If we need to set the tiling for external consumers, we need a
3519 * dedicated allocation.
3521 * See also anv_AllocateMemory.
3523 requirements
->prefersDedicatedAllocation
= true;
3524 requirements
->requiresDedicatedAllocation
= true;
3526 requirements
->prefersDedicatedAllocation
= false;
3527 requirements
->requiresDedicatedAllocation
= false;
3533 anv_debug_ignored_stype(ext
->sType
);
3539 void anv_GetImageSparseMemoryRequirements(
3542 uint32_t* pSparseMemoryRequirementCount
,
3543 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3545 *pSparseMemoryRequirementCount
= 0;
3548 void anv_GetImageSparseMemoryRequirements2(
3550 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
3551 uint32_t* pSparseMemoryRequirementCount
,
3552 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
3554 *pSparseMemoryRequirementCount
= 0;
3557 void anv_GetDeviceMemoryCommitment(
3559 VkDeviceMemory memory
,
3560 VkDeviceSize
* pCommittedMemoryInBytes
)
3562 *pCommittedMemoryInBytes
= 0;
3566 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
3568 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
3569 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
3571 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
3574 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
3575 buffer
->address
= (struct anv_address
) {
3577 .offset
= pBindInfo
->memoryOffset
,
3580 buffer
->address
= ANV_NULL_ADDRESS
;
3584 VkResult
anv_BindBufferMemory(
3587 VkDeviceMemory memory
,
3588 VkDeviceSize memoryOffset
)
3590 anv_bind_buffer_memory(
3591 &(VkBindBufferMemoryInfo
) {
3592 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3595 .memoryOffset
= memoryOffset
,
3601 VkResult
anv_BindBufferMemory2(
3603 uint32_t bindInfoCount
,
3604 const VkBindBufferMemoryInfo
* pBindInfos
)
3606 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
3607 anv_bind_buffer_memory(&pBindInfos
[i
]);
3612 VkResult
anv_QueueBindSparse(
3614 uint32_t bindInfoCount
,
3615 const VkBindSparseInfo
* pBindInfo
,
3618 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
3619 if (anv_device_is_lost(queue
->device
))
3620 return VK_ERROR_DEVICE_LOST
;
3622 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
3627 VkResult
anv_CreateEvent(
3629 const VkEventCreateInfo
* pCreateInfo
,
3630 const VkAllocationCallbacks
* pAllocator
,
3633 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3634 struct anv_state state
;
3635 struct anv_event
*event
;
3637 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
3639 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
3642 event
->state
= state
;
3643 event
->semaphore
= VK_EVENT_RESET
;
3645 if (!device
->info
.has_llc
) {
3646 /* Make sure the writes we're flushing have landed. */
3647 __builtin_ia32_mfence();
3648 __builtin_ia32_clflush(event
);
3651 *pEvent
= anv_event_to_handle(event
);
3656 void anv_DestroyEvent(
3659 const VkAllocationCallbacks
* pAllocator
)
3661 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3662 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3667 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
3670 VkResult
anv_GetEventStatus(
3674 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3675 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3677 if (anv_device_is_lost(device
))
3678 return VK_ERROR_DEVICE_LOST
;
3680 if (!device
->info
.has_llc
) {
3681 /* Invalidate read cache before reading event written by GPU. */
3682 __builtin_ia32_clflush(event
);
3683 __builtin_ia32_mfence();
3687 return event
->semaphore
;
3690 VkResult
anv_SetEvent(
3694 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3695 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3697 event
->semaphore
= VK_EVENT_SET
;
3699 if (!device
->info
.has_llc
) {
3700 /* Make sure the writes we're flushing have landed. */
3701 __builtin_ia32_mfence();
3702 __builtin_ia32_clflush(event
);
3708 VkResult
anv_ResetEvent(
3712 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3713 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3715 event
->semaphore
= VK_EVENT_RESET
;
3717 if (!device
->info
.has_llc
) {
3718 /* Make sure the writes we're flushing have landed. */
3719 __builtin_ia32_mfence();
3720 __builtin_ia32_clflush(event
);
3728 VkResult
anv_CreateBuffer(
3730 const VkBufferCreateInfo
* pCreateInfo
,
3731 const VkAllocationCallbacks
* pAllocator
,
3734 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3735 struct anv_buffer
*buffer
;
3737 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3739 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3740 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3742 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3744 buffer
->size
= pCreateInfo
->size
;
3745 buffer
->usage
= pCreateInfo
->usage
;
3746 buffer
->address
= ANV_NULL_ADDRESS
;
3748 *pBuffer
= anv_buffer_to_handle(buffer
);
3753 void anv_DestroyBuffer(
3756 const VkAllocationCallbacks
* pAllocator
)
3758 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3759 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3764 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3767 VkDeviceAddress
anv_GetBufferDeviceAddressEXT(
3769 const VkBufferDeviceAddressInfoEXT
* pInfo
)
3771 ANV_FROM_HANDLE(anv_buffer
, buffer
, pInfo
->buffer
);
3773 assert(buffer
->address
.bo
->flags
& EXEC_OBJECT_PINNED
);
3775 return anv_address_physical(buffer
->address
);
3779 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
3780 enum isl_format format
,
3781 struct anv_address address
,
3782 uint32_t range
, uint32_t stride
)
3784 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
3785 .address
= anv_address_physical(address
),
3786 .mocs
= device
->default_mocs
,
3789 .swizzle
= ISL_SWIZZLE_IDENTITY
,
3790 .stride_B
= stride
);
3793 void anv_DestroySampler(
3796 const VkAllocationCallbacks
* pAllocator
)
3798 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3799 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
3804 if (sampler
->bindless_state
.map
) {
3805 anv_state_pool_free(&device
->dynamic_state_pool
,
3806 sampler
->bindless_state
);
3809 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3812 VkResult
anv_CreateFramebuffer(
3814 const VkFramebufferCreateInfo
* pCreateInfo
,
3815 const VkAllocationCallbacks
* pAllocator
,
3816 VkFramebuffer
* pFramebuffer
)
3818 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3819 struct anv_framebuffer
*framebuffer
;
3821 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3823 size_t size
= sizeof(*framebuffer
);
3825 /* VK_KHR_imageless_framebuffer extension says:
3827 * If flags includes VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR,
3828 * parameter pAttachments is ignored.
3830 if (!(pCreateInfo
->flags
& VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR
)) {
3831 size
+= sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
3832 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3833 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3834 if (framebuffer
== NULL
)
3835 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3837 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3838 ANV_FROM_HANDLE(anv_image_view
, iview
, pCreateInfo
->pAttachments
[i
]);
3839 framebuffer
->attachments
[i
] = iview
;
3841 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3843 assert(device
->enabled_extensions
.KHR_imageless_framebuffer
);
3844 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3845 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3846 if (framebuffer
== NULL
)
3847 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3849 framebuffer
->attachment_count
= 0;
3852 framebuffer
->width
= pCreateInfo
->width
;
3853 framebuffer
->height
= pCreateInfo
->height
;
3854 framebuffer
->layers
= pCreateInfo
->layers
;
3856 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
3861 void anv_DestroyFramebuffer(
3864 const VkAllocationCallbacks
* pAllocator
)
3866 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3867 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
3872 vk_free2(&device
->alloc
, pAllocator
, fb
);
3875 static const VkTimeDomainEXT anv_time_domains
[] = {
3876 VK_TIME_DOMAIN_DEVICE_EXT
,
3877 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
3878 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
3881 VkResult
anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
3882 VkPhysicalDevice physicalDevice
,
3883 uint32_t *pTimeDomainCount
,
3884 VkTimeDomainEXT
*pTimeDomains
)
3887 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
3889 for (d
= 0; d
< ARRAY_SIZE(anv_time_domains
); d
++) {
3890 vk_outarray_append(&out
, i
) {
3891 *i
= anv_time_domains
[d
];
3895 return vk_outarray_status(&out
);
3899 anv_clock_gettime(clockid_t clock_id
)
3901 struct timespec current
;
3904 ret
= clock_gettime(clock_id
, ¤t
);
3905 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
3906 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3910 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
3913 #define TIMESTAMP 0x2358
3915 VkResult
anv_GetCalibratedTimestampsEXT(
3917 uint32_t timestampCount
,
3918 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
3919 uint64_t *pTimestamps
,
3920 uint64_t *pMaxDeviation
)
3922 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3923 uint64_t timestamp_frequency
= device
->info
.timestamp_frequency
;
3926 uint64_t begin
, end
;
3927 uint64_t max_clock_period
= 0;
3929 begin
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3931 for (d
= 0; d
< timestampCount
; d
++) {
3932 switch (pTimestampInfos
[d
].timeDomain
) {
3933 case VK_TIME_DOMAIN_DEVICE_EXT
:
3934 ret
= anv_gem_reg_read(device
, TIMESTAMP
| 1,
3938 return anv_device_set_lost(device
, "Failed to read the TIMESTAMP "
3941 uint64_t device_period
= DIV_ROUND_UP(1000000000, timestamp_frequency
);
3942 max_clock_period
= MAX2(max_clock_period
, device_period
);
3944 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
3945 pTimestamps
[d
] = anv_clock_gettime(CLOCK_MONOTONIC
);
3946 max_clock_period
= MAX2(max_clock_period
, 1);
3949 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
3950 pTimestamps
[d
] = begin
;
3958 end
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3961 * The maximum deviation is the sum of the interval over which we
3962 * perform the sampling and the maximum period of any sampled
3963 * clock. That's because the maximum skew between any two sampled
3964 * clock edges is when the sampled clock with the largest period is
3965 * sampled at the end of that period but right at the beginning of the
3966 * sampling interval and some other clock is sampled right at the
3967 * begining of its sampling period and right at the end of the
3968 * sampling interval. Let's assume the GPU has the longest clock
3969 * period and that the application is sampling GPU and monotonic:
3972 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
3973 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3977 * GPU -----_____-----_____-----_____-----_____
3980 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
3981 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3983 * Interval <----------------->
3984 * Deviation <-------------------------->
3988 * m = read(monotonic) 2
3991 * We round the sample interval up by one tick to cover sampling error
3992 * in the interval clock
3995 uint64_t sample_interval
= end
- begin
+ 1;
3997 *pMaxDeviation
= sample_interval
+ max_clock_period
;
4002 /* vk_icd.h does not declare this function, so we declare it here to
4003 * suppress Wmissing-prototypes.
4005 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4006 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
4008 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4009 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
4011 /* For the full details on loader interface versioning, see
4012 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4013 * What follows is a condensed summary, to help you navigate the large and
4014 * confusing official doc.
4016 * - Loader interface v0 is incompatible with later versions. We don't
4019 * - In loader interface v1:
4020 * - The first ICD entrypoint called by the loader is
4021 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4023 * - The ICD must statically expose no other Vulkan symbol unless it is
4024 * linked with -Bsymbolic.
4025 * - Each dispatchable Vulkan handle created by the ICD must be
4026 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4027 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4028 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4029 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4030 * such loader-managed surfaces.
4032 * - Loader interface v2 differs from v1 in:
4033 * - The first ICD entrypoint called by the loader is
4034 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4035 * statically expose this entrypoint.
4037 * - Loader interface v3 differs from v2 in:
4038 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4039 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4040 * because the loader no longer does so.
4042 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);