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_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/mesa-sha1.h"
41 #include "genxml/gen7_pack.h"
44 compiler_debug_log(void *data
, const char *fmt
, ...)
48 compiler_perf_log(void *data
, const char *fmt
, ...)
53 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
54 intel_logd_v(fmt
, args
);
60 anv_compute_heap_size(int fd
, uint64_t *heap_size
)
63 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
65 /* If, for whatever reason, we can't actually get the GTT size from the
66 * kernel (too old?) fall back to the aperture size.
68 anv_perf_warn(NULL
, NULL
,
69 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
71 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
72 return vk_errorf(NULL
, NULL
, VK_ERROR_INITIALIZATION_FAILED
,
73 "failed to get aperture size: %m");
77 /* Query the total ram from the system */
81 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
83 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
84 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
86 uint64_t available_ram
;
87 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
88 available_ram
= total_ram
/ 2;
90 available_ram
= total_ram
* 3 / 4;
92 /* We also want to leave some padding for things we allocate in the driver,
93 * so don't go over 3/4 of the GTT either.
95 uint64_t available_gtt
= gtt_size
* 3 / 4;
97 *heap_size
= MIN2(available_ram
, available_gtt
);
103 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
105 /* The kernel query only tells us whether or not the kernel supports the
106 * EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and not whether or not the
107 * hardware has actual 48bit address support.
109 device
->supports_48bit_addresses
=
110 (device
->info
.gen
>= 8) && anv_gem_supports_48b_addresses(fd
);
113 VkResult result
= anv_compute_heap_size(fd
, &heap_size
);
114 if (result
!= VK_SUCCESS
)
117 if (heap_size
> (2ull << 30) && !device
->supports_48bit_addresses
) {
118 /* When running with an overridden PCI ID, we may get a GTT size from
119 * the kernel that is greater than 2 GiB but the execbuf check for 48bit
120 * address support can still fail. Just clamp the address space size to
121 * 2 GiB if we don't have 48-bit support.
123 intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but "
124 "not support for 48-bit addresses",
126 heap_size
= 2ull << 30;
129 if (heap_size
<= 3ull * (1ull << 30)) {
130 /* In this case, everything fits nicely into the 32-bit address space,
131 * so there's no need for supporting 48bit addresses on client-allocated
134 device
->memory
.heap_count
= 1;
135 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
137 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
138 .supports_48bit_addresses
= false,
141 /* Not everything will fit nicely into a 32-bit address space. In this
142 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
143 * larger 48-bit heap. If we're in this case, then we have a total heap
144 * size larger than 3GiB which most likely means they have 8 GiB of
145 * video memory and so carving off 1 GiB for the 32-bit heap should be
148 const uint64_t heap_size_32bit
= 1ull << 30;
149 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
151 assert(device
->supports_48bit_addresses
);
153 device
->memory
.heap_count
= 2;
154 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
155 .size
= heap_size_48bit
,
156 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
157 .supports_48bit_addresses
= true,
159 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
160 .size
= heap_size_32bit
,
161 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
162 .supports_48bit_addresses
= false,
166 uint32_t type_count
= 0;
167 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
168 uint32_t valid_buffer_usage
= ~0;
170 /* There appears to be a hardware issue in the VF cache where it only
171 * considers the bottom 32 bits of memory addresses. If you happen to
172 * have two vertex buffers which get placed exactly 4 GiB apart and use
173 * them in back-to-back draw calls, you can get collisions. In order to
174 * solve this problem, we require vertex and index buffers be bound to
175 * memory allocated out of the 32-bit heap.
177 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
178 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
179 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
182 if (device
->info
.has_llc
) {
183 /* Big core GPUs share LLC with the CPU and thus one memory type can be
184 * both cached and coherent at the same time.
186 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
187 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
188 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
189 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
190 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
192 .valid_buffer_usage
= valid_buffer_usage
,
195 /* The spec requires that we expose a host-visible, coherent memory
196 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
197 * to give the application a choice between cached, but not coherent and
198 * coherent but uncached (WC though).
200 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
201 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
202 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
203 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
205 .valid_buffer_usage
= valid_buffer_usage
,
207 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
208 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
209 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
210 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
212 .valid_buffer_usage
= valid_buffer_usage
,
216 device
->memory
.type_count
= type_count
;
222 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
224 const struct build_id_note
*note
=
225 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
227 return vk_errorf(device
->instance
, device
,
228 VK_ERROR_INITIALIZATION_FAILED
,
229 "Failed to find build-id");
232 unsigned build_id_len
= build_id_length(note
);
233 if (build_id_len
< 20) {
234 return vk_errorf(device
->instance
, device
,
235 VK_ERROR_INITIALIZATION_FAILED
,
236 "build-id too short. It needs to be a SHA");
239 struct mesa_sha1 sha1_ctx
;
241 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
243 /* The pipeline cache UUID is used for determining when a pipeline cache is
244 * invalid. It needs both a driver build and the PCI ID of the device.
246 _mesa_sha1_init(&sha1_ctx
);
247 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
248 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
249 sizeof(device
->chipset_id
));
250 _mesa_sha1_final(&sha1_ctx
, sha1
);
251 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
253 /* The driver UUID is used for determining sharability of images and memory
254 * between two Vulkan instances in separate processes. People who want to
255 * share memory need to also check the device UUID (below) so all this
256 * needs to be is the build-id.
258 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
260 /* The device UUID uniquely identifies the given device within the machine.
261 * Since we never have more than one device, this doesn't need to be a real
262 * UUID. However, on the off-chance that someone tries to use this to
263 * cache pre-tiled images or something of the like, we use the PCI ID and
264 * some bits of ISL info to ensure that this is safe.
266 _mesa_sha1_init(&sha1_ctx
);
267 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
268 sizeof(device
->chipset_id
));
269 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
270 sizeof(device
->isl_dev
.has_bit6_swizzling
));
271 _mesa_sha1_final(&sha1_ctx
, sha1
);
272 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
278 anv_physical_device_init(struct anv_physical_device
*device
,
279 struct anv_instance
*instance
,
285 brw_process_intel_debug_variable();
287 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
289 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
291 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
292 device
->instance
= instance
;
294 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
295 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
297 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
298 if (!device
->chipset_id
) {
299 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
303 device
->name
= gen_get_device_name(device
->chipset_id
);
304 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
305 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
309 if (device
->info
.is_haswell
) {
310 intel_logw("Haswell Vulkan support is incomplete");
311 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
312 intel_logw("Ivy Bridge Vulkan support is incomplete");
313 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
314 intel_logw("Bay Trail Vulkan support is incomplete");
315 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 9) {
316 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake, Coffelake is as
317 * fully supported as anything */
318 } else if (device
->info
.gen
== 10) {
319 intel_logw("Cannonlake Vulkan support is alpha");
321 result
= vk_errorf(device
->instance
, device
,
322 VK_ERROR_INCOMPATIBLE_DRIVER
,
323 "Vulkan not yet supported on %s", device
->name
);
327 device
->cmd_parser_version
= -1;
328 if (device
->info
.gen
== 7) {
329 device
->cmd_parser_version
=
330 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
331 if (device
->cmd_parser_version
== -1) {
332 result
= vk_errorf(device
->instance
, device
,
333 VK_ERROR_INITIALIZATION_FAILED
,
334 "failed to get command parser version");
339 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
340 result
= vk_errorf(device
->instance
, device
,
341 VK_ERROR_INITIALIZATION_FAILED
,
342 "kernel missing gem wait");
346 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
347 result
= vk_errorf(device
->instance
, device
,
348 VK_ERROR_INITIALIZATION_FAILED
,
349 "kernel missing execbuf2");
353 if (!device
->info
.has_llc
&&
354 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
355 result
= vk_errorf(device
->instance
, device
,
356 VK_ERROR_INITIALIZATION_FAILED
,
357 "kernel missing wc mmap");
361 result
= anv_physical_device_init_heaps(device
, fd
);
362 if (result
!= VK_SUCCESS
)
365 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
366 device
->has_exec_capture
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CAPTURE
);
367 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
368 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
369 device
->has_syncobj_wait
= device
->has_syncobj
&&
370 anv_gem_supports_syncobj_wait(fd
);
372 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
374 /* Starting with Gen10, the timestamp frequency of the command streamer may
375 * vary from one part to another. We can query the value from the kernel.
377 if (device
->info
.gen
>= 10) {
378 int timestamp_frequency
=
379 anv_gem_get_param(fd
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
);
381 if (timestamp_frequency
< 0)
382 intel_logw("Kernel 4.16-rc1+ required to properly query CS timestamp frequency");
384 device
->info
.timestamp_frequency
= timestamp_frequency
;
387 /* GENs prior to 8 do not support EU/Subslice info */
388 if (device
->info
.gen
>= 8) {
389 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
390 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
392 /* Without this information, we cannot get the right Braswell
393 * brandstrings, and we have to use conservative numbers for GPGPU on
394 * many platforms, but otherwise, things will just work.
396 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
397 intel_logw("Kernel 4.1 required to properly query GPU properties");
399 } else if (device
->info
.gen
== 7) {
400 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
403 if (device
->info
.is_cherryview
&&
404 device
->subslice_total
> 0 && device
->eu_total
> 0) {
405 /* Logical CS threads = EUs per subslice * num threads per EU */
406 uint32_t max_cs_threads
=
407 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
409 /* Fuse configurations may give more threads than expected, never less. */
410 if (max_cs_threads
> device
->info
.max_cs_threads
)
411 device
->info
.max_cs_threads
= max_cs_threads
;
414 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
415 if (device
->compiler
== NULL
) {
416 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
419 device
->compiler
->shader_debug_log
= compiler_debug_log
;
420 device
->compiler
->shader_perf_log
= compiler_perf_log
;
421 device
->compiler
->supports_pull_constants
= false;
422 device
->compiler
->constant_buffer_0_is_relative
= true;
424 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
426 result
= anv_physical_device_init_uuids(device
);
427 if (result
!= VK_SUCCESS
)
430 result
= anv_init_wsi(device
);
431 if (result
!= VK_SUCCESS
) {
432 ralloc_free(device
->compiler
);
436 anv_physical_device_get_supported_extensions(device
,
437 &device
->supported_extensions
);
439 device
->local_fd
= fd
;
448 anv_physical_device_finish(struct anv_physical_device
*device
)
450 anv_finish_wsi(device
);
451 ralloc_free(device
->compiler
);
452 close(device
->local_fd
);
456 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
457 VkSystemAllocationScope allocationScope
)
463 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
464 size_t align
, VkSystemAllocationScope allocationScope
)
466 return realloc(pOriginal
, size
);
470 default_free_func(void *pUserData
, void *pMemory
)
475 static const VkAllocationCallbacks default_alloc
= {
477 .pfnAllocation
= default_alloc_func
,
478 .pfnReallocation
= default_realloc_func
,
479 .pfnFree
= default_free_func
,
482 VkResult
anv_EnumerateInstanceExtensionProperties(
483 const char* pLayerName
,
484 uint32_t* pPropertyCount
,
485 VkExtensionProperties
* pProperties
)
487 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
489 for (int i
= 0; i
< ANV_INSTANCE_EXTENSION_COUNT
; i
++) {
490 if (anv_instance_extensions_supported
.extensions
[i
]) {
491 vk_outarray_append(&out
, prop
) {
492 *prop
= anv_instance_extensions
[i
];
497 return vk_outarray_status(&out
);
500 VkResult
anv_CreateInstance(
501 const VkInstanceCreateInfo
* pCreateInfo
,
502 const VkAllocationCallbacks
* pAllocator
,
503 VkInstance
* pInstance
)
505 struct anv_instance
*instance
;
508 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
510 /* Check if user passed a debug report callback to be used during
511 * Create/Destroy of instance.
513 const VkDebugReportCallbackCreateInfoEXT
*ctor_cb
=
514 vk_find_struct_const(pCreateInfo
->pNext
,
515 DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT
);
517 uint32_t client_version
;
518 if (pCreateInfo
->pApplicationInfo
&&
519 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
520 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
522 client_version
= VK_MAKE_VERSION(1, 0, 0);
525 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
526 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
528 if (ctor_cb
&& ctor_cb
->flags
& VK_DEBUG_REPORT_ERROR_BIT_EXT
)
529 ctor_cb
->pfnCallback(VK_DEBUG_REPORT_ERROR_BIT_EXT
,
530 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
,
531 VK_NULL_HANDLE
, /* No handle available yet. */
535 "incompatible driver version",
538 return vk_errorf(NULL
, NULL
, VK_ERROR_INCOMPATIBLE_DRIVER
,
539 "Client requested version %d.%d.%d",
540 VK_VERSION_MAJOR(client_version
),
541 VK_VERSION_MINOR(client_version
),
542 VK_VERSION_PATCH(client_version
));
545 struct anv_instance_extension_table enabled_extensions
= {};
546 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
548 for (idx
= 0; idx
< ANV_INSTANCE_EXTENSION_COUNT
; idx
++) {
549 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
550 anv_instance_extensions
[idx
].extensionName
) == 0)
554 if (idx
>= ANV_INSTANCE_EXTENSION_COUNT
)
555 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
557 if (!anv_instance_extensions_supported
.extensions
[idx
])
558 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
560 enabled_extensions
.extensions
[idx
] = true;
563 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
564 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
566 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
568 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
571 instance
->alloc
= *pAllocator
;
573 instance
->alloc
= default_alloc
;
575 instance
->apiVersion
= client_version
;
576 instance
->enabled_extensions
= enabled_extensions
;
578 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
579 /* Vulkan requires that entrypoints for extensions which have not been
580 * enabled must not be advertised.
582 if (!anv_entrypoint_is_enabled(i
, instance
->apiVersion
,
583 &instance
->enabled_extensions
, NULL
)) {
584 instance
->dispatch
.entrypoints
[i
] = NULL
;
586 instance
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
590 instance
->physicalDeviceCount
= -1;
592 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
593 if (result
!= VK_SUCCESS
) {
594 vk_free2(&default_alloc
, pAllocator
, instance
);
595 return vk_error(result
);
600 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
602 *pInstance
= anv_instance_to_handle(instance
);
607 void anv_DestroyInstance(
608 VkInstance _instance
,
609 const VkAllocationCallbacks
* pAllocator
)
611 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
616 if (instance
->physicalDeviceCount
> 0) {
617 /* We support at most one physical device. */
618 assert(instance
->physicalDeviceCount
== 1);
619 anv_physical_device_finish(&instance
->physicalDevice
);
622 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
624 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
628 vk_free(&instance
->alloc
, instance
);
632 anv_enumerate_devices(struct anv_instance
*instance
)
634 /* TODO: Check for more devices ? */
635 drmDevicePtr devices
[8];
636 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
639 instance
->physicalDeviceCount
= 0;
641 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
643 return VK_ERROR_INCOMPATIBLE_DRIVER
;
645 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
646 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
647 devices
[i
]->bustype
== DRM_BUS_PCI
&&
648 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
650 result
= anv_physical_device_init(&instance
->physicalDevice
,
652 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
653 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
657 drmFreeDevices(devices
, max_devices
);
659 if (result
== VK_SUCCESS
)
660 instance
->physicalDeviceCount
= 1;
666 VkResult
anv_EnumeratePhysicalDevices(
667 VkInstance _instance
,
668 uint32_t* pPhysicalDeviceCount
,
669 VkPhysicalDevice
* pPhysicalDevices
)
671 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
672 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
675 if (instance
->physicalDeviceCount
< 0) {
676 result
= anv_enumerate_devices(instance
);
677 if (result
!= VK_SUCCESS
&&
678 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
682 if (instance
->physicalDeviceCount
> 0) {
683 assert(instance
->physicalDeviceCount
== 1);
684 vk_outarray_append(&out
, i
) {
685 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
689 return vk_outarray_status(&out
);
692 void anv_GetPhysicalDeviceFeatures(
693 VkPhysicalDevice physicalDevice
,
694 VkPhysicalDeviceFeatures
* pFeatures
)
696 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
698 *pFeatures
= (VkPhysicalDeviceFeatures
) {
699 .robustBufferAccess
= true,
700 .fullDrawIndexUint32
= true,
701 .imageCubeArray
= true,
702 .independentBlend
= true,
703 .geometryShader
= true,
704 .tessellationShader
= true,
705 .sampleRateShading
= true,
706 .dualSrcBlend
= true,
708 .multiDrawIndirect
= true,
709 .drawIndirectFirstInstance
= true,
711 .depthBiasClamp
= true,
712 .fillModeNonSolid
= true,
713 .depthBounds
= false,
717 .multiViewport
= true,
718 .samplerAnisotropy
= true,
719 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
720 pdevice
->info
.is_baytrail
,
721 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
722 .textureCompressionBC
= true,
723 .occlusionQueryPrecise
= true,
724 .pipelineStatisticsQuery
= true,
725 .fragmentStoresAndAtomics
= true,
726 .shaderTessellationAndGeometryPointSize
= true,
727 .shaderImageGatherExtended
= true,
728 .shaderStorageImageExtendedFormats
= true,
729 .shaderStorageImageMultisample
= false,
730 .shaderStorageImageReadWithoutFormat
= false,
731 .shaderStorageImageWriteWithoutFormat
= true,
732 .shaderUniformBufferArrayDynamicIndexing
= true,
733 .shaderSampledImageArrayDynamicIndexing
= true,
734 .shaderStorageBufferArrayDynamicIndexing
= true,
735 .shaderStorageImageArrayDynamicIndexing
= true,
736 .shaderClipDistance
= true,
737 .shaderCullDistance
= true,
738 .shaderFloat64
= pdevice
->info
.gen
>= 8,
739 .shaderInt64
= pdevice
->info
.gen
>= 8,
740 .shaderInt16
= false,
741 .shaderResourceMinLod
= false,
742 .variableMultisampleRate
= false,
743 .inheritedQueries
= true,
746 /* We can't do image stores in vec4 shaders */
747 pFeatures
->vertexPipelineStoresAndAtomics
=
748 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
749 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
752 void anv_GetPhysicalDeviceFeatures2KHR(
753 VkPhysicalDevice physicalDevice
,
754 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
756 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
758 vk_foreach_struct(ext
, pFeatures
->pNext
) {
759 switch (ext
->sType
) {
760 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
761 VkPhysicalDeviceMultiviewFeaturesKHX
*features
=
762 (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
763 features
->multiview
= true;
764 features
->multiviewGeometryShader
= true;
765 features
->multiviewTessellationShader
= true;
769 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
770 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
771 features
->variablePointersStorageBuffer
= true;
772 features
->variablePointers
= true;
776 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES_KHR
: {
777 VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR
*features
=
778 (VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR
*) ext
;
779 features
->samplerYcbcrConversion
= true;
783 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR
: {
784 VkPhysicalDevice16BitStorageFeaturesKHR
*features
=
785 (VkPhysicalDevice16BitStorageFeaturesKHR
*)ext
;
787 features
->storageBuffer16BitAccess
= false;
788 features
->uniformAndStorageBuffer16BitAccess
= false;
789 features
->storagePushConstant16
= false;
790 features
->storageInputOutput16
= false;
795 anv_debug_ignored_stype(ext
->sType
);
801 void anv_GetPhysicalDeviceProperties(
802 VkPhysicalDevice physicalDevice
,
803 VkPhysicalDeviceProperties
* pProperties
)
805 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
806 const struct gen_device_info
*devinfo
= &pdevice
->info
;
808 /* See assertions made when programming the buffer surface state. */
809 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
810 (1ul << 30) : (1ul << 27);
812 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
815 VkSampleCountFlags sample_counts
=
816 isl_device_get_sample_counts(&pdevice
->isl_dev
);
818 VkPhysicalDeviceLimits limits
= {
819 .maxImageDimension1D
= (1 << 14),
820 .maxImageDimension2D
= (1 << 14),
821 .maxImageDimension3D
= (1 << 11),
822 .maxImageDimensionCube
= (1 << 14),
823 .maxImageArrayLayers
= (1 << 11),
824 .maxTexelBufferElements
= 128 * 1024 * 1024,
825 .maxUniformBufferRange
= (1ul << 27),
826 .maxStorageBufferRange
= max_raw_buffer_sz
,
827 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
828 .maxMemoryAllocationCount
= UINT32_MAX
,
829 .maxSamplerAllocationCount
= 64 * 1024,
830 .bufferImageGranularity
= 64, /* A cache line */
831 .sparseAddressSpaceSize
= 0,
832 .maxBoundDescriptorSets
= MAX_SETS
,
833 .maxPerStageDescriptorSamplers
= max_samplers
,
834 .maxPerStageDescriptorUniformBuffers
= 64,
835 .maxPerStageDescriptorStorageBuffers
= 64,
836 .maxPerStageDescriptorSampledImages
= max_samplers
,
837 .maxPerStageDescriptorStorageImages
= 64,
838 .maxPerStageDescriptorInputAttachments
= 64,
839 .maxPerStageResources
= 250,
840 .maxDescriptorSetSamplers
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSamplers */
841 .maxDescriptorSetUniformBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorUniformBuffers */
842 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
843 .maxDescriptorSetStorageBuffers
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageBuffers */
844 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
845 .maxDescriptorSetSampledImages
= 6 * max_samplers
, /* number of stages * maxPerStageDescriptorSampledImages */
846 .maxDescriptorSetStorageImages
= 6 * 64, /* number of stages * maxPerStageDescriptorStorageImages */
847 .maxDescriptorSetInputAttachments
= 256,
848 .maxVertexInputAttributes
= MAX_VBS
,
849 .maxVertexInputBindings
= MAX_VBS
,
850 .maxVertexInputAttributeOffset
= 2047,
851 .maxVertexInputBindingStride
= 2048,
852 .maxVertexOutputComponents
= 128,
853 .maxTessellationGenerationLevel
= 64,
854 .maxTessellationPatchSize
= 32,
855 .maxTessellationControlPerVertexInputComponents
= 128,
856 .maxTessellationControlPerVertexOutputComponents
= 128,
857 .maxTessellationControlPerPatchOutputComponents
= 128,
858 .maxTessellationControlTotalOutputComponents
= 2048,
859 .maxTessellationEvaluationInputComponents
= 128,
860 .maxTessellationEvaluationOutputComponents
= 128,
861 .maxGeometryShaderInvocations
= 32,
862 .maxGeometryInputComponents
= 64,
863 .maxGeometryOutputComponents
= 128,
864 .maxGeometryOutputVertices
= 256,
865 .maxGeometryTotalOutputComponents
= 1024,
866 .maxFragmentInputComponents
= 128,
867 .maxFragmentOutputAttachments
= 8,
868 .maxFragmentDualSrcAttachments
= 1,
869 .maxFragmentCombinedOutputResources
= 8,
870 .maxComputeSharedMemorySize
= 32768,
871 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
872 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
873 .maxComputeWorkGroupSize
= {
874 16 * devinfo
->max_cs_threads
,
875 16 * devinfo
->max_cs_threads
,
876 16 * devinfo
->max_cs_threads
,
878 .subPixelPrecisionBits
= 4 /* FIXME */,
879 .subTexelPrecisionBits
= 4 /* FIXME */,
880 .mipmapPrecisionBits
= 4 /* FIXME */,
881 .maxDrawIndexedIndexValue
= UINT32_MAX
,
882 .maxDrawIndirectCount
= UINT32_MAX
,
883 .maxSamplerLodBias
= 16,
884 .maxSamplerAnisotropy
= 16,
885 .maxViewports
= MAX_VIEWPORTS
,
886 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
887 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
888 .viewportSubPixelBits
= 13, /* We take a float? */
889 .minMemoryMapAlignment
= 4096, /* A page */
890 .minTexelBufferOffsetAlignment
= 1,
891 /* We need 16 for UBO block reads to work and 32 for push UBOs */
892 .minUniformBufferOffsetAlignment
= 32,
893 .minStorageBufferOffsetAlignment
= 4,
894 .minTexelOffset
= -8,
896 .minTexelGatherOffset
= -32,
897 .maxTexelGatherOffset
= 31,
898 .minInterpolationOffset
= -0.5,
899 .maxInterpolationOffset
= 0.4375,
900 .subPixelInterpolationOffsetBits
= 4,
901 .maxFramebufferWidth
= (1 << 14),
902 .maxFramebufferHeight
= (1 << 14),
903 .maxFramebufferLayers
= (1 << 11),
904 .framebufferColorSampleCounts
= sample_counts
,
905 .framebufferDepthSampleCounts
= sample_counts
,
906 .framebufferStencilSampleCounts
= sample_counts
,
907 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
908 .maxColorAttachments
= MAX_RTS
,
909 .sampledImageColorSampleCounts
= sample_counts
,
910 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
911 .sampledImageDepthSampleCounts
= sample_counts
,
912 .sampledImageStencilSampleCounts
= sample_counts
,
913 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
914 .maxSampleMaskWords
= 1,
915 .timestampComputeAndGraphics
= false,
916 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
917 .maxClipDistances
= 8,
918 .maxCullDistances
= 8,
919 .maxCombinedClipAndCullDistances
= 8,
920 .discreteQueuePriorities
= 1,
921 .pointSizeRange
= { 0.125, 255.875 },
922 .lineWidthRange
= { 0.0, 7.9921875 },
923 .pointSizeGranularity
= (1.0 / 8.0),
924 .lineWidthGranularity
= (1.0 / 128.0),
925 .strictLines
= false, /* FINISHME */
926 .standardSampleLocations
= true,
927 .optimalBufferCopyOffsetAlignment
= 128,
928 .optimalBufferCopyRowPitchAlignment
= 128,
929 .nonCoherentAtomSize
= 64,
932 *pProperties
= (VkPhysicalDeviceProperties
) {
933 .apiVersion
= anv_physical_device_api_version(pdevice
),
934 .driverVersion
= vk_get_driver_version(),
936 .deviceID
= pdevice
->chipset_id
,
937 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
939 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
942 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
943 "%s", pdevice
->name
);
944 memcpy(pProperties
->pipelineCacheUUID
,
945 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
948 void anv_GetPhysicalDeviceProperties2KHR(
949 VkPhysicalDevice physicalDevice
,
950 VkPhysicalDeviceProperties2KHR
* pProperties
)
952 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
954 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
956 vk_foreach_struct(ext
, pProperties
->pNext
) {
957 switch (ext
->sType
) {
958 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
959 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
960 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
962 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
966 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
967 VkPhysicalDeviceIDPropertiesKHR
*id_props
=
968 (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
969 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
970 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
971 /* The LUID is for Windows. */
972 id_props
->deviceLUIDValid
= false;
976 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
977 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
=
978 (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
979 properties
->maxMultiviewViewCount
= 16;
980 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
984 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
985 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
986 (VkPhysicalDevicePointClippingPropertiesKHR
*) ext
;
987 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
988 anv_finishme("Implement pop-free point clipping");
993 anv_debug_ignored_stype(ext
->sType
);
999 /* We support exactly one queue family. */
1000 static const VkQueueFamilyProperties
1001 anv_queue_family_properties
= {
1002 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1003 VK_QUEUE_COMPUTE_BIT
|
1004 VK_QUEUE_TRANSFER_BIT
,
1006 .timestampValidBits
= 36, /* XXX: Real value here */
1007 .minImageTransferGranularity
= { 1, 1, 1 },
1010 void anv_GetPhysicalDeviceQueueFamilyProperties(
1011 VkPhysicalDevice physicalDevice
,
1013 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1015 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
1017 vk_outarray_append(&out
, p
) {
1018 *p
= anv_queue_family_properties
;
1022 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
1023 VkPhysicalDevice physicalDevice
,
1024 uint32_t* pQueueFamilyPropertyCount
,
1025 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
1028 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1030 vk_outarray_append(&out
, p
) {
1031 p
->queueFamilyProperties
= anv_queue_family_properties
;
1033 vk_foreach_struct(s
, p
->pNext
) {
1034 anv_debug_ignored_stype(s
->sType
);
1039 void anv_GetPhysicalDeviceMemoryProperties(
1040 VkPhysicalDevice physicalDevice
,
1041 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
1043 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1045 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
1046 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
1047 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
1048 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
1049 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
1053 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
1054 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
1055 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
1056 .size
= physical_device
->memory
.heaps
[i
].size
,
1057 .flags
= physical_device
->memory
.heaps
[i
].flags
,
1062 void anv_GetPhysicalDeviceMemoryProperties2KHR(
1063 VkPhysicalDevice physicalDevice
,
1064 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
1066 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1067 &pMemoryProperties
->memoryProperties
);
1069 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
1070 switch (ext
->sType
) {
1072 anv_debug_ignored_stype(ext
->sType
);
1078 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1079 VkInstance _instance
,
1082 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1084 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
1085 * when we have to return valid function pointers, NULL, or it's left
1086 * undefined. See the table for exact details.
1091 #define LOOKUP_ANV_ENTRYPOINT(entrypoint) \
1092 if (strcmp(pName, "vk" #entrypoint) == 0) \
1093 return (PFN_vkVoidFunction)anv_##entrypoint
1095 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
1096 LOOKUP_ANV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
1097 LOOKUP_ANV_ENTRYPOINT(CreateInstance
);
1099 #undef LOOKUP_ANV_ENTRYPOINT
1101 if (instance
== NULL
)
1104 int idx
= anv_get_entrypoint_index(pName
);
1108 return instance
->dispatch
.entrypoints
[idx
];
1111 /* With version 1+ of the loader interface the ICD should expose
1112 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1115 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1116 VkInstance instance
,
1120 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1121 VkInstance instance
,
1124 return anv_GetInstanceProcAddr(instance
, pName
);
1127 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1131 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1133 if (!device
|| !pName
)
1136 int idx
= anv_get_entrypoint_index(pName
);
1140 return device
->dispatch
.entrypoints
[idx
];
1144 anv_CreateDebugReportCallbackEXT(VkInstance _instance
,
1145 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
1146 const VkAllocationCallbacks
* pAllocator
,
1147 VkDebugReportCallbackEXT
* pCallback
)
1149 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1150 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
1151 pCreateInfo
, pAllocator
, &instance
->alloc
,
1156 anv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
1157 VkDebugReportCallbackEXT _callback
,
1158 const VkAllocationCallbacks
* pAllocator
)
1160 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1161 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
1162 _callback
, pAllocator
, &instance
->alloc
);
1166 anv_DebugReportMessageEXT(VkInstance _instance
,
1167 VkDebugReportFlagsEXT flags
,
1168 VkDebugReportObjectTypeEXT objectType
,
1171 int32_t messageCode
,
1172 const char* pLayerPrefix
,
1173 const char* pMessage
)
1175 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
1176 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
1177 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
1181 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1183 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1184 queue
->device
= device
;
1185 queue
->pool
= &device
->surface_state_pool
;
1189 anv_queue_finish(struct anv_queue
*queue
)
1193 static struct anv_state
1194 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1196 struct anv_state state
;
1198 state
= anv_state_pool_alloc(pool
, size
, align
);
1199 memcpy(state
.map
, p
, size
);
1201 anv_state_flush(pool
->block_pool
.device
, state
);
1206 struct gen8_border_color
{
1211 /* Pad out to 64 bytes */
1216 anv_device_init_border_colors(struct anv_device
*device
)
1218 static const struct gen8_border_color border_colors
[] = {
1219 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1220 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1221 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1222 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1223 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1224 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1227 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1228 sizeof(border_colors
), 64,
1233 anv_device_init_trivial_batch(struct anv_device
*device
)
1235 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1237 if (device
->instance
->physicalDevice
.has_exec_async
)
1238 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1240 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1243 struct anv_batch batch
= {
1249 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1250 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1252 if (!device
->info
.has_llc
)
1253 gen_clflush_range(map
, batch
.next
- map
);
1255 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1258 VkResult
anv_EnumerateDeviceExtensionProperties(
1259 VkPhysicalDevice physicalDevice
,
1260 const char* pLayerName
,
1261 uint32_t* pPropertyCount
,
1262 VkExtensionProperties
* pProperties
)
1264 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
1265 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1268 for (int i
= 0; i
< ANV_DEVICE_EXTENSION_COUNT
; i
++) {
1269 if (device
->supported_extensions
.extensions
[i
]) {
1270 vk_outarray_append(&out
, prop
) {
1271 *prop
= anv_device_extensions
[i
];
1276 return vk_outarray_status(&out
);
1280 anv_device_init_dispatch(struct anv_device
*device
)
1282 const struct anv_dispatch_table
*genX_table
;
1283 switch (device
->info
.gen
) {
1285 genX_table
= &gen10_dispatch_table
;
1288 genX_table
= &gen9_dispatch_table
;
1291 genX_table
= &gen8_dispatch_table
;
1294 if (device
->info
.is_haswell
)
1295 genX_table
= &gen75_dispatch_table
;
1297 genX_table
= &gen7_dispatch_table
;
1300 unreachable("unsupported gen\n");
1303 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
1304 /* Vulkan requires that entrypoints for extensions which have not been
1305 * enabled must not be advertised.
1307 if (!anv_entrypoint_is_enabled(i
, device
->instance
->apiVersion
,
1308 &device
->instance
->enabled_extensions
,
1309 &device
->enabled_extensions
)) {
1310 device
->dispatch
.entrypoints
[i
] = NULL
;
1311 } else if (genX_table
->entrypoints
[i
]) {
1312 device
->dispatch
.entrypoints
[i
] = genX_table
->entrypoints
[i
];
1314 device
->dispatch
.entrypoints
[i
] = anv_dispatch_table
.entrypoints
[i
];
1319 VkResult
anv_CreateDevice(
1320 VkPhysicalDevice physicalDevice
,
1321 const VkDeviceCreateInfo
* pCreateInfo
,
1322 const VkAllocationCallbacks
* pAllocator
,
1325 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1327 struct anv_device
*device
;
1329 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1331 struct anv_device_extension_table enabled_extensions
;
1332 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1334 for (idx
= 0; idx
< ANV_DEVICE_EXTENSION_COUNT
; idx
++) {
1335 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1336 anv_device_extensions
[idx
].extensionName
) == 0)
1340 if (idx
>= ANV_DEVICE_EXTENSION_COUNT
)
1341 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1343 if (!physical_device
->supported_extensions
.extensions
[idx
])
1344 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1346 enabled_extensions
.extensions
[idx
] = true;
1349 /* Check enabled features */
1350 if (pCreateInfo
->pEnabledFeatures
) {
1351 VkPhysicalDeviceFeatures supported_features
;
1352 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1353 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1354 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1355 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1356 for (uint32_t i
= 0; i
< num_features
; i
++) {
1357 if (enabled_feature
[i
] && !supported_feature
[i
])
1358 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1362 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1364 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1366 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1368 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1369 device
->instance
= physical_device
->instance
;
1370 device
->chipset_id
= physical_device
->chipset_id
;
1371 device
->lost
= false;
1374 device
->alloc
= *pAllocator
;
1376 device
->alloc
= physical_device
->instance
->alloc
;
1378 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1379 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1380 if (device
->fd
== -1) {
1381 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1385 device
->context_id
= anv_gem_create_context(device
);
1386 if (device
->context_id
== -1) {
1387 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1391 device
->info
= physical_device
->info
;
1392 device
->isl_dev
= physical_device
->isl_dev
;
1394 /* On Broadwell and later, we can use batch chaining to more efficiently
1395 * implement growing command buffers. Prior to Haswell, the kernel
1396 * command parser gets in the way and we have to fall back to growing
1399 device
->can_chain_batches
= device
->info
.gen
>= 8;
1401 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1402 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1403 device
->enabled_extensions
= enabled_extensions
;
1405 anv_device_init_dispatch(device
);
1407 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1408 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1409 goto fail_context_id
;
1412 pthread_condattr_t condattr
;
1413 if (pthread_condattr_init(&condattr
) != 0) {
1414 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1417 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1418 pthread_condattr_destroy(&condattr
);
1419 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1422 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1423 pthread_condattr_destroy(&condattr
);
1424 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1427 pthread_condattr_destroy(&condattr
);
1430 (physical_device
->supports_48bit_addresses
? EXEC_OBJECT_SUPPORTS_48B_ADDRESS
: 0) |
1431 (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1432 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0);
1434 anv_bo_pool_init(&device
->batch_bo_pool
, device
, bo_flags
);
1436 result
= anv_bo_cache_init(&device
->bo_cache
);
1437 if (result
!= VK_SUCCESS
)
1438 goto fail_batch_bo_pool
;
1440 /* For the state pools we explicitly disable 48bit. */
1441 bo_flags
= (physical_device
->has_exec_async
? EXEC_OBJECT_ASYNC
: 0) |
1442 (physical_device
->has_exec_capture
? EXEC_OBJECT_CAPTURE
: 0);
1444 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384,
1446 if (result
!= VK_SUCCESS
)
1449 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384,
1451 if (result
!= VK_SUCCESS
)
1452 goto fail_dynamic_state_pool
;
1454 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096,
1456 if (result
!= VK_SUCCESS
)
1457 goto fail_instruction_state_pool
;
1459 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1460 if (result
!= VK_SUCCESS
)
1461 goto fail_surface_state_pool
;
1463 anv_device_init_trivial_batch(device
);
1465 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1467 anv_queue_init(device
, &device
->queue
);
1469 switch (device
->info
.gen
) {
1471 if (!device
->info
.is_haswell
)
1472 result
= gen7_init_device_state(device
);
1474 result
= gen75_init_device_state(device
);
1477 result
= gen8_init_device_state(device
);
1480 result
= gen9_init_device_state(device
);
1483 result
= gen10_init_device_state(device
);
1486 /* Shouldn't get here as we don't create physical devices for any other
1488 unreachable("unhandled gen");
1490 if (result
!= VK_SUCCESS
)
1491 goto fail_workaround_bo
;
1493 anv_device_init_blorp(device
);
1495 anv_device_init_border_colors(device
);
1497 *pDevice
= anv_device_to_handle(device
);
1502 anv_queue_finish(&device
->queue
);
1503 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1504 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1505 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1506 fail_surface_state_pool
:
1507 anv_state_pool_finish(&device
->surface_state_pool
);
1508 fail_instruction_state_pool
:
1509 anv_state_pool_finish(&device
->instruction_state_pool
);
1510 fail_dynamic_state_pool
:
1511 anv_state_pool_finish(&device
->dynamic_state_pool
);
1513 anv_bo_cache_finish(&device
->bo_cache
);
1515 anv_bo_pool_finish(&device
->batch_bo_pool
);
1516 pthread_cond_destroy(&device
->queue_submit
);
1518 pthread_mutex_destroy(&device
->mutex
);
1520 anv_gem_destroy_context(device
, device
->context_id
);
1524 vk_free(&device
->alloc
, device
);
1529 void anv_DestroyDevice(
1531 const VkAllocationCallbacks
* pAllocator
)
1533 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1538 anv_device_finish_blorp(device
);
1540 anv_queue_finish(&device
->queue
);
1542 #ifdef HAVE_VALGRIND
1543 /* We only need to free these to prevent valgrind errors. The backing
1544 * BO will go away in a couple of lines so we don't actually leak.
1546 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1549 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1551 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1552 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1554 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1556 anv_state_pool_finish(&device
->surface_state_pool
);
1557 anv_state_pool_finish(&device
->instruction_state_pool
);
1558 anv_state_pool_finish(&device
->dynamic_state_pool
);
1560 anv_bo_cache_finish(&device
->bo_cache
);
1562 anv_bo_pool_finish(&device
->batch_bo_pool
);
1564 pthread_cond_destroy(&device
->queue_submit
);
1565 pthread_mutex_destroy(&device
->mutex
);
1567 anv_gem_destroy_context(device
, device
->context_id
);
1571 vk_free(&device
->alloc
, device
);
1574 VkResult
anv_EnumerateInstanceLayerProperties(
1575 uint32_t* pPropertyCount
,
1576 VkLayerProperties
* pProperties
)
1578 if (pProperties
== NULL
) {
1579 *pPropertyCount
= 0;
1583 /* None supported at this time */
1584 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1587 VkResult
anv_EnumerateDeviceLayerProperties(
1588 VkPhysicalDevice physicalDevice
,
1589 uint32_t* pPropertyCount
,
1590 VkLayerProperties
* pProperties
)
1592 if (pProperties
== NULL
) {
1593 *pPropertyCount
= 0;
1597 /* None supported at this time */
1598 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1601 void anv_GetDeviceQueue(
1603 uint32_t queueNodeIndex
,
1604 uint32_t queueIndex
,
1607 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1609 assert(queueIndex
== 0);
1611 *pQueue
= anv_queue_to_handle(&device
->queue
);
1615 anv_device_query_status(struct anv_device
*device
)
1617 /* This isn't likely as most of the callers of this function already check
1618 * for it. However, it doesn't hurt to check and it potentially lets us
1621 if (unlikely(device
->lost
))
1622 return VK_ERROR_DEVICE_LOST
;
1624 uint32_t active
, pending
;
1625 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1627 /* We don't know the real error. */
1628 device
->lost
= true;
1629 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1630 "get_reset_stats failed: %m");
1634 device
->lost
= true;
1635 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1636 "GPU hung on one of our command buffers");
1637 } else if (pending
) {
1638 device
->lost
= true;
1639 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1640 "GPU hung with commands in-flight");
1647 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1649 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1650 * Other usages of the BO (such as on different hardware) will not be
1651 * flagged as "busy" by this ioctl. Use with care.
1653 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1655 return VK_NOT_READY
;
1656 } else if (ret
== -1) {
1657 /* We don't know the real error. */
1658 device
->lost
= true;
1659 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1660 "gem wait failed: %m");
1663 /* Query for device status after the busy call. If the BO we're checking
1664 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1665 * client because it clearly doesn't have valid data. Yes, this most
1666 * likely means an ioctl, but we just did an ioctl to query the busy status
1667 * so it's no great loss.
1669 return anv_device_query_status(device
);
1673 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1676 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1677 if (ret
== -1 && errno
== ETIME
) {
1679 } else if (ret
== -1) {
1680 /* We don't know the real error. */
1681 device
->lost
= true;
1682 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1683 "gem wait failed: %m");
1686 /* Query for device status after the wait. If the BO we're waiting on got
1687 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1688 * because it clearly doesn't have valid data. Yes, this most likely means
1689 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1691 return anv_device_query_status(device
);
1694 VkResult
anv_DeviceWaitIdle(
1697 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1698 if (unlikely(device
->lost
))
1699 return VK_ERROR_DEVICE_LOST
;
1701 struct anv_batch batch
;
1704 batch
.start
= batch
.next
= cmds
;
1705 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1707 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1708 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1710 return anv_device_submit_simple_batch(device
, &batch
);
1714 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1716 uint32_t gem_handle
= anv_gem_create(device
, size
);
1718 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1720 anv_bo_init(bo
, gem_handle
, size
);
1725 VkResult
anv_AllocateMemory(
1727 const VkMemoryAllocateInfo
* pAllocateInfo
,
1728 const VkAllocationCallbacks
* pAllocator
,
1729 VkDeviceMemory
* pMem
)
1731 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1732 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1733 struct anv_device_memory
*mem
;
1734 VkResult result
= VK_SUCCESS
;
1736 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1738 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1739 assert(pAllocateInfo
->allocationSize
> 0);
1741 /* The kernel relocation API has a limitation of a 32-bit delta value
1742 * applied to the address before it is written which, in spite of it being
1743 * unsigned, is treated as signed . Because of the way that this maps to
1744 * the Vulkan API, we cannot handle an offset into a buffer that does not
1745 * fit into a signed 32 bits. The only mechanism we have for dealing with
1746 * this at the moment is to limit all VkDeviceMemory objects to a maximum
1747 * of 2GB each. The Vulkan spec allows us to do this:
1749 * "Some platforms may have a limit on the maximum size of a single
1750 * allocation. For example, certain systems may fail to create
1751 * allocations with a size greater than or equal to 4GB. Such a limit is
1752 * implementation-dependent, and if such a failure occurs then the error
1753 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
1755 * We don't use vk_error here because it's not an error so much as an
1756 * indication to the application that the allocation is too large.
1758 if (pAllocateInfo
->allocationSize
> (1ull << 31))
1759 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1761 /* FINISHME: Fail if allocation request exceeds heap size. */
1763 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1764 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1766 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1768 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1769 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1773 const VkImportMemoryFdInfoKHR
*fd_info
=
1774 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1776 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1779 if (fd_info
&& fd_info
->handleType
) {
1780 /* At the moment, we support only the below handle types. */
1781 assert(fd_info
->handleType
==
1782 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
1783 fd_info
->handleType
==
1784 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1786 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1787 fd_info
->fd
, &mem
->bo
);
1788 if (result
!= VK_SUCCESS
)
1791 VkDeviceSize aligned_alloc_size
=
1792 align_u64(pAllocateInfo
->allocationSize
, 4096);
1794 /* For security purposes, we reject importing the bo if it's smaller
1795 * than the requested allocation size. This prevents a malicious client
1796 * from passing a buffer to a trusted client, lying about the size, and
1797 * telling the trusted client to try and texture from an image that goes
1798 * out-of-bounds. This sort of thing could lead to GPU hangs or worse
1799 * in the trusted client. The trusted client can protect itself against
1800 * this sort of attack but only if it can trust the buffer size.
1802 if (mem
->bo
->size
< aligned_alloc_size
) {
1803 result
= vk_errorf(device
->instance
, device
,
1804 VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
,
1805 "aligned allocationSize too large for "
1806 "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR: "
1807 "%"PRIu64
"B > %"PRIu64
"B",
1808 aligned_alloc_size
, mem
->bo
->size
);
1809 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1813 /* From the Vulkan spec:
1815 * "Importing memory from a file descriptor transfers ownership of
1816 * the file descriptor from the application to the Vulkan
1817 * implementation. The application must not perform any operations on
1818 * the file descriptor after a successful import."
1820 * If the import fails, we leave the file descriptor open.
1824 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1825 pAllocateInfo
->allocationSize
,
1827 if (result
!= VK_SUCCESS
)
1830 const VkMemoryDedicatedAllocateInfoKHR
*dedicated_info
=
1831 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
1832 if (dedicated_info
&& dedicated_info
->image
!= VK_NULL_HANDLE
) {
1833 ANV_FROM_HANDLE(anv_image
, image
, dedicated_info
->image
);
1835 /* For images using modifiers, we require a dedicated allocation
1836 * and we set the BO tiling to match the tiling of the underlying
1837 * modifier. This is a bit unfortunate as this is completely
1838 * pointless for Vulkan. However, GL needs to be able to map things
1839 * so it needs the tiling to be set. The only way to do this in a
1840 * non-racy way is to set the tiling in the creator of the BO so that
1843 * One of these days, once the GL driver learns to not map things
1844 * through the GTT in random places, we can drop this and start
1845 * allowing multiple modified images in the same BO.
1847 if (image
->drm_format_mod
!= DRM_FORMAT_MOD_INVALID
) {
1848 assert(isl_drm_modifier_get_info(image
->drm_format_mod
)->tiling
==
1849 image
->planes
[0].surface
.isl
.tiling
);
1850 const uint32_t i915_tiling
=
1851 isl_tiling_to_i915_tiling(image
->planes
[0].surface
.isl
.tiling
);
1852 int ret
= anv_gem_set_tiling(device
, mem
->bo
->gem_handle
,
1853 image
->planes
[0].surface
.isl
.row_pitch
,
1856 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1857 return vk_errorf(device
->instance
, NULL
,
1858 VK_ERROR_OUT_OF_DEVICE_MEMORY
,
1859 "failed to set BO tiling: %m");
1865 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
1866 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
1867 mem
->bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1869 const struct wsi_memory_allocate_info
*wsi_info
=
1870 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
1871 if (wsi_info
&& wsi_info
->implicit_sync
) {
1872 /* We need to set the WRITE flag on window system buffers so that GEM
1873 * will know we're writing to them and synchronize uses on other rings
1874 * (eg if the display server uses the blitter ring).
1876 mem
->bo
->flags
|= EXEC_OBJECT_WRITE
;
1877 } else if (pdevice
->has_exec_async
) {
1878 mem
->bo
->flags
|= EXEC_OBJECT_ASYNC
;
1881 *pMem
= anv_device_memory_to_handle(mem
);
1886 vk_free2(&device
->alloc
, pAllocator
, mem
);
1891 VkResult
anv_GetMemoryFdKHR(
1893 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
1896 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
1897 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
1899 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
1901 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
1902 pGetFdInfo
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1904 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
1907 VkResult
anv_GetMemoryFdPropertiesKHR(
1909 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1911 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
1913 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1914 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1916 switch (handleType
) {
1917 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1918 /* dma-buf can be imported as any memory type */
1919 pMemoryFdProperties
->memoryTypeBits
=
1920 (1 << pdevice
->memory
.type_count
) - 1;
1924 /* The valid usage section for this function says:
1926 * "handleType must not be one of the handle types defined as
1929 * So opaque handle types fall into the default "unsupported" case.
1931 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
1935 void anv_FreeMemory(
1937 VkDeviceMemory _mem
,
1938 const VkAllocationCallbacks
* pAllocator
)
1940 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1941 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1947 anv_UnmapMemory(_device
, _mem
);
1949 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1951 vk_free2(&device
->alloc
, pAllocator
, mem
);
1954 VkResult
anv_MapMemory(
1956 VkDeviceMemory _memory
,
1957 VkDeviceSize offset
,
1959 VkMemoryMapFlags flags
,
1962 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1963 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1970 if (size
== VK_WHOLE_SIZE
)
1971 size
= mem
->bo
->size
- offset
;
1973 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1975 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1976 * assert(size != 0);
1977 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1978 * equal to the size of the memory minus offset
1981 assert(offset
+ size
<= mem
->bo
->size
);
1983 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1984 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1985 * at a time is valid. We could just mmap up front and return an offset
1986 * pointer here, but that may exhaust virtual memory on 32 bit
1989 uint32_t gem_flags
= 0;
1991 if (!device
->info
.has_llc
&&
1992 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
1993 gem_flags
|= I915_MMAP_WC
;
1995 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1996 uint64_t map_offset
= offset
& ~4095ull;
1997 assert(offset
>= map_offset
);
1998 uint64_t map_size
= (offset
+ size
) - map_offset
;
2000 /* Let's map whole pages */
2001 map_size
= align_u64(map_size
, 4096);
2003 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
2004 map_offset
, map_size
, gem_flags
);
2005 if (map
== MAP_FAILED
)
2006 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2009 mem
->map_size
= map_size
;
2011 *ppData
= mem
->map
+ (offset
- map_offset
);
2016 void anv_UnmapMemory(
2018 VkDeviceMemory _memory
)
2020 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
2025 anv_gem_munmap(mem
->map
, mem
->map_size
);
2032 clflush_mapped_ranges(struct anv_device
*device
,
2034 const VkMappedMemoryRange
*ranges
)
2036 for (uint32_t i
= 0; i
< count
; i
++) {
2037 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
2038 if (ranges
[i
].offset
>= mem
->map_size
)
2041 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
2042 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
2046 VkResult
anv_FlushMappedMemoryRanges(
2048 uint32_t memoryRangeCount
,
2049 const VkMappedMemoryRange
* pMemoryRanges
)
2051 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2053 if (device
->info
.has_llc
)
2056 /* Make sure the writes we're flushing have landed. */
2057 __builtin_ia32_mfence();
2059 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2064 VkResult
anv_InvalidateMappedMemoryRanges(
2066 uint32_t memoryRangeCount
,
2067 const VkMappedMemoryRange
* pMemoryRanges
)
2069 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2071 if (device
->info
.has_llc
)
2074 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
2076 /* Make sure no reads get moved up above the invalidate. */
2077 __builtin_ia32_mfence();
2082 void anv_GetBufferMemoryRequirements(
2085 VkMemoryRequirements
* pMemoryRequirements
)
2087 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2088 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2089 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2091 /* The Vulkan spec (git aaed022) says:
2093 * memoryTypeBits is a bitfield and contains one bit set for every
2094 * supported memory type for the resource. The bit `1<<i` is set if and
2095 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2096 * structure for the physical device is supported.
2098 uint32_t memory_types
= 0;
2099 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
2100 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
2101 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
2102 memory_types
|= (1u << i
);
2105 /* Base alignment requirement of a cache line */
2106 uint32_t alignment
= 16;
2108 /* We need an alignment of 32 for pushing UBOs */
2109 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
2110 alignment
= MAX2(alignment
, 32);
2112 pMemoryRequirements
->size
= buffer
->size
;
2113 pMemoryRequirements
->alignment
= alignment
;
2114 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2117 void anv_GetBufferMemoryRequirements2KHR(
2119 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2120 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2122 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
2123 &pMemoryRequirements
->memoryRequirements
);
2125 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2126 switch (ext
->sType
) {
2127 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2128 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
2129 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2130 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2135 anv_debug_ignored_stype(ext
->sType
);
2141 void anv_GetImageMemoryRequirements(
2144 VkMemoryRequirements
* pMemoryRequirements
)
2146 ANV_FROM_HANDLE(anv_image
, image
, _image
);
2147 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2148 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2150 /* The Vulkan spec (git aaed022) says:
2152 * memoryTypeBits is a bitfield and contains one bit set for every
2153 * supported memory type for the resource. The bit `1<<i` is set if and
2154 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
2155 * structure for the physical device is supported.
2157 * All types are currently supported for images.
2159 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
2161 pMemoryRequirements
->size
= image
->size
;
2162 pMemoryRequirements
->alignment
= image
->alignment
;
2163 pMemoryRequirements
->memoryTypeBits
= memory_types
;
2166 void anv_GetImageMemoryRequirements2KHR(
2168 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2169 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2171 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2172 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
2174 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
2175 &pMemoryRequirements
->memoryRequirements
);
2177 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
2178 switch (ext
->sType
) {
2179 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO_KHR
: {
2180 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
2181 const VkImagePlaneMemoryRequirementsInfoKHR
*plane_reqs
=
2182 (const VkImagePlaneMemoryRequirementsInfoKHR
*) ext
;
2183 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
2184 plane_reqs
->planeAspect
);
2186 assert(image
->planes
[plane
].offset
== 0);
2188 /* The Vulkan spec (git aaed022) says:
2190 * memoryTypeBits is a bitfield and contains one bit set for every
2191 * supported memory type for the resource. The bit `1<<i` is set
2192 * if and only if the memory type `i` in the
2193 * VkPhysicalDeviceMemoryProperties structure for the physical
2194 * device is supported.
2196 * All types are currently supported for images.
2198 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
2199 (1ull << pdevice
->memory
.type_count
) - 1;
2201 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
2202 pMemoryRequirements
->memoryRequirements
.alignment
=
2203 image
->planes
[plane
].alignment
;
2208 anv_debug_ignored_stype(ext
->sType
);
2213 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2214 switch (ext
->sType
) {
2215 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2216 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
2217 if (image
->drm_format_mod
!= DRM_FORMAT_MOD_INVALID
) {
2218 /* Require a dedicated allocation for images with modifiers.
2220 * See also anv_AllocateMemory.
2222 requirements
->prefersDedicatedAllocation
= VK_TRUE
;
2223 requirements
->requiresDedicatedAllocation
= VK_TRUE
;
2225 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
2226 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
2232 anv_debug_ignored_stype(ext
->sType
);
2238 void anv_GetImageSparseMemoryRequirements(
2241 uint32_t* pSparseMemoryRequirementCount
,
2242 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2244 *pSparseMemoryRequirementCount
= 0;
2247 void anv_GetImageSparseMemoryRequirements2KHR(
2249 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2250 uint32_t* pSparseMemoryRequirementCount
,
2251 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2253 *pSparseMemoryRequirementCount
= 0;
2256 void anv_GetDeviceMemoryCommitment(
2258 VkDeviceMemory memory
,
2259 VkDeviceSize
* pCommittedMemoryInBytes
)
2261 *pCommittedMemoryInBytes
= 0;
2265 anv_bind_buffer_memory(const VkBindBufferMemoryInfoKHR
*pBindInfo
)
2267 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
2268 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
2270 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
);
2273 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
2274 buffer
->bo
= mem
->bo
;
2275 buffer
->offset
= pBindInfo
->memoryOffset
;
2282 VkResult
anv_BindBufferMemory(
2285 VkDeviceMemory memory
,
2286 VkDeviceSize memoryOffset
)
2288 anv_bind_buffer_memory(
2289 &(VkBindBufferMemoryInfoKHR
) {
2290 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2293 .memoryOffset
= memoryOffset
,
2299 VkResult
anv_BindBufferMemory2KHR(
2301 uint32_t bindInfoCount
,
2302 const VkBindBufferMemoryInfoKHR
* pBindInfos
)
2304 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
2305 anv_bind_buffer_memory(&pBindInfos
[i
]);
2310 VkResult
anv_QueueBindSparse(
2312 uint32_t bindInfoCount
,
2313 const VkBindSparseInfo
* pBindInfo
,
2316 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
2317 if (unlikely(queue
->device
->lost
))
2318 return VK_ERROR_DEVICE_LOST
;
2320 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
2325 VkResult
anv_CreateEvent(
2327 const VkEventCreateInfo
* pCreateInfo
,
2328 const VkAllocationCallbacks
* pAllocator
,
2331 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2332 struct anv_state state
;
2333 struct anv_event
*event
;
2335 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
2337 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2340 event
->state
= state
;
2341 event
->semaphore
= VK_EVENT_RESET
;
2343 if (!device
->info
.has_llc
) {
2344 /* Make sure the writes we're flushing have landed. */
2345 __builtin_ia32_mfence();
2346 __builtin_ia32_clflush(event
);
2349 *pEvent
= anv_event_to_handle(event
);
2354 void anv_DestroyEvent(
2357 const VkAllocationCallbacks
* pAllocator
)
2359 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2360 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2365 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2368 VkResult
anv_GetEventStatus(
2372 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2373 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2375 if (unlikely(device
->lost
))
2376 return VK_ERROR_DEVICE_LOST
;
2378 if (!device
->info
.has_llc
) {
2379 /* Invalidate read cache before reading event written by GPU. */
2380 __builtin_ia32_clflush(event
);
2381 __builtin_ia32_mfence();
2385 return event
->semaphore
;
2388 VkResult
anv_SetEvent(
2392 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2393 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2395 event
->semaphore
= VK_EVENT_SET
;
2397 if (!device
->info
.has_llc
) {
2398 /* Make sure the writes we're flushing have landed. */
2399 __builtin_ia32_mfence();
2400 __builtin_ia32_clflush(event
);
2406 VkResult
anv_ResetEvent(
2410 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2411 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2413 event
->semaphore
= VK_EVENT_RESET
;
2415 if (!device
->info
.has_llc
) {
2416 /* Make sure the writes we're flushing have landed. */
2417 __builtin_ia32_mfence();
2418 __builtin_ia32_clflush(event
);
2426 VkResult
anv_CreateBuffer(
2428 const VkBufferCreateInfo
* pCreateInfo
,
2429 const VkAllocationCallbacks
* pAllocator
,
2432 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2433 struct anv_buffer
*buffer
;
2435 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2437 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2438 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2440 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2442 buffer
->size
= pCreateInfo
->size
;
2443 buffer
->usage
= pCreateInfo
->usage
;
2447 *pBuffer
= anv_buffer_to_handle(buffer
);
2452 void anv_DestroyBuffer(
2455 const VkAllocationCallbacks
* pAllocator
)
2457 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2458 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2463 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2467 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2468 enum isl_format format
,
2469 uint32_t offset
, uint32_t range
, uint32_t stride
)
2471 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2473 .mocs
= device
->default_mocs
,
2478 anv_state_flush(device
, state
);
2481 void anv_DestroySampler(
2484 const VkAllocationCallbacks
* pAllocator
)
2486 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2487 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2492 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2495 VkResult
anv_CreateFramebuffer(
2497 const VkFramebufferCreateInfo
* pCreateInfo
,
2498 const VkAllocationCallbacks
* pAllocator
,
2499 VkFramebuffer
* pFramebuffer
)
2501 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2502 struct anv_framebuffer
*framebuffer
;
2504 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2506 size_t size
= sizeof(*framebuffer
) +
2507 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2508 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2509 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2510 if (framebuffer
== NULL
)
2511 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2513 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2514 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2515 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2516 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2519 framebuffer
->width
= pCreateInfo
->width
;
2520 framebuffer
->height
= pCreateInfo
->height
;
2521 framebuffer
->layers
= pCreateInfo
->layers
;
2523 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2528 void anv_DestroyFramebuffer(
2531 const VkAllocationCallbacks
* pAllocator
)
2533 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2534 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2539 vk_free2(&device
->alloc
, pAllocator
, fb
);
2542 /* vk_icd.h does not declare this function, so we declare it here to
2543 * suppress Wmissing-prototypes.
2545 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2546 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2548 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2549 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2551 /* For the full details on loader interface versioning, see
2552 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2553 * What follows is a condensed summary, to help you navigate the large and
2554 * confusing official doc.
2556 * - Loader interface v0 is incompatible with later versions. We don't
2559 * - In loader interface v1:
2560 * - The first ICD entrypoint called by the loader is
2561 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2563 * - The ICD must statically expose no other Vulkan symbol unless it is
2564 * linked with -Bsymbolic.
2565 * - Each dispatchable Vulkan handle created by the ICD must be
2566 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2567 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2568 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2569 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2570 * such loader-managed surfaces.
2572 * - Loader interface v2 differs from v1 in:
2573 * - The first ICD entrypoint called by the loader is
2574 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2575 * statically expose this entrypoint.
2577 * - Loader interface v3 differs from v2 in:
2578 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2579 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2580 * because the loader no longer does so.
2582 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);