tu: Use an input for the layer when lowering input attachments
[mesa.git] / src / freedreno / vulkan / tu_device.c
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
7 *
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:
14 *
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
17 * Software.
18 *
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.
26 */
27
28 #include "tu_private.h"
29
30 #include <fcntl.h>
31 #include <libsync.h>
32 #include <stdbool.h>
33 #include <string.h>
34 #include <sys/sysinfo.h>
35 #include <unistd.h>
36
37 #include "compiler/glsl_types.h"
38 #include "util/debug.h"
39 #include "util/disk_cache.h"
40 #include "util/u_atomic.h"
41 #include "vk_format.h"
42 #include "vk_util.h"
43
44 /* for fd_get_driver/device_uuid() */
45 #include "freedreno/common/freedreno_uuid.h"
46
47 static int
48 tu_device_get_cache_uuid(uint16_t family, void *uuid)
49 {
50 uint32_t mesa_timestamp;
51 uint16_t f = family;
52 memset(uuid, 0, VK_UUID_SIZE);
53 if (!disk_cache_get_function_timestamp(tu_device_get_cache_uuid,
54 &mesa_timestamp))
55 return -1;
56
57 memcpy(uuid, &mesa_timestamp, 4);
58 memcpy((char *) uuid + 4, &f, 2);
59 snprintf((char *) uuid + 6, VK_UUID_SIZE - 10, "tu");
60 return 0;
61 }
62
63 VkResult
64 tu_physical_device_init(struct tu_physical_device *device,
65 struct tu_instance *instance)
66 {
67 VkResult result = VK_SUCCESS;
68
69 memset(device->name, 0, sizeof(device->name));
70 sprintf(device->name, "FD%d", device->gpu_id);
71
72 device->limited_z24s8 = (device->gpu_id == 630);
73
74 switch (device->gpu_id) {
75 case 618:
76 device->ccu_offset_gmem = 0x7c000; /* 0x7e000 in some cases? */
77 device->ccu_offset_bypass = 0x10000;
78 device->tile_align_w = 32;
79 device->magic.PC_UNKNOWN_9805 = 0x0;
80 device->magic.SP_UNKNOWN_A0F8 = 0x0;
81 break;
82 case 630:
83 case 640:
84 device->ccu_offset_gmem = 0xf8000;
85 device->ccu_offset_bypass = 0x20000;
86 device->tile_align_w = 32;
87 device->magic.PC_UNKNOWN_9805 = 0x1;
88 device->magic.SP_UNKNOWN_A0F8 = 0x1;
89 break;
90 case 650:
91 device->ccu_offset_gmem = 0x114000;
92 device->ccu_offset_bypass = 0x30000;
93 device->tile_align_w = 96;
94 device->magic.PC_UNKNOWN_9805 = 0x2;
95 device->magic.SP_UNKNOWN_A0F8 = 0x2;
96 break;
97 default:
98 result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
99 "device %s is unsupported", device->name);
100 goto fail;
101 }
102 if (tu_device_get_cache_uuid(device->gpu_id, device->cache_uuid)) {
103 result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
104 "cannot generate UUID");
105 goto fail;
106 }
107
108 /* The gpu id is already embedded in the uuid so we just pass "tu"
109 * when creating the cache.
110 */
111 char buf[VK_UUID_SIZE * 2 + 1];
112 disk_cache_format_hex_id(buf, device->cache_uuid, VK_UUID_SIZE * 2);
113 device->disk_cache = disk_cache_create(device->name, buf, 0);
114
115 fprintf(stderr, "WARNING: tu is not a conformant vulkan implementation, "
116 "testing use only.\n");
117
118 fd_get_driver_uuid(device->driver_uuid);
119 fd_get_device_uuid(device->device_uuid, device->gpu_id);
120
121 tu_physical_device_get_supported_extensions(device, &device->supported_extensions);
122
123 if (result != VK_SUCCESS) {
124 vk_error(instance, result);
125 goto fail;
126 }
127
128 result = tu_wsi_init(device);
129 if (result != VK_SUCCESS) {
130 vk_error(instance, result);
131 goto fail;
132 }
133
134 return VK_SUCCESS;
135
136 fail:
137 close(device->local_fd);
138 if (device->master_fd != -1)
139 close(device->master_fd);
140 return result;
141 }
142
143 static void
144 tu_physical_device_finish(struct tu_physical_device *device)
145 {
146 tu_wsi_finish(device);
147
148 disk_cache_destroy(device->disk_cache);
149 close(device->local_fd);
150 if (device->master_fd != -1)
151 close(device->master_fd);
152
153 vk_object_base_finish(&device->base);
154 }
155
156 static VKAPI_ATTR void *
157 default_alloc_func(void *pUserData,
158 size_t size,
159 size_t align,
160 VkSystemAllocationScope allocationScope)
161 {
162 return malloc(size);
163 }
164
165 static VKAPI_ATTR void *
166 default_realloc_func(void *pUserData,
167 void *pOriginal,
168 size_t size,
169 size_t align,
170 VkSystemAllocationScope allocationScope)
171 {
172 return realloc(pOriginal, size);
173 }
174
175 static VKAPI_ATTR void
176 default_free_func(void *pUserData, void *pMemory)
177 {
178 free(pMemory);
179 }
180
181 static const VkAllocationCallbacks default_alloc = {
182 .pUserData = NULL,
183 .pfnAllocation = default_alloc_func,
184 .pfnReallocation = default_realloc_func,
185 .pfnFree = default_free_func,
186 };
187
188 static const struct debug_control tu_debug_options[] = {
189 { "startup", TU_DEBUG_STARTUP },
190 { "nir", TU_DEBUG_NIR },
191 { "ir3", TU_DEBUG_IR3 },
192 { "nobin", TU_DEBUG_NOBIN },
193 { "sysmem", TU_DEBUG_SYSMEM },
194 { "forcebin", TU_DEBUG_FORCEBIN },
195 { "noubwc", TU_DEBUG_NOUBWC },
196 { NULL, 0 }
197 };
198
199 const char *
200 tu_get_debug_option_name(int id)
201 {
202 assert(id < ARRAY_SIZE(tu_debug_options) - 1);
203 return tu_debug_options[id].string;
204 }
205
206 static int
207 tu_get_instance_extension_index(const char *name)
208 {
209 for (unsigned i = 0; i < TU_INSTANCE_EXTENSION_COUNT; ++i) {
210 if (strcmp(name, tu_instance_extensions[i].extensionName) == 0)
211 return i;
212 }
213 return -1;
214 }
215
216 VkResult
217 tu_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
218 const VkAllocationCallbacks *pAllocator,
219 VkInstance *pInstance)
220 {
221 struct tu_instance *instance;
222 VkResult result;
223
224 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
225
226 uint32_t client_version;
227 if (pCreateInfo->pApplicationInfo &&
228 pCreateInfo->pApplicationInfo->apiVersion != 0) {
229 client_version = pCreateInfo->pApplicationInfo->apiVersion;
230 } else {
231 tu_EnumerateInstanceVersion(&client_version);
232 }
233
234 instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
235 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
236
237 if (!instance)
238 return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
239
240 vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE);
241
242 if (pAllocator)
243 instance->alloc = *pAllocator;
244 else
245 instance->alloc = default_alloc;
246
247 instance->api_version = client_version;
248 instance->physical_device_count = -1;
249
250 instance->debug_flags =
251 parse_debug_string(getenv("TU_DEBUG"), tu_debug_options);
252
253 if (instance->debug_flags & TU_DEBUG_STARTUP)
254 tu_logi("Created an instance");
255
256 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
257 const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
258 int index = tu_get_instance_extension_index(ext_name);
259
260 if (index < 0 || !tu_instance_extensions_supported.extensions[index]) {
261 vk_object_base_finish(&instance->base);
262 vk_free2(&default_alloc, pAllocator, instance);
263 return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT);
264 }
265
266 instance->enabled_extensions.extensions[index] = true;
267 }
268
269 result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
270 if (result != VK_SUCCESS) {
271 vk_object_base_finish(&instance->base);
272 vk_free2(&default_alloc, pAllocator, instance);
273 return vk_error(instance, result);
274 }
275
276 glsl_type_singleton_init_or_ref();
277
278 VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
279
280 *pInstance = tu_instance_to_handle(instance);
281
282 return VK_SUCCESS;
283 }
284
285 void
286 tu_DestroyInstance(VkInstance _instance,
287 const VkAllocationCallbacks *pAllocator)
288 {
289 TU_FROM_HANDLE(tu_instance, instance, _instance);
290
291 if (!instance)
292 return;
293
294 for (int i = 0; i < instance->physical_device_count; ++i) {
295 tu_physical_device_finish(instance->physical_devices + i);
296 }
297
298 VG(VALGRIND_DESTROY_MEMPOOL(instance));
299
300 glsl_type_singleton_decref();
301
302 vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
303
304 vk_object_base_finish(&instance->base);
305 vk_free(&instance->alloc, instance);
306 }
307
308 VkResult
309 tu_EnumeratePhysicalDevices(VkInstance _instance,
310 uint32_t *pPhysicalDeviceCount,
311 VkPhysicalDevice *pPhysicalDevices)
312 {
313 TU_FROM_HANDLE(tu_instance, instance, _instance);
314 VK_OUTARRAY_MAKE(out, pPhysicalDevices, pPhysicalDeviceCount);
315
316 VkResult result;
317
318 if (instance->physical_device_count < 0) {
319 result = tu_enumerate_devices(instance);
320 if (result != VK_SUCCESS && result != VK_ERROR_INCOMPATIBLE_DRIVER)
321 return result;
322 }
323
324 for (uint32_t i = 0; i < instance->physical_device_count; ++i) {
325 vk_outarray_append(&out, p)
326 {
327 *p = tu_physical_device_to_handle(instance->physical_devices + i);
328 }
329 }
330
331 return vk_outarray_status(&out);
332 }
333
334 VkResult
335 tu_EnumeratePhysicalDeviceGroups(
336 VkInstance _instance,
337 uint32_t *pPhysicalDeviceGroupCount,
338 VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties)
339 {
340 TU_FROM_HANDLE(tu_instance, instance, _instance);
341 VK_OUTARRAY_MAKE(out, pPhysicalDeviceGroupProperties,
342 pPhysicalDeviceGroupCount);
343 VkResult result;
344
345 if (instance->physical_device_count < 0) {
346 result = tu_enumerate_devices(instance);
347 if (result != VK_SUCCESS && result != VK_ERROR_INCOMPATIBLE_DRIVER)
348 return result;
349 }
350
351 for (uint32_t i = 0; i < instance->physical_device_count; ++i) {
352 vk_outarray_append(&out, p)
353 {
354 p->physicalDeviceCount = 1;
355 p->physicalDevices[0] =
356 tu_physical_device_to_handle(instance->physical_devices + i);
357 p->subsetAllocation = false;
358 }
359 }
360
361 return vk_outarray_status(&out);
362 }
363
364 void
365 tu_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
366 VkPhysicalDeviceFeatures *pFeatures)
367 {
368 memset(pFeatures, 0, sizeof(*pFeatures));
369
370 *pFeatures = (VkPhysicalDeviceFeatures) {
371 .robustBufferAccess = true,
372 .fullDrawIndexUint32 = true,
373 .imageCubeArray = true,
374 .independentBlend = true,
375 .geometryShader = true,
376 .tessellationShader = true,
377 .sampleRateShading = true,
378 .dualSrcBlend = true,
379 .logicOp = true,
380 .multiDrawIndirect = true,
381 .drawIndirectFirstInstance = true,
382 .depthClamp = true,
383 .depthBiasClamp = true,
384 .fillModeNonSolid = true,
385 .depthBounds = true,
386 .wideLines = false,
387 .largePoints = true,
388 .alphaToOne = true,
389 .multiViewport = false,
390 .samplerAnisotropy = true,
391 .textureCompressionETC2 = true,
392 .textureCompressionASTC_LDR = true,
393 .textureCompressionBC = true,
394 .occlusionQueryPrecise = true,
395 .pipelineStatisticsQuery = false,
396 .vertexPipelineStoresAndAtomics = true,
397 .fragmentStoresAndAtomics = true,
398 .shaderTessellationAndGeometryPointSize = false,
399 .shaderImageGatherExtended = false,
400 .shaderStorageImageExtendedFormats = false,
401 .shaderStorageImageMultisample = false,
402 .shaderUniformBufferArrayDynamicIndexing = true,
403 .shaderSampledImageArrayDynamicIndexing = true,
404 .shaderStorageBufferArrayDynamicIndexing = true,
405 .shaderStorageImageArrayDynamicIndexing = true,
406 .shaderStorageImageReadWithoutFormat = false,
407 .shaderStorageImageWriteWithoutFormat = false,
408 .shaderClipDistance = false,
409 .shaderCullDistance = false,
410 .shaderFloat64 = false,
411 .shaderInt64 = false,
412 .shaderInt16 = false,
413 .sparseBinding = false,
414 .variableMultisampleRate = false,
415 .inheritedQueries = false,
416 };
417 }
418
419 void
420 tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
421 VkPhysicalDeviceFeatures2 *pFeatures)
422 {
423 vk_foreach_struct(ext, pFeatures->pNext)
424 {
425 switch (ext->sType) {
426 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES: {
427 VkPhysicalDeviceVulkan11Features *features = (void *) ext;
428 features->storageBuffer16BitAccess = false;
429 features->uniformAndStorageBuffer16BitAccess = false;
430 features->storagePushConstant16 = false;
431 features->storageInputOutput16 = false;
432 features->multiview = false;
433 features->multiviewGeometryShader = false;
434 features->multiviewTessellationShader = false;
435 features->variablePointersStorageBuffer = true;
436 features->variablePointers = true;
437 features->protectedMemory = false;
438 features->samplerYcbcrConversion = true;
439 features->shaderDrawParameters = true;
440 break;
441 }
442 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES: {
443 VkPhysicalDeviceVulkan12Features *features = (void *) ext;
444 features->samplerMirrorClampToEdge = true;
445 features->drawIndirectCount = true;
446 features->storageBuffer8BitAccess = false;
447 features->uniformAndStorageBuffer8BitAccess = false;
448 features->storagePushConstant8 = false;
449 features->shaderBufferInt64Atomics = false;
450 features->shaderSharedInt64Atomics = false;
451 features->shaderFloat16 = false;
452 features->shaderInt8 = false;
453
454 features->descriptorIndexing = false;
455 features->shaderInputAttachmentArrayDynamicIndexing = false;
456 features->shaderUniformTexelBufferArrayDynamicIndexing = false;
457 features->shaderStorageTexelBufferArrayDynamicIndexing = false;
458 features->shaderUniformBufferArrayNonUniformIndexing = false;
459 features->shaderSampledImageArrayNonUniformIndexing = false;
460 features->shaderStorageBufferArrayNonUniformIndexing = false;
461 features->shaderStorageImageArrayNonUniformIndexing = false;
462 features->shaderInputAttachmentArrayNonUniformIndexing = false;
463 features->shaderUniformTexelBufferArrayNonUniformIndexing = false;
464 features->shaderStorageTexelBufferArrayNonUniformIndexing = false;
465 features->descriptorBindingUniformBufferUpdateAfterBind = false;
466 features->descriptorBindingSampledImageUpdateAfterBind = false;
467 features->descriptorBindingStorageImageUpdateAfterBind = false;
468 features->descriptorBindingStorageBufferUpdateAfterBind = false;
469 features->descriptorBindingUniformTexelBufferUpdateAfterBind = false;
470 features->descriptorBindingStorageTexelBufferUpdateAfterBind = false;
471 features->descriptorBindingUpdateUnusedWhilePending = false;
472 features->descriptorBindingPartiallyBound = false;
473 features->descriptorBindingVariableDescriptorCount = false;
474 features->runtimeDescriptorArray = false;
475
476 features->samplerFilterMinmax = true;
477 features->scalarBlockLayout = false;
478 features->imagelessFramebuffer = false;
479 features->uniformBufferStandardLayout = false;
480 features->shaderSubgroupExtendedTypes = false;
481 features->separateDepthStencilLayouts = false;
482 features->hostQueryReset = false;
483 features->timelineSemaphore = false;
484 features->bufferDeviceAddress = false;
485 features->bufferDeviceAddressCaptureReplay = false;
486 features->bufferDeviceAddressMultiDevice = false;
487 features->vulkanMemoryModel = false;
488 features->vulkanMemoryModelDeviceScope = false;
489 features->vulkanMemoryModelAvailabilityVisibilityChains = false;
490 features->shaderOutputViewportIndex = false;
491 features->shaderOutputLayer = false;
492 features->subgroupBroadcastDynamicId = false;
493 break;
494 }
495 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES: {
496 VkPhysicalDeviceVariablePointersFeatures *features = (void *) ext;
497 features->variablePointersStorageBuffer = true;
498 features->variablePointers = true;
499 break;
500 }
501 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: {
502 VkPhysicalDeviceMultiviewFeatures *features =
503 (VkPhysicalDeviceMultiviewFeatures *) ext;
504 features->multiview = false;
505 features->multiviewGeometryShader = false;
506 features->multiviewTessellationShader = false;
507 break;
508 }
509 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES: {
510 VkPhysicalDeviceShaderDrawParametersFeatures *features =
511 (VkPhysicalDeviceShaderDrawParametersFeatures *) ext;
512 features->shaderDrawParameters = true;
513 break;
514 }
515 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
516 VkPhysicalDeviceProtectedMemoryFeatures *features =
517 (VkPhysicalDeviceProtectedMemoryFeatures *) ext;
518 features->protectedMemory = false;
519 break;
520 }
521 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
522 VkPhysicalDevice16BitStorageFeatures *features =
523 (VkPhysicalDevice16BitStorageFeatures *) ext;
524 features->storageBuffer16BitAccess = false;
525 features->uniformAndStorageBuffer16BitAccess = false;
526 features->storagePushConstant16 = false;
527 features->storageInputOutput16 = false;
528 break;
529 }
530 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
531 VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
532 (VkPhysicalDeviceSamplerYcbcrConversionFeatures *) ext;
533 features->samplerYcbcrConversion = true;
534 break;
535 }
536 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT: {
537 VkPhysicalDeviceDescriptorIndexingFeaturesEXT *features =
538 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT *) ext;
539 features->shaderInputAttachmentArrayDynamicIndexing = false;
540 features->shaderUniformTexelBufferArrayDynamicIndexing = false;
541 features->shaderStorageTexelBufferArrayDynamicIndexing = false;
542 features->shaderUniformBufferArrayNonUniformIndexing = false;
543 features->shaderSampledImageArrayNonUniformIndexing = false;
544 features->shaderStorageBufferArrayNonUniformIndexing = false;
545 features->shaderStorageImageArrayNonUniformIndexing = false;
546 features->shaderInputAttachmentArrayNonUniformIndexing = false;
547 features->shaderUniformTexelBufferArrayNonUniformIndexing = false;
548 features->shaderStorageTexelBufferArrayNonUniformIndexing = false;
549 features->descriptorBindingUniformBufferUpdateAfterBind = false;
550 features->descriptorBindingSampledImageUpdateAfterBind = false;
551 features->descriptorBindingStorageImageUpdateAfterBind = false;
552 features->descriptorBindingStorageBufferUpdateAfterBind = false;
553 features->descriptorBindingUniformTexelBufferUpdateAfterBind = false;
554 features->descriptorBindingStorageTexelBufferUpdateAfterBind = false;
555 features->descriptorBindingUpdateUnusedWhilePending = false;
556 features->descriptorBindingPartiallyBound = false;
557 features->descriptorBindingVariableDescriptorCount = false;
558 features->runtimeDescriptorArray = false;
559 break;
560 }
561 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT: {
562 VkPhysicalDeviceConditionalRenderingFeaturesEXT *features =
563 (VkPhysicalDeviceConditionalRenderingFeaturesEXT *) ext;
564 features->conditionalRendering = true;
565 features->inheritedConditionalRendering = true;
566 break;
567 }
568 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT: {
569 VkPhysicalDeviceTransformFeedbackFeaturesEXT *features =
570 (VkPhysicalDeviceTransformFeedbackFeaturesEXT *) ext;
571 features->transformFeedback = true;
572 features->geometryStreams = false;
573 break;
574 }
575 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
576 VkPhysicalDeviceIndexTypeUint8FeaturesEXT *features =
577 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT *)ext;
578 features->indexTypeUint8 = true;
579 break;
580 }
581 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
582 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *features =
583 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *)ext;
584 features->vertexAttributeInstanceRateDivisor = true;
585 features->vertexAttributeInstanceRateZeroDivisor = true;
586 break;
587 }
588 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT: {
589 VkPhysicalDevicePrivateDataFeaturesEXT *features =
590 (VkPhysicalDevicePrivateDataFeaturesEXT *)ext;
591 features->privateData = true;
592 break;
593 }
594 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT: {
595 VkPhysicalDeviceDepthClipEnableFeaturesEXT *features =
596 (VkPhysicalDeviceDepthClipEnableFeaturesEXT *)ext;
597 features->depthClipEnable = true;
598 break;
599 }
600 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_4444_FORMATS_FEATURES_EXT: {
601 VkPhysicalDevice4444FormatsFeaturesEXT *features = (void *)ext;
602 features->formatA4R4G4B4 = true;
603 features->formatA4B4G4R4 = true;
604 break;
605 }
606 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT: {
607 VkPhysicalDeviceCustomBorderColorFeaturesEXT *features = (void *) ext;
608 features->customBorderColors = true;
609 features->customBorderColorWithoutFormat = true;
610 break;
611 }
612 default:
613 break;
614 }
615 }
616 return tu_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
617 }
618
619 void
620 tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
621 VkPhysicalDeviceProperties *pProperties)
622 {
623 TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
624 VkSampleCountFlags sample_counts =
625 VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT;
626
627 /* I have no idea what the maximum size is, but the hardware supports very
628 * large numbers of descriptors (at least 2^16). This limit is based on
629 * CP_LOAD_STATE6, which has a 28-bit field for the DWORD offset, so that
630 * we don't have to think about what to do if that overflows, but really
631 * nothing is likely to get close to this.
632 */
633 const size_t max_descriptor_set_size = (1 << 28) / A6XX_TEX_CONST_DWORDS;
634
635 VkPhysicalDeviceLimits limits = {
636 .maxImageDimension1D = (1 << 14),
637 .maxImageDimension2D = (1 << 14),
638 .maxImageDimension3D = (1 << 11),
639 .maxImageDimensionCube = (1 << 14),
640 .maxImageArrayLayers = (1 << 11),
641 .maxTexelBufferElements = 128 * 1024 * 1024,
642 .maxUniformBufferRange = MAX_UNIFORM_BUFFER_RANGE,
643 .maxStorageBufferRange = MAX_STORAGE_BUFFER_RANGE,
644 .maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE,
645 .maxMemoryAllocationCount = UINT32_MAX,
646 .maxSamplerAllocationCount = 64 * 1024,
647 .bufferImageGranularity = 64, /* A cache line */
648 .sparseAddressSpaceSize = 0xffffffffu, /* buffer max size */
649 .maxBoundDescriptorSets = MAX_SETS,
650 .maxPerStageDescriptorSamplers = max_descriptor_set_size,
651 .maxPerStageDescriptorUniformBuffers = max_descriptor_set_size,
652 .maxPerStageDescriptorStorageBuffers = max_descriptor_set_size,
653 .maxPerStageDescriptorSampledImages = max_descriptor_set_size,
654 .maxPerStageDescriptorStorageImages = max_descriptor_set_size,
655 .maxPerStageDescriptorInputAttachments = MAX_RTS,
656 .maxPerStageResources = max_descriptor_set_size,
657 .maxDescriptorSetSamplers = max_descriptor_set_size,
658 .maxDescriptorSetUniformBuffers = max_descriptor_set_size,
659 .maxDescriptorSetUniformBuffersDynamic = MAX_DYNAMIC_UNIFORM_BUFFERS,
660 .maxDescriptorSetStorageBuffers = max_descriptor_set_size,
661 .maxDescriptorSetStorageBuffersDynamic = MAX_DYNAMIC_STORAGE_BUFFERS,
662 .maxDescriptorSetSampledImages = max_descriptor_set_size,
663 .maxDescriptorSetStorageImages = max_descriptor_set_size,
664 .maxDescriptorSetInputAttachments = MAX_RTS,
665 .maxVertexInputAttributes = 32,
666 .maxVertexInputBindings = 32,
667 .maxVertexInputAttributeOffset = 4095,
668 .maxVertexInputBindingStride = 2048,
669 .maxVertexOutputComponents = 128,
670 .maxTessellationGenerationLevel = 64,
671 .maxTessellationPatchSize = 32,
672 .maxTessellationControlPerVertexInputComponents = 128,
673 .maxTessellationControlPerVertexOutputComponents = 128,
674 .maxTessellationControlPerPatchOutputComponents = 120,
675 .maxTessellationControlTotalOutputComponents = 4096,
676 .maxTessellationEvaluationInputComponents = 128,
677 .maxTessellationEvaluationOutputComponents = 128,
678 .maxGeometryShaderInvocations = 32,
679 .maxGeometryInputComponents = 64,
680 .maxGeometryOutputComponents = 128,
681 .maxGeometryOutputVertices = 256,
682 .maxGeometryTotalOutputComponents = 1024,
683 .maxFragmentInputComponents = 124,
684 .maxFragmentOutputAttachments = 8,
685 .maxFragmentDualSrcAttachments = 1,
686 .maxFragmentCombinedOutputResources = 8,
687 .maxComputeSharedMemorySize = 32768,
688 .maxComputeWorkGroupCount = { 65535, 65535, 65535 },
689 .maxComputeWorkGroupInvocations = 2048,
690 .maxComputeWorkGroupSize = { 2048, 2048, 2048 },
691 .subPixelPrecisionBits = 8,
692 .subTexelPrecisionBits = 8,
693 .mipmapPrecisionBits = 8,
694 .maxDrawIndexedIndexValue = UINT32_MAX,
695 .maxDrawIndirectCount = UINT32_MAX,
696 .maxSamplerLodBias = 4095.0 / 256.0, /* [-16, 15.99609375] */
697 .maxSamplerAnisotropy = 16,
698 .maxViewports = MAX_VIEWPORTS,
699 .maxViewportDimensions = { (1 << 14), (1 << 14) },
700 .viewportBoundsRange = { INT16_MIN, INT16_MAX },
701 .viewportSubPixelBits = 8,
702 .minMemoryMapAlignment = 4096, /* A page */
703 .minTexelBufferOffsetAlignment = 64,
704 .minUniformBufferOffsetAlignment = 64,
705 .minStorageBufferOffsetAlignment = 64,
706 .minTexelOffset = -16,
707 .maxTexelOffset = 15,
708 .minTexelGatherOffset = -32,
709 .maxTexelGatherOffset = 31,
710 .minInterpolationOffset = -0.5,
711 .maxInterpolationOffset = 0.4375,
712 .subPixelInterpolationOffsetBits = 4,
713 .maxFramebufferWidth = (1 << 14),
714 .maxFramebufferHeight = (1 << 14),
715 .maxFramebufferLayers = (1 << 10),
716 .framebufferColorSampleCounts = sample_counts,
717 .framebufferDepthSampleCounts = sample_counts,
718 .framebufferStencilSampleCounts = sample_counts,
719 .framebufferNoAttachmentsSampleCounts = sample_counts,
720 .maxColorAttachments = MAX_RTS,
721 .sampledImageColorSampleCounts = sample_counts,
722 .sampledImageIntegerSampleCounts = VK_SAMPLE_COUNT_1_BIT,
723 .sampledImageDepthSampleCounts = sample_counts,
724 .sampledImageStencilSampleCounts = sample_counts,
725 .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT,
726 .maxSampleMaskWords = 1,
727 .timestampComputeAndGraphics = true,
728 .timestampPeriod = 1000000000.0 / 19200000.0, /* CP_ALWAYS_ON_COUNTER is fixed 19.2MHz */
729 .maxClipDistances = 8,
730 .maxCullDistances = 8,
731 .maxCombinedClipAndCullDistances = 8,
732 .discreteQueuePriorities = 1,
733 .pointSizeRange = { 1, 4092 },
734 .lineWidthRange = { 0.0, 7.9921875 },
735 .pointSizeGranularity = 0.0625,
736 .lineWidthGranularity = (1.0 / 128.0),
737 .strictLines = false, /* FINISHME */
738 .standardSampleLocations = true,
739 .optimalBufferCopyOffsetAlignment = 128,
740 .optimalBufferCopyRowPitchAlignment = 128,
741 .nonCoherentAtomSize = 64,
742 };
743
744 *pProperties = (VkPhysicalDeviceProperties) {
745 .apiVersion = tu_physical_device_api_version(pdevice),
746 .driverVersion = vk_get_driver_version(),
747 .vendorID = 0, /* TODO */
748 .deviceID = 0,
749 .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
750 .limits = limits,
751 .sparseProperties = { 0 },
752 };
753
754 strcpy(pProperties->deviceName, pdevice->name);
755 memcpy(pProperties->pipelineCacheUUID, pdevice->cache_uuid, VK_UUID_SIZE);
756 }
757
758 void
759 tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
760 VkPhysicalDeviceProperties2 *pProperties)
761 {
762 TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
763 tu_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
764
765 vk_foreach_struct(ext, pProperties->pNext)
766 {
767 switch (ext->sType) {
768 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
769 VkPhysicalDevicePushDescriptorPropertiesKHR *properties =
770 (VkPhysicalDevicePushDescriptorPropertiesKHR *) ext;
771 properties->maxPushDescriptors = MAX_PUSH_DESCRIPTORS;
772 break;
773 }
774 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: {
775 VkPhysicalDeviceIDProperties *properties =
776 (VkPhysicalDeviceIDProperties *) ext;
777 memcpy(properties->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
778 memcpy(properties->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
779 properties->deviceLUIDValid = false;
780 break;
781 }
782 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES: {
783 VkPhysicalDeviceMultiviewProperties *properties =
784 (VkPhysicalDeviceMultiviewProperties *) ext;
785 properties->maxMultiviewViewCount = MAX_VIEWS;
786 properties->maxMultiviewInstanceIndex = INT_MAX;
787 break;
788 }
789 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES: {
790 VkPhysicalDevicePointClippingProperties *properties =
791 (VkPhysicalDevicePointClippingProperties *) ext;
792 properties->pointClippingBehavior =
793 VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES;
794 break;
795 }
796 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
797 VkPhysicalDeviceMaintenance3Properties *properties =
798 (VkPhysicalDeviceMaintenance3Properties *) ext;
799 /* Make sure everything is addressable by a signed 32-bit int, and
800 * our largest descriptors are 96 bytes. */
801 properties->maxPerSetDescriptors = (1ull << 31) / 96;
802 /* Our buffer size fields allow only this much */
803 properties->maxMemoryAllocationSize = 0xFFFFFFFFull;
804 break;
805 }
806 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT: {
807 VkPhysicalDeviceTransformFeedbackPropertiesEXT *properties =
808 (VkPhysicalDeviceTransformFeedbackPropertiesEXT *)ext;
809
810 properties->maxTransformFeedbackStreams = IR3_MAX_SO_STREAMS;
811 properties->maxTransformFeedbackBuffers = IR3_MAX_SO_BUFFERS;
812 properties->maxTransformFeedbackBufferSize = UINT32_MAX;
813 properties->maxTransformFeedbackStreamDataSize = 512;
814 properties->maxTransformFeedbackBufferDataSize = 512;
815 properties->maxTransformFeedbackBufferDataStride = 512;
816 properties->transformFeedbackQueries = true;
817 properties->transformFeedbackStreamsLinesTriangles = false;
818 properties->transformFeedbackRasterizationStreamSelect = false;
819 properties->transformFeedbackDraw = true;
820 break;
821 }
822 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT: {
823 VkPhysicalDeviceSampleLocationsPropertiesEXT *properties =
824 (VkPhysicalDeviceSampleLocationsPropertiesEXT *)ext;
825 properties->sampleLocationSampleCounts = 0;
826 if (pdevice->supported_extensions.EXT_sample_locations) {
827 properties->sampleLocationSampleCounts =
828 VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT;
829 }
830 properties->maxSampleLocationGridSize = (VkExtent2D) { 1 , 1 };
831 properties->sampleLocationCoordinateRange[0] = 0.0f;
832 properties->sampleLocationCoordinateRange[1] = 0.9375f;
833 properties->sampleLocationSubPixelBits = 4;
834 properties->variableSampleLocations = true;
835 break;
836 }
837 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES: {
838 VkPhysicalDeviceSamplerFilterMinmaxProperties *properties =
839 (VkPhysicalDeviceSamplerFilterMinmaxProperties *)ext;
840 properties->filterMinmaxImageComponentMapping = true;
841 properties->filterMinmaxSingleComponentFormats = true;
842 break;
843 }
844 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES: {
845 VkPhysicalDeviceSubgroupProperties *properties =
846 (VkPhysicalDeviceSubgroupProperties *)ext;
847 properties->subgroupSize = 64;
848 properties->supportedStages = VK_SHADER_STAGE_COMPUTE_BIT;
849 properties->supportedOperations = VK_SUBGROUP_FEATURE_BASIC_BIT |
850 VK_SUBGROUP_FEATURE_VOTE_BIT;
851 properties->quadOperationsInAllStages = false;
852 break;
853 }
854 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
855 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *props =
856 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *)ext;
857 props->maxVertexAttribDivisor = UINT32_MAX;
858 break;
859 }
860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT: {
861 VkPhysicalDeviceCustomBorderColorPropertiesEXT *props = (void *)ext;
862 props->maxCustomBorderColorSamplers = TU_BORDER_COLOR_COUNT;
863 break;
864 }
865 default:
866 break;
867 }
868 }
869 }
870
871 static const VkQueueFamilyProperties tu_queue_family_properties = {
872 .queueFlags =
873 VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT,
874 .queueCount = 1,
875 .timestampValidBits = 48,
876 .minImageTransferGranularity = { 1, 1, 1 },
877 };
878
879 void
880 tu_GetPhysicalDeviceQueueFamilyProperties(
881 VkPhysicalDevice physicalDevice,
882 uint32_t *pQueueFamilyPropertyCount,
883 VkQueueFamilyProperties *pQueueFamilyProperties)
884 {
885 VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount);
886
887 vk_outarray_append(&out, p) { *p = tu_queue_family_properties; }
888 }
889
890 void
891 tu_GetPhysicalDeviceQueueFamilyProperties2(
892 VkPhysicalDevice physicalDevice,
893 uint32_t *pQueueFamilyPropertyCount,
894 VkQueueFamilyProperties2 *pQueueFamilyProperties)
895 {
896 VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount);
897
898 vk_outarray_append(&out, p)
899 {
900 p->queueFamilyProperties = tu_queue_family_properties;
901 }
902 }
903
904 static uint64_t
905 tu_get_system_heap_size()
906 {
907 struct sysinfo info;
908 sysinfo(&info);
909
910 uint64_t total_ram = (uint64_t) info.totalram * (uint64_t) info.mem_unit;
911
912 /* We don't want to burn too much ram with the GPU. If the user has 4GiB
913 * or less, we use at most half. If they have more than 4GiB, we use 3/4.
914 */
915 uint64_t available_ram;
916 if (total_ram <= 4ull * 1024ull * 1024ull * 1024ull)
917 available_ram = total_ram / 2;
918 else
919 available_ram = total_ram * 3 / 4;
920
921 return available_ram;
922 }
923
924 void
925 tu_GetPhysicalDeviceMemoryProperties(
926 VkPhysicalDevice physicalDevice,
927 VkPhysicalDeviceMemoryProperties *pMemoryProperties)
928 {
929 pMemoryProperties->memoryHeapCount = 1;
930 pMemoryProperties->memoryHeaps[0].size = tu_get_system_heap_size();
931 pMemoryProperties->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
932
933 pMemoryProperties->memoryTypeCount = 1;
934 pMemoryProperties->memoryTypes[0].propertyFlags =
935 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
936 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
937 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
938 pMemoryProperties->memoryTypes[0].heapIndex = 0;
939 }
940
941 void
942 tu_GetPhysicalDeviceMemoryProperties2(
943 VkPhysicalDevice physicalDevice,
944 VkPhysicalDeviceMemoryProperties2 *pMemoryProperties)
945 {
946 return tu_GetPhysicalDeviceMemoryProperties(
947 physicalDevice, &pMemoryProperties->memoryProperties);
948 }
949
950 static VkResult
951 tu_queue_init(struct tu_device *device,
952 struct tu_queue *queue,
953 uint32_t queue_family_index,
954 int idx,
955 VkDeviceQueueCreateFlags flags)
956 {
957 vk_object_base_init(&device->vk, &queue->base, VK_OBJECT_TYPE_QUEUE);
958
959 queue->device = device;
960 queue->queue_family_index = queue_family_index;
961 queue->queue_idx = idx;
962 queue->flags = flags;
963
964 int ret = tu_drm_submitqueue_new(device, 0, &queue->msm_queue_id);
965 if (ret)
966 return VK_ERROR_INITIALIZATION_FAILED;
967
968 tu_fence_init(&queue->submit_fence, false);
969
970 return VK_SUCCESS;
971 }
972
973 static void
974 tu_queue_finish(struct tu_queue *queue)
975 {
976 tu_fence_finish(&queue->submit_fence);
977 tu_drm_submitqueue_close(queue->device, queue->msm_queue_id);
978 }
979
980 static int
981 tu_get_device_extension_index(const char *name)
982 {
983 for (unsigned i = 0; i < TU_DEVICE_EXTENSION_COUNT; ++i) {
984 if (strcmp(name, tu_device_extensions[i].extensionName) == 0)
985 return i;
986 }
987 return -1;
988 }
989
990 VkResult
991 tu_CreateDevice(VkPhysicalDevice physicalDevice,
992 const VkDeviceCreateInfo *pCreateInfo,
993 const VkAllocationCallbacks *pAllocator,
994 VkDevice *pDevice)
995 {
996 TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice);
997 VkResult result;
998 struct tu_device *device;
999 bool custom_border_colors = false;
1000
1001 /* Check enabled features */
1002 if (pCreateInfo->pEnabledFeatures) {
1003 VkPhysicalDeviceFeatures supported_features;
1004 tu_GetPhysicalDeviceFeatures(physicalDevice, &supported_features);
1005 VkBool32 *supported_feature = (VkBool32 *) &supported_features;
1006 VkBool32 *enabled_feature = (VkBool32 *) pCreateInfo->pEnabledFeatures;
1007 unsigned num_features =
1008 sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
1009 for (uint32_t i = 0; i < num_features; i++) {
1010 if (enabled_feature[i] && !supported_feature[i])
1011 return vk_error(physical_device->instance,
1012 VK_ERROR_FEATURE_NOT_PRESENT);
1013 }
1014 }
1015
1016 vk_foreach_struct_const(ext, pCreateInfo->pNext) {
1017 switch (ext->sType) {
1018 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT: {
1019 const VkPhysicalDeviceCustomBorderColorFeaturesEXT *border_color_features = (const void *)ext;
1020 custom_border_colors = border_color_features->customBorderColors;
1021 break;
1022 }
1023 default:
1024 break;
1025 }
1026 }
1027
1028 device = vk_zalloc2(&physical_device->instance->alloc, pAllocator,
1029 sizeof(*device), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
1030 if (!device)
1031 return vk_error(physical_device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1032
1033 vk_device_init(&device->vk, pCreateInfo,
1034 &physical_device->instance->alloc, pAllocator);
1035
1036 device->instance = physical_device->instance;
1037 device->physical_device = physical_device;
1038 device->_lost = false;
1039
1040 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
1041 const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
1042 int index = tu_get_device_extension_index(ext_name);
1043 if (index < 0 ||
1044 !physical_device->supported_extensions.extensions[index]) {
1045 vk_free(&device->vk.alloc, device);
1046 return vk_error(physical_device->instance,
1047 VK_ERROR_EXTENSION_NOT_PRESENT);
1048 }
1049
1050 device->enabled_extensions.extensions[index] = true;
1051 }
1052
1053 for (unsigned i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
1054 const VkDeviceQueueCreateInfo *queue_create =
1055 &pCreateInfo->pQueueCreateInfos[i];
1056 uint32_t qfi = queue_create->queueFamilyIndex;
1057 device->queues[qfi] = vk_alloc(
1058 &device->vk.alloc, queue_create->queueCount * sizeof(struct tu_queue),
1059 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
1060 if (!device->queues[qfi]) {
1061 result = VK_ERROR_OUT_OF_HOST_MEMORY;
1062 goto fail_queues;
1063 }
1064
1065 memset(device->queues[qfi], 0,
1066 queue_create->queueCount * sizeof(struct tu_queue));
1067
1068 device->queue_count[qfi] = queue_create->queueCount;
1069
1070 for (unsigned q = 0; q < queue_create->queueCount; q++) {
1071 result = tu_queue_init(device, &device->queues[qfi][q], qfi, q,
1072 queue_create->flags);
1073 if (result != VK_SUCCESS)
1074 goto fail_queues;
1075 }
1076 }
1077
1078 device->compiler = ir3_compiler_create(NULL, physical_device->gpu_id);
1079 if (!device->compiler)
1080 goto fail_queues;
1081
1082 /* initial sizes, these will increase if there is overflow */
1083 device->vsc_draw_strm_pitch = 0x1000 + VSC_PAD;
1084 device->vsc_prim_strm_pitch = 0x4000 + VSC_PAD;
1085
1086 uint32_t global_size = sizeof(struct tu6_global);
1087 if (custom_border_colors)
1088 global_size += TU_BORDER_COLOR_COUNT * sizeof(struct bcolor_entry);
1089
1090 result = tu_bo_init_new(device, &device->global_bo, global_size);
1091 if (result != VK_SUCCESS)
1092 goto fail_global_bo;
1093
1094 result = tu_bo_map(device, &device->global_bo);
1095 if (result != VK_SUCCESS)
1096 goto fail_global_bo_map;
1097
1098 struct tu6_global *global = device->global_bo.map;
1099 tu_init_clear_blit_shaders(device->global_bo.map);
1100 global->predicate = 0;
1101 tu6_pack_border_color(&global->bcolor_builtin[VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK],
1102 &(VkClearColorValue) {}, false);
1103 tu6_pack_border_color(&global->bcolor_builtin[VK_BORDER_COLOR_INT_TRANSPARENT_BLACK],
1104 &(VkClearColorValue) {}, true);
1105 tu6_pack_border_color(&global->bcolor_builtin[VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK],
1106 &(VkClearColorValue) { .float32[3] = 1.0f }, false);
1107 tu6_pack_border_color(&global->bcolor_builtin[VK_BORDER_COLOR_INT_OPAQUE_BLACK],
1108 &(VkClearColorValue) { .int32[3] = 1 }, true);
1109 tu6_pack_border_color(&global->bcolor_builtin[VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE],
1110 &(VkClearColorValue) { .float32[0 ... 3] = 1.0f }, false);
1111 tu6_pack_border_color(&global->bcolor_builtin[VK_BORDER_COLOR_INT_OPAQUE_WHITE],
1112 &(VkClearColorValue) { .int32[0 ... 3] = 1 }, true);
1113
1114 /* initialize to ones so ffs can be used to find unused slots */
1115 BITSET_ONES(device->custom_border_color);
1116
1117 VkPipelineCacheCreateInfo ci;
1118 ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1119 ci.pNext = NULL;
1120 ci.flags = 0;
1121 ci.pInitialData = NULL;
1122 ci.initialDataSize = 0;
1123 VkPipelineCache pc;
1124 result =
1125 tu_CreatePipelineCache(tu_device_to_handle(device), &ci, NULL, &pc);
1126 if (result != VK_SUCCESS)
1127 goto fail_pipeline_cache;
1128
1129 device->mem_cache = tu_pipeline_cache_from_handle(pc);
1130
1131 for (unsigned i = 0; i < ARRAY_SIZE(device->scratch_bos); i++)
1132 mtx_init(&device->scratch_bos[i].construct_mtx, mtx_plain);
1133
1134 mtx_init(&device->mutex, mtx_plain);
1135
1136 *pDevice = tu_device_to_handle(device);
1137 return VK_SUCCESS;
1138
1139 fail_pipeline_cache:
1140 fail_global_bo_map:
1141 tu_bo_finish(device, &device->global_bo);
1142
1143 fail_global_bo:
1144 ralloc_free(device->compiler);
1145
1146 fail_queues:
1147 for (unsigned i = 0; i < TU_MAX_QUEUE_FAMILIES; i++) {
1148 for (unsigned q = 0; q < device->queue_count[i]; q++)
1149 tu_queue_finish(&device->queues[i][q]);
1150 if (device->queue_count[i])
1151 vk_object_free(&device->vk, NULL, device->queues[i]);
1152 }
1153
1154 vk_free(&device->vk.alloc, device);
1155 return result;
1156 }
1157
1158 void
1159 tu_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator)
1160 {
1161 TU_FROM_HANDLE(tu_device, device, _device);
1162
1163 if (!device)
1164 return;
1165
1166 for (unsigned i = 0; i < TU_MAX_QUEUE_FAMILIES; i++) {
1167 for (unsigned q = 0; q < device->queue_count[i]; q++)
1168 tu_queue_finish(&device->queues[i][q]);
1169 if (device->queue_count[i])
1170 vk_object_free(&device->vk, NULL, device->queues[i]);
1171 }
1172
1173 for (unsigned i = 0; i < ARRAY_SIZE(device->scratch_bos); i++) {
1174 if (device->scratch_bos[i].initialized)
1175 tu_bo_finish(device, &device->scratch_bos[i].bo);
1176 }
1177
1178 ir3_compiler_destroy(device->compiler);
1179
1180 VkPipelineCache pc = tu_pipeline_cache_to_handle(device->mem_cache);
1181 tu_DestroyPipelineCache(tu_device_to_handle(device), pc, NULL);
1182
1183 vk_free(&device->vk.alloc, device);
1184 }
1185
1186 VkResult
1187 _tu_device_set_lost(struct tu_device *device,
1188 const char *file, int line,
1189 const char *msg, ...)
1190 {
1191 /* Set the flag indicating that waits should return in finite time even
1192 * after device loss.
1193 */
1194 p_atomic_inc(&device->_lost);
1195
1196 /* TODO: Report the log message through VkDebugReportCallbackEXT instead */
1197 fprintf(stderr, "%s:%d: ", file, line);
1198 va_list ap;
1199 va_start(ap, msg);
1200 vfprintf(stderr, msg, ap);
1201 va_end(ap);
1202
1203 if (env_var_as_boolean("TU_ABORT_ON_DEVICE_LOSS", false))
1204 abort();
1205
1206 return VK_ERROR_DEVICE_LOST;
1207 }
1208
1209 VkResult
1210 tu_get_scratch_bo(struct tu_device *dev, uint64_t size, struct tu_bo **bo)
1211 {
1212 unsigned size_log2 = MAX2(util_logbase2_ceil64(size), MIN_SCRATCH_BO_SIZE_LOG2);
1213 unsigned index = size_log2 - MIN_SCRATCH_BO_SIZE_LOG2;
1214 assert(index < ARRAY_SIZE(dev->scratch_bos));
1215
1216 for (unsigned i = index; i < ARRAY_SIZE(dev->scratch_bos); i++) {
1217 if (p_atomic_read(&dev->scratch_bos[i].initialized)) {
1218 /* Fast path: just return the already-allocated BO. */
1219 *bo = &dev->scratch_bos[i].bo;
1220 return VK_SUCCESS;
1221 }
1222 }
1223
1224 /* Slow path: actually allocate the BO. We take a lock because the process
1225 * of allocating it is slow, and we don't want to block the CPU while it
1226 * finishes.
1227 */
1228 mtx_lock(&dev->scratch_bos[index].construct_mtx);
1229
1230 /* Another thread may have allocated it already while we were waiting on
1231 * the lock. We need to check this in order to avoid double-allocating.
1232 */
1233 if (dev->scratch_bos[index].initialized) {
1234 mtx_unlock(&dev->scratch_bos[index].construct_mtx);
1235 *bo = &dev->scratch_bos[index].bo;
1236 return VK_SUCCESS;
1237 }
1238
1239 unsigned bo_size = 1ull << size_log2;
1240 VkResult result = tu_bo_init_new(dev, &dev->scratch_bos[index].bo, bo_size);
1241 if (result != VK_SUCCESS) {
1242 mtx_unlock(&dev->scratch_bos[index].construct_mtx);
1243 return result;
1244 }
1245
1246 p_atomic_set(&dev->scratch_bos[index].initialized, true);
1247
1248 mtx_unlock(&dev->scratch_bos[index].construct_mtx);
1249
1250 *bo = &dev->scratch_bos[index].bo;
1251 return VK_SUCCESS;
1252 }
1253
1254 VkResult
1255 tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
1256 VkLayerProperties *pProperties)
1257 {
1258 *pPropertyCount = 0;
1259 return VK_SUCCESS;
1260 }
1261
1262 VkResult
1263 tu_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
1264 uint32_t *pPropertyCount,
1265 VkLayerProperties *pProperties)
1266 {
1267 *pPropertyCount = 0;
1268 return VK_SUCCESS;
1269 }
1270
1271 void
1272 tu_GetDeviceQueue2(VkDevice _device,
1273 const VkDeviceQueueInfo2 *pQueueInfo,
1274 VkQueue *pQueue)
1275 {
1276 TU_FROM_HANDLE(tu_device, device, _device);
1277 struct tu_queue *queue;
1278
1279 queue =
1280 &device->queues[pQueueInfo->queueFamilyIndex][pQueueInfo->queueIndex];
1281 if (pQueueInfo->flags != queue->flags) {
1282 /* From the Vulkan 1.1.70 spec:
1283 *
1284 * "The queue returned by vkGetDeviceQueue2 must have the same
1285 * flags value from this structure as that used at device
1286 * creation time in a VkDeviceQueueCreateInfo instance. If no
1287 * matching flags were specified at device creation time then
1288 * pQueue will return VK_NULL_HANDLE."
1289 */
1290 *pQueue = VK_NULL_HANDLE;
1291 return;
1292 }
1293
1294 *pQueue = tu_queue_to_handle(queue);
1295 }
1296
1297 void
1298 tu_GetDeviceQueue(VkDevice _device,
1299 uint32_t queueFamilyIndex,
1300 uint32_t queueIndex,
1301 VkQueue *pQueue)
1302 {
1303 const VkDeviceQueueInfo2 info =
1304 (VkDeviceQueueInfo2) { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2,
1305 .queueFamilyIndex = queueFamilyIndex,
1306 .queueIndex = queueIndex };
1307
1308 tu_GetDeviceQueue2(_device, &info, pQueue);
1309 }
1310
1311 VkResult
1312 tu_QueueWaitIdle(VkQueue _queue)
1313 {
1314 TU_FROM_HANDLE(tu_queue, queue, _queue);
1315
1316 if (tu_device_is_lost(queue->device))
1317 return VK_ERROR_DEVICE_LOST;
1318
1319 tu_fence_wait_idle(&queue->submit_fence);
1320
1321 return VK_SUCCESS;
1322 }
1323
1324 VkResult
1325 tu_DeviceWaitIdle(VkDevice _device)
1326 {
1327 TU_FROM_HANDLE(tu_device, device, _device);
1328
1329 if (tu_device_is_lost(device))
1330 return VK_ERROR_DEVICE_LOST;
1331
1332 for (unsigned i = 0; i < TU_MAX_QUEUE_FAMILIES; i++) {
1333 for (unsigned q = 0; q < device->queue_count[i]; q++) {
1334 tu_QueueWaitIdle(tu_queue_to_handle(&device->queues[i][q]));
1335 }
1336 }
1337 return VK_SUCCESS;
1338 }
1339
1340 VkResult
1341 tu_EnumerateInstanceExtensionProperties(const char *pLayerName,
1342 uint32_t *pPropertyCount,
1343 VkExtensionProperties *pProperties)
1344 {
1345 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
1346
1347 /* We spport no lyaers */
1348 if (pLayerName)
1349 return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
1350
1351 for (int i = 0; i < TU_INSTANCE_EXTENSION_COUNT; i++) {
1352 if (tu_instance_extensions_supported.extensions[i]) {
1353 vk_outarray_append(&out, prop) { *prop = tu_instance_extensions[i]; }
1354 }
1355 }
1356
1357 return vk_outarray_status(&out);
1358 }
1359
1360 VkResult
1361 tu_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
1362 const char *pLayerName,
1363 uint32_t *pPropertyCount,
1364 VkExtensionProperties *pProperties)
1365 {
1366 /* We spport no lyaers */
1367 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
1368 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
1369
1370 /* We spport no lyaers */
1371 if (pLayerName)
1372 return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
1373
1374 for (int i = 0; i < TU_DEVICE_EXTENSION_COUNT; i++) {
1375 if (device->supported_extensions.extensions[i]) {
1376 vk_outarray_append(&out, prop) { *prop = tu_device_extensions[i]; }
1377 }
1378 }
1379
1380 return vk_outarray_status(&out);
1381 }
1382
1383 PFN_vkVoidFunction
1384 tu_GetInstanceProcAddr(VkInstance _instance, const char *pName)
1385 {
1386 TU_FROM_HANDLE(tu_instance, instance, _instance);
1387
1388 return tu_lookup_entrypoint_checked(
1389 pName, instance ? instance->api_version : 0,
1390 instance ? &instance->enabled_extensions : NULL, NULL);
1391 }
1392
1393 /* The loader wants us to expose a second GetInstanceProcAddr function
1394 * to work around certain LD_PRELOAD issues seen in apps.
1395 */
1396 PUBLIC
1397 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1398 vk_icdGetInstanceProcAddr(VkInstance instance, const char *pName);
1399
1400 PUBLIC
1401 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
1402 vk_icdGetInstanceProcAddr(VkInstance instance, const char *pName)
1403 {
1404 return tu_GetInstanceProcAddr(instance, pName);
1405 }
1406
1407 PFN_vkVoidFunction
1408 tu_GetDeviceProcAddr(VkDevice _device, const char *pName)
1409 {
1410 TU_FROM_HANDLE(tu_device, device, _device);
1411
1412 return tu_lookup_entrypoint_checked(pName, device->instance->api_version,
1413 &device->instance->enabled_extensions,
1414 &device->enabled_extensions);
1415 }
1416
1417 static VkResult
1418 tu_alloc_memory(struct tu_device *device,
1419 const VkMemoryAllocateInfo *pAllocateInfo,
1420 const VkAllocationCallbacks *pAllocator,
1421 VkDeviceMemory *pMem)
1422 {
1423 struct tu_device_memory *mem;
1424 VkResult result;
1425
1426 assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
1427
1428 if (pAllocateInfo->allocationSize == 0) {
1429 /* Apparently, this is allowed */
1430 *pMem = VK_NULL_HANDLE;
1431 return VK_SUCCESS;
1432 }
1433
1434 mem = vk_object_alloc(&device->vk, pAllocator, sizeof(*mem),
1435 VK_OBJECT_TYPE_DEVICE_MEMORY);
1436 if (mem == NULL)
1437 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1438
1439 const VkImportMemoryFdInfoKHR *fd_info =
1440 vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
1441 if (fd_info && !fd_info->handleType)
1442 fd_info = NULL;
1443
1444 if (fd_info) {
1445 assert(fd_info->handleType ==
1446 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
1447 fd_info->handleType ==
1448 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
1449
1450 /*
1451 * TODO Importing the same fd twice gives us the same handle without
1452 * reference counting. We need to maintain a per-instance handle-to-bo
1453 * table and add reference count to tu_bo.
1454 */
1455 result = tu_bo_init_dmabuf(device, &mem->bo,
1456 pAllocateInfo->allocationSize, fd_info->fd);
1457 if (result == VK_SUCCESS) {
1458 /* take ownership and close the fd */
1459 close(fd_info->fd);
1460 }
1461 } else {
1462 result =
1463 tu_bo_init_new(device, &mem->bo, pAllocateInfo->allocationSize);
1464 }
1465
1466 if (result != VK_SUCCESS) {
1467 vk_object_free(&device->vk, pAllocator, mem);
1468 return result;
1469 }
1470
1471 mem->size = pAllocateInfo->allocationSize;
1472 mem->type_index = pAllocateInfo->memoryTypeIndex;
1473
1474 mem->map = NULL;
1475 mem->user_ptr = NULL;
1476
1477 *pMem = tu_device_memory_to_handle(mem);
1478
1479 return VK_SUCCESS;
1480 }
1481
1482 VkResult
1483 tu_AllocateMemory(VkDevice _device,
1484 const VkMemoryAllocateInfo *pAllocateInfo,
1485 const VkAllocationCallbacks *pAllocator,
1486 VkDeviceMemory *pMem)
1487 {
1488 TU_FROM_HANDLE(tu_device, device, _device);
1489 return tu_alloc_memory(device, pAllocateInfo, pAllocator, pMem);
1490 }
1491
1492 void
1493 tu_FreeMemory(VkDevice _device,
1494 VkDeviceMemory _mem,
1495 const VkAllocationCallbacks *pAllocator)
1496 {
1497 TU_FROM_HANDLE(tu_device, device, _device);
1498 TU_FROM_HANDLE(tu_device_memory, mem, _mem);
1499
1500 if (mem == NULL)
1501 return;
1502
1503 tu_bo_finish(device, &mem->bo);
1504 vk_object_free(&device->vk, pAllocator, mem);
1505 }
1506
1507 VkResult
1508 tu_MapMemory(VkDevice _device,
1509 VkDeviceMemory _memory,
1510 VkDeviceSize offset,
1511 VkDeviceSize size,
1512 VkMemoryMapFlags flags,
1513 void **ppData)
1514 {
1515 TU_FROM_HANDLE(tu_device, device, _device);
1516 TU_FROM_HANDLE(tu_device_memory, mem, _memory);
1517 VkResult result;
1518
1519 if (mem == NULL) {
1520 *ppData = NULL;
1521 return VK_SUCCESS;
1522 }
1523
1524 if (mem->user_ptr) {
1525 *ppData = mem->user_ptr;
1526 } else if (!mem->map) {
1527 result = tu_bo_map(device, &mem->bo);
1528 if (result != VK_SUCCESS)
1529 return result;
1530 *ppData = mem->map = mem->bo.map;
1531 } else
1532 *ppData = mem->map;
1533
1534 if (*ppData) {
1535 *ppData += offset;
1536 return VK_SUCCESS;
1537 }
1538
1539 return vk_error(device->instance, VK_ERROR_MEMORY_MAP_FAILED);
1540 }
1541
1542 void
1543 tu_UnmapMemory(VkDevice _device, VkDeviceMemory _memory)
1544 {
1545 /* I do not see any unmapping done by the freedreno Gallium driver. */
1546 }
1547
1548 VkResult
1549 tu_FlushMappedMemoryRanges(VkDevice _device,
1550 uint32_t memoryRangeCount,
1551 const VkMappedMemoryRange *pMemoryRanges)
1552 {
1553 return VK_SUCCESS;
1554 }
1555
1556 VkResult
1557 tu_InvalidateMappedMemoryRanges(VkDevice _device,
1558 uint32_t memoryRangeCount,
1559 const VkMappedMemoryRange *pMemoryRanges)
1560 {
1561 return VK_SUCCESS;
1562 }
1563
1564 void
1565 tu_GetBufferMemoryRequirements(VkDevice _device,
1566 VkBuffer _buffer,
1567 VkMemoryRequirements *pMemoryRequirements)
1568 {
1569 TU_FROM_HANDLE(tu_buffer, buffer, _buffer);
1570
1571 pMemoryRequirements->memoryTypeBits = 1;
1572 pMemoryRequirements->alignment = 64;
1573 pMemoryRequirements->size =
1574 align64(buffer->size, pMemoryRequirements->alignment);
1575 }
1576
1577 void
1578 tu_GetBufferMemoryRequirements2(
1579 VkDevice device,
1580 const VkBufferMemoryRequirementsInfo2 *pInfo,
1581 VkMemoryRequirements2 *pMemoryRequirements)
1582 {
1583 tu_GetBufferMemoryRequirements(device, pInfo->buffer,
1584 &pMemoryRequirements->memoryRequirements);
1585 }
1586
1587 void
1588 tu_GetImageMemoryRequirements(VkDevice _device,
1589 VkImage _image,
1590 VkMemoryRequirements *pMemoryRequirements)
1591 {
1592 TU_FROM_HANDLE(tu_image, image, _image);
1593
1594 pMemoryRequirements->memoryTypeBits = 1;
1595 pMemoryRequirements->size = image->total_size;
1596 pMemoryRequirements->alignment = image->layout[0].base_align;
1597 }
1598
1599 void
1600 tu_GetImageMemoryRequirements2(VkDevice device,
1601 const VkImageMemoryRequirementsInfo2 *pInfo,
1602 VkMemoryRequirements2 *pMemoryRequirements)
1603 {
1604 tu_GetImageMemoryRequirements(device, pInfo->image,
1605 &pMemoryRequirements->memoryRequirements);
1606 }
1607
1608 void
1609 tu_GetImageSparseMemoryRequirements(
1610 VkDevice device,
1611 VkImage image,
1612 uint32_t *pSparseMemoryRequirementCount,
1613 VkSparseImageMemoryRequirements *pSparseMemoryRequirements)
1614 {
1615 tu_stub();
1616 }
1617
1618 void
1619 tu_GetImageSparseMemoryRequirements2(
1620 VkDevice device,
1621 const VkImageSparseMemoryRequirementsInfo2 *pInfo,
1622 uint32_t *pSparseMemoryRequirementCount,
1623 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements)
1624 {
1625 tu_stub();
1626 }
1627
1628 void
1629 tu_GetDeviceMemoryCommitment(VkDevice device,
1630 VkDeviceMemory memory,
1631 VkDeviceSize *pCommittedMemoryInBytes)
1632 {
1633 *pCommittedMemoryInBytes = 0;
1634 }
1635
1636 VkResult
1637 tu_BindBufferMemory2(VkDevice device,
1638 uint32_t bindInfoCount,
1639 const VkBindBufferMemoryInfo *pBindInfos)
1640 {
1641 for (uint32_t i = 0; i < bindInfoCount; ++i) {
1642 TU_FROM_HANDLE(tu_device_memory, mem, pBindInfos[i].memory);
1643 TU_FROM_HANDLE(tu_buffer, buffer, pBindInfos[i].buffer);
1644
1645 if (mem) {
1646 buffer->bo = &mem->bo;
1647 buffer->bo_offset = pBindInfos[i].memoryOffset;
1648 } else {
1649 buffer->bo = NULL;
1650 }
1651 }
1652 return VK_SUCCESS;
1653 }
1654
1655 VkResult
1656 tu_BindBufferMemory(VkDevice device,
1657 VkBuffer buffer,
1658 VkDeviceMemory memory,
1659 VkDeviceSize memoryOffset)
1660 {
1661 const VkBindBufferMemoryInfo info = {
1662 .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO,
1663 .buffer = buffer,
1664 .memory = memory,
1665 .memoryOffset = memoryOffset
1666 };
1667
1668 return tu_BindBufferMemory2(device, 1, &info);
1669 }
1670
1671 VkResult
1672 tu_BindImageMemory2(VkDevice device,
1673 uint32_t bindInfoCount,
1674 const VkBindImageMemoryInfo *pBindInfos)
1675 {
1676 for (uint32_t i = 0; i < bindInfoCount; ++i) {
1677 TU_FROM_HANDLE(tu_image, image, pBindInfos[i].image);
1678 TU_FROM_HANDLE(tu_device_memory, mem, pBindInfos[i].memory);
1679
1680 if (mem) {
1681 image->bo = &mem->bo;
1682 image->bo_offset = pBindInfos[i].memoryOffset;
1683 } else {
1684 image->bo = NULL;
1685 image->bo_offset = 0;
1686 }
1687 }
1688
1689 return VK_SUCCESS;
1690 }
1691
1692 VkResult
1693 tu_BindImageMemory(VkDevice device,
1694 VkImage image,
1695 VkDeviceMemory memory,
1696 VkDeviceSize memoryOffset)
1697 {
1698 const VkBindImageMemoryInfo info = {
1699 .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO,
1700 .image = image,
1701 .memory = memory,
1702 .memoryOffset = memoryOffset
1703 };
1704
1705 return tu_BindImageMemory2(device, 1, &info);
1706 }
1707
1708 VkResult
1709 tu_QueueBindSparse(VkQueue _queue,
1710 uint32_t bindInfoCount,
1711 const VkBindSparseInfo *pBindInfo,
1712 VkFence _fence)
1713 {
1714 return VK_SUCCESS;
1715 }
1716
1717
1718 VkResult
1719 tu_CreateEvent(VkDevice _device,
1720 const VkEventCreateInfo *pCreateInfo,
1721 const VkAllocationCallbacks *pAllocator,
1722 VkEvent *pEvent)
1723 {
1724 TU_FROM_HANDLE(tu_device, device, _device);
1725
1726 struct tu_event *event =
1727 vk_object_alloc(&device->vk, pAllocator, sizeof(*event),
1728 VK_OBJECT_TYPE_EVENT);
1729 if (!event)
1730 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1731
1732 VkResult result = tu_bo_init_new(device, &event->bo, 0x1000);
1733 if (result != VK_SUCCESS)
1734 goto fail_alloc;
1735
1736 result = tu_bo_map(device, &event->bo);
1737 if (result != VK_SUCCESS)
1738 goto fail_map;
1739
1740 *pEvent = tu_event_to_handle(event);
1741
1742 return VK_SUCCESS;
1743
1744 fail_map:
1745 tu_bo_finish(device, &event->bo);
1746 fail_alloc:
1747 vk_object_free(&device->vk, pAllocator, event);
1748 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1749 }
1750
1751 void
1752 tu_DestroyEvent(VkDevice _device,
1753 VkEvent _event,
1754 const VkAllocationCallbacks *pAllocator)
1755 {
1756 TU_FROM_HANDLE(tu_device, device, _device);
1757 TU_FROM_HANDLE(tu_event, event, _event);
1758
1759 if (!event)
1760 return;
1761
1762 tu_bo_finish(device, &event->bo);
1763 vk_object_free(&device->vk, pAllocator, event);
1764 }
1765
1766 VkResult
1767 tu_GetEventStatus(VkDevice _device, VkEvent _event)
1768 {
1769 TU_FROM_HANDLE(tu_event, event, _event);
1770
1771 if (*(uint64_t*) event->bo.map == 1)
1772 return VK_EVENT_SET;
1773 return VK_EVENT_RESET;
1774 }
1775
1776 VkResult
1777 tu_SetEvent(VkDevice _device, VkEvent _event)
1778 {
1779 TU_FROM_HANDLE(tu_event, event, _event);
1780 *(uint64_t*) event->bo.map = 1;
1781
1782 return VK_SUCCESS;
1783 }
1784
1785 VkResult
1786 tu_ResetEvent(VkDevice _device, VkEvent _event)
1787 {
1788 TU_FROM_HANDLE(tu_event, event, _event);
1789 *(uint64_t*) event->bo.map = 0;
1790
1791 return VK_SUCCESS;
1792 }
1793
1794 VkResult
1795 tu_CreateBuffer(VkDevice _device,
1796 const VkBufferCreateInfo *pCreateInfo,
1797 const VkAllocationCallbacks *pAllocator,
1798 VkBuffer *pBuffer)
1799 {
1800 TU_FROM_HANDLE(tu_device, device, _device);
1801 struct tu_buffer *buffer;
1802
1803 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
1804
1805 buffer = vk_object_alloc(&device->vk, pAllocator, sizeof(*buffer),
1806 VK_OBJECT_TYPE_BUFFER);
1807 if (buffer == NULL)
1808 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1809
1810 buffer->size = pCreateInfo->size;
1811 buffer->usage = pCreateInfo->usage;
1812 buffer->flags = pCreateInfo->flags;
1813
1814 *pBuffer = tu_buffer_to_handle(buffer);
1815
1816 return VK_SUCCESS;
1817 }
1818
1819 void
1820 tu_DestroyBuffer(VkDevice _device,
1821 VkBuffer _buffer,
1822 const VkAllocationCallbacks *pAllocator)
1823 {
1824 TU_FROM_HANDLE(tu_device, device, _device);
1825 TU_FROM_HANDLE(tu_buffer, buffer, _buffer);
1826
1827 if (!buffer)
1828 return;
1829
1830 vk_object_free(&device->vk, pAllocator, buffer);
1831 }
1832
1833 VkResult
1834 tu_CreateFramebuffer(VkDevice _device,
1835 const VkFramebufferCreateInfo *pCreateInfo,
1836 const VkAllocationCallbacks *pAllocator,
1837 VkFramebuffer *pFramebuffer)
1838 {
1839 TU_FROM_HANDLE(tu_device, device, _device);
1840 TU_FROM_HANDLE(tu_render_pass, pass, pCreateInfo->renderPass);
1841 struct tu_framebuffer *framebuffer;
1842
1843 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
1844
1845 size_t size = sizeof(*framebuffer) + sizeof(struct tu_attachment_info) *
1846 pCreateInfo->attachmentCount;
1847 framebuffer = vk_object_alloc(&device->vk, pAllocator, size,
1848 VK_OBJECT_TYPE_FRAMEBUFFER);
1849 if (framebuffer == NULL)
1850 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1851
1852 framebuffer->attachment_count = pCreateInfo->attachmentCount;
1853 framebuffer->width = pCreateInfo->width;
1854 framebuffer->height = pCreateInfo->height;
1855 framebuffer->layers = pCreateInfo->layers;
1856 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
1857 VkImageView _iview = pCreateInfo->pAttachments[i];
1858 struct tu_image_view *iview = tu_image_view_from_handle(_iview);
1859 framebuffer->attachments[i].attachment = iview;
1860 }
1861
1862 tu_framebuffer_tiling_config(framebuffer, device, pass);
1863
1864 *pFramebuffer = tu_framebuffer_to_handle(framebuffer);
1865 return VK_SUCCESS;
1866 }
1867
1868 void
1869 tu_DestroyFramebuffer(VkDevice _device,
1870 VkFramebuffer _fb,
1871 const VkAllocationCallbacks *pAllocator)
1872 {
1873 TU_FROM_HANDLE(tu_device, device, _device);
1874 TU_FROM_HANDLE(tu_framebuffer, fb, _fb);
1875
1876 if (!fb)
1877 return;
1878
1879 vk_object_free(&device->vk, pAllocator, fb);
1880 }
1881
1882 static void
1883 tu_init_sampler(struct tu_device *device,
1884 struct tu_sampler *sampler,
1885 const VkSamplerCreateInfo *pCreateInfo)
1886 {
1887 const struct VkSamplerReductionModeCreateInfo *reduction =
1888 vk_find_struct_const(pCreateInfo->pNext, SAMPLER_REDUCTION_MODE_CREATE_INFO);
1889 const struct VkSamplerYcbcrConversionInfo *ycbcr_conversion =
1890 vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO);
1891 const VkSamplerCustomBorderColorCreateInfoEXT *custom_border_color =
1892 vk_find_struct_const(pCreateInfo->pNext, SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT);
1893 /* for non-custom border colors, the VK enum is translated directly to an offset in
1894 * the border color buffer. custom border colors are located immediately after the
1895 * builtin colors, and thus an offset of TU_BORDER_COLOR_BUILTIN is added.
1896 */
1897 uint32_t border_color = (unsigned) pCreateInfo->borderColor;
1898 if (pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT ||
1899 pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT) {
1900 mtx_lock(&device->mutex);
1901 border_color = BITSET_FFS(device->custom_border_color);
1902 BITSET_CLEAR(device->custom_border_color, border_color);
1903 mtx_unlock(&device->mutex);
1904 tu6_pack_border_color(device->global_bo.map + gb_offset(bcolor[border_color]),
1905 &custom_border_color->customBorderColor,
1906 pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT);
1907 border_color += TU_BORDER_COLOR_BUILTIN;
1908 }
1909
1910 unsigned aniso = pCreateInfo->anisotropyEnable ?
1911 util_last_bit(MIN2((uint32_t)pCreateInfo->maxAnisotropy >> 1, 8)) : 0;
1912 bool miplinear = (pCreateInfo->mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR);
1913 float min_lod = CLAMP(pCreateInfo->minLod, 0.0f, 4095.0f / 256.0f);
1914 float max_lod = CLAMP(pCreateInfo->maxLod, 0.0f, 4095.0f / 256.0f);
1915
1916 sampler->descriptor[0] =
1917 COND(miplinear, A6XX_TEX_SAMP_0_MIPFILTER_LINEAR_NEAR) |
1918 A6XX_TEX_SAMP_0_XY_MAG(tu6_tex_filter(pCreateInfo->magFilter, aniso)) |
1919 A6XX_TEX_SAMP_0_XY_MIN(tu6_tex_filter(pCreateInfo->minFilter, aniso)) |
1920 A6XX_TEX_SAMP_0_ANISO(aniso) |
1921 A6XX_TEX_SAMP_0_WRAP_S(tu6_tex_wrap(pCreateInfo->addressModeU)) |
1922 A6XX_TEX_SAMP_0_WRAP_T(tu6_tex_wrap(pCreateInfo->addressModeV)) |
1923 A6XX_TEX_SAMP_0_WRAP_R(tu6_tex_wrap(pCreateInfo->addressModeW)) |
1924 A6XX_TEX_SAMP_0_LOD_BIAS(pCreateInfo->mipLodBias);
1925 sampler->descriptor[1] =
1926 /* COND(!cso->seamless_cube_map, A6XX_TEX_SAMP_1_CUBEMAPSEAMLESSFILTOFF) | */
1927 COND(pCreateInfo->unnormalizedCoordinates, A6XX_TEX_SAMP_1_UNNORM_COORDS) |
1928 A6XX_TEX_SAMP_1_MIN_LOD(min_lod) |
1929 A6XX_TEX_SAMP_1_MAX_LOD(max_lod) |
1930 COND(pCreateInfo->compareEnable,
1931 A6XX_TEX_SAMP_1_COMPARE_FUNC(tu6_compare_func(pCreateInfo->compareOp)));
1932 sampler->descriptor[2] = A6XX_TEX_SAMP_2_BCOLOR(border_color);
1933 sampler->descriptor[3] = 0;
1934
1935 if (reduction) {
1936 sampler->descriptor[2] |= A6XX_TEX_SAMP_2_REDUCTION_MODE(
1937 tu6_reduction_mode(reduction->reductionMode));
1938 }
1939
1940 sampler->ycbcr_sampler = ycbcr_conversion ?
1941 tu_sampler_ycbcr_conversion_from_handle(ycbcr_conversion->conversion) : NULL;
1942
1943 if (sampler->ycbcr_sampler &&
1944 sampler->ycbcr_sampler->chroma_filter == VK_FILTER_LINEAR) {
1945 sampler->descriptor[2] |= A6XX_TEX_SAMP_2_CHROMA_LINEAR;
1946 }
1947
1948 /* TODO:
1949 * A6XX_TEX_SAMP_1_MIPFILTER_LINEAR_FAR disables mipmapping, but vk has no NONE mipfilter?
1950 */
1951 }
1952
1953 VkResult
1954 tu_CreateSampler(VkDevice _device,
1955 const VkSamplerCreateInfo *pCreateInfo,
1956 const VkAllocationCallbacks *pAllocator,
1957 VkSampler *pSampler)
1958 {
1959 TU_FROM_HANDLE(tu_device, device, _device);
1960 struct tu_sampler *sampler;
1961
1962 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
1963
1964 sampler = vk_object_alloc(&device->vk, pAllocator, sizeof(*sampler),
1965 VK_OBJECT_TYPE_SAMPLER);
1966 if (!sampler)
1967 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1968
1969 tu_init_sampler(device, sampler, pCreateInfo);
1970 *pSampler = tu_sampler_to_handle(sampler);
1971
1972 return VK_SUCCESS;
1973 }
1974
1975 void
1976 tu_DestroySampler(VkDevice _device,
1977 VkSampler _sampler,
1978 const VkAllocationCallbacks *pAllocator)
1979 {
1980 TU_FROM_HANDLE(tu_device, device, _device);
1981 TU_FROM_HANDLE(tu_sampler, sampler, _sampler);
1982 uint32_t border_color;
1983
1984 if (!sampler)
1985 return;
1986
1987 border_color = (sampler->descriptor[2] & A6XX_TEX_SAMP_2_BCOLOR__MASK) >> A6XX_TEX_SAMP_2_BCOLOR__SHIFT;
1988 if (border_color >= TU_BORDER_COLOR_BUILTIN) {
1989 border_color -= TU_BORDER_COLOR_BUILTIN;
1990 /* if the sampler had a custom border color, free it. TODO: no lock */
1991 mtx_lock(&device->mutex);
1992 assert(!BITSET_TEST(device->custom_border_color, border_color));
1993 BITSET_SET(device->custom_border_color, border_color);
1994 mtx_unlock(&device->mutex);
1995 }
1996
1997 vk_object_free(&device->vk, pAllocator, sampler);
1998 }
1999
2000 /* vk_icd.h does not declare this function, so we declare it here to
2001 * suppress Wmissing-prototypes.
2002 */
2003 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2004 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion);
2005
2006 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2007 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion)
2008 {
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.
2013 *
2014 * - Loader interface v0 is incompatible with later versions. We don't
2015 * support it.
2016 *
2017 * - In loader interface v1:
2018 * - The first ICD entrypoint called by the loader is
2019 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2020 * entrypoint.
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
2026 * ICD_LOADER_MAGIC.
2027 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2028 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2029 * such loader-managed surfaces.
2030 *
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.
2035 *
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.
2040 */
2041 *pSupportedVersion = MIN2(*pSupportedVersion, 3u);
2042 return VK_SUCCESS;
2043 }
2044
2045 VkResult
2046 tu_GetMemoryFdKHR(VkDevice _device,
2047 const VkMemoryGetFdInfoKHR *pGetFdInfo,
2048 int *pFd)
2049 {
2050 TU_FROM_HANDLE(tu_device, device, _device);
2051 TU_FROM_HANDLE(tu_device_memory, memory, pGetFdInfo->memory);
2052
2053 assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
2054
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);
2060
2061 int prime_fd = tu_bo_export_dmabuf(device, &memory->bo);
2062 if (prime_fd < 0)
2063 return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
2064
2065 *pFd = prime_fd;
2066 return VK_SUCCESS;
2067 }
2068
2069 VkResult
2070 tu_GetMemoryFdPropertiesKHR(VkDevice _device,
2071 VkExternalMemoryHandleTypeFlagBits handleType,
2072 int fd,
2073 VkMemoryFdPropertiesKHR *pMemoryFdProperties)
2074 {
2075 assert(handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
2076 pMemoryFdProperties->memoryTypeBits = 1;
2077 return VK_SUCCESS;
2078 }
2079
2080 VkResult
2081 tu_ImportFenceFdKHR(VkDevice _device,
2082 const VkImportFenceFdInfoKHR *pImportFenceFdInfo)
2083 {
2084 tu_stub();
2085
2086 return VK_SUCCESS;
2087 }
2088
2089 VkResult
2090 tu_GetFenceFdKHR(VkDevice _device,
2091 const VkFenceGetFdInfoKHR *pGetFdInfo,
2092 int *pFd)
2093 {
2094 tu_stub();
2095
2096 return VK_SUCCESS;
2097 }
2098
2099 void
2100 tu_GetPhysicalDeviceExternalFenceProperties(
2101 VkPhysicalDevice physicalDevice,
2102 const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo,
2103 VkExternalFenceProperties *pExternalFenceProperties)
2104 {
2105 pExternalFenceProperties->exportFromImportedHandleTypes = 0;
2106 pExternalFenceProperties->compatibleHandleTypes = 0;
2107 pExternalFenceProperties->externalFenceFeatures = 0;
2108 }
2109
2110 VkResult
2111 tu_CreateDebugReportCallbackEXT(
2112 VkInstance _instance,
2113 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
2114 const VkAllocationCallbacks *pAllocator,
2115 VkDebugReportCallbackEXT *pCallback)
2116 {
2117 TU_FROM_HANDLE(tu_instance, instance, _instance);
2118 return vk_create_debug_report_callback(&instance->debug_report_callbacks,
2119 pCreateInfo, pAllocator,
2120 &instance->alloc, pCallback);
2121 }
2122
2123 void
2124 tu_DestroyDebugReportCallbackEXT(VkInstance _instance,
2125 VkDebugReportCallbackEXT _callback,
2126 const VkAllocationCallbacks *pAllocator)
2127 {
2128 TU_FROM_HANDLE(tu_instance, instance, _instance);
2129 vk_destroy_debug_report_callback(&instance->debug_report_callbacks,
2130 _callback, pAllocator, &instance->alloc);
2131 }
2132
2133 void
2134 tu_DebugReportMessageEXT(VkInstance _instance,
2135 VkDebugReportFlagsEXT flags,
2136 VkDebugReportObjectTypeEXT objectType,
2137 uint64_t object,
2138 size_t location,
2139 int32_t messageCode,
2140 const char *pLayerPrefix,
2141 const char *pMessage)
2142 {
2143 TU_FROM_HANDLE(tu_instance, instance, _instance);
2144 vk_debug_report(&instance->debug_report_callbacks, flags, objectType,
2145 object, location, messageCode, pLayerPrefix, pMessage);
2146 }
2147
2148 void
2149 tu_GetDeviceGroupPeerMemoryFeatures(
2150 VkDevice device,
2151 uint32_t heapIndex,
2152 uint32_t localDeviceIndex,
2153 uint32_t remoteDeviceIndex,
2154 VkPeerMemoryFeatureFlags *pPeerMemoryFeatures)
2155 {
2156 assert(localDeviceIndex == remoteDeviceIndex);
2157
2158 *pPeerMemoryFeatures = VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT |
2159 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT |
2160 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT |
2161 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT;
2162 }
2163
2164 void tu_GetPhysicalDeviceMultisamplePropertiesEXT(
2165 VkPhysicalDevice physicalDevice,
2166 VkSampleCountFlagBits samples,
2167 VkMultisamplePropertiesEXT* pMultisampleProperties)
2168 {
2169 TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
2170
2171 if (samples <= VK_SAMPLE_COUNT_4_BIT && pdevice->supported_extensions.EXT_sample_locations)
2172 pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){ 1, 1 };
2173 else
2174 pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){ 0, 0 };
2175 }
2176
2177
2178 VkResult
2179 tu_CreatePrivateDataSlotEXT(VkDevice _device,
2180 const VkPrivateDataSlotCreateInfoEXT* pCreateInfo,
2181 const VkAllocationCallbacks* pAllocator,
2182 VkPrivateDataSlotEXT* pPrivateDataSlot)
2183 {
2184 TU_FROM_HANDLE(tu_device, device, _device);
2185 return vk_private_data_slot_create(&device->vk,
2186 pCreateInfo,
2187 pAllocator,
2188 pPrivateDataSlot);
2189 }
2190
2191 void
2192 tu_DestroyPrivateDataSlotEXT(VkDevice _device,
2193 VkPrivateDataSlotEXT privateDataSlot,
2194 const VkAllocationCallbacks* pAllocator)
2195 {
2196 TU_FROM_HANDLE(tu_device, device, _device);
2197 vk_private_data_slot_destroy(&device->vk, privateDataSlot, pAllocator);
2198 }
2199
2200 VkResult
2201 tu_SetPrivateDataEXT(VkDevice _device,
2202 VkObjectType objectType,
2203 uint64_t objectHandle,
2204 VkPrivateDataSlotEXT privateDataSlot,
2205 uint64_t data)
2206 {
2207 TU_FROM_HANDLE(tu_device, device, _device);
2208 return vk_object_base_set_private_data(&device->vk,
2209 objectType,
2210 objectHandle,
2211 privateDataSlot,
2212 data);
2213 }
2214
2215 void
2216 tu_GetPrivateDataEXT(VkDevice _device,
2217 VkObjectType objectType,
2218 uint64_t objectHandle,
2219 VkPrivateDataSlotEXT privateDataSlot,
2220 uint64_t* pData)
2221 {
2222 TU_FROM_HANDLE(tu_device, device, _device);
2223 vk_object_base_get_private_data(&device->vk,
2224 objectType,
2225 objectHandle,
2226 privateDataSlot,
2227 pData);
2228 }