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>
33 #include "anv_private.h"
34 #include "util/strtod.h"
35 #include "util/debug.h"
36 #include "util/build_id.h"
37 #include "util/mesa-sha1.h"
38 #include "util/vk_util.h"
40 #include "genxml/gen7_pack.h"
43 compiler_debug_log(void *data
, const char *fmt
, ...)
47 compiler_perf_log(void *data
, const char *fmt
, ...)
52 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
))
53 vfprintf(stderr
, fmt
, args
);
59 anv_compute_heap_size(int fd
, uint64_t *heap_size
)
62 if (anv_gem_get_context_param(fd
, 0, I915_CONTEXT_PARAM_GTT_SIZE
,
64 /* If, for whatever reason, we can't actually get the GTT size from the
65 * kernel (too old?) fall back to the aperture size.
67 anv_perf_warn("Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
69 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
70 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
71 "failed to get aperture size: %m");
75 /* Query the total ram from the system */
79 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
81 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
82 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
84 uint64_t available_ram
;
85 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
86 available_ram
= total_ram
/ 2;
88 available_ram
= total_ram
* 3 / 4;
90 /* We also want to leave some padding for things we allocate in the driver,
91 * so don't go over 3/4 of the GTT either.
93 uint64_t available_gtt
= gtt_size
* 3 / 4;
95 *heap_size
= MIN2(available_ram
, available_gtt
);
101 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
103 /* The kernel query only tells us whether or not the kernel supports the
104 * EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and not whether or not the
105 * hardware has actual 48bit address support.
107 device
->supports_48bit_addresses
=
108 (device
->info
.gen
>= 8) && anv_gem_supports_48b_addresses(fd
);
111 VkResult result
= anv_compute_heap_size(fd
, &heap_size
);
112 if (result
!= VK_SUCCESS
)
115 if (device
->info
.has_llc
) {
116 /* Big core GPUs share LLC with the CPU and thus one memory type can be
117 * both cached and coherent at the same time.
119 device
->memory
.type_count
= 1;
120 device
->memory
.types
[0] = (struct anv_memory_type
) {
121 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
122 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
123 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
124 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
126 .valid_buffer_usage
= ~0,
129 /* The spec requires that we expose a host-visible, coherent memory
130 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
131 * to give the application a choice between cached, but not coherent and
132 * coherent but uncached (WC though).
134 device
->memory
.type_count
= 2;
135 device
->memory
.types
[0] = (struct anv_memory_type
) {
136 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
137 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
138 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
140 .valid_buffer_usage
= ~0,
142 device
->memory
.types
[1] = (struct anv_memory_type
) {
143 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
144 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
145 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
147 .valid_buffer_usage
= ~0,
151 device
->memory
.heap_count
= 1;
152 device
->memory
.heaps
[0] = (VkMemoryHeap
) {
154 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
161 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
163 const struct build_id_note
*note
= build_id_find_nhdr("libvulkan_intel.so");
165 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
166 "Failed to find build-id");
169 unsigned build_id_len
= build_id_length(note
);
170 if (build_id_len
< 20) {
171 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
172 "build-id too short. It needs to be a SHA");
175 struct mesa_sha1 sha1_ctx
;
177 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
179 /* The pipeline cache UUID is used for determining when a pipeline cache is
180 * invalid. It needs both a driver build and the PCI ID of the device.
182 _mesa_sha1_init(&sha1_ctx
);
183 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
184 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
185 sizeof(device
->chipset_id
));
186 _mesa_sha1_final(&sha1_ctx
, sha1
);
187 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
189 /* The driver UUID is used for determining sharability of images and memory
190 * between two Vulkan instances in separate processes. People who want to
191 * share memory need to also check the device UUID (below) so all this
192 * needs to be is the build-id.
194 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
196 /* The device UUID uniquely identifies the given device within the machine.
197 * Since we never have more than one device, this doesn't need to be a real
198 * UUID. However, on the off-chance that someone tries to use this to
199 * cache pre-tiled images or something of the like, we use the PCI ID and
200 * some bits of ISL info to ensure that this is safe.
202 _mesa_sha1_init(&sha1_ctx
);
203 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
204 sizeof(device
->chipset_id
));
205 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
206 sizeof(device
->isl_dev
.has_bit6_swizzling
));
207 _mesa_sha1_final(&sha1_ctx
, sha1
);
208 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
214 anv_physical_device_init(struct anv_physical_device
*device
,
215 struct anv_instance
*instance
,
221 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
223 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
225 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
226 device
->instance
= instance
;
228 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
229 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
231 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
232 if (!device
->chipset_id
) {
233 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
237 device
->name
= gen_get_device_name(device
->chipset_id
);
238 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
239 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
243 if (device
->info
.is_haswell
) {
244 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
245 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
246 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
247 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
248 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
249 } else if (device
->info
.gen
>= 8) {
250 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
251 * supported as anything */
253 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
254 "Vulkan not yet supported on %s", device
->name
);
258 device
->cmd_parser_version
= -1;
259 if (device
->info
.gen
== 7) {
260 device
->cmd_parser_version
=
261 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
262 if (device
->cmd_parser_version
== -1) {
263 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
264 "failed to get command parser version");
269 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
270 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
271 "kernel missing gem wait");
275 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
276 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
277 "kernel missing execbuf2");
281 if (!device
->info
.has_llc
&&
282 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
283 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
284 "kernel missing wc mmap");
288 result
= anv_physical_device_init_heaps(device
, fd
);
289 if (result
!= VK_SUCCESS
)
292 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
294 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
296 /* GENs prior to 8 do not support EU/Subslice info */
297 if (device
->info
.gen
>= 8) {
298 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
299 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
301 /* Without this information, we cannot get the right Braswell
302 * brandstrings, and we have to use conservative numbers for GPGPU on
303 * many platforms, but otherwise, things will just work.
305 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
306 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
307 " query GPU properties.\n");
309 } else if (device
->info
.gen
== 7) {
310 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
313 if (device
->info
.is_cherryview
&&
314 device
->subslice_total
> 0 && device
->eu_total
> 0) {
315 /* Logical CS threads = EUs per subslice * 7 threads per EU */
316 uint32_t max_cs_threads
= device
->eu_total
/ device
->subslice_total
* 7;
318 /* Fuse configurations may give more threads than expected, never less. */
319 if (max_cs_threads
> device
->info
.max_cs_threads
)
320 device
->info
.max_cs_threads
= max_cs_threads
;
323 brw_process_intel_debug_variable();
325 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
326 if (device
->compiler
== NULL
) {
327 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
330 device
->compiler
->shader_debug_log
= compiler_debug_log
;
331 device
->compiler
->shader_perf_log
= compiler_perf_log
;
333 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
335 result
= anv_physical_device_init_uuids(device
);
336 if (result
!= VK_SUCCESS
)
339 result
= anv_init_wsi(device
);
340 if (result
!= VK_SUCCESS
) {
341 ralloc_free(device
->compiler
);
345 device
->local_fd
= fd
;
354 anv_physical_device_finish(struct anv_physical_device
*device
)
356 anv_finish_wsi(device
);
357 ralloc_free(device
->compiler
);
358 close(device
->local_fd
);
361 static const VkExtensionProperties global_extensions
[] = {
363 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
367 .extensionName
= VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME
,
371 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
374 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
376 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
380 #ifdef VK_USE_PLATFORM_XCB_KHR
382 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
386 #ifdef VK_USE_PLATFORM_XLIB_KHR
388 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
393 .extensionName
= VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
,
397 .extensionName
= VK_KHX_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME
,
402 static const VkExtensionProperties device_extensions
[] = {
404 .extensionName
= VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME
,
408 .extensionName
= VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME
,
412 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
416 .extensionName
= VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
,
420 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
424 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
428 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
432 .extensionName
= VK_KHX_EXTERNAL_MEMORY_EXTENSION_NAME
,
436 .extensionName
= VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME
,
440 .extensionName
= VK_KHX_EXTERNAL_SEMAPHORE_EXTENSION_NAME
,
444 .extensionName
= VK_KHX_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME
,
448 .extensionName
= VK_KHX_MULTIVIEW_EXTENSION_NAME
,
454 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
455 VkSystemAllocationScope allocationScope
)
461 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
462 size_t align
, VkSystemAllocationScope allocationScope
)
464 return realloc(pOriginal
, size
);
468 default_free_func(void *pUserData
, void *pMemory
)
473 static const VkAllocationCallbacks default_alloc
= {
475 .pfnAllocation
= default_alloc_func
,
476 .pfnReallocation
= default_realloc_func
,
477 .pfnFree
= default_free_func
,
480 VkResult
anv_CreateInstance(
481 const VkInstanceCreateInfo
* pCreateInfo
,
482 const VkAllocationCallbacks
* pAllocator
,
483 VkInstance
* pInstance
)
485 struct anv_instance
*instance
;
487 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
489 uint32_t client_version
;
490 if (pCreateInfo
->pApplicationInfo
&&
491 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
492 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
494 client_version
= VK_MAKE_VERSION(1, 0, 0);
497 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
498 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
499 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
500 "Client requested version %d.%d.%d",
501 VK_VERSION_MAJOR(client_version
),
502 VK_VERSION_MINOR(client_version
),
503 VK_VERSION_PATCH(client_version
));
506 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
508 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
509 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
510 global_extensions
[j
].extensionName
) == 0) {
516 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
519 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
520 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
522 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
524 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
527 instance
->alloc
= *pAllocator
;
529 instance
->alloc
= default_alloc
;
531 instance
->apiVersion
= client_version
;
532 instance
->physicalDeviceCount
= -1;
536 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
538 *pInstance
= anv_instance_to_handle(instance
);
543 void anv_DestroyInstance(
544 VkInstance _instance
,
545 const VkAllocationCallbacks
* pAllocator
)
547 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
552 if (instance
->physicalDeviceCount
> 0) {
553 /* We support at most one physical device. */
554 assert(instance
->physicalDeviceCount
== 1);
555 anv_physical_device_finish(&instance
->physicalDevice
);
558 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
562 vk_free(&instance
->alloc
, instance
);
566 anv_enumerate_devices(struct anv_instance
*instance
)
568 /* TODO: Check for more devices ? */
569 drmDevicePtr devices
[8];
570 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
573 instance
->physicalDeviceCount
= 0;
575 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
577 return VK_ERROR_INCOMPATIBLE_DRIVER
;
579 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
580 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
581 devices
[i
]->bustype
== DRM_BUS_PCI
&&
582 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
584 result
= anv_physical_device_init(&instance
->physicalDevice
,
586 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
587 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
591 drmFreeDevices(devices
, max_devices
);
593 if (result
== VK_SUCCESS
)
594 instance
->physicalDeviceCount
= 1;
600 VkResult
anv_EnumeratePhysicalDevices(
601 VkInstance _instance
,
602 uint32_t* pPhysicalDeviceCount
,
603 VkPhysicalDevice
* pPhysicalDevices
)
605 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
606 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
609 if (instance
->physicalDeviceCount
< 0) {
610 result
= anv_enumerate_devices(instance
);
611 if (result
!= VK_SUCCESS
&&
612 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
616 if (instance
->physicalDeviceCount
> 0) {
617 assert(instance
->physicalDeviceCount
== 1);
618 vk_outarray_append(&out
, i
) {
619 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
623 return vk_outarray_status(&out
);
626 void anv_GetPhysicalDeviceFeatures(
627 VkPhysicalDevice physicalDevice
,
628 VkPhysicalDeviceFeatures
* pFeatures
)
630 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
632 *pFeatures
= (VkPhysicalDeviceFeatures
) {
633 .robustBufferAccess
= true,
634 .fullDrawIndexUint32
= true,
635 .imageCubeArray
= true,
636 .independentBlend
= true,
637 .geometryShader
= true,
638 .tessellationShader
= true,
639 .sampleRateShading
= true,
640 .dualSrcBlend
= true,
642 .multiDrawIndirect
= true,
643 .drawIndirectFirstInstance
= true,
645 .depthBiasClamp
= true,
646 .fillModeNonSolid
= true,
647 .depthBounds
= false,
651 .multiViewport
= true,
652 .samplerAnisotropy
= true,
653 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
654 pdevice
->info
.is_baytrail
,
655 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
656 .textureCompressionBC
= true,
657 .occlusionQueryPrecise
= true,
658 .pipelineStatisticsQuery
= true,
659 .fragmentStoresAndAtomics
= true,
660 .shaderTessellationAndGeometryPointSize
= true,
661 .shaderImageGatherExtended
= true,
662 .shaderStorageImageExtendedFormats
= true,
663 .shaderStorageImageMultisample
= false,
664 .shaderStorageImageReadWithoutFormat
= false,
665 .shaderStorageImageWriteWithoutFormat
= true,
666 .shaderUniformBufferArrayDynamicIndexing
= true,
667 .shaderSampledImageArrayDynamicIndexing
= true,
668 .shaderStorageBufferArrayDynamicIndexing
= true,
669 .shaderStorageImageArrayDynamicIndexing
= true,
670 .shaderClipDistance
= true,
671 .shaderCullDistance
= true,
672 .shaderFloat64
= pdevice
->info
.gen
>= 8,
673 .shaderInt64
= pdevice
->info
.gen
>= 8,
674 .shaderInt16
= false,
675 .shaderResourceMinLod
= false,
676 .variableMultisampleRate
= false,
677 .inheritedQueries
= true,
680 /* We can't do image stores in vec4 shaders */
681 pFeatures
->vertexPipelineStoresAndAtomics
=
682 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
683 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
686 void anv_GetPhysicalDeviceFeatures2KHR(
687 VkPhysicalDevice physicalDevice
,
688 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
690 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
692 vk_foreach_struct(ext
, pFeatures
->pNext
) {
693 switch (ext
->sType
) {
694 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
695 VkPhysicalDeviceMultiviewFeaturesKHX
*features
=
696 (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
697 features
->multiview
= true;
698 features
->multiviewGeometryShader
= true;
699 features
->multiviewTessellationShader
= true;
704 anv_debug_ignored_stype(ext
->sType
);
710 void anv_GetPhysicalDeviceProperties(
711 VkPhysicalDevice physicalDevice
,
712 VkPhysicalDeviceProperties
* pProperties
)
714 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
715 const struct gen_device_info
*devinfo
= &pdevice
->info
;
717 /* See assertions made when programming the buffer surface state. */
718 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
719 (1ul << 30) : (1ul << 27);
721 VkSampleCountFlags sample_counts
=
722 isl_device_get_sample_counts(&pdevice
->isl_dev
);
724 VkPhysicalDeviceLimits limits
= {
725 .maxImageDimension1D
= (1 << 14),
726 .maxImageDimension2D
= (1 << 14),
727 .maxImageDimension3D
= (1 << 11),
728 .maxImageDimensionCube
= (1 << 14),
729 .maxImageArrayLayers
= (1 << 11),
730 .maxTexelBufferElements
= 128 * 1024 * 1024,
731 .maxUniformBufferRange
= (1ul << 27),
732 .maxStorageBufferRange
= max_raw_buffer_sz
,
733 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
734 .maxMemoryAllocationCount
= UINT32_MAX
,
735 .maxSamplerAllocationCount
= 64 * 1024,
736 .bufferImageGranularity
= 64, /* A cache line */
737 .sparseAddressSpaceSize
= 0,
738 .maxBoundDescriptorSets
= MAX_SETS
,
739 .maxPerStageDescriptorSamplers
= 64,
740 .maxPerStageDescriptorUniformBuffers
= 64,
741 .maxPerStageDescriptorStorageBuffers
= 64,
742 .maxPerStageDescriptorSampledImages
= 64,
743 .maxPerStageDescriptorStorageImages
= 64,
744 .maxPerStageDescriptorInputAttachments
= 64,
745 .maxPerStageResources
= 128,
746 .maxDescriptorSetSamplers
= 256,
747 .maxDescriptorSetUniformBuffers
= 256,
748 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
749 .maxDescriptorSetStorageBuffers
= 256,
750 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
751 .maxDescriptorSetSampledImages
= 256,
752 .maxDescriptorSetStorageImages
= 256,
753 .maxDescriptorSetInputAttachments
= 256,
754 .maxVertexInputAttributes
= MAX_VBS
,
755 .maxVertexInputBindings
= MAX_VBS
,
756 .maxVertexInputAttributeOffset
= 2047,
757 .maxVertexInputBindingStride
= 2048,
758 .maxVertexOutputComponents
= 128,
759 .maxTessellationGenerationLevel
= 64,
760 .maxTessellationPatchSize
= 32,
761 .maxTessellationControlPerVertexInputComponents
= 128,
762 .maxTessellationControlPerVertexOutputComponents
= 128,
763 .maxTessellationControlPerPatchOutputComponents
= 128,
764 .maxTessellationControlTotalOutputComponents
= 2048,
765 .maxTessellationEvaluationInputComponents
= 128,
766 .maxTessellationEvaluationOutputComponents
= 128,
767 .maxGeometryShaderInvocations
= 32,
768 .maxGeometryInputComponents
= 64,
769 .maxGeometryOutputComponents
= 128,
770 .maxGeometryOutputVertices
= 256,
771 .maxGeometryTotalOutputComponents
= 1024,
772 .maxFragmentInputComponents
= 128,
773 .maxFragmentOutputAttachments
= 8,
774 .maxFragmentDualSrcAttachments
= 1,
775 .maxFragmentCombinedOutputResources
= 8,
776 .maxComputeSharedMemorySize
= 32768,
777 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
778 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
779 .maxComputeWorkGroupSize
= {
780 16 * devinfo
->max_cs_threads
,
781 16 * devinfo
->max_cs_threads
,
782 16 * devinfo
->max_cs_threads
,
784 .subPixelPrecisionBits
= 4 /* FIXME */,
785 .subTexelPrecisionBits
= 4 /* FIXME */,
786 .mipmapPrecisionBits
= 4 /* FIXME */,
787 .maxDrawIndexedIndexValue
= UINT32_MAX
,
788 .maxDrawIndirectCount
= UINT32_MAX
,
789 .maxSamplerLodBias
= 16,
790 .maxSamplerAnisotropy
= 16,
791 .maxViewports
= MAX_VIEWPORTS
,
792 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
793 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
794 .viewportSubPixelBits
= 13, /* We take a float? */
795 .minMemoryMapAlignment
= 4096, /* A page */
796 .minTexelBufferOffsetAlignment
= 1,
797 .minUniformBufferOffsetAlignment
= 16,
798 .minStorageBufferOffsetAlignment
= 4,
799 .minTexelOffset
= -8,
801 .minTexelGatherOffset
= -32,
802 .maxTexelGatherOffset
= 31,
803 .minInterpolationOffset
= -0.5,
804 .maxInterpolationOffset
= 0.4375,
805 .subPixelInterpolationOffsetBits
= 4,
806 .maxFramebufferWidth
= (1 << 14),
807 .maxFramebufferHeight
= (1 << 14),
808 .maxFramebufferLayers
= (1 << 11),
809 .framebufferColorSampleCounts
= sample_counts
,
810 .framebufferDepthSampleCounts
= sample_counts
,
811 .framebufferStencilSampleCounts
= sample_counts
,
812 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
813 .maxColorAttachments
= MAX_RTS
,
814 .sampledImageColorSampleCounts
= sample_counts
,
815 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
816 .sampledImageDepthSampleCounts
= sample_counts
,
817 .sampledImageStencilSampleCounts
= sample_counts
,
818 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
819 .maxSampleMaskWords
= 1,
820 .timestampComputeAndGraphics
= false,
821 .timestampPeriod
= devinfo
->timebase_scale
,
822 .maxClipDistances
= 8,
823 .maxCullDistances
= 8,
824 .maxCombinedClipAndCullDistances
= 8,
825 .discreteQueuePriorities
= 1,
826 .pointSizeRange
= { 0.125, 255.875 },
827 .lineWidthRange
= { 0.0, 7.9921875 },
828 .pointSizeGranularity
= (1.0 / 8.0),
829 .lineWidthGranularity
= (1.0 / 128.0),
830 .strictLines
= false, /* FINISHME */
831 .standardSampleLocations
= true,
832 .optimalBufferCopyOffsetAlignment
= 128,
833 .optimalBufferCopyRowPitchAlignment
= 128,
834 .nonCoherentAtomSize
= 64,
837 *pProperties
= (VkPhysicalDeviceProperties
) {
838 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
841 .deviceID
= pdevice
->chipset_id
,
842 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
844 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
847 strcpy(pProperties
->deviceName
, pdevice
->name
);
848 memcpy(pProperties
->pipelineCacheUUID
,
849 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
852 void anv_GetPhysicalDeviceProperties2KHR(
853 VkPhysicalDevice physicalDevice
,
854 VkPhysicalDeviceProperties2KHR
* pProperties
)
856 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
858 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
860 vk_foreach_struct(ext
, pProperties
->pNext
) {
861 switch (ext
->sType
) {
862 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
863 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
864 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
866 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
870 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHX
: {
871 VkPhysicalDeviceIDPropertiesKHX
*id_props
=
872 (VkPhysicalDeviceIDPropertiesKHX
*)ext
;
873 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
874 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
875 /* The LUID is for Windows. */
876 id_props
->deviceLUIDValid
= false;
880 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
881 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
=
882 (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
883 properties
->maxMultiviewViewCount
= 16;
884 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
889 anv_debug_ignored_stype(ext
->sType
);
895 /* We support exactly one queue family. */
896 static const VkQueueFamilyProperties
897 anv_queue_family_properties
= {
898 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
899 VK_QUEUE_COMPUTE_BIT
|
900 VK_QUEUE_TRANSFER_BIT
,
902 .timestampValidBits
= 36, /* XXX: Real value here */
903 .minImageTransferGranularity
= { 1, 1, 1 },
906 void anv_GetPhysicalDeviceQueueFamilyProperties(
907 VkPhysicalDevice physicalDevice
,
909 VkQueueFamilyProperties
* pQueueFamilyProperties
)
911 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
913 vk_outarray_append(&out
, p
) {
914 *p
= anv_queue_family_properties
;
918 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
919 VkPhysicalDevice physicalDevice
,
920 uint32_t* pQueueFamilyPropertyCount
,
921 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
924 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
926 vk_outarray_append(&out
, p
) {
927 p
->queueFamilyProperties
= anv_queue_family_properties
;
929 vk_foreach_struct(s
, p
->pNext
) {
930 anv_debug_ignored_stype(s
->sType
);
935 void anv_GetPhysicalDeviceMemoryProperties(
936 VkPhysicalDevice physicalDevice
,
937 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
939 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
941 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
942 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
943 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
944 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
945 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
949 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
950 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
951 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
952 .size
= physical_device
->memory
.heaps
[i
].size
,
953 .flags
= physical_device
->memory
.heaps
[i
].flags
,
958 void anv_GetPhysicalDeviceMemoryProperties2KHR(
959 VkPhysicalDevice physicalDevice
,
960 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
962 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
963 &pMemoryProperties
->memoryProperties
);
965 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
966 switch (ext
->sType
) {
968 anv_debug_ignored_stype(ext
->sType
);
974 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
978 return anv_lookup_entrypoint(NULL
, pName
);
981 /* With version 1+ of the loader interface the ICD should expose
982 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
985 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
990 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
994 return anv_GetInstanceProcAddr(instance
, pName
);
997 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1001 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1002 return anv_lookup_entrypoint(&device
->info
, pName
);
1006 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1008 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1009 queue
->device
= device
;
1010 queue
->pool
= &device
->surface_state_pool
;
1014 anv_queue_finish(struct anv_queue
*queue
)
1018 static struct anv_state
1019 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1021 struct anv_state state
;
1023 state
= anv_state_pool_alloc(pool
, size
, align
);
1024 memcpy(state
.map
, p
, size
);
1026 anv_state_flush(pool
->block_pool
.device
, state
);
1031 struct gen8_border_color
{
1036 /* Pad out to 64 bytes */
1041 anv_device_init_border_colors(struct anv_device
*device
)
1043 static const struct gen8_border_color border_colors
[] = {
1044 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1045 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1046 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1047 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1048 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1049 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1052 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1053 sizeof(border_colors
), 64,
1057 VkResult
anv_CreateDevice(
1058 VkPhysicalDevice physicalDevice
,
1059 const VkDeviceCreateInfo
* pCreateInfo
,
1060 const VkAllocationCallbacks
* pAllocator
,
1063 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1065 struct anv_device
*device
;
1067 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1069 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1071 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
1072 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1073 device_extensions
[j
].extensionName
) == 0) {
1079 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1082 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1084 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1086 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1088 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1089 device
->instance
= physical_device
->instance
;
1090 device
->chipset_id
= physical_device
->chipset_id
;
1091 device
->lost
= false;
1094 device
->alloc
= *pAllocator
;
1096 device
->alloc
= physical_device
->instance
->alloc
;
1098 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1099 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1100 if (device
->fd
== -1) {
1101 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1105 device
->context_id
= anv_gem_create_context(device
);
1106 if (device
->context_id
== -1) {
1107 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1111 device
->info
= physical_device
->info
;
1112 device
->isl_dev
= physical_device
->isl_dev
;
1114 /* On Broadwell and later, we can use batch chaining to more efficiently
1115 * implement growing command buffers. Prior to Haswell, the kernel
1116 * command parser gets in the way and we have to fall back to growing
1119 device
->can_chain_batches
= device
->info
.gen
>= 8;
1121 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1122 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1124 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1125 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1126 goto fail_context_id
;
1129 pthread_condattr_t condattr
;
1130 if (pthread_condattr_init(&condattr
) != 0) {
1131 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1134 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1135 pthread_condattr_destroy(&condattr
);
1136 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1139 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1140 pthread_condattr_destroy(&condattr
);
1141 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1144 pthread_condattr_destroy(&condattr
);
1146 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1148 result
= anv_bo_cache_init(&device
->bo_cache
);
1149 if (result
!= VK_SUCCESS
)
1150 goto fail_batch_bo_pool
;
1152 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384);
1153 if (result
!= VK_SUCCESS
)
1156 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384);
1157 if (result
!= VK_SUCCESS
)
1158 goto fail_dynamic_state_pool
;
1160 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096);
1161 if (result
!= VK_SUCCESS
)
1162 goto fail_instruction_state_pool
;
1164 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1165 if (result
!= VK_SUCCESS
)
1166 goto fail_surface_state_pool
;
1168 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1170 anv_queue_init(device
, &device
->queue
);
1172 switch (device
->info
.gen
) {
1174 if (!device
->info
.is_haswell
)
1175 result
= gen7_init_device_state(device
);
1177 result
= gen75_init_device_state(device
);
1180 result
= gen8_init_device_state(device
);
1183 result
= gen9_init_device_state(device
);
1186 /* Shouldn't get here as we don't create physical devices for any other
1188 unreachable("unhandled gen");
1190 if (result
!= VK_SUCCESS
)
1191 goto fail_workaround_bo
;
1193 anv_device_init_blorp(device
);
1195 anv_device_init_border_colors(device
);
1197 *pDevice
= anv_device_to_handle(device
);
1202 anv_queue_finish(&device
->queue
);
1203 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1204 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1205 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1206 fail_surface_state_pool
:
1207 anv_state_pool_finish(&device
->surface_state_pool
);
1208 fail_instruction_state_pool
:
1209 anv_state_pool_finish(&device
->instruction_state_pool
);
1210 fail_dynamic_state_pool
:
1211 anv_state_pool_finish(&device
->dynamic_state_pool
);
1213 anv_bo_cache_finish(&device
->bo_cache
);
1215 anv_bo_pool_finish(&device
->batch_bo_pool
);
1216 pthread_cond_destroy(&device
->queue_submit
);
1218 pthread_mutex_destroy(&device
->mutex
);
1220 anv_gem_destroy_context(device
, device
->context_id
);
1224 vk_free(&device
->alloc
, device
);
1229 void anv_DestroyDevice(
1231 const VkAllocationCallbacks
* pAllocator
)
1233 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1238 anv_device_finish_blorp(device
);
1240 anv_queue_finish(&device
->queue
);
1242 #ifdef HAVE_VALGRIND
1243 /* We only need to free these to prevent valgrind errors. The backing
1244 * BO will go away in a couple of lines so we don't actually leak.
1246 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1249 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1251 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1252 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1254 anv_state_pool_finish(&device
->surface_state_pool
);
1255 anv_state_pool_finish(&device
->instruction_state_pool
);
1256 anv_state_pool_finish(&device
->dynamic_state_pool
);
1258 anv_bo_cache_finish(&device
->bo_cache
);
1260 anv_bo_pool_finish(&device
->batch_bo_pool
);
1262 pthread_cond_destroy(&device
->queue_submit
);
1263 pthread_mutex_destroy(&device
->mutex
);
1265 anv_gem_destroy_context(device
, device
->context_id
);
1269 vk_free(&device
->alloc
, device
);
1272 VkResult
anv_EnumerateInstanceExtensionProperties(
1273 const char* pLayerName
,
1274 uint32_t* pPropertyCount
,
1275 VkExtensionProperties
* pProperties
)
1277 if (pProperties
== NULL
) {
1278 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
1282 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(global_extensions
));
1283 typed_memcpy(pProperties
, global_extensions
, *pPropertyCount
);
1285 if (*pPropertyCount
< ARRAY_SIZE(global_extensions
))
1286 return VK_INCOMPLETE
;
1291 VkResult
anv_EnumerateDeviceExtensionProperties(
1292 VkPhysicalDevice physicalDevice
,
1293 const char* pLayerName
,
1294 uint32_t* pPropertyCount
,
1295 VkExtensionProperties
* pProperties
)
1297 if (pProperties
== NULL
) {
1298 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
1302 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(device_extensions
));
1303 typed_memcpy(pProperties
, device_extensions
, *pPropertyCount
);
1305 if (*pPropertyCount
< ARRAY_SIZE(device_extensions
))
1306 return VK_INCOMPLETE
;
1311 VkResult
anv_EnumerateInstanceLayerProperties(
1312 uint32_t* pPropertyCount
,
1313 VkLayerProperties
* pProperties
)
1315 if (pProperties
== NULL
) {
1316 *pPropertyCount
= 0;
1320 /* None supported at this time */
1321 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1324 VkResult
anv_EnumerateDeviceLayerProperties(
1325 VkPhysicalDevice physicalDevice
,
1326 uint32_t* pPropertyCount
,
1327 VkLayerProperties
* pProperties
)
1329 if (pProperties
== NULL
) {
1330 *pPropertyCount
= 0;
1334 /* None supported at this time */
1335 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1338 void anv_GetDeviceQueue(
1340 uint32_t queueNodeIndex
,
1341 uint32_t queueIndex
,
1344 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1346 assert(queueIndex
== 0);
1348 *pQueue
= anv_queue_to_handle(&device
->queue
);
1352 anv_device_query_status(struct anv_device
*device
)
1354 /* This isn't likely as most of the callers of this function already check
1355 * for it. However, it doesn't hurt to check and it potentially lets us
1358 if (unlikely(device
->lost
))
1359 return VK_ERROR_DEVICE_LOST
;
1361 uint32_t active
, pending
;
1362 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1364 /* We don't know the real error. */
1365 device
->lost
= true;
1366 return vk_errorf(VK_ERROR_DEVICE_LOST
, "get_reset_stats failed: %m");
1370 device
->lost
= true;
1371 return vk_errorf(VK_ERROR_DEVICE_LOST
,
1372 "GPU hung on one of our command buffers");
1373 } else if (pending
) {
1374 device
->lost
= true;
1375 return vk_errorf(VK_ERROR_DEVICE_LOST
,
1376 "GPU hung with commands in-flight");
1383 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1385 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1386 * Other usages of the BO (such as on different hardware) will not be
1387 * flagged as "busy" by this ioctl. Use with care.
1389 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1391 return VK_NOT_READY
;
1392 } else if (ret
== -1) {
1393 /* We don't know the real error. */
1394 device
->lost
= true;
1395 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1398 /* Query for device status after the busy call. If the BO we're checking
1399 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1400 * client because it clearly doesn't have valid data. Yes, this most
1401 * likely means an ioctl, but we just did an ioctl to query the busy status
1402 * so it's no great loss.
1404 return anv_device_query_status(device
);
1408 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1411 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1412 if (ret
== -1 && errno
== ETIME
) {
1414 } else if (ret
== -1) {
1415 /* We don't know the real error. */
1416 device
->lost
= true;
1417 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1420 /* Query for device status after the wait. If the BO we're waiting on got
1421 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1422 * because it clearly doesn't have valid data. Yes, this most likely means
1423 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1425 return anv_device_query_status(device
);
1428 VkResult
anv_DeviceWaitIdle(
1431 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1432 if (unlikely(device
->lost
))
1433 return VK_ERROR_DEVICE_LOST
;
1435 struct anv_batch batch
;
1438 batch
.start
= batch
.next
= cmds
;
1439 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1441 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1442 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1444 return anv_device_submit_simple_batch(device
, &batch
);
1448 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1450 uint32_t gem_handle
= anv_gem_create(device
, size
);
1452 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1454 anv_bo_init(bo
, gem_handle
, size
);
1456 if (device
->instance
->physicalDevice
.supports_48bit_addresses
)
1457 bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1459 if (device
->instance
->physicalDevice
.has_exec_async
)
1460 bo
->flags
|= EXEC_OBJECT_ASYNC
;
1465 VkResult
anv_AllocateMemory(
1467 const VkMemoryAllocateInfo
* pAllocateInfo
,
1468 const VkAllocationCallbacks
* pAllocator
,
1469 VkDeviceMemory
* pMem
)
1471 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1472 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1473 struct anv_device_memory
*mem
;
1474 VkResult result
= VK_SUCCESS
;
1476 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1478 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1479 assert(pAllocateInfo
->allocationSize
> 0);
1481 /* The kernel relocation API has a limitation of a 32-bit delta value
1482 * applied to the address before it is written which, in spite of it being
1483 * unsigned, is treated as signed . Because of the way that this maps to
1484 * the Vulkan API, we cannot handle an offset into a buffer that does not
1485 * fit into a signed 32 bits. The only mechanism we have for dealing with
1486 * this at the moment is to limit all VkDeviceMemory objects to a maximum
1487 * of 2GB each. The Vulkan spec allows us to do this:
1489 * "Some platforms may have a limit on the maximum size of a single
1490 * allocation. For example, certain systems may fail to create
1491 * allocations with a size greater than or equal to 4GB. Such a limit is
1492 * implementation-dependent, and if such a failure occurs then the error
1493 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
1495 * We don't use vk_error here because it's not an error so much as an
1496 * indication to the application that the allocation is too large.
1498 if (pAllocateInfo
->allocationSize
> (1ull << 31))
1499 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1501 /* FINISHME: Fail if allocation request exceeds heap size. */
1503 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1504 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1506 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1508 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1509 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1513 const VkImportMemoryFdInfoKHX
*fd_info
=
1514 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHX
);
1516 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1519 if (fd_info
&& fd_info
->handleType
) {
1520 /* At the moment, we only support the OPAQUE_FD memory type which is
1521 * just a GEM buffer.
1523 assert(fd_info
->handleType
==
1524 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX
);
1526 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1527 fd_info
->fd
, pAllocateInfo
->allocationSize
,
1529 if (result
!= VK_SUCCESS
)
1532 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1533 pAllocateInfo
->allocationSize
,
1535 if (result
!= VK_SUCCESS
)
1539 *pMem
= anv_device_memory_to_handle(mem
);
1544 vk_free2(&device
->alloc
, pAllocator
, mem
);
1549 VkResult
anv_GetMemoryFdKHX(
1551 VkDeviceMemory memory_h
,
1552 VkExternalMemoryHandleTypeFlagBitsKHX handleType
,
1555 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
1556 ANV_FROM_HANDLE(anv_device_memory
, mem
, memory_h
);
1558 /* We support only one handle type. */
1559 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX
);
1561 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
1564 VkResult
anv_GetMemoryFdPropertiesKHX(
1566 VkExternalMemoryHandleTypeFlagBitsKHX handleType
,
1568 VkMemoryFdPropertiesKHX
* pMemoryFdProperties
)
1570 /* The valid usage section for this function says:
1572 * "handleType must not be one of the handle types defined as opaque."
1574 * Since we only handle opaque handles for now, there are no FD properties.
1576 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX
;
1579 void anv_FreeMemory(
1581 VkDeviceMemory _mem
,
1582 const VkAllocationCallbacks
* pAllocator
)
1584 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1585 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1591 anv_UnmapMemory(_device
, _mem
);
1593 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1595 vk_free2(&device
->alloc
, pAllocator
, mem
);
1598 VkResult
anv_MapMemory(
1600 VkDeviceMemory _memory
,
1601 VkDeviceSize offset
,
1603 VkMemoryMapFlags flags
,
1606 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1607 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1614 if (size
== VK_WHOLE_SIZE
)
1615 size
= mem
->bo
->size
- offset
;
1617 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1619 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1620 * assert(size != 0);
1621 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1622 * equal to the size of the memory minus offset
1625 assert(offset
+ size
<= mem
->bo
->size
);
1627 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1628 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1629 * at a time is valid. We could just mmap up front and return an offset
1630 * pointer here, but that may exhaust virtual memory on 32 bit
1633 uint32_t gem_flags
= 0;
1635 if (!device
->info
.has_llc
&&
1636 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
1637 gem_flags
|= I915_MMAP_WC
;
1639 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1640 uint64_t map_offset
= offset
& ~4095ull;
1641 assert(offset
>= map_offset
);
1642 uint64_t map_size
= (offset
+ size
) - map_offset
;
1644 /* Let's map whole pages */
1645 map_size
= align_u64(map_size
, 4096);
1647 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
1648 map_offset
, map_size
, gem_flags
);
1649 if (map
== MAP_FAILED
)
1650 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1653 mem
->map_size
= map_size
;
1655 *ppData
= mem
->map
+ (offset
- map_offset
);
1660 void anv_UnmapMemory(
1662 VkDeviceMemory _memory
)
1664 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1669 anv_gem_munmap(mem
->map
, mem
->map_size
);
1676 clflush_mapped_ranges(struct anv_device
*device
,
1678 const VkMappedMemoryRange
*ranges
)
1680 for (uint32_t i
= 0; i
< count
; i
++) {
1681 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1682 if (ranges
[i
].offset
>= mem
->map_size
)
1685 anv_clflush_range(mem
->map
+ ranges
[i
].offset
,
1686 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1690 VkResult
anv_FlushMappedMemoryRanges(
1692 uint32_t memoryRangeCount
,
1693 const VkMappedMemoryRange
* pMemoryRanges
)
1695 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1697 if (device
->info
.has_llc
)
1700 /* Make sure the writes we're flushing have landed. */
1701 __builtin_ia32_mfence();
1703 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1708 VkResult
anv_InvalidateMappedMemoryRanges(
1710 uint32_t memoryRangeCount
,
1711 const VkMappedMemoryRange
* pMemoryRanges
)
1713 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1715 if (device
->info
.has_llc
)
1718 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1720 /* Make sure no reads get moved up above the invalidate. */
1721 __builtin_ia32_mfence();
1726 void anv_GetBufferMemoryRequirements(
1729 VkMemoryRequirements
* pMemoryRequirements
)
1731 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1732 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1733 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1735 /* The Vulkan spec (git aaed022) says:
1737 * memoryTypeBits is a bitfield and contains one bit set for every
1738 * supported memory type for the resource. The bit `1<<i` is set if and
1739 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1740 * structure for the physical device is supported.
1742 uint32_t memory_types
= 0;
1743 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
1744 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
1745 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
1746 memory_types
|= (1u << i
);
1749 pMemoryRequirements
->size
= buffer
->size
;
1750 pMemoryRequirements
->alignment
= 16;
1751 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1754 void anv_GetImageMemoryRequirements(
1757 VkMemoryRequirements
* pMemoryRequirements
)
1759 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1760 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1761 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1763 /* The Vulkan spec (git aaed022) says:
1765 * memoryTypeBits is a bitfield and contains one bit set for every
1766 * supported memory type for the resource. The bit `1<<i` is set if and
1767 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1768 * structure for the physical device is supported.
1770 * All types are currently supported for images.
1772 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
1774 pMemoryRequirements
->size
= image
->size
;
1775 pMemoryRequirements
->alignment
= image
->alignment
;
1776 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1779 void anv_GetImageSparseMemoryRequirements(
1782 uint32_t* pSparseMemoryRequirementCount
,
1783 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1785 *pSparseMemoryRequirementCount
= 0;
1788 void anv_GetDeviceMemoryCommitment(
1790 VkDeviceMemory memory
,
1791 VkDeviceSize
* pCommittedMemoryInBytes
)
1793 *pCommittedMemoryInBytes
= 0;
1796 VkResult
anv_BindBufferMemory(
1799 VkDeviceMemory _memory
,
1800 VkDeviceSize memoryOffset
)
1802 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1803 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1806 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
1807 buffer
->bo
= mem
->bo
;
1808 buffer
->offset
= memoryOffset
;
1817 VkResult
anv_QueueBindSparse(
1819 uint32_t bindInfoCount
,
1820 const VkBindSparseInfo
* pBindInfo
,
1823 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1824 if (unlikely(queue
->device
->lost
))
1825 return VK_ERROR_DEVICE_LOST
;
1827 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1832 VkResult
anv_CreateEvent(
1834 const VkEventCreateInfo
* pCreateInfo
,
1835 const VkAllocationCallbacks
* pAllocator
,
1838 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1839 struct anv_state state
;
1840 struct anv_event
*event
;
1842 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1844 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1847 event
->state
= state
;
1848 event
->semaphore
= VK_EVENT_RESET
;
1850 if (!device
->info
.has_llc
) {
1851 /* Make sure the writes we're flushing have landed. */
1852 __builtin_ia32_mfence();
1853 __builtin_ia32_clflush(event
);
1856 *pEvent
= anv_event_to_handle(event
);
1861 void anv_DestroyEvent(
1864 const VkAllocationCallbacks
* pAllocator
)
1866 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1867 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1872 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1875 VkResult
anv_GetEventStatus(
1879 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1880 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1882 if (unlikely(device
->lost
))
1883 return VK_ERROR_DEVICE_LOST
;
1885 if (!device
->info
.has_llc
) {
1886 /* Invalidate read cache before reading event written by GPU. */
1887 __builtin_ia32_clflush(event
);
1888 __builtin_ia32_mfence();
1892 return event
->semaphore
;
1895 VkResult
anv_SetEvent(
1899 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1900 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1902 event
->semaphore
= VK_EVENT_SET
;
1904 if (!device
->info
.has_llc
) {
1905 /* Make sure the writes we're flushing have landed. */
1906 __builtin_ia32_mfence();
1907 __builtin_ia32_clflush(event
);
1913 VkResult
anv_ResetEvent(
1917 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1918 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1920 event
->semaphore
= VK_EVENT_RESET
;
1922 if (!device
->info
.has_llc
) {
1923 /* Make sure the writes we're flushing have landed. */
1924 __builtin_ia32_mfence();
1925 __builtin_ia32_clflush(event
);
1933 VkResult
anv_CreateBuffer(
1935 const VkBufferCreateInfo
* pCreateInfo
,
1936 const VkAllocationCallbacks
* pAllocator
,
1939 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1940 struct anv_buffer
*buffer
;
1942 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1944 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1945 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1947 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1949 buffer
->size
= pCreateInfo
->size
;
1950 buffer
->usage
= pCreateInfo
->usage
;
1954 *pBuffer
= anv_buffer_to_handle(buffer
);
1959 void anv_DestroyBuffer(
1962 const VkAllocationCallbacks
* pAllocator
)
1964 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1965 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1970 vk_free2(&device
->alloc
, pAllocator
, buffer
);
1974 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
1975 enum isl_format format
,
1976 uint32_t offset
, uint32_t range
, uint32_t stride
)
1978 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
1980 .mocs
= device
->default_mocs
,
1985 anv_state_flush(device
, state
);
1988 void anv_DestroySampler(
1991 const VkAllocationCallbacks
* pAllocator
)
1993 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1994 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
1999 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2002 VkResult
anv_CreateFramebuffer(
2004 const VkFramebufferCreateInfo
* pCreateInfo
,
2005 const VkAllocationCallbacks
* pAllocator
,
2006 VkFramebuffer
* pFramebuffer
)
2008 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2009 struct anv_framebuffer
*framebuffer
;
2011 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2013 size_t size
= sizeof(*framebuffer
) +
2014 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2015 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2016 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2017 if (framebuffer
== NULL
)
2018 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2020 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2021 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2022 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2023 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2026 framebuffer
->width
= pCreateInfo
->width
;
2027 framebuffer
->height
= pCreateInfo
->height
;
2028 framebuffer
->layers
= pCreateInfo
->layers
;
2030 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2035 void anv_DestroyFramebuffer(
2038 const VkAllocationCallbacks
* pAllocator
)
2040 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2041 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2046 vk_free2(&device
->alloc
, pAllocator
, fb
);
2049 /* vk_icd.h does not declare this function, so we declare it here to
2050 * suppress Wmissing-prototypes.
2052 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2053 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2055 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2056 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2058 /* For the full details on loader interface versioning, see
2059 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2060 * What follows is a condensed summary, to help you navigate the large and
2061 * confusing official doc.
2063 * - Loader interface v0 is incompatible with later versions. We don't
2066 * - In loader interface v1:
2067 * - The first ICD entrypoint called by the loader is
2068 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2070 * - The ICD must statically expose no other Vulkan symbol unless it is
2071 * linked with -Bsymbolic.
2072 * - Each dispatchable Vulkan handle created by the ICD must be
2073 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2074 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2075 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2076 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2077 * such loader-managed surfaces.
2079 * - Loader interface v2 differs from v1 in:
2080 * - The first ICD entrypoint called by the loader is
2081 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2082 * statically expose this entrypoint.
2084 * - Loader interface v3 differs from v2 in:
2085 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2086 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2087 * because the loader no longer does so.
2089 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);