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
= 64;
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
= 64;
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;
769 return tu_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
773 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
774 VkPhysicalDeviceProperties
*pProperties
)
776 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
777 VkSampleCountFlags sample_counts
=
778 VK_SAMPLE_COUNT_1_BIT
| VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
;
780 /* I have no idea what the maximum size is, but the hardware supports very
781 * large numbers of descriptors (at least 2^16). This limit is based on
782 * CP_LOAD_STATE6, which has a 28-bit field for the DWORD offset, so that
783 * we don't have to think about what to do if that overflows, but really
784 * nothing is likely to get close to this.
786 const size_t max_descriptor_set_size
= (1 << 28) / A6XX_TEX_CONST_DWORDS
;
788 VkPhysicalDeviceLimits limits
= {
789 .maxImageDimension1D
= (1 << 14),
790 .maxImageDimension2D
= (1 << 14),
791 .maxImageDimension3D
= (1 << 11),
792 .maxImageDimensionCube
= (1 << 14),
793 .maxImageArrayLayers
= (1 << 11),
794 .maxTexelBufferElements
= 128 * 1024 * 1024,
795 .maxUniformBufferRange
= MAX_UNIFORM_BUFFER_RANGE
,
796 .maxStorageBufferRange
= MAX_STORAGE_BUFFER_RANGE
,
797 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
798 .maxMemoryAllocationCount
= UINT32_MAX
,
799 .maxSamplerAllocationCount
= 64 * 1024,
800 .bufferImageGranularity
= 64, /* A cache line */
801 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
802 .maxBoundDescriptorSets
= MAX_SETS
,
803 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
804 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
805 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
806 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
807 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
808 .maxPerStageDescriptorInputAttachments
= MAX_RTS
,
809 .maxPerStageResources
= max_descriptor_set_size
,
810 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
811 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
812 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
813 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
814 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
815 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
816 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
817 .maxDescriptorSetInputAttachments
= MAX_RTS
,
818 .maxVertexInputAttributes
= 32,
819 .maxVertexInputBindings
= 32,
820 .maxVertexInputAttributeOffset
= 4095,
821 .maxVertexInputBindingStride
= 2048,
822 .maxVertexOutputComponents
= 128,
823 .maxTessellationGenerationLevel
= 64,
824 .maxTessellationPatchSize
= 32,
825 .maxTessellationControlPerVertexInputComponents
= 128,
826 .maxTessellationControlPerVertexOutputComponents
= 128,
827 .maxTessellationControlPerPatchOutputComponents
= 120,
828 .maxTessellationControlTotalOutputComponents
= 4096,
829 .maxTessellationEvaluationInputComponents
= 128,
830 .maxTessellationEvaluationOutputComponents
= 128,
831 .maxGeometryShaderInvocations
= 32,
832 .maxGeometryInputComponents
= 64,
833 .maxGeometryOutputComponents
= 128,
834 .maxGeometryOutputVertices
= 256,
835 .maxGeometryTotalOutputComponents
= 1024,
836 .maxFragmentInputComponents
= 124,
837 .maxFragmentOutputAttachments
= 8,
838 .maxFragmentDualSrcAttachments
= 1,
839 .maxFragmentCombinedOutputResources
= 8,
840 .maxComputeSharedMemorySize
= 32768,
841 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
842 .maxComputeWorkGroupInvocations
= 2048,
843 .maxComputeWorkGroupSize
= { 2048, 2048, 2048 },
844 .subPixelPrecisionBits
= 8,
845 .subTexelPrecisionBits
= 8,
846 .mipmapPrecisionBits
= 8,
847 .maxDrawIndexedIndexValue
= UINT32_MAX
,
848 .maxDrawIndirectCount
= UINT32_MAX
,
849 .maxSamplerLodBias
= 4095.0 / 256.0, /* [-16, 15.99609375] */
850 .maxSamplerAnisotropy
= 16,
851 .maxViewports
= MAX_VIEWPORTS
,
852 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
853 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
854 .viewportSubPixelBits
= 8,
855 .minMemoryMapAlignment
= 4096, /* A page */
856 .minTexelBufferOffsetAlignment
= 64,
857 .minUniformBufferOffsetAlignment
= 64,
858 .minStorageBufferOffsetAlignment
= 64,
859 .minTexelOffset
= -16,
860 .maxTexelOffset
= 15,
861 .minTexelGatherOffset
= -32,
862 .maxTexelGatherOffset
= 31,
863 .minInterpolationOffset
= -0.5,
864 .maxInterpolationOffset
= 0.4375,
865 .subPixelInterpolationOffsetBits
= 4,
866 .maxFramebufferWidth
= (1 << 14),
867 .maxFramebufferHeight
= (1 << 14),
868 .maxFramebufferLayers
= (1 << 10),
869 .framebufferColorSampleCounts
= sample_counts
,
870 .framebufferDepthSampleCounts
= sample_counts
,
871 .framebufferStencilSampleCounts
= sample_counts
,
872 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
873 .maxColorAttachments
= MAX_RTS
,
874 .sampledImageColorSampleCounts
= sample_counts
,
875 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
876 .sampledImageDepthSampleCounts
= sample_counts
,
877 .sampledImageStencilSampleCounts
= sample_counts
,
878 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
879 .maxSampleMaskWords
= 1,
880 .timestampComputeAndGraphics
= true,
881 .timestampPeriod
= 1000000000.0 / 19200000.0, /* CP_ALWAYS_ON_COUNTER is fixed 19.2MHz */
882 .maxClipDistances
= 8,
883 .maxCullDistances
= 8,
884 .maxCombinedClipAndCullDistances
= 8,
885 .discreteQueuePriorities
= 1,
886 .pointSizeRange
= { 1, 4092 },
887 .lineWidthRange
= { 0.0, 7.9921875 },
888 .pointSizeGranularity
= 0.0625,
889 .lineWidthGranularity
= (1.0 / 128.0),
890 .strictLines
= false, /* FINISHME */
891 .standardSampleLocations
= true,
892 .optimalBufferCopyOffsetAlignment
= 128,
893 .optimalBufferCopyRowPitchAlignment
= 128,
894 .nonCoherentAtomSize
= 64,
897 *pProperties
= (VkPhysicalDeviceProperties
) {
898 .apiVersion
= tu_physical_device_api_version(pdevice
),
899 .driverVersion
= vk_get_driver_version(),
900 .vendorID
= 0, /* TODO */
902 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
904 .sparseProperties
= { 0 },
907 strcpy(pProperties
->deviceName
, pdevice
->name
);
908 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
912 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice
,
913 VkPhysicalDeviceProperties2
*pProperties
)
915 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
916 tu_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
918 vk_foreach_struct(ext
, pProperties
->pNext
)
920 switch (ext
->sType
) {
921 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
922 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
923 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
924 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
927 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
928 VkPhysicalDeviceIDProperties
*properties
=
929 (VkPhysicalDeviceIDProperties
*) ext
;
930 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
931 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
932 properties
->deviceLUIDValid
= false;
935 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
936 VkPhysicalDeviceMultiviewProperties
*properties
=
937 (VkPhysicalDeviceMultiviewProperties
*) ext
;
938 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
939 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
942 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
943 VkPhysicalDevicePointClippingProperties
*properties
=
944 (VkPhysicalDevicePointClippingProperties
*) ext
;
945 properties
->pointClippingBehavior
=
946 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
949 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
950 VkPhysicalDeviceMaintenance3Properties
*properties
=
951 (VkPhysicalDeviceMaintenance3Properties
*) ext
;
952 /* Make sure everything is addressable by a signed 32-bit int, and
953 * our largest descriptors are 96 bytes. */
954 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
955 /* Our buffer size fields allow only this much */
956 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
959 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
960 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
961 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
963 properties
->maxTransformFeedbackStreams
= IR3_MAX_SO_STREAMS
;
964 properties
->maxTransformFeedbackBuffers
= IR3_MAX_SO_BUFFERS
;
965 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
966 properties
->maxTransformFeedbackStreamDataSize
= 512;
967 properties
->maxTransformFeedbackBufferDataSize
= 512;
968 properties
->maxTransformFeedbackBufferDataStride
= 512;
969 properties
->transformFeedbackQueries
= true;
970 properties
->transformFeedbackStreamsLinesTriangles
= false;
971 properties
->transformFeedbackRasterizationStreamSelect
= false;
972 properties
->transformFeedbackDraw
= true;
975 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
976 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
977 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
978 properties
->sampleLocationSampleCounts
= 0;
979 if (pdevice
->supported_extensions
.EXT_sample_locations
) {
980 properties
->sampleLocationSampleCounts
=
981 VK_SAMPLE_COUNT_1_BIT
| VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
;
983 properties
->maxSampleLocationGridSize
= (VkExtent2D
) { 1 , 1 };
984 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
985 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
986 properties
->sampleLocationSubPixelBits
= 4;
987 properties
->variableSampleLocations
= true;
990 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES
: {
991 VkPhysicalDeviceSamplerFilterMinmaxProperties
*properties
=
992 (VkPhysicalDeviceSamplerFilterMinmaxProperties
*)ext
;
993 properties
->filterMinmaxImageComponentMapping
= true;
994 properties
->filterMinmaxSingleComponentFormats
= true;
997 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
998 VkPhysicalDeviceSubgroupProperties
*properties
=
999 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1000 properties
->subgroupSize
= 64;
1001 properties
->supportedStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1002 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1003 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1004 properties
->quadOperationsInAllStages
= false;
1007 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1008 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
1009 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1010 props
->maxVertexAttribDivisor
= UINT32_MAX
;
1019 static const VkQueueFamilyProperties tu_queue_family_properties
= {
1021 VK_QUEUE_GRAPHICS_BIT
| VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
1023 .timestampValidBits
= 48,
1024 .minImageTransferGranularity
= { 1, 1, 1 },
1028 tu_GetPhysicalDeviceQueueFamilyProperties(
1029 VkPhysicalDevice physicalDevice
,
1030 uint32_t *pQueueFamilyPropertyCount
,
1031 VkQueueFamilyProperties
*pQueueFamilyProperties
)
1033 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1035 vk_outarray_append(&out
, p
) { *p
= tu_queue_family_properties
; }
1039 tu_GetPhysicalDeviceQueueFamilyProperties2(
1040 VkPhysicalDevice physicalDevice
,
1041 uint32_t *pQueueFamilyPropertyCount
,
1042 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1044 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
1046 vk_outarray_append(&out
, p
)
1048 p
->queueFamilyProperties
= tu_queue_family_properties
;
1053 tu_get_system_heap_size()
1055 struct sysinfo info
;
1058 uint64_t total_ram
= (uint64_t) info
.totalram
* (uint64_t) info
.mem_unit
;
1060 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
1061 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
1063 uint64_t available_ram
;
1064 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
1065 available_ram
= total_ram
/ 2;
1067 available_ram
= total_ram
* 3 / 4;
1069 return available_ram
;
1073 tu_GetPhysicalDeviceMemoryProperties(
1074 VkPhysicalDevice physicalDevice
,
1075 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1077 pMemoryProperties
->memoryHeapCount
= 1;
1078 pMemoryProperties
->memoryHeaps
[0].size
= tu_get_system_heap_size();
1079 pMemoryProperties
->memoryHeaps
[0].flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
;
1081 pMemoryProperties
->memoryTypeCount
= 1;
1082 pMemoryProperties
->memoryTypes
[0].propertyFlags
=
1083 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
1084 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1085 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
;
1086 pMemoryProperties
->memoryTypes
[0].heapIndex
= 0;
1090 tu_GetPhysicalDeviceMemoryProperties2(
1091 VkPhysicalDevice physicalDevice
,
1092 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1094 return tu_GetPhysicalDeviceMemoryProperties(
1095 physicalDevice
, &pMemoryProperties
->memoryProperties
);
1099 tu_queue_init(struct tu_device
*device
,
1100 struct tu_queue
*queue
,
1101 uint32_t queue_family_index
,
1103 VkDeviceQueueCreateFlags flags
)
1105 vk_object_base_init(&device
->vk
, &queue
->base
, VK_OBJECT_TYPE_QUEUE
);
1107 queue
->device
= device
;
1108 queue
->queue_family_index
= queue_family_index
;
1109 queue
->queue_idx
= idx
;
1110 queue
->flags
= flags
;
1112 int ret
= tu_drm_submitqueue_new(device
, 0, &queue
->msm_queue_id
);
1114 return VK_ERROR_INITIALIZATION_FAILED
;
1116 tu_fence_init(&queue
->submit_fence
, false);
1122 tu_queue_finish(struct tu_queue
*queue
)
1124 tu_fence_finish(&queue
->submit_fence
);
1125 tu_drm_submitqueue_close(queue
->device
, queue
->msm_queue_id
);
1129 tu_get_device_extension_index(const char *name
)
1131 for (unsigned i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; ++i
) {
1132 if (strcmp(name
, tu_device_extensions
[i
].extensionName
) == 0)
1138 struct PACKED bcolor_entry
{
1150 uint32_t z24
; /* also s8? */
1151 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
1153 } border_color
[] = {
1154 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = {},
1155 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = {},
1156 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = {
1157 .fp32
[3] = 0x3f800000,
1165 .rgb10a2
= 0xc0000000,
1168 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = {
1172 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = {
1173 .fp32
[0 ... 3] = 0x3f800000,
1174 .ui16
[0 ... 3] = 0xffff,
1175 .si16
[0 ... 3] = 0x7fff,
1176 .fp16
[0 ... 3] = 0x3c00,
1180 .ui8
[0 ... 3] = 0xff,
1181 .si8
[0 ... 3] = 0x7f,
1182 .rgb10a2
= 0xffffffff,
1184 .srgb
[0 ... 3] = 0x3c00,
1186 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = {
1193 tu_CreateDevice(VkPhysicalDevice physicalDevice
,
1194 const VkDeviceCreateInfo
*pCreateInfo
,
1195 const VkAllocationCallbacks
*pAllocator
,
1198 TU_FROM_HANDLE(tu_physical_device
, physical_device
, physicalDevice
);
1200 struct tu_device
*device
;
1202 /* Check enabled features */
1203 if (pCreateInfo
->pEnabledFeatures
) {
1204 VkPhysicalDeviceFeatures supported_features
;
1205 tu_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1206 VkBool32
*supported_feature
= (VkBool32
*) &supported_features
;
1207 VkBool32
*enabled_feature
= (VkBool32
*) pCreateInfo
->pEnabledFeatures
;
1208 unsigned num_features
=
1209 sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1210 for (uint32_t i
= 0; i
< num_features
; i
++) {
1211 if (enabled_feature
[i
] && !supported_feature
[i
])
1212 return vk_error(physical_device
->instance
,
1213 VK_ERROR_FEATURE_NOT_PRESENT
);
1217 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1218 sizeof(*device
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1220 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1222 vk_device_init(&device
->vk
, pCreateInfo
,
1223 &physical_device
->instance
->alloc
, pAllocator
);
1225 device
->instance
= physical_device
->instance
;
1226 device
->physical_device
= physical_device
;
1227 device
->_lost
= false;
1229 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1230 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1231 int index
= tu_get_device_extension_index(ext_name
);
1233 !physical_device
->supported_extensions
.extensions
[index
]) {
1234 vk_free(&device
->vk
.alloc
, device
);
1235 return vk_error(physical_device
->instance
,
1236 VK_ERROR_EXTENSION_NOT_PRESENT
);
1239 device
->enabled_extensions
.extensions
[index
] = true;
1242 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1243 const VkDeviceQueueCreateInfo
*queue_create
=
1244 &pCreateInfo
->pQueueCreateInfos
[i
];
1245 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1246 device
->queues
[qfi
] = vk_alloc(
1247 &device
->vk
.alloc
, queue_create
->queueCount
* sizeof(struct tu_queue
),
1248 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1249 if (!device
->queues
[qfi
]) {
1250 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1254 memset(device
->queues
[qfi
], 0,
1255 queue_create
->queueCount
* sizeof(struct tu_queue
));
1257 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1259 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1260 result
= tu_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
,
1261 queue_create
->flags
);
1262 if (result
!= VK_SUCCESS
)
1267 device
->compiler
= ir3_compiler_create(NULL
, physical_device
->gpu_id
);
1268 if (!device
->compiler
)
1271 /* initial sizes, these will increase if there is overflow */
1272 device
->vsc_draw_strm_pitch
= 0x1000 + VSC_PAD
;
1273 device
->vsc_prim_strm_pitch
= 0x4000 + VSC_PAD
;
1275 STATIC_ASSERT(sizeof(border_color
) == sizeof(((struct tu6_global
*) 0)->border_color
));
1276 result
= tu_bo_init_new(device
, &device
->global_bo
, sizeof(struct tu6_global
));
1277 if (result
!= VK_SUCCESS
)
1278 goto fail_global_bo
;
1280 result
= tu_bo_map(device
, &device
->global_bo
);
1281 if (result
!= VK_SUCCESS
)
1282 goto fail_global_bo_map
;
1284 memcpy(device
->global_bo
.map
+ gb_offset(border_color
), border_color
, sizeof(border_color
));
1285 tu_init_clear_blit_shaders(device
->global_bo
.map
);
1287 VkPipelineCacheCreateInfo ci
;
1288 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1291 ci
.pInitialData
= NULL
;
1292 ci
.initialDataSize
= 0;
1295 tu_CreatePipelineCache(tu_device_to_handle(device
), &ci
, NULL
, &pc
);
1296 if (result
!= VK_SUCCESS
)
1297 goto fail_pipeline_cache
;
1299 device
->mem_cache
= tu_pipeline_cache_from_handle(pc
);
1301 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->scratch_bos
); i
++)
1302 mtx_init(&device
->scratch_bos
[i
].construct_mtx
, mtx_plain
);
1304 mtx_init(&device
->vsc_pitch_mtx
, mtx_plain
);
1306 *pDevice
= tu_device_to_handle(device
);
1309 fail_pipeline_cache
:
1311 tu_bo_finish(device
, &device
->global_bo
);
1314 ralloc_free(device
->compiler
);
1317 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1318 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1319 tu_queue_finish(&device
->queues
[i
][q
]);
1320 if (device
->queue_count
[i
])
1321 vk_object_free(&device
->vk
, NULL
, device
->queues
[i
]);
1324 vk_free(&device
->vk
.alloc
, device
);
1329 tu_DestroyDevice(VkDevice _device
, const VkAllocationCallbacks
*pAllocator
)
1331 TU_FROM_HANDLE(tu_device
, device
, _device
);
1336 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1337 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1338 tu_queue_finish(&device
->queues
[i
][q
]);
1339 if (device
->queue_count
[i
])
1340 vk_object_free(&device
->vk
, NULL
, device
->queues
[i
]);
1343 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->scratch_bos
); i
++) {
1344 if (device
->scratch_bos
[i
].initialized
)
1345 tu_bo_finish(device
, &device
->scratch_bos
[i
].bo
);
1348 ir3_compiler_destroy(device
->compiler
);
1350 VkPipelineCache pc
= tu_pipeline_cache_to_handle(device
->mem_cache
);
1351 tu_DestroyPipelineCache(tu_device_to_handle(device
), pc
, NULL
);
1353 vk_free(&device
->vk
.alloc
, device
);
1357 _tu_device_set_lost(struct tu_device
*device
,
1358 const char *file
, int line
,
1359 const char *msg
, ...)
1361 /* Set the flag indicating that waits should return in finite time even
1362 * after device loss.
1364 p_atomic_inc(&device
->_lost
);
1366 /* TODO: Report the log message through VkDebugReportCallbackEXT instead */
1367 fprintf(stderr
, "%s:%d: ", file
, line
);
1370 vfprintf(stderr
, msg
, ap
);
1373 if (env_var_as_boolean("TU_ABORT_ON_DEVICE_LOSS", false))
1376 return VK_ERROR_DEVICE_LOST
;
1380 tu_get_scratch_bo(struct tu_device
*dev
, uint64_t size
, struct tu_bo
**bo
)
1382 unsigned size_log2
= MAX2(util_logbase2_ceil64(size
), MIN_SCRATCH_BO_SIZE_LOG2
);
1383 unsigned index
= size_log2
- MIN_SCRATCH_BO_SIZE_LOG2
;
1384 assert(index
< ARRAY_SIZE(dev
->scratch_bos
));
1386 for (unsigned i
= index
; i
< ARRAY_SIZE(dev
->scratch_bos
); i
++) {
1387 if (p_atomic_read(&dev
->scratch_bos
[i
].initialized
)) {
1388 /* Fast path: just return the already-allocated BO. */
1389 *bo
= &dev
->scratch_bos
[i
].bo
;
1394 /* Slow path: actually allocate the BO. We take a lock because the process
1395 * of allocating it is slow, and we don't want to block the CPU while it
1398 mtx_lock(&dev
->scratch_bos
[index
].construct_mtx
);
1400 /* Another thread may have allocated it already while we were waiting on
1401 * the lock. We need to check this in order to avoid double-allocating.
1403 if (dev
->scratch_bos
[index
].initialized
) {
1404 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1405 *bo
= &dev
->scratch_bos
[index
].bo
;
1409 unsigned bo_size
= 1ull << size_log2
;
1410 VkResult result
= tu_bo_init_new(dev
, &dev
->scratch_bos
[index
].bo
, bo_size
);
1411 if (result
!= VK_SUCCESS
) {
1412 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1416 p_atomic_set(&dev
->scratch_bos
[index
].initialized
, true);
1418 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1420 *bo
= &dev
->scratch_bos
[index
].bo
;
1425 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount
,
1426 VkLayerProperties
*pProperties
)
1428 *pPropertyCount
= 0;
1433 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice
,
1434 uint32_t *pPropertyCount
,
1435 VkLayerProperties
*pProperties
)
1437 *pPropertyCount
= 0;
1442 tu_GetDeviceQueue2(VkDevice _device
,
1443 const VkDeviceQueueInfo2
*pQueueInfo
,
1446 TU_FROM_HANDLE(tu_device
, device
, _device
);
1447 struct tu_queue
*queue
;
1450 &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1451 if (pQueueInfo
->flags
!= queue
->flags
) {
1452 /* From the Vulkan 1.1.70 spec:
1454 * "The queue returned by vkGetDeviceQueue2 must have the same
1455 * flags value from this structure as that used at device
1456 * creation time in a VkDeviceQueueCreateInfo instance. If no
1457 * matching flags were specified at device creation time then
1458 * pQueue will return VK_NULL_HANDLE."
1460 *pQueue
= VK_NULL_HANDLE
;
1464 *pQueue
= tu_queue_to_handle(queue
);
1468 tu_GetDeviceQueue(VkDevice _device
,
1469 uint32_t queueFamilyIndex
,
1470 uint32_t queueIndex
,
1473 const VkDeviceQueueInfo2 info
=
1474 (VkDeviceQueueInfo2
) { .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1475 .queueFamilyIndex
= queueFamilyIndex
,
1476 .queueIndex
= queueIndex
};
1478 tu_GetDeviceQueue2(_device
, &info
, pQueue
);
1482 tu_get_semaphore_syncobjs(const VkSemaphore
*sems
,
1485 struct drm_msm_gem_submit_syncobj
**out
,
1486 uint32_t *out_count
)
1488 uint32_t syncobj_count
= 0;
1489 struct drm_msm_gem_submit_syncobj
*syncobjs
;
1491 for (uint32_t i
= 0; i
< sem_count
; ++i
) {
1492 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1494 struct tu_semaphore_part
*part
=
1495 sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
?
1496 &sem
->temporary
: &sem
->permanent
;
1498 if (part
->kind
== TU_SEMAPHORE_SYNCOBJ
)
1503 *out_count
= syncobj_count
;
1507 *out
= syncobjs
= calloc(syncobj_count
, sizeof (*syncobjs
));
1509 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1511 for (uint32_t i
= 0, j
= 0; i
< sem_count
; ++i
) {
1512 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1514 struct tu_semaphore_part
*part
=
1515 sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
?
1516 &sem
->temporary
: &sem
->permanent
;
1518 if (part
->kind
== TU_SEMAPHORE_SYNCOBJ
) {
1519 syncobjs
[j
].handle
= part
->syncobj
;
1520 syncobjs
[j
].flags
= wait
? MSM_SUBMIT_SYNCOBJ_RESET
: 0;
1530 tu_semaphores_remove_temp(struct tu_device
*device
,
1531 const VkSemaphore
*sems
,
1534 for (uint32_t i
= 0; i
< sem_count
; ++i
) {
1535 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1536 tu_semaphore_remove_temp(device
, sem
);
1541 tu_QueueSubmit(VkQueue _queue
,
1542 uint32_t submitCount
,
1543 const VkSubmitInfo
*pSubmits
,
1546 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1549 for (uint32_t i
= 0; i
< submitCount
; ++i
) {
1550 const VkSubmitInfo
*submit
= pSubmits
+ i
;
1551 const bool last_submit
= (i
== submitCount
- 1);
1552 struct drm_msm_gem_submit_syncobj
*in_syncobjs
= NULL
, *out_syncobjs
= NULL
;
1553 uint32_t nr_in_syncobjs
, nr_out_syncobjs
;
1554 struct tu_bo_list bo_list
;
1555 tu_bo_list_init(&bo_list
);
1557 result
= tu_get_semaphore_syncobjs(pSubmits
[i
].pWaitSemaphores
,
1558 pSubmits
[i
].waitSemaphoreCount
,
1559 false, &in_syncobjs
, &nr_in_syncobjs
);
1560 if (result
!= VK_SUCCESS
) {
1561 return tu_device_set_lost(queue
->device
,
1562 "failed to allocate space for semaphore submission\n");
1565 result
= tu_get_semaphore_syncobjs(pSubmits
[i
].pSignalSemaphores
,
1566 pSubmits
[i
].signalSemaphoreCount
,
1567 false, &out_syncobjs
, &nr_out_syncobjs
);
1568 if (result
!= VK_SUCCESS
) {
1570 return tu_device_set_lost(queue
->device
,
1571 "failed to allocate space for semaphore submission\n");
1574 uint32_t entry_count
= 0;
1575 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1576 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1577 entry_count
+= cmdbuf
->cs
.entry_count
;
1580 struct drm_msm_gem_submit_cmd cmds
[entry_count
];
1581 uint32_t entry_idx
= 0;
1582 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1583 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1584 struct tu_cs
*cs
= &cmdbuf
->cs
;
1585 for (unsigned i
= 0; i
< cs
->entry_count
; ++i
, ++entry_idx
) {
1586 cmds
[entry_idx
].type
= MSM_SUBMIT_CMD_BUF
;
1587 cmds
[entry_idx
].submit_idx
=
1588 tu_bo_list_add(&bo_list
, cs
->entries
[i
].bo
,
1589 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1590 cmds
[entry_idx
].submit_offset
= cs
->entries
[i
].offset
;
1591 cmds
[entry_idx
].size
= cs
->entries
[i
].size
;
1592 cmds
[entry_idx
].pad
= 0;
1593 cmds
[entry_idx
].nr_relocs
= 0;
1594 cmds
[entry_idx
].relocs
= 0;
1597 tu_bo_list_merge(&bo_list
, &cmdbuf
->bo_list
);
1600 uint32_t flags
= MSM_PIPE_3D0
;
1601 if (nr_in_syncobjs
) {
1602 flags
|= MSM_SUBMIT_SYNCOBJ_IN
;
1604 if (nr_out_syncobjs
) {
1605 flags
|= MSM_SUBMIT_SYNCOBJ_OUT
;
1609 flags
|= MSM_SUBMIT_FENCE_FD_OUT
;
1612 struct drm_msm_gem_submit req
= {
1614 .queueid
= queue
->msm_queue_id
,
1615 .bos
= (uint64_t)(uintptr_t) bo_list
.bo_infos
,
1616 .nr_bos
= bo_list
.count
,
1617 .cmds
= (uint64_t)(uintptr_t)cmds
,
1618 .nr_cmds
= entry_count
,
1619 .in_syncobjs
= (uint64_t)(uintptr_t)in_syncobjs
,
1620 .out_syncobjs
= (uint64_t)(uintptr_t)out_syncobjs
,
1621 .nr_in_syncobjs
= nr_in_syncobjs
,
1622 .nr_out_syncobjs
= nr_out_syncobjs
,
1623 .syncobj_stride
= sizeof(struct drm_msm_gem_submit_syncobj
),
1626 int ret
= drmCommandWriteRead(queue
->device
->physical_device
->local_fd
,
1632 return tu_device_set_lost(queue
->device
, "submit failed: %s\n",
1636 tu_bo_list_destroy(&bo_list
);
1640 tu_semaphores_remove_temp(queue
->device
, pSubmits
[i
].pWaitSemaphores
,
1641 pSubmits
[i
].waitSemaphoreCount
);
1643 /* no need to merge fences as queue execution is serialized */
1644 tu_fence_update_fd(&queue
->submit_fence
, req
.fence_fd
);
1645 } else if (last_submit
) {
1646 close(req
.fence_fd
);
1650 if (_fence
!= VK_NULL_HANDLE
) {
1651 TU_FROM_HANDLE(tu_fence
, fence
, _fence
);
1652 tu_fence_copy(fence
, &queue
->submit_fence
);
1659 tu_QueueWaitIdle(VkQueue _queue
)
1661 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1663 if (tu_device_is_lost(queue
->device
))
1664 return VK_ERROR_DEVICE_LOST
;
1666 tu_fence_wait_idle(&queue
->submit_fence
);
1672 tu_DeviceWaitIdle(VkDevice _device
)
1674 TU_FROM_HANDLE(tu_device
, device
, _device
);
1676 if (tu_device_is_lost(device
))
1677 return VK_ERROR_DEVICE_LOST
;
1679 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1680 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1681 tu_QueueWaitIdle(tu_queue_to_handle(&device
->queues
[i
][q
]));
1688 tu_EnumerateInstanceExtensionProperties(const char *pLayerName
,
1689 uint32_t *pPropertyCount
,
1690 VkExtensionProperties
*pProperties
)
1692 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1694 /* We spport no lyaers */
1696 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1698 for (int i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; i
++) {
1699 if (tu_instance_extensions_supported
.extensions
[i
]) {
1700 vk_outarray_append(&out
, prop
) { *prop
= tu_instance_extensions
[i
]; }
1704 return vk_outarray_status(&out
);
1708 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
1709 const char *pLayerName
,
1710 uint32_t *pPropertyCount
,
1711 VkExtensionProperties
*pProperties
)
1713 /* We spport no lyaers */
1714 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
1715 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1717 /* We spport no lyaers */
1719 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1721 for (int i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; i
++) {
1722 if (device
->supported_extensions
.extensions
[i
]) {
1723 vk_outarray_append(&out
, prop
) { *prop
= tu_device_extensions
[i
]; }
1727 return vk_outarray_status(&out
);
1731 tu_GetInstanceProcAddr(VkInstance _instance
, const char *pName
)
1733 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
1735 return tu_lookup_entrypoint_checked(
1736 pName
, instance
? instance
->api_version
: 0,
1737 instance
? &instance
->enabled_extensions
: NULL
, NULL
);
1740 /* The loader wants us to expose a second GetInstanceProcAddr function
1741 * to work around certain LD_PRELOAD issues seen in apps.
1744 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1745 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
);
1748 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1749 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
)
1751 return tu_GetInstanceProcAddr(instance
, pName
);
1755 tu_GetDeviceProcAddr(VkDevice _device
, const char *pName
)
1757 TU_FROM_HANDLE(tu_device
, device
, _device
);
1759 return tu_lookup_entrypoint_checked(pName
, device
->instance
->api_version
,
1760 &device
->instance
->enabled_extensions
,
1761 &device
->enabled_extensions
);
1765 tu_alloc_memory(struct tu_device
*device
,
1766 const VkMemoryAllocateInfo
*pAllocateInfo
,
1767 const VkAllocationCallbacks
*pAllocator
,
1768 VkDeviceMemory
*pMem
)
1770 struct tu_device_memory
*mem
;
1773 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1775 if (pAllocateInfo
->allocationSize
== 0) {
1776 /* Apparently, this is allowed */
1777 *pMem
= VK_NULL_HANDLE
;
1781 mem
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*mem
),
1782 VK_OBJECT_TYPE_DEVICE_MEMORY
);
1784 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1786 const VkImportMemoryFdInfoKHR
*fd_info
=
1787 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1788 if (fd_info
&& !fd_info
->handleType
)
1792 assert(fd_info
->handleType
==
1793 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1794 fd_info
->handleType
==
1795 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1798 * TODO Importing the same fd twice gives us the same handle without
1799 * reference counting. We need to maintain a per-instance handle-to-bo
1800 * table and add reference count to tu_bo.
1802 result
= tu_bo_init_dmabuf(device
, &mem
->bo
,
1803 pAllocateInfo
->allocationSize
, fd_info
->fd
);
1804 if (result
== VK_SUCCESS
) {
1805 /* take ownership and close the fd */
1810 tu_bo_init_new(device
, &mem
->bo
, pAllocateInfo
->allocationSize
);
1813 if (result
!= VK_SUCCESS
) {
1814 vk_object_free(&device
->vk
, pAllocator
, mem
);
1818 mem
->size
= pAllocateInfo
->allocationSize
;
1819 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1822 mem
->user_ptr
= NULL
;
1824 *pMem
= tu_device_memory_to_handle(mem
);
1830 tu_AllocateMemory(VkDevice _device
,
1831 const VkMemoryAllocateInfo
*pAllocateInfo
,
1832 const VkAllocationCallbacks
*pAllocator
,
1833 VkDeviceMemory
*pMem
)
1835 TU_FROM_HANDLE(tu_device
, device
, _device
);
1836 return tu_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
1840 tu_FreeMemory(VkDevice _device
,
1841 VkDeviceMemory _mem
,
1842 const VkAllocationCallbacks
*pAllocator
)
1844 TU_FROM_HANDLE(tu_device
, device
, _device
);
1845 TU_FROM_HANDLE(tu_device_memory
, mem
, _mem
);
1850 tu_bo_finish(device
, &mem
->bo
);
1851 vk_object_free(&device
->vk
, pAllocator
, mem
);
1855 tu_MapMemory(VkDevice _device
,
1856 VkDeviceMemory _memory
,
1857 VkDeviceSize offset
,
1859 VkMemoryMapFlags flags
,
1862 TU_FROM_HANDLE(tu_device
, device
, _device
);
1863 TU_FROM_HANDLE(tu_device_memory
, mem
, _memory
);
1871 if (mem
->user_ptr
) {
1872 *ppData
= mem
->user_ptr
;
1873 } else if (!mem
->map
) {
1874 result
= tu_bo_map(device
, &mem
->bo
);
1875 if (result
!= VK_SUCCESS
)
1877 *ppData
= mem
->map
= mem
->bo
.map
;
1886 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
1890 tu_UnmapMemory(VkDevice _device
, VkDeviceMemory _memory
)
1892 /* I do not see any unmapping done by the freedreno Gallium driver. */
1896 tu_FlushMappedMemoryRanges(VkDevice _device
,
1897 uint32_t memoryRangeCount
,
1898 const VkMappedMemoryRange
*pMemoryRanges
)
1904 tu_InvalidateMappedMemoryRanges(VkDevice _device
,
1905 uint32_t memoryRangeCount
,
1906 const VkMappedMemoryRange
*pMemoryRanges
)
1912 tu_GetBufferMemoryRequirements(VkDevice _device
,
1914 VkMemoryRequirements
*pMemoryRequirements
)
1916 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1918 pMemoryRequirements
->memoryTypeBits
= 1;
1919 pMemoryRequirements
->alignment
= 64;
1920 pMemoryRequirements
->size
=
1921 align64(buffer
->size
, pMemoryRequirements
->alignment
);
1925 tu_GetBufferMemoryRequirements2(
1927 const VkBufferMemoryRequirementsInfo2
*pInfo
,
1928 VkMemoryRequirements2
*pMemoryRequirements
)
1930 tu_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
1931 &pMemoryRequirements
->memoryRequirements
);
1935 tu_GetImageMemoryRequirements(VkDevice _device
,
1937 VkMemoryRequirements
*pMemoryRequirements
)
1939 TU_FROM_HANDLE(tu_image
, image
, _image
);
1941 pMemoryRequirements
->memoryTypeBits
= 1;
1942 pMemoryRequirements
->size
= image
->total_size
;
1943 pMemoryRequirements
->alignment
= image
->layout
[0].base_align
;
1947 tu_GetImageMemoryRequirements2(VkDevice device
,
1948 const VkImageMemoryRequirementsInfo2
*pInfo
,
1949 VkMemoryRequirements2
*pMemoryRequirements
)
1951 tu_GetImageMemoryRequirements(device
, pInfo
->image
,
1952 &pMemoryRequirements
->memoryRequirements
);
1956 tu_GetImageSparseMemoryRequirements(
1959 uint32_t *pSparseMemoryRequirementCount
,
1960 VkSparseImageMemoryRequirements
*pSparseMemoryRequirements
)
1966 tu_GetImageSparseMemoryRequirements2(
1968 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
1969 uint32_t *pSparseMemoryRequirementCount
,
1970 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
1976 tu_GetDeviceMemoryCommitment(VkDevice device
,
1977 VkDeviceMemory memory
,
1978 VkDeviceSize
*pCommittedMemoryInBytes
)
1980 *pCommittedMemoryInBytes
= 0;
1984 tu_BindBufferMemory2(VkDevice device
,
1985 uint32_t bindInfoCount
,
1986 const VkBindBufferMemoryInfo
*pBindInfos
)
1988 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1989 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1990 TU_FROM_HANDLE(tu_buffer
, buffer
, pBindInfos
[i
].buffer
);
1993 buffer
->bo
= &mem
->bo
;
1994 buffer
->bo_offset
= pBindInfos
[i
].memoryOffset
;
2003 tu_BindBufferMemory(VkDevice device
,
2005 VkDeviceMemory memory
,
2006 VkDeviceSize memoryOffset
)
2008 const VkBindBufferMemoryInfo info
= {
2009 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2012 .memoryOffset
= memoryOffset
2015 return tu_BindBufferMemory2(device
, 1, &info
);
2019 tu_BindImageMemory2(VkDevice device
,
2020 uint32_t bindInfoCount
,
2021 const VkBindImageMemoryInfo
*pBindInfos
)
2023 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2024 TU_FROM_HANDLE(tu_image
, image
, pBindInfos
[i
].image
);
2025 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
2028 image
->bo
= &mem
->bo
;
2029 image
->bo_offset
= pBindInfos
[i
].memoryOffset
;
2032 image
->bo_offset
= 0;
2040 tu_BindImageMemory(VkDevice device
,
2042 VkDeviceMemory memory
,
2043 VkDeviceSize memoryOffset
)
2045 const VkBindImageMemoryInfo info
= {
2046 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
2049 .memoryOffset
= memoryOffset
2052 return tu_BindImageMemory2(device
, 1, &info
);
2056 tu_QueueBindSparse(VkQueue _queue
,
2057 uint32_t bindInfoCount
,
2058 const VkBindSparseInfo
*pBindInfo
,
2064 // Queue semaphore functions
2068 tu_semaphore_part_destroy(struct tu_device
*device
,
2069 struct tu_semaphore_part
*part
)
2071 switch(part
->kind
) {
2072 case TU_SEMAPHORE_NONE
:
2074 case TU_SEMAPHORE_SYNCOBJ
:
2075 drmSyncobjDestroy(device
->physical_device
->local_fd
, part
->syncobj
);
2078 part
->kind
= TU_SEMAPHORE_NONE
;
2082 tu_semaphore_remove_temp(struct tu_device
*device
,
2083 struct tu_semaphore
*sem
)
2085 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2086 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2091 tu_CreateSemaphore(VkDevice _device
,
2092 const VkSemaphoreCreateInfo
*pCreateInfo
,
2093 const VkAllocationCallbacks
*pAllocator
,
2094 VkSemaphore
*pSemaphore
)
2096 TU_FROM_HANDLE(tu_device
, device
, _device
);
2098 struct tu_semaphore
*sem
=
2099 vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*sem
),
2100 VK_OBJECT_TYPE_SEMAPHORE
);
2102 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2104 const VkExportSemaphoreCreateInfo
*export
=
2105 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
2106 VkExternalSemaphoreHandleTypeFlags handleTypes
=
2107 export
? export
->handleTypes
: 0;
2109 sem
->permanent
.kind
= TU_SEMAPHORE_NONE
;
2110 sem
->temporary
.kind
= TU_SEMAPHORE_NONE
;
2113 if (drmSyncobjCreate(device
->physical_device
->local_fd
, 0, &sem
->permanent
.syncobj
) < 0) {
2114 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
2115 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2117 sem
->permanent
.kind
= TU_SEMAPHORE_SYNCOBJ
;
2119 *pSemaphore
= tu_semaphore_to_handle(sem
);
2124 tu_DestroySemaphore(VkDevice _device
,
2125 VkSemaphore _semaphore
,
2126 const VkAllocationCallbacks
*pAllocator
)
2128 TU_FROM_HANDLE(tu_device
, device
, _device
);
2129 TU_FROM_HANDLE(tu_semaphore
, sem
, _semaphore
);
2133 tu_semaphore_part_destroy(device
, &sem
->permanent
);
2134 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2136 vk_object_free(&device
->vk
, pAllocator
, sem
);
2140 tu_CreateEvent(VkDevice _device
,
2141 const VkEventCreateInfo
*pCreateInfo
,
2142 const VkAllocationCallbacks
*pAllocator
,
2145 TU_FROM_HANDLE(tu_device
, device
, _device
);
2147 struct tu_event
*event
=
2148 vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*event
),
2149 VK_OBJECT_TYPE_EVENT
);
2151 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2153 VkResult result
= tu_bo_init_new(device
, &event
->bo
, 0x1000);
2154 if (result
!= VK_SUCCESS
)
2157 result
= tu_bo_map(device
, &event
->bo
);
2158 if (result
!= VK_SUCCESS
)
2161 *pEvent
= tu_event_to_handle(event
);
2166 tu_bo_finish(device
, &event
->bo
);
2168 vk_object_free(&device
->vk
, pAllocator
, event
);
2169 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2173 tu_DestroyEvent(VkDevice _device
,
2175 const VkAllocationCallbacks
*pAllocator
)
2177 TU_FROM_HANDLE(tu_device
, device
, _device
);
2178 TU_FROM_HANDLE(tu_event
, event
, _event
);
2183 tu_bo_finish(device
, &event
->bo
);
2184 vk_object_free(&device
->vk
, pAllocator
, event
);
2188 tu_GetEventStatus(VkDevice _device
, VkEvent _event
)
2190 TU_FROM_HANDLE(tu_event
, event
, _event
);
2192 if (*(uint64_t*) event
->bo
.map
== 1)
2193 return VK_EVENT_SET
;
2194 return VK_EVENT_RESET
;
2198 tu_SetEvent(VkDevice _device
, VkEvent _event
)
2200 TU_FROM_HANDLE(tu_event
, event
, _event
);
2201 *(uint64_t*) event
->bo
.map
= 1;
2207 tu_ResetEvent(VkDevice _device
, VkEvent _event
)
2209 TU_FROM_HANDLE(tu_event
, event
, _event
);
2210 *(uint64_t*) event
->bo
.map
= 0;
2216 tu_CreateBuffer(VkDevice _device
,
2217 const VkBufferCreateInfo
*pCreateInfo
,
2218 const VkAllocationCallbacks
*pAllocator
,
2221 TU_FROM_HANDLE(tu_device
, device
, _device
);
2222 struct tu_buffer
*buffer
;
2224 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2226 buffer
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*buffer
),
2227 VK_OBJECT_TYPE_BUFFER
);
2229 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2231 buffer
->size
= pCreateInfo
->size
;
2232 buffer
->usage
= pCreateInfo
->usage
;
2233 buffer
->flags
= pCreateInfo
->flags
;
2235 *pBuffer
= tu_buffer_to_handle(buffer
);
2241 tu_DestroyBuffer(VkDevice _device
,
2243 const VkAllocationCallbacks
*pAllocator
)
2245 TU_FROM_HANDLE(tu_device
, device
, _device
);
2246 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
2251 vk_object_free(&device
->vk
, pAllocator
, buffer
);
2255 tu_CreateFramebuffer(VkDevice _device
,
2256 const VkFramebufferCreateInfo
*pCreateInfo
,
2257 const VkAllocationCallbacks
*pAllocator
,
2258 VkFramebuffer
*pFramebuffer
)
2260 TU_FROM_HANDLE(tu_device
, device
, _device
);
2261 TU_FROM_HANDLE(tu_render_pass
, pass
, pCreateInfo
->renderPass
);
2262 struct tu_framebuffer
*framebuffer
;
2264 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2266 size_t size
= sizeof(*framebuffer
) + sizeof(struct tu_attachment_info
) *
2267 pCreateInfo
->attachmentCount
;
2268 framebuffer
= vk_object_alloc(&device
->vk
, pAllocator
, size
,
2269 VK_OBJECT_TYPE_FRAMEBUFFER
);
2270 if (framebuffer
== NULL
)
2271 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2273 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2274 framebuffer
->width
= pCreateInfo
->width
;
2275 framebuffer
->height
= pCreateInfo
->height
;
2276 framebuffer
->layers
= pCreateInfo
->layers
;
2277 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2278 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2279 struct tu_image_view
*iview
= tu_image_view_from_handle(_iview
);
2280 framebuffer
->attachments
[i
].attachment
= iview
;
2283 tu_framebuffer_tiling_config(framebuffer
, device
, pass
);
2285 *pFramebuffer
= tu_framebuffer_to_handle(framebuffer
);
2290 tu_DestroyFramebuffer(VkDevice _device
,
2292 const VkAllocationCallbacks
*pAllocator
)
2294 TU_FROM_HANDLE(tu_device
, device
, _device
);
2295 TU_FROM_HANDLE(tu_framebuffer
, fb
, _fb
);
2300 vk_object_free(&device
->vk
, pAllocator
, fb
);
2304 tu_init_sampler(struct tu_device
*device
,
2305 struct tu_sampler
*sampler
,
2306 const VkSamplerCreateInfo
*pCreateInfo
)
2308 const struct VkSamplerReductionModeCreateInfo
*reduction
=
2309 vk_find_struct_const(pCreateInfo
->pNext
, SAMPLER_REDUCTION_MODE_CREATE_INFO
);
2310 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
2311 vk_find_struct_const(pCreateInfo
->pNext
, SAMPLER_YCBCR_CONVERSION_INFO
);
2313 unsigned aniso
= pCreateInfo
->anisotropyEnable
?
2314 util_last_bit(MIN2((uint32_t)pCreateInfo
->maxAnisotropy
>> 1, 8)) : 0;
2315 bool miplinear
= (pCreateInfo
->mipmapMode
== VK_SAMPLER_MIPMAP_MODE_LINEAR
);
2316 float min_lod
= CLAMP(pCreateInfo
->minLod
, 0.0f
, 4095.0f
/ 256.0f
);
2317 float max_lod
= CLAMP(pCreateInfo
->maxLod
, 0.0f
, 4095.0f
/ 256.0f
);
2319 sampler
->descriptor
[0] =
2320 COND(miplinear
, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR
) |
2321 A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo
->magFilter
, aniso
)) |
2322 A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo
->minFilter
, aniso
)) |
2323 A6XX_TEX_SAMP_0_ANISO(aniso
) |
2324 A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo
->addressModeU
)) |
2325 A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo
->addressModeV
)) |
2326 A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo
->addressModeW
)) |
2327 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo
->mipLodBias
);
2328 sampler
->descriptor
[1] =
2329 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
2330 COND(pCreateInfo
->unnormalizedCoordinates
, A6XX_TEX_SAMP_1_UNNORM_COORDS
) |
2331 A6XX_TEX_SAMP_1_MIN_LOD(min_lod
) |
2332 A6XX_TEX_SAMP_1_MAX_LOD(max_lod
) |
2333 COND(pCreateInfo
->compareEnable
,
2334 A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo
->compareOp
)));
2335 /* This is an offset into the border_color BO, which we fill with all the
2336 * possible Vulkan border colors in the correct order, so we can just use
2337 * the Vulkan enum with no translation necessary.
2339 sampler
->descriptor
[2] =
2340 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((unsigned) pCreateInfo
->borderColor
*
2341 sizeof(struct bcolor_entry
));
2342 sampler
->descriptor
[3] = 0;
2345 sampler
->descriptor
[2] |= A6XX_TEX_SAMP_2_REDUCTION_MODE(
2346 tu6_reduction_mode(reduction
->reductionMode
));
2349 sampler
->ycbcr_sampler
= ycbcr_conversion
?
2350 tu_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
) : NULL
;
2352 if (sampler
->ycbcr_sampler
&&
2353 sampler
->ycbcr_sampler
->chroma_filter
== VK_FILTER_LINEAR
) {
2354 sampler
->descriptor
[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR
;
2358 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
2363 tu_CreateSampler(VkDevice _device
,
2364 const VkSamplerCreateInfo
*pCreateInfo
,
2365 const VkAllocationCallbacks
*pAllocator
,
2366 VkSampler
*pSampler
)
2368 TU_FROM_HANDLE(tu_device
, device
, _device
);
2369 struct tu_sampler
*sampler
;
2371 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2373 sampler
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*sampler
),
2374 VK_OBJECT_TYPE_SAMPLER
);
2376 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2378 tu_init_sampler(device
, sampler
, pCreateInfo
);
2379 *pSampler
= tu_sampler_to_handle(sampler
);
2385 tu_DestroySampler(VkDevice _device
,
2387 const VkAllocationCallbacks
*pAllocator
)
2389 TU_FROM_HANDLE(tu_device
, device
, _device
);
2390 TU_FROM_HANDLE(tu_sampler
, sampler
, _sampler
);
2395 vk_object_free(&device
->vk
, pAllocator
, sampler
);
2398 /* vk_icd.h does not declare this function, so we declare it here to
2399 * suppress Wmissing-prototypes.
2401 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2402 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2404 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2405 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2407 /* For the full details on loader interface versioning, see
2408 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2409 * What follows is a condensed summary, to help you navigate the large and
2410 * confusing official doc.
2412 * - Loader interface v0 is incompatible with later versions. We don't
2415 * - In loader interface v1:
2416 * - The first ICD entrypoint called by the loader is
2417 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2419 * - The ICD must statically expose no other Vulkan symbol unless it
2420 * is linked with -Bsymbolic.
2421 * - Each dispatchable Vulkan handle created by the ICD must be
2422 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2423 * ICD must initialize VK_LOADER_DATA.loadMagic to
2425 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2426 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2427 * such loader-managed surfaces.
2429 * - Loader interface v2 differs from v1 in:
2430 * - The first ICD entrypoint called by the loader is
2431 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2432 * statically expose this entrypoint.
2434 * - Loader interface v3 differs from v2 in:
2435 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2436 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2437 * because the loader no longer does so.
2439 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
2444 tu_GetMemoryFdKHR(VkDevice _device
,
2445 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
2448 TU_FROM_HANDLE(tu_device
, device
, _device
);
2449 TU_FROM_HANDLE(tu_device_memory
, memory
, pGetFdInfo
->memory
);
2451 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2453 /* At the moment, we support only the below handle types. */
2454 assert(pGetFdInfo
->handleType
==
2455 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2456 pGetFdInfo
->handleType
==
2457 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2459 int prime_fd
= tu_bo_export_dmabuf(device
, &memory
->bo
);
2461 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2468 tu_GetMemoryFdPropertiesKHR(VkDevice _device
,
2469 VkExternalMemoryHandleTypeFlagBits handleType
,
2471 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
2473 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2474 pMemoryFdProperties
->memoryTypeBits
= 1;
2479 tu_ImportFenceFdKHR(VkDevice _device
,
2480 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
2488 tu_GetFenceFdKHR(VkDevice _device
,
2489 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
2498 tu_ImportSemaphoreFdKHR(VkDevice _device
,
2499 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
2501 TU_FROM_HANDLE(tu_device
, device
, _device
);
2502 TU_FROM_HANDLE(tu_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
2504 struct tu_semaphore_part
*dst
= NULL
;
2506 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
2507 dst
= &sem
->temporary
;
2509 dst
= &sem
->permanent
;
2512 uint32_t syncobj
= dst
->kind
== TU_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
2514 switch(pImportSemaphoreFdInfo
->handleType
) {
2515 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
: {
2516 uint32_t old_syncobj
= syncobj
;
2517 ret
= drmSyncobjFDToHandle(device
->physical_device
->local_fd
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
2519 close(pImportSemaphoreFdInfo
->fd
);
2521 drmSyncobjDestroy(device
->physical_device
->local_fd
, old_syncobj
);
2525 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
: {
2527 ret
= drmSyncobjCreate(device
->physical_device
->local_fd
, 0, &syncobj
);
2531 if (pImportSemaphoreFdInfo
->fd
== -1) {
2532 ret
= drmSyncobjSignal(device
->physical_device
->local_fd
, &syncobj
, 1);
2534 ret
= drmSyncobjImportSyncFile(device
->physical_device
->local_fd
, syncobj
, pImportSemaphoreFdInfo
->fd
);
2537 close(pImportSemaphoreFdInfo
->fd
);
2541 unreachable("Unhandled semaphore handle type");
2545 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
2547 dst
->syncobj
= syncobj
;
2548 dst
->kind
= TU_SEMAPHORE_SYNCOBJ
;
2554 tu_GetSemaphoreFdKHR(VkDevice _device
,
2555 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
2558 TU_FROM_HANDLE(tu_device
, device
, _device
);
2559 TU_FROM_HANDLE(tu_semaphore
, sem
, pGetFdInfo
->semaphore
);
2561 uint32_t syncobj_handle
;
2563 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2564 assert(sem
->temporary
.kind
== TU_SEMAPHORE_SYNCOBJ
);
2565 syncobj_handle
= sem
->temporary
.syncobj
;
2567 assert(sem
->permanent
.kind
== TU_SEMAPHORE_SYNCOBJ
);
2568 syncobj_handle
= sem
->permanent
.syncobj
;
2571 switch(pGetFdInfo
->handleType
) {
2572 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
2573 ret
= drmSyncobjHandleToFD(device
->physical_device
->local_fd
, syncobj_handle
, pFd
);
2575 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
2576 ret
= drmSyncobjExportSyncFile(device
->physical_device
->local_fd
, syncobj_handle
, pFd
);
2578 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2579 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2581 drmSyncobjReset(device
->physical_device
->local_fd
, &syncobj_handle
, 1);
2586 unreachable("Unhandled semaphore handle type");
2590 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2595 static bool tu_has_syncobj(struct tu_physical_device
*pdev
)
2598 if (drmGetCap(pdev
->local_fd
, DRM_CAP_SYNCOBJ
, &value
))
2600 return value
&& pdev
->msm_major_version
== 1 && pdev
->msm_minor_version
>= 6;
2604 tu_GetPhysicalDeviceExternalSemaphoreProperties(
2605 VkPhysicalDevice physicalDevice
,
2606 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
2607 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
2609 TU_FROM_HANDLE(tu_physical_device
, pdev
, physicalDevice
);
2611 if (tu_has_syncobj(pdev
) &&
2612 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
2613 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
2614 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
2615 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
2616 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
2617 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
2619 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
2620 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
2621 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
2626 tu_GetPhysicalDeviceExternalFenceProperties(
2627 VkPhysicalDevice physicalDevice
,
2628 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
2629 VkExternalFenceProperties
*pExternalFenceProperties
)
2631 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
2632 pExternalFenceProperties
->compatibleHandleTypes
= 0;
2633 pExternalFenceProperties
->externalFenceFeatures
= 0;
2637 tu_CreateDebugReportCallbackEXT(
2638 VkInstance _instance
,
2639 const VkDebugReportCallbackCreateInfoEXT
*pCreateInfo
,
2640 const VkAllocationCallbacks
*pAllocator
,
2641 VkDebugReportCallbackEXT
*pCallback
)
2643 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2644 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2645 pCreateInfo
, pAllocator
,
2646 &instance
->alloc
, pCallback
);
2650 tu_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2651 VkDebugReportCallbackEXT _callback
,
2652 const VkAllocationCallbacks
*pAllocator
)
2654 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2655 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2656 _callback
, pAllocator
, &instance
->alloc
);
2660 tu_DebugReportMessageEXT(VkInstance _instance
,
2661 VkDebugReportFlagsEXT flags
,
2662 VkDebugReportObjectTypeEXT objectType
,
2665 int32_t messageCode
,
2666 const char *pLayerPrefix
,
2667 const char *pMessage
)
2669 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2670 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2671 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2675 tu_GetDeviceGroupPeerMemoryFeatures(
2678 uint32_t localDeviceIndex
,
2679 uint32_t remoteDeviceIndex
,
2680 VkPeerMemoryFeatureFlags
*pPeerMemoryFeatures
)
2682 assert(localDeviceIndex
== remoteDeviceIndex
);
2684 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2685 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2686 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2687 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
2690 void tu_GetPhysicalDeviceMultisamplePropertiesEXT(
2691 VkPhysicalDevice physicalDevice
,
2692 VkSampleCountFlagBits samples
,
2693 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
2695 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
2697 if (samples
<= VK_SAMPLE_COUNT_4_BIT
&& pdevice
->supported_extensions
.EXT_sample_locations
)
2698 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 1, 1 };
2700 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };