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"
34 #include <sys/sysinfo.h>
38 #include "compiler/glsl_types.h"
39 #include "util/debug.h"
40 #include "util/disk_cache.h"
41 #include "util/u_atomic.h"
42 #include "vk_format.h"
45 #include "drm-uapi/msm_drm.h"
47 /* for fd_get_driver/device_uuid() */
48 #include "freedreno/common/freedreno_uuid.h"
51 tu_semaphore_remove_temp(struct tu_device
*device
,
52 struct tu_semaphore
*sem
);
55 tu_device_get_cache_uuid(uint16_t family
, void *uuid
)
57 uint32_t mesa_timestamp
;
59 memset(uuid
, 0, VK_UUID_SIZE
);
60 if (!disk_cache_get_function_timestamp(tu_device_get_cache_uuid
,
64 memcpy(uuid
, &mesa_timestamp
, 4);
65 memcpy((char *) uuid
+ 4, &f
, 2);
66 snprintf((char *) uuid
+ 6, VK_UUID_SIZE
- 10, "tu");
71 tu_physical_device_init(struct tu_physical_device
*device
,
72 struct tu_instance
*instance
)
74 VkResult result
= VK_SUCCESS
;
76 memset(device
->name
, 0, sizeof(device
->name
));
77 sprintf(device
->name
, "FD%d", device
->gpu_id
);
79 device
->limited_z24s8
= (device
->gpu_id
== 630);
81 switch (device
->gpu_id
) {
83 device
->ccu_offset_gmem
= 0x7c000; /* 0x7e000 in some cases? */
84 device
->ccu_offset_bypass
= 0x10000;
85 device
->tile_align_w
= 32;
86 device
->magic
.PC_UNKNOWN_9805
= 0x0;
87 device
->magic
.SP_UNKNOWN_A0F8
= 0x0;
91 device
->ccu_offset_gmem
= 0xf8000;
92 device
->ccu_offset_bypass
= 0x20000;
93 device
->tile_align_w
= 32;
94 device
->magic
.PC_UNKNOWN_9805
= 0x1;
95 device
->magic
.SP_UNKNOWN_A0F8
= 0x1;
98 device
->ccu_offset_gmem
= 0x114000;
99 device
->ccu_offset_bypass
= 0x30000;
100 device
->tile_align_w
= 96;
101 device
->magic
.PC_UNKNOWN_9805
= 0x2;
102 device
->magic
.SP_UNKNOWN_A0F8
= 0x2;
105 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
106 "device %s is unsupported", device
->name
);
109 if (tu_device_get_cache_uuid(device
->gpu_id
, device
->cache_uuid
)) {
110 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
111 "cannot generate UUID");
115 /* The gpu id is already embedded in the uuid so we just pass "tu"
116 * when creating the cache.
118 char buf
[VK_UUID_SIZE
* 2 + 1];
119 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
120 device
->disk_cache
= disk_cache_create(device
->name
, buf
, 0);
122 fprintf(stderr
, "WARNING: tu is not a conformant vulkan implementation, "
123 "testing use only.\n");
125 fd_get_driver_uuid(device
->driver_uuid
);
126 fd_get_device_uuid(device
->device_uuid
, device
->gpu_id
);
128 tu_physical_device_get_supported_extensions(device
, &device
->supported_extensions
);
130 if (result
!= VK_SUCCESS
) {
131 vk_error(instance
, result
);
135 result
= tu_wsi_init(device
);
136 if (result
!= VK_SUCCESS
) {
137 vk_error(instance
, result
);
144 close(device
->local_fd
);
145 if (device
->master_fd
!= -1)
146 close(device
->master_fd
);
151 tu_physical_device_finish(struct tu_physical_device
*device
)
153 tu_wsi_finish(device
);
155 disk_cache_destroy(device
->disk_cache
);
156 close(device
->local_fd
);
157 if (device
->master_fd
!= -1)
158 close(device
->master_fd
);
160 vk_object_base_finish(&device
->base
);
163 static VKAPI_ATTR
void *
164 default_alloc_func(void *pUserData
,
167 VkSystemAllocationScope allocationScope
)
172 static VKAPI_ATTR
void *
173 default_realloc_func(void *pUserData
,
177 VkSystemAllocationScope allocationScope
)
179 return realloc(pOriginal
, size
);
182 static VKAPI_ATTR
void
183 default_free_func(void *pUserData
, void *pMemory
)
188 static const VkAllocationCallbacks default_alloc
= {
190 .pfnAllocation
= default_alloc_func
,
191 .pfnReallocation
= default_realloc_func
,
192 .pfnFree
= default_free_func
,
195 static const struct debug_control tu_debug_options
[] = {
196 { "startup", TU_DEBUG_STARTUP
},
197 { "nir", TU_DEBUG_NIR
},
198 { "ir3", TU_DEBUG_IR3
},
199 { "nobin", TU_DEBUG_NOBIN
},
200 { "sysmem", TU_DEBUG_SYSMEM
},
201 { "forcebin", TU_DEBUG_FORCEBIN
},
202 { "noubwc", TU_DEBUG_NOUBWC
},
207 tu_get_debug_option_name(int id
)
209 assert(id
< ARRAY_SIZE(tu_debug_options
) - 1);
210 return tu_debug_options
[id
].string
;
214 tu_get_instance_extension_index(const char *name
)
216 for (unsigned i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; ++i
) {
217 if (strcmp(name
, tu_instance_extensions
[i
].extensionName
) == 0)
224 tu_CreateInstance(const VkInstanceCreateInfo
*pCreateInfo
,
225 const VkAllocationCallbacks
*pAllocator
,
226 VkInstance
*pInstance
)
228 struct tu_instance
*instance
;
231 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
233 uint32_t client_version
;
234 if (pCreateInfo
->pApplicationInfo
&&
235 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
236 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
238 tu_EnumerateInstanceVersion(&client_version
);
241 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
242 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
245 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
247 vk_object_base_init(NULL
, &instance
->base
, VK_OBJECT_TYPE_INSTANCE
);
250 instance
->alloc
= *pAllocator
;
252 instance
->alloc
= default_alloc
;
254 instance
->api_version
= client_version
;
255 instance
->physical_device_count
= -1;
257 instance
->debug_flags
=
258 parse_debug_string(getenv("TU_DEBUG"), tu_debug_options
);
260 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
261 tu_logi("Created an instance");
263 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
264 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
265 int index
= tu_get_instance_extension_index(ext_name
);
267 if (index
< 0 || !tu_instance_extensions_supported
.extensions
[index
]) {
268 vk_object_base_finish(&instance
->base
);
269 vk_free2(&default_alloc
, pAllocator
, instance
);
270 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
273 instance
->enabled_extensions
.extensions
[index
] = true;
276 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
277 if (result
!= VK_SUCCESS
) {
278 vk_object_base_finish(&instance
->base
);
279 vk_free2(&default_alloc
, pAllocator
, instance
);
280 return vk_error(instance
, result
);
283 glsl_type_singleton_init_or_ref();
285 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
287 *pInstance
= tu_instance_to_handle(instance
);
293 tu_DestroyInstance(VkInstance _instance
,
294 const VkAllocationCallbacks
*pAllocator
)
296 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
301 for (int i
= 0; i
< instance
->physical_device_count
; ++i
) {
302 tu_physical_device_finish(instance
->physical_devices
+ i
);
305 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
307 glsl_type_singleton_decref();
309 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
311 vk_object_base_finish(&instance
->base
);
312 vk_free(&instance
->alloc
, instance
);
316 tu_EnumeratePhysicalDevices(VkInstance _instance
,
317 uint32_t *pPhysicalDeviceCount
,
318 VkPhysicalDevice
*pPhysicalDevices
)
320 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
321 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
325 if (instance
->physical_device_count
< 0) {
326 result
= tu_enumerate_devices(instance
);
327 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
331 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
332 vk_outarray_append(&out
, p
)
334 *p
= tu_physical_device_to_handle(instance
->physical_devices
+ i
);
338 return vk_outarray_status(&out
);
342 tu_EnumeratePhysicalDeviceGroups(
343 VkInstance _instance
,
344 uint32_t *pPhysicalDeviceGroupCount
,
345 VkPhysicalDeviceGroupProperties
*pPhysicalDeviceGroupProperties
)
347 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
348 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
349 pPhysicalDeviceGroupCount
);
352 if (instance
->physical_device_count
< 0) {
353 result
= tu_enumerate_devices(instance
);
354 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
358 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
359 vk_outarray_append(&out
, p
)
361 p
->physicalDeviceCount
= 1;
362 p
->physicalDevices
[0] =
363 tu_physical_device_to_handle(instance
->physical_devices
+ i
);
364 p
->subsetAllocation
= false;
368 return vk_outarray_status(&out
);
372 tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice
,
373 VkPhysicalDeviceFeatures
*pFeatures
)
375 memset(pFeatures
, 0, sizeof(*pFeatures
));
377 *pFeatures
= (VkPhysicalDeviceFeatures
) {
378 .robustBufferAccess
= true,
379 .fullDrawIndexUint32
= true,
380 .imageCubeArray
= true,
381 .independentBlend
= true,
382 .geometryShader
= true,
383 .tessellationShader
= true,
384 .sampleRateShading
= true,
385 .dualSrcBlend
= true,
387 .multiDrawIndirect
= true,
388 .drawIndirectFirstInstance
= true,
390 .depthBiasClamp
= true,
391 .fillModeNonSolid
= true,
396 .multiViewport
= false,
397 .samplerAnisotropy
= true,
398 .textureCompressionETC2
= true,
399 .textureCompressionASTC_LDR
= true,
400 .textureCompressionBC
= true,
401 .occlusionQueryPrecise
= true,
402 .pipelineStatisticsQuery
= false,
403 .vertexPipelineStoresAndAtomics
= true,
404 .fragmentStoresAndAtomics
= true,
405 .shaderTessellationAndGeometryPointSize
= false,
406 .shaderImageGatherExtended
= false,
407 .shaderStorageImageExtendedFormats
= false,
408 .shaderStorageImageMultisample
= false,
409 .shaderUniformBufferArrayDynamicIndexing
= true,
410 .shaderSampledImageArrayDynamicIndexing
= true,
411 .shaderStorageBufferArrayDynamicIndexing
= true,
412 .shaderStorageImageArrayDynamicIndexing
= true,
413 .shaderStorageImageReadWithoutFormat
= false,
414 .shaderStorageImageWriteWithoutFormat
= false,
415 .shaderClipDistance
= false,
416 .shaderCullDistance
= false,
417 .shaderFloat64
= false,
418 .shaderInt64
= false,
419 .shaderInt16
= false,
420 .sparseBinding
= false,
421 .variableMultisampleRate
= false,
422 .inheritedQueries
= false,
427 tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice
,
428 VkPhysicalDeviceFeatures2
*pFeatures
)
430 vk_foreach_struct(ext
, pFeatures
->pNext
)
432 switch (ext
->sType
) {
433 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
: {
434 VkPhysicalDeviceVulkan11Features
*features
= (void *) ext
;
435 features
->storageBuffer16BitAccess
= false;
436 features
->uniformAndStorageBuffer16BitAccess
= false;
437 features
->storagePushConstant16
= false;
438 features
->storageInputOutput16
= false;
439 features
->multiview
= false;
440 features
->multiviewGeometryShader
= false;
441 features
->multiviewTessellationShader
= false;
442 features
->variablePointersStorageBuffer
= true;
443 features
->variablePointers
= true;
444 features
->protectedMemory
= false;
445 features
->samplerYcbcrConversion
= true;
446 features
->shaderDrawParameters
= true;
449 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
: {
450 VkPhysicalDeviceVulkan12Features
*features
= (void *) ext
;
451 features
->samplerMirrorClampToEdge
= true;
452 features
->drawIndirectCount
= true;
453 features
->storageBuffer8BitAccess
= false;
454 features
->uniformAndStorageBuffer8BitAccess
= false;
455 features
->storagePushConstant8
= false;
456 features
->shaderBufferInt64Atomics
= false;
457 features
->shaderSharedInt64Atomics
= false;
458 features
->shaderFloat16
= false;
459 features
->shaderInt8
= false;
461 features
->descriptorIndexing
= false;
462 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
463 features
->shaderUniformTexelBufferArrayDynamicIndexing
= false;
464 features
->shaderStorageTexelBufferArrayDynamicIndexing
= false;
465 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
466 features
->shaderSampledImageArrayNonUniformIndexing
= false;
467 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
468 features
->shaderStorageImageArrayNonUniformIndexing
= false;
469 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
470 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
471 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
472 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
473 features
->descriptorBindingSampledImageUpdateAfterBind
= false;
474 features
->descriptorBindingStorageImageUpdateAfterBind
= false;
475 features
->descriptorBindingStorageBufferUpdateAfterBind
= false;
476 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= false;
477 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= false;
478 features
->descriptorBindingUpdateUnusedWhilePending
= false;
479 features
->descriptorBindingPartiallyBound
= false;
480 features
->descriptorBindingVariableDescriptorCount
= false;
481 features
->runtimeDescriptorArray
= false;
483 features
->samplerFilterMinmax
= true;
484 features
->scalarBlockLayout
= false;
485 features
->imagelessFramebuffer
= false;
486 features
->uniformBufferStandardLayout
= false;
487 features
->shaderSubgroupExtendedTypes
= false;
488 features
->separateDepthStencilLayouts
= false;
489 features
->hostQueryReset
= false;
490 features
->timelineSemaphore
= false;
491 features
->bufferDeviceAddress
= false;
492 features
->bufferDeviceAddressCaptureReplay
= false;
493 features
->bufferDeviceAddressMultiDevice
= false;
494 features
->vulkanMemoryModel
= false;
495 features
->vulkanMemoryModelDeviceScope
= false;
496 features
->vulkanMemoryModelAvailabilityVisibilityChains
= false;
497 features
->shaderOutputViewportIndex
= false;
498 features
->shaderOutputLayer
= false;
499 features
->subgroupBroadcastDynamicId
= false;
502 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
503 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *) ext
;
504 features
->variablePointersStorageBuffer
= true;
505 features
->variablePointers
= true;
508 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
509 VkPhysicalDeviceMultiviewFeatures
*features
=
510 (VkPhysicalDeviceMultiviewFeatures
*) ext
;
511 features
->multiview
= false;
512 features
->multiviewGeometryShader
= false;
513 features
->multiviewTessellationShader
= false;
516 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
517 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
518 (VkPhysicalDeviceShaderDrawParametersFeatures
*) ext
;
519 features
->shaderDrawParameters
= true;
522 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
523 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
524 (VkPhysicalDeviceProtectedMemoryFeatures
*) ext
;
525 features
->protectedMemory
= false;
528 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
529 VkPhysicalDevice16BitStorageFeatures
*features
=
530 (VkPhysicalDevice16BitStorageFeatures
*) ext
;
531 features
->storageBuffer16BitAccess
= false;
532 features
->uniformAndStorageBuffer16BitAccess
= false;
533 features
->storagePushConstant16
= false;
534 features
->storageInputOutput16
= false;
537 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
538 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
539 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
540 features
->samplerYcbcrConversion
= true;
543 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
544 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
545 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*) ext
;
546 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
547 features
->shaderUniformTexelBufferArrayDynamicIndexing
= false;
548 features
->shaderStorageTexelBufferArrayDynamicIndexing
= false;
549 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
550 features
->shaderSampledImageArrayNonUniformIndexing
= false;
551 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
552 features
->shaderStorageImageArrayNonUniformIndexing
= false;
553 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
554 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
555 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
556 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
557 features
->descriptorBindingSampledImageUpdateAfterBind
= false;
558 features
->descriptorBindingStorageImageUpdateAfterBind
= false;
559 features
->descriptorBindingStorageBufferUpdateAfterBind
= false;
560 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= false;
561 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= false;
562 features
->descriptorBindingUpdateUnusedWhilePending
= false;
563 features
->descriptorBindingPartiallyBound
= false;
564 features
->descriptorBindingVariableDescriptorCount
= false;
565 features
->runtimeDescriptorArray
= false;
568 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
569 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
570 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*) ext
;
571 features
->conditionalRendering
= true;
572 features
->inheritedConditionalRendering
= true;
575 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
576 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
577 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*) ext
;
578 features
->transformFeedback
= true;
579 features
->geometryStreams
= false;
582 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
583 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
584 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
585 features
->indexTypeUint8
= true;
588 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
589 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
590 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
591 features
->vertexAttributeInstanceRateDivisor
= true;
592 features
->vertexAttributeInstanceRateZeroDivisor
= true;
595 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT
: {
596 VkPhysicalDevicePrivateDataFeaturesEXT
*features
=
597 (VkPhysicalDevicePrivateDataFeaturesEXT
*)ext
;
598 features
->privateData
= true;
601 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
602 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
603 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
604 features
->depthClipEnable
= true;
607 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT
: {
608 VkPhysicalDevice4444FormatsFeaturesEXT
*features
= (void *)ext
;
609 features
->formatA4R4G4B4
= true;
610 features
->formatA4B4G4R4
= true;
617 return tu_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
621 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
622 VkPhysicalDeviceProperties
*pProperties
)
624 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
625 VkSampleCountFlags sample_counts
=
626 VK_SAMPLE_COUNT_1_BIT
| VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
;
628 /* I have no idea what the maximum size is, but the hardware supports very
629 * large numbers of descriptors (at least 2^16). This limit is based on
630 * CP_LOAD_STATE6, which has a 28-bit field for the DWORD offset, so that
631 * we don't have to think about what to do if that overflows, but really
632 * nothing is likely to get close to this.
634 const size_t max_descriptor_set_size
= (1 << 28) / A6XX_TEX_CONST_DWORDS
;
636 VkPhysicalDeviceLimits limits
= {
637 .maxImageDimension1D
= (1 << 14),
638 .maxImageDimension2D
= (1 << 14),
639 .maxImageDimension3D
= (1 << 11),
640 .maxImageDimensionCube
= (1 << 14),
641 .maxImageArrayLayers
= (1 << 11),
642 .maxTexelBufferElements
= 128 * 1024 * 1024,
643 .maxUniformBufferRange
= MAX_UNIFORM_BUFFER_RANGE
,
644 .maxStorageBufferRange
= MAX_STORAGE_BUFFER_RANGE
,
645 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
646 .maxMemoryAllocationCount
= UINT32_MAX
,
647 .maxSamplerAllocationCount
= 64 * 1024,
648 .bufferImageGranularity
= 64, /* A cache line */
649 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
650 .maxBoundDescriptorSets
= MAX_SETS
,
651 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
652 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
653 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
654 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
655 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
656 .maxPerStageDescriptorInputAttachments
= MAX_RTS
,
657 .maxPerStageResources
= max_descriptor_set_size
,
658 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
659 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
660 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
661 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
662 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
663 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
664 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
665 .maxDescriptorSetInputAttachments
= MAX_RTS
,
666 .maxVertexInputAttributes
= 32,
667 .maxVertexInputBindings
= 32,
668 .maxVertexInputAttributeOffset
= 4095,
669 .maxVertexInputBindingStride
= 2048,
670 .maxVertexOutputComponents
= 128,
671 .maxTessellationGenerationLevel
= 64,
672 .maxTessellationPatchSize
= 32,
673 .maxTessellationControlPerVertexInputComponents
= 128,
674 .maxTessellationControlPerVertexOutputComponents
= 128,
675 .maxTessellationControlPerPatchOutputComponents
= 120,
676 .maxTessellationControlTotalOutputComponents
= 4096,
677 .maxTessellationEvaluationInputComponents
= 128,
678 .maxTessellationEvaluationOutputComponents
= 128,
679 .maxGeometryShaderInvocations
= 32,
680 .maxGeometryInputComponents
= 64,
681 .maxGeometryOutputComponents
= 128,
682 .maxGeometryOutputVertices
= 256,
683 .maxGeometryTotalOutputComponents
= 1024,
684 .maxFragmentInputComponents
= 124,
685 .maxFragmentOutputAttachments
= 8,
686 .maxFragmentDualSrcAttachments
= 1,
687 .maxFragmentCombinedOutputResources
= 8,
688 .maxComputeSharedMemorySize
= 32768,
689 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
690 .maxComputeWorkGroupInvocations
= 2048,
691 .maxComputeWorkGroupSize
= { 2048, 2048, 2048 },
692 .subPixelPrecisionBits
= 8,
693 .subTexelPrecisionBits
= 8,
694 .mipmapPrecisionBits
= 8,
695 .maxDrawIndexedIndexValue
= UINT32_MAX
,
696 .maxDrawIndirectCount
= UINT32_MAX
,
697 .maxSamplerLodBias
= 4095.0 / 256.0, /* [-16, 15.99609375] */
698 .maxSamplerAnisotropy
= 16,
699 .maxViewports
= MAX_VIEWPORTS
,
700 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
701 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
702 .viewportSubPixelBits
= 8,
703 .minMemoryMapAlignment
= 4096, /* A page */
704 .minTexelBufferOffsetAlignment
= 64,
705 .minUniformBufferOffsetAlignment
= 64,
706 .minStorageBufferOffsetAlignment
= 64,
707 .minTexelOffset
= -16,
708 .maxTexelOffset
= 15,
709 .minTexelGatherOffset
= -32,
710 .maxTexelGatherOffset
= 31,
711 .minInterpolationOffset
= -0.5,
712 .maxInterpolationOffset
= 0.4375,
713 .subPixelInterpolationOffsetBits
= 4,
714 .maxFramebufferWidth
= (1 << 14),
715 .maxFramebufferHeight
= (1 << 14),
716 .maxFramebufferLayers
= (1 << 10),
717 .framebufferColorSampleCounts
= sample_counts
,
718 .framebufferDepthSampleCounts
= sample_counts
,
719 .framebufferStencilSampleCounts
= sample_counts
,
720 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
721 .maxColorAttachments
= MAX_RTS
,
722 .sampledImageColorSampleCounts
= sample_counts
,
723 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
724 .sampledImageDepthSampleCounts
= sample_counts
,
725 .sampledImageStencilSampleCounts
= sample_counts
,
726 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
727 .maxSampleMaskWords
= 1,
728 .timestampComputeAndGraphics
= true,
729 .timestampPeriod
= 1000000000.0 / 19200000.0, /* CP_ALWAYS_ON_COUNTER is fixed 19.2MHz */
730 .maxClipDistances
= 8,
731 .maxCullDistances
= 8,
732 .maxCombinedClipAndCullDistances
= 8,
733 .discreteQueuePriorities
= 1,
734 .pointSizeRange
= { 1, 4092 },
735 .lineWidthRange
= { 0.0, 7.9921875 },
736 .pointSizeGranularity
= 0.0625,
737 .lineWidthGranularity
= (1.0 / 128.0),
738 .strictLines
= false, /* FINISHME */
739 .standardSampleLocations
= true,
740 .optimalBufferCopyOffsetAlignment
= 128,
741 .optimalBufferCopyRowPitchAlignment
= 128,
742 .nonCoherentAtomSize
= 64,
745 *pProperties
= (VkPhysicalDeviceProperties
) {
746 .apiVersion
= tu_physical_device_api_version(pdevice
),
747 .driverVersion
= vk_get_driver_version(),
748 .vendorID
= 0, /* TODO */
750 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
752 .sparseProperties
= { 0 },
755 strcpy(pProperties
->deviceName
, pdevice
->name
);
756 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
760 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice
,
761 VkPhysicalDeviceProperties2
*pProperties
)
763 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
764 tu_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
766 vk_foreach_struct(ext
, pProperties
->pNext
)
768 switch (ext
->sType
) {
769 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
770 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
771 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
772 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
775 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
776 VkPhysicalDeviceIDProperties
*properties
=
777 (VkPhysicalDeviceIDProperties
*) ext
;
778 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
779 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
780 properties
->deviceLUIDValid
= false;
783 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
784 VkPhysicalDeviceMultiviewProperties
*properties
=
785 (VkPhysicalDeviceMultiviewProperties
*) ext
;
786 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
787 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
790 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
791 VkPhysicalDevicePointClippingProperties
*properties
=
792 (VkPhysicalDevicePointClippingProperties
*) ext
;
793 properties
->pointClippingBehavior
=
794 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
797 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
798 VkPhysicalDeviceMaintenance3Properties
*properties
=
799 (VkPhysicalDeviceMaintenance3Properties
*) ext
;
800 /* Make sure everything is addressable by a signed 32-bit int, and
801 * our largest descriptors are 96 bytes. */
802 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
803 /* Our buffer size fields allow only this much */
804 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
807 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
808 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
809 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
811 properties
->maxTransformFeedbackStreams
= IR3_MAX_SO_STREAMS
;
812 properties
->maxTransformFeedbackBuffers
= IR3_MAX_SO_BUFFERS
;
813 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
814 properties
->maxTransformFeedbackStreamDataSize
= 512;
815 properties
->maxTransformFeedbackBufferDataSize
= 512;
816 properties
->maxTransformFeedbackBufferDataStride
= 512;
817 properties
->transformFeedbackQueries
= true;
818 properties
->transformFeedbackStreamsLinesTriangles
= false;
819 properties
->transformFeedbackRasterizationStreamSelect
= false;
820 properties
->transformFeedbackDraw
= true;
823 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
824 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
825 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
826 properties
->sampleLocationSampleCounts
= 0;
827 if (pdevice
->supported_extensions
.EXT_sample_locations
) {
828 properties
->sampleLocationSampleCounts
=
829 VK_SAMPLE_COUNT_1_BIT
| VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
;
831 properties
->maxSampleLocationGridSize
= (VkExtent2D
) { 1 , 1 };
832 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
833 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
834 properties
->sampleLocationSubPixelBits
= 4;
835 properties
->variableSampleLocations
= true;
838 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES
: {
839 VkPhysicalDeviceSamplerFilterMinmaxProperties
*properties
=
840 (VkPhysicalDeviceSamplerFilterMinmaxProperties
*)ext
;
841 properties
->filterMinmaxImageComponentMapping
= true;
842 properties
->filterMinmaxSingleComponentFormats
= true;
845 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
846 VkPhysicalDeviceSubgroupProperties
*properties
=
847 (VkPhysicalDeviceSubgroupProperties
*)ext
;
848 properties
->subgroupSize
= 64;
849 properties
->supportedStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
850 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
851 VK_SUBGROUP_FEATURE_VOTE_BIT
;
852 properties
->quadOperationsInAllStages
= false;
855 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
856 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*props
=
857 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
858 props
->maxVertexAttribDivisor
= UINT32_MAX
;
867 static const VkQueueFamilyProperties tu_queue_family_properties
= {
869 VK_QUEUE_GRAPHICS_BIT
| VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
871 .timestampValidBits
= 48,
872 .minImageTransferGranularity
= { 1, 1, 1 },
876 tu_GetPhysicalDeviceQueueFamilyProperties(
877 VkPhysicalDevice physicalDevice
,
878 uint32_t *pQueueFamilyPropertyCount
,
879 VkQueueFamilyProperties
*pQueueFamilyProperties
)
881 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
883 vk_outarray_append(&out
, p
) { *p
= tu_queue_family_properties
; }
887 tu_GetPhysicalDeviceQueueFamilyProperties2(
888 VkPhysicalDevice physicalDevice
,
889 uint32_t *pQueueFamilyPropertyCount
,
890 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
892 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
894 vk_outarray_append(&out
, p
)
896 p
->queueFamilyProperties
= tu_queue_family_properties
;
901 tu_get_system_heap_size()
906 uint64_t total_ram
= (uint64_t) info
.totalram
* (uint64_t) info
.mem_unit
;
908 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
909 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
911 uint64_t available_ram
;
912 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
913 available_ram
= total_ram
/ 2;
915 available_ram
= total_ram
* 3 / 4;
917 return available_ram
;
921 tu_GetPhysicalDeviceMemoryProperties(
922 VkPhysicalDevice physicalDevice
,
923 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
925 pMemoryProperties
->memoryHeapCount
= 1;
926 pMemoryProperties
->memoryHeaps
[0].size
= tu_get_system_heap_size();
927 pMemoryProperties
->memoryHeaps
[0].flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
;
929 pMemoryProperties
->memoryTypeCount
= 1;
930 pMemoryProperties
->memoryTypes
[0].propertyFlags
=
931 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
932 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
933 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
;
934 pMemoryProperties
->memoryTypes
[0].heapIndex
= 0;
938 tu_GetPhysicalDeviceMemoryProperties2(
939 VkPhysicalDevice physicalDevice
,
940 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
942 return tu_GetPhysicalDeviceMemoryProperties(
943 physicalDevice
, &pMemoryProperties
->memoryProperties
);
947 tu_queue_init(struct tu_device
*device
,
948 struct tu_queue
*queue
,
949 uint32_t queue_family_index
,
951 VkDeviceQueueCreateFlags flags
)
953 vk_object_base_init(&device
->vk
, &queue
->base
, VK_OBJECT_TYPE_QUEUE
);
955 queue
->device
= device
;
956 queue
->queue_family_index
= queue_family_index
;
957 queue
->queue_idx
= idx
;
958 queue
->flags
= flags
;
960 int ret
= tu_drm_submitqueue_new(device
, 0, &queue
->msm_queue_id
);
962 return VK_ERROR_INITIALIZATION_FAILED
;
964 tu_fence_init(&queue
->submit_fence
, false);
970 tu_queue_finish(struct tu_queue
*queue
)
972 tu_fence_finish(&queue
->submit_fence
);
973 tu_drm_submitqueue_close(queue
->device
, queue
->msm_queue_id
);
977 tu_get_device_extension_index(const char *name
)
979 for (unsigned i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; ++i
) {
980 if (strcmp(name
, tu_device_extensions
[i
].extensionName
) == 0)
986 struct PACKED bcolor_entry
{
998 uint32_t z24
; /* also s8? */
999 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
1001 } border_color
[] = {
1002 [VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
] = {},
1003 [VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
] = {},
1004 [VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
] = {
1005 .fp32
[3] = 0x3f800000,
1013 .rgb10a2
= 0xc0000000,
1016 [VK_BORDER_COLOR_INT_OPAQUE_BLACK
] = {
1020 [VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
] = {
1021 .fp32
[0 ... 3] = 0x3f800000,
1022 .ui16
[0 ... 3] = 0xffff,
1023 .si16
[0 ... 3] = 0x7fff,
1024 .fp16
[0 ... 3] = 0x3c00,
1028 .ui8
[0 ... 3] = 0xff,
1029 .si8
[0 ... 3] = 0x7f,
1030 .rgb10a2
= 0xffffffff,
1032 .srgb
[0 ... 3] = 0x3c00,
1034 [VK_BORDER_COLOR_INT_OPAQUE_WHITE
] = {
1041 tu_CreateDevice(VkPhysicalDevice physicalDevice
,
1042 const VkDeviceCreateInfo
*pCreateInfo
,
1043 const VkAllocationCallbacks
*pAllocator
,
1046 TU_FROM_HANDLE(tu_physical_device
, physical_device
, physicalDevice
);
1048 struct tu_device
*device
;
1050 /* Check enabled features */
1051 if (pCreateInfo
->pEnabledFeatures
) {
1052 VkPhysicalDeviceFeatures supported_features
;
1053 tu_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1054 VkBool32
*supported_feature
= (VkBool32
*) &supported_features
;
1055 VkBool32
*enabled_feature
= (VkBool32
*) pCreateInfo
->pEnabledFeatures
;
1056 unsigned num_features
=
1057 sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1058 for (uint32_t i
= 0; i
< num_features
; i
++) {
1059 if (enabled_feature
[i
] && !supported_feature
[i
])
1060 return vk_error(physical_device
->instance
,
1061 VK_ERROR_FEATURE_NOT_PRESENT
);
1065 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1066 sizeof(*device
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1068 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1070 vk_device_init(&device
->vk
, pCreateInfo
,
1071 &physical_device
->instance
->alloc
, pAllocator
);
1073 device
->instance
= physical_device
->instance
;
1074 device
->physical_device
= physical_device
;
1075 device
->_lost
= false;
1077 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1078 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1079 int index
= tu_get_device_extension_index(ext_name
);
1081 !physical_device
->supported_extensions
.extensions
[index
]) {
1082 vk_free(&device
->vk
.alloc
, device
);
1083 return vk_error(physical_device
->instance
,
1084 VK_ERROR_EXTENSION_NOT_PRESENT
);
1087 device
->enabled_extensions
.extensions
[index
] = true;
1090 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1091 const VkDeviceQueueCreateInfo
*queue_create
=
1092 &pCreateInfo
->pQueueCreateInfos
[i
];
1093 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1094 device
->queues
[qfi
] = vk_alloc(
1095 &device
->vk
.alloc
, queue_create
->queueCount
* sizeof(struct tu_queue
),
1096 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1097 if (!device
->queues
[qfi
]) {
1098 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1102 memset(device
->queues
[qfi
], 0,
1103 queue_create
->queueCount
* sizeof(struct tu_queue
));
1105 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1107 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1108 result
= tu_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
,
1109 queue_create
->flags
);
1110 if (result
!= VK_SUCCESS
)
1115 device
->compiler
= ir3_compiler_create(NULL
, physical_device
->gpu_id
);
1116 if (!device
->compiler
)
1119 /* initial sizes, these will increase if there is overflow */
1120 device
->vsc_draw_strm_pitch
= 0x1000 + VSC_PAD
;
1121 device
->vsc_prim_strm_pitch
= 0x4000 + VSC_PAD
;
1123 STATIC_ASSERT(sizeof(border_color
) == sizeof(((struct tu6_global
*) 0)->border_color
));
1124 result
= tu_bo_init_new(device
, &device
->global_bo
, sizeof(struct tu6_global
));
1125 if (result
!= VK_SUCCESS
)
1126 goto fail_global_bo
;
1128 result
= tu_bo_map(device
, &device
->global_bo
);
1129 if (result
!= VK_SUCCESS
)
1130 goto fail_global_bo_map
;
1132 struct tu6_global
*global
= device
->global_bo
.map
;
1133 memcpy(global
->border_color
, border_color
, sizeof(border_color
));
1134 global
->predicate
= 0;
1135 tu_init_clear_blit_shaders(global
);
1137 VkPipelineCacheCreateInfo ci
;
1138 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1141 ci
.pInitialData
= NULL
;
1142 ci
.initialDataSize
= 0;
1145 tu_CreatePipelineCache(tu_device_to_handle(device
), &ci
, NULL
, &pc
);
1146 if (result
!= VK_SUCCESS
)
1147 goto fail_pipeline_cache
;
1149 device
->mem_cache
= tu_pipeline_cache_from_handle(pc
);
1151 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->scratch_bos
); i
++)
1152 mtx_init(&device
->scratch_bos
[i
].construct_mtx
, mtx_plain
);
1154 mtx_init(&device
->vsc_pitch_mtx
, mtx_plain
);
1156 *pDevice
= tu_device_to_handle(device
);
1159 fail_pipeline_cache
:
1161 tu_bo_finish(device
, &device
->global_bo
);
1164 ralloc_free(device
->compiler
);
1167 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1168 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1169 tu_queue_finish(&device
->queues
[i
][q
]);
1170 if (device
->queue_count
[i
])
1171 vk_object_free(&device
->vk
, NULL
, device
->queues
[i
]);
1174 vk_free(&device
->vk
.alloc
, device
);
1179 tu_DestroyDevice(VkDevice _device
, const VkAllocationCallbacks
*pAllocator
)
1181 TU_FROM_HANDLE(tu_device
, device
, _device
);
1186 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1187 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1188 tu_queue_finish(&device
->queues
[i
][q
]);
1189 if (device
->queue_count
[i
])
1190 vk_object_free(&device
->vk
, NULL
, device
->queues
[i
]);
1193 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->scratch_bos
); i
++) {
1194 if (device
->scratch_bos
[i
].initialized
)
1195 tu_bo_finish(device
, &device
->scratch_bos
[i
].bo
);
1198 ir3_compiler_destroy(device
->compiler
);
1200 VkPipelineCache pc
= tu_pipeline_cache_to_handle(device
->mem_cache
);
1201 tu_DestroyPipelineCache(tu_device_to_handle(device
), pc
, NULL
);
1203 vk_free(&device
->vk
.alloc
, device
);
1207 _tu_device_set_lost(struct tu_device
*device
,
1208 const char *file
, int line
,
1209 const char *msg
, ...)
1211 /* Set the flag indicating that waits should return in finite time even
1212 * after device loss.
1214 p_atomic_inc(&device
->_lost
);
1216 /* TODO: Report the log message through VkDebugReportCallbackEXT instead */
1217 fprintf(stderr
, "%s:%d: ", file
, line
);
1220 vfprintf(stderr
, msg
, ap
);
1223 if (env_var_as_boolean("TU_ABORT_ON_DEVICE_LOSS", false))
1226 return VK_ERROR_DEVICE_LOST
;
1230 tu_get_scratch_bo(struct tu_device
*dev
, uint64_t size
, struct tu_bo
**bo
)
1232 unsigned size_log2
= MAX2(util_logbase2_ceil64(size
), MIN_SCRATCH_BO_SIZE_LOG2
);
1233 unsigned index
= size_log2
- MIN_SCRATCH_BO_SIZE_LOG2
;
1234 assert(index
< ARRAY_SIZE(dev
->scratch_bos
));
1236 for (unsigned i
= index
; i
< ARRAY_SIZE(dev
->scratch_bos
); i
++) {
1237 if (p_atomic_read(&dev
->scratch_bos
[i
].initialized
)) {
1238 /* Fast path: just return the already-allocated BO. */
1239 *bo
= &dev
->scratch_bos
[i
].bo
;
1244 /* Slow path: actually allocate the BO. We take a lock because the process
1245 * of allocating it is slow, and we don't want to block the CPU while it
1248 mtx_lock(&dev
->scratch_bos
[index
].construct_mtx
);
1250 /* Another thread may have allocated it already while we were waiting on
1251 * the lock. We need to check this in order to avoid double-allocating.
1253 if (dev
->scratch_bos
[index
].initialized
) {
1254 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1255 *bo
= &dev
->scratch_bos
[index
].bo
;
1259 unsigned bo_size
= 1ull << size_log2
;
1260 VkResult result
= tu_bo_init_new(dev
, &dev
->scratch_bos
[index
].bo
, bo_size
);
1261 if (result
!= VK_SUCCESS
) {
1262 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1266 p_atomic_set(&dev
->scratch_bos
[index
].initialized
, true);
1268 mtx_unlock(&dev
->scratch_bos
[index
].construct_mtx
);
1270 *bo
= &dev
->scratch_bos
[index
].bo
;
1275 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount
,
1276 VkLayerProperties
*pProperties
)
1278 *pPropertyCount
= 0;
1283 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice
,
1284 uint32_t *pPropertyCount
,
1285 VkLayerProperties
*pProperties
)
1287 *pPropertyCount
= 0;
1292 tu_GetDeviceQueue2(VkDevice _device
,
1293 const VkDeviceQueueInfo2
*pQueueInfo
,
1296 TU_FROM_HANDLE(tu_device
, device
, _device
);
1297 struct tu_queue
*queue
;
1300 &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1301 if (pQueueInfo
->flags
!= queue
->flags
) {
1302 /* From the Vulkan 1.1.70 spec:
1304 * "The queue returned by vkGetDeviceQueue2 must have the same
1305 * flags value from this structure as that used at device
1306 * creation time in a VkDeviceQueueCreateInfo instance. If no
1307 * matching flags were specified at device creation time then
1308 * pQueue will return VK_NULL_HANDLE."
1310 *pQueue
= VK_NULL_HANDLE
;
1314 *pQueue
= tu_queue_to_handle(queue
);
1318 tu_GetDeviceQueue(VkDevice _device
,
1319 uint32_t queueFamilyIndex
,
1320 uint32_t queueIndex
,
1323 const VkDeviceQueueInfo2 info
=
1324 (VkDeviceQueueInfo2
) { .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1325 .queueFamilyIndex
= queueFamilyIndex
,
1326 .queueIndex
= queueIndex
};
1328 tu_GetDeviceQueue2(_device
, &info
, pQueue
);
1332 tu_get_semaphore_syncobjs(const VkSemaphore
*sems
,
1335 struct drm_msm_gem_submit_syncobj
**out
,
1336 uint32_t *out_count
)
1338 uint32_t syncobj_count
= 0;
1339 struct drm_msm_gem_submit_syncobj
*syncobjs
;
1341 for (uint32_t i
= 0; i
< sem_count
; ++i
) {
1342 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1344 struct tu_semaphore_part
*part
=
1345 sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
?
1346 &sem
->temporary
: &sem
->permanent
;
1348 if (part
->kind
== TU_SEMAPHORE_SYNCOBJ
)
1353 *out_count
= syncobj_count
;
1357 *out
= syncobjs
= calloc(syncobj_count
, sizeof (*syncobjs
));
1359 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1361 for (uint32_t i
= 0, j
= 0; i
< sem_count
; ++i
) {
1362 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1364 struct tu_semaphore_part
*part
=
1365 sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
?
1366 &sem
->temporary
: &sem
->permanent
;
1368 if (part
->kind
== TU_SEMAPHORE_SYNCOBJ
) {
1369 syncobjs
[j
].handle
= part
->syncobj
;
1370 syncobjs
[j
].flags
= wait
? MSM_SUBMIT_SYNCOBJ_RESET
: 0;
1380 tu_semaphores_remove_temp(struct tu_device
*device
,
1381 const VkSemaphore
*sems
,
1384 for (uint32_t i
= 0; i
< sem_count
; ++i
) {
1385 TU_FROM_HANDLE(tu_semaphore
, sem
, sems
[i
]);
1386 tu_semaphore_remove_temp(device
, sem
);
1391 tu_QueueSubmit(VkQueue _queue
,
1392 uint32_t submitCount
,
1393 const VkSubmitInfo
*pSubmits
,
1396 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1399 for (uint32_t i
= 0; i
< submitCount
; ++i
) {
1400 const VkSubmitInfo
*submit
= pSubmits
+ i
;
1401 const bool last_submit
= (i
== submitCount
- 1);
1402 struct drm_msm_gem_submit_syncobj
*in_syncobjs
= NULL
, *out_syncobjs
= NULL
;
1403 uint32_t nr_in_syncobjs
, nr_out_syncobjs
;
1404 struct tu_bo_list bo_list
;
1405 tu_bo_list_init(&bo_list
);
1407 result
= tu_get_semaphore_syncobjs(pSubmits
[i
].pWaitSemaphores
,
1408 pSubmits
[i
].waitSemaphoreCount
,
1409 false, &in_syncobjs
, &nr_in_syncobjs
);
1410 if (result
!= VK_SUCCESS
) {
1411 return tu_device_set_lost(queue
->device
,
1412 "failed to allocate space for semaphore submission\n");
1415 result
= tu_get_semaphore_syncobjs(pSubmits
[i
].pSignalSemaphores
,
1416 pSubmits
[i
].signalSemaphoreCount
,
1417 false, &out_syncobjs
, &nr_out_syncobjs
);
1418 if (result
!= VK_SUCCESS
) {
1420 return tu_device_set_lost(queue
->device
,
1421 "failed to allocate space for semaphore submission\n");
1424 uint32_t entry_count
= 0;
1425 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1426 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1427 entry_count
+= cmdbuf
->cs
.entry_count
;
1430 struct drm_msm_gem_submit_cmd cmds
[entry_count
];
1431 uint32_t entry_idx
= 0;
1432 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1433 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1434 struct tu_cs
*cs
= &cmdbuf
->cs
;
1435 for (unsigned i
= 0; i
< cs
->entry_count
; ++i
, ++entry_idx
) {
1436 cmds
[entry_idx
].type
= MSM_SUBMIT_CMD_BUF
;
1437 cmds
[entry_idx
].submit_idx
=
1438 tu_bo_list_add(&bo_list
, cs
->entries
[i
].bo
,
1439 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1440 cmds
[entry_idx
].submit_offset
= cs
->entries
[i
].offset
;
1441 cmds
[entry_idx
].size
= cs
->entries
[i
].size
;
1442 cmds
[entry_idx
].pad
= 0;
1443 cmds
[entry_idx
].nr_relocs
= 0;
1444 cmds
[entry_idx
].relocs
= 0;
1447 tu_bo_list_merge(&bo_list
, &cmdbuf
->bo_list
);
1450 uint32_t flags
= MSM_PIPE_3D0
;
1451 if (nr_in_syncobjs
) {
1452 flags
|= MSM_SUBMIT_SYNCOBJ_IN
;
1454 if (nr_out_syncobjs
) {
1455 flags
|= MSM_SUBMIT_SYNCOBJ_OUT
;
1459 flags
|= MSM_SUBMIT_FENCE_FD_OUT
;
1462 struct drm_msm_gem_submit req
= {
1464 .queueid
= queue
->msm_queue_id
,
1465 .bos
= (uint64_t)(uintptr_t) bo_list
.bo_infos
,
1466 .nr_bos
= bo_list
.count
,
1467 .cmds
= (uint64_t)(uintptr_t)cmds
,
1468 .nr_cmds
= entry_count
,
1469 .in_syncobjs
= (uint64_t)(uintptr_t)in_syncobjs
,
1470 .out_syncobjs
= (uint64_t)(uintptr_t)out_syncobjs
,
1471 .nr_in_syncobjs
= nr_in_syncobjs
,
1472 .nr_out_syncobjs
= nr_out_syncobjs
,
1473 .syncobj_stride
= sizeof(struct drm_msm_gem_submit_syncobj
),
1476 int ret
= drmCommandWriteRead(queue
->device
->physical_device
->local_fd
,
1482 return tu_device_set_lost(queue
->device
, "submit failed: %s\n",
1486 tu_bo_list_destroy(&bo_list
);
1490 tu_semaphores_remove_temp(queue
->device
, pSubmits
[i
].pWaitSemaphores
,
1491 pSubmits
[i
].waitSemaphoreCount
);
1493 /* no need to merge fences as queue execution is serialized */
1494 tu_fence_update_fd(&queue
->submit_fence
, req
.fence_fd
);
1495 } else if (last_submit
) {
1496 close(req
.fence_fd
);
1500 if (_fence
!= VK_NULL_HANDLE
) {
1501 TU_FROM_HANDLE(tu_fence
, fence
, _fence
);
1502 tu_fence_copy(fence
, &queue
->submit_fence
);
1509 tu_QueueWaitIdle(VkQueue _queue
)
1511 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1513 if (tu_device_is_lost(queue
->device
))
1514 return VK_ERROR_DEVICE_LOST
;
1516 tu_fence_wait_idle(&queue
->submit_fence
);
1522 tu_DeviceWaitIdle(VkDevice _device
)
1524 TU_FROM_HANDLE(tu_device
, device
, _device
);
1526 if (tu_device_is_lost(device
))
1527 return VK_ERROR_DEVICE_LOST
;
1529 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1530 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1531 tu_QueueWaitIdle(tu_queue_to_handle(&device
->queues
[i
][q
]));
1538 tu_EnumerateInstanceExtensionProperties(const char *pLayerName
,
1539 uint32_t *pPropertyCount
,
1540 VkExtensionProperties
*pProperties
)
1542 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1544 /* We spport no lyaers */
1546 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1548 for (int i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; i
++) {
1549 if (tu_instance_extensions_supported
.extensions
[i
]) {
1550 vk_outarray_append(&out
, prop
) { *prop
= tu_instance_extensions
[i
]; }
1554 return vk_outarray_status(&out
);
1558 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
1559 const char *pLayerName
,
1560 uint32_t *pPropertyCount
,
1561 VkExtensionProperties
*pProperties
)
1563 /* We spport no lyaers */
1564 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
1565 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1567 /* We spport no lyaers */
1569 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1571 for (int i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; i
++) {
1572 if (device
->supported_extensions
.extensions
[i
]) {
1573 vk_outarray_append(&out
, prop
) { *prop
= tu_device_extensions
[i
]; }
1577 return vk_outarray_status(&out
);
1581 tu_GetInstanceProcAddr(VkInstance _instance
, const char *pName
)
1583 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
1585 return tu_lookup_entrypoint_checked(
1586 pName
, instance
? instance
->api_version
: 0,
1587 instance
? &instance
->enabled_extensions
: NULL
, NULL
);
1590 /* The loader wants us to expose a second GetInstanceProcAddr function
1591 * to work around certain LD_PRELOAD issues seen in apps.
1594 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1595 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
);
1598 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1599 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
)
1601 return tu_GetInstanceProcAddr(instance
, pName
);
1605 tu_GetDeviceProcAddr(VkDevice _device
, const char *pName
)
1607 TU_FROM_HANDLE(tu_device
, device
, _device
);
1609 return tu_lookup_entrypoint_checked(pName
, device
->instance
->api_version
,
1610 &device
->instance
->enabled_extensions
,
1611 &device
->enabled_extensions
);
1615 tu_alloc_memory(struct tu_device
*device
,
1616 const VkMemoryAllocateInfo
*pAllocateInfo
,
1617 const VkAllocationCallbacks
*pAllocator
,
1618 VkDeviceMemory
*pMem
)
1620 struct tu_device_memory
*mem
;
1623 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1625 if (pAllocateInfo
->allocationSize
== 0) {
1626 /* Apparently, this is allowed */
1627 *pMem
= VK_NULL_HANDLE
;
1631 mem
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*mem
),
1632 VK_OBJECT_TYPE_DEVICE_MEMORY
);
1634 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1636 const VkImportMemoryFdInfoKHR
*fd_info
=
1637 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1638 if (fd_info
&& !fd_info
->handleType
)
1642 assert(fd_info
->handleType
==
1643 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1644 fd_info
->handleType
==
1645 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1648 * TODO Importing the same fd twice gives us the same handle without
1649 * reference counting. We need to maintain a per-instance handle-to-bo
1650 * table and add reference count to tu_bo.
1652 result
= tu_bo_init_dmabuf(device
, &mem
->bo
,
1653 pAllocateInfo
->allocationSize
, fd_info
->fd
);
1654 if (result
== VK_SUCCESS
) {
1655 /* take ownership and close the fd */
1660 tu_bo_init_new(device
, &mem
->bo
, pAllocateInfo
->allocationSize
);
1663 if (result
!= VK_SUCCESS
) {
1664 vk_object_free(&device
->vk
, pAllocator
, mem
);
1668 mem
->size
= pAllocateInfo
->allocationSize
;
1669 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1672 mem
->user_ptr
= NULL
;
1674 *pMem
= tu_device_memory_to_handle(mem
);
1680 tu_AllocateMemory(VkDevice _device
,
1681 const VkMemoryAllocateInfo
*pAllocateInfo
,
1682 const VkAllocationCallbacks
*pAllocator
,
1683 VkDeviceMemory
*pMem
)
1685 TU_FROM_HANDLE(tu_device
, device
, _device
);
1686 return tu_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
1690 tu_FreeMemory(VkDevice _device
,
1691 VkDeviceMemory _mem
,
1692 const VkAllocationCallbacks
*pAllocator
)
1694 TU_FROM_HANDLE(tu_device
, device
, _device
);
1695 TU_FROM_HANDLE(tu_device_memory
, mem
, _mem
);
1700 tu_bo_finish(device
, &mem
->bo
);
1701 vk_object_free(&device
->vk
, pAllocator
, mem
);
1705 tu_MapMemory(VkDevice _device
,
1706 VkDeviceMemory _memory
,
1707 VkDeviceSize offset
,
1709 VkMemoryMapFlags flags
,
1712 TU_FROM_HANDLE(tu_device
, device
, _device
);
1713 TU_FROM_HANDLE(tu_device_memory
, mem
, _memory
);
1721 if (mem
->user_ptr
) {
1722 *ppData
= mem
->user_ptr
;
1723 } else if (!mem
->map
) {
1724 result
= tu_bo_map(device
, &mem
->bo
);
1725 if (result
!= VK_SUCCESS
)
1727 *ppData
= mem
->map
= mem
->bo
.map
;
1736 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
1740 tu_UnmapMemory(VkDevice _device
, VkDeviceMemory _memory
)
1742 /* I do not see any unmapping done by the freedreno Gallium driver. */
1746 tu_FlushMappedMemoryRanges(VkDevice _device
,
1747 uint32_t memoryRangeCount
,
1748 const VkMappedMemoryRange
*pMemoryRanges
)
1754 tu_InvalidateMappedMemoryRanges(VkDevice _device
,
1755 uint32_t memoryRangeCount
,
1756 const VkMappedMemoryRange
*pMemoryRanges
)
1762 tu_GetBufferMemoryRequirements(VkDevice _device
,
1764 VkMemoryRequirements
*pMemoryRequirements
)
1766 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1768 pMemoryRequirements
->memoryTypeBits
= 1;
1769 pMemoryRequirements
->alignment
= 64;
1770 pMemoryRequirements
->size
=
1771 align64(buffer
->size
, pMemoryRequirements
->alignment
);
1775 tu_GetBufferMemoryRequirements2(
1777 const VkBufferMemoryRequirementsInfo2
*pInfo
,
1778 VkMemoryRequirements2
*pMemoryRequirements
)
1780 tu_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
1781 &pMemoryRequirements
->memoryRequirements
);
1785 tu_GetImageMemoryRequirements(VkDevice _device
,
1787 VkMemoryRequirements
*pMemoryRequirements
)
1789 TU_FROM_HANDLE(tu_image
, image
, _image
);
1791 pMemoryRequirements
->memoryTypeBits
= 1;
1792 pMemoryRequirements
->size
= image
->total_size
;
1793 pMemoryRequirements
->alignment
= image
->layout
[0].base_align
;
1797 tu_GetImageMemoryRequirements2(VkDevice device
,
1798 const VkImageMemoryRequirementsInfo2
*pInfo
,
1799 VkMemoryRequirements2
*pMemoryRequirements
)
1801 tu_GetImageMemoryRequirements(device
, pInfo
->image
,
1802 &pMemoryRequirements
->memoryRequirements
);
1806 tu_GetImageSparseMemoryRequirements(
1809 uint32_t *pSparseMemoryRequirementCount
,
1810 VkSparseImageMemoryRequirements
*pSparseMemoryRequirements
)
1816 tu_GetImageSparseMemoryRequirements2(
1818 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
1819 uint32_t *pSparseMemoryRequirementCount
,
1820 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
1826 tu_GetDeviceMemoryCommitment(VkDevice device
,
1827 VkDeviceMemory memory
,
1828 VkDeviceSize
*pCommittedMemoryInBytes
)
1830 *pCommittedMemoryInBytes
= 0;
1834 tu_BindBufferMemory2(VkDevice device
,
1835 uint32_t bindInfoCount
,
1836 const VkBindBufferMemoryInfo
*pBindInfos
)
1838 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1839 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1840 TU_FROM_HANDLE(tu_buffer
, buffer
, pBindInfos
[i
].buffer
);
1843 buffer
->bo
= &mem
->bo
;
1844 buffer
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1853 tu_BindBufferMemory(VkDevice device
,
1855 VkDeviceMemory memory
,
1856 VkDeviceSize memoryOffset
)
1858 const VkBindBufferMemoryInfo info
= {
1859 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1862 .memoryOffset
= memoryOffset
1865 return tu_BindBufferMemory2(device
, 1, &info
);
1869 tu_BindImageMemory2(VkDevice device
,
1870 uint32_t bindInfoCount
,
1871 const VkBindImageMemoryInfo
*pBindInfos
)
1873 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1874 TU_FROM_HANDLE(tu_image
, image
, pBindInfos
[i
].image
);
1875 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1878 image
->bo
= &mem
->bo
;
1879 image
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1882 image
->bo_offset
= 0;
1890 tu_BindImageMemory(VkDevice device
,
1892 VkDeviceMemory memory
,
1893 VkDeviceSize memoryOffset
)
1895 const VkBindImageMemoryInfo info
= {
1896 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1899 .memoryOffset
= memoryOffset
1902 return tu_BindImageMemory2(device
, 1, &info
);
1906 tu_QueueBindSparse(VkQueue _queue
,
1907 uint32_t bindInfoCount
,
1908 const VkBindSparseInfo
*pBindInfo
,
1914 // Queue semaphore functions
1918 tu_semaphore_part_destroy(struct tu_device
*device
,
1919 struct tu_semaphore_part
*part
)
1921 switch(part
->kind
) {
1922 case TU_SEMAPHORE_NONE
:
1924 case TU_SEMAPHORE_SYNCOBJ
:
1925 drmSyncobjDestroy(device
->physical_device
->local_fd
, part
->syncobj
);
1928 part
->kind
= TU_SEMAPHORE_NONE
;
1932 tu_semaphore_remove_temp(struct tu_device
*device
,
1933 struct tu_semaphore
*sem
)
1935 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
1936 tu_semaphore_part_destroy(device
, &sem
->temporary
);
1941 tu_CreateSemaphore(VkDevice _device
,
1942 const VkSemaphoreCreateInfo
*pCreateInfo
,
1943 const VkAllocationCallbacks
*pAllocator
,
1944 VkSemaphore
*pSemaphore
)
1946 TU_FROM_HANDLE(tu_device
, device
, _device
);
1948 struct tu_semaphore
*sem
=
1949 vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*sem
),
1950 VK_OBJECT_TYPE_SEMAPHORE
);
1952 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1954 const VkExportSemaphoreCreateInfo
*export
=
1955 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
1956 VkExternalSemaphoreHandleTypeFlags handleTypes
=
1957 export
? export
->handleTypes
: 0;
1959 sem
->permanent
.kind
= TU_SEMAPHORE_NONE
;
1960 sem
->temporary
.kind
= TU_SEMAPHORE_NONE
;
1963 if (drmSyncobjCreate(device
->physical_device
->local_fd
, 0, &sem
->permanent
.syncobj
) < 0) {
1964 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
1965 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1967 sem
->permanent
.kind
= TU_SEMAPHORE_SYNCOBJ
;
1969 *pSemaphore
= tu_semaphore_to_handle(sem
);
1974 tu_DestroySemaphore(VkDevice _device
,
1975 VkSemaphore _semaphore
,
1976 const VkAllocationCallbacks
*pAllocator
)
1978 TU_FROM_HANDLE(tu_device
, device
, _device
);
1979 TU_FROM_HANDLE(tu_semaphore
, sem
, _semaphore
);
1983 tu_semaphore_part_destroy(device
, &sem
->permanent
);
1984 tu_semaphore_part_destroy(device
, &sem
->temporary
);
1986 vk_object_free(&device
->vk
, pAllocator
, sem
);
1990 tu_CreateEvent(VkDevice _device
,
1991 const VkEventCreateInfo
*pCreateInfo
,
1992 const VkAllocationCallbacks
*pAllocator
,
1995 TU_FROM_HANDLE(tu_device
, device
, _device
);
1997 struct tu_event
*event
=
1998 vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*event
),
1999 VK_OBJECT_TYPE_EVENT
);
2001 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2003 VkResult result
= tu_bo_init_new(device
, &event
->bo
, 0x1000);
2004 if (result
!= VK_SUCCESS
)
2007 result
= tu_bo_map(device
, &event
->bo
);
2008 if (result
!= VK_SUCCESS
)
2011 *pEvent
= tu_event_to_handle(event
);
2016 tu_bo_finish(device
, &event
->bo
);
2018 vk_object_free(&device
->vk
, pAllocator
, event
);
2019 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2023 tu_DestroyEvent(VkDevice _device
,
2025 const VkAllocationCallbacks
*pAllocator
)
2027 TU_FROM_HANDLE(tu_device
, device
, _device
);
2028 TU_FROM_HANDLE(tu_event
, event
, _event
);
2033 tu_bo_finish(device
, &event
->bo
);
2034 vk_object_free(&device
->vk
, pAllocator
, event
);
2038 tu_GetEventStatus(VkDevice _device
, VkEvent _event
)
2040 TU_FROM_HANDLE(tu_event
, event
, _event
);
2042 if (*(uint64_t*) event
->bo
.map
== 1)
2043 return VK_EVENT_SET
;
2044 return VK_EVENT_RESET
;
2048 tu_SetEvent(VkDevice _device
, VkEvent _event
)
2050 TU_FROM_HANDLE(tu_event
, event
, _event
);
2051 *(uint64_t*) event
->bo
.map
= 1;
2057 tu_ResetEvent(VkDevice _device
, VkEvent _event
)
2059 TU_FROM_HANDLE(tu_event
, event
, _event
);
2060 *(uint64_t*) event
->bo
.map
= 0;
2066 tu_CreateBuffer(VkDevice _device
,
2067 const VkBufferCreateInfo
*pCreateInfo
,
2068 const VkAllocationCallbacks
*pAllocator
,
2071 TU_FROM_HANDLE(tu_device
, device
, _device
);
2072 struct tu_buffer
*buffer
;
2074 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2076 buffer
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*buffer
),
2077 VK_OBJECT_TYPE_BUFFER
);
2079 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2081 buffer
->size
= pCreateInfo
->size
;
2082 buffer
->usage
= pCreateInfo
->usage
;
2083 buffer
->flags
= pCreateInfo
->flags
;
2085 *pBuffer
= tu_buffer_to_handle(buffer
);
2091 tu_DestroyBuffer(VkDevice _device
,
2093 const VkAllocationCallbacks
*pAllocator
)
2095 TU_FROM_HANDLE(tu_device
, device
, _device
);
2096 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
2101 vk_object_free(&device
->vk
, pAllocator
, buffer
);
2105 tu_CreateFramebuffer(VkDevice _device
,
2106 const VkFramebufferCreateInfo
*pCreateInfo
,
2107 const VkAllocationCallbacks
*pAllocator
,
2108 VkFramebuffer
*pFramebuffer
)
2110 TU_FROM_HANDLE(tu_device
, device
, _device
);
2111 TU_FROM_HANDLE(tu_render_pass
, pass
, pCreateInfo
->renderPass
);
2112 struct tu_framebuffer
*framebuffer
;
2114 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2116 size_t size
= sizeof(*framebuffer
) + sizeof(struct tu_attachment_info
) *
2117 pCreateInfo
->attachmentCount
;
2118 framebuffer
= vk_object_alloc(&device
->vk
, pAllocator
, size
,
2119 VK_OBJECT_TYPE_FRAMEBUFFER
);
2120 if (framebuffer
== NULL
)
2121 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2123 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2124 framebuffer
->width
= pCreateInfo
->width
;
2125 framebuffer
->height
= pCreateInfo
->height
;
2126 framebuffer
->layers
= pCreateInfo
->layers
;
2127 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2128 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2129 struct tu_image_view
*iview
= tu_image_view_from_handle(_iview
);
2130 framebuffer
->attachments
[i
].attachment
= iview
;
2133 tu_framebuffer_tiling_config(framebuffer
, device
, pass
);
2135 *pFramebuffer
= tu_framebuffer_to_handle(framebuffer
);
2140 tu_DestroyFramebuffer(VkDevice _device
,
2142 const VkAllocationCallbacks
*pAllocator
)
2144 TU_FROM_HANDLE(tu_device
, device
, _device
);
2145 TU_FROM_HANDLE(tu_framebuffer
, fb
, _fb
);
2150 vk_object_free(&device
->vk
, pAllocator
, fb
);
2154 tu_init_sampler(struct tu_device
*device
,
2155 struct tu_sampler
*sampler
,
2156 const VkSamplerCreateInfo
*pCreateInfo
)
2158 const struct VkSamplerReductionModeCreateInfo
*reduction
=
2159 vk_find_struct_const(pCreateInfo
->pNext
, SAMPLER_REDUCTION_MODE_CREATE_INFO
);
2160 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
2161 vk_find_struct_const(pCreateInfo
->pNext
, SAMPLER_YCBCR_CONVERSION_INFO
);
2163 unsigned aniso
= pCreateInfo
->anisotropyEnable
?
2164 util_last_bit(MIN2((uint32_t)pCreateInfo
->maxAnisotropy
>> 1, 8)) : 0;
2165 bool miplinear
= (pCreateInfo
->mipmapMode
== VK_SAMPLER_MIPMAP_MODE_LINEAR
);
2166 float min_lod
= CLAMP(pCreateInfo
->minLod
, 0.0f
, 4095.0f
/ 256.0f
);
2167 float max_lod
= CLAMP(pCreateInfo
->maxLod
, 0.0f
, 4095.0f
/ 256.0f
);
2169 sampler
->descriptor
[0] =
2170 COND(miplinear
, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR
) |
2171 A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo
->magFilter
, aniso
)) |
2172 A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo
->minFilter
, aniso
)) |
2173 A6XX_TEX_SAMP_0_ANISO(aniso
) |
2174 A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo
->addressModeU
)) |
2175 A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo
->addressModeV
)) |
2176 A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo
->addressModeW
)) |
2177 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo
->mipLodBias
);
2178 sampler
->descriptor
[1] =
2179 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
2180 COND(pCreateInfo
->unnormalizedCoordinates
, A6XX_TEX_SAMP_1_UNNORM_COORDS
) |
2181 A6XX_TEX_SAMP_1_MIN_LOD(min_lod
) |
2182 A6XX_TEX_SAMP_1_MAX_LOD(max_lod
) |
2183 COND(pCreateInfo
->compareEnable
,
2184 A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo
->compareOp
)));
2185 /* This is an offset into the border_color BO, which we fill with all the
2186 * possible Vulkan border colors in the correct order, so we can just use
2187 * the Vulkan enum with no translation necessary.
2189 sampler
->descriptor
[2] =
2190 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((unsigned) pCreateInfo
->borderColor
*
2191 sizeof(struct bcolor_entry
));
2192 sampler
->descriptor
[3] = 0;
2195 sampler
->descriptor
[2] |= A6XX_TEX_SAMP_2_REDUCTION_MODE(
2196 tu6_reduction_mode(reduction
->reductionMode
));
2199 sampler
->ycbcr_sampler
= ycbcr_conversion
?
2200 tu_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
) : NULL
;
2202 if (sampler
->ycbcr_sampler
&&
2203 sampler
->ycbcr_sampler
->chroma_filter
== VK_FILTER_LINEAR
) {
2204 sampler
->descriptor
[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR
;
2208 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
2213 tu_CreateSampler(VkDevice _device
,
2214 const VkSamplerCreateInfo
*pCreateInfo
,
2215 const VkAllocationCallbacks
*pAllocator
,
2216 VkSampler
*pSampler
)
2218 TU_FROM_HANDLE(tu_device
, device
, _device
);
2219 struct tu_sampler
*sampler
;
2221 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2223 sampler
= vk_object_alloc(&device
->vk
, pAllocator
, sizeof(*sampler
),
2224 VK_OBJECT_TYPE_SAMPLER
);
2226 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2228 tu_init_sampler(device
, sampler
, pCreateInfo
);
2229 *pSampler
= tu_sampler_to_handle(sampler
);
2235 tu_DestroySampler(VkDevice _device
,
2237 const VkAllocationCallbacks
*pAllocator
)
2239 TU_FROM_HANDLE(tu_device
, device
, _device
);
2240 TU_FROM_HANDLE(tu_sampler
, sampler
, _sampler
);
2245 vk_object_free(&device
->vk
, pAllocator
, sampler
);
2248 /* vk_icd.h does not declare this function, so we declare it here to
2249 * suppress Wmissing-prototypes.
2251 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2252 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2254 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2255 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2257 /* For the full details on loader interface versioning, see
2258 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2259 * What follows is a condensed summary, to help you navigate the large and
2260 * confusing official doc.
2262 * - Loader interface v0 is incompatible with later versions. We don't
2265 * - In loader interface v1:
2266 * - The first ICD entrypoint called by the loader is
2267 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2269 * - The ICD must statically expose no other Vulkan symbol unless it
2270 * is linked with -Bsymbolic.
2271 * - Each dispatchable Vulkan handle created by the ICD must be
2272 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2273 * ICD must initialize VK_LOADER_DATA.loadMagic to
2275 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2276 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2277 * such loader-managed surfaces.
2279 * - Loader interface v2 differs from v1 in:
2280 * - The first ICD entrypoint called by the loader is
2281 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2282 * statically expose this entrypoint.
2284 * - Loader interface v3 differs from v2 in:
2285 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2286 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2287 * because the loader no longer does so.
2289 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
2294 tu_GetMemoryFdKHR(VkDevice _device
,
2295 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
2298 TU_FROM_HANDLE(tu_device
, device
, _device
);
2299 TU_FROM_HANDLE(tu_device_memory
, memory
, pGetFdInfo
->memory
);
2301 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2303 /* At the moment, we support only the below handle types. */
2304 assert(pGetFdInfo
->handleType
==
2305 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2306 pGetFdInfo
->handleType
==
2307 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2309 int prime_fd
= tu_bo_export_dmabuf(device
, &memory
->bo
);
2311 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2318 tu_GetMemoryFdPropertiesKHR(VkDevice _device
,
2319 VkExternalMemoryHandleTypeFlagBits handleType
,
2321 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
2323 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2324 pMemoryFdProperties
->memoryTypeBits
= 1;
2329 tu_ImportFenceFdKHR(VkDevice _device
,
2330 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
2338 tu_GetFenceFdKHR(VkDevice _device
,
2339 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
2348 tu_ImportSemaphoreFdKHR(VkDevice _device
,
2349 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
2351 TU_FROM_HANDLE(tu_device
, device
, _device
);
2352 TU_FROM_HANDLE(tu_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
2354 struct tu_semaphore_part
*dst
= NULL
;
2356 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
2357 dst
= &sem
->temporary
;
2359 dst
= &sem
->permanent
;
2362 uint32_t syncobj
= dst
->kind
== TU_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
2364 switch(pImportSemaphoreFdInfo
->handleType
) {
2365 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
: {
2366 uint32_t old_syncobj
= syncobj
;
2367 ret
= drmSyncobjFDToHandle(device
->physical_device
->local_fd
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
2369 close(pImportSemaphoreFdInfo
->fd
);
2371 drmSyncobjDestroy(device
->physical_device
->local_fd
, old_syncobj
);
2375 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
: {
2377 ret
= drmSyncobjCreate(device
->physical_device
->local_fd
, 0, &syncobj
);
2381 if (pImportSemaphoreFdInfo
->fd
== -1) {
2382 ret
= drmSyncobjSignal(device
->physical_device
->local_fd
, &syncobj
, 1);
2384 ret
= drmSyncobjImportSyncFile(device
->physical_device
->local_fd
, syncobj
, pImportSemaphoreFdInfo
->fd
);
2387 close(pImportSemaphoreFdInfo
->fd
);
2391 unreachable("Unhandled semaphore handle type");
2395 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
2397 dst
->syncobj
= syncobj
;
2398 dst
->kind
= TU_SEMAPHORE_SYNCOBJ
;
2404 tu_GetSemaphoreFdKHR(VkDevice _device
,
2405 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
2408 TU_FROM_HANDLE(tu_device
, device
, _device
);
2409 TU_FROM_HANDLE(tu_semaphore
, sem
, pGetFdInfo
->semaphore
);
2411 uint32_t syncobj_handle
;
2413 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2414 assert(sem
->temporary
.kind
== TU_SEMAPHORE_SYNCOBJ
);
2415 syncobj_handle
= sem
->temporary
.syncobj
;
2417 assert(sem
->permanent
.kind
== TU_SEMAPHORE_SYNCOBJ
);
2418 syncobj_handle
= sem
->permanent
.syncobj
;
2421 switch(pGetFdInfo
->handleType
) {
2422 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
2423 ret
= drmSyncobjHandleToFD(device
->physical_device
->local_fd
, syncobj_handle
, pFd
);
2425 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
2426 ret
= drmSyncobjExportSyncFile(device
->physical_device
->local_fd
, syncobj_handle
, pFd
);
2428 if (sem
->temporary
.kind
!= TU_SEMAPHORE_NONE
) {
2429 tu_semaphore_part_destroy(device
, &sem
->temporary
);
2431 drmSyncobjReset(device
->physical_device
->local_fd
, &syncobj_handle
, 1);
2436 unreachable("Unhandled semaphore handle type");
2440 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
2445 static bool tu_has_syncobj(struct tu_physical_device
*pdev
)
2448 if (drmGetCap(pdev
->local_fd
, DRM_CAP_SYNCOBJ
, &value
))
2450 return value
&& pdev
->msm_major_version
== 1 && pdev
->msm_minor_version
>= 6;
2454 tu_GetPhysicalDeviceExternalSemaphoreProperties(
2455 VkPhysicalDevice physicalDevice
,
2456 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
2457 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
2459 TU_FROM_HANDLE(tu_physical_device
, pdev
, physicalDevice
);
2461 if (tu_has_syncobj(pdev
) &&
2462 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
2463 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
2464 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
2465 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
2466 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
2467 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
2469 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
2470 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
2471 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
2476 tu_GetPhysicalDeviceExternalFenceProperties(
2477 VkPhysicalDevice physicalDevice
,
2478 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
2479 VkExternalFenceProperties
*pExternalFenceProperties
)
2481 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
2482 pExternalFenceProperties
->compatibleHandleTypes
= 0;
2483 pExternalFenceProperties
->externalFenceFeatures
= 0;
2487 tu_CreateDebugReportCallbackEXT(
2488 VkInstance _instance
,
2489 const VkDebugReportCallbackCreateInfoEXT
*pCreateInfo
,
2490 const VkAllocationCallbacks
*pAllocator
,
2491 VkDebugReportCallbackEXT
*pCallback
)
2493 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2494 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2495 pCreateInfo
, pAllocator
,
2496 &instance
->alloc
, pCallback
);
2500 tu_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2501 VkDebugReportCallbackEXT _callback
,
2502 const VkAllocationCallbacks
*pAllocator
)
2504 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2505 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2506 _callback
, pAllocator
, &instance
->alloc
);
2510 tu_DebugReportMessageEXT(VkInstance _instance
,
2511 VkDebugReportFlagsEXT flags
,
2512 VkDebugReportObjectTypeEXT objectType
,
2515 int32_t messageCode
,
2516 const char *pLayerPrefix
,
2517 const char *pMessage
)
2519 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2520 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2521 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2525 tu_GetDeviceGroupPeerMemoryFeatures(
2528 uint32_t localDeviceIndex
,
2529 uint32_t remoteDeviceIndex
,
2530 VkPeerMemoryFeatureFlags
*pPeerMemoryFeatures
)
2532 assert(localDeviceIndex
== remoteDeviceIndex
);
2534 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2535 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2536 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2537 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
2540 void tu_GetPhysicalDeviceMultisamplePropertiesEXT(
2541 VkPhysicalDevice physicalDevice
,
2542 VkSampleCountFlagBits samples
,
2543 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
2545 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
2547 if (samples
<= VK_SAMPLE_COUNT_4_BIT
&& pdevice
->supported_extensions
.EXT_sample_locations
)
2548 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 1, 1 };
2550 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };
2555 tu_CreatePrivateDataSlotEXT(VkDevice _device
,
2556 const VkPrivateDataSlotCreateInfoEXT
* pCreateInfo
,
2557 const VkAllocationCallbacks
* pAllocator
,
2558 VkPrivateDataSlotEXT
* pPrivateDataSlot
)
2560 TU_FROM_HANDLE(tu_device
, device
, _device
);
2561 return vk_private_data_slot_create(&device
->vk
,
2568 tu_DestroyPrivateDataSlotEXT(VkDevice _device
,
2569 VkPrivateDataSlotEXT privateDataSlot
,
2570 const VkAllocationCallbacks
* pAllocator
)
2572 TU_FROM_HANDLE(tu_device
, device
, _device
);
2573 vk_private_data_slot_destroy(&device
->vk
, privateDataSlot
, pAllocator
);
2577 tu_SetPrivateDataEXT(VkDevice _device
,
2578 VkObjectType objectType
,
2579 uint64_t objectHandle
,
2580 VkPrivateDataSlotEXT privateDataSlot
,
2583 TU_FROM_HANDLE(tu_device
, device
, _device
);
2584 return vk_object_base_set_private_data(&device
->vk
,
2592 tu_GetPrivateDataEXT(VkDevice _device
,
2593 VkObjectType objectType
,
2594 uint64_t objectHandle
,
2595 VkPrivateDataSlotEXT privateDataSlot
,
2598 TU_FROM_HANDLE(tu_device
, device
, _device
);
2599 vk_object_base_get_private_data(&device
->vk
,