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 memset(device
->name
, 0, sizeof(device
->name
));
256 sprintf(device
->name
, "FD%d", device
->gpu_id
);
258 switch (device
->gpu_id
) {
260 device
->tile_align_w
= 64;
261 device
->tile_align_h
= 16;
262 device
->magic
.RB_UNKNOWN_8E04_blit
= 0x00100000;
263 device
->magic
.RB_CCU_CNTL_gmem
= 0x3e400004;
264 device
->magic
.PC_UNKNOWN_9805
= 0x0;
265 device
->magic
.SP_UNKNOWN_A0F8
= 0x0;
269 device
->tile_align_w
= 64;
270 device
->tile_align_h
= 16;
271 device
->magic
.RB_UNKNOWN_8E04_blit
= 0x01000000;
272 device
->magic
.RB_CCU_CNTL_gmem
= 0x7c400004;
273 device
->magic
.PC_UNKNOWN_9805
= 0x1;
274 device
->magic
.SP_UNKNOWN_A0F8
= 0x1;
277 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
278 "device %s is unsupported", device
->name
);
281 if (tu_device_get_cache_uuid(device
->gpu_id
, device
->cache_uuid
)) {
282 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
283 "cannot generate UUID");
287 /* The gpu id is already embedded in the uuid so we just pass "tu"
288 * when creating the cache.
290 char buf
[VK_UUID_SIZE
* 2 + 1];
291 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
292 device
->disk_cache
= disk_cache_create(device
->name
, buf
, 0);
294 fprintf(stderr
, "WARNING: tu is not a conformant vulkan implementation, "
295 "testing use only.\n");
297 tu_get_driver_uuid(&device
->device_uuid
);
298 tu_get_device_uuid(&device
->device_uuid
);
300 tu_fill_device_extension_table(device
, &device
->supported_extensions
);
302 if (result
!= VK_SUCCESS
) {
303 vk_error(instance
, result
);
307 result
= tu_wsi_init(device
);
308 if (result
!= VK_SUCCESS
) {
309 vk_error(instance
, result
);
323 tu_physical_device_finish(struct tu_physical_device
*device
)
325 tu_wsi_finish(device
);
327 disk_cache_destroy(device
->disk_cache
);
328 close(device
->local_fd
);
329 if (device
->master_fd
!= -1)
330 close(device
->master_fd
);
334 default_alloc_func(void *pUserData
,
337 VkSystemAllocationScope allocationScope
)
343 default_realloc_func(void *pUserData
,
347 VkSystemAllocationScope allocationScope
)
349 return realloc(pOriginal
, size
);
353 default_free_func(void *pUserData
, void *pMemory
)
358 static const VkAllocationCallbacks default_alloc
= {
360 .pfnAllocation
= default_alloc_func
,
361 .pfnReallocation
= default_realloc_func
,
362 .pfnFree
= default_free_func
,
365 static const struct debug_control tu_debug_options
[] = {
366 { "startup", TU_DEBUG_STARTUP
},
367 { "nir", TU_DEBUG_NIR
},
368 { "ir3", TU_DEBUG_IR3
},
369 { "nobin", TU_DEBUG_NOBIN
},
370 { "sysmem", TU_DEBUG_SYSMEM
},
371 { "forcebin", TU_DEBUG_FORCEBIN
},
376 tu_get_debug_option_name(int id
)
378 assert(id
< ARRAY_SIZE(tu_debug_options
) - 1);
379 return tu_debug_options
[id
].string
;
383 tu_get_instance_extension_index(const char *name
)
385 for (unsigned i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; ++i
) {
386 if (strcmp(name
, tu_instance_extensions
[i
].extensionName
) == 0)
393 tu_CreateInstance(const VkInstanceCreateInfo
*pCreateInfo
,
394 const VkAllocationCallbacks
*pAllocator
,
395 VkInstance
*pInstance
)
397 struct tu_instance
*instance
;
400 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
402 uint32_t client_version
;
403 if (pCreateInfo
->pApplicationInfo
&&
404 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
405 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
407 tu_EnumerateInstanceVersion(&client_version
);
410 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
411 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
413 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
415 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
418 instance
->alloc
= *pAllocator
;
420 instance
->alloc
= default_alloc
;
422 instance
->api_version
= client_version
;
423 instance
->physical_device_count
= -1;
425 instance
->debug_flags
=
426 parse_debug_string(getenv("TU_DEBUG"), tu_debug_options
);
428 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
429 tu_logi("Created an instance");
431 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
432 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
433 int index
= tu_get_instance_extension_index(ext_name
);
435 if (index
< 0 || !tu_supported_instance_extensions
.extensions
[index
]) {
436 vk_free2(&default_alloc
, pAllocator
, instance
);
437 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
440 instance
->enabled_extensions
.extensions
[index
] = true;
443 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
444 if (result
!= VK_SUCCESS
) {
445 vk_free2(&default_alloc
, pAllocator
, instance
);
446 return vk_error(instance
, result
);
449 glsl_type_singleton_init_or_ref();
451 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
453 *pInstance
= tu_instance_to_handle(instance
);
459 tu_DestroyInstance(VkInstance _instance
,
460 const VkAllocationCallbacks
*pAllocator
)
462 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
467 for (int i
= 0; i
< instance
->physical_device_count
; ++i
) {
468 tu_physical_device_finish(instance
->physical_devices
+ i
);
471 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
473 glsl_type_singleton_decref();
475 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
477 vk_free(&instance
->alloc
, instance
);
481 tu_enumerate_devices(struct tu_instance
*instance
)
483 /* TODO: Check for more devices ? */
484 drmDevicePtr devices
[8];
485 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
488 instance
->physical_device_count
= 0;
490 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
492 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
493 tu_logi("Found %d drm nodes", max_devices
);
496 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
498 for (unsigned i
= 0; i
< (unsigned) max_devices
; i
++) {
499 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
500 devices
[i
]->bustype
== DRM_BUS_PLATFORM
) {
502 result
= tu_physical_device_init(
503 instance
->physical_devices
+ instance
->physical_device_count
,
504 instance
, devices
[i
]);
505 if (result
== VK_SUCCESS
)
506 ++instance
->physical_device_count
;
507 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
511 drmFreeDevices(devices
, max_devices
);
517 tu_EnumeratePhysicalDevices(VkInstance _instance
,
518 uint32_t *pPhysicalDeviceCount
,
519 VkPhysicalDevice
*pPhysicalDevices
)
521 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
522 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
526 if (instance
->physical_device_count
< 0) {
527 result
= tu_enumerate_devices(instance
);
528 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
532 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
533 vk_outarray_append(&out
, p
)
535 *p
= tu_physical_device_to_handle(instance
->physical_devices
+ i
);
539 return vk_outarray_status(&out
);
543 tu_EnumeratePhysicalDeviceGroups(
544 VkInstance _instance
,
545 uint32_t *pPhysicalDeviceGroupCount
,
546 VkPhysicalDeviceGroupProperties
*pPhysicalDeviceGroupProperties
)
548 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
549 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
550 pPhysicalDeviceGroupCount
);
553 if (instance
->physical_device_count
< 0) {
554 result
= tu_enumerate_devices(instance
);
555 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
559 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
560 vk_outarray_append(&out
, p
)
562 p
->physicalDeviceCount
= 1;
563 p
->physicalDevices
[0] =
564 tu_physical_device_to_handle(instance
->physical_devices
+ i
);
565 p
->subsetAllocation
= false;
569 return vk_outarray_status(&out
);
573 tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice
,
574 VkPhysicalDeviceFeatures
*pFeatures
)
576 memset(pFeatures
, 0, sizeof(*pFeatures
));
578 *pFeatures
= (VkPhysicalDeviceFeatures
) {
579 .robustBufferAccess
= false,
580 .fullDrawIndexUint32
= false,
581 .imageCubeArray
= false,
582 .independentBlend
= false,
583 .geometryShader
= false,
584 .tessellationShader
= false,
585 .sampleRateShading
= true,
586 .dualSrcBlend
= false,
588 .multiDrawIndirect
= false,
589 .drawIndirectFirstInstance
= false,
591 .depthBiasClamp
= false,
592 .fillModeNonSolid
= false,
593 .depthBounds
= false,
595 .largePoints
= false,
597 .multiViewport
= false,
598 .samplerAnisotropy
= true,
599 .textureCompressionETC2
= true,
600 .textureCompressionASTC_LDR
= true,
601 .textureCompressionBC
= true,
602 .occlusionQueryPrecise
= true,
603 .pipelineStatisticsQuery
= false,
604 .vertexPipelineStoresAndAtomics
= false,
605 .fragmentStoresAndAtomics
= false,
606 .shaderTessellationAndGeometryPointSize
= false,
607 .shaderImageGatherExtended
= false,
608 .shaderStorageImageExtendedFormats
= false,
609 .shaderStorageImageMultisample
= false,
610 .shaderUniformBufferArrayDynamicIndexing
= false,
611 .shaderSampledImageArrayDynamicIndexing
= false,
612 .shaderStorageBufferArrayDynamicIndexing
= false,
613 .shaderStorageImageArrayDynamicIndexing
= false,
614 .shaderStorageImageReadWithoutFormat
= false,
615 .shaderStorageImageWriteWithoutFormat
= false,
616 .shaderClipDistance
= false,
617 .shaderCullDistance
= false,
618 .shaderFloat64
= false,
619 .shaderInt64
= false,
620 .shaderInt16
= false,
621 .sparseBinding
= false,
622 .variableMultisampleRate
= false,
623 .inheritedQueries
= false,
628 tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice
,
629 VkPhysicalDeviceFeatures2
*pFeatures
)
631 vk_foreach_struct(ext
, pFeatures
->pNext
)
633 switch (ext
->sType
) {
634 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
635 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *) ext
;
636 features
->variablePointersStorageBuffer
= false;
637 features
->variablePointers
= false;
640 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
641 VkPhysicalDeviceMultiviewFeatures
*features
=
642 (VkPhysicalDeviceMultiviewFeatures
*) ext
;
643 features
->multiview
= false;
644 features
->multiviewGeometryShader
= false;
645 features
->multiviewTessellationShader
= false;
648 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
649 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
650 (VkPhysicalDeviceShaderDrawParametersFeatures
*) ext
;
651 features
->shaderDrawParameters
= false;
654 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
655 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
656 (VkPhysicalDeviceProtectedMemoryFeatures
*) ext
;
657 features
->protectedMemory
= false;
660 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
661 VkPhysicalDevice16BitStorageFeatures
*features
=
662 (VkPhysicalDevice16BitStorageFeatures
*) ext
;
663 features
->storageBuffer16BitAccess
= false;
664 features
->uniformAndStorageBuffer16BitAccess
= false;
665 features
->storagePushConstant16
= false;
666 features
->storageInputOutput16
= false;
669 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
670 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
671 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
672 features
->samplerYcbcrConversion
= false;
675 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
676 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
677 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*) ext
;
678 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
679 features
->shaderUniformTexelBufferArrayDynamicIndexing
= false;
680 features
->shaderStorageTexelBufferArrayDynamicIndexing
= false;
681 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
682 features
->shaderSampledImageArrayNonUniformIndexing
= false;
683 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
684 features
->shaderStorageImageArrayNonUniformIndexing
= false;
685 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
686 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
687 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
688 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
689 features
->descriptorBindingSampledImageUpdateAfterBind
= false;
690 features
->descriptorBindingStorageImageUpdateAfterBind
= false;
691 features
->descriptorBindingStorageBufferUpdateAfterBind
= false;
692 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= false;
693 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= false;
694 features
->descriptorBindingUpdateUnusedWhilePending
= false;
695 features
->descriptorBindingPartiallyBound
= false;
696 features
->descriptorBindingVariableDescriptorCount
= false;
697 features
->runtimeDescriptorArray
= false;
700 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
701 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
702 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*) ext
;
703 features
->conditionalRendering
= false;
704 features
->inheritedConditionalRendering
= false;
711 return tu_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
715 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
716 VkPhysicalDeviceProperties
*pProperties
)
718 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
719 VkSampleCountFlags sample_counts
= VK_SAMPLE_COUNT_1_BIT
|
720 VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
| VK_SAMPLE_COUNT_8_BIT
;
722 /* make sure that the entire descriptor set is addressable with a signed
723 * 32-bit int. So the sum of all limits scaled by descriptor size has to
724 * be at most 2 GiB. the combined image & samples object count as one of
725 * both. This limit is for the pipeline layout, not for the set layout, but
726 * there is no set limit, so we just set a pipeline limit. I don't think
727 * any app is going to hit this soon. */
728 size_t max_descriptor_set_size
=
729 ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
730 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
731 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
732 32 /* sampler, largest when combined with image */ +
733 64 /* sampled image */ + 64 /* storage image */);
735 VkPhysicalDeviceLimits limits
= {
736 .maxImageDimension1D
= (1 << 14),
737 .maxImageDimension2D
= (1 << 14),
738 .maxImageDimension3D
= (1 << 11),
739 .maxImageDimensionCube
= (1 << 14),
740 .maxImageArrayLayers
= (1 << 11),
741 .maxTexelBufferElements
= 128 * 1024 * 1024,
742 .maxUniformBufferRange
= UINT32_MAX
,
743 .maxStorageBufferRange
= MAX_STORAGE_BUFFER_RANGE
,
744 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
745 .maxMemoryAllocationCount
= UINT32_MAX
,
746 .maxSamplerAllocationCount
= 64 * 1024,
747 .bufferImageGranularity
= 64, /* A cache line */
748 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
749 .maxBoundDescriptorSets
= MAX_SETS
,
750 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
751 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
752 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
753 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
754 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
755 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
756 .maxPerStageResources
= max_descriptor_set_size
,
757 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
758 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
759 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
760 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
761 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
762 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
763 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
764 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
765 .maxVertexInputAttributes
= 32,
766 .maxVertexInputBindings
= 32,
767 .maxVertexInputAttributeOffset
= 2047,
768 .maxVertexInputBindingStride
= 2048,
769 .maxVertexOutputComponents
= 128,
770 .maxTessellationGenerationLevel
= 64,
771 .maxTessellationPatchSize
= 32,
772 .maxTessellationControlPerVertexInputComponents
= 128,
773 .maxTessellationControlPerVertexOutputComponents
= 128,
774 .maxTessellationControlPerPatchOutputComponents
= 120,
775 .maxTessellationControlTotalOutputComponents
= 4096,
776 .maxTessellationEvaluationInputComponents
= 128,
777 .maxTessellationEvaluationOutputComponents
= 128,
778 .maxGeometryShaderInvocations
= 127,
779 .maxGeometryInputComponents
= 64,
780 .maxGeometryOutputComponents
= 128,
781 .maxGeometryOutputVertices
= 256,
782 .maxGeometryTotalOutputComponents
= 1024,
783 .maxFragmentInputComponents
= 128,
784 .maxFragmentOutputAttachments
= 8,
785 .maxFragmentDualSrcAttachments
= 1,
786 .maxFragmentCombinedOutputResources
= 8,
787 .maxComputeSharedMemorySize
= 32768,
788 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
789 .maxComputeWorkGroupInvocations
= 2048,
790 .maxComputeWorkGroupSize
= { 2048, 2048, 2048 },
791 .subPixelPrecisionBits
= 4 /* FIXME */,
792 .subTexelPrecisionBits
= 4 /* FIXME */,
793 .mipmapPrecisionBits
= 4 /* FIXME */,
794 .maxDrawIndexedIndexValue
= UINT32_MAX
,
795 .maxDrawIndirectCount
= UINT32_MAX
,
796 .maxSamplerLodBias
= 16,
797 .maxSamplerAnisotropy
= 16,
798 .maxViewports
= MAX_VIEWPORTS
,
799 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
800 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
801 .viewportSubPixelBits
= 8,
802 .minMemoryMapAlignment
= 4096, /* A page */
803 .minTexelBufferOffsetAlignment
= 64,
804 .minUniformBufferOffsetAlignment
= 4,
805 .minStorageBufferOffsetAlignment
= 4,
806 .minTexelOffset
= -32,
807 .maxTexelOffset
= 31,
808 .minTexelGatherOffset
= -32,
809 .maxTexelGatherOffset
= 31,
810 .minInterpolationOffset
= -2,
811 .maxInterpolationOffset
= 2,
812 .subPixelInterpolationOffsetBits
= 8,
813 .maxFramebufferWidth
= (1 << 14),
814 .maxFramebufferHeight
= (1 << 14),
815 .maxFramebufferLayers
= (1 << 10),
816 .framebufferColorSampleCounts
= sample_counts
,
817 .framebufferDepthSampleCounts
= sample_counts
,
818 .framebufferStencilSampleCounts
= sample_counts
,
819 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
820 .maxColorAttachments
= MAX_RTS
,
821 .sampledImageColorSampleCounts
= sample_counts
,
822 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
823 .sampledImageDepthSampleCounts
= sample_counts
,
824 .sampledImageStencilSampleCounts
= sample_counts
,
825 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
826 .maxSampleMaskWords
= 1,
827 .timestampComputeAndGraphics
= false, /* FINISHME */
828 .timestampPeriod
= 1,
829 .maxClipDistances
= 8,
830 .maxCullDistances
= 8,
831 .maxCombinedClipAndCullDistances
= 8,
832 .discreteQueuePriorities
= 1,
833 .pointSizeRange
= { 0.125, 255.875 },
834 .lineWidthRange
= { 0.0, 7.9921875 },
835 .pointSizeGranularity
= (1.0 / 8.0),
836 .lineWidthGranularity
= (1.0 / 128.0),
837 .strictLines
= false, /* FINISHME */
838 .standardSampleLocations
= true,
839 .optimalBufferCopyOffsetAlignment
= 128,
840 .optimalBufferCopyRowPitchAlignment
= 128,
841 .nonCoherentAtomSize
= 64,
844 *pProperties
= (VkPhysicalDeviceProperties
) {
845 .apiVersion
= tu_physical_device_api_version(pdevice
),
846 .driverVersion
= vk_get_driver_version(),
847 .vendorID
= 0, /* TODO */
849 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
851 .sparseProperties
= { 0 },
854 strcpy(pProperties
->deviceName
, pdevice
->name
);
855 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
859 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice
,
860 VkPhysicalDeviceProperties2
*pProperties
)
862 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
863 tu_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
865 vk_foreach_struct(ext
, pProperties
->pNext
)
867 switch (ext
->sType
) {
868 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
869 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
870 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
871 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
874 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
875 VkPhysicalDeviceIDProperties
*properties
=
876 (VkPhysicalDeviceIDProperties
*) ext
;
877 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
878 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
879 properties
->deviceLUIDValid
= false;
882 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
883 VkPhysicalDeviceMultiviewProperties
*properties
=
884 (VkPhysicalDeviceMultiviewProperties
*) ext
;
885 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
886 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
889 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
890 VkPhysicalDevicePointClippingProperties
*properties
=
891 (VkPhysicalDevicePointClippingProperties
*) ext
;
892 properties
->pointClippingBehavior
=
893 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
896 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
897 VkPhysicalDeviceMaintenance3Properties
*properties
=
898 (VkPhysicalDeviceMaintenance3Properties
*) ext
;
899 /* Make sure everything is addressable by a signed 32-bit int, and
900 * our largest descriptors are 96 bytes. */
901 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
902 /* Our buffer size fields allow only this much */
903 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
912 static const VkQueueFamilyProperties tu_queue_family_properties
= {
914 VK_QUEUE_GRAPHICS_BIT
| VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
916 .timestampValidBits
= 0, /* FINISHME */
917 .minImageTransferGranularity
= { 1, 1, 1 },
921 tu_GetPhysicalDeviceQueueFamilyProperties(
922 VkPhysicalDevice physicalDevice
,
923 uint32_t *pQueueFamilyPropertyCount
,
924 VkQueueFamilyProperties
*pQueueFamilyProperties
)
926 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
928 vk_outarray_append(&out
, p
) { *p
= tu_queue_family_properties
; }
932 tu_GetPhysicalDeviceQueueFamilyProperties2(
933 VkPhysicalDevice physicalDevice
,
934 uint32_t *pQueueFamilyPropertyCount
,
935 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
937 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
939 vk_outarray_append(&out
, p
)
941 p
->queueFamilyProperties
= tu_queue_family_properties
;
946 tu_get_system_heap_size()
951 uint64_t total_ram
= (uint64_t) info
.totalram
* (uint64_t) info
.mem_unit
;
953 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
954 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
956 uint64_t available_ram
;
957 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
958 available_ram
= total_ram
/ 2;
960 available_ram
= total_ram
* 3 / 4;
962 return available_ram
;
966 tu_GetPhysicalDeviceMemoryProperties(
967 VkPhysicalDevice physicalDevice
,
968 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
970 pMemoryProperties
->memoryHeapCount
= 1;
971 pMemoryProperties
->memoryHeaps
[0].size
= tu_get_system_heap_size();
972 pMemoryProperties
->memoryHeaps
[0].flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
;
974 pMemoryProperties
->memoryTypeCount
= 1;
975 pMemoryProperties
->memoryTypes
[0].propertyFlags
=
976 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
977 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
978 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
;
979 pMemoryProperties
->memoryTypes
[0].heapIndex
= 0;
983 tu_GetPhysicalDeviceMemoryProperties2(
984 VkPhysicalDevice physicalDevice
,
985 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
987 return tu_GetPhysicalDeviceMemoryProperties(
988 physicalDevice
, &pMemoryProperties
->memoryProperties
);
992 tu_queue_init(struct tu_device
*device
,
993 struct tu_queue
*queue
,
994 uint32_t queue_family_index
,
996 VkDeviceQueueCreateFlags flags
)
998 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
999 queue
->device
= device
;
1000 queue
->queue_family_index
= queue_family_index
;
1001 queue
->queue_idx
= idx
;
1002 queue
->flags
= flags
;
1004 int ret
= tu_drm_submitqueue_new(device
, 0, &queue
->msm_queue_id
);
1006 return VK_ERROR_INITIALIZATION_FAILED
;
1008 tu_fence_init(&queue
->submit_fence
, false);
1014 tu_queue_finish(struct tu_queue
*queue
)
1016 tu_fence_finish(&queue
->submit_fence
);
1017 tu_drm_submitqueue_close(queue
->device
, queue
->msm_queue_id
);
1021 tu_get_device_extension_index(const char *name
)
1023 for (unsigned i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; ++i
) {
1024 if (strcmp(name
, tu_device_extensions
[i
].extensionName
) == 0)
1031 tu_CreateDevice(VkPhysicalDevice physicalDevice
,
1032 const VkDeviceCreateInfo
*pCreateInfo
,
1033 const VkAllocationCallbacks
*pAllocator
,
1036 TU_FROM_HANDLE(tu_physical_device
, physical_device
, physicalDevice
);
1038 struct tu_device
*device
;
1040 /* Check enabled features */
1041 if (pCreateInfo
->pEnabledFeatures
) {
1042 VkPhysicalDeviceFeatures supported_features
;
1043 tu_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1044 VkBool32
*supported_feature
= (VkBool32
*) &supported_features
;
1045 VkBool32
*enabled_feature
= (VkBool32
*) pCreateInfo
->pEnabledFeatures
;
1046 unsigned num_features
=
1047 sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1048 for (uint32_t i
= 0; i
< num_features
; i
++) {
1049 if (enabled_feature
[i
] && !supported_feature
[i
])
1050 return vk_error(physical_device
->instance
,
1051 VK_ERROR_FEATURE_NOT_PRESENT
);
1055 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1056 sizeof(*device
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1058 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1060 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1061 device
->instance
= physical_device
->instance
;
1062 device
->physical_device
= physical_device
;
1065 device
->alloc
= *pAllocator
;
1067 device
->alloc
= physical_device
->instance
->alloc
;
1069 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1070 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1071 int index
= tu_get_device_extension_index(ext_name
);
1073 !physical_device
->supported_extensions
.extensions
[index
]) {
1074 vk_free(&device
->alloc
, device
);
1075 return vk_error(physical_device
->instance
,
1076 VK_ERROR_EXTENSION_NOT_PRESENT
);
1079 device
->enabled_extensions
.extensions
[index
] = true;
1082 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1083 const VkDeviceQueueCreateInfo
*queue_create
=
1084 &pCreateInfo
->pQueueCreateInfos
[i
];
1085 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1086 device
->queues
[qfi
] = vk_alloc(
1087 &device
->alloc
, queue_create
->queueCount
* sizeof(struct tu_queue
),
1088 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1089 if (!device
->queues
[qfi
]) {
1090 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1094 memset(device
->queues
[qfi
], 0,
1095 queue_create
->queueCount
* sizeof(struct tu_queue
));
1097 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1099 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1100 result
= tu_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
,
1101 queue_create
->flags
);
1102 if (result
!= VK_SUCCESS
)
1107 device
->compiler
= ir3_compiler_create(NULL
, physical_device
->gpu_id
);
1108 if (!device
->compiler
)
1111 #define VSC_DATA_SIZE(pitch) ((pitch) * 32 + 0x100) /* extra size to store VSC_SIZE */
1112 #define VSC_DATA2_SIZE(pitch) ((pitch) * 32)
1114 device
->vsc_data_pitch
= 0x440 * 4;
1115 device
->vsc_data2_pitch
= 0x1040 * 4;
1117 result
= tu_bo_init_new(device
, &device
->vsc_data
, VSC_DATA_SIZE(device
->vsc_data_pitch
));
1118 if (result
!= VK_SUCCESS
)
1121 result
= tu_bo_init_new(device
, &device
->vsc_data2
, VSC_DATA2_SIZE(device
->vsc_data2_pitch
));
1122 if (result
!= VK_SUCCESS
)
1123 goto fail_vsc_data2
;
1125 VkPipelineCacheCreateInfo ci
;
1126 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1129 ci
.pInitialData
= NULL
;
1130 ci
.initialDataSize
= 0;
1133 tu_CreatePipelineCache(tu_device_to_handle(device
), &ci
, NULL
, &pc
);
1134 if (result
!= VK_SUCCESS
)
1135 goto fail_pipeline_cache
;
1137 device
->mem_cache
= tu_pipeline_cache_from_handle(pc
);
1139 *pDevice
= tu_device_to_handle(device
);
1142 fail_pipeline_cache
:
1143 tu_bo_finish(device
, &device
->vsc_data2
);
1146 tu_bo_finish(device
, &device
->vsc_data
);
1149 ralloc_free(device
->compiler
);
1152 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1153 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1154 tu_queue_finish(&device
->queues
[i
][q
]);
1155 if (device
->queue_count
[i
])
1156 vk_free(&device
->alloc
, device
->queues
[i
]);
1159 vk_free(&device
->alloc
, device
);
1164 tu_DestroyDevice(VkDevice _device
, const VkAllocationCallbacks
*pAllocator
)
1166 TU_FROM_HANDLE(tu_device
, device
, _device
);
1171 tu_bo_finish(device
, &device
->vsc_data
);
1172 tu_bo_finish(device
, &device
->vsc_data2
);
1174 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1175 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1176 tu_queue_finish(&device
->queues
[i
][q
]);
1177 if (device
->queue_count
[i
])
1178 vk_free(&device
->alloc
, device
->queues
[i
]);
1181 /* the compiler does not use pAllocator */
1182 ralloc_free(device
->compiler
);
1184 VkPipelineCache pc
= tu_pipeline_cache_to_handle(device
->mem_cache
);
1185 tu_DestroyPipelineCache(tu_device_to_handle(device
), pc
, NULL
);
1187 vk_free(&device
->alloc
, device
);
1191 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount
,
1192 VkLayerProperties
*pProperties
)
1194 *pPropertyCount
= 0;
1199 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice
,
1200 uint32_t *pPropertyCount
,
1201 VkLayerProperties
*pProperties
)
1203 *pPropertyCount
= 0;
1208 tu_GetDeviceQueue2(VkDevice _device
,
1209 const VkDeviceQueueInfo2
*pQueueInfo
,
1212 TU_FROM_HANDLE(tu_device
, device
, _device
);
1213 struct tu_queue
*queue
;
1216 &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1217 if (pQueueInfo
->flags
!= queue
->flags
) {
1218 /* From the Vulkan 1.1.70 spec:
1220 * "The queue returned by vkGetDeviceQueue2 must have the same
1221 * flags value from this structure as that used at device
1222 * creation time in a VkDeviceQueueCreateInfo instance. If no
1223 * matching flags were specified at device creation time then
1224 * pQueue will return VK_NULL_HANDLE."
1226 *pQueue
= VK_NULL_HANDLE
;
1230 *pQueue
= tu_queue_to_handle(queue
);
1234 tu_GetDeviceQueue(VkDevice _device
,
1235 uint32_t queueFamilyIndex
,
1236 uint32_t queueIndex
,
1239 const VkDeviceQueueInfo2 info
=
1240 (VkDeviceQueueInfo2
) { .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1241 .queueFamilyIndex
= queueFamilyIndex
,
1242 .queueIndex
= queueIndex
};
1244 tu_GetDeviceQueue2(_device
, &info
, pQueue
);
1248 tu_QueueSubmit(VkQueue _queue
,
1249 uint32_t submitCount
,
1250 const VkSubmitInfo
*pSubmits
,
1253 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1255 for (uint32_t i
= 0; i
< submitCount
; ++i
) {
1256 const VkSubmitInfo
*submit
= pSubmits
+ i
;
1257 const bool last_submit
= (i
== submitCount
- 1);
1258 struct tu_bo_list bo_list
;
1259 tu_bo_list_init(&bo_list
);
1261 uint32_t entry_count
= 0;
1262 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1263 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1264 entry_count
+= cmdbuf
->cs
.entry_count
;
1267 struct drm_msm_gem_submit_cmd cmds
[entry_count
];
1268 uint32_t entry_idx
= 0;
1269 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1270 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1271 struct tu_cs
*cs
= &cmdbuf
->cs
;
1272 for (unsigned i
= 0; i
< cs
->entry_count
; ++i
, ++entry_idx
) {
1273 cmds
[entry_idx
].type
= MSM_SUBMIT_CMD_BUF
;
1274 cmds
[entry_idx
].submit_idx
=
1275 tu_bo_list_add(&bo_list
, cs
->entries
[i
].bo
,
1276 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1277 cmds
[entry_idx
].submit_offset
= cs
->entries
[i
].offset
;
1278 cmds
[entry_idx
].size
= cs
->entries
[i
].size
;
1279 cmds
[entry_idx
].pad
= 0;
1280 cmds
[entry_idx
].nr_relocs
= 0;
1281 cmds
[entry_idx
].relocs
= 0;
1284 tu_bo_list_merge(&bo_list
, &cmdbuf
->bo_list
);
1287 uint32_t flags
= MSM_PIPE_3D0
;
1289 flags
|= MSM_SUBMIT_FENCE_FD_OUT
;
1292 struct drm_msm_gem_submit req
= {
1294 .queueid
= queue
->msm_queue_id
,
1295 .bos
= (uint64_t)(uintptr_t) bo_list
.bo_infos
,
1296 .nr_bos
= bo_list
.count
,
1297 .cmds
= (uint64_t)(uintptr_t)cmds
,
1298 .nr_cmds
= entry_count
,
1301 int ret
= drmCommandWriteRead(queue
->device
->physical_device
->local_fd
,
1305 fprintf(stderr
, "submit failed: %s\n", strerror(errno
));
1309 tu_bo_list_destroy(&bo_list
);
1312 /* no need to merge fences as queue execution is serialized */
1313 tu_fence_update_fd(&queue
->submit_fence
, req
.fence_fd
);
1317 if (_fence
!= VK_NULL_HANDLE
) {
1318 TU_FROM_HANDLE(tu_fence
, fence
, _fence
);
1319 tu_fence_copy(fence
, &queue
->submit_fence
);
1326 tu_QueueWaitIdle(VkQueue _queue
)
1328 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1330 tu_fence_wait_idle(&queue
->submit_fence
);
1336 tu_DeviceWaitIdle(VkDevice _device
)
1338 TU_FROM_HANDLE(tu_device
, device
, _device
);
1340 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1341 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1342 tu_QueueWaitIdle(tu_queue_to_handle(&device
->queues
[i
][q
]));
1349 tu_EnumerateInstanceExtensionProperties(const char *pLayerName
,
1350 uint32_t *pPropertyCount
,
1351 VkExtensionProperties
*pProperties
)
1353 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1355 /* We spport no lyaers */
1357 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1359 for (int i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; i
++) {
1360 if (tu_supported_instance_extensions
.extensions
[i
]) {
1361 vk_outarray_append(&out
, prop
) { *prop
= tu_instance_extensions
[i
]; }
1365 return vk_outarray_status(&out
);
1369 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
1370 const char *pLayerName
,
1371 uint32_t *pPropertyCount
,
1372 VkExtensionProperties
*pProperties
)
1374 /* We spport no lyaers */
1375 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
1376 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1378 /* We spport no lyaers */
1380 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1382 for (int i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; i
++) {
1383 if (device
->supported_extensions
.extensions
[i
]) {
1384 vk_outarray_append(&out
, prop
) { *prop
= tu_device_extensions
[i
]; }
1388 return vk_outarray_status(&out
);
1392 tu_GetInstanceProcAddr(VkInstance _instance
, const char *pName
)
1394 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
1396 return tu_lookup_entrypoint_checked(
1397 pName
, instance
? instance
->api_version
: 0,
1398 instance
? &instance
->enabled_extensions
: NULL
, NULL
);
1401 /* The loader wants us to expose a second GetInstanceProcAddr function
1402 * to work around certain LD_PRELOAD issues seen in apps.
1405 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1406 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
);
1409 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1410 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
)
1412 return tu_GetInstanceProcAddr(instance
, pName
);
1416 tu_GetDeviceProcAddr(VkDevice _device
, const char *pName
)
1418 TU_FROM_HANDLE(tu_device
, device
, _device
);
1420 return tu_lookup_entrypoint_checked(pName
, device
->instance
->api_version
,
1421 &device
->instance
->enabled_extensions
,
1422 &device
->enabled_extensions
);
1426 tu_alloc_memory(struct tu_device
*device
,
1427 const VkMemoryAllocateInfo
*pAllocateInfo
,
1428 const VkAllocationCallbacks
*pAllocator
,
1429 VkDeviceMemory
*pMem
)
1431 struct tu_device_memory
*mem
;
1434 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1436 if (pAllocateInfo
->allocationSize
== 0) {
1437 /* Apparently, this is allowed */
1438 *pMem
= VK_NULL_HANDLE
;
1442 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1443 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1445 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1447 const VkImportMemoryFdInfoKHR
*fd_info
=
1448 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1449 if (fd_info
&& !fd_info
->handleType
)
1453 assert(fd_info
->handleType
==
1454 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1455 fd_info
->handleType
==
1456 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1459 * TODO Importing the same fd twice gives us the same handle without
1460 * reference counting. We need to maintain a per-instance handle-to-bo
1461 * table and add reference count to tu_bo.
1463 result
= tu_bo_init_dmabuf(device
, &mem
->bo
,
1464 pAllocateInfo
->allocationSize
, fd_info
->fd
);
1465 if (result
== VK_SUCCESS
) {
1466 /* take ownership and close the fd */
1471 tu_bo_init_new(device
, &mem
->bo
, pAllocateInfo
->allocationSize
);
1474 if (result
!= VK_SUCCESS
) {
1475 vk_free2(&device
->alloc
, pAllocator
, mem
);
1479 mem
->size
= pAllocateInfo
->allocationSize
;
1480 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1483 mem
->user_ptr
= NULL
;
1485 *pMem
= tu_device_memory_to_handle(mem
);
1491 tu_AllocateMemory(VkDevice _device
,
1492 const VkMemoryAllocateInfo
*pAllocateInfo
,
1493 const VkAllocationCallbacks
*pAllocator
,
1494 VkDeviceMemory
*pMem
)
1496 TU_FROM_HANDLE(tu_device
, device
, _device
);
1497 return tu_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
1501 tu_FreeMemory(VkDevice _device
,
1502 VkDeviceMemory _mem
,
1503 const VkAllocationCallbacks
*pAllocator
)
1505 TU_FROM_HANDLE(tu_device
, device
, _device
);
1506 TU_FROM_HANDLE(tu_device_memory
, mem
, _mem
);
1511 tu_bo_finish(device
, &mem
->bo
);
1512 vk_free2(&device
->alloc
, pAllocator
, mem
);
1516 tu_MapMemory(VkDevice _device
,
1517 VkDeviceMemory _memory
,
1518 VkDeviceSize offset
,
1520 VkMemoryMapFlags flags
,
1523 TU_FROM_HANDLE(tu_device
, device
, _device
);
1524 TU_FROM_HANDLE(tu_device_memory
, mem
, _memory
);
1532 if (mem
->user_ptr
) {
1533 *ppData
= mem
->user_ptr
;
1534 } else if (!mem
->map
) {
1535 result
= tu_bo_map(device
, &mem
->bo
);
1536 if (result
!= VK_SUCCESS
)
1538 *ppData
= mem
->map
= mem
->bo
.map
;
1547 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
1551 tu_UnmapMemory(VkDevice _device
, VkDeviceMemory _memory
)
1553 /* I do not see any unmapping done by the freedreno Gallium driver. */
1557 tu_FlushMappedMemoryRanges(VkDevice _device
,
1558 uint32_t memoryRangeCount
,
1559 const VkMappedMemoryRange
*pMemoryRanges
)
1565 tu_InvalidateMappedMemoryRanges(VkDevice _device
,
1566 uint32_t memoryRangeCount
,
1567 const VkMappedMemoryRange
*pMemoryRanges
)
1573 tu_GetBufferMemoryRequirements(VkDevice _device
,
1575 VkMemoryRequirements
*pMemoryRequirements
)
1577 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1579 pMemoryRequirements
->memoryTypeBits
= 1;
1580 pMemoryRequirements
->alignment
= 16;
1581 pMemoryRequirements
->size
=
1582 align64(buffer
->size
, pMemoryRequirements
->alignment
);
1586 tu_GetBufferMemoryRequirements2(
1588 const VkBufferMemoryRequirementsInfo2
*pInfo
,
1589 VkMemoryRequirements2
*pMemoryRequirements
)
1591 tu_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
1592 &pMemoryRequirements
->memoryRequirements
);
1596 tu_GetImageMemoryRequirements(VkDevice _device
,
1598 VkMemoryRequirements
*pMemoryRequirements
)
1600 TU_FROM_HANDLE(tu_image
, image
, _image
);
1602 pMemoryRequirements
->memoryTypeBits
= 1;
1603 pMemoryRequirements
->size
= image
->layout
.size
;
1604 pMemoryRequirements
->alignment
= image
->alignment
;
1608 tu_GetImageMemoryRequirements2(VkDevice device
,
1609 const VkImageMemoryRequirementsInfo2
*pInfo
,
1610 VkMemoryRequirements2
*pMemoryRequirements
)
1612 tu_GetImageMemoryRequirements(device
, pInfo
->image
,
1613 &pMemoryRequirements
->memoryRequirements
);
1617 tu_GetImageSparseMemoryRequirements(
1620 uint32_t *pSparseMemoryRequirementCount
,
1621 VkSparseImageMemoryRequirements
*pSparseMemoryRequirements
)
1627 tu_GetImageSparseMemoryRequirements2(
1629 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
1630 uint32_t *pSparseMemoryRequirementCount
,
1631 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
1637 tu_GetDeviceMemoryCommitment(VkDevice device
,
1638 VkDeviceMemory memory
,
1639 VkDeviceSize
*pCommittedMemoryInBytes
)
1641 *pCommittedMemoryInBytes
= 0;
1645 tu_BindBufferMemory2(VkDevice device
,
1646 uint32_t bindInfoCount
,
1647 const VkBindBufferMemoryInfo
*pBindInfos
)
1649 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1650 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1651 TU_FROM_HANDLE(tu_buffer
, buffer
, pBindInfos
[i
].buffer
);
1654 buffer
->bo
= &mem
->bo
;
1655 buffer
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1664 tu_BindBufferMemory(VkDevice device
,
1666 VkDeviceMemory memory
,
1667 VkDeviceSize memoryOffset
)
1669 const VkBindBufferMemoryInfo info
= {
1670 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1673 .memoryOffset
= memoryOffset
1676 return tu_BindBufferMemory2(device
, 1, &info
);
1680 tu_BindImageMemory2(VkDevice device
,
1681 uint32_t bindInfoCount
,
1682 const VkBindImageMemoryInfo
*pBindInfos
)
1684 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1685 TU_FROM_HANDLE(tu_image
, image
, pBindInfos
[i
].image
);
1686 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1689 image
->bo
= &mem
->bo
;
1690 image
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1693 image
->bo_offset
= 0;
1701 tu_BindImageMemory(VkDevice device
,
1703 VkDeviceMemory memory
,
1704 VkDeviceSize memoryOffset
)
1706 const VkBindImageMemoryInfo info
= {
1707 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1710 .memoryOffset
= memoryOffset
1713 return tu_BindImageMemory2(device
, 1, &info
);
1717 tu_QueueBindSparse(VkQueue _queue
,
1718 uint32_t bindInfoCount
,
1719 const VkBindSparseInfo
*pBindInfo
,
1725 // Queue semaphore functions
1728 tu_CreateSemaphore(VkDevice _device
,
1729 const VkSemaphoreCreateInfo
*pCreateInfo
,
1730 const VkAllocationCallbacks
*pAllocator
,
1731 VkSemaphore
*pSemaphore
)
1733 TU_FROM_HANDLE(tu_device
, device
, _device
);
1735 struct tu_semaphore
*sem
=
1736 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sem
), 8,
1737 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1739 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1741 *pSemaphore
= tu_semaphore_to_handle(sem
);
1746 tu_DestroySemaphore(VkDevice _device
,
1747 VkSemaphore _semaphore
,
1748 const VkAllocationCallbacks
*pAllocator
)
1750 TU_FROM_HANDLE(tu_device
, device
, _device
);
1751 TU_FROM_HANDLE(tu_semaphore
, sem
, _semaphore
);
1755 vk_free2(&device
->alloc
, pAllocator
, sem
);
1759 tu_CreateEvent(VkDevice _device
,
1760 const VkEventCreateInfo
*pCreateInfo
,
1761 const VkAllocationCallbacks
*pAllocator
,
1764 TU_FROM_HANDLE(tu_device
, device
, _device
);
1765 struct tu_event
*event
=
1766 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*event
), 8,
1767 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1770 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1772 VkResult result
= tu_bo_init_new(device
, &event
->bo
, 0x1000);
1773 if (result
!= VK_SUCCESS
)
1776 result
= tu_bo_map(device
, &event
->bo
);
1777 if (result
!= VK_SUCCESS
)
1780 *pEvent
= tu_event_to_handle(event
);
1785 tu_bo_finish(device
, &event
->bo
);
1787 vk_free2(&device
->alloc
, pAllocator
, event
);
1788 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1792 tu_DestroyEvent(VkDevice _device
,
1794 const VkAllocationCallbacks
*pAllocator
)
1796 TU_FROM_HANDLE(tu_device
, device
, _device
);
1797 TU_FROM_HANDLE(tu_event
, event
, _event
);
1802 tu_bo_finish(device
, &event
->bo
);
1803 vk_free2(&device
->alloc
, pAllocator
, event
);
1807 tu_GetEventStatus(VkDevice _device
, VkEvent _event
)
1809 TU_FROM_HANDLE(tu_event
, event
, _event
);
1811 if (*(uint64_t*) event
->bo
.map
== 1)
1812 return VK_EVENT_SET
;
1813 return VK_EVENT_RESET
;
1817 tu_SetEvent(VkDevice _device
, VkEvent _event
)
1819 TU_FROM_HANDLE(tu_event
, event
, _event
);
1820 *(uint64_t*) event
->bo
.map
= 1;
1826 tu_ResetEvent(VkDevice _device
, VkEvent _event
)
1828 TU_FROM_HANDLE(tu_event
, event
, _event
);
1829 *(uint64_t*) event
->bo
.map
= 0;
1835 tu_CreateBuffer(VkDevice _device
,
1836 const VkBufferCreateInfo
*pCreateInfo
,
1837 const VkAllocationCallbacks
*pAllocator
,
1840 TU_FROM_HANDLE(tu_device
, device
, _device
);
1841 struct tu_buffer
*buffer
;
1843 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1845 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1846 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1848 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1850 buffer
->size
= pCreateInfo
->size
;
1851 buffer
->usage
= pCreateInfo
->usage
;
1852 buffer
->flags
= pCreateInfo
->flags
;
1854 *pBuffer
= tu_buffer_to_handle(buffer
);
1860 tu_DestroyBuffer(VkDevice _device
,
1862 const VkAllocationCallbacks
*pAllocator
)
1864 TU_FROM_HANDLE(tu_device
, device
, _device
);
1865 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1870 vk_free2(&device
->alloc
, pAllocator
, buffer
);
1874 tu_surface_max_layer_count(struct tu_image_view
*iview
)
1876 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
1877 ? iview
->extent
.depth
1878 : (iview
->base_layer
+ iview
->layer_count
);
1882 tu_CreateFramebuffer(VkDevice _device
,
1883 const VkFramebufferCreateInfo
*pCreateInfo
,
1884 const VkAllocationCallbacks
*pAllocator
,
1885 VkFramebuffer
*pFramebuffer
)
1887 TU_FROM_HANDLE(tu_device
, device
, _device
);
1888 struct tu_framebuffer
*framebuffer
;
1890 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1892 size_t size
= sizeof(*framebuffer
) + sizeof(struct tu_attachment_info
) *
1893 pCreateInfo
->attachmentCount
;
1894 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1895 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1896 if (framebuffer
== NULL
)
1897 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1899 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1900 framebuffer
->width
= pCreateInfo
->width
;
1901 framebuffer
->height
= pCreateInfo
->height
;
1902 framebuffer
->layers
= pCreateInfo
->layers
;
1903 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1904 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1905 struct tu_image_view
*iview
= tu_image_view_from_handle(_iview
);
1906 framebuffer
->attachments
[i
].attachment
= iview
;
1908 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
1909 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
1910 framebuffer
->layers
=
1911 MIN2(framebuffer
->layers
, tu_surface_max_layer_count(iview
));
1914 *pFramebuffer
= tu_framebuffer_to_handle(framebuffer
);
1919 tu_DestroyFramebuffer(VkDevice _device
,
1921 const VkAllocationCallbacks
*pAllocator
)
1923 TU_FROM_HANDLE(tu_device
, device
, _device
);
1924 TU_FROM_HANDLE(tu_framebuffer
, fb
, _fb
);
1928 vk_free2(&device
->alloc
, pAllocator
, fb
);
1931 static enum a6xx_tex_clamp
1932 tu6_tex_wrap(VkSamplerAddressMode address_mode
, bool *needs_border
)
1934 switch (address_mode
) {
1935 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
1936 return A6XX_TEX_REPEAT
;
1937 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
1938 return A6XX_TEX_MIRROR_REPEAT
;
1939 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
1940 return A6XX_TEX_CLAMP_TO_EDGE
;
1941 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
1942 *needs_border
= true;
1943 return A6XX_TEX_CLAMP_TO_BORDER
;
1944 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
1945 /* only works for PoT.. need to emulate otherwise! */
1946 return A6XX_TEX_MIRROR_CLAMP
;
1948 unreachable("illegal tex wrap mode");
1953 static enum a6xx_tex_filter
1954 tu6_tex_filter(VkFilter filter
, unsigned aniso
)
1957 case VK_FILTER_NEAREST
:
1958 return A6XX_TEX_NEAREST
;
1959 case VK_FILTER_LINEAR
:
1960 return aniso
? A6XX_TEX_ANISO
: A6XX_TEX_LINEAR
;
1961 case VK_FILTER_CUBIC_IMG
:
1963 unreachable("illegal texture filter");
1968 static inline enum adreno_compare_func
1969 tu6_compare_func(VkCompareOp op
)
1971 return (enum adreno_compare_func
) op
;
1975 tu_init_sampler(struct tu_device
*device
,
1976 struct tu_sampler
*sampler
,
1977 const VkSamplerCreateInfo
*pCreateInfo
)
1979 unsigned aniso
= pCreateInfo
->anisotropyEnable
?
1980 util_last_bit(MIN2((uint32_t)pCreateInfo
->maxAnisotropy
>> 1, 8)) : 0;
1981 bool miplinear
= (pCreateInfo
->mipmapMode
== VK_SAMPLER_MIPMAP_MODE_LINEAR
);
1982 bool needs_border
= false;
1985 COND(miplinear
, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR
) |
1986 A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo
->magFilter
, aniso
)) |
1987 A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo
->minFilter
, aniso
)) |
1988 A6XX_TEX_SAMP_0_ANISO(aniso
) |
1989 A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo
->addressModeU
, &needs_border
)) |
1990 A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo
->addressModeV
, &needs_border
)) |
1991 A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo
->addressModeW
, &needs_border
)) |
1992 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo
->mipLodBias
);
1994 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
1995 COND(pCreateInfo
->unnormalizedCoordinates
, A6XX_TEX_SAMP_1_UNNORM_COORDS
) |
1996 A6XX_TEX_SAMP_1_MIN_LOD(pCreateInfo
->minLod
) |
1997 A6XX_TEX_SAMP_1_MAX_LOD(pCreateInfo
->maxLod
) |
1998 COND(pCreateInfo
->compareEnable
,
1999 A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo
->compareOp
)));
2000 sampler
->state
[2] = 0;
2001 sampler
->state
[3] = 0;
2004 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
2008 sampler
->needs_border
= needs_border
;
2009 sampler
->border
= pCreateInfo
->borderColor
;
2013 tu_CreateSampler(VkDevice _device
,
2014 const VkSamplerCreateInfo
*pCreateInfo
,
2015 const VkAllocationCallbacks
*pAllocator
,
2016 VkSampler
*pSampler
)
2018 TU_FROM_HANDLE(tu_device
, device
, _device
);
2019 struct tu_sampler
*sampler
;
2021 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2023 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
2024 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2026 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2028 tu_init_sampler(device
, sampler
, pCreateInfo
);
2029 *pSampler
= tu_sampler_to_handle(sampler
);
2035 tu_DestroySampler(VkDevice _device
,
2037 const VkAllocationCallbacks
*pAllocator
)
2039 TU_FROM_HANDLE(tu_device
, device
, _device
);
2040 TU_FROM_HANDLE(tu_sampler
, sampler
, _sampler
);
2044 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2047 /* vk_icd.h does not declare this function, so we declare it here to
2048 * suppress Wmissing-prototypes.
2050 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2051 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2053 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2054 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2056 /* For the full details on loader interface versioning, see
2057 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2058 * What follows is a condensed summary, to help you navigate the large and
2059 * confusing official doc.
2061 * - Loader interface v0 is incompatible with later versions. We don't
2064 * - In loader interface v1:
2065 * - The first ICD entrypoint called by the loader is
2066 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2068 * - The ICD must statically expose no other Vulkan symbol unless it
2069 * is linked with -Bsymbolic.
2070 * - Each dispatchable Vulkan handle created by the ICD must be
2071 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2072 * ICD must initialize VK_LOADER_DATA.loadMagic to
2074 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2075 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2076 * such loader-managed surfaces.
2078 * - Loader interface v2 differs from v1 in:
2079 * - The first ICD entrypoint called by the loader is
2080 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2081 * statically expose this entrypoint.
2083 * - Loader interface v3 differs from v2 in:
2084 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2085 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2086 * because the loader no longer does so.
2088 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
2093 tu_GetMemoryFdKHR(VkDevice _device
,
2094 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
2097 TU_FROM_HANDLE(tu_device
, device
, _device
);
2098 TU_FROM_HANDLE(tu_device_memory
, memory
, pGetFdInfo
->memory
);
2100 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2102 /* At the moment, we support only the below handle types. */
2103 assert(pGetFdInfo
->handleType
==
2104 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2105 pGetFdInfo
->handleType
==
2106 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2108 int prime_fd
= tu_bo_export_dmabuf(device
, &memory
->bo
);
2110 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2117 tu_GetMemoryFdPropertiesKHR(VkDevice _device
,
2118 VkExternalMemoryHandleTypeFlagBits handleType
,
2120 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
2122 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2123 pMemoryFdProperties
->memoryTypeBits
= 1;
2128 tu_GetPhysicalDeviceExternalSemaphoreProperties(
2129 VkPhysicalDevice physicalDevice
,
2130 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
2131 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
2133 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
2134 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
2135 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
2139 tu_GetPhysicalDeviceExternalFenceProperties(
2140 VkPhysicalDevice physicalDevice
,
2141 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
2142 VkExternalFenceProperties
*pExternalFenceProperties
)
2144 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
2145 pExternalFenceProperties
->compatibleHandleTypes
= 0;
2146 pExternalFenceProperties
->externalFenceFeatures
= 0;
2150 tu_CreateDebugReportCallbackEXT(
2151 VkInstance _instance
,
2152 const VkDebugReportCallbackCreateInfoEXT
*pCreateInfo
,
2153 const VkAllocationCallbacks
*pAllocator
,
2154 VkDebugReportCallbackEXT
*pCallback
)
2156 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2157 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2158 pCreateInfo
, pAllocator
,
2159 &instance
->alloc
, pCallback
);
2163 tu_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2164 VkDebugReportCallbackEXT _callback
,
2165 const VkAllocationCallbacks
*pAllocator
)
2167 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2168 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2169 _callback
, pAllocator
, &instance
->alloc
);
2173 tu_DebugReportMessageEXT(VkInstance _instance
,
2174 VkDebugReportFlagsEXT flags
,
2175 VkDebugReportObjectTypeEXT objectType
,
2178 int32_t messageCode
,
2179 const char *pLayerPrefix
,
2180 const char *pMessage
)
2182 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2183 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2184 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2188 tu_GetDeviceGroupPeerMemoryFeatures(
2191 uint32_t localDeviceIndex
,
2192 uint32_t remoteDeviceIndex
,
2193 VkPeerMemoryFeatureFlags
*pPeerMemoryFeatures
)
2195 assert(localDeviceIndex
== remoteDeviceIndex
);
2197 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2198 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2199 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2200 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;