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