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 "vk_format.h"
45 #include "drm-uapi/msm_drm.h"
48 tu_device_get_cache_uuid(uint16_t family
, void *uuid
)
50 uint32_t mesa_timestamp
;
52 memset(uuid
, 0, VK_UUID_SIZE
);
53 if (!disk_cache_get_function_timestamp(tu_device_get_cache_uuid
,
57 memcpy(uuid
, &mesa_timestamp
, 4);
58 memcpy((char *) uuid
+ 4, &f
, 2);
59 snprintf((char *) uuid
+ 6, VK_UUID_SIZE
- 10, "tu");
64 tu_get_driver_uuid(void *uuid
)
66 memset(uuid
, 0, VK_UUID_SIZE
);
67 snprintf(uuid
, VK_UUID_SIZE
, "freedreno");
71 tu_get_device_uuid(void *uuid
)
73 memset(uuid
, 0, VK_UUID_SIZE
);
77 tu_bo_init(struct tu_device
*dev
,
82 uint64_t iova
= tu_gem_info_iova(dev
, gem_handle
);
84 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
86 *bo
= (struct tu_bo
) {
87 .gem_handle
= gem_handle
,
96 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
)
98 /* TODO: Choose better flags. As of 2018-11-12, freedreno/drm/msm_bo.c
99 * always sets `flags = MSM_BO_WC`, and we copy that behavior here.
101 uint32_t gem_handle
= tu_gem_new(dev
, size
, MSM_BO_WC
);
103 return vk_error(dev
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
105 VkResult result
= tu_bo_init(dev
, bo
, gem_handle
, size
);
106 if (result
!= VK_SUCCESS
) {
107 tu_gem_close(dev
, gem_handle
);
108 return vk_error(dev
->instance
, result
);
115 tu_bo_init_dmabuf(struct tu_device
*dev
,
120 uint32_t gem_handle
= tu_gem_import_dmabuf(dev
, fd
, size
);
122 return vk_error(dev
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
124 VkResult result
= tu_bo_init(dev
, bo
, gem_handle
, size
);
125 if (result
!= VK_SUCCESS
) {
126 tu_gem_close(dev
, gem_handle
);
127 return vk_error(dev
->instance
, result
);
134 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
)
136 return tu_gem_export_dmabuf(dev
, bo
->gem_handle
);
140 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
)
145 uint64_t offset
= tu_gem_info_offset(dev
, bo
->gem_handle
);
147 return vk_error(dev
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
149 /* TODO: Should we use the wrapper os_mmap() like Freedreno does? */
150 void *map
= mmap(0, bo
->size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
151 dev
->physical_device
->local_fd
, offset
);
152 if (map
== MAP_FAILED
)
153 return vk_error(dev
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
160 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
)
162 assert(bo
->gem_handle
);
165 munmap(bo
->map
, bo
->size
);
167 tu_gem_close(dev
, bo
->gem_handle
);
171 tu_physical_device_init(struct tu_physical_device
*device
,
172 struct tu_instance
*instance
,
173 drmDevicePtr drm_device
)
175 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
176 VkResult result
= VK_SUCCESS
;
177 drmVersionPtr version
;
181 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
183 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
184 "failed to open device %s", path
);
187 /* Version 1.3 added MSM_INFO_IOVA. */
188 const int min_version_major
= 1;
189 const int min_version_minor
= 3;
191 version
= drmGetVersion(fd
);
194 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
195 "failed to query kernel driver version for device %s",
199 if (strcmp(version
->name
, "msm")) {
200 drmFreeVersion(version
);
202 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
203 "device %s does not use the msm kernel driver", path
);
206 if (version
->version_major
!= min_version_major
||
207 version
->version_minor
< min_version_minor
) {
208 result
= vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
209 "kernel driver for device %s has version %d.%d, "
210 "but Vulkan requires version >= %d.%d",
211 path
, version
->version_major
, version
->version_minor
,
212 min_version_major
, min_version_minor
);
213 drmFreeVersion(version
);
218 drmFreeVersion(version
);
220 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
221 tu_logi("Found compatible device '%s'.", path
);
223 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
224 device
->instance
= instance
;
225 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
226 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
228 if (instance
->enabled_extensions
.KHR_display
) {
230 open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
231 if (master_fd
>= 0) {
232 /* TODO: free master_fd is accel is not working? */
236 device
->master_fd
= master_fd
;
237 device
->local_fd
= fd
;
239 if (tu_drm_get_gpu_id(device
, &device
->gpu_id
)) {
240 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
241 tu_logi("Could not query the GPU ID");
242 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
243 "could not get GPU ID");
247 if (tu_drm_get_gmem_size(device
, &device
->gmem_size
)) {
248 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
249 tu_logi("Could not query the GMEM size");
250 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
251 "could not get GMEM size");
255 if (tu_drm_get_gmem_base(device
, &device
->gmem_base
)) {
256 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
257 tu_logi("Could not query the GMEM size");
258 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
259 "could not get GMEM size");
263 memset(device
->name
, 0, sizeof(device
->name
));
264 sprintf(device
->name
, "FD%d", device
->gpu_id
);
266 switch (device
->gpu_id
) {
268 device
->tile_align_w
= 64;
269 device
->tile_align_h
= 16;
270 device
->magic
.RB_UNKNOWN_8E04_blit
= 0x00100000;
271 device
->magic
.RB_CCU_CNTL_gmem
= 0x3e400004;
272 device
->magic
.PC_UNKNOWN_9805
= 0x0;
273 device
->magic
.SP_UNKNOWN_A0F8
= 0x0;
277 device
->tile_align_w
= 64;
278 device
->tile_align_h
= 16;
279 device
->magic
.RB_UNKNOWN_8E04_blit
= 0x01000000;
280 device
->magic
.RB_CCU_CNTL_gmem
= 0x7c400004;
281 device
->magic
.PC_UNKNOWN_9805
= 0x1;
282 device
->magic
.SP_UNKNOWN_A0F8
= 0x1;
285 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
286 "device %s is unsupported", device
->name
);
289 if (tu_device_get_cache_uuid(device
->gpu_id
, device
->cache_uuid
)) {
290 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
291 "cannot generate UUID");
295 /* The gpu id is already embedded in the uuid so we just pass "tu"
296 * when creating the cache.
298 char buf
[VK_UUID_SIZE
* 2 + 1];
299 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
300 device
->disk_cache
= disk_cache_create(device
->name
, buf
, 0);
302 fprintf(stderr
, "WARNING: tu is not a conformant vulkan implementation, "
303 "testing use only.\n");
305 tu_get_driver_uuid(&device
->device_uuid
);
306 tu_get_device_uuid(&device
->device_uuid
);
308 tu_fill_device_extension_table(device
, &device
->supported_extensions
);
310 if (result
!= VK_SUCCESS
) {
311 vk_error(instance
, result
);
315 result
= tu_wsi_init(device
);
316 if (result
!= VK_SUCCESS
) {
317 vk_error(instance
, result
);
331 tu_physical_device_finish(struct tu_physical_device
*device
)
333 tu_wsi_finish(device
);
335 disk_cache_destroy(device
->disk_cache
);
336 close(device
->local_fd
);
337 if (device
->master_fd
!= -1)
338 close(device
->master_fd
);
342 default_alloc_func(void *pUserData
,
345 VkSystemAllocationScope allocationScope
)
351 default_realloc_func(void *pUserData
,
355 VkSystemAllocationScope allocationScope
)
357 return realloc(pOriginal
, size
);
361 default_free_func(void *pUserData
, void *pMemory
)
366 static const VkAllocationCallbacks default_alloc
= {
368 .pfnAllocation
= default_alloc_func
,
369 .pfnReallocation
= default_realloc_func
,
370 .pfnFree
= default_free_func
,
373 static const struct debug_control tu_debug_options
[] = {
374 { "startup", TU_DEBUG_STARTUP
},
375 { "nir", TU_DEBUG_NIR
},
376 { "ir3", TU_DEBUG_IR3
},
377 { "nobin", TU_DEBUG_NOBIN
},
378 { "sysmem", TU_DEBUG_SYSMEM
},
379 { "forcebin", TU_DEBUG_FORCEBIN
},
384 tu_get_debug_option_name(int id
)
386 assert(id
< ARRAY_SIZE(tu_debug_options
) - 1);
387 return tu_debug_options
[id
].string
;
391 tu_get_instance_extension_index(const char *name
)
393 for (unsigned i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; ++i
) {
394 if (strcmp(name
, tu_instance_extensions
[i
].extensionName
) == 0)
401 tu_CreateInstance(const VkInstanceCreateInfo
*pCreateInfo
,
402 const VkAllocationCallbacks
*pAllocator
,
403 VkInstance
*pInstance
)
405 struct tu_instance
*instance
;
408 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
410 uint32_t client_version
;
411 if (pCreateInfo
->pApplicationInfo
&&
412 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
413 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
415 tu_EnumerateInstanceVersion(&client_version
);
418 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
419 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
421 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
423 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
426 instance
->alloc
= *pAllocator
;
428 instance
->alloc
= default_alloc
;
430 instance
->api_version
= client_version
;
431 instance
->physical_device_count
= -1;
433 instance
->debug_flags
=
434 parse_debug_string(getenv("TU_DEBUG"), tu_debug_options
);
436 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
437 tu_logi("Created an instance");
439 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
440 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
441 int index
= tu_get_instance_extension_index(ext_name
);
443 if (index
< 0 || !tu_supported_instance_extensions
.extensions
[index
]) {
444 vk_free2(&default_alloc
, pAllocator
, instance
);
445 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
448 instance
->enabled_extensions
.extensions
[index
] = true;
451 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
452 if (result
!= VK_SUCCESS
) {
453 vk_free2(&default_alloc
, pAllocator
, instance
);
454 return vk_error(instance
, result
);
457 glsl_type_singleton_init_or_ref();
459 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
461 *pInstance
= tu_instance_to_handle(instance
);
467 tu_DestroyInstance(VkInstance _instance
,
468 const VkAllocationCallbacks
*pAllocator
)
470 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
475 for (int i
= 0; i
< instance
->physical_device_count
; ++i
) {
476 tu_physical_device_finish(instance
->physical_devices
+ i
);
479 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
481 glsl_type_singleton_decref();
483 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
485 vk_free(&instance
->alloc
, instance
);
489 tu_enumerate_devices(struct tu_instance
*instance
)
491 /* TODO: Check for more devices ? */
492 drmDevicePtr devices
[8];
493 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
496 instance
->physical_device_count
= 0;
498 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
500 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
501 tu_logi("Found %d drm nodes", max_devices
);
504 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
506 for (unsigned i
= 0; i
< (unsigned) max_devices
; i
++) {
507 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
508 devices
[i
]->bustype
== DRM_BUS_PLATFORM
) {
510 result
= tu_physical_device_init(
511 instance
->physical_devices
+ instance
->physical_device_count
,
512 instance
, devices
[i
]);
513 if (result
== VK_SUCCESS
)
514 ++instance
->physical_device_count
;
515 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
519 drmFreeDevices(devices
, max_devices
);
525 tu_EnumeratePhysicalDevices(VkInstance _instance
,
526 uint32_t *pPhysicalDeviceCount
,
527 VkPhysicalDevice
*pPhysicalDevices
)
529 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
530 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
534 if (instance
->physical_device_count
< 0) {
535 result
= tu_enumerate_devices(instance
);
536 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
540 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
541 vk_outarray_append(&out
, p
)
543 *p
= tu_physical_device_to_handle(instance
->physical_devices
+ i
);
547 return vk_outarray_status(&out
);
551 tu_EnumeratePhysicalDeviceGroups(
552 VkInstance _instance
,
553 uint32_t *pPhysicalDeviceGroupCount
,
554 VkPhysicalDeviceGroupProperties
*pPhysicalDeviceGroupProperties
)
556 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
557 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
558 pPhysicalDeviceGroupCount
);
561 if (instance
->physical_device_count
< 0) {
562 result
= tu_enumerate_devices(instance
);
563 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
567 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
568 vk_outarray_append(&out
, p
)
570 p
->physicalDeviceCount
= 1;
571 p
->physicalDevices
[0] =
572 tu_physical_device_to_handle(instance
->physical_devices
+ i
);
573 p
->subsetAllocation
= false;
577 return vk_outarray_status(&out
);
581 tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice
,
582 VkPhysicalDeviceFeatures
*pFeatures
)
584 memset(pFeatures
, 0, sizeof(*pFeatures
));
586 *pFeatures
= (VkPhysicalDeviceFeatures
) {
587 .robustBufferAccess
= false,
588 .fullDrawIndexUint32
= true,
589 .imageCubeArray
= false,
590 .independentBlend
= true,
591 .geometryShader
= false,
592 .tessellationShader
= false,
593 .sampleRateShading
= true,
594 .dualSrcBlend
= true,
596 .multiDrawIndirect
= false,
597 .drawIndirectFirstInstance
= false,
599 .depthBiasClamp
= false,
600 .fillModeNonSolid
= false,
601 .depthBounds
= false,
603 .largePoints
= false,
605 .multiViewport
= false,
606 .samplerAnisotropy
= true,
607 .textureCompressionETC2
= true,
608 .textureCompressionASTC_LDR
= true,
609 .textureCompressionBC
= true,
610 .occlusionQueryPrecise
= true,
611 .pipelineStatisticsQuery
= false,
612 .vertexPipelineStoresAndAtomics
= false,
613 .fragmentStoresAndAtomics
= false,
614 .shaderTessellationAndGeometryPointSize
= false,
615 .shaderImageGatherExtended
= false,
616 .shaderStorageImageExtendedFormats
= false,
617 .shaderStorageImageMultisample
= false,
618 .shaderUniformBufferArrayDynamicIndexing
= false,
619 .shaderSampledImageArrayDynamicIndexing
= false,
620 .shaderStorageBufferArrayDynamicIndexing
= false,
621 .shaderStorageImageArrayDynamicIndexing
= false,
622 .shaderStorageImageReadWithoutFormat
= false,
623 .shaderStorageImageWriteWithoutFormat
= false,
624 .shaderClipDistance
= false,
625 .shaderCullDistance
= false,
626 .shaderFloat64
= false,
627 .shaderInt64
= false,
628 .shaderInt16
= false,
629 .sparseBinding
= false,
630 .variableMultisampleRate
= false,
631 .inheritedQueries
= false,
636 tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice
,
637 VkPhysicalDeviceFeatures2
*pFeatures
)
639 vk_foreach_struct(ext
, pFeatures
->pNext
)
641 switch (ext
->sType
) {
642 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
643 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *) ext
;
644 features
->variablePointersStorageBuffer
= false;
645 features
->variablePointers
= false;
648 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
649 VkPhysicalDeviceMultiviewFeatures
*features
=
650 (VkPhysicalDeviceMultiviewFeatures
*) ext
;
651 features
->multiview
= false;
652 features
->multiviewGeometryShader
= false;
653 features
->multiviewTessellationShader
= false;
656 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
657 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
658 (VkPhysicalDeviceShaderDrawParametersFeatures
*) ext
;
659 features
->shaderDrawParameters
= false;
662 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
663 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
664 (VkPhysicalDeviceProtectedMemoryFeatures
*) ext
;
665 features
->protectedMemory
= false;
668 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
669 VkPhysicalDevice16BitStorageFeatures
*features
=
670 (VkPhysicalDevice16BitStorageFeatures
*) ext
;
671 features
->storageBuffer16BitAccess
= false;
672 features
->uniformAndStorageBuffer16BitAccess
= false;
673 features
->storagePushConstant16
= false;
674 features
->storageInputOutput16
= false;
677 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
678 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
679 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
680 features
->samplerYcbcrConversion
= false;
683 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
684 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
685 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*) ext
;
686 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
687 features
->shaderUniformTexelBufferArrayDynamicIndexing
= false;
688 features
->shaderStorageTexelBufferArrayDynamicIndexing
= false;
689 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
690 features
->shaderSampledImageArrayNonUniformIndexing
= false;
691 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
692 features
->shaderStorageImageArrayNonUniformIndexing
= false;
693 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
694 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
695 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
696 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
697 features
->descriptorBindingSampledImageUpdateAfterBind
= false;
698 features
->descriptorBindingStorageImageUpdateAfterBind
= false;
699 features
->descriptorBindingStorageBufferUpdateAfterBind
= false;
700 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= false;
701 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= false;
702 features
->descriptorBindingUpdateUnusedWhilePending
= false;
703 features
->descriptorBindingPartiallyBound
= false;
704 features
->descriptorBindingVariableDescriptorCount
= false;
705 features
->runtimeDescriptorArray
= false;
708 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
709 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
710 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*) ext
;
711 features
->conditionalRendering
= false;
712 features
->inheritedConditionalRendering
= false;
715 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
716 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
717 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*) ext
;
718 features
->transformFeedback
= true;
719 features
->geometryStreams
= false;
726 return tu_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
730 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
731 VkPhysicalDeviceProperties
*pProperties
)
733 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
734 VkSampleCountFlags sample_counts
= VK_SAMPLE_COUNT_1_BIT
|
735 VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
| VK_SAMPLE_COUNT_8_BIT
;
737 /* make sure that the entire descriptor set is addressable with a signed
738 * 32-bit int. So the sum of all limits scaled by descriptor size has to
739 * be at most 2 GiB. the combined image & samples object count as one of
740 * both. This limit is for the pipeline layout, not for the set layout, but
741 * there is no set limit, so we just set a pipeline limit. I don't think
742 * any app is going to hit this soon. */
743 size_t max_descriptor_set_size
=
744 ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
745 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
746 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
747 32 /* sampler, largest when combined with image */ +
748 64 /* sampled image */ + 64 /* storage image */);
750 VkPhysicalDeviceLimits limits
= {
751 .maxImageDimension1D
= (1 << 14),
752 .maxImageDimension2D
= (1 << 14),
753 .maxImageDimension3D
= (1 << 11),
754 .maxImageDimensionCube
= (1 << 14),
755 .maxImageArrayLayers
= (1 << 11),
756 .maxTexelBufferElements
= 128 * 1024 * 1024,
757 .maxUniformBufferRange
= UINT32_MAX
,
758 .maxStorageBufferRange
= MAX_STORAGE_BUFFER_RANGE
,
759 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
760 .maxMemoryAllocationCount
= UINT32_MAX
,
761 .maxSamplerAllocationCount
= 64 * 1024,
762 .bufferImageGranularity
= 64, /* A cache line */
763 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
764 .maxBoundDescriptorSets
= MAX_SETS
,
765 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
766 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
767 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
768 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
769 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
770 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
771 .maxPerStageResources
= max_descriptor_set_size
,
772 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
773 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
774 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
775 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
776 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
777 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
778 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
779 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
780 .maxVertexInputAttributes
= 32,
781 .maxVertexInputBindings
= 32,
782 .maxVertexInputAttributeOffset
= 2047,
783 .maxVertexInputBindingStride
= 2048,
784 .maxVertexOutputComponents
= 128,
785 .maxTessellationGenerationLevel
= 64,
786 .maxTessellationPatchSize
= 32,
787 .maxTessellationControlPerVertexInputComponents
= 128,
788 .maxTessellationControlPerVertexOutputComponents
= 128,
789 .maxTessellationControlPerPatchOutputComponents
= 120,
790 .maxTessellationControlTotalOutputComponents
= 4096,
791 .maxTessellationEvaluationInputComponents
= 128,
792 .maxTessellationEvaluationOutputComponents
= 128,
793 .maxGeometryShaderInvocations
= 127,
794 .maxGeometryInputComponents
= 64,
795 .maxGeometryOutputComponents
= 128,
796 .maxGeometryOutputVertices
= 256,
797 .maxGeometryTotalOutputComponents
= 1024,
798 .maxFragmentInputComponents
= 128,
799 .maxFragmentOutputAttachments
= 8,
800 .maxFragmentDualSrcAttachments
= 1,
801 .maxFragmentCombinedOutputResources
= 8,
802 .maxComputeSharedMemorySize
= 32768,
803 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
804 .maxComputeWorkGroupInvocations
= 2048,
805 .maxComputeWorkGroupSize
= { 2048, 2048, 2048 },
806 .subPixelPrecisionBits
= 4 /* FIXME */,
807 .subTexelPrecisionBits
= 4 /* FIXME */,
808 .mipmapPrecisionBits
= 4 /* FIXME */,
809 .maxDrawIndexedIndexValue
= UINT32_MAX
,
810 .maxDrawIndirectCount
= UINT32_MAX
,
811 .maxSamplerLodBias
= 16,
812 .maxSamplerAnisotropy
= 16,
813 .maxViewports
= MAX_VIEWPORTS
,
814 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
815 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
816 .viewportSubPixelBits
= 8,
817 .minMemoryMapAlignment
= 4096, /* A page */
818 .minTexelBufferOffsetAlignment
= 64,
819 .minUniformBufferOffsetAlignment
= 4,
820 .minStorageBufferOffsetAlignment
= 4,
821 .minTexelOffset
= -32,
822 .maxTexelOffset
= 31,
823 .minTexelGatherOffset
= -32,
824 .maxTexelGatherOffset
= 31,
825 .minInterpolationOffset
= -2,
826 .maxInterpolationOffset
= 2,
827 .subPixelInterpolationOffsetBits
= 8,
828 .maxFramebufferWidth
= (1 << 14),
829 .maxFramebufferHeight
= (1 << 14),
830 .maxFramebufferLayers
= (1 << 10),
831 .framebufferColorSampleCounts
= sample_counts
,
832 .framebufferDepthSampleCounts
= sample_counts
,
833 .framebufferStencilSampleCounts
= sample_counts
,
834 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
835 .maxColorAttachments
= MAX_RTS
,
836 .sampledImageColorSampleCounts
= sample_counts
,
837 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
838 .sampledImageDepthSampleCounts
= sample_counts
,
839 .sampledImageStencilSampleCounts
= sample_counts
,
840 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
841 .maxSampleMaskWords
= 1,
842 .timestampComputeAndGraphics
= false, /* FINISHME */
843 .timestampPeriod
= 1,
844 .maxClipDistances
= 8,
845 .maxCullDistances
= 8,
846 .maxCombinedClipAndCullDistances
= 8,
847 .discreteQueuePriorities
= 1,
848 .pointSizeRange
= { 0.125, 255.875 },
849 .lineWidthRange
= { 0.0, 7.9921875 },
850 .pointSizeGranularity
= (1.0 / 8.0),
851 .lineWidthGranularity
= (1.0 / 128.0),
852 .strictLines
= false, /* FINISHME */
853 .standardSampleLocations
= true,
854 .optimalBufferCopyOffsetAlignment
= 128,
855 .optimalBufferCopyRowPitchAlignment
= 128,
856 .nonCoherentAtomSize
= 64,
859 *pProperties
= (VkPhysicalDeviceProperties
) {
860 .apiVersion
= tu_physical_device_api_version(pdevice
),
861 .driverVersion
= vk_get_driver_version(),
862 .vendorID
= 0, /* TODO */
864 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
866 .sparseProperties
= { 0 },
869 strcpy(pProperties
->deviceName
, pdevice
->name
);
870 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
874 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice
,
875 VkPhysicalDeviceProperties2
*pProperties
)
877 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
878 tu_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
880 vk_foreach_struct(ext
, pProperties
->pNext
)
882 switch (ext
->sType
) {
883 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
884 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
885 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
886 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
889 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
890 VkPhysicalDeviceIDProperties
*properties
=
891 (VkPhysicalDeviceIDProperties
*) ext
;
892 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
893 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
894 properties
->deviceLUIDValid
= false;
897 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
898 VkPhysicalDeviceMultiviewProperties
*properties
=
899 (VkPhysicalDeviceMultiviewProperties
*) ext
;
900 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
901 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
904 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
905 VkPhysicalDevicePointClippingProperties
*properties
=
906 (VkPhysicalDevicePointClippingProperties
*) ext
;
907 properties
->pointClippingBehavior
=
908 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
911 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
912 VkPhysicalDeviceMaintenance3Properties
*properties
=
913 (VkPhysicalDeviceMaintenance3Properties
*) ext
;
914 /* Make sure everything is addressable by a signed 32-bit int, and
915 * our largest descriptors are 96 bytes. */
916 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
917 /* Our buffer size fields allow only this much */
918 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
921 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
922 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
923 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
925 properties
->maxTransformFeedbackStreams
= IR3_MAX_SO_STREAMS
;
926 properties
->maxTransformFeedbackBuffers
= IR3_MAX_SO_BUFFERS
;
927 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
928 properties
->maxTransformFeedbackStreamDataSize
= 512;
929 properties
->maxTransformFeedbackBufferDataSize
= 512;
930 properties
->maxTransformFeedbackBufferDataStride
= 512;
931 /* TODO: enable xfb query */
932 properties
->transformFeedbackQueries
= false;
933 properties
->transformFeedbackStreamsLinesTriangles
= false;
934 properties
->transformFeedbackRasterizationStreamSelect
= false;
935 properties
->transformFeedbackDraw
= true;
944 static const VkQueueFamilyProperties tu_queue_family_properties
= {
946 VK_QUEUE_GRAPHICS_BIT
| VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
948 .timestampValidBits
= 0, /* FINISHME */
949 .minImageTransferGranularity
= { 1, 1, 1 },
953 tu_GetPhysicalDeviceQueueFamilyProperties(
954 VkPhysicalDevice physicalDevice
,
955 uint32_t *pQueueFamilyPropertyCount
,
956 VkQueueFamilyProperties
*pQueueFamilyProperties
)
958 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
960 vk_outarray_append(&out
, p
) { *p
= tu_queue_family_properties
; }
964 tu_GetPhysicalDeviceQueueFamilyProperties2(
965 VkPhysicalDevice physicalDevice
,
966 uint32_t *pQueueFamilyPropertyCount
,
967 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
969 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
971 vk_outarray_append(&out
, p
)
973 p
->queueFamilyProperties
= tu_queue_family_properties
;
978 tu_get_system_heap_size()
983 uint64_t total_ram
= (uint64_t) info
.totalram
* (uint64_t) info
.mem_unit
;
985 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
986 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
988 uint64_t available_ram
;
989 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
990 available_ram
= total_ram
/ 2;
992 available_ram
= total_ram
* 3 / 4;
994 return available_ram
;
998 tu_GetPhysicalDeviceMemoryProperties(
999 VkPhysicalDevice physicalDevice
,
1000 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1002 pMemoryProperties
->memoryHeapCount
= 1;
1003 pMemoryProperties
->memoryHeaps
[0].size
= tu_get_system_heap_size();
1004 pMemoryProperties
->memoryHeaps
[0].flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
;
1006 pMemoryProperties
->memoryTypeCount
= 1;
1007 pMemoryProperties
->memoryTypes
[0].propertyFlags
=
1008 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
1009 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1010 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
;
1011 pMemoryProperties
->memoryTypes
[0].heapIndex
= 0;
1015 tu_GetPhysicalDeviceMemoryProperties2(
1016 VkPhysicalDevice physicalDevice
,
1017 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1019 return tu_GetPhysicalDeviceMemoryProperties(
1020 physicalDevice
, &pMemoryProperties
->memoryProperties
);
1024 tu_queue_init(struct tu_device
*device
,
1025 struct tu_queue
*queue
,
1026 uint32_t queue_family_index
,
1028 VkDeviceQueueCreateFlags flags
)
1030 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1031 queue
->device
= device
;
1032 queue
->queue_family_index
= queue_family_index
;
1033 queue
->queue_idx
= idx
;
1034 queue
->flags
= flags
;
1036 int ret
= tu_drm_submitqueue_new(device
, 0, &queue
->msm_queue_id
);
1038 return VK_ERROR_INITIALIZATION_FAILED
;
1040 tu_fence_init(&queue
->submit_fence
, false);
1046 tu_queue_finish(struct tu_queue
*queue
)
1048 tu_fence_finish(&queue
->submit_fence
);
1049 tu_drm_submitqueue_close(queue
->device
, queue
->msm_queue_id
);
1053 tu_get_device_extension_index(const char *name
)
1055 for (unsigned i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; ++i
) {
1056 if (strcmp(name
, tu_device_extensions
[i
].extensionName
) == 0)
1063 tu_CreateDevice(VkPhysicalDevice physicalDevice
,
1064 const VkDeviceCreateInfo
*pCreateInfo
,
1065 const VkAllocationCallbacks
*pAllocator
,
1068 TU_FROM_HANDLE(tu_physical_device
, physical_device
, physicalDevice
);
1070 struct tu_device
*device
;
1072 /* Check enabled features */
1073 if (pCreateInfo
->pEnabledFeatures
) {
1074 VkPhysicalDeviceFeatures supported_features
;
1075 tu_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1076 VkBool32
*supported_feature
= (VkBool32
*) &supported_features
;
1077 VkBool32
*enabled_feature
= (VkBool32
*) pCreateInfo
->pEnabledFeatures
;
1078 unsigned num_features
=
1079 sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1080 for (uint32_t i
= 0; i
< num_features
; i
++) {
1081 if (enabled_feature
[i
] && !supported_feature
[i
])
1082 return vk_error(physical_device
->instance
,
1083 VK_ERROR_FEATURE_NOT_PRESENT
);
1087 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1088 sizeof(*device
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1090 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1092 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1093 device
->instance
= physical_device
->instance
;
1094 device
->physical_device
= physical_device
;
1097 device
->alloc
= *pAllocator
;
1099 device
->alloc
= physical_device
->instance
->alloc
;
1101 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1102 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1103 int index
= tu_get_device_extension_index(ext_name
);
1105 !physical_device
->supported_extensions
.extensions
[index
]) {
1106 vk_free(&device
->alloc
, device
);
1107 return vk_error(physical_device
->instance
,
1108 VK_ERROR_EXTENSION_NOT_PRESENT
);
1111 device
->enabled_extensions
.extensions
[index
] = true;
1114 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1115 const VkDeviceQueueCreateInfo
*queue_create
=
1116 &pCreateInfo
->pQueueCreateInfos
[i
];
1117 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1118 device
->queues
[qfi
] = vk_alloc(
1119 &device
->alloc
, queue_create
->queueCount
* sizeof(struct tu_queue
),
1120 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1121 if (!device
->queues
[qfi
]) {
1122 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1126 memset(device
->queues
[qfi
], 0,
1127 queue_create
->queueCount
* sizeof(struct tu_queue
));
1129 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1131 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1132 result
= tu_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
,
1133 queue_create
->flags
);
1134 if (result
!= VK_SUCCESS
)
1139 device
->compiler
= ir3_compiler_create(NULL
, physical_device
->gpu_id
);
1140 if (!device
->compiler
)
1143 #define VSC_DATA_SIZE(pitch) ((pitch) * 32 + 0x100) /* extra size to store VSC_SIZE */
1144 #define VSC_DATA2_SIZE(pitch) ((pitch) * 32)
1146 device
->vsc_data_pitch
= 0x440 * 4;
1147 device
->vsc_data2_pitch
= 0x1040 * 4;
1149 result
= tu_bo_init_new(device
, &device
->vsc_data
, VSC_DATA_SIZE(device
->vsc_data_pitch
));
1150 if (result
!= VK_SUCCESS
)
1153 result
= tu_bo_init_new(device
, &device
->vsc_data2
, VSC_DATA2_SIZE(device
->vsc_data2_pitch
));
1154 if (result
!= VK_SUCCESS
)
1155 goto fail_vsc_data2
;
1157 VkPipelineCacheCreateInfo ci
;
1158 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1161 ci
.pInitialData
= NULL
;
1162 ci
.initialDataSize
= 0;
1165 tu_CreatePipelineCache(tu_device_to_handle(device
), &ci
, NULL
, &pc
);
1166 if (result
!= VK_SUCCESS
)
1167 goto fail_pipeline_cache
;
1169 device
->mem_cache
= tu_pipeline_cache_from_handle(pc
);
1171 *pDevice
= tu_device_to_handle(device
);
1174 fail_pipeline_cache
:
1175 tu_bo_finish(device
, &device
->vsc_data2
);
1178 tu_bo_finish(device
, &device
->vsc_data
);
1181 ralloc_free(device
->compiler
);
1184 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1185 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1186 tu_queue_finish(&device
->queues
[i
][q
]);
1187 if (device
->queue_count
[i
])
1188 vk_free(&device
->alloc
, device
->queues
[i
]);
1191 vk_free(&device
->alloc
, device
);
1196 tu_DestroyDevice(VkDevice _device
, const VkAllocationCallbacks
*pAllocator
)
1198 TU_FROM_HANDLE(tu_device
, device
, _device
);
1203 tu_bo_finish(device
, &device
->vsc_data
);
1204 tu_bo_finish(device
, &device
->vsc_data2
);
1206 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1207 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1208 tu_queue_finish(&device
->queues
[i
][q
]);
1209 if (device
->queue_count
[i
])
1210 vk_free(&device
->alloc
, device
->queues
[i
]);
1213 /* the compiler does not use pAllocator */
1214 ralloc_free(device
->compiler
);
1216 VkPipelineCache pc
= tu_pipeline_cache_to_handle(device
->mem_cache
);
1217 tu_DestroyPipelineCache(tu_device_to_handle(device
), pc
, NULL
);
1219 vk_free(&device
->alloc
, device
);
1223 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount
,
1224 VkLayerProperties
*pProperties
)
1226 *pPropertyCount
= 0;
1231 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice
,
1232 uint32_t *pPropertyCount
,
1233 VkLayerProperties
*pProperties
)
1235 *pPropertyCount
= 0;
1240 tu_GetDeviceQueue2(VkDevice _device
,
1241 const VkDeviceQueueInfo2
*pQueueInfo
,
1244 TU_FROM_HANDLE(tu_device
, device
, _device
);
1245 struct tu_queue
*queue
;
1248 &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1249 if (pQueueInfo
->flags
!= queue
->flags
) {
1250 /* From the Vulkan 1.1.70 spec:
1252 * "The queue returned by vkGetDeviceQueue2 must have the same
1253 * flags value from this structure as that used at device
1254 * creation time in a VkDeviceQueueCreateInfo instance. If no
1255 * matching flags were specified at device creation time then
1256 * pQueue will return VK_NULL_HANDLE."
1258 *pQueue
= VK_NULL_HANDLE
;
1262 *pQueue
= tu_queue_to_handle(queue
);
1266 tu_GetDeviceQueue(VkDevice _device
,
1267 uint32_t queueFamilyIndex
,
1268 uint32_t queueIndex
,
1271 const VkDeviceQueueInfo2 info
=
1272 (VkDeviceQueueInfo2
) { .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1273 .queueFamilyIndex
= queueFamilyIndex
,
1274 .queueIndex
= queueIndex
};
1276 tu_GetDeviceQueue2(_device
, &info
, pQueue
);
1280 tu_QueueSubmit(VkQueue _queue
,
1281 uint32_t submitCount
,
1282 const VkSubmitInfo
*pSubmits
,
1285 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1287 for (uint32_t i
= 0; i
< submitCount
; ++i
) {
1288 const VkSubmitInfo
*submit
= pSubmits
+ i
;
1289 const bool last_submit
= (i
== submitCount
- 1);
1290 struct tu_bo_list bo_list
;
1291 tu_bo_list_init(&bo_list
);
1293 uint32_t entry_count
= 0;
1294 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1295 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1296 entry_count
+= cmdbuf
->cs
.entry_count
;
1299 struct drm_msm_gem_submit_cmd cmds
[entry_count
];
1300 uint32_t entry_idx
= 0;
1301 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1302 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1303 struct tu_cs
*cs
= &cmdbuf
->cs
;
1304 for (unsigned i
= 0; i
< cs
->entry_count
; ++i
, ++entry_idx
) {
1305 cmds
[entry_idx
].type
= MSM_SUBMIT_CMD_BUF
;
1306 cmds
[entry_idx
].submit_idx
=
1307 tu_bo_list_add(&bo_list
, cs
->entries
[i
].bo
,
1308 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1309 cmds
[entry_idx
].submit_offset
= cs
->entries
[i
].offset
;
1310 cmds
[entry_idx
].size
= cs
->entries
[i
].size
;
1311 cmds
[entry_idx
].pad
= 0;
1312 cmds
[entry_idx
].nr_relocs
= 0;
1313 cmds
[entry_idx
].relocs
= 0;
1316 tu_bo_list_merge(&bo_list
, &cmdbuf
->bo_list
);
1319 uint32_t flags
= MSM_PIPE_3D0
;
1321 flags
|= MSM_SUBMIT_FENCE_FD_OUT
;
1324 struct drm_msm_gem_submit req
= {
1326 .queueid
= queue
->msm_queue_id
,
1327 .bos
= (uint64_t)(uintptr_t) bo_list
.bo_infos
,
1328 .nr_bos
= bo_list
.count
,
1329 .cmds
= (uint64_t)(uintptr_t)cmds
,
1330 .nr_cmds
= entry_count
,
1333 int ret
= drmCommandWriteRead(queue
->device
->physical_device
->local_fd
,
1337 fprintf(stderr
, "submit failed: %s\n", strerror(errno
));
1341 tu_bo_list_destroy(&bo_list
);
1344 /* no need to merge fences as queue execution is serialized */
1345 tu_fence_update_fd(&queue
->submit_fence
, req
.fence_fd
);
1349 if (_fence
!= VK_NULL_HANDLE
) {
1350 TU_FROM_HANDLE(tu_fence
, fence
, _fence
);
1351 tu_fence_copy(fence
, &queue
->submit_fence
);
1358 tu_QueueWaitIdle(VkQueue _queue
)
1360 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1362 tu_fence_wait_idle(&queue
->submit_fence
);
1368 tu_DeviceWaitIdle(VkDevice _device
)
1370 TU_FROM_HANDLE(tu_device
, device
, _device
);
1372 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1373 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1374 tu_QueueWaitIdle(tu_queue_to_handle(&device
->queues
[i
][q
]));
1381 tu_EnumerateInstanceExtensionProperties(const char *pLayerName
,
1382 uint32_t *pPropertyCount
,
1383 VkExtensionProperties
*pProperties
)
1385 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1387 /* We spport no lyaers */
1389 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1391 for (int i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; i
++) {
1392 if (tu_supported_instance_extensions
.extensions
[i
]) {
1393 vk_outarray_append(&out
, prop
) { *prop
= tu_instance_extensions
[i
]; }
1397 return vk_outarray_status(&out
);
1401 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
1402 const char *pLayerName
,
1403 uint32_t *pPropertyCount
,
1404 VkExtensionProperties
*pProperties
)
1406 /* We spport no lyaers */
1407 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
1408 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1410 /* We spport no lyaers */
1412 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1414 for (int i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; i
++) {
1415 if (device
->supported_extensions
.extensions
[i
]) {
1416 vk_outarray_append(&out
, prop
) { *prop
= tu_device_extensions
[i
]; }
1420 return vk_outarray_status(&out
);
1424 tu_GetInstanceProcAddr(VkInstance _instance
, const char *pName
)
1426 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
1428 return tu_lookup_entrypoint_checked(
1429 pName
, instance
? instance
->api_version
: 0,
1430 instance
? &instance
->enabled_extensions
: NULL
, NULL
);
1433 /* The loader wants us to expose a second GetInstanceProcAddr function
1434 * to work around certain LD_PRELOAD issues seen in apps.
1437 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1438 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
);
1441 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1442 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
)
1444 return tu_GetInstanceProcAddr(instance
, pName
);
1448 tu_GetDeviceProcAddr(VkDevice _device
, const char *pName
)
1450 TU_FROM_HANDLE(tu_device
, device
, _device
);
1452 return tu_lookup_entrypoint_checked(pName
, device
->instance
->api_version
,
1453 &device
->instance
->enabled_extensions
,
1454 &device
->enabled_extensions
);
1458 tu_alloc_memory(struct tu_device
*device
,
1459 const VkMemoryAllocateInfo
*pAllocateInfo
,
1460 const VkAllocationCallbacks
*pAllocator
,
1461 VkDeviceMemory
*pMem
)
1463 struct tu_device_memory
*mem
;
1466 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1468 if (pAllocateInfo
->allocationSize
== 0) {
1469 /* Apparently, this is allowed */
1470 *pMem
= VK_NULL_HANDLE
;
1474 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1475 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1477 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1479 const VkImportMemoryFdInfoKHR
*fd_info
=
1480 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1481 if (fd_info
&& !fd_info
->handleType
)
1485 assert(fd_info
->handleType
==
1486 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1487 fd_info
->handleType
==
1488 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1491 * TODO Importing the same fd twice gives us the same handle without
1492 * reference counting. We need to maintain a per-instance handle-to-bo
1493 * table and add reference count to tu_bo.
1495 result
= tu_bo_init_dmabuf(device
, &mem
->bo
,
1496 pAllocateInfo
->allocationSize
, fd_info
->fd
);
1497 if (result
== VK_SUCCESS
) {
1498 /* take ownership and close the fd */
1503 tu_bo_init_new(device
, &mem
->bo
, pAllocateInfo
->allocationSize
);
1506 if (result
!= VK_SUCCESS
) {
1507 vk_free2(&device
->alloc
, pAllocator
, mem
);
1511 mem
->size
= pAllocateInfo
->allocationSize
;
1512 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1515 mem
->user_ptr
= NULL
;
1517 *pMem
= tu_device_memory_to_handle(mem
);
1523 tu_AllocateMemory(VkDevice _device
,
1524 const VkMemoryAllocateInfo
*pAllocateInfo
,
1525 const VkAllocationCallbacks
*pAllocator
,
1526 VkDeviceMemory
*pMem
)
1528 TU_FROM_HANDLE(tu_device
, device
, _device
);
1529 return tu_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
1533 tu_FreeMemory(VkDevice _device
,
1534 VkDeviceMemory _mem
,
1535 const VkAllocationCallbacks
*pAllocator
)
1537 TU_FROM_HANDLE(tu_device
, device
, _device
);
1538 TU_FROM_HANDLE(tu_device_memory
, mem
, _mem
);
1543 tu_bo_finish(device
, &mem
->bo
);
1544 vk_free2(&device
->alloc
, pAllocator
, mem
);
1548 tu_MapMemory(VkDevice _device
,
1549 VkDeviceMemory _memory
,
1550 VkDeviceSize offset
,
1552 VkMemoryMapFlags flags
,
1555 TU_FROM_HANDLE(tu_device
, device
, _device
);
1556 TU_FROM_HANDLE(tu_device_memory
, mem
, _memory
);
1564 if (mem
->user_ptr
) {
1565 *ppData
= mem
->user_ptr
;
1566 } else if (!mem
->map
) {
1567 result
= tu_bo_map(device
, &mem
->bo
);
1568 if (result
!= VK_SUCCESS
)
1570 *ppData
= mem
->map
= mem
->bo
.map
;
1579 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
1583 tu_UnmapMemory(VkDevice _device
, VkDeviceMemory _memory
)
1585 /* I do not see any unmapping done by the freedreno Gallium driver. */
1589 tu_FlushMappedMemoryRanges(VkDevice _device
,
1590 uint32_t memoryRangeCount
,
1591 const VkMappedMemoryRange
*pMemoryRanges
)
1597 tu_InvalidateMappedMemoryRanges(VkDevice _device
,
1598 uint32_t memoryRangeCount
,
1599 const VkMappedMemoryRange
*pMemoryRanges
)
1605 tu_GetBufferMemoryRequirements(VkDevice _device
,
1607 VkMemoryRequirements
*pMemoryRequirements
)
1609 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1611 pMemoryRequirements
->memoryTypeBits
= 1;
1612 pMemoryRequirements
->alignment
= 16;
1613 pMemoryRequirements
->size
=
1614 align64(buffer
->size
, pMemoryRequirements
->alignment
);
1618 tu_GetBufferMemoryRequirements2(
1620 const VkBufferMemoryRequirementsInfo2
*pInfo
,
1621 VkMemoryRequirements2
*pMemoryRequirements
)
1623 tu_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
1624 &pMemoryRequirements
->memoryRequirements
);
1628 tu_GetImageMemoryRequirements(VkDevice _device
,
1630 VkMemoryRequirements
*pMemoryRequirements
)
1632 TU_FROM_HANDLE(tu_image
, image
, _image
);
1634 pMemoryRequirements
->memoryTypeBits
= 1;
1635 pMemoryRequirements
->size
= image
->layout
.size
;
1636 pMemoryRequirements
->alignment
= image
->alignment
;
1640 tu_GetImageMemoryRequirements2(VkDevice device
,
1641 const VkImageMemoryRequirementsInfo2
*pInfo
,
1642 VkMemoryRequirements2
*pMemoryRequirements
)
1644 tu_GetImageMemoryRequirements(device
, pInfo
->image
,
1645 &pMemoryRequirements
->memoryRequirements
);
1649 tu_GetImageSparseMemoryRequirements(
1652 uint32_t *pSparseMemoryRequirementCount
,
1653 VkSparseImageMemoryRequirements
*pSparseMemoryRequirements
)
1659 tu_GetImageSparseMemoryRequirements2(
1661 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
1662 uint32_t *pSparseMemoryRequirementCount
,
1663 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
1669 tu_GetDeviceMemoryCommitment(VkDevice device
,
1670 VkDeviceMemory memory
,
1671 VkDeviceSize
*pCommittedMemoryInBytes
)
1673 *pCommittedMemoryInBytes
= 0;
1677 tu_BindBufferMemory2(VkDevice device
,
1678 uint32_t bindInfoCount
,
1679 const VkBindBufferMemoryInfo
*pBindInfos
)
1681 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1682 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1683 TU_FROM_HANDLE(tu_buffer
, buffer
, pBindInfos
[i
].buffer
);
1686 buffer
->bo
= &mem
->bo
;
1687 buffer
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1696 tu_BindBufferMemory(VkDevice device
,
1698 VkDeviceMemory memory
,
1699 VkDeviceSize memoryOffset
)
1701 const VkBindBufferMemoryInfo info
= {
1702 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1705 .memoryOffset
= memoryOffset
1708 return tu_BindBufferMemory2(device
, 1, &info
);
1712 tu_BindImageMemory2(VkDevice device
,
1713 uint32_t bindInfoCount
,
1714 const VkBindImageMemoryInfo
*pBindInfos
)
1716 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1717 TU_FROM_HANDLE(tu_image
, image
, pBindInfos
[i
].image
);
1718 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1721 image
->bo
= &mem
->bo
;
1722 image
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1725 image
->bo_offset
= 0;
1733 tu_BindImageMemory(VkDevice device
,
1735 VkDeviceMemory memory
,
1736 VkDeviceSize memoryOffset
)
1738 const VkBindImageMemoryInfo info
= {
1739 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1742 .memoryOffset
= memoryOffset
1745 return tu_BindImageMemory2(device
, 1, &info
);
1749 tu_QueueBindSparse(VkQueue _queue
,
1750 uint32_t bindInfoCount
,
1751 const VkBindSparseInfo
*pBindInfo
,
1757 // Queue semaphore functions
1760 tu_CreateSemaphore(VkDevice _device
,
1761 const VkSemaphoreCreateInfo
*pCreateInfo
,
1762 const VkAllocationCallbacks
*pAllocator
,
1763 VkSemaphore
*pSemaphore
)
1765 TU_FROM_HANDLE(tu_device
, device
, _device
);
1767 struct tu_semaphore
*sem
=
1768 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sem
), 8,
1769 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1771 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1773 *pSemaphore
= tu_semaphore_to_handle(sem
);
1778 tu_DestroySemaphore(VkDevice _device
,
1779 VkSemaphore _semaphore
,
1780 const VkAllocationCallbacks
*pAllocator
)
1782 TU_FROM_HANDLE(tu_device
, device
, _device
);
1783 TU_FROM_HANDLE(tu_semaphore
, sem
, _semaphore
);
1787 vk_free2(&device
->alloc
, pAllocator
, sem
);
1791 tu_CreateEvent(VkDevice _device
,
1792 const VkEventCreateInfo
*pCreateInfo
,
1793 const VkAllocationCallbacks
*pAllocator
,
1796 TU_FROM_HANDLE(tu_device
, device
, _device
);
1797 struct tu_event
*event
=
1798 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*event
), 8,
1799 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1802 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1804 VkResult result
= tu_bo_init_new(device
, &event
->bo
, 0x1000);
1805 if (result
!= VK_SUCCESS
)
1808 result
= tu_bo_map(device
, &event
->bo
);
1809 if (result
!= VK_SUCCESS
)
1812 *pEvent
= tu_event_to_handle(event
);
1817 tu_bo_finish(device
, &event
->bo
);
1819 vk_free2(&device
->alloc
, pAllocator
, event
);
1820 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1824 tu_DestroyEvent(VkDevice _device
,
1826 const VkAllocationCallbacks
*pAllocator
)
1828 TU_FROM_HANDLE(tu_device
, device
, _device
);
1829 TU_FROM_HANDLE(tu_event
, event
, _event
);
1834 tu_bo_finish(device
, &event
->bo
);
1835 vk_free2(&device
->alloc
, pAllocator
, event
);
1839 tu_GetEventStatus(VkDevice _device
, VkEvent _event
)
1841 TU_FROM_HANDLE(tu_event
, event
, _event
);
1843 if (*(uint64_t*) event
->bo
.map
== 1)
1844 return VK_EVENT_SET
;
1845 return VK_EVENT_RESET
;
1849 tu_SetEvent(VkDevice _device
, VkEvent _event
)
1851 TU_FROM_HANDLE(tu_event
, event
, _event
);
1852 *(uint64_t*) event
->bo
.map
= 1;
1858 tu_ResetEvent(VkDevice _device
, VkEvent _event
)
1860 TU_FROM_HANDLE(tu_event
, event
, _event
);
1861 *(uint64_t*) event
->bo
.map
= 0;
1867 tu_CreateBuffer(VkDevice _device
,
1868 const VkBufferCreateInfo
*pCreateInfo
,
1869 const VkAllocationCallbacks
*pAllocator
,
1872 TU_FROM_HANDLE(tu_device
, device
, _device
);
1873 struct tu_buffer
*buffer
;
1875 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1877 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1878 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1880 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1882 buffer
->size
= pCreateInfo
->size
;
1883 buffer
->usage
= pCreateInfo
->usage
;
1884 buffer
->flags
= pCreateInfo
->flags
;
1886 *pBuffer
= tu_buffer_to_handle(buffer
);
1892 tu_DestroyBuffer(VkDevice _device
,
1894 const VkAllocationCallbacks
*pAllocator
)
1896 TU_FROM_HANDLE(tu_device
, device
, _device
);
1897 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1902 vk_free2(&device
->alloc
, pAllocator
, buffer
);
1906 tu_surface_max_layer_count(struct tu_image_view
*iview
)
1908 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
1909 ? iview
->extent
.depth
1910 : (iview
->base_layer
+ iview
->layer_count
);
1914 tu_CreateFramebuffer(VkDevice _device
,
1915 const VkFramebufferCreateInfo
*pCreateInfo
,
1916 const VkAllocationCallbacks
*pAllocator
,
1917 VkFramebuffer
*pFramebuffer
)
1919 TU_FROM_HANDLE(tu_device
, device
, _device
);
1920 struct tu_framebuffer
*framebuffer
;
1922 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1924 size_t size
= sizeof(*framebuffer
) + sizeof(struct tu_attachment_info
) *
1925 pCreateInfo
->attachmentCount
;
1926 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1927 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1928 if (framebuffer
== NULL
)
1929 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1931 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1932 framebuffer
->width
= pCreateInfo
->width
;
1933 framebuffer
->height
= pCreateInfo
->height
;
1934 framebuffer
->layers
= pCreateInfo
->layers
;
1935 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1936 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1937 struct tu_image_view
*iview
= tu_image_view_from_handle(_iview
);
1938 framebuffer
->attachments
[i
].attachment
= iview
;
1940 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
1941 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
1942 framebuffer
->layers
=
1943 MIN2(framebuffer
->layers
, tu_surface_max_layer_count(iview
));
1946 *pFramebuffer
= tu_framebuffer_to_handle(framebuffer
);
1951 tu_DestroyFramebuffer(VkDevice _device
,
1953 const VkAllocationCallbacks
*pAllocator
)
1955 TU_FROM_HANDLE(tu_device
, device
, _device
);
1956 TU_FROM_HANDLE(tu_framebuffer
, fb
, _fb
);
1960 vk_free2(&device
->alloc
, pAllocator
, fb
);
1963 static enum a6xx_tex_clamp
1964 tu6_tex_wrap(VkSamplerAddressMode address_mode
, bool *needs_border
)
1966 switch (address_mode
) {
1967 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
1968 return A6XX_TEX_REPEAT
;
1969 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
1970 return A6XX_TEX_MIRROR_REPEAT
;
1971 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
1972 return A6XX_TEX_CLAMP_TO_EDGE
;
1973 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
1974 *needs_border
= true;
1975 return A6XX_TEX_CLAMP_TO_BORDER
;
1976 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
1977 /* only works for PoT.. need to emulate otherwise! */
1978 return A6XX_TEX_MIRROR_CLAMP
;
1980 unreachable("illegal tex wrap mode");
1985 static enum a6xx_tex_filter
1986 tu6_tex_filter(VkFilter filter
, unsigned aniso
)
1989 case VK_FILTER_NEAREST
:
1990 return A6XX_TEX_NEAREST
;
1991 case VK_FILTER_LINEAR
:
1992 return aniso
? A6XX_TEX_ANISO
: A6XX_TEX_LINEAR
;
1993 case VK_FILTER_CUBIC_IMG
:
1995 unreachable("illegal texture filter");
2000 static inline enum adreno_compare_func
2001 tu6_compare_func(VkCompareOp op
)
2003 return (enum adreno_compare_func
) op
;
2007 tu_init_sampler(struct tu_device
*device
,
2008 struct tu_sampler
*sampler
,
2009 const VkSamplerCreateInfo
*pCreateInfo
)
2011 unsigned aniso
= pCreateInfo
->anisotropyEnable
?
2012 util_last_bit(MIN2((uint32_t)pCreateInfo
->maxAnisotropy
>> 1, 8)) : 0;
2013 bool miplinear
= (pCreateInfo
->mipmapMode
== VK_SAMPLER_MIPMAP_MODE_LINEAR
);
2014 bool needs_border
= false;
2017 COND(miplinear
, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR
) |
2018 A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo
->magFilter
, aniso
)) |
2019 A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo
->minFilter
, aniso
)) |
2020 A6XX_TEX_SAMP_0_ANISO(aniso
) |
2021 A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo
->addressModeU
, &needs_border
)) |
2022 A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo
->addressModeV
, &needs_border
)) |
2023 A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo
->addressModeW
, &needs_border
)) |
2024 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo
->mipLodBias
);
2026 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
2027 COND(pCreateInfo
->unnormalizedCoordinates
, A6XX_TEX_SAMP_1_UNNORM_COORDS
) |
2028 A6XX_TEX_SAMP_1_MIN_LOD(pCreateInfo
->minLod
) |
2029 A6XX_TEX_SAMP_1_MAX_LOD(pCreateInfo
->maxLod
) |
2030 COND(pCreateInfo
->compareEnable
,
2031 A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo
->compareOp
)));
2032 sampler
->state
[2] = 0;
2033 sampler
->state
[3] = 0;
2036 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
2040 sampler
->needs_border
= needs_border
;
2041 sampler
->border
= pCreateInfo
->borderColor
;
2045 tu_CreateSampler(VkDevice _device
,
2046 const VkSamplerCreateInfo
*pCreateInfo
,
2047 const VkAllocationCallbacks
*pAllocator
,
2048 VkSampler
*pSampler
)
2050 TU_FROM_HANDLE(tu_device
, device
, _device
);
2051 struct tu_sampler
*sampler
;
2053 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2055 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
2056 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2058 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2060 tu_init_sampler(device
, sampler
, pCreateInfo
);
2061 *pSampler
= tu_sampler_to_handle(sampler
);
2067 tu_DestroySampler(VkDevice _device
,
2069 const VkAllocationCallbacks
*pAllocator
)
2071 TU_FROM_HANDLE(tu_device
, device
, _device
);
2072 TU_FROM_HANDLE(tu_sampler
, sampler
, _sampler
);
2076 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2079 /* vk_icd.h does not declare this function, so we declare it here to
2080 * suppress Wmissing-prototypes.
2082 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2083 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2085 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2086 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2088 /* For the full details on loader interface versioning, see
2089 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2090 * What follows is a condensed summary, to help you navigate the large and
2091 * confusing official doc.
2093 * - Loader interface v0 is incompatible with later versions. We don't
2096 * - In loader interface v1:
2097 * - The first ICD entrypoint called by the loader is
2098 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2100 * - The ICD must statically expose no other Vulkan symbol unless it
2101 * is linked with -Bsymbolic.
2102 * - Each dispatchable Vulkan handle created by the ICD must be
2103 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2104 * ICD must initialize VK_LOADER_DATA.loadMagic to
2106 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2107 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2108 * such loader-managed surfaces.
2110 * - Loader interface v2 differs from v1 in:
2111 * - The first ICD entrypoint called by the loader is
2112 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2113 * statically expose this entrypoint.
2115 * - Loader interface v3 differs from v2 in:
2116 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2117 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2118 * because the loader no longer does so.
2120 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
2125 tu_GetMemoryFdKHR(VkDevice _device
,
2126 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
2129 TU_FROM_HANDLE(tu_device
, device
, _device
);
2130 TU_FROM_HANDLE(tu_device_memory
, memory
, pGetFdInfo
->memory
);
2132 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2134 /* At the moment, we support only the below handle types. */
2135 assert(pGetFdInfo
->handleType
==
2136 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2137 pGetFdInfo
->handleType
==
2138 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2140 int prime_fd
= tu_bo_export_dmabuf(device
, &memory
->bo
);
2142 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2149 tu_GetMemoryFdPropertiesKHR(VkDevice _device
,
2150 VkExternalMemoryHandleTypeFlagBits handleType
,
2152 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
2154 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2155 pMemoryFdProperties
->memoryTypeBits
= 1;
2160 tu_GetPhysicalDeviceExternalSemaphoreProperties(
2161 VkPhysicalDevice physicalDevice
,
2162 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
2163 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
2165 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
2166 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
2167 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
2171 tu_GetPhysicalDeviceExternalFenceProperties(
2172 VkPhysicalDevice physicalDevice
,
2173 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
2174 VkExternalFenceProperties
*pExternalFenceProperties
)
2176 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
2177 pExternalFenceProperties
->compatibleHandleTypes
= 0;
2178 pExternalFenceProperties
->externalFenceFeatures
= 0;
2182 tu_CreateDebugReportCallbackEXT(
2183 VkInstance _instance
,
2184 const VkDebugReportCallbackCreateInfoEXT
*pCreateInfo
,
2185 const VkAllocationCallbacks
*pAllocator
,
2186 VkDebugReportCallbackEXT
*pCallback
)
2188 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2189 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2190 pCreateInfo
, pAllocator
,
2191 &instance
->alloc
, pCallback
);
2195 tu_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2196 VkDebugReportCallbackEXT _callback
,
2197 const VkAllocationCallbacks
*pAllocator
)
2199 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2200 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2201 _callback
, pAllocator
, &instance
->alloc
);
2205 tu_DebugReportMessageEXT(VkInstance _instance
,
2206 VkDebugReportFlagsEXT flags
,
2207 VkDebugReportObjectTypeEXT objectType
,
2210 int32_t messageCode
,
2211 const char *pLayerPrefix
,
2212 const char *pMessage
)
2214 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2215 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2216 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2220 tu_GetDeviceGroupPeerMemoryFeatures(
2223 uint32_t localDeviceIndex
,
2224 uint32_t remoteDeviceIndex
,
2225 VkPeerMemoryFeatureFlags
*pPeerMemoryFeatures
)
2227 assert(localDeviceIndex
== remoteDeviceIndex
);
2229 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2230 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2231 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2232 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;