2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include "tu_private.h"
35 #include <sys/sysinfo.h>
39 #include "compiler/glsl_types.h"
40 #include "util/debug.h"
41 #include "util/disk_cache.h"
42 #include "util/strtod.h"
43 #include "vk_format.h"
46 #include "drm-uapi/msm_drm.h"
49 tu_device_get_cache_uuid(uint16_t family
, void *uuid
)
51 uint32_t mesa_timestamp
;
53 memset(uuid
, 0, VK_UUID_SIZE
);
54 if (!disk_cache_get_function_timestamp(tu_device_get_cache_uuid
,
58 memcpy(uuid
, &mesa_timestamp
, 4);
59 memcpy((char *) uuid
+ 4, &f
, 2);
60 snprintf((char *) uuid
+ 6, VK_UUID_SIZE
- 10, "tu");
65 tu_get_driver_uuid(void *uuid
)
67 memset(uuid
, 0, VK_UUID_SIZE
);
68 snprintf(uuid
, VK_UUID_SIZE
, "freedreno");
72 tu_get_device_uuid(void *uuid
)
74 memset(uuid
, 0, VK_UUID_SIZE
);
78 tu_bo_init(struct tu_device
*dev
,
83 uint64_t iova
= tu_gem_info_iova(dev
, gem_handle
);
85 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
87 *bo
= (struct tu_bo
) {
88 .gem_handle
= gem_handle
,
97 tu_bo_init_new(struct tu_device
*dev
, struct tu_bo
*bo
, uint64_t size
)
99 /* TODO: Choose better flags. As of 2018-11-12, freedreno/drm/msm_bo.c
100 * always sets `flags = MSM_BO_WC`, and we copy that behavior here.
102 uint32_t gem_handle
= tu_gem_new(dev
, size
, MSM_BO_WC
);
104 return vk_error(dev
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
106 VkResult result
= tu_bo_init(dev
, bo
, gem_handle
, size
);
107 if (result
!= VK_SUCCESS
) {
108 tu_gem_close(dev
, gem_handle
);
109 return vk_error(dev
->instance
, result
);
116 tu_bo_init_dmabuf(struct tu_device
*dev
,
121 uint32_t gem_handle
= tu_gem_import_dmabuf(dev
, fd
, size
);
123 return vk_error(dev
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
125 VkResult result
= tu_bo_init(dev
, bo
, gem_handle
, size
);
126 if (result
!= VK_SUCCESS
) {
127 tu_gem_close(dev
, gem_handle
);
128 return vk_error(dev
->instance
, result
);
135 tu_bo_export_dmabuf(struct tu_device
*dev
, struct tu_bo
*bo
)
137 return tu_gem_export_dmabuf(dev
, bo
->gem_handle
);
141 tu_bo_map(struct tu_device
*dev
, struct tu_bo
*bo
)
146 uint64_t offset
= tu_gem_info_offset(dev
, bo
->gem_handle
);
148 return vk_error(dev
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
150 /* TODO: Should we use the wrapper os_mmap() like Freedreno does? */
151 void *map
= mmap(0, bo
->size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
152 dev
->physical_device
->local_fd
, offset
);
153 if (map
== MAP_FAILED
)
154 return vk_error(dev
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
161 tu_bo_finish(struct tu_device
*dev
, struct tu_bo
*bo
)
163 assert(bo
->gem_handle
);
166 munmap(bo
->map
, bo
->size
);
168 tu_gem_close(dev
, bo
->gem_handle
);
172 tu_physical_device_init(struct tu_physical_device
*device
,
173 struct tu_instance
*instance
,
174 drmDevicePtr drm_device
)
176 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
177 VkResult result
= VK_SUCCESS
;
178 drmVersionPtr version
;
182 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
184 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
185 "failed to open device %s", path
);
188 /* Version 1.3 added MSM_INFO_IOVA. */
189 const int min_version_major
= 1;
190 const int min_version_minor
= 3;
192 version
= drmGetVersion(fd
);
195 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
196 "failed to query kernel driver version for device %s",
200 if (strcmp(version
->name
, "msm")) {
201 drmFreeVersion(version
);
203 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
204 "device %s does not use the msm kernel driver", path
);
207 if (version
->version_major
!= min_version_major
||
208 version
->version_minor
< min_version_minor
) {
209 result
= vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
210 "kernel driver for device %s has version %d.%d, "
211 "but Vulkan requires version >= %d.%d",
212 path
, version
->version_major
, version
->version_minor
,
213 min_version_major
, min_version_minor
);
214 drmFreeVersion(version
);
219 drmFreeVersion(version
);
221 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
222 tu_logi("Found compatible device '%s'.", path
);
224 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
225 device
->instance
= instance
;
226 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
227 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
229 if (instance
->enabled_extensions
.KHR_display
) {
231 open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
232 if (master_fd
>= 0) {
233 /* TODO: free master_fd is accel is not working? */
237 device
->master_fd
= master_fd
;
238 device
->local_fd
= fd
;
240 if (tu_drm_get_gpu_id(device
, &device
->gpu_id
)) {
241 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
242 tu_logi("Could not query the GPU ID");
243 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
244 "could not get GPU ID");
248 if (tu_drm_get_gmem_size(device
, &device
->gmem_size
)) {
249 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
250 tu_logi("Could not query the GMEM size");
251 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
252 "could not get GMEM size");
256 memset(device
->name
, 0, sizeof(device
->name
));
257 sprintf(device
->name
, "FD%d", device
->gpu_id
);
259 switch (device
->gpu_id
) {
261 device
->tile_align_w
= 32;
262 device
->tile_align_h
= 32;
265 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
266 "device %s is unsupported", device
->name
);
269 if (tu_device_get_cache_uuid(device
->gpu_id
, device
->cache_uuid
)) {
270 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
271 "cannot generate UUID");
275 /* The gpu id is already embedded in the uuid so we just pass "tu"
276 * when creating the cache.
278 char buf
[VK_UUID_SIZE
* 2 + 1];
279 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
280 device
->disk_cache
= disk_cache_create(device
->name
, buf
, 0);
282 fprintf(stderr
, "WARNING: tu is not a conformant vulkan implementation, "
283 "testing use only.\n");
285 tu_get_driver_uuid(&device
->device_uuid
);
286 tu_get_device_uuid(&device
->device_uuid
);
288 tu_fill_device_extension_table(device
, &device
->supported_extensions
);
290 if (result
!= VK_SUCCESS
) {
291 vk_error(instance
, result
);
295 result
= tu_wsi_init(device
);
296 if (result
!= VK_SUCCESS
) {
297 vk_error(instance
, result
);
311 tu_physical_device_finish(struct tu_physical_device
*device
)
313 tu_wsi_finish(device
);
315 disk_cache_destroy(device
->disk_cache
);
316 close(device
->local_fd
);
317 if (device
->master_fd
!= -1)
318 close(device
->master_fd
);
322 default_alloc_func(void *pUserData
,
325 VkSystemAllocationScope allocationScope
)
331 default_realloc_func(void *pUserData
,
335 VkSystemAllocationScope allocationScope
)
337 return realloc(pOriginal
, size
);
341 default_free_func(void *pUserData
, void *pMemory
)
346 static const VkAllocationCallbacks default_alloc
= {
348 .pfnAllocation
= default_alloc_func
,
349 .pfnReallocation
= default_realloc_func
,
350 .pfnFree
= default_free_func
,
353 static const struct debug_control tu_debug_options
[] = {
354 { "startup", TU_DEBUG_STARTUP
},
355 { "nir", TU_DEBUG_NIR
},
356 { "ir3", TU_DEBUG_IR3
},
361 tu_get_debug_option_name(int id
)
363 assert(id
< ARRAY_SIZE(tu_debug_options
) - 1);
364 return tu_debug_options
[id
].string
;
368 tu_get_instance_extension_index(const char *name
)
370 for (unsigned i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; ++i
) {
371 if (strcmp(name
, tu_instance_extensions
[i
].extensionName
) == 0)
378 tu_CreateInstance(const VkInstanceCreateInfo
*pCreateInfo
,
379 const VkAllocationCallbacks
*pAllocator
,
380 VkInstance
*pInstance
)
382 struct tu_instance
*instance
;
385 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
387 uint32_t client_version
;
388 if (pCreateInfo
->pApplicationInfo
&&
389 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
390 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
392 tu_EnumerateInstanceVersion(&client_version
);
395 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
396 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
398 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
400 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
403 instance
->alloc
= *pAllocator
;
405 instance
->alloc
= default_alloc
;
407 instance
->api_version
= client_version
;
408 instance
->physical_device_count
= -1;
410 instance
->debug_flags
=
411 parse_debug_string(getenv("TU_DEBUG"), tu_debug_options
);
413 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
414 tu_logi("Created an instance");
416 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
417 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
418 int index
= tu_get_instance_extension_index(ext_name
);
420 if (index
< 0 || !tu_supported_instance_extensions
.extensions
[index
]) {
421 vk_free2(&default_alloc
, pAllocator
, instance
);
422 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
425 instance
->enabled_extensions
.extensions
[index
] = true;
428 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
429 if (result
!= VK_SUCCESS
) {
430 vk_free2(&default_alloc
, pAllocator
, instance
);
431 return vk_error(instance
, result
);
435 glsl_type_singleton_init_or_ref();
437 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
439 *pInstance
= tu_instance_to_handle(instance
);
445 tu_DestroyInstance(VkInstance _instance
,
446 const VkAllocationCallbacks
*pAllocator
)
448 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
453 for (int i
= 0; i
< instance
->physical_device_count
; ++i
) {
454 tu_physical_device_finish(instance
->physical_devices
+ i
);
457 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
459 glsl_type_singleton_decref();
462 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
464 vk_free(&instance
->alloc
, instance
);
468 tu_enumerate_devices(struct tu_instance
*instance
)
470 /* TODO: Check for more devices ? */
471 drmDevicePtr devices
[8];
472 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
475 instance
->physical_device_count
= 0;
477 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
479 if (instance
->debug_flags
& TU_DEBUG_STARTUP
)
480 tu_logi("Found %d drm nodes", max_devices
);
483 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
485 for (unsigned i
= 0; i
< (unsigned) max_devices
; i
++) {
486 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
487 devices
[i
]->bustype
== DRM_BUS_PLATFORM
) {
489 result
= tu_physical_device_init(
490 instance
->physical_devices
+ instance
->physical_device_count
,
491 instance
, devices
[i
]);
492 if (result
== VK_SUCCESS
)
493 ++instance
->physical_device_count
;
494 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
498 drmFreeDevices(devices
, max_devices
);
504 tu_EnumeratePhysicalDevices(VkInstance _instance
,
505 uint32_t *pPhysicalDeviceCount
,
506 VkPhysicalDevice
*pPhysicalDevices
)
508 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
509 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
513 if (instance
->physical_device_count
< 0) {
514 result
= tu_enumerate_devices(instance
);
515 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
519 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
520 vk_outarray_append(&out
, p
)
522 *p
= tu_physical_device_to_handle(instance
->physical_devices
+ i
);
526 return vk_outarray_status(&out
);
530 tu_EnumeratePhysicalDeviceGroups(
531 VkInstance _instance
,
532 uint32_t *pPhysicalDeviceGroupCount
,
533 VkPhysicalDeviceGroupProperties
*pPhysicalDeviceGroupProperties
)
535 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
536 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
537 pPhysicalDeviceGroupCount
);
540 if (instance
->physical_device_count
< 0) {
541 result
= tu_enumerate_devices(instance
);
542 if (result
!= VK_SUCCESS
&& result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
546 for (uint32_t i
= 0; i
< instance
->physical_device_count
; ++i
) {
547 vk_outarray_append(&out
, p
)
549 p
->physicalDeviceCount
= 1;
550 p
->physicalDevices
[0] =
551 tu_physical_device_to_handle(instance
->physical_devices
+ i
);
552 p
->subsetAllocation
= false;
556 return vk_outarray_status(&out
);
560 tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice
,
561 VkPhysicalDeviceFeatures
*pFeatures
)
563 memset(pFeatures
, 0, sizeof(*pFeatures
));
565 *pFeatures
= (VkPhysicalDeviceFeatures
) {
566 .robustBufferAccess
= false,
567 .fullDrawIndexUint32
= false,
568 .imageCubeArray
= false,
569 .independentBlend
= false,
570 .geometryShader
= false,
571 .tessellationShader
= false,
572 .sampleRateShading
= false,
573 .dualSrcBlend
= false,
575 .multiDrawIndirect
= false,
576 .drawIndirectFirstInstance
= false,
578 .depthBiasClamp
= false,
579 .fillModeNonSolid
= false,
580 .depthBounds
= false,
582 .largePoints
= false,
584 .multiViewport
= false,
585 .samplerAnisotropy
= false,
586 .textureCompressionETC2
= false,
587 .textureCompressionASTC_LDR
= false,
588 .textureCompressionBC
= false,
589 .occlusionQueryPrecise
= false,
590 .pipelineStatisticsQuery
= false,
591 .vertexPipelineStoresAndAtomics
= false,
592 .fragmentStoresAndAtomics
= false,
593 .shaderTessellationAndGeometryPointSize
= false,
594 .shaderImageGatherExtended
= false,
595 .shaderStorageImageExtendedFormats
= false,
596 .shaderStorageImageMultisample
= false,
597 .shaderUniformBufferArrayDynamicIndexing
= false,
598 .shaderSampledImageArrayDynamicIndexing
= false,
599 .shaderStorageBufferArrayDynamicIndexing
= false,
600 .shaderStorageImageArrayDynamicIndexing
= false,
601 .shaderStorageImageReadWithoutFormat
= false,
602 .shaderStorageImageWriteWithoutFormat
= false,
603 .shaderClipDistance
= false,
604 .shaderCullDistance
= false,
605 .shaderFloat64
= false,
606 .shaderInt64
= false,
607 .shaderInt16
= false,
608 .sparseBinding
= false,
609 .variableMultisampleRate
= false,
610 .inheritedQueries
= false,
615 tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice
,
616 VkPhysicalDeviceFeatures2
*pFeatures
)
618 vk_foreach_struct(ext
, pFeatures
->pNext
)
620 switch (ext
->sType
) {
621 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
622 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *) ext
;
623 features
->variablePointersStorageBuffer
= false;
624 features
->variablePointers
= false;
627 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
628 VkPhysicalDeviceMultiviewFeatures
*features
=
629 (VkPhysicalDeviceMultiviewFeatures
*) ext
;
630 features
->multiview
= false;
631 features
->multiviewGeometryShader
= false;
632 features
->multiviewTessellationShader
= false;
635 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
636 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
637 (VkPhysicalDeviceShaderDrawParametersFeatures
*) ext
;
638 features
->shaderDrawParameters
= false;
641 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
642 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
643 (VkPhysicalDeviceProtectedMemoryFeatures
*) ext
;
644 features
->protectedMemory
= false;
647 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
648 VkPhysicalDevice16BitStorageFeatures
*features
=
649 (VkPhysicalDevice16BitStorageFeatures
*) ext
;
650 features
->storageBuffer16BitAccess
= false;
651 features
->uniformAndStorageBuffer16BitAccess
= false;
652 features
->storagePushConstant16
= false;
653 features
->storageInputOutput16
= false;
656 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
657 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
658 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*) ext
;
659 features
->samplerYcbcrConversion
= false;
662 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
663 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
664 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*) ext
;
665 features
->shaderInputAttachmentArrayDynamicIndexing
= false;
666 features
->shaderUniformTexelBufferArrayDynamicIndexing
= false;
667 features
->shaderStorageTexelBufferArrayDynamicIndexing
= false;
668 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
669 features
->shaderSampledImageArrayNonUniformIndexing
= false;
670 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
671 features
->shaderStorageImageArrayNonUniformIndexing
= false;
672 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
673 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
674 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
675 features
->descriptorBindingUniformBufferUpdateAfterBind
= false;
676 features
->descriptorBindingSampledImageUpdateAfterBind
= false;
677 features
->descriptorBindingStorageImageUpdateAfterBind
= false;
678 features
->descriptorBindingStorageBufferUpdateAfterBind
= false;
679 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= false;
680 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= false;
681 features
->descriptorBindingUpdateUnusedWhilePending
= false;
682 features
->descriptorBindingPartiallyBound
= false;
683 features
->descriptorBindingVariableDescriptorCount
= false;
684 features
->runtimeDescriptorArray
= false;
687 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
688 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
689 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*) ext
;
690 features
->conditionalRendering
= false;
691 features
->inheritedConditionalRendering
= false;
698 return tu_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
702 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice
,
703 VkPhysicalDeviceProperties
*pProperties
)
705 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
706 VkSampleCountFlags sample_counts
= 0xf;
708 /* make sure that the entire descriptor set is addressable with a signed
709 * 32-bit int. So the sum of all limits scaled by descriptor size has to
710 * be at most 2 GiB. the combined image & samples object count as one of
711 * both. This limit is for the pipeline layout, not for the set layout, but
712 * there is no set limit, so we just set a pipeline limit. I don't think
713 * any app is going to hit this soon. */
714 size_t max_descriptor_set_size
=
715 ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
716 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
717 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
718 32 /* sampler, largest when combined with image */ +
719 64 /* sampled image */ + 64 /* storage image */);
721 VkPhysicalDeviceLimits limits
= {
722 .maxImageDimension1D
= (1 << 14),
723 .maxImageDimension2D
= (1 << 14),
724 .maxImageDimension3D
= (1 << 11),
725 .maxImageDimensionCube
= (1 << 14),
726 .maxImageArrayLayers
= (1 << 11),
727 .maxTexelBufferElements
= 128 * 1024 * 1024,
728 .maxUniformBufferRange
= UINT32_MAX
,
729 .maxStorageBufferRange
= UINT32_MAX
,
730 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
731 .maxMemoryAllocationCount
= UINT32_MAX
,
732 .maxSamplerAllocationCount
= 64 * 1024,
733 .bufferImageGranularity
= 64, /* A cache line */
734 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
735 .maxBoundDescriptorSets
= MAX_SETS
,
736 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
737 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
738 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
739 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
740 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
741 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
742 .maxPerStageResources
= max_descriptor_set_size
,
743 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
744 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
745 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
746 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
747 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
748 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
749 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
750 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
751 .maxVertexInputAttributes
= 32,
752 .maxVertexInputBindings
= 32,
753 .maxVertexInputAttributeOffset
= 2047,
754 .maxVertexInputBindingStride
= 2048,
755 .maxVertexOutputComponents
= 128,
756 .maxTessellationGenerationLevel
= 64,
757 .maxTessellationPatchSize
= 32,
758 .maxTessellationControlPerVertexInputComponents
= 128,
759 .maxTessellationControlPerVertexOutputComponents
= 128,
760 .maxTessellationControlPerPatchOutputComponents
= 120,
761 .maxTessellationControlTotalOutputComponents
= 4096,
762 .maxTessellationEvaluationInputComponents
= 128,
763 .maxTessellationEvaluationOutputComponents
= 128,
764 .maxGeometryShaderInvocations
= 127,
765 .maxGeometryInputComponents
= 64,
766 .maxGeometryOutputComponents
= 128,
767 .maxGeometryOutputVertices
= 256,
768 .maxGeometryTotalOutputComponents
= 1024,
769 .maxFragmentInputComponents
= 128,
770 .maxFragmentOutputAttachments
= 8,
771 .maxFragmentDualSrcAttachments
= 1,
772 .maxFragmentCombinedOutputResources
= 8,
773 .maxComputeSharedMemorySize
= 32768,
774 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
775 .maxComputeWorkGroupInvocations
= 2048,
776 .maxComputeWorkGroupSize
= { 2048, 2048, 2048 },
777 .subPixelPrecisionBits
= 4 /* FIXME */,
778 .subTexelPrecisionBits
= 4 /* FIXME */,
779 .mipmapPrecisionBits
= 4 /* FIXME */,
780 .maxDrawIndexedIndexValue
= UINT32_MAX
,
781 .maxDrawIndirectCount
= UINT32_MAX
,
782 .maxSamplerLodBias
= 16,
783 .maxSamplerAnisotropy
= 16,
784 .maxViewports
= MAX_VIEWPORTS
,
785 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
786 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
787 .viewportSubPixelBits
= 8,
788 .minMemoryMapAlignment
= 4096, /* A page */
789 .minTexelBufferOffsetAlignment
= 1,
790 .minUniformBufferOffsetAlignment
= 4,
791 .minStorageBufferOffsetAlignment
= 4,
792 .minTexelOffset
= -32,
793 .maxTexelOffset
= 31,
794 .minTexelGatherOffset
= -32,
795 .maxTexelGatherOffset
= 31,
796 .minInterpolationOffset
= -2,
797 .maxInterpolationOffset
= 2,
798 .subPixelInterpolationOffsetBits
= 8,
799 .maxFramebufferWidth
= (1 << 14),
800 .maxFramebufferHeight
= (1 << 14),
801 .maxFramebufferLayers
= (1 << 10),
802 .framebufferColorSampleCounts
= sample_counts
,
803 .framebufferDepthSampleCounts
= sample_counts
,
804 .framebufferStencilSampleCounts
= sample_counts
,
805 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
806 .maxColorAttachments
= MAX_RTS
,
807 .sampledImageColorSampleCounts
= sample_counts
,
808 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
809 .sampledImageDepthSampleCounts
= sample_counts
,
810 .sampledImageStencilSampleCounts
= sample_counts
,
811 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
812 .maxSampleMaskWords
= 1,
813 .timestampComputeAndGraphics
= true,
814 .timestampPeriod
= 1,
815 .maxClipDistances
= 8,
816 .maxCullDistances
= 8,
817 .maxCombinedClipAndCullDistances
= 8,
818 .discreteQueuePriorities
= 1,
819 .pointSizeRange
= { 0.125, 255.875 },
820 .lineWidthRange
= { 0.0, 7.9921875 },
821 .pointSizeGranularity
= (1.0 / 8.0),
822 .lineWidthGranularity
= (1.0 / 128.0),
823 .strictLines
= false, /* FINISHME */
824 .standardSampleLocations
= true,
825 .optimalBufferCopyOffsetAlignment
= 128,
826 .optimalBufferCopyRowPitchAlignment
= 128,
827 .nonCoherentAtomSize
= 64,
830 *pProperties
= (VkPhysicalDeviceProperties
) {
831 .apiVersion
= tu_physical_device_api_version(pdevice
),
832 .driverVersion
= vk_get_driver_version(),
833 .vendorID
= 0, /* TODO */
835 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
837 .sparseProperties
= { 0 },
840 strcpy(pProperties
->deviceName
, pdevice
->name
);
841 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
845 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice
,
846 VkPhysicalDeviceProperties2
*pProperties
)
848 TU_FROM_HANDLE(tu_physical_device
, pdevice
, physicalDevice
);
849 tu_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
851 vk_foreach_struct(ext
, pProperties
->pNext
)
853 switch (ext
->sType
) {
854 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
855 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
856 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
857 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
861 VkPhysicalDeviceIDProperties
*properties
=
862 (VkPhysicalDeviceIDProperties
*) ext
;
863 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
864 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
865 properties
->deviceLUIDValid
= false;
868 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
869 VkPhysicalDeviceMultiviewProperties
*properties
=
870 (VkPhysicalDeviceMultiviewProperties
*) ext
;
871 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
872 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
875 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
876 VkPhysicalDevicePointClippingProperties
*properties
=
877 (VkPhysicalDevicePointClippingProperties
*) ext
;
878 properties
->pointClippingBehavior
=
879 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
882 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
883 VkPhysicalDeviceMaintenance3Properties
*properties
=
884 (VkPhysicalDeviceMaintenance3Properties
*) ext
;
885 /* Make sure everything is addressable by a signed 32-bit int, and
886 * our largest descriptors are 96 bytes. */
887 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
888 /* Our buffer size fields allow only this much */
889 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
898 static const VkQueueFamilyProperties tu_queue_family_properties
= {
900 VK_QUEUE_GRAPHICS_BIT
| VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
902 .timestampValidBits
= 64,
903 .minImageTransferGranularity
= { 1, 1, 1 },
907 tu_GetPhysicalDeviceQueueFamilyProperties(
908 VkPhysicalDevice physicalDevice
,
909 uint32_t *pQueueFamilyPropertyCount
,
910 VkQueueFamilyProperties
*pQueueFamilyProperties
)
912 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
914 vk_outarray_append(&out
, p
) { *p
= tu_queue_family_properties
; }
918 tu_GetPhysicalDeviceQueueFamilyProperties2(
919 VkPhysicalDevice physicalDevice
,
920 uint32_t *pQueueFamilyPropertyCount
,
921 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
923 VK_OUTARRAY_MAKE(out
, pQueueFamilyProperties
, pQueueFamilyPropertyCount
);
925 vk_outarray_append(&out
, p
)
927 p
->queueFamilyProperties
= tu_queue_family_properties
;
932 tu_get_system_heap_size()
937 uint64_t total_ram
= (uint64_t) info
.totalram
* (uint64_t) info
.mem_unit
;
939 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
940 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
942 uint64_t available_ram
;
943 if (total_ram
<= 4ull * 1024ull * 1024ull * 1024ull)
944 available_ram
= total_ram
/ 2;
946 available_ram
= total_ram
* 3 / 4;
948 return available_ram
;
952 tu_GetPhysicalDeviceMemoryProperties(
953 VkPhysicalDevice physicalDevice
,
954 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
956 pMemoryProperties
->memoryHeapCount
= 1;
957 pMemoryProperties
->memoryHeaps
[0].size
= tu_get_system_heap_size();
958 pMemoryProperties
->memoryHeaps
[0].flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
;
960 pMemoryProperties
->memoryTypeCount
= 1;
961 pMemoryProperties
->memoryTypes
[0].propertyFlags
=
962 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
963 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
964 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
;
965 pMemoryProperties
->memoryTypes
[0].heapIndex
= 0;
969 tu_GetPhysicalDeviceMemoryProperties2(
970 VkPhysicalDevice physicalDevice
,
971 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
973 return tu_GetPhysicalDeviceMemoryProperties(
974 physicalDevice
, &pMemoryProperties
->memoryProperties
);
978 tu_queue_init(struct tu_device
*device
,
979 struct tu_queue
*queue
,
980 uint32_t queue_family_index
,
982 VkDeviceQueueCreateFlags flags
)
984 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
985 queue
->device
= device
;
986 queue
->queue_family_index
= queue_family_index
;
987 queue
->queue_idx
= idx
;
988 queue
->flags
= flags
;
990 int ret
= tu_drm_submitqueue_new(device
, 0, &queue
->msm_queue_id
);
992 return VK_ERROR_INITIALIZATION_FAILED
;
994 tu_fence_init(&queue
->submit_fence
, false);
1000 tu_queue_finish(struct tu_queue
*queue
)
1002 tu_fence_finish(&queue
->submit_fence
);
1003 tu_drm_submitqueue_close(queue
->device
, queue
->msm_queue_id
);
1007 tu_get_device_extension_index(const char *name
)
1009 for (unsigned i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; ++i
) {
1010 if (strcmp(name
, tu_device_extensions
[i
].extensionName
) == 0)
1017 tu_CreateDevice(VkPhysicalDevice physicalDevice
,
1018 const VkDeviceCreateInfo
*pCreateInfo
,
1019 const VkAllocationCallbacks
*pAllocator
,
1022 TU_FROM_HANDLE(tu_physical_device
, physical_device
, physicalDevice
);
1024 struct tu_device
*device
;
1026 /* Check enabled features */
1027 if (pCreateInfo
->pEnabledFeatures
) {
1028 VkPhysicalDeviceFeatures supported_features
;
1029 tu_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1030 VkBool32
*supported_feature
= (VkBool32
*) &supported_features
;
1031 VkBool32
*enabled_feature
= (VkBool32
*) pCreateInfo
->pEnabledFeatures
;
1032 unsigned num_features
=
1033 sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1034 for (uint32_t i
= 0; i
< num_features
; i
++) {
1035 if (enabled_feature
[i
] && !supported_feature
[i
])
1036 return vk_error(physical_device
->instance
,
1037 VK_ERROR_FEATURE_NOT_PRESENT
);
1041 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1042 sizeof(*device
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1044 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1046 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1047 device
->instance
= physical_device
->instance
;
1048 device
->physical_device
= physical_device
;
1051 device
->alloc
= *pAllocator
;
1053 device
->alloc
= physical_device
->instance
->alloc
;
1055 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1056 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1057 int index
= tu_get_device_extension_index(ext_name
);
1059 !physical_device
->supported_extensions
.extensions
[index
]) {
1060 vk_free(&device
->alloc
, device
);
1061 return vk_error(physical_device
->instance
,
1062 VK_ERROR_EXTENSION_NOT_PRESENT
);
1065 device
->enabled_extensions
.extensions
[index
] = true;
1068 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1069 const VkDeviceQueueCreateInfo
*queue_create
=
1070 &pCreateInfo
->pQueueCreateInfos
[i
];
1071 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1072 device
->queues
[qfi
] = vk_alloc(
1073 &device
->alloc
, queue_create
->queueCount
* sizeof(struct tu_queue
),
1074 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1075 if (!device
->queues
[qfi
]) {
1076 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1080 memset(device
->queues
[qfi
], 0,
1081 queue_create
->queueCount
* sizeof(struct tu_queue
));
1083 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1085 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1086 result
= tu_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
,
1087 queue_create
->flags
);
1088 if (result
!= VK_SUCCESS
)
1093 device
->compiler
= ir3_compiler_create(NULL
, physical_device
->gpu_id
);
1094 if (!device
->compiler
)
1097 VkPipelineCacheCreateInfo ci
;
1098 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1101 ci
.pInitialData
= NULL
;
1102 ci
.initialDataSize
= 0;
1105 tu_CreatePipelineCache(tu_device_to_handle(device
), &ci
, NULL
, &pc
);
1106 if (result
!= VK_SUCCESS
)
1109 device
->mem_cache
= tu_pipeline_cache_from_handle(pc
);
1111 *pDevice
= tu_device_to_handle(device
);
1115 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1116 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1117 tu_queue_finish(&device
->queues
[i
][q
]);
1118 if (device
->queue_count
[i
])
1119 vk_free(&device
->alloc
, device
->queues
[i
]);
1122 if (device
->compiler
)
1123 ralloc_free(device
->compiler
);
1125 vk_free(&device
->alloc
, device
);
1130 tu_DestroyDevice(VkDevice _device
, const VkAllocationCallbacks
*pAllocator
)
1132 TU_FROM_HANDLE(tu_device
, device
, _device
);
1137 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1138 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1139 tu_queue_finish(&device
->queues
[i
][q
]);
1140 if (device
->queue_count
[i
])
1141 vk_free(&device
->alloc
, device
->queues
[i
]);
1144 /* the compiler does not use pAllocator */
1145 ralloc_free(device
->compiler
);
1147 VkPipelineCache pc
= tu_pipeline_cache_to_handle(device
->mem_cache
);
1148 tu_DestroyPipelineCache(tu_device_to_handle(device
), pc
, NULL
);
1150 vk_free(&device
->alloc
, device
);
1154 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount
,
1155 VkLayerProperties
*pProperties
)
1157 *pPropertyCount
= 0;
1162 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice
,
1163 uint32_t *pPropertyCount
,
1164 VkLayerProperties
*pProperties
)
1166 *pPropertyCount
= 0;
1171 tu_GetDeviceQueue2(VkDevice _device
,
1172 const VkDeviceQueueInfo2
*pQueueInfo
,
1175 TU_FROM_HANDLE(tu_device
, device
, _device
);
1176 struct tu_queue
*queue
;
1179 &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1180 if (pQueueInfo
->flags
!= queue
->flags
) {
1181 /* From the Vulkan 1.1.70 spec:
1183 * "The queue returned by vkGetDeviceQueue2 must have the same
1184 * flags value from this structure as that used at device
1185 * creation time in a VkDeviceQueueCreateInfo instance. If no
1186 * matching flags were specified at device creation time then
1187 * pQueue will return VK_NULL_HANDLE."
1189 *pQueue
= VK_NULL_HANDLE
;
1193 *pQueue
= tu_queue_to_handle(queue
);
1197 tu_GetDeviceQueue(VkDevice _device
,
1198 uint32_t queueFamilyIndex
,
1199 uint32_t queueIndex
,
1202 const VkDeviceQueueInfo2 info
=
1203 (VkDeviceQueueInfo2
) { .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1204 .queueFamilyIndex
= queueFamilyIndex
,
1205 .queueIndex
= queueIndex
};
1207 tu_GetDeviceQueue2(_device
, &info
, pQueue
);
1211 tu_QueueSubmit(VkQueue _queue
,
1212 uint32_t submitCount
,
1213 const VkSubmitInfo
*pSubmits
,
1216 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1218 for (uint32_t i
= 0; i
< submitCount
; ++i
) {
1219 const VkSubmitInfo
*submit
= pSubmits
+ i
;
1220 const bool last_submit
= (i
== submitCount
- 1);
1221 struct tu_bo_list bo_list
;
1222 tu_bo_list_init(&bo_list
);
1224 uint32_t entry_count
= 0;
1225 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1226 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1227 entry_count
+= cmdbuf
->cs
.entry_count
;
1230 struct drm_msm_gem_submit_cmd cmds
[entry_count
];
1231 uint32_t entry_idx
= 0;
1232 for (uint32_t j
= 0; j
< submit
->commandBufferCount
; ++j
) {
1233 TU_FROM_HANDLE(tu_cmd_buffer
, cmdbuf
, submit
->pCommandBuffers
[j
]);
1234 struct tu_cs
*cs
= &cmdbuf
->cs
;
1235 for (unsigned i
= 0; i
< cs
->entry_count
; ++i
, ++entry_idx
) {
1236 cmds
[entry_idx
].type
= MSM_SUBMIT_CMD_BUF
;
1237 cmds
[entry_idx
].submit_idx
=
1238 tu_bo_list_add(&bo_list
, cs
->entries
[i
].bo
,
1239 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1240 cmds
[entry_idx
].submit_offset
= cs
->entries
[i
].offset
;
1241 cmds
[entry_idx
].size
= cs
->entries
[i
].size
;
1242 cmds
[entry_idx
].pad
= 0;
1243 cmds
[entry_idx
].nr_relocs
= 0;
1244 cmds
[entry_idx
].relocs
= 0;
1247 tu_bo_list_merge(&bo_list
, &cmdbuf
->bo_list
);
1250 uint32_t flags
= MSM_PIPE_3D0
;
1252 flags
|= MSM_SUBMIT_FENCE_FD_OUT
;
1255 struct drm_msm_gem_submit req
= {
1257 .queueid
= queue
->msm_queue_id
,
1258 .bos
= (uint64_t)(uintptr_t) bo_list
.bo_infos
,
1259 .nr_bos
= bo_list
.count
,
1260 .cmds
= (uint64_t)(uintptr_t)cmds
,
1261 .nr_cmds
= entry_count
,
1264 int ret
= drmCommandWriteRead(queue
->device
->physical_device
->local_fd
,
1268 fprintf(stderr
, "submit failed: %s\n", strerror(errno
));
1272 tu_bo_list_destroy(&bo_list
);
1275 /* no need to merge fences as queue execution is serialized */
1276 tu_fence_update_fd(&queue
->submit_fence
, req
.fence_fd
);
1280 if (_fence
!= VK_NULL_HANDLE
) {
1281 TU_FROM_HANDLE(tu_fence
, fence
, _fence
);
1282 tu_fence_copy(fence
, &queue
->submit_fence
);
1289 tu_QueueWaitIdle(VkQueue _queue
)
1291 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
1293 tu_fence_wait_idle(&queue
->submit_fence
);
1299 tu_DeviceWaitIdle(VkDevice _device
)
1301 TU_FROM_HANDLE(tu_device
, device
, _device
);
1303 for (unsigned i
= 0; i
< TU_MAX_QUEUE_FAMILIES
; i
++) {
1304 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1305 tu_QueueWaitIdle(tu_queue_to_handle(&device
->queues
[i
][q
]));
1312 tu_EnumerateInstanceExtensionProperties(const char *pLayerName
,
1313 uint32_t *pPropertyCount
,
1314 VkExtensionProperties
*pProperties
)
1316 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1318 /* We spport no lyaers */
1320 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1322 for (int i
= 0; i
< TU_INSTANCE_EXTENSION_COUNT
; i
++) {
1323 if (tu_supported_instance_extensions
.extensions
[i
]) {
1324 vk_outarray_append(&out
, prop
) { *prop
= tu_instance_extensions
[i
]; }
1328 return vk_outarray_status(&out
);
1332 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice
,
1333 const char *pLayerName
,
1334 uint32_t *pPropertyCount
,
1335 VkExtensionProperties
*pProperties
)
1337 /* We spport no lyaers */
1338 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
1339 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
1341 /* We spport no lyaers */
1343 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1345 for (int i
= 0; i
< TU_DEVICE_EXTENSION_COUNT
; i
++) {
1346 if (device
->supported_extensions
.extensions
[i
]) {
1347 vk_outarray_append(&out
, prop
) { *prop
= tu_device_extensions
[i
]; }
1351 return vk_outarray_status(&out
);
1355 tu_GetInstanceProcAddr(VkInstance _instance
, const char *pName
)
1357 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
1359 return tu_lookup_entrypoint_checked(
1360 pName
, instance
? instance
->api_version
: 0,
1361 instance
? &instance
->enabled_extensions
: NULL
, NULL
);
1364 /* The loader wants us to expose a second GetInstanceProcAddr function
1365 * to work around certain LD_PRELOAD issues seen in apps.
1368 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1369 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
);
1372 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1373 vk_icdGetInstanceProcAddr(VkInstance instance
, const char *pName
)
1375 return tu_GetInstanceProcAddr(instance
, pName
);
1379 tu_GetDeviceProcAddr(VkDevice _device
, const char *pName
)
1381 TU_FROM_HANDLE(tu_device
, device
, _device
);
1383 return tu_lookup_entrypoint_checked(pName
, device
->instance
->api_version
,
1384 &device
->instance
->enabled_extensions
,
1385 &device
->enabled_extensions
);
1389 tu_alloc_memory(struct tu_device
*device
,
1390 const VkMemoryAllocateInfo
*pAllocateInfo
,
1391 const VkAllocationCallbacks
*pAllocator
,
1392 VkDeviceMemory
*pMem
)
1394 struct tu_device_memory
*mem
;
1397 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1399 if (pAllocateInfo
->allocationSize
== 0) {
1400 /* Apparently, this is allowed */
1401 *pMem
= VK_NULL_HANDLE
;
1405 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1406 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1408 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1410 const VkImportMemoryFdInfoKHR
*fd_info
=
1411 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
1412 if (fd_info
&& !fd_info
->handleType
)
1416 assert(fd_info
->handleType
==
1417 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
1418 fd_info
->handleType
==
1419 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
1422 * TODO Importing the same fd twice gives us the same handle without
1423 * reference counting. We need to maintain a per-instance handle-to-bo
1424 * table and add reference count to tu_bo.
1426 result
= tu_bo_init_dmabuf(device
, &mem
->bo
,
1427 pAllocateInfo
->allocationSize
, fd_info
->fd
);
1428 if (result
== VK_SUCCESS
) {
1429 /* take ownership and close the fd */
1434 tu_bo_init_new(device
, &mem
->bo
, pAllocateInfo
->allocationSize
);
1437 if (result
!= VK_SUCCESS
) {
1438 vk_free2(&device
->alloc
, pAllocator
, mem
);
1442 mem
->size
= pAllocateInfo
->allocationSize
;
1443 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1446 mem
->user_ptr
= NULL
;
1448 *pMem
= tu_device_memory_to_handle(mem
);
1454 tu_AllocateMemory(VkDevice _device
,
1455 const VkMemoryAllocateInfo
*pAllocateInfo
,
1456 const VkAllocationCallbacks
*pAllocator
,
1457 VkDeviceMemory
*pMem
)
1459 TU_FROM_HANDLE(tu_device
, device
, _device
);
1460 return tu_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
1464 tu_FreeMemory(VkDevice _device
,
1465 VkDeviceMemory _mem
,
1466 const VkAllocationCallbacks
*pAllocator
)
1468 TU_FROM_HANDLE(tu_device
, device
, _device
);
1469 TU_FROM_HANDLE(tu_device_memory
, mem
, _mem
);
1474 tu_bo_finish(device
, &mem
->bo
);
1475 vk_free2(&device
->alloc
, pAllocator
, mem
);
1479 tu_MapMemory(VkDevice _device
,
1480 VkDeviceMemory _memory
,
1481 VkDeviceSize offset
,
1483 VkMemoryMapFlags flags
,
1486 TU_FROM_HANDLE(tu_device
, device
, _device
);
1487 TU_FROM_HANDLE(tu_device_memory
, mem
, _memory
);
1495 if (mem
->user_ptr
) {
1496 *ppData
= mem
->user_ptr
;
1497 } else if (!mem
->map
) {
1498 result
= tu_bo_map(device
, &mem
->bo
);
1499 if (result
!= VK_SUCCESS
)
1501 *ppData
= mem
->map
= mem
->bo
.map
;
1510 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
1514 tu_UnmapMemory(VkDevice _device
, VkDeviceMemory _memory
)
1516 /* I do not see any unmapping done by the freedreno Gallium driver. */
1520 tu_FlushMappedMemoryRanges(VkDevice _device
,
1521 uint32_t memoryRangeCount
,
1522 const VkMappedMemoryRange
*pMemoryRanges
)
1528 tu_InvalidateMappedMemoryRanges(VkDevice _device
,
1529 uint32_t memoryRangeCount
,
1530 const VkMappedMemoryRange
*pMemoryRanges
)
1536 tu_GetBufferMemoryRequirements(VkDevice _device
,
1538 VkMemoryRequirements
*pMemoryRequirements
)
1540 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1542 pMemoryRequirements
->memoryTypeBits
= 1;
1543 pMemoryRequirements
->alignment
= 16;
1544 pMemoryRequirements
->size
=
1545 align64(buffer
->size
, pMemoryRequirements
->alignment
);
1549 tu_GetBufferMemoryRequirements2(
1551 const VkBufferMemoryRequirementsInfo2
*pInfo
,
1552 VkMemoryRequirements2
*pMemoryRequirements
)
1554 tu_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
1555 &pMemoryRequirements
->memoryRequirements
);
1559 tu_GetImageMemoryRequirements(VkDevice _device
,
1561 VkMemoryRequirements
*pMemoryRequirements
)
1563 TU_FROM_HANDLE(tu_image
, image
, _image
);
1565 pMemoryRequirements
->memoryTypeBits
= 1;
1566 pMemoryRequirements
->size
= image
->size
;
1567 pMemoryRequirements
->alignment
= image
->alignment
;
1571 tu_GetImageMemoryRequirements2(VkDevice device
,
1572 const VkImageMemoryRequirementsInfo2
*pInfo
,
1573 VkMemoryRequirements2
*pMemoryRequirements
)
1575 tu_GetImageMemoryRequirements(device
, pInfo
->image
,
1576 &pMemoryRequirements
->memoryRequirements
);
1580 tu_GetImageSparseMemoryRequirements(
1583 uint32_t *pSparseMemoryRequirementCount
,
1584 VkSparseImageMemoryRequirements
*pSparseMemoryRequirements
)
1590 tu_GetImageSparseMemoryRequirements2(
1592 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
1593 uint32_t *pSparseMemoryRequirementCount
,
1594 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
1600 tu_GetDeviceMemoryCommitment(VkDevice device
,
1601 VkDeviceMemory memory
,
1602 VkDeviceSize
*pCommittedMemoryInBytes
)
1604 *pCommittedMemoryInBytes
= 0;
1608 tu_BindBufferMemory2(VkDevice device
,
1609 uint32_t bindInfoCount
,
1610 const VkBindBufferMemoryInfo
*pBindInfos
)
1612 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1613 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1614 TU_FROM_HANDLE(tu_buffer
, buffer
, pBindInfos
[i
].buffer
);
1617 buffer
->bo
= &mem
->bo
;
1618 buffer
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1627 tu_BindBufferMemory(VkDevice device
,
1629 VkDeviceMemory memory
,
1630 VkDeviceSize memoryOffset
)
1632 const VkBindBufferMemoryInfo info
= {
1633 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1636 .memoryOffset
= memoryOffset
1639 return tu_BindBufferMemory2(device
, 1, &info
);
1643 tu_BindImageMemory2(VkDevice device
,
1644 uint32_t bindInfoCount
,
1645 const VkBindImageMemoryInfo
*pBindInfos
)
1647 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
1648 TU_FROM_HANDLE(tu_image
, image
, pBindInfos
[i
].image
);
1649 TU_FROM_HANDLE(tu_device_memory
, mem
, pBindInfos
[i
].memory
);
1652 image
->bo
= &mem
->bo
;
1653 image
->bo_offset
= pBindInfos
[i
].memoryOffset
;
1656 image
->bo_offset
= 0;
1664 tu_BindImageMemory(VkDevice device
,
1666 VkDeviceMemory memory
,
1667 VkDeviceSize memoryOffset
)
1669 const VkBindImageMemoryInfo info
= {
1670 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
1673 .memoryOffset
= memoryOffset
1676 return tu_BindImageMemory2(device
, 1, &info
);
1680 tu_QueueBindSparse(VkQueue _queue
,
1681 uint32_t bindInfoCount
,
1682 const VkBindSparseInfo
*pBindInfo
,
1688 // Queue semaphore functions
1691 tu_CreateSemaphore(VkDevice _device
,
1692 const VkSemaphoreCreateInfo
*pCreateInfo
,
1693 const VkAllocationCallbacks
*pAllocator
,
1694 VkSemaphore
*pSemaphore
)
1696 TU_FROM_HANDLE(tu_device
, device
, _device
);
1698 struct tu_semaphore
*sem
=
1699 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sem
), 8,
1700 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1702 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1704 *pSemaphore
= tu_semaphore_to_handle(sem
);
1709 tu_DestroySemaphore(VkDevice _device
,
1710 VkSemaphore _semaphore
,
1711 const VkAllocationCallbacks
*pAllocator
)
1713 TU_FROM_HANDLE(tu_device
, device
, _device
);
1714 TU_FROM_HANDLE(tu_semaphore
, sem
, _semaphore
);
1718 vk_free2(&device
->alloc
, pAllocator
, sem
);
1722 tu_CreateEvent(VkDevice _device
,
1723 const VkEventCreateInfo
*pCreateInfo
,
1724 const VkAllocationCallbacks
*pAllocator
,
1727 TU_FROM_HANDLE(tu_device
, device
, _device
);
1728 struct tu_event
*event
=
1729 vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*event
), 8,
1730 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1733 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1735 VkResult result
= tu_bo_init_new(device
, &event
->bo
, 0x1000);
1736 if (result
!= VK_SUCCESS
)
1739 result
= tu_bo_map(device
, &event
->bo
);
1740 if (result
!= VK_SUCCESS
)
1743 *pEvent
= tu_event_to_handle(event
);
1748 tu_bo_finish(device
, &event
->bo
);
1750 vk_free2(&device
->alloc
, pAllocator
, event
);
1751 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1755 tu_DestroyEvent(VkDevice _device
,
1757 const VkAllocationCallbacks
*pAllocator
)
1759 TU_FROM_HANDLE(tu_device
, device
, _device
);
1760 TU_FROM_HANDLE(tu_event
, event
, _event
);
1764 vk_free2(&device
->alloc
, pAllocator
, event
);
1768 tu_GetEventStatus(VkDevice _device
, VkEvent _event
)
1770 TU_FROM_HANDLE(tu_event
, event
, _event
);
1772 if (*(uint64_t*) event
->bo
.map
== 1)
1773 return VK_EVENT_SET
;
1774 return VK_EVENT_RESET
;
1778 tu_SetEvent(VkDevice _device
, VkEvent _event
)
1780 TU_FROM_HANDLE(tu_event
, event
, _event
);
1781 *(uint64_t*) event
->bo
.map
= 1;
1787 tu_ResetEvent(VkDevice _device
, VkEvent _event
)
1789 TU_FROM_HANDLE(tu_event
, event
, _event
);
1790 *(uint64_t*) event
->bo
.map
= 0;
1796 tu_CreateBuffer(VkDevice _device
,
1797 const VkBufferCreateInfo
*pCreateInfo
,
1798 const VkAllocationCallbacks
*pAllocator
,
1801 TU_FROM_HANDLE(tu_device
, device
, _device
);
1802 struct tu_buffer
*buffer
;
1804 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1806 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1807 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1809 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1811 buffer
->size
= pCreateInfo
->size
;
1812 buffer
->usage
= pCreateInfo
->usage
;
1813 buffer
->flags
= pCreateInfo
->flags
;
1815 *pBuffer
= tu_buffer_to_handle(buffer
);
1821 tu_DestroyBuffer(VkDevice _device
,
1823 const VkAllocationCallbacks
*pAllocator
)
1825 TU_FROM_HANDLE(tu_device
, device
, _device
);
1826 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
1831 vk_free2(&device
->alloc
, pAllocator
, buffer
);
1835 tu_surface_max_layer_count(struct tu_image_view
*iview
)
1837 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
1838 ? iview
->extent
.depth
1839 : (iview
->base_layer
+ iview
->layer_count
);
1843 tu_CreateFramebuffer(VkDevice _device
,
1844 const VkFramebufferCreateInfo
*pCreateInfo
,
1845 const VkAllocationCallbacks
*pAllocator
,
1846 VkFramebuffer
*pFramebuffer
)
1848 TU_FROM_HANDLE(tu_device
, device
, _device
);
1849 struct tu_framebuffer
*framebuffer
;
1851 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1853 size_t size
= sizeof(*framebuffer
) + sizeof(struct tu_attachment_info
) *
1854 pCreateInfo
->attachmentCount
;
1855 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1856 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1857 if (framebuffer
== NULL
)
1858 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1860 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1861 framebuffer
->width
= pCreateInfo
->width
;
1862 framebuffer
->height
= pCreateInfo
->height
;
1863 framebuffer
->layers
= pCreateInfo
->layers
;
1864 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1865 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1866 struct tu_image_view
*iview
= tu_image_view_from_handle(_iview
);
1867 framebuffer
->attachments
[i
].attachment
= iview
;
1869 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
1870 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
1871 framebuffer
->layers
=
1872 MIN2(framebuffer
->layers
, tu_surface_max_layer_count(iview
));
1875 *pFramebuffer
= tu_framebuffer_to_handle(framebuffer
);
1880 tu_DestroyFramebuffer(VkDevice _device
,
1882 const VkAllocationCallbacks
*pAllocator
)
1884 TU_FROM_HANDLE(tu_device
, device
, _device
);
1885 TU_FROM_HANDLE(tu_framebuffer
, fb
, _fb
);
1889 vk_free2(&device
->alloc
, pAllocator
, fb
);
1892 static enum a6xx_tex_clamp
1893 tu_tex_wrap(VkSamplerAddressMode address_mode
, bool *needs_border
)
1895 switch (address_mode
) {
1896 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
1897 return A6XX_TEX_REPEAT
;
1898 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
1899 return A6XX_TEX_MIRROR_REPEAT
;
1900 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
1901 return A6XX_TEX_CLAMP_TO_EDGE
;
1902 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
1903 *needs_border
= true;
1904 return A6XX_TEX_CLAMP_TO_BORDER
;
1905 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
1906 /* only works for PoT.. need to emulate otherwise! */
1907 return A6XX_TEX_MIRROR_CLAMP
;
1909 unreachable("illegal tex wrap mode");
1914 static enum a6xx_tex_filter
1915 tex_filter(VkFilter filter
, unsigned aniso
)
1918 case VK_FILTER_NEAREST
:
1919 return A6XX_TEX_NEAREST
;
1920 case VK_FILTER_LINEAR
:
1921 return aniso
> 1 ? A6XX_TEX_ANISO
: A6XX_TEX_LINEAR
;
1922 case VK_FILTER_CUBIC_IMG
:
1924 fprintf(stderr
, "illegal texture filter");
1930 tu_init_sampler(struct tu_device
*device
,
1931 struct tu_sampler
*sampler
,
1932 const VkSamplerCreateInfo
*pCreateInfo
)
1934 unsigned aniso
= pCreateInfo
->anisotropyEnable
?
1935 util_last_bit(MIN2((uint32_t)pCreateInfo
->maxAnisotropy
>> 1, 8)) : 0;
1936 bool miplinear
= (pCreateInfo
->mipmapMode
== VK_SAMPLER_MIPMAP_MODE_LINEAR
);
1937 bool needs_border
= false;
1940 COND(miplinear
, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR
) |
1941 A6XX_TEX_SAMP_0_XY_MAG(tex_filter(pCreateInfo
->magFilter
, aniso
)) |
1942 A6XX_TEX_SAMP_0_XY_MIN(tex_filter(pCreateInfo
->minFilter
, aniso
)) |
1943 A6XX_TEX_SAMP_0_ANISO(aniso
) |
1944 A6XX_TEX_SAMP_0_WRAP_S(tu_tex_wrap(pCreateInfo
->addressModeU
, &needs_border
)) |
1945 A6XX_TEX_SAMP_0_WRAP_T(tu_tex_wrap(pCreateInfo
->addressModeV
, &needs_border
)) |
1946 A6XX_TEX_SAMP_0_WRAP_R(tu_tex_wrap(pCreateInfo
->addressModeW
, &needs_border
)) |
1947 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo
->mipLodBias
);
1949 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
1950 COND(pCreateInfo
->unnormalizedCoordinates
, A6XX_TEX_SAMP_1_UNNORM_COORDS
) |
1951 A6XX_TEX_SAMP_1_MIN_LOD(pCreateInfo
->minLod
) |
1952 A6XX_TEX_SAMP_1_MAX_LOD(pCreateInfo
->maxLod
) |
1953 0; /* A6XX_TEX_SAMP_1_COMPARE_FUNC(cso->compare_func); */
1954 sampler
->state
[2] = 0;
1955 sampler
->state
[3] = 0;
1958 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
1962 sampler
->needs_border
= needs_border
;
1966 tu_CreateSampler(VkDevice _device
,
1967 const VkSamplerCreateInfo
*pCreateInfo
,
1968 const VkAllocationCallbacks
*pAllocator
,
1969 VkSampler
*pSampler
)
1971 TU_FROM_HANDLE(tu_device
, device
, _device
);
1972 struct tu_sampler
*sampler
;
1974 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
1976 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
1977 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1979 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1981 tu_init_sampler(device
, sampler
, pCreateInfo
);
1982 *pSampler
= tu_sampler_to_handle(sampler
);
1988 tu_DestroySampler(VkDevice _device
,
1990 const VkAllocationCallbacks
*pAllocator
)
1992 TU_FROM_HANDLE(tu_device
, device
, _device
);
1993 TU_FROM_HANDLE(tu_sampler
, sampler
, _sampler
);
1997 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2000 /* vk_icd.h does not declare this function, so we declare it here to
2001 * suppress Wmissing-prototypes.
2003 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2004 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2006 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2007 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2009 /* For the full details on loader interface versioning, see
2010 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2011 * What follows is a condensed summary, to help you navigate the large and
2012 * confusing official doc.
2014 * - Loader interface v0 is incompatible with later versions. We don't
2017 * - In loader interface v1:
2018 * - The first ICD entrypoint called by the loader is
2019 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2021 * - The ICD must statically expose no other Vulkan symbol unless it
2022 * is linked with -Bsymbolic.
2023 * - Each dispatchable Vulkan handle created by the ICD must be
2024 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2025 * ICD must initialize VK_LOADER_DATA.loadMagic to
2027 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2028 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2029 * such loader-managed surfaces.
2031 * - Loader interface v2 differs from v1 in:
2032 * - The first ICD entrypoint called by the loader is
2033 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2034 * statically expose this entrypoint.
2036 * - Loader interface v3 differs from v2 in:
2037 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2038 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2039 * because the loader no longer does so.
2041 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
2046 tu_GetMemoryFdKHR(VkDevice _device
,
2047 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
2050 TU_FROM_HANDLE(tu_device
, device
, _device
);
2051 TU_FROM_HANDLE(tu_device_memory
, memory
, pGetFdInfo
->memory
);
2053 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
2055 /* At the moment, we support only the below handle types. */
2056 assert(pGetFdInfo
->handleType
==
2057 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
2058 pGetFdInfo
->handleType
==
2059 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2061 int prime_fd
= tu_bo_export_dmabuf(device
, &memory
->bo
);
2063 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2070 tu_GetMemoryFdPropertiesKHR(VkDevice _device
,
2071 VkExternalMemoryHandleTypeFlagBits handleType
,
2073 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
2075 assert(handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2076 pMemoryFdProperties
->memoryTypeBits
= 1;
2081 tu_GetPhysicalDeviceExternalSemaphoreProperties(
2082 VkPhysicalDevice physicalDevice
,
2083 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
2084 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
2086 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
2087 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
2088 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
2092 tu_GetPhysicalDeviceExternalFenceProperties(
2093 VkPhysicalDevice physicalDevice
,
2094 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
2095 VkExternalFenceProperties
*pExternalFenceProperties
)
2097 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
2098 pExternalFenceProperties
->compatibleHandleTypes
= 0;
2099 pExternalFenceProperties
->externalFenceFeatures
= 0;
2103 tu_CreateDebugReportCallbackEXT(
2104 VkInstance _instance
,
2105 const VkDebugReportCallbackCreateInfoEXT
*pCreateInfo
,
2106 const VkAllocationCallbacks
*pAllocator
,
2107 VkDebugReportCallbackEXT
*pCallback
)
2109 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2110 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
2111 pCreateInfo
, pAllocator
,
2112 &instance
->alloc
, pCallback
);
2116 tu_DestroyDebugReportCallbackEXT(VkInstance _instance
,
2117 VkDebugReportCallbackEXT _callback
,
2118 const VkAllocationCallbacks
*pAllocator
)
2120 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2121 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
2122 _callback
, pAllocator
, &instance
->alloc
);
2126 tu_DebugReportMessageEXT(VkInstance _instance
,
2127 VkDebugReportFlagsEXT flags
,
2128 VkDebugReportObjectTypeEXT objectType
,
2131 int32_t messageCode
,
2132 const char *pLayerPrefix
,
2133 const char *pMessage
)
2135 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
2136 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
2137 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
2141 tu_GetDeviceGroupPeerMemoryFeatures(
2144 uint32_t localDeviceIndex
,
2145 uint32_t remoteDeviceIndex
,
2146 VkPeerMemoryFeatureFlags
*pPeerMemoryFeatures
)
2148 assert(localDeviceIndex
== remoteDeviceIndex
);
2150 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
2151 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
2152 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
2153 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;