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"
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(NULL
, NULL
,
68 "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");
70 if (anv_gem_get_aperture(fd
, >t_size
) == -1) {
71 return vk_errorf(NULL
, NULL
, VK_ERROR_INITIALIZATION_FAILED
,
72 "failed to get aperture size: %m");
76 /* Query the total ram from the system */
80 uint64_t total_ram
= (uint64_t)info
.totalram
* (uint64_t)info
.mem_unit
;
82 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
83 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
85 uint64_t available_ram
;
86 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
87 available_ram
= total_ram
/ 2;
89 available_ram
= total_ram
* 3 / 4;
91 /* We also want to leave some padding for things we allocate in the driver,
92 * so don't go over 3/4 of the GTT either.
94 uint64_t available_gtt
= gtt_size
* 3 / 4;
96 *heap_size
= MIN2(available_ram
, available_gtt
);
102 anv_physical_device_init_heaps(struct anv_physical_device
*device
, int fd
)
104 /* The kernel query only tells us whether or not the kernel supports the
105 * EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and not whether or not the
106 * hardware has actual 48bit address support.
108 device
->supports_48bit_addresses
=
109 (device
->info
.gen
>= 8) && anv_gem_supports_48b_addresses(fd
);
112 VkResult result
= anv_compute_heap_size(fd
, &heap_size
);
113 if (result
!= VK_SUCCESS
)
116 if (heap_size
<= 3ull * (1ull << 30)) {
117 /* In this case, everything fits nicely into the 32-bit address space,
118 * so there's no need for supporting 48bit addresses on client-allocated
121 device
->memory
.heap_count
= 1;
122 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
124 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
125 .supports_48bit_addresses
= false,
128 /* Not everything will fit nicely into a 32-bit address space. In this
129 * case we need a 64-bit heap. Advertise a small 32-bit heap and a
130 * larger 48-bit heap. If we're in this case, then we have a total heap
131 * size larger than 3GiB which most likely means they have 8 GiB of
132 * video memory and so carving off 1 GiB for the 32-bit heap should be
135 const uint64_t heap_size_32bit
= 1ull << 30;
136 const uint64_t heap_size_48bit
= heap_size
- heap_size_32bit
;
138 assert(device
->supports_48bit_addresses
);
140 device
->memory
.heap_count
= 2;
141 device
->memory
.heaps
[0] = (struct anv_memory_heap
) {
142 .size
= heap_size_48bit
,
143 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
144 .supports_48bit_addresses
= true,
146 device
->memory
.heaps
[1] = (struct anv_memory_heap
) {
147 .size
= heap_size_32bit
,
148 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
149 .supports_48bit_addresses
= false,
153 uint32_t type_count
= 0;
154 for (uint32_t heap
= 0; heap
< device
->memory
.heap_count
; heap
++) {
155 uint32_t valid_buffer_usage
= ~0;
157 /* There appears to be a hardware issue in the VF cache where it only
158 * considers the bottom 32 bits of memory addresses. If you happen to
159 * have two vertex buffers which get placed exactly 4 GiB apart and use
160 * them in back-to-back draw calls, you can get collisions. In order to
161 * solve this problem, we require vertex and index buffers be bound to
162 * memory allocated out of the 32-bit heap.
164 if (device
->memory
.heaps
[heap
].supports_48bit_addresses
) {
165 valid_buffer_usage
&= ~(VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
166 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
169 if (device
->info
.has_llc
) {
170 /* Big core GPUs share LLC with the CPU and thus one memory type can be
171 * both cached and coherent at the same time.
173 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
174 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
175 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
176 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
177 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
179 .valid_buffer_usage
= valid_buffer_usage
,
182 /* The spec requires that we expose a host-visible, coherent memory
183 * type, but Atom GPUs don't share LLC. Thus we offer two memory types
184 * to give the application a choice between cached, but not coherent and
185 * coherent but uncached (WC though).
187 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
188 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
189 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
190 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
192 .valid_buffer_usage
= valid_buffer_usage
,
194 device
->memory
.types
[type_count
++] = (struct anv_memory_type
) {
195 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
196 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
197 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
199 .valid_buffer_usage
= valid_buffer_usage
,
203 device
->memory
.type_count
= type_count
;
209 anv_physical_device_init_uuids(struct anv_physical_device
*device
)
211 const struct build_id_note
*note
=
212 build_id_find_nhdr_for_addr(anv_physical_device_init_uuids
);
214 return vk_errorf(device
->instance
, device
,
215 VK_ERROR_INITIALIZATION_FAILED
,
216 "Failed to find build-id");
219 unsigned build_id_len
= build_id_length(note
);
220 if (build_id_len
< 20) {
221 return vk_errorf(device
->instance
, device
,
222 VK_ERROR_INITIALIZATION_FAILED
,
223 "build-id too short. It needs to be a SHA");
226 struct mesa_sha1 sha1_ctx
;
228 STATIC_ASSERT(VK_UUID_SIZE
<= sizeof(sha1
));
230 /* The pipeline cache UUID is used for determining when a pipeline cache is
231 * invalid. It needs both a driver build and the PCI ID of the device.
233 _mesa_sha1_init(&sha1_ctx
);
234 _mesa_sha1_update(&sha1_ctx
, build_id_data(note
), build_id_len
);
235 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
236 sizeof(device
->chipset_id
));
237 _mesa_sha1_final(&sha1_ctx
, sha1
);
238 memcpy(device
->pipeline_cache_uuid
, sha1
, VK_UUID_SIZE
);
240 /* The driver UUID is used for determining sharability of images and memory
241 * between two Vulkan instances in separate processes. People who want to
242 * share memory need to also check the device UUID (below) so all this
243 * needs to be is the build-id.
245 memcpy(device
->driver_uuid
, build_id_data(note
), VK_UUID_SIZE
);
247 /* The device UUID uniquely identifies the given device within the machine.
248 * Since we never have more than one device, this doesn't need to be a real
249 * UUID. However, on the off-chance that someone tries to use this to
250 * cache pre-tiled images or something of the like, we use the PCI ID and
251 * some bits of ISL info to ensure that this is safe.
253 _mesa_sha1_init(&sha1_ctx
);
254 _mesa_sha1_update(&sha1_ctx
, &device
->chipset_id
,
255 sizeof(device
->chipset_id
));
256 _mesa_sha1_update(&sha1_ctx
, &device
->isl_dev
.has_bit6_swizzling
,
257 sizeof(device
->isl_dev
.has_bit6_swizzling
));
258 _mesa_sha1_final(&sha1_ctx
, sha1
);
259 memcpy(device
->device_uuid
, sha1
, VK_UUID_SIZE
);
265 anv_physical_device_init(struct anv_physical_device
*device
,
266 struct anv_instance
*instance
,
272 brw_process_intel_debug_variable();
274 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
276 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
278 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
279 device
->instance
= instance
;
281 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
282 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
284 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
285 if (!device
->chipset_id
) {
286 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
290 device
->name
= gen_get_device_name(device
->chipset_id
);
291 if (!gen_get_device_info(device
->chipset_id
, &device
->info
)) {
292 result
= vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
296 if (device
->info
.is_haswell
) {
297 fprintf(stderr
, "WARNING: Haswell Vulkan support is incomplete\n");
298 } else if (device
->info
.gen
== 7 && !device
->info
.is_baytrail
) {
299 fprintf(stderr
, "WARNING: Ivy Bridge Vulkan support is incomplete\n");
300 } else if (device
->info
.gen
== 7 && device
->info
.is_baytrail
) {
301 fprintf(stderr
, "WARNING: Bay Trail Vulkan support is incomplete\n");
302 } else if (device
->info
.gen
>= 8 && device
->info
.gen
<= 9) {
303 /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully
304 * supported as anything */
306 result
= vk_errorf(device
->instance
, device
,
307 VK_ERROR_INCOMPATIBLE_DRIVER
,
308 "Vulkan not yet supported on %s", device
->name
);
312 device
->cmd_parser_version
= -1;
313 if (device
->info
.gen
== 7) {
314 device
->cmd_parser_version
=
315 anv_gem_get_param(fd
, I915_PARAM_CMD_PARSER_VERSION
);
316 if (device
->cmd_parser_version
== -1) {
317 result
= vk_errorf(device
->instance
, device
,
318 VK_ERROR_INITIALIZATION_FAILED
,
319 "failed to get command parser version");
324 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
)) {
325 result
= vk_errorf(device
->instance
, device
,
326 VK_ERROR_INITIALIZATION_FAILED
,
327 "kernel missing gem wait");
331 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
)) {
332 result
= vk_errorf(device
->instance
, device
,
333 VK_ERROR_INITIALIZATION_FAILED
,
334 "kernel missing execbuf2");
338 if (!device
->info
.has_llc
&&
339 anv_gem_get_param(fd
, I915_PARAM_MMAP_VERSION
) < 1) {
340 result
= vk_errorf(device
->instance
, device
,
341 VK_ERROR_INITIALIZATION_FAILED
,
342 "kernel missing wc mmap");
346 result
= anv_physical_device_init_heaps(device
, fd
);
347 if (result
!= VK_SUCCESS
)
350 device
->has_exec_async
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_ASYNC
);
351 device
->has_exec_fence
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE
);
352 device
->has_syncobj
= anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_FENCE_ARRAY
);
353 device
->has_syncobj_wait
= device
->has_syncobj
&&
354 anv_gem_supports_syncobj_wait(fd
);
356 bool swizzled
= anv_gem_get_bit6_swizzle(fd
, I915_TILING_X
);
358 /* GENs prior to 8 do not support EU/Subslice info */
359 if (device
->info
.gen
>= 8) {
360 device
->subslice_total
= anv_gem_get_param(fd
, I915_PARAM_SUBSLICE_TOTAL
);
361 device
->eu_total
= anv_gem_get_param(fd
, I915_PARAM_EU_TOTAL
);
363 /* Without this information, we cannot get the right Braswell
364 * brandstrings, and we have to use conservative numbers for GPGPU on
365 * many platforms, but otherwise, things will just work.
367 if (device
->subslice_total
< 1 || device
->eu_total
< 1) {
368 fprintf(stderr
, "WARNING: Kernel 4.1 required to properly"
369 " query GPU properties.\n");
371 } else if (device
->info
.gen
== 7) {
372 device
->subslice_total
= 1 << (device
->info
.gt
- 1);
375 if (device
->info
.is_cherryview
&&
376 device
->subslice_total
> 0 && device
->eu_total
> 0) {
377 /* Logical CS threads = EUs per subslice * num threads per EU */
378 uint32_t max_cs_threads
=
379 device
->eu_total
/ device
->subslice_total
* device
->info
.num_thread_per_eu
;
381 /* Fuse configurations may give more threads than expected, never less. */
382 if (max_cs_threads
> device
->info
.max_cs_threads
)
383 device
->info
.max_cs_threads
= max_cs_threads
;
386 device
->compiler
= brw_compiler_create(NULL
, &device
->info
);
387 if (device
->compiler
== NULL
) {
388 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
391 device
->compiler
->shader_debug_log
= compiler_debug_log
;
392 device
->compiler
->shader_perf_log
= compiler_perf_log
;
394 isl_device_init(&device
->isl_dev
, &device
->info
, swizzled
);
396 result
= anv_physical_device_init_uuids(device
);
397 if (result
!= VK_SUCCESS
)
400 result
= anv_init_wsi(device
);
401 if (result
!= VK_SUCCESS
) {
402 ralloc_free(device
->compiler
);
406 device
->local_fd
= fd
;
415 anv_physical_device_finish(struct anv_physical_device
*device
)
417 anv_finish_wsi(device
);
418 ralloc_free(device
->compiler
);
419 close(device
->local_fd
);
423 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
424 VkSystemAllocationScope allocationScope
)
430 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
431 size_t align
, VkSystemAllocationScope allocationScope
)
433 return realloc(pOriginal
, size
);
437 default_free_func(void *pUserData
, void *pMemory
)
442 static const VkAllocationCallbacks default_alloc
= {
444 .pfnAllocation
= default_alloc_func
,
445 .pfnReallocation
= default_realloc_func
,
446 .pfnFree
= default_free_func
,
449 VkResult
anv_CreateInstance(
450 const VkInstanceCreateInfo
* pCreateInfo
,
451 const VkAllocationCallbacks
* pAllocator
,
452 VkInstance
* pInstance
)
454 struct anv_instance
*instance
;
456 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
458 /* Check if user passed a debug report callback to be used during
459 * Create/Destroy of instance.
461 const VkDebugReportCallbackCreateInfoEXT
*ctor_cb
=
462 vk_find_struct_const(pCreateInfo
->pNext
,
463 DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT
);
465 uint32_t client_version
;
466 if (pCreateInfo
->pApplicationInfo
&&
467 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
468 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
470 client_version
= VK_MAKE_VERSION(1, 0, 0);
473 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
474 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
476 if (ctor_cb
&& ctor_cb
->flags
& VK_DEBUG_REPORT_ERROR_BIT_EXT
)
477 ctor_cb
->pfnCallback(VK_DEBUG_REPORT_ERROR_BIT_EXT
,
478 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT
,
479 VK_NULL_HANDLE
, /* No handle available yet. */
483 "incompatible driver version",
486 return vk_errorf(NULL
, NULL
, VK_ERROR_INCOMPATIBLE_DRIVER
,
487 "Client requested version %d.%d.%d",
488 VK_VERSION_MAJOR(client_version
),
489 VK_VERSION_MINOR(client_version
),
490 VK_VERSION_PATCH(client_version
));
493 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
494 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
495 if (!anv_instance_extension_supported(ext_name
))
496 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
499 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
500 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
502 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
504 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
507 instance
->alloc
= *pAllocator
;
509 instance
->alloc
= default_alloc
;
511 instance
->apiVersion
= client_version
;
512 instance
->physicalDeviceCount
= -1;
514 if (pthread_mutex_init(&instance
->callbacks_mutex
, NULL
) != 0) {
515 vk_free2(&default_alloc
, pAllocator
, instance
);
516 return vk_error(VK_ERROR_INITIALIZATION_FAILED
);
519 list_inithead(&instance
->callbacks
);
521 /* Store report debug callback to be used during DestroyInstance. */
523 instance
->destroy_debug_cb
.flags
= ctor_cb
->flags
;
524 instance
->destroy_debug_cb
.callback
= ctor_cb
->pfnCallback
;
525 instance
->destroy_debug_cb
.data
= ctor_cb
->pUserData
;
530 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
532 *pInstance
= anv_instance_to_handle(instance
);
537 void anv_DestroyInstance(
538 VkInstance _instance
,
539 const VkAllocationCallbacks
* pAllocator
)
541 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
546 if (instance
->physicalDeviceCount
> 0) {
547 /* We support at most one physical device. */
548 assert(instance
->physicalDeviceCount
== 1);
549 anv_physical_device_finish(&instance
->physicalDevice
);
552 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
554 pthread_mutex_destroy(&instance
->callbacks_mutex
);
558 vk_free(&instance
->alloc
, instance
);
562 anv_enumerate_devices(struct anv_instance
*instance
)
564 /* TODO: Check for more devices ? */
565 drmDevicePtr devices
[8];
566 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
569 instance
->physicalDeviceCount
= 0;
571 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
573 return VK_ERROR_INCOMPATIBLE_DRIVER
;
575 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
576 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
577 devices
[i
]->bustype
== DRM_BUS_PCI
&&
578 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x8086) {
580 result
= anv_physical_device_init(&instance
->physicalDevice
,
582 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
583 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
587 drmFreeDevices(devices
, max_devices
);
589 if (result
== VK_SUCCESS
)
590 instance
->physicalDeviceCount
= 1;
596 VkResult
anv_EnumeratePhysicalDevices(
597 VkInstance _instance
,
598 uint32_t* pPhysicalDeviceCount
,
599 VkPhysicalDevice
* pPhysicalDevices
)
601 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
602 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
605 if (instance
->physicalDeviceCount
< 0) {
606 result
= anv_enumerate_devices(instance
);
607 if (result
!= VK_SUCCESS
&&
608 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
612 if (instance
->physicalDeviceCount
> 0) {
613 assert(instance
->physicalDeviceCount
== 1);
614 vk_outarray_append(&out
, i
) {
615 *i
= anv_physical_device_to_handle(&instance
->physicalDevice
);
619 return vk_outarray_status(&out
);
622 void anv_GetPhysicalDeviceFeatures(
623 VkPhysicalDevice physicalDevice
,
624 VkPhysicalDeviceFeatures
* pFeatures
)
626 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
628 *pFeatures
= (VkPhysicalDeviceFeatures
) {
629 .robustBufferAccess
= true,
630 .fullDrawIndexUint32
= true,
631 .imageCubeArray
= true,
632 .independentBlend
= true,
633 .geometryShader
= true,
634 .tessellationShader
= true,
635 .sampleRateShading
= true,
636 .dualSrcBlend
= true,
638 .multiDrawIndirect
= true,
639 .drawIndirectFirstInstance
= true,
641 .depthBiasClamp
= true,
642 .fillModeNonSolid
= true,
643 .depthBounds
= false,
647 .multiViewport
= true,
648 .samplerAnisotropy
= true,
649 .textureCompressionETC2
= pdevice
->info
.gen
>= 8 ||
650 pdevice
->info
.is_baytrail
,
651 .textureCompressionASTC_LDR
= pdevice
->info
.gen
>= 9, /* FINISHME CHV */
652 .textureCompressionBC
= true,
653 .occlusionQueryPrecise
= true,
654 .pipelineStatisticsQuery
= true,
655 .fragmentStoresAndAtomics
= true,
656 .shaderTessellationAndGeometryPointSize
= true,
657 .shaderImageGatherExtended
= true,
658 .shaderStorageImageExtendedFormats
= true,
659 .shaderStorageImageMultisample
= false,
660 .shaderStorageImageReadWithoutFormat
= false,
661 .shaderStorageImageWriteWithoutFormat
= true,
662 .shaderUniformBufferArrayDynamicIndexing
= true,
663 .shaderSampledImageArrayDynamicIndexing
= true,
664 .shaderStorageBufferArrayDynamicIndexing
= true,
665 .shaderStorageImageArrayDynamicIndexing
= true,
666 .shaderClipDistance
= true,
667 .shaderCullDistance
= true,
668 .shaderFloat64
= pdevice
->info
.gen
>= 8,
669 .shaderInt64
= pdevice
->info
.gen
>= 8,
670 .shaderInt16
= false,
671 .shaderResourceMinLod
= false,
672 .variableMultisampleRate
= false,
673 .inheritedQueries
= true,
676 /* We can't do image stores in vec4 shaders */
677 pFeatures
->vertexPipelineStoresAndAtomics
=
678 pdevice
->compiler
->scalar_stage
[MESA_SHADER_VERTEX
] &&
679 pdevice
->compiler
->scalar_stage
[MESA_SHADER_GEOMETRY
];
682 void anv_GetPhysicalDeviceFeatures2KHR(
683 VkPhysicalDevice physicalDevice
,
684 VkPhysicalDeviceFeatures2KHR
* pFeatures
)
686 anv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
688 vk_foreach_struct(ext
, pFeatures
->pNext
) {
689 switch (ext
->sType
) {
690 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
691 VkPhysicalDeviceMultiviewFeaturesKHX
*features
=
692 (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
693 features
->multiview
= true;
694 features
->multiviewGeometryShader
= true;
695 features
->multiviewTessellationShader
= true;
699 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
700 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
701 features
->variablePointersStorageBuffer
= true;
702 features
->variablePointers
= false;
706 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES_KHR
: {
707 VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR
*features
=
708 (VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR
*) ext
;
709 features
->samplerYcbcrConversion
= true;
714 anv_debug_ignored_stype(ext
->sType
);
720 void anv_GetPhysicalDeviceProperties(
721 VkPhysicalDevice physicalDevice
,
722 VkPhysicalDeviceProperties
* pProperties
)
724 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
725 const struct gen_device_info
*devinfo
= &pdevice
->info
;
727 /* See assertions made when programming the buffer surface state. */
728 const uint32_t max_raw_buffer_sz
= devinfo
->gen
>= 7 ?
729 (1ul << 30) : (1ul << 27);
731 const uint32_t max_samplers
= (devinfo
->gen
>= 8 || devinfo
->is_haswell
) ?
734 VkSampleCountFlags sample_counts
=
735 isl_device_get_sample_counts(&pdevice
->isl_dev
);
737 VkPhysicalDeviceLimits limits
= {
738 .maxImageDimension1D
= (1 << 14),
739 .maxImageDimension2D
= (1 << 14),
740 .maxImageDimension3D
= (1 << 11),
741 .maxImageDimensionCube
= (1 << 14),
742 .maxImageArrayLayers
= (1 << 11),
743 .maxTexelBufferElements
= 128 * 1024 * 1024,
744 .maxUniformBufferRange
= (1ul << 27),
745 .maxStorageBufferRange
= max_raw_buffer_sz
,
746 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
747 .maxMemoryAllocationCount
= UINT32_MAX
,
748 .maxSamplerAllocationCount
= 64 * 1024,
749 .bufferImageGranularity
= 64, /* A cache line */
750 .sparseAddressSpaceSize
= 0,
751 .maxBoundDescriptorSets
= MAX_SETS
,
752 .maxPerStageDescriptorSamplers
= max_samplers
,
753 .maxPerStageDescriptorUniformBuffers
= 64,
754 .maxPerStageDescriptorStorageBuffers
= 64,
755 .maxPerStageDescriptorSampledImages
= max_samplers
,
756 .maxPerStageDescriptorStorageImages
= 64,
757 .maxPerStageDescriptorInputAttachments
= 64,
758 .maxPerStageResources
= 250,
759 .maxDescriptorSetSamplers
= 256,
760 .maxDescriptorSetUniformBuffers
= 256,
761 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
762 .maxDescriptorSetStorageBuffers
= 256,
763 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
764 .maxDescriptorSetSampledImages
= 256,
765 .maxDescriptorSetStorageImages
= 256,
766 .maxDescriptorSetInputAttachments
= 256,
767 .maxVertexInputAttributes
= MAX_VBS
,
768 .maxVertexInputBindings
= MAX_VBS
,
769 .maxVertexInputAttributeOffset
= 2047,
770 .maxVertexInputBindingStride
= 2048,
771 .maxVertexOutputComponents
= 128,
772 .maxTessellationGenerationLevel
= 64,
773 .maxTessellationPatchSize
= 32,
774 .maxTessellationControlPerVertexInputComponents
= 128,
775 .maxTessellationControlPerVertexOutputComponents
= 128,
776 .maxTessellationControlPerPatchOutputComponents
= 128,
777 .maxTessellationControlTotalOutputComponents
= 2048,
778 .maxTessellationEvaluationInputComponents
= 128,
779 .maxTessellationEvaluationOutputComponents
= 128,
780 .maxGeometryShaderInvocations
= 32,
781 .maxGeometryInputComponents
= 64,
782 .maxGeometryOutputComponents
= 128,
783 .maxGeometryOutputVertices
= 256,
784 .maxGeometryTotalOutputComponents
= 1024,
785 .maxFragmentInputComponents
= 128,
786 .maxFragmentOutputAttachments
= 8,
787 .maxFragmentDualSrcAttachments
= 1,
788 .maxFragmentCombinedOutputResources
= 8,
789 .maxComputeSharedMemorySize
= 32768,
790 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
791 .maxComputeWorkGroupInvocations
= 16 * devinfo
->max_cs_threads
,
792 .maxComputeWorkGroupSize
= {
793 16 * devinfo
->max_cs_threads
,
794 16 * devinfo
->max_cs_threads
,
795 16 * devinfo
->max_cs_threads
,
797 .subPixelPrecisionBits
= 4 /* FIXME */,
798 .subTexelPrecisionBits
= 4 /* FIXME */,
799 .mipmapPrecisionBits
= 4 /* FIXME */,
800 .maxDrawIndexedIndexValue
= UINT32_MAX
,
801 .maxDrawIndirectCount
= UINT32_MAX
,
802 .maxSamplerLodBias
= 16,
803 .maxSamplerAnisotropy
= 16,
804 .maxViewports
= MAX_VIEWPORTS
,
805 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
806 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
807 .viewportSubPixelBits
= 13, /* We take a float? */
808 .minMemoryMapAlignment
= 4096, /* A page */
809 .minTexelBufferOffsetAlignment
= 1,
810 .minUniformBufferOffsetAlignment
= 16,
811 .minStorageBufferOffsetAlignment
= 4,
812 .minTexelOffset
= -8,
814 .minTexelGatherOffset
= -32,
815 .maxTexelGatherOffset
= 31,
816 .minInterpolationOffset
= -0.5,
817 .maxInterpolationOffset
= 0.4375,
818 .subPixelInterpolationOffsetBits
= 4,
819 .maxFramebufferWidth
= (1 << 14),
820 .maxFramebufferHeight
= (1 << 14),
821 .maxFramebufferLayers
= (1 << 11),
822 .framebufferColorSampleCounts
= sample_counts
,
823 .framebufferDepthSampleCounts
= sample_counts
,
824 .framebufferStencilSampleCounts
= sample_counts
,
825 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
826 .maxColorAttachments
= MAX_RTS
,
827 .sampledImageColorSampleCounts
= sample_counts
,
828 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
829 .sampledImageDepthSampleCounts
= sample_counts
,
830 .sampledImageStencilSampleCounts
= sample_counts
,
831 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
832 .maxSampleMaskWords
= 1,
833 .timestampComputeAndGraphics
= false,
834 .timestampPeriod
= 1000000000.0 / devinfo
->timestamp_frequency
,
835 .maxClipDistances
= 8,
836 .maxCullDistances
= 8,
837 .maxCombinedClipAndCullDistances
= 8,
838 .discreteQueuePriorities
= 1,
839 .pointSizeRange
= { 0.125, 255.875 },
840 .lineWidthRange
= { 0.0, 7.9921875 },
841 .pointSizeGranularity
= (1.0 / 8.0),
842 .lineWidthGranularity
= (1.0 / 128.0),
843 .strictLines
= false, /* FINISHME */
844 .standardSampleLocations
= true,
845 .optimalBufferCopyOffsetAlignment
= 128,
846 .optimalBufferCopyRowPitchAlignment
= 128,
847 .nonCoherentAtomSize
= 64,
850 *pProperties
= (VkPhysicalDeviceProperties
) {
851 .apiVersion
= anv_physical_device_api_version(pdevice
),
852 .driverVersion
= vk_get_driver_version(),
854 .deviceID
= pdevice
->chipset_id
,
855 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
857 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
860 snprintf(pProperties
->deviceName
, sizeof(pProperties
->deviceName
),
861 "%s", pdevice
->name
);
862 memcpy(pProperties
->pipelineCacheUUID
,
863 pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
866 void anv_GetPhysicalDeviceProperties2KHR(
867 VkPhysicalDevice physicalDevice
,
868 VkPhysicalDeviceProperties2KHR
* pProperties
)
870 ANV_FROM_HANDLE(anv_physical_device
, pdevice
, physicalDevice
);
872 anv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
874 vk_foreach_struct(ext
, pProperties
->pNext
) {
875 switch (ext
->sType
) {
876 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
877 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
878 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
880 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
884 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
885 VkPhysicalDeviceIDPropertiesKHR
*id_props
=
886 (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
887 memcpy(id_props
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
888 memcpy(id_props
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
889 /* The LUID is for Windows. */
890 id_props
->deviceLUIDValid
= false;
894 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
895 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
=
896 (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
897 properties
->maxMultiviewViewCount
= 16;
898 properties
->maxMultiviewInstanceIndex
= UINT32_MAX
/ 16;
902 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
903 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
904 (VkPhysicalDevicePointClippingPropertiesKHR
*) ext
;
905 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
906 anv_finishme("Implement pop-free point clipping");
911 anv_debug_ignored_stype(ext
->sType
);
917 /* We support exactly one queue family. */
918 static const VkQueueFamilyProperties
919 anv_queue_family_properties
= {
920 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
921 VK_QUEUE_COMPUTE_BIT
|
922 VK_QUEUE_TRANSFER_BIT
,
924 .timestampValidBits
= 36, /* XXX: Real value here */
925 .minImageTransferGranularity
= { 1, 1, 1 },
928 void anv_GetPhysicalDeviceQueueFamilyProperties(
929 VkPhysicalDevice physicalDevice
,
931 VkQueueFamilyProperties
* pQueueFamilyProperties
)
933 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pCount
);
935 vk_outarray_append(&out
, p
) {
936 *p
= anv_queue_family_properties
;
940 void anv_GetPhysicalDeviceQueueFamilyProperties2KHR(
941 VkPhysicalDevice physicalDevice
,
942 uint32_t* pQueueFamilyPropertyCount
,
943 VkQueueFamilyProperties2KHR
* pQueueFamilyProperties
)
946 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
948 vk_outarray_append(&out
, p
) {
949 p
->queueFamilyProperties
= anv_queue_family_properties
;
951 vk_foreach_struct(s
, p
->pNext
) {
952 anv_debug_ignored_stype(s
->sType
);
957 void anv_GetPhysicalDeviceMemoryProperties(
958 VkPhysicalDevice physicalDevice
,
959 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
961 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
963 pMemoryProperties
->memoryTypeCount
= physical_device
->memory
.type_count
;
964 for (uint32_t i
= 0; i
< physical_device
->memory
.type_count
; i
++) {
965 pMemoryProperties
->memoryTypes
[i
] = (VkMemoryType
) {
966 .propertyFlags
= physical_device
->memory
.types
[i
].propertyFlags
,
967 .heapIndex
= physical_device
->memory
.types
[i
].heapIndex
,
971 pMemoryProperties
->memoryHeapCount
= physical_device
->memory
.heap_count
;
972 for (uint32_t i
= 0; i
< physical_device
->memory
.heap_count
; i
++) {
973 pMemoryProperties
->memoryHeaps
[i
] = (VkMemoryHeap
) {
974 .size
= physical_device
->memory
.heaps
[i
].size
,
975 .flags
= physical_device
->memory
.heaps
[i
].flags
,
980 void anv_GetPhysicalDeviceMemoryProperties2KHR(
981 VkPhysicalDevice physicalDevice
,
982 VkPhysicalDeviceMemoryProperties2KHR
* pMemoryProperties
)
984 anv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
985 &pMemoryProperties
->memoryProperties
);
987 vk_foreach_struct(ext
, pMemoryProperties
->pNext
) {
988 switch (ext
->sType
) {
990 anv_debug_ignored_stype(ext
->sType
);
996 PFN_vkVoidFunction
anv_GetInstanceProcAddr(
1000 return anv_lookup_entrypoint(NULL
, pName
);
1003 /* With version 1+ of the loader interface the ICD should expose
1004 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
1007 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1008 VkInstance instance
,
1012 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1013 VkInstance instance
,
1016 return anv_GetInstanceProcAddr(instance
, pName
);
1019 PFN_vkVoidFunction
anv_GetDeviceProcAddr(
1023 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1024 return anv_lookup_entrypoint(&device
->info
, pName
);
1028 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
1030 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1031 queue
->device
= device
;
1032 queue
->pool
= &device
->surface_state_pool
;
1036 anv_queue_finish(struct anv_queue
*queue
)
1040 static struct anv_state
1041 anv_state_pool_emit_data(struct anv_state_pool
*pool
, size_t size
, size_t align
, const void *p
)
1043 struct anv_state state
;
1045 state
= anv_state_pool_alloc(pool
, size
, align
);
1046 memcpy(state
.map
, p
, size
);
1048 anv_state_flush(pool
->block_pool
.device
, state
);
1053 struct gen8_border_color
{
1058 /* Pad out to 64 bytes */
1063 anv_device_init_border_colors(struct anv_device
*device
)
1065 static const struct gen8_border_color border_colors
[] = {
1066 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 0.0 } },
1067 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = { .float32
= { 0.0, 0.0, 0.0, 1.0 } },
1068 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = { .float32
= { 1.0, 1.0, 1.0, 1.0 } },
1069 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = { .uint32
= { 0, 0, 0, 0 } },
1070 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = { .uint32
= { 0, 0, 0, 1 } },
1071 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = { .uint32
= { 1, 1, 1, 1 } },
1074 device
->border_colors
= anv_state_pool_emit_data(&device
->dynamic_state_pool
,
1075 sizeof(border_colors
), 64,
1080 anv_device_init_trivial_batch(struct anv_device
*device
)
1082 anv_bo_init_new(&device
->trivial_batch_bo
, device
, 4096);
1084 if (device
->instance
->physicalDevice
.has_exec_async
)
1085 device
->trivial_batch_bo
.flags
|= EXEC_OBJECT_ASYNC
;
1087 void *map
= anv_gem_mmap(device
, device
->trivial_batch_bo
.gem_handle
,
1090 struct anv_batch batch
= {
1096 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1097 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1099 if (!device
->info
.has_llc
)
1100 gen_clflush_range(map
, batch
.next
- map
);
1102 anv_gem_munmap(map
, device
->trivial_batch_bo
.size
);
1105 VkResult
anv_CreateDevice(
1106 VkPhysicalDevice physicalDevice
,
1107 const VkDeviceCreateInfo
* pCreateInfo
,
1108 const VkAllocationCallbacks
* pAllocator
,
1111 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
1113 struct anv_device
*device
;
1115 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
1117 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1118 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1119 if (!anv_physical_device_extension_supported(physical_device
, ext_name
))
1120 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1123 /* Check enabled features */
1124 if (pCreateInfo
->pEnabledFeatures
) {
1125 VkPhysicalDeviceFeatures supported_features
;
1126 anv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1127 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1128 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1129 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1130 for (uint32_t i
= 0; i
< num_features
; i
++) {
1131 if (enabled_feature
[i
] && !supported_feature
[i
])
1132 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1136 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1138 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1140 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1142 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1143 device
->instance
= physical_device
->instance
;
1144 device
->chipset_id
= physical_device
->chipset_id
;
1145 device
->lost
= false;
1148 device
->alloc
= *pAllocator
;
1150 device
->alloc
= physical_device
->instance
->alloc
;
1152 /* XXX(chadv): Can we dup() physicalDevice->fd here? */
1153 device
->fd
= open(physical_device
->path
, O_RDWR
| O_CLOEXEC
);
1154 if (device
->fd
== -1) {
1155 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1159 device
->context_id
= anv_gem_create_context(device
);
1160 if (device
->context_id
== -1) {
1161 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1165 device
->info
= physical_device
->info
;
1166 device
->isl_dev
= physical_device
->isl_dev
;
1168 /* On Broadwell and later, we can use batch chaining to more efficiently
1169 * implement growing command buffers. Prior to Haswell, the kernel
1170 * command parser gets in the way and we have to fall back to growing
1173 device
->can_chain_batches
= device
->info
.gen
>= 8;
1175 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1176 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1178 if (pthread_mutex_init(&device
->mutex
, NULL
) != 0) {
1179 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1180 goto fail_context_id
;
1183 pthread_condattr_t condattr
;
1184 if (pthread_condattr_init(&condattr
) != 0) {
1185 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1188 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
) != 0) {
1189 pthread_condattr_destroy(&condattr
);
1190 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1193 if (pthread_cond_init(&device
->queue_submit
, NULL
) != 0) {
1194 pthread_condattr_destroy(&condattr
);
1195 result
= vk_error(VK_ERROR_INITIALIZATION_FAILED
);
1198 pthread_condattr_destroy(&condattr
);
1200 anv_bo_pool_init(&device
->batch_bo_pool
, device
);
1202 result
= anv_bo_cache_init(&device
->bo_cache
);
1203 if (result
!= VK_SUCCESS
)
1204 goto fail_batch_bo_pool
;
1206 result
= anv_state_pool_init(&device
->dynamic_state_pool
, device
, 16384);
1207 if (result
!= VK_SUCCESS
)
1210 result
= anv_state_pool_init(&device
->instruction_state_pool
, device
, 16384);
1211 if (result
!= VK_SUCCESS
)
1212 goto fail_dynamic_state_pool
;
1214 result
= anv_state_pool_init(&device
->surface_state_pool
, device
, 4096);
1215 if (result
!= VK_SUCCESS
)
1216 goto fail_instruction_state_pool
;
1218 result
= anv_bo_init_new(&device
->workaround_bo
, device
, 1024);
1219 if (result
!= VK_SUCCESS
)
1220 goto fail_surface_state_pool
;
1222 anv_device_init_trivial_batch(device
);
1224 anv_scratch_pool_init(device
, &device
->scratch_pool
);
1226 anv_queue_init(device
, &device
->queue
);
1228 switch (device
->info
.gen
) {
1230 if (!device
->info
.is_haswell
)
1231 result
= gen7_init_device_state(device
);
1233 result
= gen75_init_device_state(device
);
1236 result
= gen8_init_device_state(device
);
1239 result
= gen9_init_device_state(device
);
1242 result
= gen10_init_device_state(device
);
1245 /* Shouldn't get here as we don't create physical devices for any other
1247 unreachable("unhandled gen");
1249 if (result
!= VK_SUCCESS
)
1250 goto fail_workaround_bo
;
1252 anv_device_init_blorp(device
);
1254 anv_device_init_border_colors(device
);
1256 *pDevice
= anv_device_to_handle(device
);
1261 anv_queue_finish(&device
->queue
);
1262 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1263 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1264 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1265 fail_surface_state_pool
:
1266 anv_state_pool_finish(&device
->surface_state_pool
);
1267 fail_instruction_state_pool
:
1268 anv_state_pool_finish(&device
->instruction_state_pool
);
1269 fail_dynamic_state_pool
:
1270 anv_state_pool_finish(&device
->dynamic_state_pool
);
1272 anv_bo_cache_finish(&device
->bo_cache
);
1274 anv_bo_pool_finish(&device
->batch_bo_pool
);
1275 pthread_cond_destroy(&device
->queue_submit
);
1277 pthread_mutex_destroy(&device
->mutex
);
1279 anv_gem_destroy_context(device
, device
->context_id
);
1283 vk_free(&device
->alloc
, device
);
1288 void anv_DestroyDevice(
1290 const VkAllocationCallbacks
* pAllocator
)
1292 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1297 anv_device_finish_blorp(device
);
1299 anv_queue_finish(&device
->queue
);
1301 #ifdef HAVE_VALGRIND
1302 /* We only need to free these to prevent valgrind errors. The backing
1303 * BO will go away in a couple of lines so we don't actually leak.
1305 anv_state_pool_free(&device
->dynamic_state_pool
, device
->border_colors
);
1308 anv_scratch_pool_finish(device
, &device
->scratch_pool
);
1310 anv_gem_munmap(device
->workaround_bo
.map
, device
->workaround_bo
.size
);
1311 anv_gem_close(device
, device
->workaround_bo
.gem_handle
);
1313 anv_gem_close(device
, device
->trivial_batch_bo
.gem_handle
);
1315 anv_state_pool_finish(&device
->surface_state_pool
);
1316 anv_state_pool_finish(&device
->instruction_state_pool
);
1317 anv_state_pool_finish(&device
->dynamic_state_pool
);
1319 anv_bo_cache_finish(&device
->bo_cache
);
1321 anv_bo_pool_finish(&device
->batch_bo_pool
);
1323 pthread_cond_destroy(&device
->queue_submit
);
1324 pthread_mutex_destroy(&device
->mutex
);
1326 anv_gem_destroy_context(device
, device
->context_id
);
1330 vk_free(&device
->alloc
, device
);
1333 VkResult
anv_EnumerateInstanceLayerProperties(
1334 uint32_t* pPropertyCount
,
1335 VkLayerProperties
* pProperties
)
1337 if (pProperties
== NULL
) {
1338 *pPropertyCount
= 0;
1342 /* None supported at this time */
1343 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1346 VkResult
anv_EnumerateDeviceLayerProperties(
1347 VkPhysicalDevice physicalDevice
,
1348 uint32_t* pPropertyCount
,
1349 VkLayerProperties
* pProperties
)
1351 if (pProperties
== NULL
) {
1352 *pPropertyCount
= 0;
1356 /* None supported at this time */
1357 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1360 void anv_GetDeviceQueue(
1362 uint32_t queueNodeIndex
,
1363 uint32_t queueIndex
,
1366 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1368 assert(queueIndex
== 0);
1370 *pQueue
= anv_queue_to_handle(&device
->queue
);
1374 anv_device_query_status(struct anv_device
*device
)
1376 /* This isn't likely as most of the callers of this function already check
1377 * for it. However, it doesn't hurt to check and it potentially lets us
1380 if (unlikely(device
->lost
))
1381 return VK_ERROR_DEVICE_LOST
;
1383 uint32_t active
, pending
;
1384 int ret
= anv_gem_gpu_get_reset_stats(device
, &active
, &pending
);
1386 /* We don't know the real error. */
1387 device
->lost
= true;
1388 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1389 "get_reset_stats failed: %m");
1393 device
->lost
= true;
1394 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1395 "GPU hung on one of our command buffers");
1396 } else if (pending
) {
1397 device
->lost
= true;
1398 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1399 "GPU hung with commands in-flight");
1406 anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
)
1408 /* Note: This only returns whether or not the BO is in use by an i915 GPU.
1409 * Other usages of the BO (such as on different hardware) will not be
1410 * flagged as "busy" by this ioctl. Use with care.
1412 int ret
= anv_gem_busy(device
, bo
->gem_handle
);
1414 return VK_NOT_READY
;
1415 } else if (ret
== -1) {
1416 /* We don't know the real error. */
1417 device
->lost
= true;
1418 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1419 "gem wait failed: %m");
1422 /* Query for device status after the busy call. If the BO we're checking
1423 * got caught in a GPU hang we don't want to return VK_SUCCESS to the
1424 * client because it clearly doesn't have valid data. Yes, this most
1425 * likely means an ioctl, but we just did an ioctl to query the busy status
1426 * so it's no great loss.
1428 return anv_device_query_status(device
);
1432 anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1435 int ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
1436 if (ret
== -1 && errno
== ETIME
) {
1438 } else if (ret
== -1) {
1439 /* We don't know the real error. */
1440 device
->lost
= true;
1441 return vk_errorf(device
->instance
, device
, VK_ERROR_DEVICE_LOST
,
1442 "gem wait failed: %m");
1445 /* Query for device status after the wait. If the BO we're waiting on got
1446 * caught in a GPU hang we don't want to return VK_SUCCESS to the client
1447 * because it clearly doesn't have valid data. Yes, this most likely means
1448 * an ioctl, but we just did an ioctl to wait so it's no great loss.
1450 return anv_device_query_status(device
);
1453 VkResult
anv_DeviceWaitIdle(
1456 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1457 if (unlikely(device
->lost
))
1458 return VK_ERROR_DEVICE_LOST
;
1460 struct anv_batch batch
;
1463 batch
.start
= batch
.next
= cmds
;
1464 batch
.end
= (void *) cmds
+ sizeof(cmds
);
1466 anv_batch_emit(&batch
, GEN7_MI_BATCH_BUFFER_END
, bbe
);
1467 anv_batch_emit(&batch
, GEN7_MI_NOOP
, noop
);
1469 return anv_device_submit_simple_batch(device
, &batch
);
1473 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
1475 uint32_t gem_handle
= anv_gem_create(device
, size
);
1477 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1479 anv_bo_init(bo
, gem_handle
, size
);
1484 VkResult
anv_AllocateMemory(
1486 const VkMemoryAllocateInfo
* pAllocateInfo
,
1487 const VkAllocationCallbacks
* pAllocator
,
1488 VkDeviceMemory
* pMem
)
1490 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1491 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1492 struct anv_device_memory
*mem
;
1493 VkResult result
= VK_SUCCESS
;
1495 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1497 /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
1498 assert(pAllocateInfo
->allocationSize
> 0);
1500 /* The kernel relocation API has a limitation of a 32-bit delta value
1501 * applied to the address before it is written which, in spite of it being
1502 * unsigned, is treated as signed . Because of the way that this maps to
1503 * the Vulkan API, we cannot handle an offset into a buffer that does not
1504 * fit into a signed 32 bits. The only mechanism we have for dealing with
1505 * this at the moment is to limit all VkDeviceMemory objects to a maximum
1506 * of 2GB each. The Vulkan spec allows us to do this:
1508 * "Some platforms may have a limit on the maximum size of a single
1509 * allocation. For example, certain systems may fail to create
1510 * allocations with a size greater than or equal to 4GB. Such a limit is
1511 * implementation-dependent, and if such a failure occurs then the error
1512 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
1514 * We don't use vk_error here because it's not an error so much as an
1515 * indication to the application that the allocation is too large.
1517 if (pAllocateInfo
->allocationSize
> (1ull << 31))
1518 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1520 /* FINISHME: Fail if allocation request exceeds heap size. */
1522 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1523 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1525 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1527 assert(pAllocateInfo
->memoryTypeIndex
< pdevice
->memory
.type_count
);
1528 mem
->type
= &pdevice
->memory
.types
[pAllocateInfo
->memoryTypeIndex
];
1532 const VkImportMemoryFdInfoKHR
*fd_info
=
1533 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1535 /* The Vulkan spec permits handleType to be 0, in which case the struct is
1538 if (fd_info
&& fd_info
->handleType
) {
1539 /* At the moment, we only support the OPAQUE_FD memory type which is
1540 * just a GEM buffer.
1542 assert(fd_info
->handleType
==
1543 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
1545 result
= anv_bo_cache_import(device
, &device
->bo_cache
,
1546 fd_info
->fd
, pAllocateInfo
->allocationSize
,
1548 if (result
!= VK_SUCCESS
)
1551 result
= anv_bo_cache_alloc(device
, &device
->bo_cache
,
1552 pAllocateInfo
->allocationSize
,
1554 if (result
!= VK_SUCCESS
)
1558 assert(mem
->type
->heapIndex
< pdevice
->memory
.heap_count
);
1559 if (pdevice
->memory
.heaps
[mem
->type
->heapIndex
].supports_48bit_addresses
)
1560 mem
->bo
->flags
|= EXEC_OBJECT_SUPPORTS_48B_ADDRESS
;
1562 if (pdevice
->has_exec_async
)
1563 mem
->bo
->flags
|= EXEC_OBJECT_ASYNC
;
1565 *pMem
= anv_device_memory_to_handle(mem
);
1570 vk_free2(&device
->alloc
, pAllocator
, mem
);
1575 VkResult
anv_GetMemoryFdKHR(
1577 const VkMemoryGetFdInfoKHR
* pGetFdInfo
,
1580 ANV_FROM_HANDLE(anv_device
, dev
, device_h
);
1581 ANV_FROM_HANDLE(anv_device_memory
, mem
, pGetFdInfo
->memory
);
1583 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
1585 /* We support only one handle type. */
1586 assert(pGetFdInfo
->handleType
==
1587 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
1589 return anv_bo_cache_export(dev
, &dev
->bo_cache
, mem
->bo
, pFd
);
1592 VkResult
anv_GetMemoryFdPropertiesKHR(
1594 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1596 VkMemoryFdPropertiesKHR
* pMemoryFdProperties
)
1598 /* The valid usage section for this function says:
1600 * "handleType must not be one of the handle types defined as opaque."
1602 * Since we only handle opaque handles for now, there are no FD properties.
1604 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1607 void anv_FreeMemory(
1609 VkDeviceMemory _mem
,
1610 const VkAllocationCallbacks
* pAllocator
)
1612 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1613 ANV_FROM_HANDLE(anv_device_memory
, mem
, _mem
);
1619 anv_UnmapMemory(_device
, _mem
);
1621 anv_bo_cache_release(device
, &device
->bo_cache
, mem
->bo
);
1623 vk_free2(&device
->alloc
, pAllocator
, mem
);
1626 VkResult
anv_MapMemory(
1628 VkDeviceMemory _memory
,
1629 VkDeviceSize offset
,
1631 VkMemoryMapFlags flags
,
1634 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1635 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1642 if (size
== VK_WHOLE_SIZE
)
1643 size
= mem
->bo
->size
- offset
;
1645 /* From the Vulkan spec version 1.0.32 docs for MapMemory:
1647 * * If size is not equal to VK_WHOLE_SIZE, size must be greater than 0
1648 * assert(size != 0);
1649 * * If size is not equal to VK_WHOLE_SIZE, size must be less than or
1650 * equal to the size of the memory minus offset
1653 assert(offset
+ size
<= mem
->bo
->size
);
1655 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
1656 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
1657 * at a time is valid. We could just mmap up front and return an offset
1658 * pointer here, but that may exhaust virtual memory on 32 bit
1661 uint32_t gem_flags
= 0;
1663 if (!device
->info
.has_llc
&&
1664 (mem
->type
->propertyFlags
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
1665 gem_flags
|= I915_MMAP_WC
;
1667 /* GEM will fail to map if the offset isn't 4k-aligned. Round down. */
1668 uint64_t map_offset
= offset
& ~4095ull;
1669 assert(offset
>= map_offset
);
1670 uint64_t map_size
= (offset
+ size
) - map_offset
;
1672 /* Let's map whole pages */
1673 map_size
= align_u64(map_size
, 4096);
1675 void *map
= anv_gem_mmap(device
, mem
->bo
->gem_handle
,
1676 map_offset
, map_size
, gem_flags
);
1677 if (map
== MAP_FAILED
)
1678 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
1681 mem
->map_size
= map_size
;
1683 *ppData
= mem
->map
+ (offset
- map_offset
);
1688 void anv_UnmapMemory(
1690 VkDeviceMemory _memory
)
1692 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
1697 anv_gem_munmap(mem
->map
, mem
->map_size
);
1704 clflush_mapped_ranges(struct anv_device
*device
,
1706 const VkMappedMemoryRange
*ranges
)
1708 for (uint32_t i
= 0; i
< count
; i
++) {
1709 ANV_FROM_HANDLE(anv_device_memory
, mem
, ranges
[i
].memory
);
1710 if (ranges
[i
].offset
>= mem
->map_size
)
1713 gen_clflush_range(mem
->map
+ ranges
[i
].offset
,
1714 MIN2(ranges
[i
].size
, mem
->map_size
- ranges
[i
].offset
));
1718 VkResult
anv_FlushMappedMemoryRanges(
1720 uint32_t memoryRangeCount
,
1721 const VkMappedMemoryRange
* pMemoryRanges
)
1723 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1725 if (device
->info
.has_llc
)
1728 /* Make sure the writes we're flushing have landed. */
1729 __builtin_ia32_mfence();
1731 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1736 VkResult
anv_InvalidateMappedMemoryRanges(
1738 uint32_t memoryRangeCount
,
1739 const VkMappedMemoryRange
* pMemoryRanges
)
1741 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1743 if (device
->info
.has_llc
)
1746 clflush_mapped_ranges(device
, memoryRangeCount
, pMemoryRanges
);
1748 /* Make sure no reads get moved up above the invalidate. */
1749 __builtin_ia32_mfence();
1754 void anv_GetBufferMemoryRequirements(
1757 VkMemoryRequirements
* pMemoryRequirements
)
1759 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
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 uint32_t memory_types
= 0;
1771 for (uint32_t i
= 0; i
< pdevice
->memory
.type_count
; i
++) {
1772 uint32_t valid_usage
= pdevice
->memory
.types
[i
].valid_buffer_usage
;
1773 if ((valid_usage
& buffer
->usage
) == buffer
->usage
)
1774 memory_types
|= (1u << i
);
1777 pMemoryRequirements
->size
= buffer
->size
;
1778 pMemoryRequirements
->alignment
= 16;
1779 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1782 void anv_GetBufferMemoryRequirements2KHR(
1784 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
1785 VkMemoryRequirements2KHR
* pMemoryRequirements
)
1787 anv_GetBufferMemoryRequirements(_device
, pInfo
->buffer
,
1788 &pMemoryRequirements
->memoryRequirements
);
1790 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
1791 switch (ext
->sType
) {
1792 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
1793 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
1794 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
1795 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
1800 anv_debug_ignored_stype(ext
->sType
);
1806 void anv_GetImageMemoryRequirements(
1809 VkMemoryRequirements
* pMemoryRequirements
)
1811 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1812 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1813 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1815 /* The Vulkan spec (git aaed022) says:
1817 * memoryTypeBits is a bitfield and contains one bit set for every
1818 * supported memory type for the resource. The bit `1<<i` is set if and
1819 * only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
1820 * structure for the physical device is supported.
1822 * All types are currently supported for images.
1824 uint32_t memory_types
= (1ull << pdevice
->memory
.type_count
) - 1;
1826 pMemoryRequirements
->size
= image
->size
;
1827 pMemoryRequirements
->alignment
= image
->alignment
;
1828 pMemoryRequirements
->memoryTypeBits
= memory_types
;
1831 void anv_GetImageMemoryRequirements2KHR(
1833 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
1834 VkMemoryRequirements2KHR
* pMemoryRequirements
)
1836 anv_GetImageMemoryRequirements(_device
, pInfo
->image
,
1837 &pMemoryRequirements
->memoryRequirements
);
1839 vk_foreach_struct_const(ext
, pInfo
->pNext
) {
1840 switch (ext
->sType
) {
1841 case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO_KHR
: {
1842 ANV_FROM_HANDLE(anv_image
, image
, pInfo
->image
);
1843 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1844 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
1845 const VkImagePlaneMemoryRequirementsInfoKHR
*plane_reqs
=
1846 (const VkImagePlaneMemoryRequirementsInfoKHR
*) ext
;
1847 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
,
1848 plane_reqs
->planeAspect
);
1850 assert(image
->planes
[plane
].offset
== 0);
1852 /* The Vulkan spec (git aaed022) says:
1854 * memoryTypeBits is a bitfield and contains one bit set for every
1855 * supported memory type for the resource. The bit `1<<i` is set
1856 * if and only if the memory type `i` in the
1857 * VkPhysicalDeviceMemoryProperties structure for the physical
1858 * device is supported.
1860 * All types are currently supported for images.
1862 pMemoryRequirements
->memoryRequirements
.memoryTypeBits
=
1863 (1ull << pdevice
->memory
.type_count
) - 1;
1865 pMemoryRequirements
->memoryRequirements
.size
= image
->planes
[plane
].size
;
1866 pMemoryRequirements
->memoryRequirements
.alignment
=
1867 image
->planes
[plane
].alignment
;
1872 anv_debug_ignored_stype(ext
->sType
);
1877 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
1878 switch (ext
->sType
) {
1879 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
1880 VkMemoryDedicatedRequirementsKHR
*requirements
= (void *)ext
;
1881 requirements
->prefersDedicatedAllocation
= VK_FALSE
;
1882 requirements
->requiresDedicatedAllocation
= VK_FALSE
;
1887 anv_debug_ignored_stype(ext
->sType
);
1893 void anv_GetImageSparseMemoryRequirements(
1896 uint32_t* pSparseMemoryRequirementCount
,
1897 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1899 *pSparseMemoryRequirementCount
= 0;
1902 void anv_GetImageSparseMemoryRequirements2KHR(
1904 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
1905 uint32_t* pSparseMemoryRequirementCount
,
1906 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
1908 *pSparseMemoryRequirementCount
= 0;
1911 void anv_GetDeviceMemoryCommitment(
1913 VkDeviceMemory memory
,
1914 VkDeviceSize
* pCommittedMemoryInBytes
)
1916 *pCommittedMemoryInBytes
= 0;
1920 anv_bind_buffer_memory(const VkBindBufferMemoryInfoKHR
*pBindInfo
)
1922 ANV_FROM_HANDLE(anv_device_memory
, mem
, pBindInfo
->memory
);
1923 ANV_FROM_HANDLE(anv_buffer
, buffer
, pBindInfo
->buffer
);
1925 assert(pBindInfo
->sType
== VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
);
1928 assert((buffer
->usage
& mem
->type
->valid_buffer_usage
) == buffer
->usage
);
1929 buffer
->bo
= mem
->bo
;
1930 buffer
->offset
= pBindInfo
->memoryOffset
;
1937 VkResult
anv_BindBufferMemory(
1940 VkDeviceMemory memory
,
1941 VkDeviceSize memoryOffset
)
1943 anv_bind_buffer_memory(
1944 &(VkBindBufferMemoryInfoKHR
) {
1945 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
1948 .memoryOffset
= memoryOffset
,
1954 VkResult
anv_BindBufferMemory2KHR(
1956 uint32_t bindInfoCount
,
1957 const VkBindBufferMemoryInfoKHR
* pBindInfos
)
1959 for (uint32_t i
= 0; i
< bindInfoCount
; i
++)
1960 anv_bind_buffer_memory(&pBindInfos
[i
]);
1965 VkResult
anv_QueueBindSparse(
1967 uint32_t bindInfoCount
,
1968 const VkBindSparseInfo
* pBindInfo
,
1971 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
1972 if (unlikely(queue
->device
->lost
))
1973 return VK_ERROR_DEVICE_LOST
;
1975 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1980 VkResult
anv_CreateEvent(
1982 const VkEventCreateInfo
* pCreateInfo
,
1983 const VkAllocationCallbacks
* pAllocator
,
1986 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1987 struct anv_state state
;
1988 struct anv_event
*event
;
1990 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
);
1992 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1995 event
->state
= state
;
1996 event
->semaphore
= VK_EVENT_RESET
;
1998 if (!device
->info
.has_llc
) {
1999 /* Make sure the writes we're flushing have landed. */
2000 __builtin_ia32_mfence();
2001 __builtin_ia32_clflush(event
);
2004 *pEvent
= anv_event_to_handle(event
);
2009 void anv_DestroyEvent(
2012 const VkAllocationCallbacks
* pAllocator
)
2014 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2015 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2020 anv_state_pool_free(&device
->dynamic_state_pool
, event
->state
);
2023 VkResult
anv_GetEventStatus(
2027 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2028 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2030 if (unlikely(device
->lost
))
2031 return VK_ERROR_DEVICE_LOST
;
2033 if (!device
->info
.has_llc
) {
2034 /* Invalidate read cache before reading event written by GPU. */
2035 __builtin_ia32_clflush(event
);
2036 __builtin_ia32_mfence();
2040 return event
->semaphore
;
2043 VkResult
anv_SetEvent(
2047 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2048 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2050 event
->semaphore
= VK_EVENT_SET
;
2052 if (!device
->info
.has_llc
) {
2053 /* Make sure the writes we're flushing have landed. */
2054 __builtin_ia32_mfence();
2055 __builtin_ia32_clflush(event
);
2061 VkResult
anv_ResetEvent(
2065 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2066 ANV_FROM_HANDLE(anv_event
, event
, _event
);
2068 event
->semaphore
= VK_EVENT_RESET
;
2070 if (!device
->info
.has_llc
) {
2071 /* Make sure the writes we're flushing have landed. */
2072 __builtin_ia32_mfence();
2073 __builtin_ia32_clflush(event
);
2081 VkResult
anv_CreateBuffer(
2083 const VkBufferCreateInfo
* pCreateInfo
,
2084 const VkAllocationCallbacks
* pAllocator
,
2087 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2088 struct anv_buffer
*buffer
;
2090 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2092 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2093 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2095 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2097 buffer
->size
= pCreateInfo
->size
;
2098 buffer
->usage
= pCreateInfo
->usage
;
2102 *pBuffer
= anv_buffer_to_handle(buffer
);
2107 void anv_DestroyBuffer(
2110 const VkAllocationCallbacks
* pAllocator
)
2112 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2113 ANV_FROM_HANDLE(anv_buffer
, buffer
, _buffer
);
2118 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2122 anv_fill_buffer_surface_state(struct anv_device
*device
, struct anv_state state
,
2123 enum isl_format format
,
2124 uint32_t offset
, uint32_t range
, uint32_t stride
)
2126 isl_buffer_fill_state(&device
->isl_dev
, state
.map
,
2128 .mocs
= device
->default_mocs
,
2133 anv_state_flush(device
, state
);
2136 void anv_DestroySampler(
2139 const VkAllocationCallbacks
* pAllocator
)
2141 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2142 ANV_FROM_HANDLE(anv_sampler
, sampler
, _sampler
);
2147 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2150 VkResult
anv_CreateFramebuffer(
2152 const VkFramebufferCreateInfo
* pCreateInfo
,
2153 const VkAllocationCallbacks
* pAllocator
,
2154 VkFramebuffer
* pFramebuffer
)
2156 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2157 struct anv_framebuffer
*framebuffer
;
2159 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2161 size_t size
= sizeof(*framebuffer
) +
2162 sizeof(struct anv_image_view
*) * pCreateInfo
->attachmentCount
;
2163 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2164 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2165 if (framebuffer
== NULL
)
2166 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2168 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2169 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2170 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2171 framebuffer
->attachments
[i
] = anv_image_view_from_handle(_iview
);
2174 framebuffer
->width
= pCreateInfo
->width
;
2175 framebuffer
->height
= pCreateInfo
->height
;
2176 framebuffer
->layers
= pCreateInfo
->layers
;
2178 *pFramebuffer
= anv_framebuffer_to_handle(framebuffer
);
2183 void anv_DestroyFramebuffer(
2186 const VkAllocationCallbacks
* pAllocator
)
2188 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2189 ANV_FROM_HANDLE(anv_framebuffer
, fb
, _fb
);
2194 vk_free2(&device
->alloc
, pAllocator
, fb
);
2197 /* vk_icd.h does not declare this function, so we declare it here to
2198 * suppress Wmissing-prototypes.
2200 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2201 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
);
2203 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2204 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion
)
2206 /* For the full details on loader interface versioning, see
2207 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2208 * What follows is a condensed summary, to help you navigate the large and
2209 * confusing official doc.
2211 * - Loader interface v0 is incompatible with later versions. We don't
2214 * - In loader interface v1:
2215 * - The first ICD entrypoint called by the loader is
2216 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2218 * - The ICD must statically expose no other Vulkan symbol unless it is
2219 * linked with -Bsymbolic.
2220 * - Each dispatchable Vulkan handle created by the ICD must be
2221 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2222 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2223 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2224 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2225 * such loader-managed surfaces.
2227 * - Loader interface v2 differs from v1 in:
2228 * - The first ICD entrypoint called by the loader is
2229 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2230 * statically expose this entrypoint.
2232 * - Loader interface v3 differs from v2 in:
2233 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2234 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2235 * because the loader no longer does so.
2237 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);