2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include "tu_private.h"
35 #include <sys/sysinfo.h>
39 #include "compiler/glsl_types.h"
40 #include "util/debug.h"
41 #include "util/disk_cache.h"
42 #include "util/u_atomic.h"
43 #include "vk_format.h"
46 #include "drm-uapi/msm_drm.h"
48 /* for fd_get_driver/device_uuid() */
49 #include "freedreno/common/freedreno_uuid.h"
52 tu_semaphore_remove_temp(struct tu_device
*device
,
53 struct tu_semaphore
*sem
);
56 tu_device_get_cache_uuid(uint16_t family
, void *uuid
)
58 uint32_t mesa_timestamp
;
60 memset(uuid
, 0, VK_UUID_SIZE
);
61 if (!disk_cache_get_function_timestamp(tu_device_get_cache_uuid
,
65 memcpy(uuid
, &mesa_timestamp
, 4);
66 memcpy((char *) uuid
+ 4, &f
, 2);
67 snprintf((char *) uuid
+ 6, VK_UUID_SIZE
- 10, "tu");
72 tu_bo_init(struct tu_device
*dev
,
77 uint64_t iova
= tu_gem_info_iova(dev
, gem_handle
);
79 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
81 *bo
= (struct tu_bo
) {
82 .gem_handle
= gem_handle
,
91 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
)
93 /* TODO: Choose better flags. As of 2018-11-12, freedreno/drm/msm_bo.c
94 * always sets `flags = MSM_BO_WC`, and we copy that behavior here.
96 uint32_t gem_handle
= tu_gem_new(dev
, size
, MSM_BO_WC
);
98 return vk_error(dev
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
100 VkResult result
= tu_bo_init(dev
, bo
, gem_handle
, size
);
101 if (result
!= VK_SUCCESS
) {
102 tu_gem_close(dev
, gem_handle
);
103 return vk_error(dev
->instance
, result
);
110 tu_bo_init_dmabuf(struct tu_device
*dev
,
115 uint32_t gem_handle
= tu_gem_import_dmabuf(dev
, fd
, size
);
117 return vk_error(dev
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
119 VkResult result
= tu_bo_init(dev
, bo
, gem_handle
, size
);
120 if (result
!= VK_SUCCESS
) {
121 tu_gem_close(dev
, gem_handle
);
122 return vk_error(dev
->instance
, result
);
129 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
)
131 return tu_gem_export_dmabuf(dev
, bo
->gem_handle
);
135 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
)
140 uint64_t offset
= tu_gem_info_offset(dev
, bo
->gem_handle
);
142 return vk_error(dev
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
144 /* TODO: Should we use the wrapper os_mmap() like Freedreno does? */
145 void *map
= mmap(0, bo
->size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
146 dev
->physical_device
->local_fd
, offset
);
147 if (map
== MAP_FAILED
)
148 return vk_error(dev
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
155 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
)
157 assert(bo
->gem_handle
);
160 munmap(bo
->map
, bo
->size
);
162 tu_gem_close(dev
, bo
->gem_handle
);
166 tu_physical_device_init(struct tu_physical_device
*device
,
167 struct tu_instance
*instance
,
168 drmDevicePtr drm_device
)
170 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
171 VkResult result
= VK_SUCCESS
;
172 drmVersionPtr version
;
176 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
178 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
179 "failed to open device %s", path
);
182 /* Version 1.3 added MSM_INFO_IOVA. */
183 const int min_version_major
= 1;
184 const int min_version_minor
= 3;
186 version
= drmGetVersion(fd
);
189 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
190 "failed to query kernel driver version for device %s",
194 if (strcmp(version
->name
, "msm")) {
195 drmFreeVersion(version
);
197 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
198 "device %s does not use the msm kernel driver", path
);
201 if (version
->version_major
!= min_version_major
||
202 version
->version_minor
< min_version_minor
) {
203 result
= vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
204 "kernel driver for device %s has version %d.%d, "
205 "but Vulkan requires version >= %d.%d",
206 path
, version
->version_major
, version
->version_minor
,
207 min_version_major
, min_version_minor
);
208 drmFreeVersion(version
);
213 device
->msm_major_version
= version
->version_major
;
214 device
->msm_minor_version
= version
->version_minor
;
216 drmFreeVersion(version
);
218 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
219 tu_logi("Found compatible device '%s'.", path
);
221 vk_object_base_init(NULL
, &device
->base
, VK_OBJECT_TYPE_PHYSICAL_DEVICE
);
222 device
->instance
= instance
;
223 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
224 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
226 if (instance
->enabled_extensions
.KHR_display
) {
228 open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
229 if (master_fd
>= 0) {
230 /* TODO: free master_fd is accel is not working? */
234 device
->master_fd
= master_fd
;
235 device
->local_fd
= fd
;
237 if (tu_drm_get_gpu_id(device
, &device
->gpu_id
)) {
238 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
239 tu_logi("Could not query the GPU ID");
240 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
241 "could not get GPU ID");
245 if (tu_drm_get_gmem_size(device
, &device
->gmem_size
)) {
246 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
247 tu_logi("Could not query the GMEM size");
248 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
249 "could not get GMEM size");
253 if (tu_drm_get_gmem_base(device
, &device
->gmem_base
)) {
254 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
255 tu_logi("Could not query the GMEM size");
256 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
257 "could not get GMEM size");
261 memset(device
->name
, 0, sizeof(device
->name
));
262 sprintf(device
->name
, "FD%d", device
->gpu_id
);
264 switch (device
->gpu_id
) {
266 device
->ccu_offset_gmem
= 0x7c000; /* 0x7e000 in some cases? */
267 device
->ccu_offset_bypass
= 0x10000;
268 device
->tile_align_w
= 32;
269 device
->magic
.PC_UNKNOWN_9805
= 0x0;
270 device
->magic
.SP_UNKNOWN_A0F8
= 0x0;
274 device
->ccu_offset_gmem
= 0xf8000;
275 device
->ccu_offset_bypass
= 0x20000;
276 device
->tile_align_w
= 32;
277 device
->magic
.PC_UNKNOWN_9805
= 0x1;
278 device
->magic
.SP_UNKNOWN_A0F8
= 0x1;
281 device
->ccu_offset_gmem
= 0x114000;
282 device
->ccu_offset_bypass
= 0x30000;
283 device
->tile_align_w
= 96;
284 device
->magic
.PC_UNKNOWN_9805
= 0x2;
285 device
->magic
.SP_UNKNOWN_A0F8
= 0x2;
288 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
289 "device %s is unsupported", device
->name
);
292 if (tu_device_get_cache_uuid(device
->gpu_id
, device
->cache_uuid
)) {
293 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
294 "cannot generate UUID");
298 /* The gpu id is already embedded in the uuid so we just pass "tu"
299 * when creating the cache.
301 char buf
[VK_UUID_SIZE
* 2 + 1];
302 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
303 device
->disk_cache
= disk_cache_create(device
->name
, buf
, 0);
305 fprintf(stderr
, "WARNING: tu is not a conformant vulkan implementation, "
306 "testing use only.\n");
308 fd_get_driver_uuid(device
->driver_uuid
);
309 fd_get_device_uuid(device
->device_uuid
, device
->gpu_id
);
311 tu_physical_device_get_supported_extensions(device
, &device
->supported_extensions
);
313 if (result
!= VK_SUCCESS
) {
314 vk_error(instance
, result
);
318 result
= tu_wsi_init(device
);
319 if (result
!= VK_SUCCESS
) {
320 vk_error(instance
, result
);
334 tu_physical_device_finish(struct tu_physical_device
*device
)
336 tu_wsi_finish(device
);
338 disk_cache_destroy(device
->disk_cache
);
339 close(device
->local_fd
);
340 if (device
->master_fd
!= -1)
341 close(device
->master_fd
);
343 vk_object_base_finish(&device
->base
);
346 static VKAPI_ATTR
void *
347 default_alloc_func(void *pUserData
,
350 VkSystemAllocationScope allocationScope
)
355 static VKAPI_ATTR
void *
356 default_realloc_func(void *pUserData
,
360 VkSystemAllocationScope allocationScope
)
362 return realloc(pOriginal
, size
);
365 static VKAPI_ATTR
void
366 default_free_func(void *pUserData
, void *pMemory
)
371 static const VkAllocationCallbacks default_alloc
= {
373 .pfnAllocation
= default_alloc_func
,
374 .pfnReallocation
= default_realloc_func
,
375 .pfnFree
= default_free_func
,
378 static const struct debug_control tu_debug_options
[] = {
379 { "startup", TU_DEBUG_STARTUP
},
380 { "nir", TU_DEBUG_NIR
},
381 { "ir3", TU_DEBUG_IR3
},
382 { "nobin", TU_DEBUG_NOBIN
},
383 { "sysmem", TU_DEBUG_SYSMEM
},
384 { "forcebin", TU_DEBUG_FORCEBIN
},
385 { "noubwc", TU_DEBUG_NOUBWC
},
390 tu_get_debug_option_name(int id
)
392 assert(id
< ARRAY_SIZE(tu_debug_options
) - 1);
393 return tu_debug_options
[id
].string
;
397 tu_get_instance_extension_index(const char *name
)
399 for (unsigned i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; ++i
) {
400 if (strcmp(name
, tu_instance_extensions
[i
].extensionName
) == 0)
407 tu_CreateInstance(const VkInstanceCreateInfo
*pCreateInfo
,
408 const VkAllocationCallbacks
*pAllocator
,
409 VkInstance
*pInstance
)
411 struct tu_instance
*instance
;
414 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
416 uint32_t client_version
;
417 if (pCreateInfo
->pApplicationInfo
&&
418 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
419 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
421 tu_EnumerateInstanceVersion(&client_version
);
424 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
425 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
428 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
430 vk_object_base_init(NULL
, &instance
->base
, VK_OBJECT_TYPE_INSTANCE
);
433 instance
->alloc
= *pAllocator
;
435 instance
->alloc
= default_alloc
;
437 instance
->api_version
= client_version
;
438 instance
->physical_device_count
= -1;
440 instance
->debug_flags
=
441 parse_debug_string(getenv("TU_DEBUG"), tu_debug_options
);
443 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
444 tu_logi("Created an instance");
446 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
447 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
448 int index
= tu_get_instance_extension_index(ext_name
);
450 if (index
< 0 || !tu_instance_extensions_supported
.extensions
[index
]) {
451 vk_object_base_finish(&instance
->base
);
452 vk_free2(&default_alloc
, pAllocator
, instance
);
453 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
456 instance
->enabled_extensions
.extensions
[index
] = true;
459 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
460 if (result
!= VK_SUCCESS
) {
461 vk_object_base_finish(&instance
->base
);
462 vk_free2(&default_alloc
, pAllocator
, instance
);
463 return vk_error(instance
, result
);
466 glsl_type_singleton_init_or_ref();
468 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
470 *pInstance
= tu_instance_to_handle(instance
);
476 tu_DestroyInstance(VkInstance _instance
,
477 const VkAllocationCallbacks
*pAllocator
)
479 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
484 for (int i
= 0; i
< instance
->physical_device_count
; ++i
) {
485 tu_physical_device_finish(instance
->physical_devices
+ i
);
488 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
490 glsl_type_singleton_decref();
492 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
494 vk_object_base_finish(&instance
->base
);
495 vk_free(&instance
->alloc
, instance
);
499 tu_enumerate_devices(struct tu_instance
*instance
)
501 /* TODO: Check for more devices ? */
502 drmDevicePtr devices
[8];
503 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
506 instance
->physical_device_count
= 0;
508 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
510 if (instance
->debug_flags
& TU_DEBUG_STARTUP
) {
512 tu_logi("drmGetDevices2 returned error: %s\n", strerror(max_devices
));
514 tu_logi("Found %d drm nodes", max_devices
);
518 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
520 for (unsigned i
= 0; i
< (unsigned) max_devices
; i
++) {
521 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
522 devices
[i
]->bustype
== DRM_BUS_PLATFORM
) {
524 result
= tu_physical_device_init(
525 instance
->physical_devices
+ instance
->physical_device_count
,
526 instance
, devices
[i
]);
527 if (result
== VK_SUCCESS
)
528 ++instance
->physical_device_count
;
529 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
533 drmFreeDevices(devices
, max_devices
);
539 tu_EnumeratePhysicalDevices(VkInstance _instance
,
540 uint32_t *pPhysicalDeviceCount
,
541 VkPhysicalDevice
*pPhysicalDevices
)
543 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
544 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
548 if (instance
->physical_device_count
< 0) {
549 result
= tu_enumerate_devices(instance
);
550 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
554 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
555 vk_outarray_append(&out
, p
)
557 *p
= tu_physical_device_to_handle(instance
->physical_devices
+ i
);
561 return vk_outarray_status(&out
);
565 tu_EnumeratePhysicalDeviceGroups(
566 VkInstance _instance
,
567 uint32_t *pPhysicalDeviceGroupCount
,
568 VkPhysicalDeviceGroupProperties
*pPhysicalDeviceGroupProperties
)
570 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
571 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
572 pPhysicalDeviceGroupCount
);
575 if (instance
->physical_device_count
< 0) {
576 result
= tu_enumerate_devices(instance
);
577 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
581 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
582 vk_outarray_append(&out
, p
)
584 p
->physicalDeviceCount
= 1;
585 p
->physicalDevices
[0] =
586 tu_physical_device_to_handle(instance
->physical_devices
+ i
);
587 p
->subsetAllocation
= false;
591 return vk_outarray_status(&out
);
595 tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice
,
596 VkPhysicalDeviceFeatures
*pFeatures
)
598 memset(pFeatures
, 0, sizeof(*pFeatures
));
600 *pFeatures
= (VkPhysicalDeviceFeatures
) {
601 .robustBufferAccess
= true,
602 .fullDrawIndexUint32
= true,
603 .imageCubeArray
= true,
604 .independentBlend
= true,
605 .geometryShader
= true,
606 .tessellationShader
= true,
607 .sampleRateShading
= true,
608 .dualSrcBlend
= true,
610 .multiDrawIndirect
= true,
611 .drawIndirectFirstInstance
= true,
613 .depthBiasClamp
= true,
614 .fillModeNonSolid
= true,
619 .multiViewport
= false,
620 .samplerAnisotropy
= true,
621 .textureCompressionETC2
= true,
622 .textureCompressionASTC_LDR
= true,
623 .textureCompressionBC
= true,
624 .occlusionQueryPrecise
= true,
625 .pipelineStatisticsQuery
= false,
626 .vertexPipelineStoresAndAtomics
= false,
627 .fragmentStoresAndAtomics
= false,
628 .shaderTessellationAndGeometryPointSize
= false,
629 .shaderImageGatherExtended
= false,
630 .shaderStorageImageExtendedFormats
= false,
631 .shaderStorageImageMultisample
= false,
632 .shaderUniformBufferArrayDynamicIndexing
= false,
633 .shaderSampledImageArrayDynamicIndexing
= false,
634 .shaderStorageBufferArrayDynamicIndexing
= false,
635 .shaderStorageImageArrayDynamicIndexing
= false,
636 .shaderStorageImageReadWithoutFormat
= false,
637 .shaderStorageImageWriteWithoutFormat
= false,
638 .shaderClipDistance
= false,
639 .shaderCullDistance
= false,
640 .shaderFloat64
= false,
641 .shaderInt64
= false,
642 .shaderInt16
= false,
643 .sparseBinding
= false,
644 .variableMultisampleRate
= false,
645 .inheritedQueries
= false,
650 tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice
,
651 VkPhysicalDeviceFeatures2
*pFeatures
)
653 vk_foreach_struct(ext
, pFeatures
->pNext
)
655 switch (ext
->sType
) {
656 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
: {
657 VkPhysicalDeviceVulkan11Features
*features
= (void *) ext
;
658 features
->storageBuffer16BitAccess
= false;
659 features
->uniformAndStorageBuffer16BitAccess
= false;
660 features
->storagePushConstant16
= false;
661 features
->storageInputOutput16
= false;
662 features
->multiview
= false;
663 features
->multiviewGeometryShader
= false;
664 features
->multiviewTessellationShader
= false;
665 features
->variablePointersStorageBuffer
= true;
666 features
->variablePointers
= true;
667 features
->protectedMemory
= false;
668 features
->samplerYcbcrConversion
= true;
669 features
->shaderDrawParameters
= true;
672 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
673 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *) ext
;
674 features
->variablePointersStorageBuffer
= true;
675 features
->variablePointers
= true;
678 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
679 VkPhysicalDeviceMultiviewFeatures
*features
=
680 (VkPhysicalDeviceMultiviewFeatures
*) ext
;
681 features
->multiview
= false;
682 features
->multiviewGeometryShader
= false;
683 features
->multiviewTessellationShader
= false;
686 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
687 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
688 (VkPhysicalDeviceShaderDrawParametersFeatures
*) ext
;
689 features
->shaderDrawParameters
= true;
692 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
693 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
694 (VkPhysicalDeviceProtectedMemoryFeatures
*) ext
;
695 features
->protectedMemory
= false;
698 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
699 VkPhysicalDevice16BitStorageFeatures
*features
=
700 (VkPhysicalDevice16BitStorageFeatures
*) ext
;
701 features
->storageBuffer16BitAccess
= false;
702 features
->uniformAndStorageBuffer16BitAccess
= false;
703 features
->storagePushConstant16
= false;
704 features
->storageInputOutput16
= false;
707 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
708 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
709 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
710 features
->samplerYcbcrConversion
= true;
713 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
714 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
715 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*) ext
;
716 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
717 features
->shaderUniformTexelBufferArrayDynamicIndexing
= false;
718 features
->shaderStorageTexelBufferArrayDynamicIndexing
= false;
719 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
720 features
->shaderSampledImageArrayNonUniformIndexing
= false;
721 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
722 features
->shaderStorageImageArrayNonUniformIndexing
= false;
723 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
724 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
725 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
726 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
727 features
->descriptorBindingSampledImageUpdateAfterBind
= false;
728 features
->descriptorBindingStorageImageUpdateAfterBind
= false;
729 features
->descriptorBindingStorageBufferUpdateAfterBind
= false;
730 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= false;
731 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= false;
732 features
->descriptorBindingUpdateUnusedWhilePending
= false;
733 features
->descriptorBindingPartiallyBound
= false;
734 features
->descriptorBindingVariableDescriptorCount
= false;
735 features
->runtimeDescriptorArray
= false;
738 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
739 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
740 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*) ext
;
741 features
->conditionalRendering
= false;
742 features
->inheritedConditionalRendering
= false;
745 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
746 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
747 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*) ext
;
748 features
->transformFeedback
= true;
749 features
->geometryStreams
= false;
752 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
753 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
754 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
755 features
->indexTypeUint8
= true;
758 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
759 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
760 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
761 features
->vertexAttributeInstanceRateDivisor
= true;
762 features
->vertexAttributeInstanceRateZeroDivisor
= true;
765 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT
: {
766 VkPhysicalDevicePrivateDataFeaturesEXT
*features
=
767 (VkPhysicalDevicePrivateDataFeaturesEXT
*)ext
;
768 features
->privateData
= true;
771 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
772 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
773 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
774 features
->depthClipEnable
= true;
781 return tu_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
785 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
786 VkPhysicalDeviceProperties
*pProperties
)
788 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
789 VkSampleCountFlags sample_counts
=
790 VK_SAMPLE_COUNT_1_BIT
| VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
;
792 /* I have no idea what the maximum size is, but the hardware supports very
793 * large numbers of descriptors (at least 2^16). This limit is based on
794 * CP_LOAD_STATE6, which has a 28-bit field for the DWORD offset, so that
795 * we don't have to think about what to do if that overflows, but really
796 * nothing is likely to get close to this.
798 const size_t max_descriptor_set_size
= (1 << 28) / A6XX_TEX_CONST_DWORDS
;
800 VkPhysicalDeviceLimits limits
= {
801 .maxImageDimension1D
= (1 << 14),
802 .maxImageDimension2D
= (1 << 14),
803 .maxImageDimension3D
= (1 << 11),
804 .maxImageDimensionCube
= (1 << 14),
805 .maxImageArrayLayers
= (1 << 11),
806 .maxTexelBufferElements
= 128 * 1024 * 1024,
807 .maxUniformBufferRange
= MAX_UNIFORM_BUFFER_RANGE
,
808 .maxStorageBufferRange
= MAX_STORAGE_BUFFER_RANGE
,
809 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
810 .maxMemoryAllocationCount
= UINT32_MAX
,
811 .maxSamplerAllocationCount
= 64 * 1024,
812 .bufferImageGranularity
= 64, /* A cache line */
813 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
814 .maxBoundDescriptorSets
= MAX_SETS
,
815 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
816 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
817 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
818 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
819 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
820 .maxPerStageDescriptorInputAttachments
= MAX_RTS
,
821 .maxPerStageResources
= max_descriptor_set_size
,
822 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
823 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
824 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
825 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
826 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
827 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
828 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
829 .maxDescriptorSetInputAttachments
= MAX_RTS
,
830 .maxVertexInputAttributes
= 32,
831 .maxVertexInputBindings
= 32,
832 .maxVertexInputAttributeOffset
= 4095,
833 .maxVertexInputBindingStride
= 2048,
834 .maxVertexOutputComponents
= 128,
835 .maxTessellationGenerationLevel
= 64,
836 .maxTessellationPatchSize
= 32,
837 .maxTessellationControlPerVertexInputComponents
= 128,
838 .maxTessellationControlPerVertexOutputComponents
= 128,
839 .maxTessellationControlPerPatchOutputComponents
= 120,
840 .maxTessellationControlTotalOutputComponents
= 4096,
841 .maxTessellationEvaluationInputComponents
= 128,
842 .maxTessellationEvaluationOutputComponents
= 128,
843 .maxGeometryShaderInvocations
= 32,
844 .maxGeometryInputComponents
= 64,
845 .maxGeometryOutputComponents
= 128,
846 .maxGeometryOutputVertices
= 256,
847 .maxGeometryTotalOutputComponents
= 1024,
848 .maxFragmentInputComponents
= 124,
849 .maxFragmentOutputAttachments
= 8,
850 .maxFragmentDualSrcAttachments
= 1,
851 .maxFragmentCombinedOutputResources
= 8,
852 .maxComputeSharedMemorySize
= 32768,
853 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
854 .maxComputeWorkGroupInvocations
= 2048,
855 .maxComputeWorkGroupSize
= { 2048, 2048, 2048 },
856 .subPixelPrecisionBits
= 8,
857 .subTexelPrecisionBits
= 8,
858 .mipmapPrecisionBits
= 8,
859 .maxDrawIndexedIndexValue
= UINT32_MAX
,
860 .maxDrawIndirectCount
= UINT32_MAX
,
861 .maxSamplerLodBias
= 4095.0 / 256.0, /* [-16, 15.99609375] */
862 .maxSamplerAnisotropy
= 16,
863 .maxViewports
= MAX_VIEWPORTS
,
864 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
865 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
866 .viewportSubPixelBits
= 8,
867 .minMemoryMapAlignment
= 4096, /* A page */
868 .minTexelBufferOffsetAlignment
= 64,
869 .minUniformBufferOffsetAlignment
= 64,
870 .minStorageBufferOffsetAlignment
= 64,
871 .minTexelOffset
= -16,
872 .maxTexelOffset
= 15,
873 .minTexelGatherOffset
= -32,
874 .maxTexelGatherOffset
= 31,
875 .minInterpolationOffset
= -0.5,
876 .maxInterpolationOffset
= 0.4375,
877 .subPixelInterpolationOffsetBits
= 4,
878 .maxFramebufferWidth
= (1 << 14),
879 .maxFramebufferHeight
= (1 << 14),
880 .maxFramebufferLayers
= (1 << 10),
881 .framebufferColorSampleCounts
= sample_counts
,
882 .framebufferDepthSampleCounts
= sample_counts
,
883 .framebufferStencilSampleCounts
= sample_counts
,
884 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
885 .maxColorAttachments
= MAX_RTS
,
886 .sampledImageColorSampleCounts
= sample_counts
,
887 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
888 .sampledImageDepthSampleCounts
= sample_counts
,
889 .sampledImageStencilSampleCounts
= sample_counts
,
890 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
891 .maxSampleMaskWords
= 1,
892 .timestampComputeAndGraphics
= true,
893 .timestampPeriod
= 1000000000.0 / 19200000.0, /* CP_ALWAYS_ON_COUNTER is fixed 19.2MHz */
894 .maxClipDistances
= 8,
895 .maxCullDistances
= 8,
896 .maxCombinedClipAndCullDistances
= 8,
897 .discreteQueuePriorities
= 1,
898 .pointSizeRange
= { 1, 4092 },
899 .lineWidthRange
= { 0.0, 7.9921875 },
900 .pointSizeGranularity
= 0.0625,
901 .lineWidthGranularity
= (1.0 / 128.0),
902 .strictLines
= false, /* FINISHME */
903 .standardSampleLocations
= true,
904 .optimalBufferCopyOffsetAlignment
= 128,
905 .optimalBufferCopyRowPitchAlignment
= 128,
906 .nonCoherentAtomSize
= 64,
909 *pProperties
= (VkPhysicalDeviceProperties
) {
910 .apiVersion
= tu_physical_device_api_version(pdevice
),
911 .driverVersion
= vk_get_driver_version(),
912 .vendorID
= 0, /* TODO */
914 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
916 .sparseProperties
= { 0 },
919 strcpy(pProperties
->deviceName
, pdevice
->name
);
920 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
924 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice
,
925 VkPhysicalDeviceProperties2
*pProperties
)
927 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
928 tu_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
930 vk_foreach_struct(ext
, pProperties
->pNext
)
932 switch (ext
->sType
) {
933 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
934 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
935 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
936 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
939 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
940 VkPhysicalDeviceIDProperties
*properties
=
941 (VkPhysicalDeviceIDProperties
*) ext
;
942 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
943 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
944 properties
->deviceLUIDValid
= false;
947 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
948 VkPhysicalDeviceMultiviewProperties
*properties
=
949 (VkPhysicalDeviceMultiviewProperties
*) ext
;
950 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
951 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
954 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
955 VkPhysicalDevicePointClippingProperties
*properties
=
956 (VkPhysicalDevicePointClippingProperties
*) ext
;
957 properties
->pointClippingBehavior
=
958 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
961 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
962 VkPhysicalDeviceMaintenance3Properties
*properties
=
963 (VkPhysicalDeviceMaintenance3Properties
*) ext
;
964 /* Make sure everything is addressable by a signed 32-bit int, and
965 * our largest descriptors are 96 bytes. */
966 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
967 /* Our buffer size fields allow only this much */
968 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
972 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
973 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
975 properties
->maxTransformFeedbackStreams
= IR3_MAX_SO_STREAMS
;
976 properties
->maxTransformFeedbackBuffers
= IR3_MAX_SO_BUFFERS
;
977 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
978 properties
->maxTransformFeedbackStreamDataSize
= 512;
979 properties
->maxTransformFeedbackBufferDataSize
= 512;
980 properties
->maxTransformFeedbackBufferDataStride
= 512;
981 properties
->transformFeedbackQueries
= true;
982 properties
->transformFeedbackStreamsLinesTriangles
= false;
983 properties
->transformFeedbackRasterizationStreamSelect
= false;
984 properties
->transformFeedbackDraw
= true;
987 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
988 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
989 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
990 properties
->sampleLocationSampleCounts
= 0;
991 if (pdevice
->supported_extensions
.EXT_sample_locations
) {
992 properties
->sampleLocationSampleCounts
=
993 VK_SAMPLE_COUNT_1_BIT
| VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
;
995 properties
->maxSampleLocationGridSize
= (VkExtent2D
) { 1 , 1 };
996 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
997 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
998 properties
->sampleLocationSubPixelBits
= 4;
999 properties
->variableSampleLocations
= true;
1002 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES
: {
1003 VkPhysicalDeviceSamplerFilterMinmaxProperties
*properties
=
1004 (VkPhysicalDeviceSamplerFilterMinmaxProperties
*)ext
;
1005 properties
->filterMinmaxImageComponentMapping
= true;
1006 properties
->filterMinmaxSingleComponentFormats
= true;
1009 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1010 VkPhysicalDeviceSubgroupProperties
*properties
=
1011 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1012 properties
->subgroupSize
= 64;
1013 properties
->supportedStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1014 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1015 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1016 properties
->quadOperationsInAllStages
= false;
1019 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1020 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
1021 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1022 props
->maxVertexAttribDivisor
= UINT32_MAX
;
1031 static const VkQueueFamilyProperties tu_queue_family_properties
= {
1033 VK_QUEUE_GRAPHICS_BIT
| VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
1035 .timestampValidBits
= 48,
1036 .minImageTransferGranularity
= { 1, 1, 1 },
1040 tu_GetPhysicalDeviceQueueFamilyProperties(
1041 VkPhysicalDevice physicalDevice
,
1042 uint32_t *pQueueFamilyPropertyCount
,
1043 VkQueueFamilyProperties
*pQueueFamilyProperties
)
1045 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1047 vk_outarray_append(&out
, p
) { *p
= tu_queue_family_properties
; }
1051 tu_GetPhysicalDeviceQueueFamilyProperties2(
1052 VkPhysicalDevice physicalDevice
,
1053 uint32_t *pQueueFamilyPropertyCount
,
1054 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1056 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1058 vk_outarray_append(&out
, p
)
1060 p
->queueFamilyProperties
= tu_queue_family_properties
;
1065 tu_get_system_heap_size()
1067 struct sysinfo info
;
1070 uint64_t total_ram
= (uint64_t) info
.totalram
* (uint64_t) info
.mem_unit
;
1072 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
1073 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
1075 uint64_t available_ram
;
1076 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
1077 available_ram
= total_ram
/ 2;
1079 available_ram
= total_ram
* 3 / 4;
1081 return available_ram
;
1085 tu_GetPhysicalDeviceMemoryProperties(
1086 VkPhysicalDevice physicalDevice
,
1087 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1089 pMemoryProperties
->memoryHeapCount
= 1;
1090 pMemoryProperties
->memoryHeaps
[0].size
= tu_get_system_heap_size();
1091 pMemoryProperties
->memoryHeaps
[0].flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
;
1093 pMemoryProperties
->memoryTypeCount
= 1;
1094 pMemoryProperties
->memoryTypes
[0].propertyFlags
=
1095 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
1096 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1097 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
;
1098 pMemoryProperties
->memoryTypes
[0].heapIndex
= 0;
1102 tu_GetPhysicalDeviceMemoryProperties2(
1103 VkPhysicalDevice physicalDevice
,
1104 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1106 return tu_GetPhysicalDeviceMemoryProperties(
1107 physicalDevice
, &pMemoryProperties
->memoryProperties
);
1111 tu_queue_init(struct tu_device
*device
,
1112 struct tu_queue
*queue
,
1113 uint32_t queue_family_index
,
1115 VkDeviceQueueCreateFlags flags
)
1117 vk_object_base_init(&device
->vk
, &queue
->base
, VK_OBJECT_TYPE_QUEUE
);
1119 queue
->device
= device
;
1120 queue
->queue_family_index
= queue_family_index
;
1121 queue
->queue_idx
= idx
;
1122 queue
->flags
= flags
;
1124 int ret
= tu_drm_submitqueue_new(device
, 0, &queue
->msm_queue_id
);
1126 return VK_ERROR_INITIALIZATION_FAILED
;
1128 tu_fence_init(&queue
->submit_fence
, false);
1134 tu_queue_finish(struct tu_queue
*queue
)
1136 tu_fence_finish(&queue
->submit_fence
);
1137 tu_drm_submitqueue_close(queue
->device
, queue
->msm_queue_id
);
1141 tu_get_device_extension_index(const char *name
)
1143 for (unsigned i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; ++i
) {
1144 if (strcmp(name
, tu_device_extensions
[i
].extensionName
) == 0)
1150 struct PACKED bcolor_entry
{
1162 uint32_t z24
; /* also s8? */
1163 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
1165 } border_color
[] = {
1166 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = {},
1167 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = {},
1168 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = {
1169 .fp32
[3] = 0x3f800000,
1177 .rgb10a2
= 0xc0000000,
1180 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = {
1184 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = {
1185 .fp32
[0 ... 3] = 0x3f800000,
1186 .ui16
[0 ... 3] = 0xffff,
1187 .si16
[0 ... 3] = 0x7fff,
1188 .fp16
[0 ... 3] = 0x3c00,
1192 .ui8
[0 ... 3] = 0xff,
1193 .si8
[0 ... 3] = 0x7f,
1194 .rgb10a2
= 0xffffffff,
1196 .srgb
[0 ... 3] = 0x3c00,
1198 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = {
1205 tu_CreateDevice(VkPhysicalDevice physicalDevice
,
1206 const VkDeviceCreateInfo
*pCreateInfo
,
1207 const VkAllocationCallbacks
*pAllocator
,
1210 TU_FROM_HANDLE(tu_physical_device
, physical_device
, physicalDevice
);
1212 struct tu_device
*device
;
1214 /* Check enabled features */
1215 if (pCreateInfo
->pEnabledFeatures
) {
1216 VkPhysicalDeviceFeatures supported_features
;
1217 tu_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1218 VkBool32
*supported_feature
= (VkBool32
*) &supported_features
;
1219 VkBool32
*enabled_feature
= (VkBool32
*) pCreateInfo
->pEnabledFeatures
;
1220 unsigned num_features
=
1221 sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1222 for (uint32_t i
= 0; i
< num_features
; i
++) {
1223 if (enabled_feature
[i
] && !supported_feature
[i
])
1224 return vk_error(physical_device
->instance
,
1225 VK_ERROR_FEATURE_NOT_PRESENT
);
1229 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1230 sizeof(*device
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1232 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1234 vk_device_init(&device
->vk
, pCreateInfo
,
1235 &physical_device
->instance
->alloc
, pAllocator
);
1237 device
->instance
= physical_device
->instance
;
1238 device
->physical_device
= physical_device
;
1239 device
->_lost
= false;
1241 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1242 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1243 int index
= tu_get_device_extension_index(ext_name
);
1245 !physical_device
->supported_extensions
.extensions
[index
]) {
1246 vk_free(&device
->vk
.alloc
, device
);
1247 return vk_error(physical_device
->instance
,
1248 VK_ERROR_EXTENSION_NOT_PRESENT
);
1251 device
->enabled_extensions
.extensions
[index
] = true;
1254 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1255 const VkDeviceQueueCreateInfo
*queue_create
=
1256 &pCreateInfo
->pQueueCreateInfos
[i
];
1257 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1258 device
->queues
[qfi
] = vk_alloc(
1259 &device
->vk
.alloc
, queue_create
->queueCount
* sizeof(struct tu_queue
),
1260 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1261 if (!device
->queues
[qfi
]) {
1262 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1266 memset(device
->queues
[qfi
], 0,
1267 queue_create
->queueCount
* sizeof(struct tu_queue
));
1269 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1271 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1272 result
= tu_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
,
1273 queue_create
->flags
);
1274 if (result
!= VK_SUCCESS
)
1279 device
->compiler
= ir3_compiler_create(NULL
, physical_device
->gpu_id
);
1280 if (!device
->compiler
)
1283 /* initial sizes, these will increase if there is overflow */
1284 device
->vsc_draw_strm_pitch
= 0x1000 + VSC_PAD
;
1285 device
->vsc_prim_strm_pitch
= 0x4000 + VSC_PAD
;
1287 STATIC_ASSERT(sizeof(border_color
) == sizeof(((struct tu6_global
*) 0)->border_color
));
1288 result
= tu_bo_init_new(device
, &device
->global_bo
, sizeof(struct tu6_global
));
1289 if (result
!= VK_SUCCESS
)
1290 goto fail_global_bo
;
1292 result
= tu_bo_map(device
, &device
->global_bo
);
1293 if (result
!= VK_SUCCESS
)
1294 goto fail_global_bo_map
;
1296 memcpy(device
->global_bo
.map
+ gb_offset(border_color
), border_color
, sizeof(border_color
));
1297 tu_init_clear_blit_shaders(device
->global_bo
.map
);
1299 VkPipelineCacheCreateInfo ci
;
1300 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1303 ci
.pInitialData
= NULL
;
1304 ci
.initialDataSize
= 0;
1307 tu_CreatePipelineCache(tu_device_to_handle(device
), &ci
, NULL
, &pc
);
1308 if (result
!= VK_SUCCESS
)
1309 goto fail_pipeline_cache
;
1311 device
->mem_cache
= tu_pipeline_cache_from_handle(pc
);
1313 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->scratch_bos
); i
++)
1314 mtx_init(&device
->scratch_bos
[i
].construct_mtx
, mtx_plain
);
1316 mtx_init(&device
->vsc_pitch_mtx
, mtx_plain
);
1318 *pDevice
= tu_device_to_handle(device
);
1321 fail_pipeline_cache
:
1323 tu_bo_finish(device
, &device
->global_bo
);
1326 ralloc_free(device
->compiler
);
1329 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1330 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1331 tu_queue_finish(&device
->queues
[i
][q
]);
1332 if (device
->queue_count
[i
])
1333 vk_object_free(&device
->vk
, NULL
, device
->queues
[i
]);
1336 vk_free(&device
->vk
.alloc
, device
);
1341 tu_DestroyDevice(VkDevice _device
, const VkAllocationCallbacks
*pAllocator
)
1343 TU_FROM_HANDLE(tu_device
, device
, _device
);
1348 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1349 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1350 tu_queue_finish(&device
->queues
[i
][q
]);
1351 if (device
->queue_count
[i
])
1352 vk_object_free(&device
->vk
, NULL
, device
->queues
[i
]);
1355 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->scratch_bos
); i
++) {
1356 if (device
->scratch_bos
[i
].initialized
)
1357 tu_bo_finish(device
, &device
->scratch_bos
[i
].bo
);
1360 ir3_compiler_destroy(device
->compiler
);
1362 VkPipelineCache pc
= tu_pipeline_cache_to_handle(device
->mem_cache
);
1363 tu_DestroyPipelineCache(tu_device_to_handle(device
), pc
, NULL
);
1365 vk_free(&device
->vk
.alloc
, device
);
1369 _tu_device_set_lost(struct tu_device
*device
,
1370 const char *file
, int line
,
1371 const char *msg
, ...)
1373 /* Set the flag indicating that waits should return in finite time even
1374 * after device loss.
1376 p_atomic_inc(&device
->_lost
);
1378 /* TODO: Report the log message through VkDebugReportCallbackEXT instead */
1379 fprintf(stderr
, "%s:%d: ", file
, line
);
1382 vfprintf(stderr
, msg
, ap
);
1385 if (env_var_as_boolean("TU_ABORT_ON_DEVICE_LOSS", false))
1388 return VK_ERROR_DEVICE_LOST
;
1392 tu_get_scratch_bo(struct tu_device
*dev
, uint64_t size
, struct tu_bo
**bo
)
1394 unsigned size_log2
= MAX2(util_logbase2_ceil64(size
), MIN_SCRATCH_BO_SIZE_LOG2
);
1395 unsigned index
= size_log2
- MIN_SCRATCH_BO_SIZE_LOG2
;
1396 assert(index
< ARRAY_SIZE(dev
->scratch_bos
));
1398 for (unsigned i
= index
; i
< ARRAY_SIZE(dev
->scratch_bos
); i
++) {
1399 if (p_atomic_read(&dev
->scratch_bos
[i
].initialized
)) {
1400 /* Fast path: just return the already-allocated BO. */
1401 *bo
= &dev
->scratch_bos
[i
].bo
;
1406 /* Slow path: actually allocate the BO. We take a lock because the process
1407 * of allocating it is slow, and we don't want to block the CPU while it
1410 mtx_lock(&dev
->scratch_bos
[index
].construct_mtx
);
1412 /* Another thread may have allocated it already while we were waiting on
1413 * the lock. We need to check this in order to avoid double-allocating.
1415 if (dev
->scratch_bos
[index
].initialized
) {
1416 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1417 *bo
= &dev
->scratch_bos
[index
].bo
;
1421 unsigned bo_size
= 1ull << size_log2
;
1422 VkResult result
= tu_bo_init_new(dev
, &dev
->scratch_bos
[index
].bo
, bo_size
);
1423 if (result
!= VK_SUCCESS
) {
1424 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1428 p_atomic_set(&dev
->scratch_bos
[index
].initialized
, true);
1430 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1432 *bo
= &dev
->scratch_bos
[index
].bo
;
1437 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount
,
1438 VkLayerProperties
*pProperties
)
1440 *pPropertyCount
= 0;
1445 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice
,
1446 uint32_t *pPropertyCount
,
1447 VkLayerProperties
*pProperties
)
1449 *pPropertyCount
= 0;
1454 tu_GetDeviceQueue2(VkDevice _device
,
1455 const VkDeviceQueueInfo2
*pQueueInfo
,
1458 TU_FROM_HANDLE(tu_device
, device
, _device
);
1459 struct tu_queue
*queue
;
1462 &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1463 if (pQueueInfo
->flags
!= queue
->flags
) {
1464 /* From the Vulkan 1.1.70 spec:
1466 * "The queue returned by vkGetDeviceQueue2 must have the same
1467 * flags value from this structure as that used at device
1468 * creation time in a VkDeviceQueueCreateInfo instance. If no
1469 * matching flags were specified at device creation time then
1470 * pQueue will return VK_NULL_HANDLE."
1472 *pQueue
= VK_NULL_HANDLE
;
1476 *pQueue
= tu_queue_to_handle(queue
);
1480 tu_GetDeviceQueue(VkDevice _device
,
1481 uint32_t queueFamilyIndex
,
1482 uint32_t queueIndex
,
1485 const VkDeviceQueueInfo2 info
=
1486 (VkDeviceQueueInfo2
) { .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1487 .queueFamilyIndex
= queueFamilyIndex
,
1488 .queueIndex
= queueIndex
};
1490 tu_GetDeviceQueue2(_device
, &info
, pQueue
);
1494 tu_get_semaphore_syncobjs(const VkSemaphore
*sems
,
1497 struct drm_msm_gem_submit_syncobj
**out
,
1498 uint32_t *out_count
)
1500 uint32_t syncobj_count
= 0;
1501 struct drm_msm_gem_submit_syncobj
*syncobjs
;
1503 for (uint32_t i
= 0; i
< sem_count
; ++i
) {
1504 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1506 struct tu_semaphore_part
*part
=
1507 sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
?
1508 &sem
->temporary
: &sem
->permanent
;
1510 if (part
->kind
== TU_SEMAPHORE_SYNCOBJ
)
1515 *out_count
= syncobj_count
;
1519 *out
= syncobjs
= calloc(syncobj_count
, sizeof (*syncobjs
));
1521 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1523 for (uint32_t i
= 0, j
= 0; i
< sem_count
; ++i
) {
1524 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1526 struct tu_semaphore_part
*part
=
1527 sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
?
1528 &sem
->temporary
: &sem
->permanent
;
1530 if (part
->kind
== TU_SEMAPHORE_SYNCOBJ
) {
1531 syncobjs
[j
].handle
= part
->syncobj
;
1532 syncobjs
[j
].flags
= wait
? MSM_SUBMIT_SYNCOBJ_RESET
: 0;
1542 tu_semaphores_remove_temp(struct tu_device
*device
,
1543 const VkSemaphore
*sems
,
1546 for (uint32_t i
= 0; i
< sem_count
; ++i
) {
1547 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1548 tu_semaphore_remove_temp(device
, sem
);
1553 tu_QueueSubmit(VkQueue _queue
,
1554 uint32_t submitCount
,
1555 const VkSubmitInfo
*pSubmits
,
1558 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1561 for (uint32_t i
= 0; i
< submitCount
; ++i
) {
1562 const VkSubmitInfo
*submit
= pSubmits
+ i
;
1563 const bool last_submit
= (i
== submitCount
- 1);
1564 struct drm_msm_gem_submit_syncobj
*in_syncobjs
= NULL
, *out_syncobjs
= NULL
;
1565 uint32_t nr_in_syncobjs
, nr_out_syncobjs
;
1566 struct tu_bo_list bo_list
;
1567 tu_bo_list_init(&bo_list
);
1569 result
= tu_get_semaphore_syncobjs(pSubmits
[i
].pWaitSemaphores
,
1570 pSubmits
[i
].waitSemaphoreCount
,
1571 false, &in_syncobjs
, &nr_in_syncobjs
);
1572 if (result
!= VK_SUCCESS
) {
1573 return tu_device_set_lost(queue
->device
,
1574 "failed to allocate space for semaphore submission\n");
1577 result
= tu_get_semaphore_syncobjs(pSubmits
[i
].pSignalSemaphores
,
1578 pSubmits
[i
].signalSemaphoreCount
,
1579 false, &out_syncobjs
, &nr_out_syncobjs
);
1580 if (result
!= VK_SUCCESS
) {
1582 return tu_device_set_lost(queue
->device
,
1583 "failed to allocate space for semaphore submission\n");
1586 uint32_t entry_count
= 0;
1587 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1588 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1589 entry_count
+= cmdbuf
->cs
.entry_count
;
1592 struct drm_msm_gem_submit_cmd cmds
[entry_count
];
1593 uint32_t entry_idx
= 0;
1594 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1595 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1596 struct tu_cs
*cs
= &cmdbuf
->cs
;
1597 for (unsigned i
= 0; i
< cs
->entry_count
; ++i
, ++entry_idx
) {
1598 cmds
[entry_idx
].type
= MSM_SUBMIT_CMD_BUF
;
1599 cmds
[entry_idx
].submit_idx
=
1600 tu_bo_list_add(&bo_list
, cs
->entries
[i
].bo
,
1601 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1602 cmds
[entry_idx
].submit_offset
= cs
->entries
[i
].offset
;
1603 cmds
[entry_idx
].size
= cs
->entries
[i
].size
;
1604 cmds
[entry_idx
].pad
= 0;
1605 cmds
[entry_idx
].nr_relocs
= 0;
1606 cmds
[entry_idx
].relocs
= 0;
1609 tu_bo_list_merge(&bo_list
, &cmdbuf
->bo_list
);
1612 uint32_t flags
= MSM_PIPE_3D0
;
1613 if (nr_in_syncobjs
) {
1614 flags
|= MSM_SUBMIT_SYNCOBJ_IN
;
1616 if (nr_out_syncobjs
) {
1617 flags
|= MSM_SUBMIT_SYNCOBJ_OUT
;
1621 flags
|= MSM_SUBMIT_FENCE_FD_OUT
;
1624 struct drm_msm_gem_submit req
= {
1626 .queueid
= queue
->msm_queue_id
,
1627 .bos
= (uint64_t)(uintptr_t) bo_list
.bo_infos
,
1628 .nr_bos
= bo_list
.count
,
1629 .cmds
= (uint64_t)(uintptr_t)cmds
,
1630 .nr_cmds
= entry_count
,
1631 .in_syncobjs
= (uint64_t)(uintptr_t)in_syncobjs
,
1632 .out_syncobjs
= (uint64_t)(uintptr_t)out_syncobjs
,
1633 .nr_in_syncobjs
= nr_in_syncobjs
,
1634 .nr_out_syncobjs
= nr_out_syncobjs
,
1635 .syncobj_stride
= sizeof(struct drm_msm_gem_submit_syncobj
),
1638 int ret
= drmCommandWriteRead(queue
->device
->physical_device
->local_fd
,
1644 return tu_device_set_lost(queue
->device
, "submit failed: %s\n",
1648 tu_bo_list_destroy(&bo_list
);
1652 tu_semaphores_remove_temp(queue
->device
, pSubmits
[i
].pWaitSemaphores
,
1653 pSubmits
[i
].waitSemaphoreCount
);
1655 /* no need to merge fences as queue execution is serialized */
1656 tu_fence_update_fd(&queue
->submit_fence
, req
.fence_fd
);
1657 } else if (last_submit
) {
1658 close(req
.fence_fd
);
1662 if (_fence
!= VK_NULL_HANDLE
) {
1663 TU_FROM_HANDLE(tu_fence
, fence
, _fence
);
1664 tu_fence_copy(fence
, &queue
->submit_fence
);
1671 tu_QueueWaitIdle(VkQueue _queue
)
1673 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1675 if (tu_device_is_lost(queue
->device
))
1676 return VK_ERROR_DEVICE_LOST
;
1678 tu_fence_wait_idle(&queue
->submit_fence
);
1684 tu_DeviceWaitIdle(VkDevice _device
)
1686 TU_FROM_HANDLE(tu_device
, device
, _device
);
1688 if (tu_device_is_lost(device
))
1689 return VK_ERROR_DEVICE_LOST
;
1691 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1692 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1693 tu_QueueWaitIdle(tu_queue_to_handle(&device
->queues
[i
][q
]));
1700 tu_EnumerateInstanceExtensionProperties(const char *pLayerName
,
1701 uint32_t *pPropertyCount
,
1702 VkExtensionProperties
*pProperties
)
1704 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1706 /* We spport no lyaers */
1708 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1710 for (int i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; i
++) {
1711 if (tu_instance_extensions_supported
.extensions
[i
]) {
1712 vk_outarray_append(&out
, prop
) { *prop
= tu_instance_extensions
[i
]; }
1716 return vk_outarray_status(&out
);
1720 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
1721 const char *pLayerName
,
1722 uint32_t *pPropertyCount
,
1723 VkExtensionProperties
*pProperties
)
1725 /* We spport no lyaers */
1726 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
1727 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1729 /* We spport no lyaers */
1731 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1733 for (int i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; i
++) {
1734 if (device
->supported_extensions
.extensions
[i
]) {
1735 vk_outarray_append(&out
, prop
) { *prop
= tu_device_extensions
[i
]; }
1739 return vk_outarray_status(&out
);
1743 tu_GetInstanceProcAddr(VkInstance _instance
, const char *pName
)
1745 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
1747 return tu_lookup_entrypoint_checked(
1748 pName
, instance
? instance
->api_version
: 0,
1749 instance
? &instance
->enabled_extensions
: NULL
, NULL
);
1752 /* The loader wants us to expose a second GetInstanceProcAddr function
1753 * to work around certain LD_PRELOAD issues seen in apps.
1756 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1757 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
);
1760 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1761 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
)
1763 return tu_GetInstanceProcAddr(instance
, pName
);
1767 tu_GetDeviceProcAddr(VkDevice _device
, const char *pName
)
1769 TU_FROM_HANDLE(tu_device
, device
, _device
);
1771 return tu_lookup_entrypoint_checked(pName
, device
->instance
->api_version
,
1772 &device
->instance
->enabled_extensions
,
1773 &device
->enabled_extensions
);
1777 tu_alloc_memory(struct tu_device
*device
,
1778 const VkMemoryAllocateInfo
*pAllocateInfo
,
1779 const VkAllocationCallbacks
*pAllocator
,
1780 VkDeviceMemory
*pMem
)
1782 struct tu_device_memory
*mem
;
1785 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1787 if (pAllocateInfo
->allocationSize
== 0) {
1788 /* Apparently, this is allowed */
1789 *pMem
= VK_NULL_HANDLE
;
1793 mem
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*mem
),
1794 VK_OBJECT_TYPE_DEVICE_MEMORY
);
1796 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1798 const VkImportMemoryFdInfoKHR
*fd_info
=
1799 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1800 if (fd_info
&& !fd_info
->handleType
)
1804 assert(fd_info
->handleType
==
1805 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1806 fd_info
->handleType
==
1807 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1810 * TODO Importing the same fd twice gives us the same handle without
1811 * reference counting. We need to maintain a per-instance handle-to-bo
1812 * table and add reference count to tu_bo.
1814 result
= tu_bo_init_dmabuf(device
, &mem
->bo
,
1815 pAllocateInfo
->allocationSize
, fd_info
->fd
);
1816 if (result
== VK_SUCCESS
) {
1817 /* take ownership and close the fd */
1822 tu_bo_init_new(device
, &mem
->bo
, pAllocateInfo
->allocationSize
);
1825 if (result
!= VK_SUCCESS
) {
1826 vk_object_free(&device
->vk
, pAllocator
, mem
);
1830 mem
->size
= pAllocateInfo
->allocationSize
;
1831 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1834 mem
->user_ptr
= NULL
;
1836 *pMem
= tu_device_memory_to_handle(mem
);
1842 tu_AllocateMemory(VkDevice _device
,
1843 const VkMemoryAllocateInfo
*pAllocateInfo
,
1844 const VkAllocationCallbacks
*pAllocator
,
1845 VkDeviceMemory
*pMem
)
1847 TU_FROM_HANDLE(tu_device
, device
, _device
);
1848 return tu_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
1852 tu_FreeMemory(VkDevice _device
,
1853 VkDeviceMemory _mem
,
1854 const VkAllocationCallbacks
*pAllocator
)
1856 TU_FROM_HANDLE(tu_device
, device
, _device
);
1857 TU_FROM_HANDLE(tu_device_memory
, mem
, _mem
);
1862 tu_bo_finish(device
, &mem
->bo
);
1863 vk_object_free(&device
->vk
, pAllocator
, mem
);
1867 tu_MapMemory(VkDevice _device
,
1868 VkDeviceMemory _memory
,
1869 VkDeviceSize offset
,
1871 VkMemoryMapFlags flags
,
1874 TU_FROM_HANDLE(tu_device
, device
, _device
);
1875 TU_FROM_HANDLE(tu_device_memory
, mem
, _memory
);
1883 if (mem
->user_ptr
) {
1884 *ppData
= mem
->user_ptr
;
1885 } else if (!mem
->map
) {
1886 result
= tu_bo_map(device
, &mem
->bo
);
1887 if (result
!= VK_SUCCESS
)
1889 *ppData
= mem
->map
= mem
->bo
.map
;
1898 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
1902 tu_UnmapMemory(VkDevice _device
, VkDeviceMemory _memory
)
1904 /* I do not see any unmapping done by the freedreno Gallium driver. */
1908 tu_FlushMappedMemoryRanges(VkDevice _device
,
1909 uint32_t memoryRangeCount
,
1910 const VkMappedMemoryRange
*pMemoryRanges
)
1916 tu_InvalidateMappedMemoryRanges(VkDevice _device
,
1917 uint32_t memoryRangeCount
,
1918 const VkMappedMemoryRange
*pMemoryRanges
)
1924 tu_GetBufferMemoryRequirements(VkDevice _device
,
1926 VkMemoryRequirements
*pMemoryRequirements
)
1928 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1930 pMemoryRequirements
->memoryTypeBits
= 1;
1931 pMemoryRequirements
->alignment
= 64;
1932 pMemoryRequirements
->size
=
1933 align64(buffer
->size
, pMemoryRequirements
->alignment
);
1937 tu_GetBufferMemoryRequirements2(
1939 const VkBufferMemoryRequirementsInfo2
*pInfo
,
1940 VkMemoryRequirements2
*pMemoryRequirements
)
1942 tu_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
1943 &pMemoryRequirements
->memoryRequirements
);
1947 tu_GetImageMemoryRequirements(VkDevice _device
,
1949 VkMemoryRequirements
*pMemoryRequirements
)
1951 TU_FROM_HANDLE(tu_image
, image
, _image
);
1953 pMemoryRequirements
->memoryTypeBits
= 1;
1954 pMemoryRequirements
->size
= image
->total_size
;
1955 pMemoryRequirements
->alignment
= image
->layout
[0].base_align
;
1959 tu_GetImageMemoryRequirements2(VkDevice device
,
1960 const VkImageMemoryRequirementsInfo2
*pInfo
,
1961 VkMemoryRequirements2
*pMemoryRequirements
)
1963 tu_GetImageMemoryRequirements(device
, pInfo
->image
,
1964 &pMemoryRequirements
->memoryRequirements
);
1968 tu_GetImageSparseMemoryRequirements(
1971 uint32_t *pSparseMemoryRequirementCount
,
1972 VkSparseImageMemoryRequirements
*pSparseMemoryRequirements
)
1978 tu_GetImageSparseMemoryRequirements2(
1980 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
1981 uint32_t *pSparseMemoryRequirementCount
,
1982 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
1988 tu_GetDeviceMemoryCommitment(VkDevice device
,
1989 VkDeviceMemory memory
,
1990 VkDeviceSize
*pCommittedMemoryInBytes
)
1992 *pCommittedMemoryInBytes
= 0;
1996 tu_BindBufferMemory2(VkDevice device
,
1997 uint32_t bindInfoCount
,
1998 const VkBindBufferMemoryInfo
*pBindInfos
)
2000 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2001 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
2002 TU_FROM_HANDLE(tu_buffer
, buffer
, pBindInfos
[i
].buffer
);
2005 buffer
->bo
= &mem
->bo
;
2006 buffer
->bo_offset
= pBindInfos
[i
].memoryOffset
;
2015 tu_BindBufferMemory(VkDevice device
,
2017 VkDeviceMemory memory
,
2018 VkDeviceSize memoryOffset
)
2020 const VkBindBufferMemoryInfo info
= {
2021 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2024 .memoryOffset
= memoryOffset
2027 return tu_BindBufferMemory2(device
, 1, &info
);
2031 tu_BindImageMemory2(VkDevice device
,
2032 uint32_t bindInfoCount
,
2033 const VkBindImageMemoryInfo
*pBindInfos
)
2035 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2036 TU_FROM_HANDLE(tu_image
, image
, pBindInfos
[i
].image
);
2037 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
2040 image
->bo
= &mem
->bo
;
2041 image
->bo_offset
= pBindInfos
[i
].memoryOffset
;
2044 image
->bo_offset
= 0;
2052 tu_BindImageMemory(VkDevice device
,
2054 VkDeviceMemory memory
,
2055 VkDeviceSize memoryOffset
)
2057 const VkBindImageMemoryInfo info
= {
2058 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2061 .memoryOffset
= memoryOffset
2064 return tu_BindImageMemory2(device
, 1, &info
);
2068 tu_QueueBindSparse(VkQueue _queue
,
2069 uint32_t bindInfoCount
,
2070 const VkBindSparseInfo
*pBindInfo
,
2076 // Queue semaphore functions
2080 tu_semaphore_part_destroy(struct tu_device
*device
,
2081 struct tu_semaphore_part
*part
)
2083 switch(part
->kind
) {
2084 case TU_SEMAPHORE_NONE
:
2086 case TU_SEMAPHORE_SYNCOBJ
:
2087 drmSyncobjDestroy(device
->physical_device
->local_fd
, part
->syncobj
);
2090 part
->kind
= TU_SEMAPHORE_NONE
;
2094 tu_semaphore_remove_temp(struct tu_device
*device
,
2095 struct tu_semaphore
*sem
)
2097 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2098 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2103 tu_CreateSemaphore(VkDevice _device
,
2104 const VkSemaphoreCreateInfo
*pCreateInfo
,
2105 const VkAllocationCallbacks
*pAllocator
,
2106 VkSemaphore
*pSemaphore
)
2108 TU_FROM_HANDLE(tu_device
, device
, _device
);
2110 struct tu_semaphore
*sem
=
2111 vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*sem
),
2112 VK_OBJECT_TYPE_SEMAPHORE
);
2114 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2116 const VkExportSemaphoreCreateInfo
*export
=
2117 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
2118 VkExternalSemaphoreHandleTypeFlags handleTypes
=
2119 export
? export
->handleTypes
: 0;
2121 sem
->permanent
.kind
= TU_SEMAPHORE_NONE
;
2122 sem
->temporary
.kind
= TU_SEMAPHORE_NONE
;
2125 if (drmSyncobjCreate(device
->physical_device
->local_fd
, 0, &sem
->permanent
.syncobj
) < 0) {
2126 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
2127 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2129 sem
->permanent
.kind
= TU_SEMAPHORE_SYNCOBJ
;
2131 *pSemaphore
= tu_semaphore_to_handle(sem
);
2136 tu_DestroySemaphore(VkDevice _device
,
2137 VkSemaphore _semaphore
,
2138 const VkAllocationCallbacks
*pAllocator
)
2140 TU_FROM_HANDLE(tu_device
, device
, _device
);
2141 TU_FROM_HANDLE(tu_semaphore
, sem
, _semaphore
);
2145 tu_semaphore_part_destroy(device
, &sem
->permanent
);
2146 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2148 vk_object_free(&device
->vk
, pAllocator
, sem
);
2152 tu_CreateEvent(VkDevice _device
,
2153 const VkEventCreateInfo
*pCreateInfo
,
2154 const VkAllocationCallbacks
*pAllocator
,
2157 TU_FROM_HANDLE(tu_device
, device
, _device
);
2159 struct tu_event
*event
=
2160 vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*event
),
2161 VK_OBJECT_TYPE_EVENT
);
2163 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2165 VkResult result
= tu_bo_init_new(device
, &event
->bo
, 0x1000);
2166 if (result
!= VK_SUCCESS
)
2169 result
= tu_bo_map(device
, &event
->bo
);
2170 if (result
!= VK_SUCCESS
)
2173 *pEvent
= tu_event_to_handle(event
);
2178 tu_bo_finish(device
, &event
->bo
);
2180 vk_object_free(&device
->vk
, pAllocator
, event
);
2181 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2185 tu_DestroyEvent(VkDevice _device
,
2187 const VkAllocationCallbacks
*pAllocator
)
2189 TU_FROM_HANDLE(tu_device
, device
, _device
);
2190 TU_FROM_HANDLE(tu_event
, event
, _event
);
2195 tu_bo_finish(device
, &event
->bo
);
2196 vk_object_free(&device
->vk
, pAllocator
, event
);
2200 tu_GetEventStatus(VkDevice _device
, VkEvent _event
)
2202 TU_FROM_HANDLE(tu_event
, event
, _event
);
2204 if (*(uint64_t*) event
->bo
.map
== 1)
2205 return VK_EVENT_SET
;
2206 return VK_EVENT_RESET
;
2210 tu_SetEvent(VkDevice _device
, VkEvent _event
)
2212 TU_FROM_HANDLE(tu_event
, event
, _event
);
2213 *(uint64_t*) event
->bo
.map
= 1;
2219 tu_ResetEvent(VkDevice _device
, VkEvent _event
)
2221 TU_FROM_HANDLE(tu_event
, event
, _event
);
2222 *(uint64_t*) event
->bo
.map
= 0;
2228 tu_CreateBuffer(VkDevice _device
,
2229 const VkBufferCreateInfo
*pCreateInfo
,
2230 const VkAllocationCallbacks
*pAllocator
,
2233 TU_FROM_HANDLE(tu_device
, device
, _device
);
2234 struct tu_buffer
*buffer
;
2236 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2238 buffer
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*buffer
),
2239 VK_OBJECT_TYPE_BUFFER
);
2241 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2243 buffer
->size
= pCreateInfo
->size
;
2244 buffer
->usage
= pCreateInfo
->usage
;
2245 buffer
->flags
= pCreateInfo
->flags
;
2247 *pBuffer
= tu_buffer_to_handle(buffer
);
2253 tu_DestroyBuffer(VkDevice _device
,
2255 const VkAllocationCallbacks
*pAllocator
)
2257 TU_FROM_HANDLE(tu_device
, device
, _device
);
2258 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
2263 vk_object_free(&device
->vk
, pAllocator
, buffer
);
2267 tu_CreateFramebuffer(VkDevice _device
,
2268 const VkFramebufferCreateInfo
*pCreateInfo
,
2269 const VkAllocationCallbacks
*pAllocator
,
2270 VkFramebuffer
*pFramebuffer
)
2272 TU_FROM_HANDLE(tu_device
, device
, _device
);
2273 TU_FROM_HANDLE(tu_render_pass
, pass
, pCreateInfo
->renderPass
);
2274 struct tu_framebuffer
*framebuffer
;
2276 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2278 size_t size
= sizeof(*framebuffer
) + sizeof(struct tu_attachment_info
) *
2279 pCreateInfo
->attachmentCount
;
2280 framebuffer
= vk_object_alloc(&device
->vk
, pAllocator
, size
,
2281 VK_OBJECT_TYPE_FRAMEBUFFER
);
2282 if (framebuffer
== NULL
)
2283 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2285 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2286 framebuffer
->width
= pCreateInfo
->width
;
2287 framebuffer
->height
= pCreateInfo
->height
;
2288 framebuffer
->layers
= pCreateInfo
->layers
;
2289 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2290 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2291 struct tu_image_view
*iview
= tu_image_view_from_handle(_iview
);
2292 framebuffer
->attachments
[i
].attachment
= iview
;
2295 tu_framebuffer_tiling_config(framebuffer
, device
, pass
);
2297 *pFramebuffer
= tu_framebuffer_to_handle(framebuffer
);
2302 tu_DestroyFramebuffer(VkDevice _device
,
2304 const VkAllocationCallbacks
*pAllocator
)
2306 TU_FROM_HANDLE(tu_device
, device
, _device
);
2307 TU_FROM_HANDLE(tu_framebuffer
, fb
, _fb
);
2312 vk_object_free(&device
->vk
, pAllocator
, fb
);
2316 tu_init_sampler(struct tu_device
*device
,
2317 struct tu_sampler
*sampler
,
2318 const VkSamplerCreateInfo
*pCreateInfo
)
2320 const struct VkSamplerReductionModeCreateInfo
*reduction
=
2321 vk_find_struct_const(pCreateInfo
->pNext
, SAMPLER_REDUCTION_MODE_CREATE_INFO
);
2322 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
2323 vk_find_struct_const(pCreateInfo
->pNext
, SAMPLER_YCBCR_CONVERSION_INFO
);
2325 unsigned aniso
= pCreateInfo
->anisotropyEnable
?
2326 util_last_bit(MIN2((uint32_t)pCreateInfo
->maxAnisotropy
>> 1, 8)) : 0;
2327 bool miplinear
= (pCreateInfo
->mipmapMode
== VK_SAMPLER_MIPMAP_MODE_LINEAR
);
2328 float min_lod
= CLAMP(pCreateInfo
->minLod
, 0.0f
, 4095.0f
/ 256.0f
);
2329 float max_lod
= CLAMP(pCreateInfo
->maxLod
, 0.0f
, 4095.0f
/ 256.0f
);
2331 sampler
->descriptor
[0] =
2332 COND(miplinear
, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR
) |
2333 A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo
->magFilter
, aniso
)) |
2334 A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo
->minFilter
, aniso
)) |
2335 A6XX_TEX_SAMP_0_ANISO(aniso
) |
2336 A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo
->addressModeU
)) |
2337 A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo
->addressModeV
)) |
2338 A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo
->addressModeW
)) |
2339 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo
->mipLodBias
);
2340 sampler
->descriptor
[1] =
2341 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
2342 COND(pCreateInfo
->unnormalizedCoordinates
, A6XX_TEX_SAMP_1_UNNORM_COORDS
) |
2343 A6XX_TEX_SAMP_1_MIN_LOD(min_lod
) |
2344 A6XX_TEX_SAMP_1_MAX_LOD(max_lod
) |
2345 COND(pCreateInfo
->compareEnable
,
2346 A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo
->compareOp
)));
2347 /* This is an offset into the border_color BO, which we fill with all the
2348 * possible Vulkan border colors in the correct order, so we can just use
2349 * the Vulkan enum with no translation necessary.
2351 sampler
->descriptor
[2] =
2352 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((unsigned) pCreateInfo
->borderColor
*
2353 sizeof(struct bcolor_entry
));
2354 sampler
->descriptor
[3] = 0;
2357 sampler
->descriptor
[2] |= A6XX_TEX_SAMP_2_REDUCTION_MODE(
2358 tu6_reduction_mode(reduction
->reductionMode
));
2361 sampler
->ycbcr_sampler
= ycbcr_conversion
?
2362 tu_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
) : NULL
;
2364 if (sampler
->ycbcr_sampler
&&
2365 sampler
->ycbcr_sampler
->chroma_filter
== VK_FILTER_LINEAR
) {
2366 sampler
->descriptor
[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR
;
2370 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
2375 tu_CreateSampler(VkDevice _device
,
2376 const VkSamplerCreateInfo
*pCreateInfo
,
2377 const VkAllocationCallbacks
*pAllocator
,
2378 VkSampler
*pSampler
)
2380 TU_FROM_HANDLE(tu_device
, device
, _device
);
2381 struct tu_sampler
*sampler
;
2383 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2385 sampler
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*sampler
),
2386 VK_OBJECT_TYPE_SAMPLER
);
2388 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2390 tu_init_sampler(device
, sampler
, pCreateInfo
);
2391 *pSampler
= tu_sampler_to_handle(sampler
);
2397 tu_DestroySampler(VkDevice _device
,
2399 const VkAllocationCallbacks
*pAllocator
)
2401 TU_FROM_HANDLE(tu_device
, device
, _device
);
2402 TU_FROM_HANDLE(tu_sampler
, sampler
, _sampler
);
2407 vk_object_free(&device
->vk
, pAllocator
, sampler
);
2410 /* vk_icd.h does not declare this function, so we declare it here to
2411 * suppress Wmissing-prototypes.
2413 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2414 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2416 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2417 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2419 /* For the full details on loader interface versioning, see
2420 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2421 * What follows is a condensed summary, to help you navigate the large and
2422 * confusing official doc.
2424 * - Loader interface v0 is incompatible with later versions. We don't
2427 * - In loader interface v1:
2428 * - The first ICD entrypoint called by the loader is
2429 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2431 * - The ICD must statically expose no other Vulkan symbol unless it
2432 * is linked with -Bsymbolic.
2433 * - Each dispatchable Vulkan handle created by the ICD must be
2434 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2435 * ICD must initialize VK_LOADER_DATA.loadMagic to
2437 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2438 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2439 * such loader-managed surfaces.
2441 * - Loader interface v2 differs from v1 in:
2442 * - The first ICD entrypoint called by the loader is
2443 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2444 * statically expose this entrypoint.
2446 * - Loader interface v3 differs from v2 in:
2447 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2448 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2449 * because the loader no longer does so.
2451 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
2456 tu_GetMemoryFdKHR(VkDevice _device
,
2457 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
2460 TU_FROM_HANDLE(tu_device
, device
, _device
);
2461 TU_FROM_HANDLE(tu_device_memory
, memory
, pGetFdInfo
->memory
);
2463 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2465 /* At the moment, we support only the below handle types. */
2466 assert(pGetFdInfo
->handleType
==
2467 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2468 pGetFdInfo
->handleType
==
2469 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2471 int prime_fd
= tu_bo_export_dmabuf(device
, &memory
->bo
);
2473 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2480 tu_GetMemoryFdPropertiesKHR(VkDevice _device
,
2481 VkExternalMemoryHandleTypeFlagBits handleType
,
2483 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
2485 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2486 pMemoryFdProperties
->memoryTypeBits
= 1;
2491 tu_ImportFenceFdKHR(VkDevice _device
,
2492 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
2500 tu_GetFenceFdKHR(VkDevice _device
,
2501 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
2510 tu_ImportSemaphoreFdKHR(VkDevice _device
,
2511 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
2513 TU_FROM_HANDLE(tu_device
, device
, _device
);
2514 TU_FROM_HANDLE(tu_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
2516 struct tu_semaphore_part
*dst
= NULL
;
2518 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
2519 dst
= &sem
->temporary
;
2521 dst
= &sem
->permanent
;
2524 uint32_t syncobj
= dst
->kind
== TU_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
2526 switch(pImportSemaphoreFdInfo
->handleType
) {
2527 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
: {
2528 uint32_t old_syncobj
= syncobj
;
2529 ret
= drmSyncobjFDToHandle(device
->physical_device
->local_fd
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
2531 close(pImportSemaphoreFdInfo
->fd
);
2533 drmSyncobjDestroy(device
->physical_device
->local_fd
, old_syncobj
);
2537 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
: {
2539 ret
= drmSyncobjCreate(device
->physical_device
->local_fd
, 0, &syncobj
);
2543 if (pImportSemaphoreFdInfo
->fd
== -1) {
2544 ret
= drmSyncobjSignal(device
->physical_device
->local_fd
, &syncobj
, 1);
2546 ret
= drmSyncobjImportSyncFile(device
->physical_device
->local_fd
, syncobj
, pImportSemaphoreFdInfo
->fd
);
2549 close(pImportSemaphoreFdInfo
->fd
);
2553 unreachable("Unhandled semaphore handle type");
2557 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
2559 dst
->syncobj
= syncobj
;
2560 dst
->kind
= TU_SEMAPHORE_SYNCOBJ
;
2566 tu_GetSemaphoreFdKHR(VkDevice _device
,
2567 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
2570 TU_FROM_HANDLE(tu_device
, device
, _device
);
2571 TU_FROM_HANDLE(tu_semaphore
, sem
, pGetFdInfo
->semaphore
);
2573 uint32_t syncobj_handle
;
2575 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2576 assert(sem
->temporary
.kind
== TU_SEMAPHORE_SYNCOBJ
);
2577 syncobj_handle
= sem
->temporary
.syncobj
;
2579 assert(sem
->permanent
.kind
== TU_SEMAPHORE_SYNCOBJ
);
2580 syncobj_handle
= sem
->permanent
.syncobj
;
2583 switch(pGetFdInfo
->handleType
) {
2584 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
2585 ret
= drmSyncobjHandleToFD(device
->physical_device
->local_fd
, syncobj_handle
, pFd
);
2587 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
2588 ret
= drmSyncobjExportSyncFile(device
->physical_device
->local_fd
, syncobj_handle
, pFd
);
2590 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2591 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2593 drmSyncobjReset(device
->physical_device
->local_fd
, &syncobj_handle
, 1);
2598 unreachable("Unhandled semaphore handle type");
2602 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2607 static bool tu_has_syncobj(struct tu_physical_device
*pdev
)
2610 if (drmGetCap(pdev
->local_fd
, DRM_CAP_SYNCOBJ
, &value
))
2612 return value
&& pdev
->msm_major_version
== 1 && pdev
->msm_minor_version
>= 6;
2616 tu_GetPhysicalDeviceExternalSemaphoreProperties(
2617 VkPhysicalDevice physicalDevice
,
2618 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
2619 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
2621 TU_FROM_HANDLE(tu_physical_device
, pdev
, physicalDevice
);
2623 if (tu_has_syncobj(pdev
) &&
2624 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
2625 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
2626 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
2627 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
2628 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
2629 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
2631 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
2632 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
2633 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
2638 tu_GetPhysicalDeviceExternalFenceProperties(
2639 VkPhysicalDevice physicalDevice
,
2640 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
2641 VkExternalFenceProperties
*pExternalFenceProperties
)
2643 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
2644 pExternalFenceProperties
->compatibleHandleTypes
= 0;
2645 pExternalFenceProperties
->externalFenceFeatures
= 0;
2649 tu_CreateDebugReportCallbackEXT(
2650 VkInstance _instance
,
2651 const VkDebugReportCallbackCreateInfoEXT
*pCreateInfo
,
2652 const VkAllocationCallbacks
*pAllocator
,
2653 VkDebugReportCallbackEXT
*pCallback
)
2655 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2656 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2657 pCreateInfo
, pAllocator
,
2658 &instance
->alloc
, pCallback
);
2662 tu_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2663 VkDebugReportCallbackEXT _callback
,
2664 const VkAllocationCallbacks
*pAllocator
)
2666 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2667 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2668 _callback
, pAllocator
, &instance
->alloc
);
2672 tu_DebugReportMessageEXT(VkInstance _instance
,
2673 VkDebugReportFlagsEXT flags
,
2674 VkDebugReportObjectTypeEXT objectType
,
2677 int32_t messageCode
,
2678 const char *pLayerPrefix
,
2679 const char *pMessage
)
2681 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2682 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2683 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2687 tu_GetDeviceGroupPeerMemoryFeatures(
2690 uint32_t localDeviceIndex
,
2691 uint32_t remoteDeviceIndex
,
2692 VkPeerMemoryFeatureFlags
*pPeerMemoryFeatures
)
2694 assert(localDeviceIndex
== remoteDeviceIndex
);
2696 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2697 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2698 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2699 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
2702 void tu_GetPhysicalDeviceMultisamplePropertiesEXT(
2703 VkPhysicalDevice physicalDevice
,
2704 VkSampleCountFlagBits samples
,
2705 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
2707 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
2709 if (samples
<= VK_SAMPLE_COUNT_4_BIT
&& pdevice
->supported_extensions
.EXT_sample_locations
)
2710 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 1, 1 };
2712 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };
2717 tu_CreatePrivateDataSlotEXT(VkDevice _device
,
2718 const VkPrivateDataSlotCreateInfoEXT
* pCreateInfo
,
2719 const VkAllocationCallbacks
* pAllocator
,
2720 VkPrivateDataSlotEXT
* pPrivateDataSlot
)
2722 TU_FROM_HANDLE(tu_device
, device
, _device
);
2723 return vk_private_data_slot_create(&device
->vk
,
2730 tu_DestroyPrivateDataSlotEXT(VkDevice _device
,
2731 VkPrivateDataSlotEXT privateDataSlot
,
2732 const VkAllocationCallbacks
* pAllocator
)
2734 TU_FROM_HANDLE(tu_device
, device
, _device
);
2735 vk_private_data_slot_destroy(&device
->vk
, privateDataSlot
, pAllocator
);
2739 tu_SetPrivateDataEXT(VkDevice _device
,
2740 VkObjectType objectType
,
2741 uint64_t objectHandle
,
2742 VkPrivateDataSlotEXT privateDataSlot
,
2745 TU_FROM_HANDLE(tu_device
, device
, _device
);
2746 return vk_object_base_set_private_data(&device
->vk
,
2754 tu_GetPrivateDataEXT(VkDevice _device
,
2755 VkObjectType objectType
,
2756 uint64_t objectHandle
,
2757 VkPrivateDataSlotEXT privateDataSlot
,
2760 TU_FROM_HANDLE(tu_device
, device
, _device
);
2761 vk_object_base_get_private_data(&device
->vk
,