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] = (struct anv_memory_heap
) {
154 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
155 .supports_48bit_addresses
= device
->supports_48bit_addresses
,
162 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
164 const struct build_id_note
*note
= build_id_find_nhdr("libvulkan_intel.so");
166 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
167 "Failed to find build-id");
170 unsigned build_id_len
= build_id_length(note
);
171 if (build_id_len
< 20) {
172 return vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
173 "build-id too short. It needs to be a SHA");
176 struct mesa_sha1 sha1_ctx
;
178 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
180 /* The pipeline cache UUID is used for determining when a pipeline cache is
181 * invalid. It needs both a driver build and the PCI ID of the device.
183 _mesa_sha1_init(&sha1_ctx
);
184 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
185 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
186 sizeof(device
->chipset_id
));
187 _mesa_sha1_final(&sha1_ctx
, sha1
);
188 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
190 /* The driver UUID is used for determining sharability of images and memory
191 * between two Vulkan instances in separate processes. People who want to
192 * share memory need to also check the device UUID (below) so all this
193 * needs to be is the build-id.
195 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
197 /* The device UUID uniquely identifies the given device within the machine.
198 * Since we never have more than one device, this doesn't need to be a real
199 * UUID. However, on the off-chance that someone tries to use this to
200 * cache pre-tiled images or something of the like, we use the PCI ID and
201 * some bits of ISL info to ensure that this is safe.
203 _mesa_sha1_init(&sha1_ctx
);
204 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
205 sizeof(device
->chipset_id
));
206 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
207 sizeof(device
->isl_dev
.has_bit6_swizzling
));
208 _mesa_sha1_final(&sha1_ctx
, sha1
);
209 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
215 anv_physical_device_init(struct anv_physical_device
*device
,
216 struct anv_instance
*instance
,
222 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
224 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
226 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
227 device
->instance
= instance
;
229 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
230 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
232 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
233 if (!device
->chipset_id
) {
234 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
238 device
->name
= gen_get_device_name(device
->chipset_id
);
239 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
240 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
244 if (device
->info
.is_haswell
) {
245 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
246 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
247 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
248 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
249 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
250 } else if (device
->info
.gen
>= 8) {
251 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
252 * supported as anything */
254 result
= vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
255 "Vulkan not yet supported on %s", device
->name
);
259 device
->cmd_parser_version
= -1;
260 if (device
->info
.gen
== 7) {
261 device
->cmd_parser_version
=
262 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
263 if (device
->cmd_parser_version
== -1) {
264 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
265 "failed to get command parser version");
270 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
271 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
272 "kernel missing gem wait");
276 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
277 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
278 "kernel missing execbuf2");
282 if (!device
->info
.has_llc
&&
283 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
284 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
285 "kernel missing wc mmap");
289 result
= anv_physical_device_init_heaps(device
, fd
);
290 if (result
!= VK_SUCCESS
)
293 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
295 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
297 /* GENs prior to 8 do not support EU/Subslice info */
298 if (device
->info
.gen
>= 8) {
299 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
300 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
302 /* Without this information, we cannot get the right Braswell
303 * brandstrings, and we have to use conservative numbers for GPGPU on
304 * many platforms, but otherwise, things will just work.
306 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
307 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
308 " query GPU properties.\n");
310 } else if (device
->info
.gen
== 7) {
311 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
314 if (device
->info
.is_cherryview
&&
315 device
->subslice_total
> 0 && device
->eu_total
> 0) {
316 /* Logical CS threads = EUs per subslice * 7 threads per EU */
317 uint32_t max_cs_threads
= device
->eu_total
/ device
->subslice_total
* 7;
319 /* Fuse configurations may give more threads than expected, never less. */
320 if (max_cs_threads
> device
->info
.max_cs_threads
)
321 device
->info
.max_cs_threads
= max_cs_threads
;
324 brw_process_intel_debug_variable();
326 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
327 if (device
->compiler
== NULL
) {
328 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
331 device
->compiler
->shader_debug_log
= compiler_debug_log
;
332 device
->compiler
->shader_perf_log
= compiler_perf_log
;
334 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
336 result
= anv_physical_device_init_uuids(device
);
337 if (result
!= VK_SUCCESS
)
340 result
= anv_init_wsi(device
);
341 if (result
!= VK_SUCCESS
) {
342 ralloc_free(device
->compiler
);
346 device
->local_fd
= fd
;
355 anv_physical_device_finish(struct anv_physical_device
*device
)
357 anv_finish_wsi(device
);
358 ralloc_free(device
->compiler
);
359 close(device
->local_fd
);
362 static const VkExtensionProperties global_extensions
[] = {
364 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
368 .extensionName
= VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME
,
372 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
375 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
377 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
381 #ifdef VK_USE_PLATFORM_XCB_KHR
383 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
387 #ifdef VK_USE_PLATFORM_XLIB_KHR
389 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
394 .extensionName
= VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
,
398 .extensionName
= VK_KHX_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME
,
403 static const VkExtensionProperties device_extensions
[] = {
405 .extensionName
= VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME
,
409 .extensionName
= VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME
,
413 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
417 .extensionName
= VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
,
421 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
425 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
429 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
433 .extensionName
= VK_KHX_EXTERNAL_MEMORY_EXTENSION_NAME
,
437 .extensionName
= VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME
,
441 .extensionName
= VK_KHX_EXTERNAL_SEMAPHORE_EXTENSION_NAME
,
445 .extensionName
= VK_KHX_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME
,
449 .extensionName
= VK_KHX_MULTIVIEW_EXTENSION_NAME
,
455 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
456 VkSystemAllocationScope allocationScope
)
462 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
463 size_t align
, VkSystemAllocationScope allocationScope
)
465 return realloc(pOriginal
, size
);
469 default_free_func(void *pUserData
, void *pMemory
)
474 static const VkAllocationCallbacks default_alloc
= {
476 .pfnAllocation
= default_alloc_func
,
477 .pfnReallocation
= default_realloc_func
,
478 .pfnFree
= default_free_func
,
481 VkResult
anv_CreateInstance(
482 const VkInstanceCreateInfo
* pCreateInfo
,
483 const VkAllocationCallbacks
* pAllocator
,
484 VkInstance
* pInstance
)
486 struct anv_instance
*instance
;
488 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
490 uint32_t client_version
;
491 if (pCreateInfo
->pApplicationInfo
&&
492 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
493 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
495 client_version
= VK_MAKE_VERSION(1, 0, 0);
498 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
499 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
500 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
501 "Client requested version %d.%d.%d",
502 VK_VERSION_MAJOR(client_version
),
503 VK_VERSION_MINOR(client_version
),
504 VK_VERSION_PATCH(client_version
));
507 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
509 for (uint32_t j
= 0; j
< ARRAY_SIZE(global_extensions
); j
++) {
510 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
511 global_extensions
[j
].extensionName
) == 0) {
517 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
520 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
521 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
523 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
525 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
528 instance
->alloc
= *pAllocator
;
530 instance
->alloc
= default_alloc
;
532 instance
->apiVersion
= client_version
;
533 instance
->physicalDeviceCount
= -1;
537 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
539 *pInstance
= anv_instance_to_handle(instance
);
544 void anv_DestroyInstance(
545 VkInstance _instance
,
546 const VkAllocationCallbacks
* pAllocator
)
548 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
553 if (instance
->physicalDeviceCount
> 0) {
554 /* We support at most one physical device. */
555 assert(instance
->physicalDeviceCount
== 1);
556 anv_physical_device_finish(&instance
->physicalDevice
);
559 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
563 vk_free(&instance
->alloc
, instance
);
567 anv_enumerate_devices(struct anv_instance
*instance
)
569 /* TODO: Check for more devices ? */
570 drmDevicePtr devices
[8];
571 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
574 instance
->physicalDeviceCount
= 0;
576 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
578 return VK_ERROR_INCOMPATIBLE_DRIVER
;
580 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
581 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
582 devices
[i
]->bustype
== DRM_BUS_PCI
&&
583 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
585 result
= anv_physical_device_init(&instance
->physicalDevice
,
587 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
588 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
592 drmFreeDevices(devices
, max_devices
);
594 if (result
== VK_SUCCESS
)
595 instance
->physicalDeviceCount
= 1;
601 VkResult
anv_EnumeratePhysicalDevices(
602 VkInstance _instance
,
603 uint32_t* pPhysicalDeviceCount
,
604 VkPhysicalDevice
* pPhysicalDevices
)
606 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
607 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
610 if (instance
->physicalDeviceCount
< 0) {
611 result
= anv_enumerate_devices(instance
);
612 if (result
!= VK_SUCCESS
&&
613 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
617 if (instance
->physicalDeviceCount
> 0) {
618 assert(instance
->physicalDeviceCount
== 1);
619 vk_outarray_append(&out
, i
) {
620 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
624 return vk_outarray_status(&out
);
627 void anv_GetPhysicalDeviceFeatures(
628 VkPhysicalDevice physicalDevice
,
629 VkPhysicalDeviceFeatures
* pFeatures
)
631 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
633 *pFeatures
= (VkPhysicalDeviceFeatures
) {
634 .robustBufferAccess
= true,
635 .fullDrawIndexUint32
= true,
636 .imageCubeArray
= true,
637 .independentBlend
= true,
638 .geometryShader
= true,
639 .tessellationShader
= true,
640 .sampleRateShading
= true,
641 .dualSrcBlend
= true,
643 .multiDrawIndirect
= true,
644 .drawIndirectFirstInstance
= true,
646 .depthBiasClamp
= true,
647 .fillModeNonSolid
= true,
648 .depthBounds
= false,
652 .multiViewport
= true,
653 .samplerAnisotropy
= true,
654 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
655 pdevice
->info
.is_baytrail
,
656 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
657 .textureCompressionBC
= true,
658 .occlusionQueryPrecise
= true,
659 .pipelineStatisticsQuery
= true,
660 .fragmentStoresAndAtomics
= true,
661 .shaderTessellationAndGeometryPointSize
= true,
662 .shaderImageGatherExtended
= true,
663 .shaderStorageImageExtendedFormats
= true,
664 .shaderStorageImageMultisample
= false,
665 .shaderStorageImageReadWithoutFormat
= false,
666 .shaderStorageImageWriteWithoutFormat
= true,
667 .shaderUniformBufferArrayDynamicIndexing
= true,
668 .shaderSampledImageArrayDynamicIndexing
= true,
669 .shaderStorageBufferArrayDynamicIndexing
= true,
670 .shaderStorageImageArrayDynamicIndexing
= true,
671 .shaderClipDistance
= true,
672 .shaderCullDistance
= true,
673 .shaderFloat64
= pdevice
->info
.gen
>= 8,
674 .shaderInt64
= pdevice
->info
.gen
>= 8,
675 .shaderInt16
= false,
676 .shaderResourceMinLod
= false,
677 .variableMultisampleRate
= false,
678 .inheritedQueries
= true,
681 /* We can't do image stores in vec4 shaders */
682 pFeatures
->vertexPipelineStoresAndAtomics
=
683 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
684 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
687 void anv_GetPhysicalDeviceFeatures2KHR(
688 VkPhysicalDevice physicalDevice
,
689 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
691 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
693 vk_foreach_struct(ext
, pFeatures
->pNext
) {
694 switch (ext
->sType
) {
695 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
696 VkPhysicalDeviceMultiviewFeaturesKHX
*features
=
697 (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
698 features
->multiview
= true;
699 features
->multiviewGeometryShader
= true;
700 features
->multiviewTessellationShader
= true;
705 anv_debug_ignored_stype(ext
->sType
);
711 void anv_GetPhysicalDeviceProperties(
712 VkPhysicalDevice physicalDevice
,
713 VkPhysicalDeviceProperties
* pProperties
)
715 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
716 const struct gen_device_info
*devinfo
= &pdevice
->info
;
718 /* See assertions made when programming the buffer surface state. */
719 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
720 (1ul << 30) : (1ul << 27);
722 VkSampleCountFlags sample_counts
=
723 isl_device_get_sample_counts(&pdevice
->isl_dev
);
725 VkPhysicalDeviceLimits limits
= {
726 .maxImageDimension1D
= (1 << 14),
727 .maxImageDimension2D
= (1 << 14),
728 .maxImageDimension3D
= (1 << 11),
729 .maxImageDimensionCube
= (1 << 14),
730 .maxImageArrayLayers
= (1 << 11),
731 .maxTexelBufferElements
= 128 * 1024 * 1024,
732 .maxUniformBufferRange
= (1ul << 27),
733 .maxStorageBufferRange
= max_raw_buffer_sz
,
734 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
735 .maxMemoryAllocationCount
= UINT32_MAX
,
736 .maxSamplerAllocationCount
= 64 * 1024,
737 .bufferImageGranularity
= 64, /* A cache line */
738 .sparseAddressSpaceSize
= 0,
739 .maxBoundDescriptorSets
= MAX_SETS
,
740 .maxPerStageDescriptorSamplers
= 64,
741 .maxPerStageDescriptorUniformBuffers
= 64,
742 .maxPerStageDescriptorStorageBuffers
= 64,
743 .maxPerStageDescriptorSampledImages
= 64,
744 .maxPerStageDescriptorStorageImages
= 64,
745 .maxPerStageDescriptorInputAttachments
= 64,
746 .maxPerStageResources
= 128,
747 .maxDescriptorSetSamplers
= 256,
748 .maxDescriptorSetUniformBuffers
= 256,
749 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
750 .maxDescriptorSetStorageBuffers
= 256,
751 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
752 .maxDescriptorSetSampledImages
= 256,
753 .maxDescriptorSetStorageImages
= 256,
754 .maxDescriptorSetInputAttachments
= 256,
755 .maxVertexInputAttributes
= MAX_VBS
,
756 .maxVertexInputBindings
= MAX_VBS
,
757 .maxVertexInputAttributeOffset
= 2047,
758 .maxVertexInputBindingStride
= 2048,
759 .maxVertexOutputComponents
= 128,
760 .maxTessellationGenerationLevel
= 64,
761 .maxTessellationPatchSize
= 32,
762 .maxTessellationControlPerVertexInputComponents
= 128,
763 .maxTessellationControlPerVertexOutputComponents
= 128,
764 .maxTessellationControlPerPatchOutputComponents
= 128,
765 .maxTessellationControlTotalOutputComponents
= 2048,
766 .maxTessellationEvaluationInputComponents
= 128,
767 .maxTessellationEvaluationOutputComponents
= 128,
768 .maxGeometryShaderInvocations
= 32,
769 .maxGeometryInputComponents
= 64,
770 .maxGeometryOutputComponents
= 128,
771 .maxGeometryOutputVertices
= 256,
772 .maxGeometryTotalOutputComponents
= 1024,
773 .maxFragmentInputComponents
= 128,
774 .maxFragmentOutputAttachments
= 8,
775 .maxFragmentDualSrcAttachments
= 1,
776 .maxFragmentCombinedOutputResources
= 8,
777 .maxComputeSharedMemorySize
= 32768,
778 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
779 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
780 .maxComputeWorkGroupSize
= {
781 16 * devinfo
->max_cs_threads
,
782 16 * devinfo
->max_cs_threads
,
783 16 * devinfo
->max_cs_threads
,
785 .subPixelPrecisionBits
= 4 /* FIXME */,
786 .subTexelPrecisionBits
= 4 /* FIXME */,
787 .mipmapPrecisionBits
= 4 /* FIXME */,
788 .maxDrawIndexedIndexValue
= UINT32_MAX
,
789 .maxDrawIndirectCount
= UINT32_MAX
,
790 .maxSamplerLodBias
= 16,
791 .maxSamplerAnisotropy
= 16,
792 .maxViewports
= MAX_VIEWPORTS
,
793 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
794 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
795 .viewportSubPixelBits
= 13, /* We take a float? */
796 .minMemoryMapAlignment
= 4096, /* A page */
797 .minTexelBufferOffsetAlignment
= 1,
798 .minUniformBufferOffsetAlignment
= 16,
799 .minStorageBufferOffsetAlignment
= 4,
800 .minTexelOffset
= -8,
802 .minTexelGatherOffset
= -32,
803 .maxTexelGatherOffset
= 31,
804 .minInterpolationOffset
= -0.5,
805 .maxInterpolationOffset
= 0.4375,
806 .subPixelInterpolationOffsetBits
= 4,
807 .maxFramebufferWidth
= (1 << 14),
808 .maxFramebufferHeight
= (1 << 14),
809 .maxFramebufferLayers
= (1 << 11),
810 .framebufferColorSampleCounts
= sample_counts
,
811 .framebufferDepthSampleCounts
= sample_counts
,
812 .framebufferStencilSampleCounts
= sample_counts
,
813 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
814 .maxColorAttachments
= MAX_RTS
,
815 .sampledImageColorSampleCounts
= sample_counts
,
816 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
817 .sampledImageDepthSampleCounts
= sample_counts
,
818 .sampledImageStencilSampleCounts
= sample_counts
,
819 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
820 .maxSampleMaskWords
= 1,
821 .timestampComputeAndGraphics
= false,
822 .timestampPeriod
= devinfo
->timebase_scale
,
823 .maxClipDistances
= 8,
824 .maxCullDistances
= 8,
825 .maxCombinedClipAndCullDistances
= 8,
826 .discreteQueuePriorities
= 1,
827 .pointSizeRange
= { 0.125, 255.875 },
828 .lineWidthRange
= { 0.0, 7.9921875 },
829 .pointSizeGranularity
= (1.0 / 8.0),
830 .lineWidthGranularity
= (1.0 / 128.0),
831 .strictLines
= false, /* FINISHME */
832 .standardSampleLocations
= true,
833 .optimalBufferCopyOffsetAlignment
= 128,
834 .optimalBufferCopyRowPitchAlignment
= 128,
835 .nonCoherentAtomSize
= 64,
838 *pProperties
= (VkPhysicalDeviceProperties
) {
839 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
842 .deviceID
= pdevice
->chipset_id
,
843 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
845 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
848 strcpy(pProperties
->deviceName
, pdevice
->name
);
849 memcpy(pProperties
->pipelineCacheUUID
,
850 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
853 void anv_GetPhysicalDeviceProperties2KHR(
854 VkPhysicalDevice physicalDevice
,
855 VkPhysicalDeviceProperties2KHR
* pProperties
)
857 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
859 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
861 vk_foreach_struct(ext
, pProperties
->pNext
) {
862 switch (ext
->sType
) {
863 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
864 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
865 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
867 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
871 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHX
: {
872 VkPhysicalDeviceIDPropertiesKHX
*id_props
=
873 (VkPhysicalDeviceIDPropertiesKHX
*)ext
;
874 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
875 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
876 /* The LUID is for Windows. */
877 id_props
->deviceLUIDValid
= false;
881 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
882 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
=
883 (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
884 properties
->maxMultiviewViewCount
= 16;
885 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
890 anv_debug_ignored_stype(ext
->sType
);
896 /* We support exactly one queue family. */
897 static const VkQueueFamilyProperties
898 anv_queue_family_properties
= {
899 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
900 VK_QUEUE_COMPUTE_BIT
|
901 VK_QUEUE_TRANSFER_BIT
,
903 .timestampValidBits
= 36, /* XXX: Real value here */
904 .minImageTransferGranularity
= { 1, 1, 1 },
907 void anv_GetPhysicalDeviceQueueFamilyProperties(
908 VkPhysicalDevice physicalDevice
,
910 VkQueueFamilyProperties
* pQueueFamilyProperties
)
912 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
914 vk_outarray_append(&out
, p
) {
915 *p
= anv_queue_family_properties
;
919 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
920 VkPhysicalDevice physicalDevice
,
921 uint32_t* pQueueFamilyPropertyCount
,
922 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
925 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
927 vk_outarray_append(&out
, p
) {
928 p
->queueFamilyProperties
= anv_queue_family_properties
;
930 vk_foreach_struct(s
, p
->pNext
) {
931 anv_debug_ignored_stype(s
->sType
);
936 void anv_GetPhysicalDeviceMemoryProperties(
937 VkPhysicalDevice physicalDevice
,
938 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
940 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
942 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
943 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
944 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
945 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
946 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
950 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
951 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
952 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
953 .size
= physical_device
->memory
.heaps
[i
].size
,
954 .flags
= physical_device
->memory
.heaps
[i
].flags
,
959 void anv_GetPhysicalDeviceMemoryProperties2KHR(
960 VkPhysicalDevice physicalDevice
,
961 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
963 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
964 &pMemoryProperties
->memoryProperties
);
966 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
967 switch (ext
->sType
) {
969 anv_debug_ignored_stype(ext
->sType
);
975 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
979 return anv_lookup_entrypoint(NULL
, pName
);
982 /* With version 1+ of the loader interface the ICD should expose
983 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
986 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
991 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
995 return anv_GetInstanceProcAddr(instance
, pName
);
998 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1002 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1003 return anv_lookup_entrypoint(&device
->info
, pName
);
1007 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1009 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1010 queue
->device
= device
;
1011 queue
->pool
= &device
->surface_state_pool
;
1015 anv_queue_finish(struct anv_queue
*queue
)
1019 static struct anv_state
1020 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1022 struct anv_state state
;
1024 state
= anv_state_pool_alloc(pool
, size
, align
);
1025 memcpy(state
.map
, p
, size
);
1027 anv_state_flush(pool
->block_pool
.device
, state
);
1032 struct gen8_border_color
{
1037 /* Pad out to 64 bytes */
1042 anv_device_init_border_colors(struct anv_device
*device
)
1044 static const struct gen8_border_color border_colors
[] = {
1045 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1046 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1047 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1048 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1049 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1050 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1053 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1054 sizeof(border_colors
), 64,
1058 VkResult
anv_CreateDevice(
1059 VkPhysicalDevice physicalDevice
,
1060 const VkDeviceCreateInfo
* pCreateInfo
,
1061 const VkAllocationCallbacks
* pAllocator
,
1064 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1066 struct anv_device
*device
;
1068 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1070 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1072 for (uint32_t j
= 0; j
< ARRAY_SIZE(device_extensions
); j
++) {
1073 if (strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
1074 device_extensions
[j
].extensionName
) == 0) {
1080 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1083 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1085 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1087 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1089 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1090 device
->instance
= physical_device
->instance
;
1091 device
->chipset_id
= physical_device
->chipset_id
;
1092 device
->lost
= false;
1095 device
->alloc
= *pAllocator
;
1097 device
->alloc
= physical_device
->instance
->alloc
;
1099 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1100 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1101 if (device
->fd
== -1) {
1102 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1106 device
->context_id
= anv_gem_create_context(device
);
1107 if (device
->context_id
== -1) {
1108 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1112 device
->info
= physical_device
->info
;
1113 device
->isl_dev
= physical_device
->isl_dev
;
1115 /* On Broadwell and later, we can use batch chaining to more efficiently
1116 * implement growing command buffers. Prior to Haswell, the kernel
1117 * command parser gets in the way and we have to fall back to growing
1120 device
->can_chain_batches
= device
->info
.gen
>= 8;
1122 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1123 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1125 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1126 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1127 goto fail_context_id
;
1130 pthread_condattr_t condattr
;
1131 if (pthread_condattr_init(&condattr
) != 0) {
1132 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1135 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1136 pthread_condattr_destroy(&condattr
);
1137 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1140 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1141 pthread_condattr_destroy(&condattr
);
1142 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1145 pthread_condattr_destroy(&condattr
);
1147 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1149 result
= anv_bo_cache_init(&device
->bo_cache
);
1150 if (result
!= VK_SUCCESS
)
1151 goto fail_batch_bo_pool
;
1153 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384);
1154 if (result
!= VK_SUCCESS
)
1157 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384);
1158 if (result
!= VK_SUCCESS
)
1159 goto fail_dynamic_state_pool
;
1161 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096);
1162 if (result
!= VK_SUCCESS
)
1163 goto fail_instruction_state_pool
;
1165 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1166 if (result
!= VK_SUCCESS
)
1167 goto fail_surface_state_pool
;
1169 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1171 anv_queue_init(device
, &device
->queue
);
1173 switch (device
->info
.gen
) {
1175 if (!device
->info
.is_haswell
)
1176 result
= gen7_init_device_state(device
);
1178 result
= gen75_init_device_state(device
);
1181 result
= gen8_init_device_state(device
);
1184 result
= gen9_init_device_state(device
);
1187 /* Shouldn't get here as we don't create physical devices for any other
1189 unreachable("unhandled gen");
1191 if (result
!= VK_SUCCESS
)
1192 goto fail_workaround_bo
;
1194 anv_device_init_blorp(device
);
1196 anv_device_init_border_colors(device
);
1198 *pDevice
= anv_device_to_handle(device
);
1203 anv_queue_finish(&device
->queue
);
1204 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1205 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1206 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1207 fail_surface_state_pool
:
1208 anv_state_pool_finish(&device
->surface_state_pool
);
1209 fail_instruction_state_pool
:
1210 anv_state_pool_finish(&device
->instruction_state_pool
);
1211 fail_dynamic_state_pool
:
1212 anv_state_pool_finish(&device
->dynamic_state_pool
);
1214 anv_bo_cache_finish(&device
->bo_cache
);
1216 anv_bo_pool_finish(&device
->batch_bo_pool
);
1217 pthread_cond_destroy(&device
->queue_submit
);
1219 pthread_mutex_destroy(&device
->mutex
);
1221 anv_gem_destroy_context(device
, device
->context_id
);
1225 vk_free(&device
->alloc
, device
);
1230 void anv_DestroyDevice(
1232 const VkAllocationCallbacks
* pAllocator
)
1234 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1239 anv_device_finish_blorp(device
);
1241 anv_queue_finish(&device
->queue
);
1243 #ifdef HAVE_VALGRIND
1244 /* We only need to free these to prevent valgrind errors. The backing
1245 * BO will go away in a couple of lines so we don't actually leak.
1247 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1250 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1252 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1253 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1255 anv_state_pool_finish(&device
->surface_state_pool
);
1256 anv_state_pool_finish(&device
->instruction_state_pool
);
1257 anv_state_pool_finish(&device
->dynamic_state_pool
);
1259 anv_bo_cache_finish(&device
->bo_cache
);
1261 anv_bo_pool_finish(&device
->batch_bo_pool
);
1263 pthread_cond_destroy(&device
->queue_submit
);
1264 pthread_mutex_destroy(&device
->mutex
);
1266 anv_gem_destroy_context(device
, device
->context_id
);
1270 vk_free(&device
->alloc
, device
);
1273 VkResult
anv_EnumerateInstanceExtensionProperties(
1274 const char* pLayerName
,
1275 uint32_t* pPropertyCount
,
1276 VkExtensionProperties
* pProperties
)
1278 if (pProperties
== NULL
) {
1279 *pPropertyCount
= ARRAY_SIZE(global_extensions
);
1283 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(global_extensions
));
1284 typed_memcpy(pProperties
, global_extensions
, *pPropertyCount
);
1286 if (*pPropertyCount
< ARRAY_SIZE(global_extensions
))
1287 return VK_INCOMPLETE
;
1292 VkResult
anv_EnumerateDeviceExtensionProperties(
1293 VkPhysicalDevice physicalDevice
,
1294 const char* pLayerName
,
1295 uint32_t* pPropertyCount
,
1296 VkExtensionProperties
* pProperties
)
1298 if (pProperties
== NULL
) {
1299 *pPropertyCount
= ARRAY_SIZE(device_extensions
);
1303 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(device_extensions
));
1304 typed_memcpy(pProperties
, device_extensions
, *pPropertyCount
);
1306 if (*pPropertyCount
< ARRAY_SIZE(device_extensions
))
1307 return VK_INCOMPLETE
;
1312 VkResult
anv_EnumerateInstanceLayerProperties(
1313 uint32_t* pPropertyCount
,
1314 VkLayerProperties
* pProperties
)
1316 if (pProperties
== NULL
) {
1317 *pPropertyCount
= 0;
1321 /* None supported at this time */
1322 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1325 VkResult
anv_EnumerateDeviceLayerProperties(
1326 VkPhysicalDevice physicalDevice
,
1327 uint32_t* pPropertyCount
,
1328 VkLayerProperties
* pProperties
)
1330 if (pProperties
== NULL
) {
1331 *pPropertyCount
= 0;
1335 /* None supported at this time */
1336 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1339 void anv_GetDeviceQueue(
1341 uint32_t queueNodeIndex
,
1342 uint32_t queueIndex
,
1345 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1347 assert(queueIndex
== 0);
1349 *pQueue
= anv_queue_to_handle(&device
->queue
);
1353 anv_device_query_status(struct anv_device
*device
)
1355 /* This isn't likely as most of the callers of this function already check
1356 * for it. However, it doesn't hurt to check and it potentially lets us
1359 if (unlikely(device
->lost
))
1360 return VK_ERROR_DEVICE_LOST
;
1362 uint32_t active
, pending
;
1363 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1365 /* We don't know the real error. */
1366 device
->lost
= true;
1367 return vk_errorf(VK_ERROR_DEVICE_LOST
, "get_reset_stats failed: %m");
1371 device
->lost
= true;
1372 return vk_errorf(VK_ERROR_DEVICE_LOST
,
1373 "GPU hung on one of our command buffers");
1374 } else if (pending
) {
1375 device
->lost
= true;
1376 return vk_errorf(VK_ERROR_DEVICE_LOST
,
1377 "GPU hung with commands in-flight");
1384 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1386 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1387 * Other usages of the BO (such as on different hardware) will not be
1388 * flagged as "busy" by this ioctl. Use with care.
1390 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1392 return VK_NOT_READY
;
1393 } else if (ret
== -1) {
1394 /* We don't know the real error. */
1395 device
->lost
= true;
1396 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1399 /* Query for device status after the busy call. If the BO we're checking
1400 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1401 * client because it clearly doesn't have valid data. Yes, this most
1402 * likely means an ioctl, but we just did an ioctl to query the busy status
1403 * so it's no great loss.
1405 return anv_device_query_status(device
);
1409 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1412 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1413 if (ret
== -1 && errno
== ETIME
) {
1415 } else if (ret
== -1) {
1416 /* We don't know the real error. */
1417 device
->lost
= true;
1418 return vk_errorf(VK_ERROR_DEVICE_LOST
, "gem wait failed: %m");
1421 /* Query for device status after the wait. If the BO we're waiting on got
1422 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1423 * because it clearly doesn't have valid data. Yes, this most likely means
1424 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1426 return anv_device_query_status(device
);
1429 VkResult
anv_DeviceWaitIdle(
1432 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1433 if (unlikely(device
->lost
))
1434 return VK_ERROR_DEVICE_LOST
;
1436 struct anv_batch batch
;
1439 batch
.start
= batch
.next
= cmds
;
1440 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1442 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1443 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1445 return anv_device_submit_simple_batch(device
, &batch
);
1449 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1451 uint32_t gem_handle
= anv_gem_create(device
, size
);
1453 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1455 anv_bo_init(bo
, gem_handle
, size
);
1460 VkResult
anv_AllocateMemory(
1462 const VkMemoryAllocateInfo
* pAllocateInfo
,
1463 const VkAllocationCallbacks
* pAllocator
,
1464 VkDeviceMemory
* pMem
)
1466 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1467 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1468 struct anv_device_memory
*mem
;
1469 VkResult result
= VK_SUCCESS
;
1471 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1473 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1474 assert(pAllocateInfo
->allocationSize
> 0);
1476 /* The kernel relocation API has a limitation of a 32-bit delta value
1477 * applied to the address before it is written which, in spite of it being
1478 * unsigned, is treated as signed . Because of the way that this maps to
1479 * the Vulkan API, we cannot handle an offset into a buffer that does not
1480 * fit into a signed 32 bits. The only mechanism we have for dealing with
1481 * this at the moment is to limit all VkDeviceMemory objects to a maximum
1482 * of 2GB each. The Vulkan spec allows us to do this:
1484 * "Some platforms may have a limit on the maximum size of a single
1485 * allocation. For example, certain systems may fail to create
1486 * allocations with a size greater than or equal to 4GB. Such a limit is
1487 * implementation-dependent, and if such a failure occurs then the error
1488 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
1490 * We don't use vk_error here because it's not an error so much as an
1491 * indication to the application that the allocation is too large.
1493 if (pAllocateInfo
->allocationSize
> (1ull << 31))
1494 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1496 /* FINISHME: Fail if allocation request exceeds heap size. */
1498 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1499 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1501 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1503 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1504 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1508 const VkImportMemoryFdInfoKHX
*fd_info
=
1509 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHX
);
1511 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1514 if (fd_info
&& fd_info
->handleType
) {
1515 /* At the moment, we only support the OPAQUE_FD memory type which is
1516 * just a GEM buffer.
1518 assert(fd_info
->handleType
==
1519 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX
);
1521 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1522 fd_info
->fd
, pAllocateInfo
->allocationSize
,
1524 if (result
!= VK_SUCCESS
)
1527 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1528 pAllocateInfo
->allocationSize
,
1530 if (result
!= VK_SUCCESS
)
1534 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
1535 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
1536 mem
->bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1538 if (pdevice
->has_exec_async
)
1539 mem
->bo
->flags
|= EXEC_OBJECT_ASYNC
;
1541 *pMem
= anv_device_memory_to_handle(mem
);
1546 vk_free2(&device
->alloc
, pAllocator
, mem
);
1551 VkResult
anv_GetMemoryFdKHX(
1553 VkDeviceMemory memory_h
,
1554 VkExternalMemoryHandleTypeFlagBitsKHX handleType
,
1557 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
1558 ANV_FROM_HANDLE(anv_device_memory
, mem
, memory_h
);
1560 /* We support only one handle type. */
1561 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX
);
1563 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
1566 VkResult
anv_GetMemoryFdPropertiesKHX(
1568 VkExternalMemoryHandleTypeFlagBitsKHX handleType
,
1570 VkMemoryFdPropertiesKHX
* pMemoryFdProperties
)
1572 /* The valid usage section for this function says:
1574 * "handleType must not be one of the handle types defined as opaque."
1576 * Since we only handle opaque handles for now, there are no FD properties.
1578 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX
;
1581 void anv_FreeMemory(
1583 VkDeviceMemory _mem
,
1584 const VkAllocationCallbacks
* pAllocator
)
1586 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1587 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1593 anv_UnmapMemory(_device
, _mem
);
1595 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1597 vk_free2(&device
->alloc
, pAllocator
, mem
);
1600 VkResult
anv_MapMemory(
1602 VkDeviceMemory _memory
,
1603 VkDeviceSize offset
,
1605 VkMemoryMapFlags flags
,
1608 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1609 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1616 if (size
== VK_WHOLE_SIZE
)
1617 size
= mem
->bo
->size
- offset
;
1619 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1621 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1622 * assert(size != 0);
1623 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1624 * equal to the size of the memory minus offset
1627 assert(offset
+ size
<= mem
->bo
->size
);
1629 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1630 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1631 * at a time is valid. We could just mmap up front and return an offset
1632 * pointer here, but that may exhaust virtual memory on 32 bit
1635 uint32_t gem_flags
= 0;
1637 if (!device
->info
.has_llc
&&
1638 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
1639 gem_flags
|= I915_MMAP_WC
;
1641 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1642 uint64_t map_offset
= offset
& ~4095ull;
1643 assert(offset
>= map_offset
);
1644 uint64_t map_size
= (offset
+ size
) - map_offset
;
1646 /* Let's map whole pages */
1647 map_size
= align_u64(map_size
, 4096);
1649 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
1650 map_offset
, map_size
, gem_flags
);
1651 if (map
== MAP_FAILED
)
1652 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1655 mem
->map_size
= map_size
;
1657 *ppData
= mem
->map
+ (offset
- map_offset
);
1662 void anv_UnmapMemory(
1664 VkDeviceMemory _memory
)
1666 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1671 anv_gem_munmap(mem
->map
, mem
->map_size
);
1678 clflush_mapped_ranges(struct anv_device
*device
,
1680 const VkMappedMemoryRange
*ranges
)
1682 for (uint32_t i
= 0; i
< count
; i
++) {
1683 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1684 if (ranges
[i
].offset
>= mem
->map_size
)
1687 anv_clflush_range(mem
->map
+ ranges
[i
].offset
,
1688 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1692 VkResult
anv_FlushMappedMemoryRanges(
1694 uint32_t memoryRangeCount
,
1695 const VkMappedMemoryRange
* pMemoryRanges
)
1697 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1699 if (device
->info
.has_llc
)
1702 /* Make sure the writes we're flushing have landed. */
1703 __builtin_ia32_mfence();
1705 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1710 VkResult
anv_InvalidateMappedMemoryRanges(
1712 uint32_t memoryRangeCount
,
1713 const VkMappedMemoryRange
* pMemoryRanges
)
1715 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1717 if (device
->info
.has_llc
)
1720 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1722 /* Make sure no reads get moved up above the invalidate. */
1723 __builtin_ia32_mfence();
1728 void anv_GetBufferMemoryRequirements(
1731 VkMemoryRequirements
* pMemoryRequirements
)
1733 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1734 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1735 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1737 /* The Vulkan spec (git aaed022) says:
1739 * memoryTypeBits is a bitfield and contains one bit set for every
1740 * supported memory type for the resource. The bit `1<<i` is set if and
1741 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1742 * structure for the physical device is supported.
1744 uint32_t memory_types
= 0;
1745 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
1746 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
1747 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
1748 memory_types
|= (1u << i
);
1751 pMemoryRequirements
->size
= buffer
->size
;
1752 pMemoryRequirements
->alignment
= 16;
1753 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1756 void anv_GetImageMemoryRequirements(
1759 VkMemoryRequirements
* pMemoryRequirements
)
1761 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1762 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1763 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1765 /* The Vulkan spec (git aaed022) says:
1767 * memoryTypeBits is a bitfield and contains one bit set for every
1768 * supported memory type for the resource. The bit `1<<i` is set if and
1769 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1770 * structure for the physical device is supported.
1772 * All types are currently supported for images.
1774 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
1776 pMemoryRequirements
->size
= image
->size
;
1777 pMemoryRequirements
->alignment
= image
->alignment
;
1778 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1781 void anv_GetImageSparseMemoryRequirements(
1784 uint32_t* pSparseMemoryRequirementCount
,
1785 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1787 *pSparseMemoryRequirementCount
= 0;
1790 void anv_GetDeviceMemoryCommitment(
1792 VkDeviceMemory memory
,
1793 VkDeviceSize
* pCommittedMemoryInBytes
)
1795 *pCommittedMemoryInBytes
= 0;
1798 VkResult
anv_BindBufferMemory(
1801 VkDeviceMemory _memory
,
1802 VkDeviceSize memoryOffset
)
1804 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1805 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1808 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
1809 buffer
->bo
= mem
->bo
;
1810 buffer
->offset
= memoryOffset
;
1819 VkResult
anv_QueueBindSparse(
1821 uint32_t bindInfoCount
,
1822 const VkBindSparseInfo
* pBindInfo
,
1825 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1826 if (unlikely(queue
->device
->lost
))
1827 return VK_ERROR_DEVICE_LOST
;
1829 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1834 VkResult
anv_CreateEvent(
1836 const VkEventCreateInfo
* pCreateInfo
,
1837 const VkAllocationCallbacks
* pAllocator
,
1840 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1841 struct anv_state state
;
1842 struct anv_event
*event
;
1844 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1846 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1849 event
->state
= state
;
1850 event
->semaphore
= VK_EVENT_RESET
;
1852 if (!device
->info
.has_llc
) {
1853 /* Make sure the writes we're flushing have landed. */
1854 __builtin_ia32_mfence();
1855 __builtin_ia32_clflush(event
);
1858 *pEvent
= anv_event_to_handle(event
);
1863 void anv_DestroyEvent(
1866 const VkAllocationCallbacks
* pAllocator
)
1868 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1869 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1874 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
1877 VkResult
anv_GetEventStatus(
1881 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1882 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1884 if (unlikely(device
->lost
))
1885 return VK_ERROR_DEVICE_LOST
;
1887 if (!device
->info
.has_llc
) {
1888 /* Invalidate read cache before reading event written by GPU. */
1889 __builtin_ia32_clflush(event
);
1890 __builtin_ia32_mfence();
1894 return event
->semaphore
;
1897 VkResult
anv_SetEvent(
1901 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1902 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1904 event
->semaphore
= VK_EVENT_SET
;
1906 if (!device
->info
.has_llc
) {
1907 /* Make sure the writes we're flushing have landed. */
1908 __builtin_ia32_mfence();
1909 __builtin_ia32_clflush(event
);
1915 VkResult
anv_ResetEvent(
1919 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1920 ANV_FROM_HANDLE(anv_event
, event
, _event
);
1922 event
->semaphore
= VK_EVENT_RESET
;
1924 if (!device
->info
.has_llc
) {
1925 /* Make sure the writes we're flushing have landed. */
1926 __builtin_ia32_mfence();
1927 __builtin_ia32_clflush(event
);
1935 VkResult
anv_CreateBuffer(
1937 const VkBufferCreateInfo
* pCreateInfo
,
1938 const VkAllocationCallbacks
* pAllocator
,
1941 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1942 struct anv_buffer
*buffer
;
1944 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1946 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1947 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1949 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1951 buffer
->size
= pCreateInfo
->size
;
1952 buffer
->usage
= pCreateInfo
->usage
;
1956 *pBuffer
= anv_buffer_to_handle(buffer
);
1961 void anv_DestroyBuffer(
1964 const VkAllocationCallbacks
* pAllocator
)
1966 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1967 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
1972 vk_free2(&device
->alloc
, pAllocator
, buffer
);
1976 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
1977 enum isl_format format
,
1978 uint32_t offset
, uint32_t range
, uint32_t stride
)
1980 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
1982 .mocs
= device
->default_mocs
,
1987 anv_state_flush(device
, state
);
1990 void anv_DestroySampler(
1993 const VkAllocationCallbacks
* pAllocator
)
1995 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1996 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2001 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2004 VkResult
anv_CreateFramebuffer(
2006 const VkFramebufferCreateInfo
* pCreateInfo
,
2007 const VkAllocationCallbacks
* pAllocator
,
2008 VkFramebuffer
* pFramebuffer
)
2010 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2011 struct anv_framebuffer
*framebuffer
;
2013 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2015 size_t size
= sizeof(*framebuffer
) +
2016 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2017 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2018 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2019 if (framebuffer
== NULL
)
2020 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2022 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2023 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2024 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2025 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2028 framebuffer
->width
= pCreateInfo
->width
;
2029 framebuffer
->height
= pCreateInfo
->height
;
2030 framebuffer
->layers
= pCreateInfo
->layers
;
2032 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2037 void anv_DestroyFramebuffer(
2040 const VkAllocationCallbacks
* pAllocator
)
2042 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2043 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2048 vk_free2(&device
->alloc
, pAllocator
, fb
);
2051 /* vk_icd.h does not declare this function, so we declare it here to
2052 * suppress Wmissing-prototypes.
2054 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2055 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2057 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2058 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2060 /* For the full details on loader interface versioning, see
2061 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2062 * What follows is a condensed summary, to help you navigate the large and
2063 * confusing official doc.
2065 * - Loader interface v0 is incompatible with later versions. We don't
2068 * - In loader interface v1:
2069 * - The first ICD entrypoint called by the loader is
2070 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2072 * - The ICD must statically expose no other Vulkan symbol unless it is
2073 * linked with -Bsymbolic.
2074 * - Each dispatchable Vulkan handle created by the ICD must be
2075 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2076 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2077 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2078 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2079 * such loader-managed surfaces.
2081 * - Loader interface v2 differs from v1 in:
2082 * - The first ICD entrypoint called by the loader is
2083 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2084 * statically expose this entrypoint.
2086 * - Loader interface v3 differs from v2 in:
2087 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2088 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2089 * because the loader no longer does so.
2091 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);