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
,
785 *pInstance
= anv_instance_to_handle(instance
);
790 void anv_DestroyInstance(
791 VkInstance _instance
,
792 const VkAllocationCallbacks
* pAllocator
)
794 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
799 if (instance
->physicalDeviceCount
> 0) {
800 /* We support at most one physical device. */
801 assert(instance
->physicalDeviceCount
== 1);
802 anv_physical_device_finish(&instance
->physicalDevice
);
805 vk_free(&instance
->alloc
, (char *)instance
->app_info
.app_name
);
806 vk_free(&instance
->alloc
, (char *)instance
->app_info
.engine_name
);
808 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
810 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
812 glsl_type_singleton_decref();
815 driDestroyOptionCache(&instance
->dri_options
);
816 driDestroyOptionInfo(&instance
->available_dri_options
);
818 vk_free(&instance
->alloc
, instance
);
822 anv_enumerate_devices(struct anv_instance
*instance
)
824 /* TODO: Check for more devices ? */
825 drmDevicePtr devices
[8];
826 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
829 instance
->physicalDeviceCount
= 0;
831 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
833 return VK_ERROR_INCOMPATIBLE_DRIVER
;
835 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
836 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
837 devices
[i
]->bustype
== DRM_BUS_PCI
&&
838 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
840 result
= anv_physical_device_init(&instance
->physicalDevice
,
841 instance
, devices
[i
]);
842 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
846 drmFreeDevices(devices
, max_devices
);
848 if (result
== VK_SUCCESS
)
849 instance
->physicalDeviceCount
= 1;
855 anv_instance_ensure_physical_device(struct anv_instance
*instance
)
857 if (instance
->physicalDeviceCount
< 0) {
858 VkResult result
= anv_enumerate_devices(instance
);
859 if (result
!= VK_SUCCESS
&&
860 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
867 VkResult
anv_EnumeratePhysicalDevices(
868 VkInstance _instance
,
869 uint32_t* pPhysicalDeviceCount
,
870 VkPhysicalDevice
* pPhysicalDevices
)
872 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
873 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
875 VkResult result
= anv_instance_ensure_physical_device(instance
);
876 if (result
!= VK_SUCCESS
)
879 if (instance
->physicalDeviceCount
== 0)
882 assert(instance
->physicalDeviceCount
== 1);
883 vk_outarray_append(&out
, i
) {
884 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
887 return vk_outarray_status(&out
);
890 VkResult
anv_EnumeratePhysicalDeviceGroups(
891 VkInstance _instance
,
892 uint32_t* pPhysicalDeviceGroupCount
,
893 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
895 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
896 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
897 pPhysicalDeviceGroupCount
);
899 VkResult result
= anv_instance_ensure_physical_device(instance
);
900 if (result
!= VK_SUCCESS
)
903 if (instance
->physicalDeviceCount
== 0)
906 assert(instance
->physicalDeviceCount
== 1);
908 vk_outarray_append(&out
, p
) {
909 p
->physicalDeviceCount
= 1;
910 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
911 p
->physicalDevices
[0] =
912 anv_physical_device_to_handle(&instance
->physicalDevice
);
913 p
->subsetAllocation
= false;
915 vk_foreach_struct(ext
, p
->pNext
)
916 anv_debug_ignored_stype(ext
->sType
);
919 return vk_outarray_status(&out
);
922 void anv_GetPhysicalDeviceFeatures(
923 VkPhysicalDevice physicalDevice
,
924 VkPhysicalDeviceFeatures
* pFeatures
)
926 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
928 *pFeatures
= (VkPhysicalDeviceFeatures
) {
929 .robustBufferAccess
= true,
930 .fullDrawIndexUint32
= true,
931 .imageCubeArray
= true,
932 .independentBlend
= true,
933 .geometryShader
= true,
934 .tessellationShader
= true,
935 .sampleRateShading
= true,
936 .dualSrcBlend
= true,
938 .multiDrawIndirect
= true,
939 .drawIndirectFirstInstance
= true,
941 .depthBiasClamp
= true,
942 .fillModeNonSolid
= true,
943 .depthBounds
= false,
947 .multiViewport
= true,
948 .samplerAnisotropy
= true,
949 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
950 pdevice
->info
.is_baytrail
,
951 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
952 .textureCompressionBC
= true,
953 .occlusionQueryPrecise
= true,
954 .pipelineStatisticsQuery
= true,
955 .fragmentStoresAndAtomics
= true,
956 .shaderTessellationAndGeometryPointSize
= true,
957 .shaderImageGatherExtended
= true,
958 .shaderStorageImageExtendedFormats
= true,
959 .shaderStorageImageMultisample
= false,
960 .shaderStorageImageReadWithoutFormat
= false,
961 .shaderStorageImageWriteWithoutFormat
= true,
962 .shaderUniformBufferArrayDynamicIndexing
= true,
963 .shaderSampledImageArrayDynamicIndexing
= true,
964 .shaderStorageBufferArrayDynamicIndexing
= true,
965 .shaderStorageImageArrayDynamicIndexing
= true,
966 .shaderClipDistance
= true,
967 .shaderCullDistance
= true,
968 .shaderFloat64
= pdevice
->info
.gen
>= 8 &&
969 pdevice
->info
.has_64bit_types
,
970 .shaderInt64
= pdevice
->info
.gen
>= 8 &&
971 pdevice
->info
.has_64bit_types
,
972 .shaderInt16
= pdevice
->info
.gen
>= 8,
973 .shaderResourceMinLod
= pdevice
->info
.gen
>= 9,
974 .variableMultisampleRate
= true,
975 .inheritedQueries
= true,
978 /* We can't do image stores in vec4 shaders */
979 pFeatures
->vertexPipelineStoresAndAtomics
=
980 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
981 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
983 struct anv_app_info
*app_info
= &pdevice
->instance
->app_info
;
985 /* The new DOOM and Wolfenstein games require depthBounds without
986 * checking for it. They seem to run fine without it so just claim it's
987 * there and accept the consequences.
989 if (app_info
->engine_name
&& strcmp(app_info
->engine_name
, "idTech") == 0)
990 pFeatures
->depthBounds
= true;
993 void anv_GetPhysicalDeviceFeatures2(
994 VkPhysicalDevice physicalDevice
,
995 VkPhysicalDeviceFeatures2
* pFeatures
)
997 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
998 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1000 vk_foreach_struct(ext
, pFeatures
->pNext
) {
1001 switch (ext
->sType
) {
1002 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
1003 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
1004 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
1005 features
->storageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
1006 features
->uniformAndStorageBuffer8BitAccess
= pdevice
->info
.gen
>= 8;
1007 features
->storagePushConstant8
= pdevice
->info
.gen
>= 8;
1011 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
1012 VkPhysicalDevice16BitStorageFeatures
*features
=
1013 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
1014 features
->storageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
1015 features
->uniformAndStorageBuffer16BitAccess
= pdevice
->info
.gen
>= 8;
1016 features
->storagePushConstant16
= pdevice
->info
.gen
>= 8;
1017 features
->storageInputOutput16
= false;
1021 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1022 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
= (void *)ext
;
1023 features
->bufferDeviceAddress
= pdevice
->has_a64_buffer_access
;
1024 features
->bufferDeviceAddressCaptureReplay
= false;
1025 features
->bufferDeviceAddressMultiDevice
= false;
1029 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1030 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1031 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1032 features
->computeDerivativeGroupQuads
= true;
1033 features
->computeDerivativeGroupLinear
= true;
1037 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
1038 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
1039 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
1040 features
->conditionalRendering
= pdevice
->info
.gen
>= 8 ||
1041 pdevice
->info
.is_haswell
;
1042 features
->inheritedConditionalRendering
= pdevice
->info
.gen
>= 8 ||
1043 pdevice
->info
.is_haswell
;
1047 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1048 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1049 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1050 features
->depthClipEnable
= true;
1054 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
1055 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
= (void *)ext
;
1056 features
->shaderFloat16
= pdevice
->info
.gen
>= 8;
1057 features
->shaderInt8
= pdevice
->info
.gen
>= 8;
1061 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_INTERLOCK_FEATURES_EXT
: {
1062 VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*features
=
1063 (VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT
*)ext
;
1064 features
->fragmentShaderSampleInterlock
= pdevice
->info
.gen
>= 9;
1065 features
->fragmentShaderPixelInterlock
= pdevice
->info
.gen
>= 9;
1066 features
->fragmentShaderShadingRateInterlock
= false;
1070 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
1071 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
1072 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
1073 features
->hostQueryReset
= true;
1077 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
1078 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
1079 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
1080 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
1081 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
1082 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
1083 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
1084 features
->shaderSampledImageArrayNonUniformIndexing
= true;
1085 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
1086 features
->shaderStorageImageArrayNonUniformIndexing
= true;
1087 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
1088 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
1089 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
1090 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
1091 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
1092 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
1093 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
1094 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
1095 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
1096 features
->descriptorBindingUpdateUnusedWhilePending
= true;
1097 features
->descriptorBindingPartiallyBound
= true;
1098 features
->descriptorBindingVariableDescriptorCount
= false;
1099 features
->runtimeDescriptorArray
= true;
1103 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1104 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1105 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1106 features
->indexTypeUint8
= true;
1110 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1111 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1112 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1113 features
->inlineUniformBlock
= true;
1114 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1118 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1119 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1120 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1121 features
->rectangularLines
= true;
1122 features
->bresenhamLines
= true;
1123 features
->smoothLines
= true;
1124 features
->stippledRectangularLines
= false;
1125 features
->stippledBresenhamLines
= true;
1126 features
->stippledSmoothLines
= false;
1130 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
1131 VkPhysicalDeviceMultiviewFeatures
*features
=
1132 (VkPhysicalDeviceMultiviewFeatures
*)ext
;
1133 features
->multiview
= true;
1134 features
->multiviewGeometryShader
= true;
1135 features
->multiviewTessellationShader
= true;
1139 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1140 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1141 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1142 features
->imagelessFramebuffer
= true;
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1147 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1148 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1149 features
->pipelineExecutableInfo
= true;
1153 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
1154 VkPhysicalDeviceProtectedMemoryFeatures
*features
= (void *)ext
;
1155 features
->protectedMemory
= false;
1159 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
1160 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
1161 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
1162 features
->samplerYcbcrConversion
= true;
1166 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
1167 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
1168 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
1169 features
->scalarBlockLayout
= true;
1173 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
1174 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
= (void *)ext
;
1175 features
->shaderBufferInt64Atomics
=
1176 pdevice
->info
.gen
>= 9 && pdevice
->use_softpin
;
1177 features
->shaderSharedInt64Atomics
= VK_FALSE
;
1181 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1182 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
= (void *)ext
;
1183 features
->shaderDemoteToHelperInvocation
= true;
1187 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
1188 VkPhysicalDeviceShaderDrawParametersFeatures
*features
= (void *)ext
;
1189 features
->shaderDrawParameters
= true;
1193 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1194 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1195 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1196 features
->subgroupSizeControl
= true;
1197 features
->computeFullSubgroups
= true;
1201 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1202 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1203 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1204 features
->texelBufferAlignment
= true;
1208 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
1209 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
1210 features
->variablePointersStorageBuffer
= true;
1211 features
->variablePointers
= true;
1215 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1216 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1217 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1218 features
->transformFeedback
= true;
1219 features
->geometryStreams
= true;
1223 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1224 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1225 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1226 features
->uniformBufferStandardLayout
= true;
1230 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
1231 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1232 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1233 features
->vertexAttributeInstanceRateDivisor
= true;
1234 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1238 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1239 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1240 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1241 features
->ycbcrImageArrays
= true;
1246 anv_debug_ignored_stype(ext
->sType
);
1252 #define MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS 64
1254 #define MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS 64
1255 #define MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS 256
1257 void anv_GetPhysicalDeviceProperties(
1258 VkPhysicalDevice physicalDevice
,
1259 VkPhysicalDeviceProperties
* pProperties
)
1261 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1262 const struct gen_device_info
*devinfo
= &pdevice
->info
;
1264 /* See assertions made when programming the buffer surface state. */
1265 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
1266 (1ul << 30) : (1ul << 27);
1268 const uint32_t max_ssbos
= pdevice
->has_a64_buffer_access
? UINT16_MAX
: 64;
1269 const uint32_t max_textures
=
1270 pdevice
->has_bindless_images
? UINT16_MAX
: 128;
1271 const uint32_t max_samplers
=
1272 pdevice
->has_bindless_samplers
? UINT16_MAX
:
1273 (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ? 128 : 16;
1274 const uint32_t max_images
=
1275 pdevice
->has_bindless_images
? UINT16_MAX
: MAX_IMAGES
;
1277 /* The moment we have anything bindless, claim a high per-stage limit */
1278 const uint32_t max_per_stage
=
1279 pdevice
->has_a64_buffer_access
? UINT32_MAX
:
1280 MAX_BINDING_TABLE_SIZE
- MAX_RTS
;
1282 const uint32_t max_workgroup_size
= 32 * devinfo
->max_cs_threads
;
1284 VkSampleCountFlags sample_counts
=
1285 isl_device_get_sample_counts(&pdevice
->isl_dev
);
1288 VkPhysicalDeviceLimits limits
= {
1289 .maxImageDimension1D
= (1 << 14),
1290 .maxImageDimension2D
= (1 << 14),
1291 .maxImageDimension3D
= (1 << 11),
1292 .maxImageDimensionCube
= (1 << 14),
1293 .maxImageArrayLayers
= (1 << 11),
1294 .maxTexelBufferElements
= 128 * 1024 * 1024,
1295 .maxUniformBufferRange
= (1ul << 27),
1296 .maxStorageBufferRange
= max_raw_buffer_sz
,
1297 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1298 .maxMemoryAllocationCount
= UINT32_MAX
,
1299 .maxSamplerAllocationCount
= 64 * 1024,
1300 .bufferImageGranularity
= 64, /* A cache line */
1301 .sparseAddressSpaceSize
= 0,
1302 .maxBoundDescriptorSets
= MAX_SETS
,
1303 .maxPerStageDescriptorSamplers
= max_samplers
,
1304 .maxPerStageDescriptorUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
,
1305 .maxPerStageDescriptorStorageBuffers
= max_ssbos
,
1306 .maxPerStageDescriptorSampledImages
= max_textures
,
1307 .maxPerStageDescriptorStorageImages
= max_images
,
1308 .maxPerStageDescriptorInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
,
1309 .maxPerStageResources
= max_per_stage
,
1310 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
1311 .maxDescriptorSetUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
, /* number of stages * maxPerStageDescriptorUniformBuffers */
1312 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1313 .maxDescriptorSetStorageBuffers
= 6 * max_ssbos
, /* number of stages * maxPerStageDescriptorStorageBuffers */
1314 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
1315 .maxDescriptorSetSampledImages
= 6 * max_textures
, /* number of stages * maxPerStageDescriptorSampledImages */
1316 .maxDescriptorSetStorageImages
= 6 * max_images
, /* number of stages * maxPerStageDescriptorStorageImages */
1317 .maxDescriptorSetInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
,
1318 .maxVertexInputAttributes
= MAX_VBS
,
1319 .maxVertexInputBindings
= MAX_VBS
,
1320 .maxVertexInputAttributeOffset
= 2047,
1321 .maxVertexInputBindingStride
= 2048,
1322 .maxVertexOutputComponents
= 128,
1323 .maxTessellationGenerationLevel
= 64,
1324 .maxTessellationPatchSize
= 32,
1325 .maxTessellationControlPerVertexInputComponents
= 128,
1326 .maxTessellationControlPerVertexOutputComponents
= 128,
1327 .maxTessellationControlPerPatchOutputComponents
= 128,
1328 .maxTessellationControlTotalOutputComponents
= 2048,
1329 .maxTessellationEvaluationInputComponents
= 128,
1330 .maxTessellationEvaluationOutputComponents
= 128,
1331 .maxGeometryShaderInvocations
= 32,
1332 .maxGeometryInputComponents
= 64,
1333 .maxGeometryOutputComponents
= 128,
1334 .maxGeometryOutputVertices
= 256,
1335 .maxGeometryTotalOutputComponents
= 1024,
1336 .maxFragmentInputComponents
= 116, /* 128 components - (PSIZ, CLIP_DIST0, CLIP_DIST1) */
1337 .maxFragmentOutputAttachments
= 8,
1338 .maxFragmentDualSrcAttachments
= 1,
1339 .maxFragmentCombinedOutputResources
= 8,
1340 .maxComputeSharedMemorySize
= 64 * 1024,
1341 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1342 .maxComputeWorkGroupInvocations
= max_workgroup_size
,
1343 .maxComputeWorkGroupSize
= {
1348 .subPixelPrecisionBits
= 8,
1349 .subTexelPrecisionBits
= 8,
1350 .mipmapPrecisionBits
= 8,
1351 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1352 .maxDrawIndirectCount
= UINT32_MAX
,
1353 .maxSamplerLodBias
= 16,
1354 .maxSamplerAnisotropy
= 16,
1355 .maxViewports
= MAX_VIEWPORTS
,
1356 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1357 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1358 .viewportSubPixelBits
= 13, /* We take a float? */
1359 .minMemoryMapAlignment
= 4096, /* A page */
1360 /* The dataport requires texel alignment so we need to assume a worst
1361 * case of R32G32B32A32 which is 16 bytes.
1363 .minTexelBufferOffsetAlignment
= 16,
1364 /* We need 16 for UBO block reads to work and 32 for push UBOs */
1365 .minUniformBufferOffsetAlignment
= 32,
1366 .minStorageBufferOffsetAlignment
= 4,
1367 .minTexelOffset
= -8,
1368 .maxTexelOffset
= 7,
1369 .minTexelGatherOffset
= -32,
1370 .maxTexelGatherOffset
= 31,
1371 .minInterpolationOffset
= -0.5,
1372 .maxInterpolationOffset
= 0.4375,
1373 .subPixelInterpolationOffsetBits
= 4,
1374 .maxFramebufferWidth
= (1 << 14),
1375 .maxFramebufferHeight
= (1 << 14),
1376 .maxFramebufferLayers
= (1 << 11),
1377 .framebufferColorSampleCounts
= sample_counts
,
1378 .framebufferDepthSampleCounts
= sample_counts
,
1379 .framebufferStencilSampleCounts
= sample_counts
,
1380 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1381 .maxColorAttachments
= MAX_RTS
,
1382 .sampledImageColorSampleCounts
= sample_counts
,
1383 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1384 .sampledImageDepthSampleCounts
= sample_counts
,
1385 .sampledImageStencilSampleCounts
= sample_counts
,
1386 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1387 .maxSampleMaskWords
= 1,
1388 .timestampComputeAndGraphics
= true,
1389 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
1390 .maxClipDistances
= 8,
1391 .maxCullDistances
= 8,
1392 .maxCombinedClipAndCullDistances
= 8,
1393 .discreteQueuePriorities
= 2,
1394 .pointSizeRange
= { 0.125, 255.875 },
1397 (devinfo
->gen
>= 9 || devinfo
->is_cherryview
) ?
1398 2047.9921875 : 7.9921875,
1400 .pointSizeGranularity
= (1.0 / 8.0),
1401 .lineWidthGranularity
= (1.0 / 128.0),
1402 .strictLines
= false,
1403 .standardSampleLocations
= true,
1404 .optimalBufferCopyOffsetAlignment
= 128,
1405 .optimalBufferCopyRowPitchAlignment
= 128,
1406 .nonCoherentAtomSize
= 64,
1409 *pProperties
= (VkPhysicalDeviceProperties
) {
1410 .apiVersion
= anv_physical_device_api_version(pdevice
),
1411 .driverVersion
= vk_get_driver_version(),
1413 .deviceID
= pdevice
->chipset_id
,
1414 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1416 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
1419 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
1420 "%s", pdevice
->name
);
1421 memcpy(pProperties
->pipelineCacheUUID
,
1422 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
1425 void anv_GetPhysicalDeviceProperties2(
1426 VkPhysicalDevice physicalDevice
,
1427 VkPhysicalDeviceProperties2
* pProperties
)
1429 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
1431 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1433 vk_foreach_struct(ext
, pProperties
->pNext
) {
1434 switch (ext
->sType
) {
1435 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1436 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*props
=
1437 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1439 /* We support all of the depth resolve modes */
1440 props
->supportedDepthResolveModes
=
1441 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1442 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1443 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1444 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1446 /* Average doesn't make sense for stencil so we don't support that */
1447 props
->supportedStencilResolveModes
=
1448 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
;
1449 if (pdevice
->info
.gen
>= 8) {
1450 /* The advanced stencil resolve modes currently require stencil
1451 * sampling be supported by the hardware.
1453 props
->supportedStencilResolveModes
|=
1454 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1455 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1458 props
->independentResolveNone
= true;
1459 props
->independentResolve
= true;
1463 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1464 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*props
=
1465 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1467 /* It's a bit hard to exactly map our implementation to the limits
1468 * described here. The bindless surface handle in the extended
1469 * message descriptors is 20 bits and it's an index into the table of
1470 * RENDER_SURFACE_STATE structs that starts at bindless surface base
1471 * address. Given that most things consume two surface states per
1472 * view (general/sampled for textures and write-only/read-write for
1473 * images), we claim 2^19 things.
1475 * For SSBOs, we just use A64 messages so there is no real limit
1476 * there beyond the limit on the total size of a descriptor set.
1478 const unsigned max_bindless_views
= 1 << 19;
1480 props
->maxUpdateAfterBindDescriptorsInAllPools
= max_bindless_views
;
1481 props
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1482 props
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1483 props
->shaderStorageBufferArrayNonUniformIndexingNative
= true;
1484 props
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1485 props
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1486 props
->robustBufferAccessUpdateAfterBind
= true;
1487 props
->quadDivergentImplicitLod
= false;
1488 props
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_bindless_views
;
1489 props
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1490 props
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1491 props
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_bindless_views
;
1492 props
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_bindless_views
;
1493 props
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= MAX_PER_STAGE_DESCRIPTOR_INPUT_ATTACHMENTS
;
1494 props
->maxPerStageUpdateAfterBindResources
= UINT32_MAX
;
1495 props
->maxDescriptorSetUpdateAfterBindSamplers
= max_bindless_views
;
1496 props
->maxDescriptorSetUpdateAfterBindUniformBuffers
= 6 * MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BUFFERS
;
1497 props
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1498 props
->maxDescriptorSetUpdateAfterBindStorageBuffers
= UINT32_MAX
;
1499 props
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2;
1500 props
->maxDescriptorSetUpdateAfterBindSampledImages
= max_bindless_views
;
1501 props
->maxDescriptorSetUpdateAfterBindStorageImages
= max_bindless_views
;
1502 props
->maxDescriptorSetUpdateAfterBindInputAttachments
= MAX_DESCRIPTOR_SET_INPUT_ATTACHMENTS
;
1506 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1507 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1508 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1510 driver_props
->driverID
= VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA_KHR
;
1511 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
,
1512 "Intel open-source Mesa driver");
1514 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1515 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
);
1517 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1526 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1527 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*props
=
1528 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1529 /* Userptr needs page aligned memory. */
1530 props
->minImportedHostPointerAlignment
= 4096;
1534 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1535 VkPhysicalDeviceIDProperties
*id_props
=
1536 (VkPhysicalDeviceIDProperties
*)ext
;
1537 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1538 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1539 /* The LUID is for Windows. */
1540 id_props
->deviceLUIDValid
= false;
1544 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1545 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1546 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1547 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1548 props
->maxPerStageDescriptorInlineUniformBlocks
=
1549 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1550 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
=
1551 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1552 props
->maxDescriptorSetInlineUniformBlocks
=
1553 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1554 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
=
1555 MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS
;
1559 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1560 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1561 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1562 /* In the Skylake PRM Vol. 7, subsection titled "GIQ (Diamond)
1563 * Sampling Rules - Legacy Mode", it says the following:
1565 * "Note that the device divides a pixel into a 16x16 array of
1566 * subpixels, referenced by their upper left corners."
1568 * This is the only known reference in the PRMs to the subpixel
1569 * precision of line rasterization and a "16x16 array of subpixels"
1570 * implies 4 subpixel precision bits. Empirical testing has shown
1571 * that 4 subpixel precision bits applies to all line rasterization
1574 props
->lineSubPixelPrecisionBits
= 4;
1578 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1579 VkPhysicalDeviceMaintenance3Properties
*props
=
1580 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1581 /* This value doesn't matter for us today as our per-stage
1582 * descriptors are the real limit.
1584 props
->maxPerSetDescriptors
= 1024;
1585 props
->maxMemoryAllocationSize
= MAX_MEMORY_ALLOCATION_SIZE
;
1589 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1590 VkPhysicalDeviceMultiviewProperties
*properties
=
1591 (VkPhysicalDeviceMultiviewProperties
*)ext
;
1592 properties
->maxMultiviewViewCount
= 16;
1593 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
1597 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1598 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1599 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1600 properties
->pciDomain
= pdevice
->pci_info
.domain
;
1601 properties
->pciBus
= pdevice
->pci_info
.bus
;
1602 properties
->pciDevice
= pdevice
->pci_info
.device
;
1603 properties
->pciFunction
= pdevice
->pci_info
.function
;
1607 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1608 VkPhysicalDevicePointClippingProperties
*properties
=
1609 (VkPhysicalDevicePointClippingProperties
*) ext
;
1610 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY
;
1614 #pragma GCC diagnostic push
1615 #pragma GCC diagnostic ignored "-Wswitch"
1616 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
: {
1617 VkPhysicalDevicePresentationPropertiesANDROID
*props
=
1618 (VkPhysicalDevicePresentationPropertiesANDROID
*)ext
;
1619 props
->sharedImage
= VK_FALSE
;
1622 #pragma GCC diagnostic pop
1624 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1625 VkPhysicalDeviceProtectedMemoryProperties
*props
=
1626 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1627 props
->protectedNoFault
= false;
1631 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1632 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1633 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1635 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1639 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1640 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1641 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1642 properties
->filterMinmaxImageComponentMapping
= pdevice
->info
.gen
>= 9;
1643 properties
->filterMinmaxSingleComponentFormats
= true;
1647 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1648 VkPhysicalDeviceSubgroupProperties
*properties
= (void *)ext
;
1650 properties
->subgroupSize
= BRW_SUBGROUP_SIZE
;
1652 VkShaderStageFlags scalar_stages
= 0;
1653 for (unsigned stage
= 0; stage
< MESA_SHADER_STAGES
; stage
++) {
1654 if (pdevice
->compiler
->scalar_stage
[stage
])
1655 scalar_stages
|= mesa_to_vk_shader_stage(stage
);
1657 properties
->supportedStages
= scalar_stages
;
1659 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1660 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1661 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1662 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1663 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
1664 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1665 if (pdevice
->info
.gen
>= 8) {
1666 /* TODO: There's no technical reason why these can't be made to
1667 * work on gen7 but they don't at the moment so it's best to leave
1668 * the feature disabled than enabled and broken.
1670 properties
->supportedOperations
|=
1671 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1672 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
;
1674 properties
->quadOperationsInAllStages
= pdevice
->info
.gen
>= 8;
1678 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
1679 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
1680 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
1681 STATIC_ASSERT(8 <= BRW_SUBGROUP_SIZE
&& BRW_SUBGROUP_SIZE
<= 32);
1682 props
->minSubgroupSize
= 8;
1683 props
->maxSubgroupSize
= 32;
1684 props
->maxComputeWorkgroupSubgroups
= pdevice
->info
.max_cs_threads
;
1685 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1689 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1690 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*props
=
1691 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1693 /* From the SKL PRM Vol. 2d, docs for RENDER_SURFACE_STATE::Surface
1696 * "For SURFTYPE_BUFFER non-rendertarget surfaces, this field
1697 * specifies the base address of the first element of the surface,
1698 * computed in software by adding the surface base address to the
1699 * byte offset of the element in the buffer. The base address must
1700 * be aligned to element size."
1702 * The typed dataport messages require that things be texel aligned.
1703 * Otherwise, we may just load/store the wrong data or, in the worst
1704 * case, there may be hangs.
1706 props
->storageTexelBufferOffsetAlignmentBytes
= 16;
1707 props
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1709 /* The sampler, however, is much more forgiving and it can handle
1710 * arbitrary byte alignment for linear and buffer surfaces. It's
1711 * hard to find a good PRM citation for this but years of empirical
1712 * experience demonstrate that this is true.
1714 props
->uniformTexelBufferOffsetAlignmentBytes
= 1;
1715 props
->uniformTexelBufferOffsetSingleTexelAlignment
= false;
1719 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1720 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*props
=
1721 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1723 props
->maxTransformFeedbackStreams
= MAX_XFB_STREAMS
;
1724 props
->maxTransformFeedbackBuffers
= MAX_XFB_BUFFERS
;
1725 props
->maxTransformFeedbackBufferSize
= (1ull << 32);
1726 props
->maxTransformFeedbackStreamDataSize
= 128 * 4;
1727 props
->maxTransformFeedbackBufferDataSize
= 128 * 4;
1728 props
->maxTransformFeedbackBufferDataStride
= 2048;
1729 props
->transformFeedbackQueries
= true;
1730 props
->transformFeedbackStreamsLinesTriangles
= false;
1731 props
->transformFeedbackRasterizationStreamSelect
= false;
1732 props
->transformFeedbackDraw
= true;
1736 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1737 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
1738 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1739 /* We have to restrict this a bit for multiview */
1740 props
->maxVertexAttribDivisor
= UINT32_MAX
/ 16;
1745 anv_debug_ignored_stype(ext
->sType
);
1751 /* We support exactly one queue family. */
1752 static const VkQueueFamilyProperties
1753 anv_queue_family_properties
= {
1754 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1755 VK_QUEUE_COMPUTE_BIT
|
1756 VK_QUEUE_TRANSFER_BIT
,
1758 .timestampValidBits
= 36, /* XXX: Real value here */
1759 .minImageTransferGranularity
= { 1, 1, 1 },
1762 void anv_GetPhysicalDeviceQueueFamilyProperties(
1763 VkPhysicalDevice physicalDevice
,
1765 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1767 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1769 vk_outarray_append(&out
, p
) {
1770 *p
= anv_queue_family_properties
;
1774 void anv_GetPhysicalDeviceQueueFamilyProperties2(
1775 VkPhysicalDevice physicalDevice
,
1776 uint32_t* pQueueFamilyPropertyCount
,
1777 VkQueueFamilyProperties2
* pQueueFamilyProperties
)
1780 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1782 vk_outarray_append(&out
, p
) {
1783 p
->queueFamilyProperties
= anv_queue_family_properties
;
1785 vk_foreach_struct(s
, p
->pNext
) {
1786 anv_debug_ignored_stype(s
->sType
);
1791 void anv_GetPhysicalDeviceMemoryProperties(
1792 VkPhysicalDevice physicalDevice
,
1793 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1795 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1797 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1798 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1799 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1800 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1801 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1805 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1806 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1807 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1808 .size
= physical_device
->memory
.heaps
[i
].size
,
1809 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1815 anv_get_memory_budget(VkPhysicalDevice physicalDevice
,
1816 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1818 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1819 uint64_t sys_available
= get_available_system_memory();
1820 assert(sys_available
> 0);
1822 VkDeviceSize total_heaps_size
= 0;
1823 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++)
1824 total_heaps_size
+= device
->memory
.heaps
[i
].size
;
1826 for (size_t i
= 0; i
< device
->memory
.heap_count
; i
++) {
1827 VkDeviceSize heap_size
= device
->memory
.heaps
[i
].size
;
1828 VkDeviceSize heap_used
= device
->memory
.heaps
[i
].used
;
1829 VkDeviceSize heap_budget
;
1831 double heap_proportion
= (double) heap_size
/ total_heaps_size
;
1832 VkDeviceSize sys_available_prop
= sys_available
* heap_proportion
;
1835 * Let's not incite the app to starve the system: report at most 90% of
1836 * available system memory.
1838 uint64_t heap_available
= sys_available_prop
* 9 / 10;
1839 heap_budget
= MIN2(heap_size
, heap_used
+ heap_available
);
1842 * Round down to the nearest MB
1844 heap_budget
&= ~((1ull << 20) - 1);
1847 * The heapBudget value must be non-zero for array elements less than
1848 * VkPhysicalDeviceMemoryProperties::memoryHeapCount. The heapBudget
1849 * value must be less than or equal to VkMemoryHeap::size for each heap.
1851 assert(0 < heap_budget
&& heap_budget
<= heap_size
);
1853 memoryBudget
->heapUsage
[i
] = heap_used
;
1854 memoryBudget
->heapBudget
[i
] = heap_budget
;
1857 /* The heapBudget and heapUsage values must be zero for array elements
1858 * greater than or equal to VkPhysicalDeviceMemoryProperties::memoryHeapCount
1860 for (uint32_t i
= device
->memory
.heap_count
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1861 memoryBudget
->heapBudget
[i
] = 0;
1862 memoryBudget
->heapUsage
[i
] = 0;
1866 void anv_GetPhysicalDeviceMemoryProperties2(
1867 VkPhysicalDevice physicalDevice
,
1868 VkPhysicalDeviceMemoryProperties2
* pMemoryProperties
)
1870 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1871 &pMemoryProperties
->memoryProperties
);
1873 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1874 switch (ext
->sType
) {
1875 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
:
1876 anv_get_memory_budget(physicalDevice
, (void*)ext
);
1879 anv_debug_ignored_stype(ext
->sType
);
1886 anv_GetDeviceGroupPeerMemoryFeatures(
1889 uint32_t localDeviceIndex
,
1890 uint32_t remoteDeviceIndex
,
1891 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
1893 assert(localDeviceIndex
== 0 && remoteDeviceIndex
== 0);
1894 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
1895 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
1896 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
1897 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
1900 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1901 VkInstance _instance
,
1904 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1906 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1907 * when we have to return valid function pointers, NULL, or it's left
1908 * undefined. See the table for exact details.
1913 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1914 if (strcmp(pName, "vk" #entrypoint) == 0) \
1915 return (PFN_vkVoidFunction)anv_##entrypoint
1917 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1918 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1919 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceVersion
);
1920 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1922 #undef LOOKUP_ANV_ENTRYPOINT
1924 if (instance
== NULL
)
1927 int idx
= anv_get_instance_entrypoint_index(pName
);
1929 return instance
->dispatch
.entrypoints
[idx
];
1931 idx
= anv_get_device_entrypoint_index(pName
);
1933 return instance
->device_dispatch
.entrypoints
[idx
];
1938 /* With version 1+ of the loader interface the ICD should expose
1939 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1942 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1943 VkInstance instance
,
1947 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1948 VkInstance instance
,
1951 return anv_GetInstanceProcAddr(instance
, pName
);
1954 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1958 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1960 if (!device
|| !pName
)
1963 int idx
= anv_get_device_entrypoint_index(pName
);
1967 return device
->dispatch
.entrypoints
[idx
];
1971 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1972 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1973 const VkAllocationCallbacks
* pAllocator
,
1974 VkDebugReportCallbackEXT
* pCallback
)
1976 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1977 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1978 pCreateInfo
, pAllocator
, &instance
->alloc
,
1983 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1984 VkDebugReportCallbackEXT _callback
,
1985 const VkAllocationCallbacks
* pAllocator
)
1987 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1988 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1989 _callback
, pAllocator
, &instance
->alloc
);
1993 anv_DebugReportMessageEXT(VkInstance _instance
,
1994 VkDebugReportFlagsEXT flags
,
1995 VkDebugReportObjectTypeEXT objectType
,
1998 int32_t messageCode
,
1999 const char* pLayerPrefix
,
2000 const char* pMessage
)
2002 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
2003 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2004 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2008 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
2010 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2011 queue
->device
= device
;
2016 anv_queue_finish(struct anv_queue
*queue
)
2020 static struct anv_state
2021 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
2023 struct anv_state state
;
2025 state
= anv_state_pool_alloc(pool
, size
, align
);
2026 memcpy(state
.map
, p
, size
);
2031 /* Haswell border color is a bit of a disaster. Float and unorm formats use a
2032 * straightforward 32-bit float color in the first 64 bytes. Instead of using
2033 * a nice float/integer union like Gen8+, Haswell specifies the integer border
2034 * color as a separate entry /after/ the float color. The layout of this entry
2035 * also depends on the format's bpp (with extra hacks for RG32), and overlaps.
2037 * Since we don't know the format/bpp, we can't make any of the border colors
2038 * containing '1' work for all formats, as it would be in the wrong place for
2039 * some of them. We opt to make 32-bit integers work as this seems like the
2040 * most common option. Fortunately, transparent black works regardless, as
2041 * all zeroes is the same in every bit-size.
2043 struct hsw_border_color
{
2047 uint32_t _pad1
[108];
2050 struct gen8_border_color
{
2055 /* Pad out to 64 bytes */
2060 anv_device_init_border_colors(struct anv_device
*device
)
2062 if (device
->info
.is_haswell
) {
2063 static const struct hsw_border_color border_colors
[] = {
2064 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2065 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2066 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2067 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2068 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2069 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2072 device
->border_colors
=
2073 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2074 sizeof(border_colors
), 512, border_colors
);
2076 static const struct gen8_border_color border_colors
[] = {
2077 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
2078 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
2079 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
2080 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
2081 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
2082 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
2085 device
->border_colors
=
2086 anv_state_pool_emit_data(&device
->dynamic_state_pool
,
2087 sizeof(border_colors
), 64, border_colors
);
2092 anv_device_init_trivial_batch(struct anv_device
*device
)
2094 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
2096 if (device
->instance
->physicalDevice
.has_exec_async
)
2097 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
2099 if (device
->instance
->physicalDevice
.use_softpin
)
2100 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_PINNED
;
2102 anv_vma_alloc(device
, &device
->trivial_batch_bo
);
2104 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
2107 struct anv_batch batch
= {
2113 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2114 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2116 if (!device
->info
.has_llc
)
2117 gen_clflush_range(map
, batch
.next
- map
);
2119 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
2122 VkResult
anv_EnumerateDeviceExtensionProperties(
2123 VkPhysicalDevice physicalDevice
,
2124 const char* pLayerName
,
2125 uint32_t* pPropertyCount
,
2126 VkExtensionProperties
* pProperties
)
2128 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
2129 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2131 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
2132 if (device
->supported_extensions
.extensions
[i
]) {
2133 vk_outarray_append(&out
, prop
) {
2134 *prop
= anv_device_extensions
[i
];
2139 return vk_outarray_status(&out
);
2143 anv_device_init_dispatch(struct anv_device
*device
)
2145 const struct anv_device_dispatch_table
*genX_table
;
2146 switch (device
->info
.gen
) {
2148 genX_table
= &gen12_device_dispatch_table
;
2151 genX_table
= &gen11_device_dispatch_table
;
2154 genX_table
= &gen10_device_dispatch_table
;
2157 genX_table
= &gen9_device_dispatch_table
;
2160 genX_table
= &gen8_device_dispatch_table
;
2163 if (device
->info
.is_haswell
)
2164 genX_table
= &gen75_device_dispatch_table
;
2166 genX_table
= &gen7_device_dispatch_table
;
2169 unreachable("unsupported gen\n");
2172 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2173 /* Vulkan requires that entrypoints for extensions which have not been
2174 * enabled must not be advertised.
2176 if (!anv_device_entrypoint_is_enabled(i
, device
->instance
->app_info
.api_version
,
2177 &device
->instance
->enabled_extensions
,
2178 &device
->enabled_extensions
)) {
2179 device
->dispatch
.entrypoints
[i
] = NULL
;
2180 } else if (genX_table
->entrypoints
[i
]) {
2181 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
2183 device
->dispatch
.entrypoints
[i
] =
2184 anv_device_dispatch_table
.entrypoints
[i
];
2190 vk_priority_to_gen(int priority
)
2193 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2194 return GEN_CONTEXT_LOW_PRIORITY
;
2195 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2196 return GEN_CONTEXT_MEDIUM_PRIORITY
;
2197 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2198 return GEN_CONTEXT_HIGH_PRIORITY
;
2199 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2200 return GEN_CONTEXT_REALTIME_PRIORITY
;
2202 unreachable("Invalid priority");
2207 anv_device_init_hiz_clear_value_bo(struct anv_device
*device
)
2209 anv_bo_init_new(&device
->hiz_clear_bo
, device
, 4096);
2211 if (device
->instance
->physicalDevice
.has_exec_async
)
2212 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_ASYNC
;
2214 if (device
->instance
->physicalDevice
.use_softpin
)
2215 device
->hiz_clear_bo
.flags
|= EXEC_OBJECT_PINNED
;
2217 anv_vma_alloc(device
, &device
->hiz_clear_bo
);
2219 uint32_t *map
= anv_gem_mmap(device
, device
->hiz_clear_bo
.gem_handle
,
2222 union isl_color_value hiz_clear
= { .u32
= { 0, } };
2223 hiz_clear
.f32
[0] = ANV_HZ_FC_VAL
;
2225 memcpy(map
, hiz_clear
.u32
, sizeof(hiz_clear
.u32
));
2226 anv_gem_munmap(map
, device
->hiz_clear_bo
.size
);
2230 get_bo_from_pool(struct gen_batch_decode_bo
*ret
,
2231 struct anv_block_pool
*pool
,
2234 for (uint32_t i
= 0; i
< pool
->nbos
; i
++) {
2235 uint64_t bo_address
= pool
->bos
[i
].offset
& (~0ull >> 16);
2236 uint32_t bo_size
= pool
->bos
[i
].size
;
2237 if (address
>= bo_address
&& address
< (bo_address
+ bo_size
)) {
2238 *ret
= (struct gen_batch_decode_bo
) {
2241 .map
= pool
->bos
[i
].map
,
2249 /* Finding a buffer for batch decoding */
2250 static struct gen_batch_decode_bo
2251 decode_get_bo(void *v_batch
, bool ppgtt
, uint64_t address
)
2253 struct anv_device
*device
= v_batch
;
2254 struct gen_batch_decode_bo ret_bo
= {};
2258 if (get_bo_from_pool(&ret_bo
, &device
->dynamic_state_pool
.block_pool
, address
))
2260 if (get_bo_from_pool(&ret_bo
, &device
->instruction_state_pool
.block_pool
, address
))
2262 if (get_bo_from_pool(&ret_bo
, &device
->binding_table_pool
.block_pool
, address
))
2264 if (get_bo_from_pool(&ret_bo
, &device
->surface_state_pool
.block_pool
, address
))
2267 if (!device
->cmd_buffer_being_decoded
)
2268 return (struct gen_batch_decode_bo
) { };
2270 struct anv_batch_bo
**bo
;
2272 u_vector_foreach(bo
, &device
->cmd_buffer_being_decoded
->seen_bbos
) {
2273 /* The decoder zeroes out the top 16 bits, so we need to as well */
2274 uint64_t bo_address
= (*bo
)->bo
.offset
& (~0ull >> 16);
2276 if (address
>= bo_address
&& address
< bo_address
+ (*bo
)->bo
.size
) {
2277 return (struct gen_batch_decode_bo
) {
2279 .size
= (*bo
)->bo
.size
,
2280 .map
= (*bo
)->bo
.map
,
2285 return (struct gen_batch_decode_bo
) { };
2288 VkResult
anv_CreateDevice(
2289 VkPhysicalDevice physicalDevice
,
2290 const VkDeviceCreateInfo
* pCreateInfo
,
2291 const VkAllocationCallbacks
* pAllocator
,
2294 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
2296 struct anv_device
*device
;
2298 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
2300 struct anv_device_extension_table enabled_extensions
= { };
2301 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
2303 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
2304 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
2305 anv_device_extensions
[idx
].extensionName
) == 0)
2309 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
2310 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2312 if (!physical_device
->supported_extensions
.extensions
[idx
])
2313 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
2315 enabled_extensions
.extensions
[idx
] = true;
2318 /* Check enabled features */
2319 if (pCreateInfo
->pEnabledFeatures
) {
2320 VkPhysicalDeviceFeatures supported_features
;
2321 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2322 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2323 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
2324 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2325 for (uint32_t i
= 0; i
< num_features
; i
++) {
2326 if (enabled_feature
[i
] && !supported_feature
[i
])
2327 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2331 /* Check requested queues and fail if we are requested to create any
2332 * queues with flags we don't support.
2334 assert(pCreateInfo
->queueCreateInfoCount
> 0);
2335 for (uint32_t i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
2336 if (pCreateInfo
->pQueueCreateInfos
[i
].flags
!= 0)
2337 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2340 /* Check if client specified queue priority. */
2341 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*queue_priority
=
2342 vk_find_struct_const(pCreateInfo
->pQueueCreateInfos
[0].pNext
,
2343 DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
2345 VkQueueGlobalPriorityEXT priority
=
2346 queue_priority
? queue_priority
->globalPriority
:
2347 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
;
2349 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
2351 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2353 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2355 if (INTEL_DEBUG
& DEBUG_BATCH
) {
2356 const unsigned decode_flags
=
2357 GEN_BATCH_DECODE_FULL
|
2358 ((INTEL_DEBUG
& DEBUG_COLOR
) ? GEN_BATCH_DECODE_IN_COLOR
: 0) |
2359 GEN_BATCH_DECODE_OFFSETS
|
2360 GEN_BATCH_DECODE_FLOATS
;
2362 gen_batch_decode_ctx_init(&device
->decoder_ctx
,
2363 &physical_device
->info
,
2364 stderr
, decode_flags
, NULL
,
2365 decode_get_bo
, NULL
, device
);
2368 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2369 device
->instance
= physical_device
->instance
;
2370 device
->chipset_id
= physical_device
->chipset_id
;
2371 device
->no_hw
= physical_device
->no_hw
;
2372 device
->_lost
= false;
2375 device
->alloc
= *pAllocator
;
2377 device
->alloc
= physical_device
->instance
->alloc
;
2379 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
2380 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
2381 if (device
->fd
== -1) {
2382 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2386 device
->context_id
= anv_gem_create_context(device
);
2387 if (device
->context_id
== -1) {
2388 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2392 if (physical_device
->use_softpin
) {
2393 if (pthread_mutex_init(&device
->vma_mutex
, NULL
) != 0) {
2394 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2398 /* keep the page with address zero out of the allocator */
2399 struct anv_memory_heap
*low_heap
=
2400 &physical_device
->memory
.heaps
[physical_device
->memory
.heap_count
- 1];
2401 util_vma_heap_init(&device
->vma_lo
, low_heap
->vma_start
, low_heap
->vma_size
);
2402 device
->vma_lo_available
= low_heap
->size
;
2404 struct anv_memory_heap
*high_heap
=
2405 &physical_device
->memory
.heaps
[0];
2406 util_vma_heap_init(&device
->vma_hi
, high_heap
->vma_start
, high_heap
->vma_size
);
2407 device
->vma_hi_available
= physical_device
->memory
.heap_count
== 1 ? 0 :
2411 list_inithead(&device
->memory_objects
);
2413 /* As per spec, the driver implementation may deny requests to acquire
2414 * a priority above the default priority (MEDIUM) if the caller does not
2415 * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT
2418 if (physical_device
->has_context_priority
) {
2419 int err
= anv_gem_set_context_param(device
->fd
, device
->context_id
,
2420 I915_CONTEXT_PARAM_PRIORITY
,
2421 vk_priority_to_gen(priority
));
2422 if (err
!= 0 && priority
> VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
) {
2423 result
= vk_error(VK_ERROR_NOT_PERMITTED_EXT
);
2428 device
->info
= physical_device
->info
;
2429 device
->isl_dev
= physical_device
->isl_dev
;
2431 /* On Broadwell and later, we can use batch chaining to more efficiently
2432 * implement growing command buffers. Prior to Haswell, the kernel
2433 * command parser gets in the way and we have to fall back to growing
2436 device
->can_chain_batches
= device
->info
.gen
>= 8;
2438 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
2439 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
2440 device
->enabled_extensions
= enabled_extensions
;
2442 anv_device_init_dispatch(device
);
2444 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
2445 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2446 goto fail_context_id
;
2449 pthread_condattr_t condattr
;
2450 if (pthread_condattr_init(&condattr
) != 0) {
2451 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2454 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
2455 pthread_condattr_destroy(&condattr
);
2456 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2459 if (pthread_cond_init(&device
->queue_submit
, &condattr
) != 0) {
2460 pthread_condattr_destroy(&condattr
);
2461 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
2464 pthread_condattr_destroy(&condattr
);
2467 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
2468 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
2469 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0) |
2470 (physical_device
->use_softpin
? EXEC_OBJECT_PINNED
: 0);
2472 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
2474 result
= anv_bo_cache_init(&device
->bo_cache
);
2475 if (result
!= VK_SUCCESS
)
2476 goto fail_batch_bo_pool
;
2478 if (!physical_device
->use_softpin
)
2479 bo_flags
&= ~EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2481 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
,
2482 DYNAMIC_STATE_POOL_MIN_ADDRESS
,
2485 if (result
!= VK_SUCCESS
)
2488 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
,
2489 INSTRUCTION_STATE_POOL_MIN_ADDRESS
,
2492 if (result
!= VK_SUCCESS
)
2493 goto fail_dynamic_state_pool
;
2495 result
= anv_state_pool_init(&device
->surface_state_pool
, device
,
2496 SURFACE_STATE_POOL_MIN_ADDRESS
,
2499 if (result
!= VK_SUCCESS
)
2500 goto fail_instruction_state_pool
;
2502 if (physical_device
->use_softpin
) {
2503 result
= anv_state_pool_init(&device
->binding_table_pool
, device
,
2504 BINDING_TABLE_POOL_MIN_ADDRESS
,
2507 if (result
!= VK_SUCCESS
)
2508 goto fail_surface_state_pool
;
2511 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 4096);
2512 if (result
!= VK_SUCCESS
)
2513 goto fail_binding_table_pool
;
2515 if (physical_device
->use_softpin
)
2516 device
->workaround_bo
.flags
|= EXEC_OBJECT_PINNED
;
2518 if (!anv_vma_alloc(device
, &device
->workaround_bo
))
2519 goto fail_workaround_bo
;
2521 anv_device_init_trivial_batch(device
);
2523 if (device
->info
.gen
>= 10)
2524 anv_device_init_hiz_clear_value_bo(device
);
2526 anv_scratch_pool_init(device
, &device
->scratch_pool
);
2528 anv_queue_init(device
, &device
->queue
);
2530 switch (device
->info
.gen
) {
2532 if (!device
->info
.is_haswell
)
2533 result
= gen7_init_device_state(device
);
2535 result
= gen75_init_device_state(device
);
2538 result
= gen8_init_device_state(device
);
2541 result
= gen9_init_device_state(device
);
2544 result
= gen10_init_device_state(device
);
2547 result
= gen11_init_device_state(device
);
2550 result
= gen12_init_device_state(device
);
2553 /* Shouldn't get here as we don't create physical devices for any other
2555 unreachable("unhandled gen");
2557 if (result
!= VK_SUCCESS
)
2558 goto fail_workaround_bo
;
2560 anv_pipeline_cache_init(&device
->default_pipeline_cache
, device
, true);
2562 anv_device_init_blorp(device
);
2564 anv_device_init_border_colors(device
);
2566 *pDevice
= anv_device_to_handle(device
);
2571 anv_queue_finish(&device
->queue
);
2572 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
2573 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
2574 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
2575 fail_binding_table_pool
:
2576 if (physical_device
->use_softpin
)
2577 anv_state_pool_finish(&device
->binding_table_pool
);
2578 fail_surface_state_pool
:
2579 anv_state_pool_finish(&device
->surface_state_pool
);
2580 fail_instruction_state_pool
:
2581 anv_state_pool_finish(&device
->instruction_state_pool
);
2582 fail_dynamic_state_pool
:
2583 anv_state_pool_finish(&device
->dynamic_state_pool
);
2585 anv_bo_cache_finish(&device
->bo_cache
);
2587 anv_bo_pool_finish(&device
->batch_bo_pool
);
2588 pthread_cond_destroy(&device
->queue_submit
);
2590 pthread_mutex_destroy(&device
->mutex
);
2592 anv_gem_destroy_context(device
, device
->context_id
);
2596 vk_free(&device
->alloc
, device
);
2601 void anv_DestroyDevice(
2603 const VkAllocationCallbacks
* pAllocator
)
2605 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2606 struct anv_physical_device
*physical_device
;
2611 physical_device
= &device
->instance
->physicalDevice
;
2613 anv_device_finish_blorp(device
);
2615 anv_pipeline_cache_finish(&device
->default_pipeline_cache
);
2617 anv_queue_finish(&device
->queue
);
2619 #ifdef HAVE_VALGRIND
2620 /* We only need to free these to prevent valgrind errors. The backing
2621 * BO will go away in a couple of lines so we don't actually leak.
2623 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
2624 anv_state_pool_free(&device
->dynamic_state_pool
, device
->slice_hash
);
2627 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
2629 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
2630 anv_vma_free(device
, &device
->workaround_bo
);
2631 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
2633 anv_vma_free(device
, &device
->trivial_batch_bo
);
2634 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
2635 if (device
->info
.gen
>= 10)
2636 anv_gem_close(device
, device
->hiz_clear_bo
.gem_handle
);
2638 if (physical_device
->use_softpin
)
2639 anv_state_pool_finish(&device
->binding_table_pool
);
2640 anv_state_pool_finish(&device
->surface_state_pool
);
2641 anv_state_pool_finish(&device
->instruction_state_pool
);
2642 anv_state_pool_finish(&device
->dynamic_state_pool
);
2644 anv_bo_cache_finish(&device
->bo_cache
);
2646 anv_bo_pool_finish(&device
->batch_bo_pool
);
2648 pthread_cond_destroy(&device
->queue_submit
);
2649 pthread_mutex_destroy(&device
->mutex
);
2651 anv_gem_destroy_context(device
, device
->context_id
);
2653 if (INTEL_DEBUG
& DEBUG_BATCH
)
2654 gen_batch_decode_ctx_finish(&device
->decoder_ctx
);
2658 vk_free(&device
->alloc
, device
);
2661 VkResult
anv_EnumerateInstanceLayerProperties(
2662 uint32_t* pPropertyCount
,
2663 VkLayerProperties
* pProperties
)
2665 if (pProperties
== NULL
) {
2666 *pPropertyCount
= 0;
2670 /* None supported at this time */
2671 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2674 VkResult
anv_EnumerateDeviceLayerProperties(
2675 VkPhysicalDevice physicalDevice
,
2676 uint32_t* pPropertyCount
,
2677 VkLayerProperties
* pProperties
)
2679 if (pProperties
== NULL
) {
2680 *pPropertyCount
= 0;
2684 /* None supported at this time */
2685 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
2688 void anv_GetDeviceQueue(
2690 uint32_t queueNodeIndex
,
2691 uint32_t queueIndex
,
2694 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2696 assert(queueIndex
== 0);
2698 *pQueue
= anv_queue_to_handle(&device
->queue
);
2701 void anv_GetDeviceQueue2(
2703 const VkDeviceQueueInfo2
* pQueueInfo
,
2706 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2708 assert(pQueueInfo
->queueIndex
== 0);
2710 if (pQueueInfo
->flags
== device
->queue
.flags
)
2711 *pQueue
= anv_queue_to_handle(&device
->queue
);
2717 _anv_device_set_lost(struct anv_device
*device
,
2718 const char *file
, int line
,
2719 const char *msg
, ...)
2724 device
->_lost
= true;
2727 err
= __vk_errorv(device
->instance
, device
,
2728 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
2729 VK_ERROR_DEVICE_LOST
, file
, line
, msg
, ap
);
2732 if (env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false))
2739 anv_device_query_status(struct anv_device
*device
)
2741 /* This isn't likely as most of the callers of this function already check
2742 * for it. However, it doesn't hurt to check and it potentially lets us
2745 if (anv_device_is_lost(device
))
2746 return VK_ERROR_DEVICE_LOST
;
2748 uint32_t active
, pending
;
2749 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
2751 /* We don't know the real error. */
2752 return anv_device_set_lost(device
, "get_reset_stats failed: %m");
2756 return anv_device_set_lost(device
, "GPU hung on one of our command buffers");
2757 } else if (pending
) {
2758 return anv_device_set_lost(device
, "GPU hung with commands in-flight");
2765 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
2767 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
2768 * Other usages of the BO (such as on different hardware) will not be
2769 * flagged as "busy" by this ioctl. Use with care.
2771 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
2773 return VK_NOT_READY
;
2774 } else if (ret
== -1) {
2775 /* We don't know the real error. */
2776 return anv_device_set_lost(device
, "gem wait failed: %m");
2779 /* Query for device status after the busy call. If the BO we're checking
2780 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
2781 * client because it clearly doesn't have valid data. Yes, this most
2782 * likely means an ioctl, but we just did an ioctl to query the busy status
2783 * so it's no great loss.
2785 return anv_device_query_status(device
);
2789 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
2792 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
2793 if (ret
== -1 && errno
== ETIME
) {
2795 } else if (ret
== -1) {
2796 /* We don't know the real error. */
2797 return anv_device_set_lost(device
, "gem wait failed: %m");
2800 /* Query for device status after the wait. If the BO we're waiting on got
2801 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
2802 * because it clearly doesn't have valid data. Yes, this most likely means
2803 * an ioctl, but we just did an ioctl to wait so it's no great loss.
2805 return anv_device_query_status(device
);
2808 VkResult
anv_DeviceWaitIdle(
2811 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2812 if (anv_device_is_lost(device
))
2813 return VK_ERROR_DEVICE_LOST
;
2815 struct anv_batch batch
;
2818 batch
.start
= batch
.next
= cmds
;
2819 batch
.end
= (void *) cmds
+ sizeof(cmds
);
2821 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
2822 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
2824 return anv_device_submit_simple_batch(device
, &batch
);
2828 anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
)
2830 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2833 pthread_mutex_lock(&device
->vma_mutex
);
2837 if (bo
->flags
& EXEC_OBJECT_SUPPORTS_48B_ADDRESS
&&
2838 device
->vma_hi_available
>= bo
->size
) {
2839 uint64_t addr
= util_vma_heap_alloc(&device
->vma_hi
, bo
->size
, 4096);
2841 bo
->offset
= gen_canonical_address(addr
);
2842 assert(addr
== gen_48b_address(bo
->offset
));
2843 device
->vma_hi_available
-= bo
->size
;
2847 if (bo
->offset
== 0 && device
->vma_lo_available
>= bo
->size
) {
2848 uint64_t addr
= util_vma_heap_alloc(&device
->vma_lo
, bo
->size
, 4096);
2850 bo
->offset
= gen_canonical_address(addr
);
2851 assert(addr
== gen_48b_address(bo
->offset
));
2852 device
->vma_lo_available
-= bo
->size
;
2856 pthread_mutex_unlock(&device
->vma_mutex
);
2858 return bo
->offset
!= 0;
2862 anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
)
2864 if (!(bo
->flags
& EXEC_OBJECT_PINNED
))
2867 const uint64_t addr_48b
= gen_48b_address(bo
->offset
);
2869 pthread_mutex_lock(&device
->vma_mutex
);
2871 if (addr_48b
>= LOW_HEAP_MIN_ADDRESS
&&
2872 addr_48b
<= LOW_HEAP_MAX_ADDRESS
) {
2873 util_vma_heap_free(&device
->vma_lo
, addr_48b
, bo
->size
);
2874 device
->vma_lo_available
+= bo
->size
;
2876 ASSERTED
const struct anv_physical_device
*physical_device
=
2877 &device
->instance
->physicalDevice
;
2878 assert(addr_48b
>= physical_device
->memory
.heaps
[0].vma_start
&&
2879 addr_48b
< (physical_device
->memory
.heaps
[0].vma_start
+
2880 physical_device
->memory
.heaps
[0].vma_size
));
2881 util_vma_heap_free(&device
->vma_hi
, addr_48b
, bo
->size
);
2882 device
->vma_hi_available
+= bo
->size
;
2885 pthread_mutex_unlock(&device
->vma_mutex
);
2891 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
2893 uint32_t gem_handle
= anv_gem_create(device
, size
);
2895 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2897 anv_bo_init(bo
, gem_handle
, size
);
2902 VkResult
anv_AllocateMemory(
2904 const VkMemoryAllocateInfo
* pAllocateInfo
,
2905 const VkAllocationCallbacks
* pAllocator
,
2906 VkDeviceMemory
* pMem
)
2908 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2909 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2910 struct anv_device_memory
*mem
;
2911 VkResult result
= VK_SUCCESS
;
2913 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2915 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
2916 assert(pAllocateInfo
->allocationSize
> 0);
2918 if (pAllocateInfo
->allocationSize
> MAX_MEMORY_ALLOCATION_SIZE
)
2919 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2921 /* FINISHME: Fail if allocation request exceeds heap size. */
2923 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2924 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2926 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2928 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
2929 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
2933 mem
->host_ptr
= NULL
;
2935 uint64_t bo_flags
= 0;
2937 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
2938 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
2939 bo_flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
2941 const struct wsi_memory_allocate_info
*wsi_info
=
2942 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2943 if (wsi_info
&& wsi_info
->implicit_sync
) {
2944 /* We need to set the WRITE flag on window system buffers so that GEM
2945 * will know we're writing to them and synchronize uses on other rings
2946 * (eg if the display server uses the blitter ring).
2948 bo_flags
|= EXEC_OBJECT_WRITE
;
2949 } else if (pdevice
->has_exec_async
) {
2950 bo_flags
|= EXEC_OBJECT_ASYNC
;
2953 if (pdevice
->use_softpin
)
2954 bo_flags
|= EXEC_OBJECT_PINNED
;
2956 const VkExportMemoryAllocateInfo
*export_info
=
2957 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
2959 /* Check if we need to support Android HW buffer export. If so,
2960 * create AHardwareBuffer and import memory from it.
2962 bool android_export
= false;
2963 if (export_info
&& export_info
->handleTypes
&
2964 VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)
2965 android_export
= true;
2967 /* Android memory import. */
2968 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahw_import_info
=
2969 vk_find_struct_const(pAllocateInfo
->pNext
,
2970 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
2972 if (ahw_import_info
) {
2973 result
= anv_import_ahw_memory(_device
, mem
, ahw_import_info
);
2974 if (result
!= VK_SUCCESS
)
2978 } else if (android_export
) {
2979 result
= anv_create_ahw_memory(_device
, mem
, pAllocateInfo
);
2980 if (result
!= VK_SUCCESS
)
2983 const struct VkImportAndroidHardwareBufferInfoANDROID import_info
= {
2986 result
= anv_import_ahw_memory(_device
, mem
, &import_info
);
2987 if (result
!= VK_SUCCESS
)
2993 const VkImportMemoryFdInfoKHR
*fd_info
=
2994 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2996 /* The Vulkan spec permits handleType to be 0, in which case the struct is
2999 if (fd_info
&& fd_info
->handleType
) {
3000 /* At the moment, we support only the below handle types. */
3001 assert(fd_info
->handleType
==
3002 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3003 fd_info
->handleType
==
3004 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3006 result
= anv_bo_cache_import(device
, &device
->bo_cache
, fd_info
->fd
,
3007 bo_flags
| ANV_BO_EXTERNAL
, &mem
->bo
);
3008 if (result
!= VK_SUCCESS
)
3011 VkDeviceSize aligned_alloc_size
=
3012 align_u64(pAllocateInfo
->allocationSize
, 4096);
3014 /* For security purposes, we reject importing the bo if it's smaller
3015 * than the requested allocation size. This prevents a malicious client
3016 * from passing a buffer to a trusted client, lying about the size, and
3017 * telling the trusted client to try and texture from an image that goes
3018 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
3019 * in the trusted client. The trusted client can protect itself against
3020 * this sort of attack but only if it can trust the buffer size.
3022 if (mem
->bo
->size
< aligned_alloc_size
) {
3023 result
= vk_errorf(device
->instance
, device
,
3024 VK_ERROR_INVALID_EXTERNAL_HANDLE
,
3025 "aligned allocationSize too large for "
3026 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: "
3027 "%"PRIu64
"B > %"PRIu64
"B",
3028 aligned_alloc_size
, mem
->bo
->size
);
3029 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
3033 /* From the Vulkan spec:
3035 * "Importing memory from a file descriptor transfers ownership of
3036 * the file descriptor from the application to the Vulkan
3037 * implementation. The application must not perform any operations on
3038 * the file descriptor after a successful import."
3040 * If the import fails, we leave the file descriptor open.
3046 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3047 vk_find_struct_const(pAllocateInfo
->pNext
,
3048 IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3049 if (host_ptr_info
&& host_ptr_info
->handleType
) {
3050 if (host_ptr_info
->handleType
==
3051 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT
) {
3052 result
= vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3056 assert(host_ptr_info
->handleType
==
3057 VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3059 result
= anv_bo_cache_import_host_ptr(
3060 device
, &device
->bo_cache
, host_ptr_info
->pHostPointer
,
3061 pAllocateInfo
->allocationSize
, bo_flags
, &mem
->bo
);
3063 if (result
!= VK_SUCCESS
)
3066 mem
->host_ptr
= host_ptr_info
->pHostPointer
;
3070 /* Regular allocate (not importing memory). */
3072 if (export_info
&& export_info
->handleTypes
)
3073 bo_flags
|= ANV_BO_EXTERNAL
;
3075 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
3076 pAllocateInfo
->allocationSize
, bo_flags
,
3078 if (result
!= VK_SUCCESS
)
3081 const VkMemoryDedicatedAllocateInfo
*dedicated_info
=
3082 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3083 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
3084 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
3086 /* Some legacy (non-modifiers) consumers need the tiling to be set on
3087 * the BO. In this case, we have a dedicated allocation.
3089 if (image
->needs_set_tiling
) {
3090 const uint32_t i915_tiling
=
3091 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
3092 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
3093 image
->planes
[0].surface
.isl
.row_pitch_B
,
3096 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
3097 return vk_errorf(device
->instance
, NULL
,
3098 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
3099 "failed to set BO tiling: %m");
3105 pthread_mutex_lock(&device
->mutex
);
3106 list_addtail(&mem
->link
, &device
->memory_objects
);
3107 pthread_mutex_unlock(&device
->mutex
);
3109 *pMem
= anv_device_memory_to_handle(mem
);
3111 p_atomic_add(&pdevice
->memory
.heaps
[mem
->type
->heapIndex
].used
,
3117 vk_free2(&device
->alloc
, pAllocator
, mem
);
3122 VkResult
anv_GetMemoryFdKHR(
3124 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
3127 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
3128 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
3130 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3132 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3133 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3135 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
3138 VkResult
anv_GetMemoryFdPropertiesKHR(
3140 VkExternalMemoryHandleTypeFlagBits handleType
,
3142 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
3144 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3145 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3147 switch (handleType
) {
3148 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
3149 /* dma-buf can be imported as any memory type */
3150 pMemoryFdProperties
->memoryTypeBits
=
3151 (1 << pdevice
->memory
.type_count
) - 1;
3155 /* The valid usage section for this function says:
3157 * "handleType must not be one of the handle types defined as
3160 * So opaque handle types fall into the default "unsupported" case.
3162 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
3166 VkResult
anv_GetMemoryHostPointerPropertiesEXT(
3168 VkExternalMemoryHandleTypeFlagBits handleType
,
3169 const void* pHostPointer
,
3170 VkMemoryHostPointerPropertiesEXT
* pMemoryHostPointerProperties
)
3172 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3174 assert(pMemoryHostPointerProperties
->sType
==
3175 VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT
);
3177 switch (handleType
) {
3178 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
3179 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3181 /* Host memory can be imported as any memory type. */
3182 pMemoryHostPointerProperties
->memoryTypeBits
=
3183 (1ull << pdevice
->memory
.type_count
) - 1;
3188 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3192 void anv_FreeMemory(
3194 VkDeviceMemory _mem
,
3195 const VkAllocationCallbacks
* pAllocator
)
3197 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3198 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
3199 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3204 pthread_mutex_lock(&device
->mutex
);
3205 list_del(&mem
->link
);
3206 pthread_mutex_unlock(&device
->mutex
);
3209 anv_UnmapMemory(_device
, _mem
);
3211 p_atomic_add(&pdevice
->memory
.heaps
[mem
->type
->heapIndex
].used
,
3214 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
3216 #if defined(ANDROID) && ANDROID_API_LEVEL >= 26
3218 AHardwareBuffer_release(mem
->ahw
);
3221 vk_free2(&device
->alloc
, pAllocator
, mem
);
3224 VkResult
anv_MapMemory(
3226 VkDeviceMemory _memory
,
3227 VkDeviceSize offset
,
3229 VkMemoryMapFlags flags
,
3232 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3233 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3240 if (mem
->host_ptr
) {
3241 *ppData
= mem
->host_ptr
+ offset
;
3245 if (size
== VK_WHOLE_SIZE
)
3246 size
= mem
->bo
->size
- offset
;
3248 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
3250 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
3251 * assert(size != 0);
3252 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
3253 * equal to the size of the memory minus offset
3256 assert(offset
+ size
<= mem
->bo
->size
);
3258 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
3259 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
3260 * at a time is valid. We could just mmap up front and return an offset
3261 * pointer here, but that may exhaust virtual memory on 32 bit
3264 uint32_t gem_flags
= 0;
3266 if (!device
->info
.has_llc
&&
3267 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
3268 gem_flags
|= I915_MMAP_WC
;
3270 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
3271 uint64_t map_offset
= offset
& ~4095ull;
3272 assert(offset
>= map_offset
);
3273 uint64_t map_size
= (offset
+ size
) - map_offset
;
3275 /* Let's map whole pages */
3276 map_size
= align_u64(map_size
, 4096);
3278 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
3279 map_offset
, map_size
, gem_flags
);
3280 if (map
== MAP_FAILED
)
3281 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
3284 mem
->map_size
= map_size
;
3286 *ppData
= mem
->map
+ (offset
- map_offset
);
3291 void anv_UnmapMemory(
3293 VkDeviceMemory _memory
)
3295 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
3297 if (mem
== NULL
|| mem
->host_ptr
)
3300 anv_gem_munmap(mem
->map
, mem
->map_size
);
3307 clflush_mapped_ranges(struct anv_device
*device
,
3309 const VkMappedMemoryRange
*ranges
)
3311 for (uint32_t i
= 0; i
< count
; i
++) {
3312 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
3313 if (ranges
[i
].offset
>= mem
->map_size
)
3316 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
3317 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
3321 VkResult
anv_FlushMappedMemoryRanges(
3323 uint32_t memoryRangeCount
,
3324 const VkMappedMemoryRange
* pMemoryRanges
)
3326 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3328 if (device
->info
.has_llc
)
3331 /* Make sure the writes we're flushing have landed. */
3332 __builtin_ia32_mfence();
3334 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3339 VkResult
anv_InvalidateMappedMemoryRanges(
3341 uint32_t memoryRangeCount
,
3342 const VkMappedMemoryRange
* pMemoryRanges
)
3344 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3346 if (device
->info
.has_llc
)
3349 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
3351 /* Make sure no reads get moved up above the invalidate. */
3352 __builtin_ia32_mfence();
3357 void anv_GetBufferMemoryRequirements(
3360 VkMemoryRequirements
* pMemoryRequirements
)
3362 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3363 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3364 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3366 /* The Vulkan spec (git aaed022) says:
3368 * memoryTypeBits is a bitfield and contains one bit set for every
3369 * supported memory type for the resource. The bit `1<<i` is set if and
3370 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3371 * structure for the physical device is supported.
3373 uint32_t memory_types
= 0;
3374 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
3375 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
3376 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
3377 memory_types
|= (1u << i
);
3380 /* Base alignment requirement of a cache line */
3381 uint32_t alignment
= 16;
3383 /* We need an alignment of 32 for pushing UBOs */
3384 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
3385 alignment
= MAX2(alignment
, 32);
3387 pMemoryRequirements
->size
= buffer
->size
;
3388 pMemoryRequirements
->alignment
= alignment
;
3390 /* Storage and Uniform buffers should have their size aligned to
3391 * 32-bits to avoid boundary checks when last DWord is not complete.
3392 * This would ensure that not internal padding would be needed for
3395 if (device
->robust_buffer_access
&&
3396 (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
||
3397 buffer
->usage
& VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
))
3398 pMemoryRequirements
->size
= align_u64(buffer
->size
, 4);
3400 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3403 void anv_GetBufferMemoryRequirements2(
3405 const VkBufferMemoryRequirementsInfo2
* pInfo
,
3406 VkMemoryRequirements2
* pMemoryRequirements
)
3408 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
3409 &pMemoryRequirements
->memoryRequirements
);
3411 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3412 switch (ext
->sType
) {
3413 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3414 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
3415 requirements
->prefersDedicatedAllocation
= false;
3416 requirements
->requiresDedicatedAllocation
= false;
3421 anv_debug_ignored_stype(ext
->sType
);
3427 void anv_GetImageMemoryRequirements(
3430 VkMemoryRequirements
* pMemoryRequirements
)
3432 ANV_FROM_HANDLE(anv_image
, image
, _image
);
3433 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3434 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3436 /* The Vulkan spec (git aaed022) says:
3438 * memoryTypeBits is a bitfield and contains one bit set for every
3439 * supported memory type for the resource. The bit `1<<i` is set if and
3440 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
3441 * structure for the physical device is supported.
3443 * All types are currently supported for images.
3445 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
3447 /* We must have image allocated or imported at this point. According to the
3448 * specification, external images must have been bound to memory before
3449 * calling GetImageMemoryRequirements.
3451 assert(image
->size
> 0);
3453 pMemoryRequirements
->size
= image
->size
;
3454 pMemoryRequirements
->alignment
= image
->alignment
;
3455 pMemoryRequirements
->memoryTypeBits
= memory_types
;
3458 void anv_GetImageMemoryRequirements2(
3460 const VkImageMemoryRequirementsInfo2
* pInfo
,
3461 VkMemoryRequirements2
* pMemoryRequirements
)
3463 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3464 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
3466 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
3467 &pMemoryRequirements
->memoryRequirements
);
3469 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
3470 switch (ext
->sType
) {
3471 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO
: {
3472 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
3473 const VkImagePlaneMemoryRequirementsInfo
*plane_reqs
=
3474 (const VkImagePlaneMemoryRequirementsInfo
*) ext
;
3475 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
3476 plane_reqs
->planeAspect
);
3478 assert(image
->planes
[plane
].offset
== 0);
3480 /* The Vulkan spec (git aaed022) says:
3482 * memoryTypeBits is a bitfield and contains one bit set for every
3483 * supported memory type for the resource. The bit `1<<i` is set
3484 * if and only if the memory type `i` in the
3485 * VkPhysicalDeviceMemoryProperties structure for the physical
3486 * device is supported.
3488 * All types are currently supported for images.
3490 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
3491 (1ull << pdevice
->memory
.type_count
) - 1;
3493 /* We must have image allocated or imported at this point. According to the
3494 * specification, external images must have been bound to memory before
3495 * calling GetImageMemoryRequirements.
3497 assert(image
->planes
[plane
].size
> 0);
3499 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
3500 pMemoryRequirements
->memoryRequirements
.alignment
=
3501 image
->planes
[plane
].alignment
;
3506 anv_debug_ignored_stype(ext
->sType
);
3511 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3512 switch (ext
->sType
) {
3513 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3514 VkMemoryDedicatedRequirements
*requirements
= (void *)ext
;
3515 if (image
->needs_set_tiling
|| image
->external_format
) {
3516 /* If we need to set the tiling for external consumers, we need a
3517 * dedicated allocation.
3519 * See also anv_AllocateMemory.
3521 requirements
->prefersDedicatedAllocation
= true;
3522 requirements
->requiresDedicatedAllocation
= true;
3524 requirements
->prefersDedicatedAllocation
= false;
3525 requirements
->requiresDedicatedAllocation
= false;
3531 anv_debug_ignored_stype(ext
->sType
);
3537 void anv_GetImageSparseMemoryRequirements(
3540 uint32_t* pSparseMemoryRequirementCount
,
3541 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3543 *pSparseMemoryRequirementCount
= 0;
3546 void anv_GetImageSparseMemoryRequirements2(
3548 const VkImageSparseMemoryRequirementsInfo2
* pInfo
,
3549 uint32_t* pSparseMemoryRequirementCount
,
3550 VkSparseImageMemoryRequirements2
* pSparseMemoryRequirements
)
3552 *pSparseMemoryRequirementCount
= 0;
3555 void anv_GetDeviceMemoryCommitment(
3557 VkDeviceMemory memory
,
3558 VkDeviceSize
* pCommittedMemoryInBytes
)
3560 *pCommittedMemoryInBytes
= 0;
3564 anv_bind_buffer_memory(const VkBindBufferMemoryInfo
*pBindInfo
)
3566 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
3567 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
3569 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
);
3572 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
3573 buffer
->address
= (struct anv_address
) {
3575 .offset
= pBindInfo
->memoryOffset
,
3578 buffer
->address
= ANV_NULL_ADDRESS
;
3582 VkResult
anv_BindBufferMemory(
3585 VkDeviceMemory memory
,
3586 VkDeviceSize memoryOffset
)
3588 anv_bind_buffer_memory(
3589 &(VkBindBufferMemoryInfo
) {
3590 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3593 .memoryOffset
= memoryOffset
,
3599 VkResult
anv_BindBufferMemory2(
3601 uint32_t bindInfoCount
,
3602 const VkBindBufferMemoryInfo
* pBindInfos
)
3604 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
3605 anv_bind_buffer_memory(&pBindInfos
[i
]);
3610 VkResult
anv_QueueBindSparse(
3612 uint32_t bindInfoCount
,
3613 const VkBindSparseInfo
* pBindInfo
,
3616 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
3617 if (anv_device_is_lost(queue
->device
))
3618 return VK_ERROR_DEVICE_LOST
;
3620 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
3625 VkResult
anv_CreateEvent(
3627 const VkEventCreateInfo
* pCreateInfo
,
3628 const VkAllocationCallbacks
* pAllocator
,
3631 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3632 struct anv_state state
;
3633 struct anv_event
*event
;
3635 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
3637 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
3640 event
->state
= state
;
3641 event
->semaphore
= VK_EVENT_RESET
;
3643 if (!device
->info
.has_llc
) {
3644 /* Make sure the writes we're flushing have landed. */
3645 __builtin_ia32_mfence();
3646 __builtin_ia32_clflush(event
);
3649 *pEvent
= anv_event_to_handle(event
);
3654 void anv_DestroyEvent(
3657 const VkAllocationCallbacks
* pAllocator
)
3659 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3660 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3665 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
3668 VkResult
anv_GetEventStatus(
3672 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3673 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3675 if (anv_device_is_lost(device
))
3676 return VK_ERROR_DEVICE_LOST
;
3678 if (!device
->info
.has_llc
) {
3679 /* Invalidate read cache before reading event written by GPU. */
3680 __builtin_ia32_clflush(event
);
3681 __builtin_ia32_mfence();
3685 return event
->semaphore
;
3688 VkResult
anv_SetEvent(
3692 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3693 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3695 event
->semaphore
= VK_EVENT_SET
;
3697 if (!device
->info
.has_llc
) {
3698 /* Make sure the writes we're flushing have landed. */
3699 __builtin_ia32_mfence();
3700 __builtin_ia32_clflush(event
);
3706 VkResult
anv_ResetEvent(
3710 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3711 ANV_FROM_HANDLE(anv_event
, event
, _event
);
3713 event
->semaphore
= VK_EVENT_RESET
;
3715 if (!device
->info
.has_llc
) {
3716 /* Make sure the writes we're flushing have landed. */
3717 __builtin_ia32_mfence();
3718 __builtin_ia32_clflush(event
);
3726 VkResult
anv_CreateBuffer(
3728 const VkBufferCreateInfo
* pCreateInfo
,
3729 const VkAllocationCallbacks
* pAllocator
,
3732 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3733 struct anv_buffer
*buffer
;
3735 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3737 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3738 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3740 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3742 buffer
->size
= pCreateInfo
->size
;
3743 buffer
->usage
= pCreateInfo
->usage
;
3744 buffer
->address
= ANV_NULL_ADDRESS
;
3746 *pBuffer
= anv_buffer_to_handle(buffer
);
3751 void anv_DestroyBuffer(
3754 const VkAllocationCallbacks
* pAllocator
)
3756 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3757 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
3762 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3765 VkDeviceAddress
anv_GetBufferDeviceAddressEXT(
3767 const VkBufferDeviceAddressInfoEXT
* pInfo
)
3769 ANV_FROM_HANDLE(anv_buffer
, buffer
, pInfo
->buffer
);
3771 assert(buffer
->address
.bo
->flags
& EXEC_OBJECT_PINNED
);
3773 return anv_address_physical(buffer
->address
);
3777 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
3778 enum isl_format format
,
3779 struct anv_address address
,
3780 uint32_t range
, uint32_t stride
)
3782 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
3783 .address
= anv_address_physical(address
),
3784 .mocs
= device
->default_mocs
,
3787 .swizzle
= ISL_SWIZZLE_IDENTITY
,
3788 .stride_B
= stride
);
3791 void anv_DestroySampler(
3794 const VkAllocationCallbacks
* pAllocator
)
3796 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3797 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
3802 if (sampler
->bindless_state
.map
) {
3803 anv_state_pool_free(&device
->dynamic_state_pool
,
3804 sampler
->bindless_state
);
3807 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3810 VkResult
anv_CreateFramebuffer(
3812 const VkFramebufferCreateInfo
* pCreateInfo
,
3813 const VkAllocationCallbacks
* pAllocator
,
3814 VkFramebuffer
* pFramebuffer
)
3816 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3817 struct anv_framebuffer
*framebuffer
;
3819 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3821 size_t size
= sizeof(*framebuffer
);
3823 /* VK_KHR_imageless_framebuffer extension says:
3825 * If flags includes VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR,
3826 * parameter pAttachments is ignored.
3828 if (!(pCreateInfo
->flags
& VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR
)) {
3829 size
+= sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
3830 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3831 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3832 if (framebuffer
== NULL
)
3833 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3835 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3836 ANV_FROM_HANDLE(anv_image_view
, iview
, pCreateInfo
->pAttachments
[i
]);
3837 framebuffer
->attachments
[i
] = iview
;
3839 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3841 assert(device
->enabled_extensions
.KHR_imageless_framebuffer
);
3842 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3843 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3844 if (framebuffer
== NULL
)
3845 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3847 framebuffer
->attachment_count
= 0;
3850 framebuffer
->width
= pCreateInfo
->width
;
3851 framebuffer
->height
= pCreateInfo
->height
;
3852 framebuffer
->layers
= pCreateInfo
->layers
;
3854 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
3859 void anv_DestroyFramebuffer(
3862 const VkAllocationCallbacks
* pAllocator
)
3864 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3865 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
3870 vk_free2(&device
->alloc
, pAllocator
, fb
);
3873 static const VkTimeDomainEXT anv_time_domains
[] = {
3874 VK_TIME_DOMAIN_DEVICE_EXT
,
3875 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
3876 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
3879 VkResult
anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
3880 VkPhysicalDevice physicalDevice
,
3881 uint32_t *pTimeDomainCount
,
3882 VkTimeDomainEXT
*pTimeDomains
)
3885 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
3887 for (d
= 0; d
< ARRAY_SIZE(anv_time_domains
); d
++) {
3888 vk_outarray_append(&out
, i
) {
3889 *i
= anv_time_domains
[d
];
3893 return vk_outarray_status(&out
);
3897 anv_clock_gettime(clockid_t clock_id
)
3899 struct timespec current
;
3902 ret
= clock_gettime(clock_id
, ¤t
);
3903 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
3904 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3908 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
3911 #define TIMESTAMP 0x2358
3913 VkResult
anv_GetCalibratedTimestampsEXT(
3915 uint32_t timestampCount
,
3916 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
3917 uint64_t *pTimestamps
,
3918 uint64_t *pMaxDeviation
)
3920 ANV_FROM_HANDLE(anv_device
, device
, _device
);
3921 uint64_t timestamp_frequency
= device
->info
.timestamp_frequency
;
3924 uint64_t begin
, end
;
3925 uint64_t max_clock_period
= 0;
3927 begin
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3929 for (d
= 0; d
< timestampCount
; d
++) {
3930 switch (pTimestampInfos
[d
].timeDomain
) {
3931 case VK_TIME_DOMAIN_DEVICE_EXT
:
3932 ret
= anv_gem_reg_read(device
, TIMESTAMP
| 1,
3936 return anv_device_set_lost(device
, "Failed to read the TIMESTAMP "
3939 uint64_t device_period
= DIV_ROUND_UP(1000000000, timestamp_frequency
);
3940 max_clock_period
= MAX2(max_clock_period
, device_period
);
3942 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
3943 pTimestamps
[d
] = anv_clock_gettime(CLOCK_MONOTONIC
);
3944 max_clock_period
= MAX2(max_clock_period
, 1);
3947 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
3948 pTimestamps
[d
] = begin
;
3956 end
= anv_clock_gettime(CLOCK_MONOTONIC_RAW
);
3959 * The maximum deviation is the sum of the interval over which we
3960 * perform the sampling and the maximum period of any sampled
3961 * clock. That's because the maximum skew between any two sampled
3962 * clock edges is when the sampled clock with the largest period is
3963 * sampled at the end of that period but right at the beginning of the
3964 * sampling interval and some other clock is sampled right at the
3965 * begining of its sampling period and right at the end of the
3966 * sampling interval. Let's assume the GPU has the longest clock
3967 * period and that the application is sampling GPU and monotonic:
3970 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
3971 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3975 * GPU -----_____-----_____-----_____-----_____
3978 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
3979 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
3981 * Interval <----------------->
3982 * Deviation <-------------------------->
3986 * m = read(monotonic) 2
3989 * We round the sample interval up by one tick to cover sampling error
3990 * in the interval clock
3993 uint64_t sample_interval
= end
- begin
+ 1;
3995 *pMaxDeviation
= sample_interval
+ max_clock_period
;
4000 /* vk_icd.h does not declare this function, so we declare it here to
4001 * suppress Wmissing-prototypes.
4003 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4004 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
4006 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4007 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
4009 /* For the full details on loader interface versioning, see
4010 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4011 * What follows is a condensed summary, to help you navigate the large and
4012 * confusing official doc.
4014 * - Loader interface v0 is incompatible with later versions. We don't
4017 * - In loader interface v1:
4018 * - The first ICD entrypoint called by the loader is
4019 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4021 * - The ICD must statically expose no other Vulkan symbol unless it is
4022 * linked with -Bsymbolic.
4023 * - Each dispatchable Vulkan handle created by the ICD must be
4024 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4025 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4026 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4027 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4028 * such loader-managed surfaces.
4030 * - Loader interface v2 differs from v1 in:
4031 * - The first ICD entrypoint called by the loader is
4032 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4033 * statically expose this entrypoint.
4035 * - Loader interface v3 differs from v2 in:
4036 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4037 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4038 * because the loader no longer does so.
4040 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);