2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
53 uint32_t mesa_timestamp, llvm_timestamp;
55 memset(uuid, 0, VK_UUID_SIZE);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid, &mesa_timestamp) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo, &llvm_timestamp))
60 memcpy(uuid, &mesa_timestamp, 4);
61 memcpy((char*)uuid + 4, &llvm_timestamp, 4);
62 memcpy((char*)uuid + 8, &f, 2);
63 snprintf((char*)uuid + 10, VK_UUID_SIZE - 10, "radv");
68 radv_get_driver_uuid(void *uuid)
70 ac_compute_driver_uuid(uuid, VK_UUID_SIZE);
74 radv_get_device_uuid(struct radeon_info *info, void *uuid)
76 ac_compute_device_uuid(info, uuid, VK_UUID_SIZE);
80 radv_get_device_name(enum radeon_family family, char *name, size_t name_len)
82 const char *chip_string;
83 char llvm_string[32] = {};
86 case CHIP_TAHITI: chip_string = "AMD RADV TAHITI"; break;
87 case CHIP_PITCAIRN: chip_string = "AMD RADV PITCAIRN"; break;
88 case CHIP_VERDE: chip_string = "AMD RADV CAPE VERDE"; break;
89 case CHIP_OLAND: chip_string = "AMD RADV OLAND"; break;
90 case CHIP_HAINAN: chip_string = "AMD RADV HAINAN"; break;
91 case CHIP_BONAIRE: chip_string = "AMD RADV BONAIRE"; break;
92 case CHIP_KAVERI: chip_string = "AMD RADV KAVERI"; break;
93 case CHIP_KABINI: chip_string = "AMD RADV KABINI"; break;
94 case CHIP_HAWAII: chip_string = "AMD RADV HAWAII"; break;
95 case CHIP_MULLINS: chip_string = "AMD RADV MULLINS"; break;
96 case CHIP_TONGA: chip_string = "AMD RADV TONGA"; break;
97 case CHIP_ICELAND: chip_string = "AMD RADV ICELAND"; break;
98 case CHIP_CARRIZO: chip_string = "AMD RADV CARRIZO"; break;
99 case CHIP_FIJI: chip_string = "AMD RADV FIJI"; break;
100 case CHIP_POLARIS10: chip_string = "AMD RADV POLARIS10"; break;
101 case CHIP_POLARIS11: chip_string = "AMD RADV POLARIS11"; break;
102 case CHIP_POLARIS12: chip_string = "AMD RADV POLARIS12"; break;
103 case CHIP_STONEY: chip_string = "AMD RADV STONEY"; break;
104 case CHIP_VEGA10: chip_string = "AMD RADV VEGA10"; break;
105 case CHIP_VEGA12: chip_string = "AMD RADV VEGA12"; break;
106 case CHIP_RAVEN: chip_string = "AMD RADV RAVEN"; break;
107 default: chip_string = "AMD RADV unknown"; break;
111 snprintf(llvm_string, sizeof(llvm_string),
112 " (LLVM %i.%i.%i)", (HAVE_LLVM >> 8) & 0xff,
113 HAVE_LLVM & 0xff, MESA_LLVM_VERSION_PATCH);
116 snprintf(name, name_len, "%s%s", chip_string, llvm_string);
120 radv_physical_device_init_mem_types(struct radv_physical_device *device)
122 STATIC_ASSERT(RADV_MEM_HEAP_COUNT <= VK_MAX_MEMORY_HEAPS);
123 uint64_t visible_vram_size = MIN2(device->rad_info.vram_size,
124 device->rad_info.vram_vis_size);
126 int vram_index = -1, visible_vram_index = -1, gart_index = -1;
127 device->memory_properties.memoryHeapCount = 0;
128 if (device->rad_info.vram_size - visible_vram_size > 0) {
129 vram_index = device->memory_properties.memoryHeapCount++;
130 device->memory_properties.memoryHeaps[vram_index] = (VkMemoryHeap) {
131 .size = device->rad_info.vram_size - visible_vram_size,
132 .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
135 if (visible_vram_size) {
136 visible_vram_index = device->memory_properties.memoryHeapCount++;
137 device->memory_properties.memoryHeaps[visible_vram_index] = (VkMemoryHeap) {
138 .size = visible_vram_size,
139 .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
142 if (device->rad_info.gart_size > 0) {
143 gart_index = device->memory_properties.memoryHeapCount++;
144 device->memory_properties.memoryHeaps[gart_index] = (VkMemoryHeap) {
145 .size = device->rad_info.gart_size,
150 STATIC_ASSERT(RADV_MEM_TYPE_COUNT <= VK_MAX_MEMORY_TYPES);
151 unsigned type_count = 0;
152 if (vram_index >= 0) {
153 device->mem_type_indices[type_count] = RADV_MEM_TYPE_VRAM;
154 device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
155 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
156 .heapIndex = vram_index,
159 if (gart_index >= 0) {
160 device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_WRITE_COMBINE;
161 device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
162 .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
163 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
164 .heapIndex = gart_index,
167 if (visible_vram_index >= 0) {
168 device->mem_type_indices[type_count] = RADV_MEM_TYPE_VRAM_CPU_ACCESS;
169 device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
170 .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
171 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
172 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
173 .heapIndex = visible_vram_index,
176 if (gart_index >= 0) {
177 device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_CACHED;
178 device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
179 .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
181 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
182 .heapIndex = gart_index,
185 device->memory_properties.memoryTypeCount = type_count;
189 radv_handle_env_var_force_family(struct radv_physical_device *device)
191 const char *family = getenv("RADV_FORCE_FAMILY");
197 for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
198 if (!strcmp(family, ac_get_llvm_processor_name(i))) {
199 /* Override family and chip_class. */
200 device->rad_info.family = i;
202 if (i >= CHIP_VEGA10)
203 device->rad_info.chip_class = GFX9;
204 else if (i >= CHIP_TONGA)
205 device->rad_info.chip_class = VI;
206 else if (i >= CHIP_BONAIRE)
207 device->rad_info.chip_class = CIK;
209 device->rad_info.chip_class = SI;
215 fprintf(stderr, "radv: Unknown family: %s\n", family);
220 radv_physical_device_init(struct radv_physical_device *device,
221 struct radv_instance *instance,
222 drmDevicePtr drm_device)
224 const char *path = drm_device->nodes[DRM_NODE_RENDER];
226 drmVersionPtr version;
229 fd = open(path, O_RDWR | O_CLOEXEC);
231 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
233 version = drmGetVersion(fd);
236 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
237 "failed to get version %s: %m", path);
240 if (strcmp(version->name, "amdgpu")) {
241 drmFreeVersion(version);
243 return VK_ERROR_INCOMPATIBLE_DRIVER;
245 drmFreeVersion(version);
247 device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
248 device->instance = instance;
249 assert(strlen(path) < ARRAY_SIZE(device->path));
250 strncpy(device->path, path, ARRAY_SIZE(device->path));
252 device->ws = radv_amdgpu_winsys_create(fd, instance->debug_flags,
253 instance->perftest_flags);
255 result = VK_ERROR_INCOMPATIBLE_DRIVER;
259 device->local_fd = fd;
260 device->ws->query_info(device->ws, &device->rad_info);
262 radv_handle_env_var_force_family(device);
264 radv_get_device_name(device->rad_info.family, device->name, sizeof(device->name));
266 if (radv_device_get_cache_uuid(device->rad_info.family, device->cache_uuid)) {
267 device->ws->destroy(device->ws);
268 result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
269 "cannot generate UUID");
273 /* These flags affect shader compilation. */
274 uint64_t shader_env_flags =
275 (device->instance->perftest_flags & RADV_PERFTEST_SISCHED ? 0x1 : 0) |
276 (device->instance->debug_flags & RADV_DEBUG_UNSAFE_MATH ? 0x2 : 0);
278 /* The gpu id is already embeded in the uuid so we just pass "radv"
279 * when creating the cache.
281 char buf[VK_UUID_SIZE * 2 + 1];
282 disk_cache_format_hex_id(buf, device->cache_uuid, VK_UUID_SIZE * 2);
283 device->disk_cache = disk_cache_create(device->name, buf, shader_env_flags);
285 if (device->rad_info.chip_class < VI ||
286 device->rad_info.chip_class > GFX9)
287 fprintf(stderr, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
289 radv_get_driver_uuid(&device->device_uuid);
290 radv_get_device_uuid(&device->rad_info, &device->device_uuid);
292 if (device->rad_info.family == CHIP_STONEY ||
293 device->rad_info.chip_class >= GFX9) {
294 device->has_rbplus = true;
295 device->rbplus_allowed = device->rad_info.family == CHIP_STONEY ||
296 device->rad_info.family == CHIP_VEGA12;
299 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
302 device->has_clear_state = device->rad_info.chip_class >= CIK;
304 device->cpdma_prefetch_writes_memory = device->rad_info.chip_class <= VI;
306 /* Vega10/Raven need a special workaround for a hardware bug. */
307 device->has_scissor_bug = device->rad_info.family == CHIP_VEGA10 ||
308 device->rad_info.family == CHIP_RAVEN;
310 /* Out-of-order primitive rasterization. */
311 device->has_out_of_order_rast = device->rad_info.chip_class >= VI &&
312 device->rad_info.max_se >= 2;
313 device->out_of_order_rast_allowed = device->has_out_of_order_rast &&
314 (device->instance->perftest_flags & RADV_PERFTEST_OUT_OF_ORDER);
316 radv_physical_device_init_mem_types(device);
317 radv_fill_device_extension_table(device, &device->supported_extensions);
319 result = radv_init_wsi(device);
320 if (result != VK_SUCCESS) {
321 device->ws->destroy(device->ws);
333 radv_physical_device_finish(struct radv_physical_device *device)
335 radv_finish_wsi(device);
336 device->ws->destroy(device->ws);
337 disk_cache_destroy(device->disk_cache);
338 close(device->local_fd);
342 default_alloc_func(void *pUserData, size_t size, size_t align,
343 VkSystemAllocationScope allocationScope)
349 default_realloc_func(void *pUserData, void *pOriginal, size_t size,
350 size_t align, VkSystemAllocationScope allocationScope)
352 return realloc(pOriginal, size);
356 default_free_func(void *pUserData, void *pMemory)
361 static const VkAllocationCallbacks default_alloc = {
363 .pfnAllocation = default_alloc_func,
364 .pfnReallocation = default_realloc_func,
365 .pfnFree = default_free_func,
368 static const struct debug_control radv_debug_options[] = {
369 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS},
370 {"nodcc", RADV_DEBUG_NO_DCC},
371 {"shaders", RADV_DEBUG_DUMP_SHADERS},
372 {"nocache", RADV_DEBUG_NO_CACHE},
373 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS},
374 {"nohiz", RADV_DEBUG_NO_HIZ},
375 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE},
376 {"unsafemath", RADV_DEBUG_UNSAFE_MATH},
377 {"allbos", RADV_DEBUG_ALL_BOS},
378 {"noibs", RADV_DEBUG_NO_IBS},
379 {"spirv", RADV_DEBUG_DUMP_SPIRV},
380 {"vmfaults", RADV_DEBUG_VM_FAULTS},
381 {"zerovram", RADV_DEBUG_ZERO_VRAM},
382 {"syncshaders", RADV_DEBUG_SYNC_SHADERS},
383 {"nosisched", RADV_DEBUG_NO_SISCHED},
384 {"preoptir", RADV_DEBUG_PREOPTIR},
389 radv_get_debug_option_name(int id)
391 assert(id < ARRAY_SIZE(radv_debug_options) - 1);
392 return radv_debug_options[id].string;
395 static const struct debug_control radv_perftest_options[] = {
396 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN},
397 {"sisched", RADV_PERFTEST_SISCHED},
398 {"localbos", RADV_PERFTEST_LOCAL_BOS},
399 {"binning", RADV_PERFTEST_BINNING},
400 {"outoforderrast", RADV_PERFTEST_OUT_OF_ORDER},
405 radv_get_perftest_option_name(int id)
407 assert(id < ARRAY_SIZE(radv_debug_options) - 1);
408 return radv_perftest_options[id].string;
412 radv_handle_per_app_options(struct radv_instance *instance,
413 const VkApplicationInfo *info)
415 const char *name = info ? info->pApplicationName : NULL;
420 if (!strcmp(name, "Talos - Linux - 32bit") ||
421 !strcmp(name, "Talos - Linux - 64bit")) {
422 /* Force enable LLVM sisched for Talos because it looks safe
423 * and it gives few more FPS.
425 instance->perftest_flags |= RADV_PERFTEST_SISCHED;
429 static int radv_get_instance_extension_index(const char *name)
431 for (unsigned i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; ++i) {
432 if (strcmp(name, radv_instance_extensions[i].extensionName) == 0)
439 VkResult radv_CreateInstance(
440 const VkInstanceCreateInfo* pCreateInfo,
441 const VkAllocationCallbacks* pAllocator,
442 VkInstance* pInstance)
444 struct radv_instance *instance;
447 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
449 uint32_t client_version;
450 if (pCreateInfo->pApplicationInfo &&
451 pCreateInfo->pApplicationInfo->apiVersion != 0) {
452 client_version = pCreateInfo->pApplicationInfo->apiVersion;
454 client_version = VK_MAKE_VERSION(1, 0, 0);
457 if (VK_MAKE_VERSION(1, 0, 0) > client_version ||
458 client_version > VK_MAKE_VERSION(1, 1, 0xfff)) {
459 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
460 "Client requested version %d.%d.%d",
461 VK_VERSION_MAJOR(client_version),
462 VK_VERSION_MINOR(client_version),
463 VK_VERSION_PATCH(client_version));
466 instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
467 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
469 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
471 instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
474 instance->alloc = *pAllocator;
476 instance->alloc = default_alloc;
478 instance->apiVersion = client_version;
479 instance->physicalDeviceCount = -1;
481 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
482 const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
483 int index = radv_get_instance_extension_index(ext_name);
485 if (index < 0 || !radv_supported_instance_extensions.extensions[index]) {
486 vk_free2(&default_alloc, pAllocator, instance);
487 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
490 instance->enabled_extensions.extensions[index] = true;
493 result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
494 if (result != VK_SUCCESS) {
495 vk_free2(&default_alloc, pAllocator, instance);
496 return vk_error(result);
501 VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
503 instance->debug_flags = parse_debug_string(getenv("RADV_DEBUG"),
506 instance->perftest_flags = parse_debug_string(getenv("RADV_PERFTEST"),
507 radv_perftest_options);
509 radv_handle_per_app_options(instance, pCreateInfo->pApplicationInfo);
511 if (instance->debug_flags & RADV_DEBUG_NO_SISCHED) {
512 /* Disable sisched when the user requests it, this is mostly
513 * useful when the driver force-enable sisched for the given
516 instance->perftest_flags &= ~RADV_PERFTEST_SISCHED;
519 *pInstance = radv_instance_to_handle(instance);
524 void radv_DestroyInstance(
525 VkInstance _instance,
526 const VkAllocationCallbacks* pAllocator)
528 RADV_FROM_HANDLE(radv_instance, instance, _instance);
533 for (int i = 0; i < instance->physicalDeviceCount; ++i) {
534 radv_physical_device_finish(instance->physicalDevices + i);
537 VG(VALGRIND_DESTROY_MEMPOOL(instance));
541 vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
543 vk_free(&instance->alloc, instance);
547 radv_enumerate_devices(struct radv_instance *instance)
549 /* TODO: Check for more devices ? */
550 drmDevicePtr devices[8];
551 VkResult result = VK_ERROR_INCOMPATIBLE_DRIVER;
554 instance->physicalDeviceCount = 0;
556 max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
558 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
560 for (unsigned i = 0; i < (unsigned)max_devices; i++) {
561 if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
562 devices[i]->bustype == DRM_BUS_PCI &&
563 devices[i]->deviceinfo.pci->vendor_id == ATI_VENDOR_ID) {
565 result = radv_physical_device_init(instance->physicalDevices +
566 instance->physicalDeviceCount,
569 if (result == VK_SUCCESS)
570 ++instance->physicalDeviceCount;
571 else if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
575 drmFreeDevices(devices, max_devices);
580 VkResult radv_EnumeratePhysicalDevices(
581 VkInstance _instance,
582 uint32_t* pPhysicalDeviceCount,
583 VkPhysicalDevice* pPhysicalDevices)
585 RADV_FROM_HANDLE(radv_instance, instance, _instance);
588 if (instance->physicalDeviceCount < 0) {
589 result = radv_enumerate_devices(instance);
590 if (result != VK_SUCCESS &&
591 result != VK_ERROR_INCOMPATIBLE_DRIVER)
595 if (!pPhysicalDevices) {
596 *pPhysicalDeviceCount = instance->physicalDeviceCount;
598 *pPhysicalDeviceCount = MIN2(*pPhysicalDeviceCount, instance->physicalDeviceCount);
599 for (unsigned i = 0; i < *pPhysicalDeviceCount; ++i)
600 pPhysicalDevices[i] = radv_physical_device_to_handle(instance->physicalDevices + i);
603 return *pPhysicalDeviceCount < instance->physicalDeviceCount ? VK_INCOMPLETE
607 VkResult radv_EnumeratePhysicalDeviceGroups(
608 VkInstance _instance,
609 uint32_t* pPhysicalDeviceGroupCount,
610 VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties)
612 RADV_FROM_HANDLE(radv_instance, instance, _instance);
615 if (instance->physicalDeviceCount < 0) {
616 result = radv_enumerate_devices(instance);
617 if (result != VK_SUCCESS &&
618 result != VK_ERROR_INCOMPATIBLE_DRIVER)
622 if (!pPhysicalDeviceGroupProperties) {
623 *pPhysicalDeviceGroupCount = instance->physicalDeviceCount;
625 *pPhysicalDeviceGroupCount = MIN2(*pPhysicalDeviceGroupCount, instance->physicalDeviceCount);
626 for (unsigned i = 0; i < *pPhysicalDeviceGroupCount; ++i) {
627 pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1;
628 pPhysicalDeviceGroupProperties[i].physicalDevices[0] = radv_physical_device_to_handle(instance->physicalDevices + i);
629 pPhysicalDeviceGroupProperties[i].subsetAllocation = false;
632 return *pPhysicalDeviceGroupCount < instance->physicalDeviceCount ? VK_INCOMPLETE
636 void radv_GetPhysicalDeviceFeatures(
637 VkPhysicalDevice physicalDevice,
638 VkPhysicalDeviceFeatures* pFeatures)
640 memset(pFeatures, 0, sizeof(*pFeatures));
642 *pFeatures = (VkPhysicalDeviceFeatures) {
643 .robustBufferAccess = true,
644 .fullDrawIndexUint32 = true,
645 .imageCubeArray = true,
646 .independentBlend = true,
647 .geometryShader = true,
648 .tessellationShader = true,
649 .sampleRateShading = true,
650 .dualSrcBlend = true,
652 .multiDrawIndirect = true,
653 .drawIndirectFirstInstance = true,
655 .depthBiasClamp = true,
656 .fillModeNonSolid = true,
661 .multiViewport = true,
662 .samplerAnisotropy = true,
663 .textureCompressionETC2 = false,
664 .textureCompressionASTC_LDR = false,
665 .textureCompressionBC = true,
666 .occlusionQueryPrecise = true,
667 .pipelineStatisticsQuery = true,
668 .vertexPipelineStoresAndAtomics = true,
669 .fragmentStoresAndAtomics = true,
670 .shaderTessellationAndGeometryPointSize = true,
671 .shaderImageGatherExtended = true,
672 .shaderStorageImageExtendedFormats = true,
673 .shaderStorageImageMultisample = false,
674 .shaderUniformBufferArrayDynamicIndexing = true,
675 .shaderSampledImageArrayDynamicIndexing = true,
676 .shaderStorageBufferArrayDynamicIndexing = true,
677 .shaderStorageImageArrayDynamicIndexing = true,
678 .shaderStorageImageReadWithoutFormat = true,
679 .shaderStorageImageWriteWithoutFormat = true,
680 .shaderClipDistance = true,
681 .shaderCullDistance = true,
682 .shaderFloat64 = true,
684 .shaderInt16 = false,
685 .sparseBinding = true,
686 .variableMultisampleRate = true,
687 .inheritedQueries = true,
691 void radv_GetPhysicalDeviceFeatures2(
692 VkPhysicalDevice physicalDevice,
693 VkPhysicalDeviceFeatures2KHR *pFeatures)
695 vk_foreach_struct(ext, pFeatures->pNext) {
696 switch (ext->sType) {
697 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR: {
698 VkPhysicalDeviceVariablePointerFeaturesKHR *features = (void *)ext;
699 features->variablePointersStorageBuffer = true;
700 features->variablePointers = false;
703 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR: {
704 VkPhysicalDeviceMultiviewFeaturesKHR *features = (VkPhysicalDeviceMultiviewFeaturesKHR*)ext;
705 features->multiview = true;
706 features->multiviewGeometryShader = true;
707 features->multiviewTessellationShader = true;
710 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES: {
711 VkPhysicalDeviceShaderDrawParameterFeatures *features =
712 (VkPhysicalDeviceShaderDrawParameterFeatures*)ext;
713 features->shaderDrawParameters = true;
716 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
717 VkPhysicalDeviceProtectedMemoryFeatures *features =
718 (VkPhysicalDeviceProtectedMemoryFeatures*)ext;
719 features->protectedMemory = false;
722 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
723 VkPhysicalDevice16BitStorageFeatures *features =
724 (VkPhysicalDevice16BitStorageFeatures*)ext;
725 features->storageBuffer16BitAccess = false;
726 features->uniformAndStorageBuffer16BitAccess = false;
727 features->storagePushConstant16 = false;
728 features->storageInputOutput16 = false;
731 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
732 VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
733 (VkPhysicalDeviceSamplerYcbcrConversionFeatures*)ext;
734 features->samplerYcbcrConversion = false;
741 return radv_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
744 void radv_GetPhysicalDeviceProperties(
745 VkPhysicalDevice physicalDevice,
746 VkPhysicalDeviceProperties* pProperties)
748 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
749 VkSampleCountFlags sample_counts = 0xf;
751 /* make sure that the entire descriptor set is addressable with a signed
752 * 32-bit int. So the sum of all limits scaled by descriptor size has to
753 * be at most 2 GiB. the combined image & samples object count as one of
754 * both. This limit is for the pipeline layout, not for the set layout, but
755 * there is no set limit, so we just set a pipeline limit. I don't think
756 * any app is going to hit this soon. */
757 size_t max_descriptor_set_size = ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS) /
758 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
759 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
760 32 /* sampler, largest when combined with image */ +
761 64 /* sampled image */ +
762 64 /* storage image */);
764 VkPhysicalDeviceLimits limits = {
765 .maxImageDimension1D = (1 << 14),
766 .maxImageDimension2D = (1 << 14),
767 .maxImageDimension3D = (1 << 11),
768 .maxImageDimensionCube = (1 << 14),
769 .maxImageArrayLayers = (1 << 11),
770 .maxTexelBufferElements = 128 * 1024 * 1024,
771 .maxUniformBufferRange = UINT32_MAX,
772 .maxStorageBufferRange = UINT32_MAX,
773 .maxPushConstantsSize = MAX_PUSH_CONSTANTS_SIZE,
774 .maxMemoryAllocationCount = UINT32_MAX,
775 .maxSamplerAllocationCount = 64 * 1024,
776 .bufferImageGranularity = 64, /* A cache line */
777 .sparseAddressSpaceSize = 0xffffffffu, /* buffer max size */
778 .maxBoundDescriptorSets = MAX_SETS,
779 .maxPerStageDescriptorSamplers = max_descriptor_set_size,
780 .maxPerStageDescriptorUniformBuffers = max_descriptor_set_size,
781 .maxPerStageDescriptorStorageBuffers = max_descriptor_set_size,
782 .maxPerStageDescriptorSampledImages = max_descriptor_set_size,
783 .maxPerStageDescriptorStorageImages = max_descriptor_set_size,
784 .maxPerStageDescriptorInputAttachments = max_descriptor_set_size,
785 .maxPerStageResources = max_descriptor_set_size,
786 .maxDescriptorSetSamplers = max_descriptor_set_size,
787 .maxDescriptorSetUniformBuffers = max_descriptor_set_size,
788 .maxDescriptorSetUniformBuffersDynamic = MAX_DYNAMIC_UNIFORM_BUFFERS,
789 .maxDescriptorSetStorageBuffers = max_descriptor_set_size,
790 .maxDescriptorSetStorageBuffersDynamic = MAX_DYNAMIC_STORAGE_BUFFERS,
791 .maxDescriptorSetSampledImages = max_descriptor_set_size,
792 .maxDescriptorSetStorageImages = max_descriptor_set_size,
793 .maxDescriptorSetInputAttachments = max_descriptor_set_size,
794 .maxVertexInputAttributes = 32,
795 .maxVertexInputBindings = 32,
796 .maxVertexInputAttributeOffset = 2047,
797 .maxVertexInputBindingStride = 2048,
798 .maxVertexOutputComponents = 128,
799 .maxTessellationGenerationLevel = 64,
800 .maxTessellationPatchSize = 32,
801 .maxTessellationControlPerVertexInputComponents = 128,
802 .maxTessellationControlPerVertexOutputComponents = 128,
803 .maxTessellationControlPerPatchOutputComponents = 120,
804 .maxTessellationControlTotalOutputComponents = 4096,
805 .maxTessellationEvaluationInputComponents = 128,
806 .maxTessellationEvaluationOutputComponents = 128,
807 .maxGeometryShaderInvocations = 127,
808 .maxGeometryInputComponents = 64,
809 .maxGeometryOutputComponents = 128,
810 .maxGeometryOutputVertices = 256,
811 .maxGeometryTotalOutputComponents = 1024,
812 .maxFragmentInputComponents = 128,
813 .maxFragmentOutputAttachments = 8,
814 .maxFragmentDualSrcAttachments = 1,
815 .maxFragmentCombinedOutputResources = 8,
816 .maxComputeSharedMemorySize = 32768,
817 .maxComputeWorkGroupCount = { 65535, 65535, 65535 },
818 .maxComputeWorkGroupInvocations = 2048,
819 .maxComputeWorkGroupSize = {
824 .subPixelPrecisionBits = 4 /* FIXME */,
825 .subTexelPrecisionBits = 4 /* FIXME */,
826 .mipmapPrecisionBits = 4 /* FIXME */,
827 .maxDrawIndexedIndexValue = UINT32_MAX,
828 .maxDrawIndirectCount = UINT32_MAX,
829 .maxSamplerLodBias = 16,
830 .maxSamplerAnisotropy = 16,
831 .maxViewports = MAX_VIEWPORTS,
832 .maxViewportDimensions = { (1 << 14), (1 << 14) },
833 .viewportBoundsRange = { INT16_MIN, INT16_MAX },
834 .viewportSubPixelBits = 13, /* We take a float? */
835 .minMemoryMapAlignment = 4096, /* A page */
836 .minTexelBufferOffsetAlignment = 1,
837 .minUniformBufferOffsetAlignment = 4,
838 .minStorageBufferOffsetAlignment = 4,
839 .minTexelOffset = -32,
840 .maxTexelOffset = 31,
841 .minTexelGatherOffset = -32,
842 .maxTexelGatherOffset = 31,
843 .minInterpolationOffset = -2,
844 .maxInterpolationOffset = 2,
845 .subPixelInterpolationOffsetBits = 8,
846 .maxFramebufferWidth = (1 << 14),
847 .maxFramebufferHeight = (1 << 14),
848 .maxFramebufferLayers = (1 << 10),
849 .framebufferColorSampleCounts = sample_counts,
850 .framebufferDepthSampleCounts = sample_counts,
851 .framebufferStencilSampleCounts = sample_counts,
852 .framebufferNoAttachmentsSampleCounts = sample_counts,
853 .maxColorAttachments = MAX_RTS,
854 .sampledImageColorSampleCounts = sample_counts,
855 .sampledImageIntegerSampleCounts = VK_SAMPLE_COUNT_1_BIT,
856 .sampledImageDepthSampleCounts = sample_counts,
857 .sampledImageStencilSampleCounts = sample_counts,
858 .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT,
859 .maxSampleMaskWords = 1,
860 .timestampComputeAndGraphics = true,
861 .timestampPeriod = 1000000.0 / pdevice->rad_info.clock_crystal_freq,
862 .maxClipDistances = 8,
863 .maxCullDistances = 8,
864 .maxCombinedClipAndCullDistances = 8,
865 .discreteQueuePriorities = 1,
866 .pointSizeRange = { 0.125, 255.875 },
867 .lineWidthRange = { 0.0, 7.9921875 },
868 .pointSizeGranularity = (1.0 / 8.0),
869 .lineWidthGranularity = (1.0 / 128.0),
870 .strictLines = false, /* FINISHME */
871 .standardSampleLocations = true,
872 .optimalBufferCopyOffsetAlignment = 128,
873 .optimalBufferCopyRowPitchAlignment = 128,
874 .nonCoherentAtomSize = 64,
877 *pProperties = (VkPhysicalDeviceProperties) {
878 .apiVersion = radv_physical_device_api_version(pdevice),
879 .driverVersion = vk_get_driver_version(),
880 .vendorID = ATI_VENDOR_ID,
881 .deviceID = pdevice->rad_info.pci_id,
882 .deviceType = pdevice->rad_info.has_dedicated_vram ? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU : VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
884 .sparseProperties = {0},
887 strcpy(pProperties->deviceName, pdevice->name);
888 memcpy(pProperties->pipelineCacheUUID, pdevice->cache_uuid, VK_UUID_SIZE);
891 void radv_GetPhysicalDeviceProperties2(
892 VkPhysicalDevice physicalDevice,
893 VkPhysicalDeviceProperties2KHR *pProperties)
895 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
896 radv_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
898 vk_foreach_struct(ext, pProperties->pNext) {
899 switch (ext->sType) {
900 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
901 VkPhysicalDevicePushDescriptorPropertiesKHR *properties =
902 (VkPhysicalDevicePushDescriptorPropertiesKHR *) ext;
903 properties->maxPushDescriptors = MAX_PUSH_DESCRIPTORS;
906 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR: {
907 VkPhysicalDeviceIDPropertiesKHR *properties = (VkPhysicalDeviceIDPropertiesKHR*)ext;
908 memcpy(properties->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
909 memcpy(properties->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
910 properties->deviceLUIDValid = false;
913 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR: {
914 VkPhysicalDeviceMultiviewPropertiesKHR *properties = (VkPhysicalDeviceMultiviewPropertiesKHR*)ext;
915 properties->maxMultiviewViewCount = MAX_VIEWS;
916 properties->maxMultiviewInstanceIndex = INT_MAX;
919 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR: {
920 VkPhysicalDevicePointClippingPropertiesKHR *properties =
921 (VkPhysicalDevicePointClippingPropertiesKHR*)ext;
922 properties->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR;
925 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT: {
926 VkPhysicalDeviceDiscardRectanglePropertiesEXT *properties =
927 (VkPhysicalDeviceDiscardRectanglePropertiesEXT*)ext;
928 properties->maxDiscardRectangles = MAX_DISCARD_RECTANGLES;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT: {
932 VkPhysicalDeviceExternalMemoryHostPropertiesEXT *properties =
933 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT *) ext;
934 properties->minImportedHostPointerAlignment = 4096;
937 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES: {
938 VkPhysicalDeviceSubgroupProperties *properties =
939 (VkPhysicalDeviceSubgroupProperties*)ext;
940 properties->subgroupSize = 64;
941 properties->supportedStages = VK_SHADER_STAGE_ALL;
942 properties->supportedOperations = VK_SUBGROUP_FEATURE_BASIC_BIT;
943 properties->quadOperationsInAllStages = false;
946 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
947 VkPhysicalDeviceMaintenance3Properties *properties =
948 (VkPhysicalDeviceMaintenance3Properties*)ext;
949 /* Make sure everything is addressable by a signed 32-bit int, and
950 * our largest descriptors are 96 bytes. */
951 properties->maxPerSetDescriptors = (1ull << 31) / 96;
952 /* Our buffer size fields allow only this much */
953 properties->maxMemoryAllocationSize = 0xFFFFFFFFull;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT: {
957 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT *properties =
958 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT *)ext;
959 /* GFX6-8 only support single channel min/max filter. */
960 properties->filterMinmaxImageComponentMapping = pdevice->rad_info.chip_class >= GFX9;
961 properties->filterMinmaxSingleComponentFormats = true;
970 static void radv_get_physical_device_queue_family_properties(
971 struct radv_physical_device* pdevice,
973 VkQueueFamilyProperties** pQueueFamilyProperties)
975 int num_queue_families = 1;
977 if (pdevice->rad_info.num_compute_rings > 0 &&
978 !(pdevice->instance->debug_flags & RADV_DEBUG_NO_COMPUTE_QUEUE))
979 num_queue_families++;
981 if (pQueueFamilyProperties == NULL) {
982 *pCount = num_queue_families;
991 *pQueueFamilyProperties[idx] = (VkQueueFamilyProperties) {
992 .queueFlags = VK_QUEUE_GRAPHICS_BIT |
993 VK_QUEUE_COMPUTE_BIT |
994 VK_QUEUE_TRANSFER_BIT |
995 VK_QUEUE_SPARSE_BINDING_BIT,
997 .timestampValidBits = 64,
998 .minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
1003 if (pdevice->rad_info.num_compute_rings > 0 &&
1004 !(pdevice->instance->debug_flags & RADV_DEBUG_NO_COMPUTE_QUEUE)) {
1005 if (*pCount > idx) {
1006 *pQueueFamilyProperties[idx] = (VkQueueFamilyProperties) {
1007 .queueFlags = VK_QUEUE_COMPUTE_BIT |
1008 VK_QUEUE_TRANSFER_BIT |
1009 VK_QUEUE_SPARSE_BINDING_BIT,
1010 .queueCount = pdevice->rad_info.num_compute_rings,
1011 .timestampValidBits = 64,
1012 .minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
1020 void radv_GetPhysicalDeviceQueueFamilyProperties(
1021 VkPhysicalDevice physicalDevice,
1023 VkQueueFamilyProperties* pQueueFamilyProperties)
1025 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
1026 if (!pQueueFamilyProperties) {
1027 return radv_get_physical_device_queue_family_properties(pdevice, pCount, NULL);
1030 VkQueueFamilyProperties *properties[] = {
1031 pQueueFamilyProperties + 0,
1032 pQueueFamilyProperties + 1,
1033 pQueueFamilyProperties + 2,
1035 radv_get_physical_device_queue_family_properties(pdevice, pCount, properties);
1036 assert(*pCount <= 3);
1039 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1040 VkPhysicalDevice physicalDevice,
1042 VkQueueFamilyProperties2KHR *pQueueFamilyProperties)
1044 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
1045 if (!pQueueFamilyProperties) {
1046 return radv_get_physical_device_queue_family_properties(pdevice, pCount, NULL);
1049 VkQueueFamilyProperties *properties[] = {
1050 &pQueueFamilyProperties[0].queueFamilyProperties,
1051 &pQueueFamilyProperties[1].queueFamilyProperties,
1052 &pQueueFamilyProperties[2].queueFamilyProperties,
1054 radv_get_physical_device_queue_family_properties(pdevice, pCount, properties);
1055 assert(*pCount <= 3);
1058 void radv_GetPhysicalDeviceMemoryProperties(
1059 VkPhysicalDevice physicalDevice,
1060 VkPhysicalDeviceMemoryProperties *pMemoryProperties)
1062 RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1064 *pMemoryProperties = physical_device->memory_properties;
1067 void radv_GetPhysicalDeviceMemoryProperties2(
1068 VkPhysicalDevice physicalDevice,
1069 VkPhysicalDeviceMemoryProperties2KHR *pMemoryProperties)
1071 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice,
1072 &pMemoryProperties->memoryProperties);
1075 VkResult radv_GetMemoryHostPointerPropertiesEXT(
1077 VkExternalMemoryHandleTypeFlagBitsKHR handleType,
1078 const void *pHostPointer,
1079 VkMemoryHostPointerPropertiesEXT *pMemoryHostPointerProperties)
1081 RADV_FROM_HANDLE(radv_device, device, _device);
1085 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT: {
1086 const struct radv_physical_device *physical_device = device->physical_device;
1087 uint32_t memoryTypeBits = 0;
1088 for (int i = 0; i < physical_device->memory_properties.memoryTypeCount; i++) {
1089 if (physical_device->mem_type_indices[i] == RADV_MEM_TYPE_GTT_CACHED) {
1090 memoryTypeBits = (1 << i);
1094 pMemoryHostPointerProperties->memoryTypeBits = memoryTypeBits;
1098 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
1102 static enum radeon_ctx_priority
1103 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT *pObj)
1105 /* Default to MEDIUM when a specific global priority isn't requested */
1107 return RADEON_CTX_PRIORITY_MEDIUM;
1109 switch(pObj->globalPriority) {
1110 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT:
1111 return RADEON_CTX_PRIORITY_REALTIME;
1112 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT:
1113 return RADEON_CTX_PRIORITY_HIGH;
1114 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT:
1115 return RADEON_CTX_PRIORITY_MEDIUM;
1116 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT:
1117 return RADEON_CTX_PRIORITY_LOW;
1119 unreachable("Illegal global priority value");
1120 return RADEON_CTX_PRIORITY_INVALID;
1125 radv_queue_init(struct radv_device *device, struct radv_queue *queue,
1126 uint32_t queue_family_index, int idx,
1127 VkDeviceQueueCreateFlags flags,
1128 const VkDeviceQueueGlobalPriorityCreateInfoEXT *global_priority)
1130 queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
1131 queue->device = device;
1132 queue->queue_family_index = queue_family_index;
1133 queue->queue_idx = idx;
1134 queue->priority = radv_get_queue_global_priority(global_priority);
1135 queue->flags = flags;
1137 queue->hw_ctx = device->ws->ctx_create(device->ws, queue->priority);
1139 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1145 radv_queue_finish(struct radv_queue *queue)
1148 queue->device->ws->ctx_destroy(queue->hw_ctx);
1150 if (queue->initial_full_flush_preamble_cs)
1151 queue->device->ws->cs_destroy(queue->initial_full_flush_preamble_cs);
1152 if (queue->initial_preamble_cs)
1153 queue->device->ws->cs_destroy(queue->initial_preamble_cs);
1154 if (queue->continue_preamble_cs)
1155 queue->device->ws->cs_destroy(queue->continue_preamble_cs);
1156 if (queue->descriptor_bo)
1157 queue->device->ws->buffer_destroy(queue->descriptor_bo);
1158 if (queue->scratch_bo)
1159 queue->device->ws->buffer_destroy(queue->scratch_bo);
1160 if (queue->esgs_ring_bo)
1161 queue->device->ws->buffer_destroy(queue->esgs_ring_bo);
1162 if (queue->gsvs_ring_bo)
1163 queue->device->ws->buffer_destroy(queue->gsvs_ring_bo);
1164 if (queue->tess_rings_bo)
1165 queue->device->ws->buffer_destroy(queue->tess_rings_bo);
1166 if (queue->compute_scratch_bo)
1167 queue->device->ws->buffer_destroy(queue->compute_scratch_bo);
1171 radv_device_init_gs_info(struct radv_device *device)
1173 switch (device->physical_device->rad_info.family) {
1182 device->gs_table_depth = 16;
1191 case CHIP_POLARIS10:
1192 case CHIP_POLARIS11:
1193 case CHIP_POLARIS12:
1197 device->gs_table_depth = 32;
1200 unreachable("unknown GPU");
1204 static int radv_get_device_extension_index(const char *name)
1206 for (unsigned i = 0; i < RADV_DEVICE_EXTENSION_COUNT; ++i) {
1207 if (strcmp(name, radv_device_extensions[i].extensionName) == 0)
1213 VkResult radv_CreateDevice(
1214 VkPhysicalDevice physicalDevice,
1215 const VkDeviceCreateInfo* pCreateInfo,
1216 const VkAllocationCallbacks* pAllocator,
1219 RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1221 struct radv_device *device;
1223 bool keep_shader_info = false;
1225 /* Check enabled features */
1226 if (pCreateInfo->pEnabledFeatures) {
1227 VkPhysicalDeviceFeatures supported_features;
1228 radv_GetPhysicalDeviceFeatures(physicalDevice, &supported_features);
1229 VkBool32 *supported_feature = (VkBool32 *)&supported_features;
1230 VkBool32 *enabled_feature = (VkBool32 *)pCreateInfo->pEnabledFeatures;
1231 unsigned num_features = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
1232 for (uint32_t i = 0; i < num_features; i++) {
1233 if (enabled_feature[i] && !supported_feature[i])
1234 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT);
1238 device = vk_zalloc2(&physical_device->instance->alloc, pAllocator,
1240 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
1242 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1244 device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
1245 device->instance = physical_device->instance;
1246 device->physical_device = physical_device;
1248 device->ws = physical_device->ws;
1250 device->alloc = *pAllocator;
1252 device->alloc = physical_device->instance->alloc;
1254 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
1255 const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
1256 int index = radv_get_device_extension_index(ext_name);
1257 if (index < 0 || !physical_device->supported_extensions.extensions[index]) {
1258 vk_free(&device->alloc, device);
1259 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
1262 device->enabled_extensions.extensions[index] = true;
1265 keep_shader_info = device->enabled_extensions.AMD_shader_info;
1267 mtx_init(&device->shader_slab_mutex, mtx_plain);
1268 list_inithead(&device->shader_slabs);
1270 for (unsigned i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
1271 const VkDeviceQueueCreateInfo *queue_create = &pCreateInfo->pQueueCreateInfos[i];
1272 uint32_t qfi = queue_create->queueFamilyIndex;
1273 const VkDeviceQueueGlobalPriorityCreateInfoEXT *global_priority =
1274 vk_find_struct_const(queue_create->pNext, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT);
1276 assert(!global_priority || device->physical_device->rad_info.has_ctx_priority);
1278 device->queues[qfi] = vk_alloc(&device->alloc,
1279 queue_create->queueCount * sizeof(struct radv_queue), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
1280 if (!device->queues[qfi]) {
1281 result = VK_ERROR_OUT_OF_HOST_MEMORY;
1285 memset(device->queues[qfi], 0, queue_create->queueCount * sizeof(struct radv_queue));
1287 device->queue_count[qfi] = queue_create->queueCount;
1289 for (unsigned q = 0; q < queue_create->queueCount; q++) {
1290 result = radv_queue_init(device, &device->queues[qfi][q],
1291 qfi, q, queue_create->flags,
1293 if (result != VK_SUCCESS)
1298 device->pbb_allowed = device->physical_device->rad_info.chip_class >= GFX9 &&
1299 (device->instance->perftest_flags & RADV_PERFTEST_BINNING);
1301 /* Disabled and not implemented for now. */
1302 device->dfsm_allowed = device->pbb_allowed && false;
1305 device->always_use_syncobj = device->physical_device->rad_info.has_syncobj_wait_for_submit;
1308 device->llvm_supports_spill = true;
1310 /* The maximum number of scratch waves. Scratch space isn't divided
1311 * evenly between CUs. The number is only a function of the number of CUs.
1312 * We can decrease the constant to decrease the scratch buffer size.
1314 * sctx->scratch_waves must be >= the maximum posible size of
1315 * 1 threadgroup, so that the hw doesn't hang from being unable
1318 * The recommended value is 4 per CU at most. Higher numbers don't
1319 * bring much benefit, but they still occupy chip resources (think
1320 * async compute). I've seen ~2% performance difference between 4 and 32.
1322 uint32_t max_threads_per_block = 2048;
1323 device->scratch_waves = MAX2(32 * physical_device->rad_info.num_good_compute_units,
1324 max_threads_per_block / 64);
1326 device->dispatch_initiator = S_00B800_COMPUTE_SHADER_EN(1);
1328 if (device->physical_device->rad_info.chip_class >= CIK) {
1329 /* If the KMD allows it (there is a KMD hw register for it),
1330 * allow launching waves out-of-order.
1332 device->dispatch_initiator |= S_00B800_ORDER_MODE(1);
1335 radv_device_init_gs_info(device);
1337 device->tess_offchip_block_dw_size =
1338 device->physical_device->rad_info.family == CHIP_HAWAII ? 4096 : 8192;
1339 device->has_distributed_tess =
1340 device->physical_device->rad_info.chip_class >= VI &&
1341 device->physical_device->rad_info.max_se >= 2;
1343 if (getenv("RADV_TRACE_FILE")) {
1344 const char *filename = getenv("RADV_TRACE_FILE");
1346 keep_shader_info = true;
1348 if (!radv_init_trace(device))
1351 fprintf(stderr, "Trace file will be dumped to %s\n", filename);
1352 radv_dump_enabled_options(device, stderr);
1355 device->keep_shader_info = keep_shader_info;
1357 result = radv_device_init_meta(device);
1358 if (result != VK_SUCCESS)
1361 radv_device_init_msaa(device);
1363 for (int family = 0; family < RADV_MAX_QUEUE_FAMILIES; ++family) {
1364 device->empty_cs[family] = device->ws->cs_create(device->ws, family);
1366 case RADV_QUEUE_GENERAL:
1367 radeon_emit(device->empty_cs[family], PKT3(PKT3_CONTEXT_CONTROL, 1, 0));
1368 radeon_emit(device->empty_cs[family], CONTEXT_CONTROL_LOAD_ENABLE(1));
1369 radeon_emit(device->empty_cs[family], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1371 case RADV_QUEUE_COMPUTE:
1372 radeon_emit(device->empty_cs[family], PKT3(PKT3_NOP, 0, 0));
1373 radeon_emit(device->empty_cs[family], 0);
1376 device->ws->cs_finalize(device->empty_cs[family]);
1379 if (device->physical_device->rad_info.chip_class >= CIK)
1380 cik_create_gfx_config(device);
1382 VkPipelineCacheCreateInfo ci;
1383 ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
1386 ci.pInitialData = NULL;
1387 ci.initialDataSize = 0;
1389 result = radv_CreatePipelineCache(radv_device_to_handle(device),
1391 if (result != VK_SUCCESS)
1394 device->mem_cache = radv_pipeline_cache_from_handle(pc);
1396 *pDevice = radv_device_to_handle(device);
1400 radv_device_finish_meta(device);
1402 if (device->trace_bo)
1403 device->ws->buffer_destroy(device->trace_bo);
1405 if (device->gfx_init)
1406 device->ws->buffer_destroy(device->gfx_init);
1408 for (unsigned i = 0; i < RADV_MAX_QUEUE_FAMILIES; i++) {
1409 for (unsigned q = 0; q < device->queue_count[i]; q++)
1410 radv_queue_finish(&device->queues[i][q]);
1411 if (device->queue_count[i])
1412 vk_free(&device->alloc, device->queues[i]);
1415 vk_free(&device->alloc, device);
1419 void radv_DestroyDevice(
1421 const VkAllocationCallbacks* pAllocator)
1423 RADV_FROM_HANDLE(radv_device, device, _device);
1428 if (device->trace_bo)
1429 device->ws->buffer_destroy(device->trace_bo);
1431 if (device->gfx_init)
1432 device->ws->buffer_destroy(device->gfx_init);
1434 for (unsigned i = 0; i < RADV_MAX_QUEUE_FAMILIES; i++) {
1435 for (unsigned q = 0; q < device->queue_count[i]; q++)
1436 radv_queue_finish(&device->queues[i][q]);
1437 if (device->queue_count[i])
1438 vk_free(&device->alloc, device->queues[i]);
1439 if (device->empty_cs[i])
1440 device->ws->cs_destroy(device->empty_cs[i]);
1442 radv_device_finish_meta(device);
1444 VkPipelineCache pc = radv_pipeline_cache_to_handle(device->mem_cache);
1445 radv_DestroyPipelineCache(radv_device_to_handle(device), pc, NULL);
1447 radv_destroy_shader_slabs(device);
1449 vk_free(&device->alloc, device);
1452 VkResult radv_EnumerateInstanceLayerProperties(
1453 uint32_t* pPropertyCount,
1454 VkLayerProperties* pProperties)
1456 if (pProperties == NULL) {
1457 *pPropertyCount = 0;
1461 /* None supported at this time */
1462 return vk_error(VK_ERROR_LAYER_NOT_PRESENT);
1465 VkResult radv_EnumerateDeviceLayerProperties(
1466 VkPhysicalDevice physicalDevice,
1467 uint32_t* pPropertyCount,
1468 VkLayerProperties* pProperties)
1470 if (pProperties == NULL) {
1471 *pPropertyCount = 0;
1475 /* None supported at this time */
1476 return vk_error(VK_ERROR_LAYER_NOT_PRESENT);
1479 void radv_GetDeviceQueue2(
1481 const VkDeviceQueueInfo2* pQueueInfo,
1484 RADV_FROM_HANDLE(radv_device, device, _device);
1485 struct radv_queue *queue;
1487 queue = &device->queues[pQueueInfo->queueFamilyIndex][pQueueInfo->queueIndex];
1488 if (pQueueInfo->flags != queue->flags) {
1489 /* From the Vulkan 1.1.70 spec:
1491 * "The queue returned by vkGetDeviceQueue2 must have the same
1492 * flags value from this structure as that used at device
1493 * creation time in a VkDeviceQueueCreateInfo instance. If no
1494 * matching flags were specified at device creation time then
1495 * pQueue will return VK_NULL_HANDLE."
1497 *pQueue = VK_NULL_HANDLE;
1501 *pQueue = radv_queue_to_handle(queue);
1504 void radv_GetDeviceQueue(
1506 uint32_t queueFamilyIndex,
1507 uint32_t queueIndex,
1510 const VkDeviceQueueInfo2 info = (VkDeviceQueueInfo2) {
1511 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2,
1512 .queueFamilyIndex = queueFamilyIndex,
1513 .queueIndex = queueIndex
1516 radv_GetDeviceQueue2(_device, &info, pQueue);
1520 fill_geom_tess_rings(struct radv_queue *queue,
1522 bool add_sample_positions,
1523 uint32_t esgs_ring_size,
1524 struct radeon_winsys_bo *esgs_ring_bo,
1525 uint32_t gsvs_ring_size,
1526 struct radeon_winsys_bo *gsvs_ring_bo,
1527 uint32_t tess_factor_ring_size,
1528 uint32_t tess_offchip_ring_offset,
1529 uint32_t tess_offchip_ring_size,
1530 struct radeon_winsys_bo *tess_rings_bo)
1532 uint64_t esgs_va = 0, gsvs_va = 0;
1533 uint64_t tess_va = 0, tess_offchip_va = 0;
1534 uint32_t *desc = &map[4];
1537 esgs_va = radv_buffer_get_va(esgs_ring_bo);
1539 gsvs_va = radv_buffer_get_va(gsvs_ring_bo);
1540 if (tess_rings_bo) {
1541 tess_va = radv_buffer_get_va(tess_rings_bo);
1542 tess_offchip_va = tess_va + tess_offchip_ring_offset;
1545 /* stride 0, num records - size, add tid, swizzle, elsize4,
1548 desc[1] = S_008F04_BASE_ADDRESS_HI(esgs_va >> 32) |
1549 S_008F04_STRIDE(0) |
1550 S_008F04_SWIZZLE_ENABLE(true);
1551 desc[2] = esgs_ring_size;
1552 desc[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
1553 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1554 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
1555 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
1556 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1557 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
1558 S_008F0C_ELEMENT_SIZE(1) |
1559 S_008F0C_INDEX_STRIDE(3) |
1560 S_008F0C_ADD_TID_ENABLE(true);
1563 /* GS entry for ES->GS ring */
1564 /* stride 0, num records - size, elsize0,
1567 desc[1] = S_008F04_BASE_ADDRESS_HI(esgs_va >> 32)|
1568 S_008F04_STRIDE(0) |
1569 S_008F04_SWIZZLE_ENABLE(false);
1570 desc[2] = esgs_ring_size;
1571 desc[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
1572 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1573 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
1574 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
1575 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1576 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
1577 S_008F0C_ELEMENT_SIZE(0) |
1578 S_008F0C_INDEX_STRIDE(0) |
1579 S_008F0C_ADD_TID_ENABLE(false);
1582 /* VS entry for GS->VS ring */
1583 /* stride 0, num records - size, elsize0,
1586 desc[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va >> 32)|
1587 S_008F04_STRIDE(0) |
1588 S_008F04_SWIZZLE_ENABLE(false);
1589 desc[2] = gsvs_ring_size;
1590 desc[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
1591 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1592 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
1593 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
1594 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1595 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
1596 S_008F0C_ELEMENT_SIZE(0) |
1597 S_008F0C_INDEX_STRIDE(0) |
1598 S_008F0C_ADD_TID_ENABLE(false);
1601 /* stride gsvs_itemsize, num records 64
1602 elsize 4, index stride 16 */
1603 /* shader will patch stride and desc[2] */
1605 desc[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va >> 32)|
1606 S_008F04_STRIDE(0) |
1607 S_008F04_SWIZZLE_ENABLE(true);
1609 desc[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
1610 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1611 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
1612 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
1613 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1614 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
1615 S_008F0C_ELEMENT_SIZE(1) |
1616 S_008F0C_INDEX_STRIDE(1) |
1617 S_008F0C_ADD_TID_ENABLE(true);
1621 desc[1] = S_008F04_BASE_ADDRESS_HI(tess_va >> 32) |
1622 S_008F04_STRIDE(0) |
1623 S_008F04_SWIZZLE_ENABLE(false);
1624 desc[2] = tess_factor_ring_size;
1625 desc[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
1626 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1627 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
1628 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
1629 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1630 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
1631 S_008F0C_ELEMENT_SIZE(0) |
1632 S_008F0C_INDEX_STRIDE(0) |
1633 S_008F0C_ADD_TID_ENABLE(false);
1636 desc[0] = tess_offchip_va;
1637 desc[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va >> 32) |
1638 S_008F04_STRIDE(0) |
1639 S_008F04_SWIZZLE_ENABLE(false);
1640 desc[2] = tess_offchip_ring_size;
1641 desc[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
1642 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1643 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
1644 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
1645 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1646 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
1647 S_008F0C_ELEMENT_SIZE(0) |
1648 S_008F0C_INDEX_STRIDE(0) |
1649 S_008F0C_ADD_TID_ENABLE(false);
1652 /* add sample positions after all rings */
1653 memcpy(desc, queue->device->sample_locations_1x, 8);
1655 memcpy(desc, queue->device->sample_locations_2x, 16);
1657 memcpy(desc, queue->device->sample_locations_4x, 32);
1659 memcpy(desc, queue->device->sample_locations_8x, 64);
1661 memcpy(desc, queue->device->sample_locations_16x, 128);
1665 radv_get_hs_offchip_param(struct radv_device *device, uint32_t *max_offchip_buffers_p)
1667 bool double_offchip_buffers = device->physical_device->rad_info.chip_class >= CIK &&
1668 device->physical_device->rad_info.family != CHIP_CARRIZO &&
1669 device->physical_device->rad_info.family != CHIP_STONEY;
1670 unsigned max_offchip_buffers_per_se = double_offchip_buffers ? 128 : 64;
1671 unsigned max_offchip_buffers = max_offchip_buffers_per_se *
1672 device->physical_device->rad_info.max_se;
1673 unsigned offchip_granularity;
1674 unsigned hs_offchip_param;
1675 switch (device->tess_offchip_block_dw_size) {
1680 offchip_granularity = V_03093C_X_8K_DWORDS;
1683 offchip_granularity = V_03093C_X_4K_DWORDS;
1687 switch (device->physical_device->rad_info.chip_class) {
1689 max_offchip_buffers = MIN2(max_offchip_buffers, 126);
1695 max_offchip_buffers = MIN2(max_offchip_buffers, 508);
1699 *max_offchip_buffers_p = max_offchip_buffers;
1700 if (device->physical_device->rad_info.chip_class >= CIK) {
1701 if (device->physical_device->rad_info.chip_class >= VI)
1702 --max_offchip_buffers;
1704 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers) |
1705 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity);
1708 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers);
1710 return hs_offchip_param;
1714 radv_get_preamble_cs(struct radv_queue *queue,
1715 uint32_t scratch_size,
1716 uint32_t compute_scratch_size,
1717 uint32_t esgs_ring_size,
1718 uint32_t gsvs_ring_size,
1719 bool needs_tess_rings,
1720 bool needs_sample_positions,
1721 struct radeon_winsys_cs **initial_full_flush_preamble_cs,
1722 struct radeon_winsys_cs **initial_preamble_cs,
1723 struct radeon_winsys_cs **continue_preamble_cs)
1725 struct radeon_winsys_bo *scratch_bo = NULL;
1726 struct radeon_winsys_bo *descriptor_bo = NULL;
1727 struct radeon_winsys_bo *compute_scratch_bo = NULL;
1728 struct radeon_winsys_bo *esgs_ring_bo = NULL;
1729 struct radeon_winsys_bo *gsvs_ring_bo = NULL;
1730 struct radeon_winsys_bo *tess_rings_bo = NULL;
1731 struct radeon_winsys_cs *dest_cs[3] = {0};
1732 bool add_tess_rings = false, add_sample_positions = false;
1733 unsigned tess_factor_ring_size = 0, tess_offchip_ring_size = 0;
1734 unsigned max_offchip_buffers;
1735 unsigned hs_offchip_param = 0;
1736 unsigned tess_offchip_ring_offset;
1737 uint32_t ring_bo_flags = RADEON_FLAG_NO_CPU_ACCESS | RADEON_FLAG_NO_INTERPROCESS_SHARING;
1738 if (!queue->has_tess_rings) {
1739 if (needs_tess_rings)
1740 add_tess_rings = true;
1742 if (!queue->has_sample_positions) {
1743 if (needs_sample_positions)
1744 add_sample_positions = true;
1746 tess_factor_ring_size = 32768 * queue->device->physical_device->rad_info.max_se;
1747 hs_offchip_param = radv_get_hs_offchip_param(queue->device,
1748 &max_offchip_buffers);
1749 tess_offchip_ring_offset = align(tess_factor_ring_size, 64 * 1024);
1750 tess_offchip_ring_size = max_offchip_buffers *
1751 queue->device->tess_offchip_block_dw_size * 4;
1753 if (scratch_size <= queue->scratch_size &&
1754 compute_scratch_size <= queue->compute_scratch_size &&
1755 esgs_ring_size <= queue->esgs_ring_size &&
1756 gsvs_ring_size <= queue->gsvs_ring_size &&
1757 !add_tess_rings && !add_sample_positions &&
1758 queue->initial_preamble_cs) {
1759 *initial_full_flush_preamble_cs = queue->initial_full_flush_preamble_cs;
1760 *initial_preamble_cs = queue->initial_preamble_cs;
1761 *continue_preamble_cs = queue->continue_preamble_cs;
1762 if (!scratch_size && !compute_scratch_size && !esgs_ring_size && !gsvs_ring_size)
1763 *continue_preamble_cs = NULL;
1767 if (scratch_size > queue->scratch_size) {
1768 scratch_bo = queue->device->ws->buffer_create(queue->device->ws,
1776 scratch_bo = queue->scratch_bo;
1778 if (compute_scratch_size > queue->compute_scratch_size) {
1779 compute_scratch_bo = queue->device->ws->buffer_create(queue->device->ws,
1780 compute_scratch_size,
1784 if (!compute_scratch_bo)
1788 compute_scratch_bo = queue->compute_scratch_bo;
1790 if (esgs_ring_size > queue->esgs_ring_size) {
1791 esgs_ring_bo = queue->device->ws->buffer_create(queue->device->ws,
1799 esgs_ring_bo = queue->esgs_ring_bo;
1800 esgs_ring_size = queue->esgs_ring_size;
1803 if (gsvs_ring_size > queue->gsvs_ring_size) {
1804 gsvs_ring_bo = queue->device->ws->buffer_create(queue->device->ws,
1812 gsvs_ring_bo = queue->gsvs_ring_bo;
1813 gsvs_ring_size = queue->gsvs_ring_size;
1816 if (add_tess_rings) {
1817 tess_rings_bo = queue->device->ws->buffer_create(queue->device->ws,
1818 tess_offchip_ring_offset + tess_offchip_ring_size,
1825 tess_rings_bo = queue->tess_rings_bo;
1828 if (scratch_bo != queue->scratch_bo ||
1829 esgs_ring_bo != queue->esgs_ring_bo ||
1830 gsvs_ring_bo != queue->gsvs_ring_bo ||
1831 tess_rings_bo != queue->tess_rings_bo ||
1832 add_sample_positions) {
1834 if (gsvs_ring_bo || esgs_ring_bo ||
1835 tess_rings_bo || add_sample_positions) {
1836 size = 112; /* 2 dword + 2 padding + 4 dword * 6 */
1837 if (add_sample_positions)
1838 size += 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1840 else if (scratch_bo)
1841 size = 8; /* 2 dword */
1843 descriptor_bo = queue->device->ws->buffer_create(queue->device->ws,
1847 RADEON_FLAG_CPU_ACCESS |
1848 RADEON_FLAG_NO_INTERPROCESS_SHARING |
1849 RADEON_FLAG_READ_ONLY);
1853 descriptor_bo = queue->descriptor_bo;
1855 for(int i = 0; i < 3; ++i) {
1856 struct radeon_winsys_cs *cs = NULL;
1857 cs = queue->device->ws->cs_create(queue->device->ws,
1858 queue->queue_family_index ? RING_COMPUTE : RING_GFX);
1865 radv_cs_add_buffer(queue->device->ws, cs, scratch_bo, 8);
1868 radv_cs_add_buffer(queue->device->ws, cs, esgs_ring_bo, 8);
1871 radv_cs_add_buffer(queue->device->ws, cs, gsvs_ring_bo, 8);
1874 radv_cs_add_buffer(queue->device->ws, cs, tess_rings_bo, 8);
1877 radv_cs_add_buffer(queue->device->ws, cs, descriptor_bo, 8);
1879 if (descriptor_bo != queue->descriptor_bo) {
1880 uint32_t *map = (uint32_t*)queue->device->ws->buffer_map(descriptor_bo);
1883 uint64_t scratch_va = radv_buffer_get_va(scratch_bo);
1884 uint32_t rsrc1 = S_008F04_BASE_ADDRESS_HI(scratch_va >> 32) |
1885 S_008F04_SWIZZLE_ENABLE(1);
1886 map[0] = scratch_va;
1890 if (esgs_ring_bo || gsvs_ring_bo || tess_rings_bo ||
1891 add_sample_positions)
1892 fill_geom_tess_rings(queue, map, add_sample_positions,
1893 esgs_ring_size, esgs_ring_bo,
1894 gsvs_ring_size, gsvs_ring_bo,
1895 tess_factor_ring_size,
1896 tess_offchip_ring_offset,
1897 tess_offchip_ring_size,
1900 queue->device->ws->buffer_unmap(descriptor_bo);
1903 if (esgs_ring_bo || gsvs_ring_bo || tess_rings_bo) {
1904 radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
1905 radeon_emit(cs, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH) | EVENT_INDEX(4));
1906 radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0));
1907 radeon_emit(cs, EVENT_TYPE(V_028A90_VGT_FLUSH) | EVENT_INDEX(0));
1910 if (esgs_ring_bo || gsvs_ring_bo) {
1911 if (queue->device->physical_device->rad_info.chip_class >= CIK) {
1912 radeon_set_uconfig_reg_seq(cs, R_030900_VGT_ESGS_RING_SIZE, 2);
1913 radeon_emit(cs, esgs_ring_size >> 8);
1914 radeon_emit(cs, gsvs_ring_size >> 8);
1916 radeon_set_config_reg_seq(cs, R_0088C8_VGT_ESGS_RING_SIZE, 2);
1917 radeon_emit(cs, esgs_ring_size >> 8);
1918 radeon_emit(cs, gsvs_ring_size >> 8);
1922 if (tess_rings_bo) {
1923 uint64_t tf_va = radv_buffer_get_va(tess_rings_bo);
1924 if (queue->device->physical_device->rad_info.chip_class >= CIK) {
1925 radeon_set_uconfig_reg(cs, R_030938_VGT_TF_RING_SIZE,
1926 S_030938_SIZE(tess_factor_ring_size / 4));
1927 radeon_set_uconfig_reg(cs, R_030940_VGT_TF_MEMORY_BASE,
1929 if (queue->device->physical_device->rad_info.chip_class >= GFX9) {
1930 radeon_set_uconfig_reg(cs, R_030944_VGT_TF_MEMORY_BASE_HI,
1931 S_030944_BASE_HI(tf_va >> 40));
1933 radeon_set_uconfig_reg(cs, R_03093C_VGT_HS_OFFCHIP_PARAM, hs_offchip_param);
1935 radeon_set_config_reg(cs, R_008988_VGT_TF_RING_SIZE,
1936 S_008988_SIZE(tess_factor_ring_size / 4));
1937 radeon_set_config_reg(cs, R_0089B8_VGT_TF_MEMORY_BASE,
1939 radeon_set_config_reg(cs, R_0089B0_VGT_HS_OFFCHIP_PARAM,
1944 if (descriptor_bo) {
1945 uint64_t va = radv_buffer_get_va(descriptor_bo);
1946 if (queue->device->physical_device->rad_info.chip_class >= GFX9) {
1947 uint32_t regs[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0,
1948 R_00B130_SPI_SHADER_USER_DATA_VS_0,
1949 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS,
1950 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS};
1952 for (int i = 0; i < ARRAY_SIZE(regs); ++i) {
1953 radeon_set_sh_reg_seq(cs, regs[i], 2);
1954 radeon_emit(cs, va);
1955 radeon_emit(cs, va >> 32);
1958 uint32_t regs[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0,
1959 R_00B130_SPI_SHADER_USER_DATA_VS_0,
1960 R_00B230_SPI_SHADER_USER_DATA_GS_0,
1961 R_00B330_SPI_SHADER_USER_DATA_ES_0,
1962 R_00B430_SPI_SHADER_USER_DATA_HS_0,
1963 R_00B530_SPI_SHADER_USER_DATA_LS_0};
1965 for (int i = 0; i < ARRAY_SIZE(regs); ++i) {
1966 radeon_set_sh_reg_seq(cs, regs[i], 2);
1967 radeon_emit(cs, va);
1968 radeon_emit(cs, va >> 32);
1973 if (compute_scratch_bo) {
1974 uint64_t scratch_va = radv_buffer_get_va(compute_scratch_bo);
1975 uint32_t rsrc1 = S_008F04_BASE_ADDRESS_HI(scratch_va >> 32) |
1976 S_008F04_SWIZZLE_ENABLE(1);
1978 radv_cs_add_buffer(queue->device->ws, cs, compute_scratch_bo, 8);
1980 radeon_set_sh_reg_seq(cs, R_00B900_COMPUTE_USER_DATA_0, 2);
1981 radeon_emit(cs, scratch_va);
1982 radeon_emit(cs, rsrc1);
1986 si_cs_emit_cache_flush(cs,
1987 queue->device->physical_device->rad_info.chip_class,
1989 queue->queue_family_index == RING_COMPUTE &&
1990 queue->device->physical_device->rad_info.chip_class >= CIK,
1991 (queue->queue_family_index == RADV_QUEUE_COMPUTE ? RADV_CMD_FLAG_CS_PARTIAL_FLUSH : (RADV_CMD_FLAG_CS_PARTIAL_FLUSH | RADV_CMD_FLAG_PS_PARTIAL_FLUSH)) |
1992 RADV_CMD_FLAG_INV_ICACHE |
1993 RADV_CMD_FLAG_INV_SMEM_L1 |
1994 RADV_CMD_FLAG_INV_VMEM_L1 |
1995 RADV_CMD_FLAG_INV_GLOBAL_L2);
1996 } else if (i == 1) {
1997 si_cs_emit_cache_flush(cs,
1998 queue->device->physical_device->rad_info.chip_class,
2000 queue->queue_family_index == RING_COMPUTE &&
2001 queue->device->physical_device->rad_info.chip_class >= CIK,
2002 RADV_CMD_FLAG_INV_ICACHE |
2003 RADV_CMD_FLAG_INV_SMEM_L1 |
2004 RADV_CMD_FLAG_INV_VMEM_L1 |
2005 RADV_CMD_FLAG_INV_GLOBAL_L2);
2008 if (!queue->device->ws->cs_finalize(cs))
2012 if (queue->initial_full_flush_preamble_cs)
2013 queue->device->ws->cs_destroy(queue->initial_full_flush_preamble_cs);
2015 if (queue->initial_preamble_cs)
2016 queue->device->ws->cs_destroy(queue->initial_preamble_cs);
2018 if (queue->continue_preamble_cs)
2019 queue->device->ws->cs_destroy(queue->continue_preamble_cs);
2021 queue->initial_full_flush_preamble_cs = dest_cs[0];
2022 queue->initial_preamble_cs = dest_cs[1];
2023 queue->continue_preamble_cs = dest_cs[2];
2025 if (scratch_bo != queue->scratch_bo) {
2026 if (queue->scratch_bo)
2027 queue->device->ws->buffer_destroy(queue->scratch_bo);
2028 queue->scratch_bo = scratch_bo;
2029 queue->scratch_size = scratch_size;
2032 if (compute_scratch_bo != queue->compute_scratch_bo) {
2033 if (queue->compute_scratch_bo)
2034 queue->device->ws->buffer_destroy(queue->compute_scratch_bo);
2035 queue->compute_scratch_bo = compute_scratch_bo;
2036 queue->compute_scratch_size = compute_scratch_size;
2039 if (esgs_ring_bo != queue->esgs_ring_bo) {
2040 if (queue->esgs_ring_bo)
2041 queue->device->ws->buffer_destroy(queue->esgs_ring_bo);
2042 queue->esgs_ring_bo = esgs_ring_bo;
2043 queue->esgs_ring_size = esgs_ring_size;
2046 if (gsvs_ring_bo != queue->gsvs_ring_bo) {
2047 if (queue->gsvs_ring_bo)
2048 queue->device->ws->buffer_destroy(queue->gsvs_ring_bo);
2049 queue->gsvs_ring_bo = gsvs_ring_bo;
2050 queue->gsvs_ring_size = gsvs_ring_size;
2053 if (tess_rings_bo != queue->tess_rings_bo) {
2054 queue->tess_rings_bo = tess_rings_bo;
2055 queue->has_tess_rings = true;
2058 if (descriptor_bo != queue->descriptor_bo) {
2059 if (queue->descriptor_bo)
2060 queue->device->ws->buffer_destroy(queue->descriptor_bo);
2062 queue->descriptor_bo = descriptor_bo;
2065 if (add_sample_positions)
2066 queue->has_sample_positions = true;
2068 *initial_full_flush_preamble_cs = queue->initial_full_flush_preamble_cs;
2069 *initial_preamble_cs = queue->initial_preamble_cs;
2070 *continue_preamble_cs = queue->continue_preamble_cs;
2071 if (!scratch_size && !compute_scratch_size && !esgs_ring_size && !gsvs_ring_size)
2072 *continue_preamble_cs = NULL;
2075 for (int i = 0; i < ARRAY_SIZE(dest_cs); ++i)
2077 queue->device->ws->cs_destroy(dest_cs[i]);
2078 if (descriptor_bo && descriptor_bo != queue->descriptor_bo)
2079 queue->device->ws->buffer_destroy(descriptor_bo);
2080 if (scratch_bo && scratch_bo != queue->scratch_bo)
2081 queue->device->ws->buffer_destroy(scratch_bo);
2082 if (compute_scratch_bo && compute_scratch_bo != queue->compute_scratch_bo)
2083 queue->device->ws->buffer_destroy(compute_scratch_bo);
2084 if (esgs_ring_bo && esgs_ring_bo != queue->esgs_ring_bo)
2085 queue->device->ws->buffer_destroy(esgs_ring_bo);
2086 if (gsvs_ring_bo && gsvs_ring_bo != queue->gsvs_ring_bo)
2087 queue->device->ws->buffer_destroy(gsvs_ring_bo);
2088 if (tess_rings_bo && tess_rings_bo != queue->tess_rings_bo)
2089 queue->device->ws->buffer_destroy(tess_rings_bo);
2090 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
2093 static VkResult radv_alloc_sem_counts(struct radv_winsys_sem_counts *counts,
2095 const VkSemaphore *sems,
2099 int syncobj_idx = 0, sem_idx = 0;
2101 if (num_sems == 0 && _fence == VK_NULL_HANDLE)
2104 for (uint32_t i = 0; i < num_sems; i++) {
2105 RADV_FROM_HANDLE(radv_semaphore, sem, sems[i]);
2107 if (sem->temp_syncobj || sem->syncobj)
2108 counts->syncobj_count++;
2110 counts->sem_count++;
2113 if (_fence != VK_NULL_HANDLE) {
2114 RADV_FROM_HANDLE(radv_fence, fence, _fence);
2115 if (fence->temp_syncobj || fence->syncobj)
2116 counts->syncobj_count++;
2119 if (counts->syncobj_count) {
2120 counts->syncobj = (uint32_t *)malloc(sizeof(uint32_t) * counts->syncobj_count);
2121 if (!counts->syncobj)
2122 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
2125 if (counts->sem_count) {
2126 counts->sem = (struct radeon_winsys_sem **)malloc(sizeof(struct radeon_winsys_sem *) * counts->sem_count);
2128 free(counts->syncobj);
2129 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
2133 for (uint32_t i = 0; i < num_sems; i++) {
2134 RADV_FROM_HANDLE(radv_semaphore, sem, sems[i]);
2136 if (sem->temp_syncobj) {
2137 counts->syncobj[syncobj_idx++] = sem->temp_syncobj;
2139 else if (sem->syncobj)
2140 counts->syncobj[syncobj_idx++] = sem->syncobj;
2143 counts->sem[sem_idx++] = sem->sem;
2147 if (_fence != VK_NULL_HANDLE) {
2148 RADV_FROM_HANDLE(radv_fence, fence, _fence);
2149 if (fence->temp_syncobj)
2150 counts->syncobj[syncobj_idx++] = fence->temp_syncobj;
2151 else if (fence->syncobj)
2152 counts->syncobj[syncobj_idx++] = fence->syncobj;
2158 void radv_free_sem_info(struct radv_winsys_sem_info *sem_info)
2160 free(sem_info->wait.syncobj);
2161 free(sem_info->wait.sem);
2162 free(sem_info->signal.syncobj);
2163 free(sem_info->signal.sem);
2167 static void radv_free_temp_syncobjs(struct radv_device *device,
2169 const VkSemaphore *sems)
2171 for (uint32_t i = 0; i < num_sems; i++) {
2172 RADV_FROM_HANDLE(radv_semaphore, sem, sems[i]);
2174 if (sem->temp_syncobj) {
2175 device->ws->destroy_syncobj(device->ws, sem->temp_syncobj);
2176 sem->temp_syncobj = 0;
2181 VkResult radv_alloc_sem_info(struct radv_winsys_sem_info *sem_info,
2183 const VkSemaphore *wait_sems,
2184 int num_signal_sems,
2185 const VkSemaphore *signal_sems,
2189 memset(sem_info, 0, sizeof(*sem_info));
2191 ret = radv_alloc_sem_counts(&sem_info->wait, num_wait_sems, wait_sems, VK_NULL_HANDLE, true);
2194 ret = radv_alloc_sem_counts(&sem_info->signal, num_signal_sems, signal_sems, fence, false);
2196 radv_free_sem_info(sem_info);
2198 /* caller can override these */
2199 sem_info->cs_emit_wait = true;
2200 sem_info->cs_emit_signal = true;
2204 /* Signals fence as soon as all the work currently put on queue is done. */
2205 static VkResult radv_signal_fence(struct radv_queue *queue,
2206 struct radv_fence *fence)
2210 struct radv_winsys_sem_info sem_info;
2212 result = radv_alloc_sem_info(&sem_info, 0, NULL, 0, NULL,
2213 radv_fence_to_handle(fence));
2214 if (result != VK_SUCCESS)
2217 ret = queue->device->ws->cs_submit(queue->hw_ctx, queue->queue_idx,
2218 &queue->device->empty_cs[queue->queue_family_index],
2219 1, NULL, NULL, &sem_info,
2220 false, fence->fence);
2221 radv_free_sem_info(&sem_info);
2223 /* TODO: find a better error */
2225 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
2230 VkResult radv_QueueSubmit(
2232 uint32_t submitCount,
2233 const VkSubmitInfo* pSubmits,
2236 RADV_FROM_HANDLE(radv_queue, queue, _queue);
2237 RADV_FROM_HANDLE(radv_fence, fence, _fence);
2238 struct radeon_winsys_fence *base_fence = fence ? fence->fence : NULL;
2239 struct radeon_winsys_ctx *ctx = queue->hw_ctx;
2241 uint32_t max_cs_submission = queue->device->trace_bo ? 1 : UINT32_MAX;
2242 uint32_t scratch_size = 0;
2243 uint32_t compute_scratch_size = 0;
2244 uint32_t esgs_ring_size = 0, gsvs_ring_size = 0;
2245 struct radeon_winsys_cs *initial_preamble_cs = NULL, *initial_flush_preamble_cs = NULL, *continue_preamble_cs = NULL;
2247 bool fence_emitted = false;
2248 bool tess_rings_needed = false;
2249 bool sample_positions_needed = false;
2251 /* Do this first so failing to allocate scratch buffers can't result in
2252 * partially executed submissions. */
2253 for (uint32_t i = 0; i < submitCount; i++) {
2254 for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) {
2255 RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer,
2256 pSubmits[i].pCommandBuffers[j]);
2258 scratch_size = MAX2(scratch_size, cmd_buffer->scratch_size_needed);
2259 compute_scratch_size = MAX2(compute_scratch_size,
2260 cmd_buffer->compute_scratch_size_needed);
2261 esgs_ring_size = MAX2(esgs_ring_size, cmd_buffer->esgs_ring_size_needed);
2262 gsvs_ring_size = MAX2(gsvs_ring_size, cmd_buffer->gsvs_ring_size_needed);
2263 tess_rings_needed |= cmd_buffer->tess_rings_needed;
2264 sample_positions_needed |= cmd_buffer->sample_positions_needed;
2268 result = radv_get_preamble_cs(queue, scratch_size, compute_scratch_size,
2269 esgs_ring_size, gsvs_ring_size, tess_rings_needed,
2270 sample_positions_needed, &initial_flush_preamble_cs,
2271 &initial_preamble_cs, &continue_preamble_cs);
2272 if (result != VK_SUCCESS)
2275 for (uint32_t i = 0; i < submitCount; i++) {
2276 struct radeon_winsys_cs **cs_array;
2277 bool do_flush = !i || pSubmits[i].pWaitDstStageMask;
2278 bool can_patch = true;
2280 struct radv_winsys_sem_info sem_info;
2282 result = radv_alloc_sem_info(&sem_info,
2283 pSubmits[i].waitSemaphoreCount,
2284 pSubmits[i].pWaitSemaphores,
2285 pSubmits[i].signalSemaphoreCount,
2286 pSubmits[i].pSignalSemaphores,
2288 if (result != VK_SUCCESS)
2291 if (!pSubmits[i].commandBufferCount) {
2292 if (pSubmits[i].waitSemaphoreCount || pSubmits[i].signalSemaphoreCount) {
2293 ret = queue->device->ws->cs_submit(ctx, queue->queue_idx,
2294 &queue->device->empty_cs[queue->queue_family_index],
2299 radv_loge("failed to submit CS %d\n", i);
2302 fence_emitted = true;
2304 radv_free_sem_info(&sem_info);
2308 cs_array = malloc(sizeof(struct radeon_winsys_cs *) *
2309 (pSubmits[i].commandBufferCount));
2311 for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) {
2312 RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer,
2313 pSubmits[i].pCommandBuffers[j]);
2314 assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2316 cs_array[j] = cmd_buffer->cs;
2317 if ((cmd_buffer->usage_flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT))
2320 cmd_buffer->status = RADV_CMD_BUFFER_STATUS_PENDING;
2323 for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j += advance) {
2324 struct radeon_winsys_cs *initial_preamble = (do_flush && !j) ? initial_flush_preamble_cs : initial_preamble_cs;
2325 advance = MIN2(max_cs_submission,
2326 pSubmits[i].commandBufferCount - j);
2328 if (queue->device->trace_bo)
2329 *queue->device->trace_id_ptr = 0;
2331 sem_info.cs_emit_wait = j == 0;
2332 sem_info.cs_emit_signal = j + advance == pSubmits[i].commandBufferCount;
2334 ret = queue->device->ws->cs_submit(ctx, queue->queue_idx, cs_array + j,
2335 advance, initial_preamble, continue_preamble_cs,
2337 can_patch, base_fence);
2340 radv_loge("failed to submit CS %d\n", i);
2343 fence_emitted = true;
2344 if (queue->device->trace_bo) {
2345 radv_check_gpu_hangs(queue, cs_array[j]);
2349 radv_free_temp_syncobjs(queue->device,
2350 pSubmits[i].waitSemaphoreCount,
2351 pSubmits[i].pWaitSemaphores);
2352 radv_free_sem_info(&sem_info);
2357 if (!fence_emitted) {
2358 radv_signal_fence(queue, fence);
2360 fence->submitted = true;
2366 VkResult radv_QueueWaitIdle(
2369 RADV_FROM_HANDLE(radv_queue, queue, _queue);
2371 queue->device->ws->ctx_wait_idle(queue->hw_ctx,
2372 radv_queue_family_to_ring(queue->queue_family_index),
2377 VkResult radv_DeviceWaitIdle(
2380 RADV_FROM_HANDLE(radv_device, device, _device);
2382 for (unsigned i = 0; i < RADV_MAX_QUEUE_FAMILIES; i++) {
2383 for (unsigned q = 0; q < device->queue_count[i]; q++) {
2384 radv_QueueWaitIdle(radv_queue_to_handle(&device->queues[i][q]));
2390 VkResult radv_EnumerateInstanceExtensionProperties(
2391 const char* pLayerName,
2392 uint32_t* pPropertyCount,
2393 VkExtensionProperties* pProperties)
2395 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
2397 for (int i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; i++) {
2398 if (radv_supported_instance_extensions.extensions[i]) {
2399 vk_outarray_append(&out, prop) {
2400 *prop = radv_instance_extensions[i];
2405 return vk_outarray_status(&out);
2408 VkResult radv_EnumerateDeviceExtensionProperties(
2409 VkPhysicalDevice physicalDevice,
2410 const char* pLayerName,
2411 uint32_t* pPropertyCount,
2412 VkExtensionProperties* pProperties)
2414 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
2415 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
2417 for (int i = 0; i < RADV_DEVICE_EXTENSION_COUNT; i++) {
2418 if (device->supported_extensions.extensions[i]) {
2419 vk_outarray_append(&out, prop) {
2420 *prop = radv_device_extensions[i];
2425 return vk_outarray_status(&out);
2428 PFN_vkVoidFunction radv_GetInstanceProcAddr(
2429 VkInstance _instance,
2432 RADV_FROM_HANDLE(radv_instance, instance, _instance);
2434 return radv_lookup_entrypoint_checked(pName,
2435 instance ? instance->apiVersion : 0,
2436 instance ? &instance->enabled_extensions : NULL,
2440 /* The loader wants us to expose a second GetInstanceProcAddr function
2441 * to work around certain LD_PRELOAD issues seen in apps.
2444 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
2445 VkInstance instance,
2449 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
2450 VkInstance instance,
2453 return radv_GetInstanceProcAddr(instance, pName);
2456 PFN_vkVoidFunction radv_GetDeviceProcAddr(
2460 RADV_FROM_HANDLE(radv_device, device, _device);
2462 return radv_lookup_entrypoint_checked(pName,
2463 device->instance->apiVersion,
2464 &device->instance->enabled_extensions,
2465 &device->enabled_extensions);
2468 bool radv_get_memory_fd(struct radv_device *device,
2469 struct radv_device_memory *memory,
2472 struct radeon_bo_metadata metadata;
2474 if (memory->image) {
2475 radv_init_metadata(device, memory->image, &metadata);
2476 device->ws->buffer_set_metadata(memory->bo, &metadata);
2479 return device->ws->buffer_get_fd(device->ws, memory->bo,
2483 static VkResult radv_alloc_memory(struct radv_device *device,
2484 const VkMemoryAllocateInfo* pAllocateInfo,
2485 const VkAllocationCallbacks* pAllocator,
2486 VkDeviceMemory* pMem)
2488 struct radv_device_memory *mem;
2490 enum radeon_bo_domain domain;
2492 enum radv_mem_type mem_type_index = device->physical_device->mem_type_indices[pAllocateInfo->memoryTypeIndex];
2494 assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
2496 if (pAllocateInfo->allocationSize == 0) {
2497 /* Apparently, this is allowed */
2498 *pMem = VK_NULL_HANDLE;
2502 const VkImportMemoryFdInfoKHR *import_info =
2503 vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
2504 const VkMemoryDedicatedAllocateInfoKHR *dedicate_info =
2505 vk_find_struct_const(pAllocateInfo->pNext, MEMORY_DEDICATED_ALLOCATE_INFO_KHR);
2506 const VkExportMemoryAllocateInfoKHR *export_info =
2507 vk_find_struct_const(pAllocateInfo->pNext, EXPORT_MEMORY_ALLOCATE_INFO_KHR);
2508 const VkImportMemoryHostPointerInfoEXT *host_ptr_info =
2509 vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_HOST_POINTER_INFO_EXT);
2511 const struct wsi_memory_allocate_info *wsi_info =
2512 vk_find_struct_const(pAllocateInfo->pNext, WSI_MEMORY_ALLOCATE_INFO_MESA);
2514 mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
2515 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
2517 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
2519 if (wsi_info && wsi_info->implicit_sync)
2520 flags |= RADEON_FLAG_IMPLICIT_SYNC;
2522 if (dedicate_info) {
2523 mem->image = radv_image_from_handle(dedicate_info->image);
2524 mem->buffer = radv_buffer_from_handle(dedicate_info->buffer);
2530 mem->user_ptr = NULL;
2533 assert(import_info->handleType ==
2534 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR ||
2535 import_info->handleType ==
2536 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
2537 mem->bo = device->ws->buffer_from_fd(device->ws, import_info->fd,
2540 result = VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
2543 close(import_info->fd);
2548 if (host_ptr_info) {
2549 assert(host_ptr_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT);
2550 assert(mem_type_index == RADV_MEM_TYPE_GTT_CACHED);
2551 mem->bo = device->ws->buffer_from_ptr(device->ws, host_ptr_info->pHostPointer,
2552 pAllocateInfo->allocationSize);
2554 result = VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
2557 mem->user_ptr = host_ptr_info->pHostPointer;
2562 uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096);
2563 if (mem_type_index == RADV_MEM_TYPE_GTT_WRITE_COMBINE ||
2564 mem_type_index == RADV_MEM_TYPE_GTT_CACHED)
2565 domain = RADEON_DOMAIN_GTT;
2567 domain = RADEON_DOMAIN_VRAM;
2569 if (mem_type_index == RADV_MEM_TYPE_VRAM)
2570 flags |= RADEON_FLAG_NO_CPU_ACCESS;
2572 flags |= RADEON_FLAG_CPU_ACCESS;
2574 if (mem_type_index == RADV_MEM_TYPE_GTT_WRITE_COMBINE)
2575 flags |= RADEON_FLAG_GTT_WC;
2577 if (!dedicate_info && !import_info && (!export_info || !export_info->handleTypes))
2578 flags |= RADEON_FLAG_NO_INTERPROCESS_SHARING;
2580 mem->bo = device->ws->buffer_create(device->ws, alloc_size, device->physical_device->rad_info.max_alignment,
2584 result = VK_ERROR_OUT_OF_DEVICE_MEMORY;
2587 mem->type_index = mem_type_index;
2589 *pMem = radv_device_memory_to_handle(mem);
2594 vk_free2(&device->alloc, pAllocator, mem);
2599 VkResult radv_AllocateMemory(
2601 const VkMemoryAllocateInfo* pAllocateInfo,
2602 const VkAllocationCallbacks* pAllocator,
2603 VkDeviceMemory* pMem)
2605 RADV_FROM_HANDLE(radv_device, device, _device);
2606 return radv_alloc_memory(device, pAllocateInfo, pAllocator, pMem);
2609 void radv_FreeMemory(
2611 VkDeviceMemory _mem,
2612 const VkAllocationCallbacks* pAllocator)
2614 RADV_FROM_HANDLE(radv_device, device, _device);
2615 RADV_FROM_HANDLE(radv_device_memory, mem, _mem);
2620 device->ws->buffer_destroy(mem->bo);
2623 vk_free2(&device->alloc, pAllocator, mem);
2626 VkResult radv_MapMemory(
2628 VkDeviceMemory _memory,
2629 VkDeviceSize offset,
2631 VkMemoryMapFlags flags,
2634 RADV_FROM_HANDLE(radv_device, device, _device);
2635 RADV_FROM_HANDLE(radv_device_memory, mem, _memory);
2643 *ppData = mem->user_ptr;
2645 *ppData = device->ws->buffer_map(mem->bo);
2652 return vk_error(VK_ERROR_MEMORY_MAP_FAILED);
2655 void radv_UnmapMemory(
2657 VkDeviceMemory _memory)
2659 RADV_FROM_HANDLE(radv_device, device, _device);
2660 RADV_FROM_HANDLE(radv_device_memory, mem, _memory);
2665 if (mem->user_ptr == NULL)
2666 device->ws->buffer_unmap(mem->bo);
2669 VkResult radv_FlushMappedMemoryRanges(
2671 uint32_t memoryRangeCount,
2672 const VkMappedMemoryRange* pMemoryRanges)
2677 VkResult radv_InvalidateMappedMemoryRanges(
2679 uint32_t memoryRangeCount,
2680 const VkMappedMemoryRange* pMemoryRanges)
2685 void radv_GetBufferMemoryRequirements(
2688 VkMemoryRequirements* pMemoryRequirements)
2690 RADV_FROM_HANDLE(radv_device, device, _device);
2691 RADV_FROM_HANDLE(radv_buffer, buffer, _buffer);
2693 pMemoryRequirements->memoryTypeBits = (1u << device->physical_device->memory_properties.memoryTypeCount) - 1;
2695 if (buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
2696 pMemoryRequirements->alignment = 4096;
2698 pMemoryRequirements->alignment = 16;
2700 pMemoryRequirements->size = align64(buffer->size, pMemoryRequirements->alignment);
2703 void radv_GetBufferMemoryRequirements2(
2705 const VkBufferMemoryRequirementsInfo2KHR* pInfo,
2706 VkMemoryRequirements2KHR* pMemoryRequirements)
2708 radv_GetBufferMemoryRequirements(device, pInfo->buffer,
2709 &pMemoryRequirements->memoryRequirements);
2710 RADV_FROM_HANDLE(radv_buffer, buffer, pInfo->buffer);
2711 vk_foreach_struct(ext, pMemoryRequirements->pNext) {
2712 switch (ext->sType) {
2713 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR: {
2714 VkMemoryDedicatedRequirementsKHR *req =
2715 (VkMemoryDedicatedRequirementsKHR *) ext;
2716 req->requiresDedicatedAllocation = buffer->shareable;
2717 req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
2726 void radv_GetImageMemoryRequirements(
2729 VkMemoryRequirements* pMemoryRequirements)
2731 RADV_FROM_HANDLE(radv_device, device, _device);
2732 RADV_FROM_HANDLE(radv_image, image, _image);
2734 pMemoryRequirements->memoryTypeBits = (1u << device->physical_device->memory_properties.memoryTypeCount) - 1;
2736 pMemoryRequirements->size = image->size;
2737 pMemoryRequirements->alignment = image->alignment;
2740 void radv_GetImageMemoryRequirements2(
2742 const VkImageMemoryRequirementsInfo2KHR* pInfo,
2743 VkMemoryRequirements2KHR* pMemoryRequirements)
2745 radv_GetImageMemoryRequirements(device, pInfo->image,
2746 &pMemoryRequirements->memoryRequirements);
2748 RADV_FROM_HANDLE(radv_image, image, pInfo->image);
2750 vk_foreach_struct(ext, pMemoryRequirements->pNext) {
2751 switch (ext->sType) {
2752 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR: {
2753 VkMemoryDedicatedRequirementsKHR *req =
2754 (VkMemoryDedicatedRequirementsKHR *) ext;
2755 req->requiresDedicatedAllocation = image->shareable;
2756 req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
2765 void radv_GetImageSparseMemoryRequirements(
2768 uint32_t* pSparseMemoryRequirementCount,
2769 VkSparseImageMemoryRequirements* pSparseMemoryRequirements)
2774 void radv_GetImageSparseMemoryRequirements2(
2776 const VkImageSparseMemoryRequirementsInfo2KHR* pInfo,
2777 uint32_t* pSparseMemoryRequirementCount,
2778 VkSparseImageMemoryRequirements2KHR* pSparseMemoryRequirements)
2783 void radv_GetDeviceMemoryCommitment(
2785 VkDeviceMemory memory,
2786 VkDeviceSize* pCommittedMemoryInBytes)
2788 *pCommittedMemoryInBytes = 0;
2791 VkResult radv_BindBufferMemory2(VkDevice device,
2792 uint32_t bindInfoCount,
2793 const VkBindBufferMemoryInfoKHR *pBindInfos)
2795 for (uint32_t i = 0; i < bindInfoCount; ++i) {
2796 RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
2797 RADV_FROM_HANDLE(radv_buffer, buffer, pBindInfos[i].buffer);
2800 buffer->bo = mem->bo;
2801 buffer->offset = pBindInfos[i].memoryOffset;
2809 VkResult radv_BindBufferMemory(
2812 VkDeviceMemory memory,
2813 VkDeviceSize memoryOffset)
2815 const VkBindBufferMemoryInfoKHR info = {
2816 .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR,
2819 .memoryOffset = memoryOffset
2822 return radv_BindBufferMemory2(device, 1, &info);
2825 VkResult radv_BindImageMemory2(VkDevice device,
2826 uint32_t bindInfoCount,
2827 const VkBindImageMemoryInfoKHR *pBindInfos)
2829 for (uint32_t i = 0; i < bindInfoCount; ++i) {
2830 RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
2831 RADV_FROM_HANDLE(radv_image, image, pBindInfos[i].image);
2834 image->bo = mem->bo;
2835 image->offset = pBindInfos[i].memoryOffset;
2845 VkResult radv_BindImageMemory(
2848 VkDeviceMemory memory,
2849 VkDeviceSize memoryOffset)
2851 const VkBindImageMemoryInfoKHR info = {
2852 .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR,
2855 .memoryOffset = memoryOffset
2858 return radv_BindImageMemory2(device, 1, &info);
2863 radv_sparse_buffer_bind_memory(struct radv_device *device,
2864 const VkSparseBufferMemoryBindInfo *bind)
2866 RADV_FROM_HANDLE(radv_buffer, buffer, bind->buffer);
2868 for (uint32_t i = 0; i < bind->bindCount; ++i) {
2869 struct radv_device_memory *mem = NULL;
2871 if (bind->pBinds[i].memory != VK_NULL_HANDLE)
2872 mem = radv_device_memory_from_handle(bind->pBinds[i].memory);
2874 device->ws->buffer_virtual_bind(buffer->bo,
2875 bind->pBinds[i].resourceOffset,
2876 bind->pBinds[i].size,
2877 mem ? mem->bo : NULL,
2878 bind->pBinds[i].memoryOffset);
2883 radv_sparse_image_opaque_bind_memory(struct radv_device *device,
2884 const VkSparseImageOpaqueMemoryBindInfo *bind)
2886 RADV_FROM_HANDLE(radv_image, image, bind->image);
2888 for (uint32_t i = 0; i < bind->bindCount; ++i) {
2889 struct radv_device_memory *mem = NULL;
2891 if (bind->pBinds[i].memory != VK_NULL_HANDLE)
2892 mem = radv_device_memory_from_handle(bind->pBinds[i].memory);
2894 device->ws->buffer_virtual_bind(image->bo,
2895 bind->pBinds[i].resourceOffset,
2896 bind->pBinds[i].size,
2897 mem ? mem->bo : NULL,
2898 bind->pBinds[i].memoryOffset);
2902 VkResult radv_QueueBindSparse(
2904 uint32_t bindInfoCount,
2905 const VkBindSparseInfo* pBindInfo,
2908 RADV_FROM_HANDLE(radv_fence, fence, _fence);
2909 RADV_FROM_HANDLE(radv_queue, queue, _queue);
2910 struct radeon_winsys_fence *base_fence = fence ? fence->fence : NULL;
2911 bool fence_emitted = false;
2913 for (uint32_t i = 0; i < bindInfoCount; ++i) {
2914 struct radv_winsys_sem_info sem_info;
2915 for (uint32_t j = 0; j < pBindInfo[i].bufferBindCount; ++j) {
2916 radv_sparse_buffer_bind_memory(queue->device,
2917 pBindInfo[i].pBufferBinds + j);
2920 for (uint32_t j = 0; j < pBindInfo[i].imageOpaqueBindCount; ++j) {
2921 radv_sparse_image_opaque_bind_memory(queue->device,
2922 pBindInfo[i].pImageOpaqueBinds + j);
2926 result = radv_alloc_sem_info(&sem_info,
2927 pBindInfo[i].waitSemaphoreCount,
2928 pBindInfo[i].pWaitSemaphores,
2929 pBindInfo[i].signalSemaphoreCount,
2930 pBindInfo[i].pSignalSemaphores,
2932 if (result != VK_SUCCESS)
2935 if (pBindInfo[i].waitSemaphoreCount || pBindInfo[i].signalSemaphoreCount) {
2936 queue->device->ws->cs_submit(queue->hw_ctx, queue->queue_idx,
2937 &queue->device->empty_cs[queue->queue_family_index],
2941 fence_emitted = true;
2943 fence->submitted = true;
2946 radv_free_sem_info(&sem_info);
2951 if (!fence_emitted) {
2952 radv_signal_fence(queue, fence);
2954 fence->submitted = true;
2960 VkResult radv_CreateFence(
2962 const VkFenceCreateInfo* pCreateInfo,
2963 const VkAllocationCallbacks* pAllocator,
2966 RADV_FROM_HANDLE(radv_device, device, _device);
2967 const VkExportFenceCreateInfoKHR *export =
2968 vk_find_struct_const(pCreateInfo->pNext, EXPORT_FENCE_CREATE_INFO_KHR);
2969 VkExternalFenceHandleTypeFlagsKHR handleTypes =
2970 export ? export->handleTypes : 0;
2972 struct radv_fence *fence = vk_alloc2(&device->alloc, pAllocator,
2974 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
2977 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
2979 fence->submitted = false;
2980 fence->signalled = !!(pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT);
2981 fence->temp_syncobj = 0;
2982 if (device->always_use_syncobj || handleTypes) {
2983 int ret = device->ws->create_syncobj(device->ws, &fence->syncobj);
2985 vk_free2(&device->alloc, pAllocator, fence);
2986 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
2988 if (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) {
2989 device->ws->signal_syncobj(device->ws, fence->syncobj);
2991 fence->fence = NULL;
2993 fence->fence = device->ws->create_fence();
2994 if (!fence->fence) {
2995 vk_free2(&device->alloc, pAllocator, fence);
2996 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3001 *pFence = radv_fence_to_handle(fence);
3006 void radv_DestroyFence(
3009 const VkAllocationCallbacks* pAllocator)
3011 RADV_FROM_HANDLE(radv_device, device, _device);
3012 RADV_FROM_HANDLE(radv_fence, fence, _fence);
3017 if (fence->temp_syncobj)
3018 device->ws->destroy_syncobj(device->ws, fence->temp_syncobj);
3020 device->ws->destroy_syncobj(device->ws, fence->syncobj);
3022 device->ws->destroy_fence(fence->fence);
3023 vk_free2(&device->alloc, pAllocator, fence);
3027 static uint64_t radv_get_current_time()
3030 clock_gettime(CLOCK_MONOTONIC, &tv);
3031 return tv.tv_nsec + tv.tv_sec*1000000000ull;
3034 static uint64_t radv_get_absolute_timeout(uint64_t timeout)
3036 uint64_t current_time = radv_get_current_time();
3038 timeout = MIN2(UINT64_MAX - current_time, timeout);
3040 return current_time + timeout;
3044 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount, const VkFence *pFences)
3046 for (uint32_t i = 0; i < fenceCount; ++i) {
3047 RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
3048 if (fence->syncobj || fence->temp_syncobj || (!fence->signalled && !fence->submitted))
3054 VkResult radv_WaitForFences(
3056 uint32_t fenceCount,
3057 const VkFence* pFences,
3061 RADV_FROM_HANDLE(radv_device, device, _device);
3062 timeout = radv_get_absolute_timeout(timeout);
3064 if (device->always_use_syncobj) {
3065 uint32_t *handles = malloc(sizeof(uint32_t) * fenceCount);
3067 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3069 for (uint32_t i = 0; i < fenceCount; ++i) {
3070 RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
3071 handles[i] = fence->temp_syncobj ? fence->temp_syncobj : fence->syncobj;
3074 bool success = device->ws->wait_syncobj(device->ws, handles, fenceCount, waitAll, timeout);
3077 return success ? VK_SUCCESS : VK_TIMEOUT;
3080 if (!waitAll && fenceCount > 1) {
3081 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3082 if (device->physical_device->rad_info.drm_minor >= 10 && radv_all_fences_plain_and_submitted(fenceCount, pFences)) {
3083 uint32_t wait_count = 0;
3084 struct radeon_winsys_fence **fences = malloc(sizeof(struct radeon_winsys_fence *) * fenceCount);
3086 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3088 for (uint32_t i = 0; i < fenceCount; ++i) {
3089 RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
3091 if (fence->signalled) {
3096 fences[wait_count++] = fence->fence;
3099 bool success = device->ws->fences_wait(device->ws, fences, wait_count,
3100 waitAll, timeout - radv_get_current_time());
3103 return success ? VK_SUCCESS : VK_TIMEOUT;
3106 while(radv_get_current_time() <= timeout) {
3107 for (uint32_t i = 0; i < fenceCount; ++i) {
3108 if (radv_GetFenceStatus(_device, pFences[i]) == VK_SUCCESS)
3115 for (uint32_t i = 0; i < fenceCount; ++i) {
3116 RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
3117 bool expired = false;
3119 if (fence->temp_syncobj) {
3120 if (!device->ws->wait_syncobj(device->ws, &fence->temp_syncobj, 1, true, timeout))
3125 if (fence->syncobj) {
3126 if (!device->ws->wait_syncobj(device->ws, &fence->syncobj, 1, true, timeout))
3131 if (fence->signalled)
3134 if (!fence->submitted) {
3135 while(radv_get_current_time() <= timeout && !fence->submitted)
3138 if (!fence->submitted)
3141 /* Recheck as it may have been set by submitting operations. */
3142 if (fence->signalled)
3146 expired = device->ws->fence_wait(device->ws, fence->fence, true, timeout);
3150 fence->signalled = true;
3156 VkResult radv_ResetFences(VkDevice _device,
3157 uint32_t fenceCount,
3158 const VkFence *pFences)
3160 RADV_FROM_HANDLE(radv_device, device, _device);
3162 for (unsigned i = 0; i < fenceCount; ++i) {
3163 RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
3164 fence->submitted = fence->signalled = false;
3166 /* Per spec, we first restore the permanent payload, and then reset, so
3167 * having a temp syncobj should not skip resetting the permanent syncobj. */
3168 if (fence->temp_syncobj) {
3169 device->ws->destroy_syncobj(device->ws, fence->temp_syncobj);
3170 fence->temp_syncobj = 0;
3173 if (fence->syncobj) {
3174 device->ws->reset_syncobj(device->ws, fence->syncobj);
3181 VkResult radv_GetFenceStatus(VkDevice _device, VkFence _fence)
3183 RADV_FROM_HANDLE(radv_device, device, _device);
3184 RADV_FROM_HANDLE(radv_fence, fence, _fence);
3186 if (fence->temp_syncobj) {
3187 bool success = device->ws->wait_syncobj(device->ws, &fence->temp_syncobj, 1, true, 0);
3188 return success ? VK_SUCCESS : VK_NOT_READY;
3191 if (fence->syncobj) {
3192 bool success = device->ws->wait_syncobj(device->ws, &fence->syncobj, 1, true, 0);
3193 return success ? VK_SUCCESS : VK_NOT_READY;
3196 if (fence->signalled)
3198 if (!fence->submitted)
3199 return VK_NOT_READY;
3200 if (!device->ws->fence_wait(device->ws, fence->fence, false, 0))
3201 return VK_NOT_READY;
3207 // Queue semaphore functions
3209 VkResult radv_CreateSemaphore(
3211 const VkSemaphoreCreateInfo* pCreateInfo,
3212 const VkAllocationCallbacks* pAllocator,
3213 VkSemaphore* pSemaphore)
3215 RADV_FROM_HANDLE(radv_device, device, _device);
3216 const VkExportSemaphoreCreateInfoKHR *export =
3217 vk_find_struct_const(pCreateInfo->pNext, EXPORT_SEMAPHORE_CREATE_INFO_KHR);
3218 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes =
3219 export ? export->handleTypes : 0;
3221 struct radv_semaphore *sem = vk_alloc2(&device->alloc, pAllocator,
3223 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
3225 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3227 sem->temp_syncobj = 0;
3228 /* create a syncobject if we are going to export this semaphore */
3229 if (device->always_use_syncobj || handleTypes) {
3230 assert (device->physical_device->rad_info.has_syncobj);
3231 int ret = device->ws->create_syncobj(device->ws, &sem->syncobj);
3233 vk_free2(&device->alloc, pAllocator, sem);
3234 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3238 sem->sem = device->ws->create_sem(device->ws);
3240 vk_free2(&device->alloc, pAllocator, sem);
3241 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3246 *pSemaphore = radv_semaphore_to_handle(sem);
3250 void radv_DestroySemaphore(
3252 VkSemaphore _semaphore,
3253 const VkAllocationCallbacks* pAllocator)
3255 RADV_FROM_HANDLE(radv_device, device, _device);
3256 RADV_FROM_HANDLE(radv_semaphore, sem, _semaphore);
3261 device->ws->destroy_syncobj(device->ws, sem->syncobj);
3263 device->ws->destroy_sem(sem->sem);
3264 vk_free2(&device->alloc, pAllocator, sem);
3267 VkResult radv_CreateEvent(
3269 const VkEventCreateInfo* pCreateInfo,
3270 const VkAllocationCallbacks* pAllocator,
3273 RADV_FROM_HANDLE(radv_device, device, _device);
3274 struct radv_event *event = vk_alloc2(&device->alloc, pAllocator,
3276 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
3279 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3281 event->bo = device->ws->buffer_create(device->ws, 8, 8,
3283 RADEON_FLAG_VA_UNCACHED | RADEON_FLAG_CPU_ACCESS | RADEON_FLAG_NO_INTERPROCESS_SHARING);
3285 vk_free2(&device->alloc, pAllocator, event);
3286 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
3289 event->map = (uint64_t*)device->ws->buffer_map(event->bo);
3291 *pEvent = radv_event_to_handle(event);
3296 void radv_DestroyEvent(
3299 const VkAllocationCallbacks* pAllocator)
3301 RADV_FROM_HANDLE(radv_device, device, _device);
3302 RADV_FROM_HANDLE(radv_event, event, _event);
3306 device->ws->buffer_destroy(event->bo);
3307 vk_free2(&device->alloc, pAllocator, event);
3310 VkResult radv_GetEventStatus(
3314 RADV_FROM_HANDLE(radv_event, event, _event);
3316 if (*event->map == 1)
3317 return VK_EVENT_SET;
3318 return VK_EVENT_RESET;
3321 VkResult radv_SetEvent(
3325 RADV_FROM_HANDLE(radv_event, event, _event);
3331 VkResult radv_ResetEvent(
3335 RADV_FROM_HANDLE(radv_event, event, _event);
3341 VkResult radv_CreateBuffer(
3343 const VkBufferCreateInfo* pCreateInfo,
3344 const VkAllocationCallbacks* pAllocator,
3347 RADV_FROM_HANDLE(radv_device, device, _device);
3348 struct radv_buffer *buffer;
3350 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
3352 buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8,
3353 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
3355 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3357 buffer->size = pCreateInfo->size;
3358 buffer->usage = pCreateInfo->usage;
3361 buffer->flags = pCreateInfo->flags;
3363 buffer->shareable = vk_find_struct_const(pCreateInfo->pNext,
3364 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR) != NULL;
3366 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) {
3367 buffer->bo = device->ws->buffer_create(device->ws,
3368 align64(buffer->size, 4096),
3369 4096, 0, RADEON_FLAG_VIRTUAL);
3371 vk_free2(&device->alloc, pAllocator, buffer);
3372 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
3376 *pBuffer = radv_buffer_to_handle(buffer);
3381 void radv_DestroyBuffer(
3384 const VkAllocationCallbacks* pAllocator)
3386 RADV_FROM_HANDLE(radv_device, device, _device);
3387 RADV_FROM_HANDLE(radv_buffer, buffer, _buffer);
3392 if (buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
3393 device->ws->buffer_destroy(buffer->bo);
3395 vk_free2(&device->alloc, pAllocator, buffer);
3398 static inline unsigned
3399 si_tile_mode_index(const struct radv_image *image, unsigned level, bool stencil)
3402 return image->surface.u.legacy.stencil_tiling_index[level];
3404 return image->surface.u.legacy.tiling_index[level];
3407 static uint32_t radv_surface_max_layer_count(struct radv_image_view *iview)
3409 return iview->type == VK_IMAGE_VIEW_TYPE_3D ? iview->extent.depth : (iview->base_layer + iview->layer_count);
3413 radv_initialise_color_surface(struct radv_device *device,
3414 struct radv_color_buffer_info *cb,
3415 struct radv_image_view *iview)
3417 const struct vk_format_description *desc;
3418 unsigned ntype, format, swap, endian;
3419 unsigned blend_clamp = 0, blend_bypass = 0;
3421 const struct radeon_surf *surf = &iview->image->surface;
3423 desc = vk_format_description(iview->vk_format);
3425 memset(cb, 0, sizeof(*cb));
3427 /* Intensity is implemented as Red, so treat it that way. */
3428 cb->cb_color_attrib = S_028C74_FORCE_DST_ALPHA_1(desc->swizzle[3] == VK_SWIZZLE_1);
3430 va = radv_buffer_get_va(iview->bo) + iview->image->offset;
3432 cb->cb_color_base = va >> 8;
3434 if (device->physical_device->rad_info.chip_class >= GFX9) {
3435 struct gfx9_surf_meta_flags meta;
3436 if (iview->image->dcc_offset)
3437 meta = iview->image->surface.u.gfx9.dcc;
3439 meta = iview->image->surface.u.gfx9.cmask;
3441 cb->cb_color_attrib |= S_028C74_COLOR_SW_MODE(iview->image->surface.u.gfx9.surf.swizzle_mode) |
3442 S_028C74_FMASK_SW_MODE(iview->image->surface.u.gfx9.fmask.swizzle_mode) |
3443 S_028C74_RB_ALIGNED(meta.rb_aligned) |
3444 S_028C74_PIPE_ALIGNED(meta.pipe_aligned);
3446 cb->cb_color_base += iview->image->surface.u.gfx9.surf_offset >> 8;
3447 cb->cb_color_base |= iview->image->surface.tile_swizzle;
3449 const struct legacy_surf_level *level_info = &surf->u.legacy.level[iview->base_mip];
3450 unsigned pitch_tile_max, slice_tile_max, tile_mode_index;
3452 cb->cb_color_base += level_info->offset >> 8;
3453 if (level_info->mode == RADEON_SURF_MODE_2D)
3454 cb->cb_color_base |= iview->image->surface.tile_swizzle;
3456 pitch_tile_max = level_info->nblk_x / 8 - 1;
3457 slice_tile_max = (level_info->nblk_x * level_info->nblk_y) / 64 - 1;
3458 tile_mode_index = si_tile_mode_index(iview->image, iview->base_mip, false);
3460 cb->cb_color_pitch = S_028C64_TILE_MAX(pitch_tile_max);
3461 cb->cb_color_slice = S_028C68_TILE_MAX(slice_tile_max);
3462 cb->cb_color_cmask_slice = iview->image->cmask.slice_tile_max;
3464 cb->cb_color_attrib |= S_028C74_TILE_MODE_INDEX(tile_mode_index);
3466 if (radv_image_has_fmask(iview->image)) {
3467 if (device->physical_device->rad_info.chip_class >= CIK)
3468 cb->cb_color_pitch |= S_028C64_FMASK_TILE_MAX(iview->image->fmask.pitch_in_pixels / 8 - 1);
3469 cb->cb_color_attrib |= S_028C74_FMASK_TILE_MODE_INDEX(iview->image->fmask.tile_mode_index);
3470 cb->cb_color_fmask_slice = S_028C88_TILE_MAX(iview->image->fmask.slice_tile_max);
3472 /* This must be set for fast clear to work without FMASK. */
3473 if (device->physical_device->rad_info.chip_class >= CIK)
3474 cb->cb_color_pitch |= S_028C64_FMASK_TILE_MAX(pitch_tile_max);
3475 cb->cb_color_attrib |= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index);
3476 cb->cb_color_fmask_slice = S_028C88_TILE_MAX(slice_tile_max);
3480 /* CMASK variables */
3481 va = radv_buffer_get_va(iview->bo) + iview->image->offset;
3482 va += iview->image->cmask.offset;
3483 cb->cb_color_cmask = va >> 8;
3485 va = radv_buffer_get_va(iview->bo) + iview->image->offset;
3486 va += iview->image->dcc_offset;
3487 cb->cb_dcc_base = va >> 8;
3488 cb->cb_dcc_base |= iview->image->surface.tile_swizzle;
3490 uint32_t max_slice = radv_surface_max_layer_count(iview) - 1;
3491 cb->cb_color_view = S_028C6C_SLICE_START(iview->base_layer) |
3492 S_028C6C_SLICE_MAX(max_slice);
3494 if (iview->image->info.samples > 1) {
3495 unsigned log_samples = util_logbase2(iview->image->info.samples);
3497 cb->cb_color_attrib |= S_028C74_NUM_SAMPLES(log_samples) |
3498 S_028C74_NUM_FRAGMENTS(log_samples);
3501 if (radv_image_has_fmask(iview->image)) {
3502 va = radv_buffer_get_va(iview->bo) + iview->image->offset + iview->image->fmask.offset;
3503 cb->cb_color_fmask = va >> 8;
3504 cb->cb_color_fmask |= iview->image->fmask.tile_swizzle;
3506 cb->cb_color_fmask = cb->cb_color_base;
3509 ntype = radv_translate_color_numformat(iview->vk_format,
3511 vk_format_get_first_non_void_channel(iview->vk_format));
3512 format = radv_translate_colorformat(iview->vk_format);
3513 if (format == V_028C70_COLOR_INVALID || ntype == ~0u)
3514 radv_finishme("Illegal color\n");
3515 swap = radv_translate_colorswap(iview->vk_format, FALSE);
3516 endian = radv_colorformat_endian_swap(format);
3518 /* blend clamp should be set for all NORM/SRGB types */
3519 if (ntype == V_028C70_NUMBER_UNORM ||
3520 ntype == V_028C70_NUMBER_SNORM ||
3521 ntype == V_028C70_NUMBER_SRGB)
3524 /* set blend bypass according to docs if SINT/UINT or
3525 8/24 COLOR variants */
3526 if (ntype == V_028C70_NUMBER_UINT || ntype == V_028C70_NUMBER_SINT ||
3527 format == V_028C70_COLOR_8_24 || format == V_028C70_COLOR_24_8 ||
3528 format == V_028C70_COLOR_X24_8_32_FLOAT) {
3533 if ((ntype == V_028C70_NUMBER_UINT || ntype == V_028C70_NUMBER_SINT) &&
3534 (format == V_028C70_COLOR_8 ||
3535 format == V_028C70_COLOR_8_8 ||
3536 format == V_028C70_COLOR_8_8_8_8))
3537 ->color_is_int8 = true;
3539 cb->cb_color_info = S_028C70_FORMAT(format) |
3540 S_028C70_COMP_SWAP(swap) |
3541 S_028C70_BLEND_CLAMP(blend_clamp) |
3542 S_028C70_BLEND_BYPASS(blend_bypass) |
3543 S_028C70_SIMPLE_FLOAT(1) |
3544 S_028C70_ROUND_MODE(ntype != V_028C70_NUMBER_UNORM &&
3545 ntype != V_028C70_NUMBER_SNORM &&
3546 ntype != V_028C70_NUMBER_SRGB &&
3547 format != V_028C70_COLOR_8_24 &&
3548 format != V_028C70_COLOR_24_8) |
3549 S_028C70_NUMBER_TYPE(ntype) |
3550 S_028C70_ENDIAN(endian);
3551 if ((iview->image->info.samples > 1) && radv_image_has_fmask(iview->image)) {
3552 cb->cb_color_info |= S_028C70_COMPRESSION(1);
3553 if (device->physical_device->rad_info.chip_class == SI) {
3554 unsigned fmask_bankh = util_logbase2(iview->image->fmask.bank_height);
3555 cb->cb_color_attrib |= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh);
3559 if (radv_image_has_cmask(iview->image) &&
3560 !(device->instance->debug_flags & RADV_DEBUG_NO_FAST_CLEARS))
3561 cb->cb_color_info |= S_028C70_FAST_CLEAR(1);
3563 if (radv_dcc_enabled(iview->image, iview->base_mip))
3564 cb->cb_color_info |= S_028C70_DCC_ENABLE(1);
3566 if (device->physical_device->rad_info.chip_class >= VI) {
3567 unsigned max_uncompressed_block_size = V_028C78_MAX_BLOCK_SIZE_256B;
3568 unsigned min_compressed_block_size = V_028C78_MIN_BLOCK_SIZE_32B;
3569 unsigned independent_64b_blocks = 0;
3570 unsigned max_compressed_block_size;
3572 /* amdvlk: [min-compressed-block-size] should be set to 32 for dGPU and
3573 64 for APU because all of our APUs to date use DIMMs which have
3574 a request granularity size of 64B while all other chips have a
3576 if (!device->physical_device->rad_info.has_dedicated_vram)
3577 min_compressed_block_size = V_028C78_MIN_BLOCK_SIZE_64B;
3579 if (iview->image->info.samples > 1) {
3580 if (iview->image->surface.bpe == 1)
3581 max_uncompressed_block_size = V_028C78_MAX_BLOCK_SIZE_64B;
3582 else if (iview->image->surface.bpe == 2)
3583 max_uncompressed_block_size = V_028C78_MAX_BLOCK_SIZE_128B;
3586 if (iview->image->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
3587 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
3588 independent_64b_blocks = 1;
3589 max_compressed_block_size = V_028C78_MAX_BLOCK_SIZE_64B;
3591 max_compressed_block_size = max_uncompressed_block_size;
3593 cb->cb_dcc_control = S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size) |
3594 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size) |
3595 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size) |
3596 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks);
3599 /* This must be set for fast clear to work without FMASK. */
3600 if (!radv_image_has_fmask(iview->image) &&
3601 device->physical_device->rad_info.chip_class == SI) {
3602 unsigned bankh = util_logbase2(iview->image->surface.u.legacy.bankh);
3603 cb->cb_color_attrib |= S_028C74_FMASK_BANK_HEIGHT(bankh);
3606 if (device->physical_device->rad_info.chip_class >= GFX9) {
3607 unsigned mip0_depth = iview->image->type == VK_IMAGE_TYPE_3D ?
3608 (iview->extent.depth - 1) : (iview->image->info.array_size - 1);
3610 cb->cb_color_view |= S_028C6C_MIP_LEVEL(iview->base_mip);
3611 cb->cb_color_attrib |= S_028C74_MIP0_DEPTH(mip0_depth) |
3612 S_028C74_RESOURCE_TYPE(iview->image->surface.u.gfx9.resource_type);
3613 cb->cb_color_attrib2 = S_028C68_MIP0_WIDTH(iview->extent.width - 1) |
3614 S_028C68_MIP0_HEIGHT(iview->extent.height - 1) |
3615 S_028C68_MAX_MIP(iview->image->info.levels - 1);
3620 radv_calc_decompress_on_z_planes(struct radv_device *device,
3621 struct radv_image_view *iview)
3623 unsigned max_zplanes = 0;
3625 assert(iview->image->tc_compatible_htile);
3627 if (device->physical_device->rad_info.chip_class >= GFX9) {
3628 /* Default value for 32-bit depth surfaces. */
3631 if (iview->vk_format == VK_FORMAT_D16_UNORM &&
3632 iview->image->info.samples > 1)
3635 max_zplanes = max_zplanes + 1;
3637 if (iview->vk_format == VK_FORMAT_D16_UNORM) {
3638 /* Do not enable Z plane compression for 16-bit depth
3639 * surfaces because isn't supported on GFX8. Only
3640 * 32-bit depth surfaces are supported by the hardware.
3641 * This allows to maintain shader compatibility and to
3642 * reduce the number of depth decompressions.
3646 if (iview->image->info.samples <= 1)
3648 else if (iview->image->info.samples <= 4)
3659 radv_initialise_ds_surface(struct radv_device *device,
3660 struct radv_ds_buffer_info *ds,
3661 struct radv_image_view *iview)
3663 unsigned level = iview->base_mip;
3664 unsigned format, stencil_format;
3665 uint64_t va, s_offs, z_offs;
3666 bool stencil_only = false;
3667 memset(ds, 0, sizeof(*ds));
3668 switch (iview->image->vk_format) {
3669 case VK_FORMAT_D24_UNORM_S8_UINT:
3670 case VK_FORMAT_X8_D24_UNORM_PACK32:
3671 ds->pa_su_poly_offset_db_fmt_cntl = S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3672 ds->offset_scale = 2.0f;
3674 case VK_FORMAT_D16_UNORM:
3675 case VK_FORMAT_D16_UNORM_S8_UINT:
3676 ds->pa_su_poly_offset_db_fmt_cntl = S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3677 ds->offset_scale = 4.0f;
3679 case VK_FORMAT_D32_SFLOAT:
3680 case VK_FORMAT_D32_SFLOAT_S8_UINT:
3681 ds->pa_su_poly_offset_db_fmt_cntl = S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3682 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3683 ds->offset_scale = 1.0f;
3685 case VK_FORMAT_S8_UINT:
3686 stencil_only = true;
3692 format = radv_translate_dbformat(iview->image->vk_format);
3693 stencil_format = iview->image->surface.has_stencil ?
3694 V_028044_STENCIL_8 : V_028044_STENCIL_INVALID;
3696 uint32_t max_slice = radv_surface_max_layer_count(iview) - 1;
3697 ds->db_depth_view = S_028008_SLICE_START(iview->base_layer) |
3698 S_028008_SLICE_MAX(max_slice);
3700 ds->db_htile_data_base = 0;
3701 ds->db_htile_surface = 0;
3703 va = radv_buffer_get_va(iview->bo) + iview->image->offset;
3704 s_offs = z_offs = va;
3706 if (device->physical_device->rad_info.chip_class >= GFX9) {
3707 assert(iview->image->surface.u.gfx9.surf_offset == 0);
3708 s_offs += iview->image->surface.u.gfx9.stencil_offset;
3710 ds->db_z_info = S_028038_FORMAT(format) |
3711 S_028038_NUM_SAMPLES(util_logbase2(iview->image->info.samples)) |
3712 S_028038_SW_MODE(iview->image->surface.u.gfx9.surf.swizzle_mode) |
3713 S_028038_MAXMIP(iview->image->info.levels - 1);
3714 ds->db_stencil_info = S_02803C_FORMAT(stencil_format) |
3715 S_02803C_SW_MODE(iview->image->surface.u.gfx9.stencil.swizzle_mode);
3717 ds->db_z_info2 = S_028068_EPITCH(iview->image->surface.u.gfx9.surf.epitch);
3718 ds->db_stencil_info2 = S_02806C_EPITCH(iview->image->surface.u.gfx9.stencil.epitch);
3719 ds->db_depth_view |= S_028008_MIPID(level);
3721 ds->db_depth_size = S_02801C_X_MAX(iview->image->info.width - 1) |
3722 S_02801C_Y_MAX(iview->image->info.height - 1);
3724 if (radv_htile_enabled(iview->image, level)) {
3725 ds->db_z_info |= S_028038_TILE_SURFACE_ENABLE(1);
3727 if (iview->image->tc_compatible_htile) {
3728 unsigned max_zplanes =
3729 radv_calc_decompress_on_z_planes(device, iview);
3731 ds->db_z_info |= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes) |
3732 S_028038_ITERATE_FLUSH(1);
3733 ds->db_stencil_info |= S_02803C_ITERATE_FLUSH(1);
3736 if (!iview->image->surface.has_stencil)
3737 /* Use all of the htile_buffer for depth if there's no stencil. */
3738 ds->db_stencil_info |= S_02803C_TILE_STENCIL_DISABLE(1);
3739 va = radv_buffer_get_va(iview->bo) + iview->image->offset +
3740 iview->image->htile_offset;
3741 ds->db_htile_data_base = va >> 8;
3742 ds->db_htile_surface = S_028ABC_FULL_CACHE(1) |
3743 S_028ABC_PIPE_ALIGNED(iview->image->surface.u.gfx9.htile.pipe_aligned) |
3744 S_028ABC_RB_ALIGNED(iview->image->surface.u.gfx9.htile.rb_aligned);
3747 const struct legacy_surf_level *level_info = &iview->image->surface.u.legacy.level[level];
3750 level_info = &iview->image->surface.u.legacy.stencil_level[level];
3752 z_offs += iview->image->surface.u.legacy.level[level].offset;
3753 s_offs += iview->image->surface.u.legacy.stencil_level[level].offset;
3755 ds->db_depth_info = S_02803C_ADDR5_SWIZZLE_MASK(!iview->image->tc_compatible_htile);
3756 ds->db_z_info = S_028040_FORMAT(format) | S_028040_ZRANGE_PRECISION(1);
3757 ds->db_stencil_info = S_028044_FORMAT(stencil_format);
3759 if (iview->image->info.samples > 1)
3760 ds->db_z_info |= S_028040_NUM_SAMPLES(util_logbase2(iview->image->info.samples));
3762 if (device->physical_device->rad_info.chip_class >= CIK) {
3763 struct radeon_info *info = &device->physical_device->rad_info;
3764 unsigned tiling_index = iview->image->surface.u.legacy.tiling_index[level];
3765 unsigned stencil_index = iview->image->surface.u.legacy.stencil_tiling_index[level];
3766 unsigned macro_index = iview->image->surface.u.legacy.macro_tile_index;
3767 unsigned tile_mode = info->si_tile_mode_array[tiling_index];
3768 unsigned stencil_tile_mode = info->si_tile_mode_array[stencil_index];
3769 unsigned macro_mode = info->cik_macrotile_mode_array[macro_index];
3772 tile_mode = stencil_tile_mode;
3774 ds->db_depth_info |=
3775 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode)) |
3776 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode)) |
3777 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode)) |
3778 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode)) |
3779 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode)) |
3780 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode));
3781 ds->db_z_info |= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode));
3782 ds->db_stencil_info |= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode));
3784 unsigned tile_mode_index = si_tile_mode_index(iview->image, level, false);
3785 ds->db_z_info |= S_028040_TILE_MODE_INDEX(tile_mode_index);
3786 tile_mode_index = si_tile_mode_index(iview->image, level, true);
3787 ds->db_stencil_info |= S_028044_TILE_MODE_INDEX(tile_mode_index);
3789 ds->db_z_info |= S_028040_TILE_MODE_INDEX(tile_mode_index);
3792 ds->db_depth_size = S_028058_PITCH_TILE_MAX((level_info->nblk_x / 8) - 1) |
3793 S_028058_HEIGHT_TILE_MAX((level_info->nblk_y / 8) - 1);
3794 ds->db_depth_slice = S_02805C_SLICE_TILE_MAX((level_info->nblk_x * level_info->nblk_y) / 64 - 1);
3796 if (radv_htile_enabled(iview->image, level)) {
3797 ds->db_z_info |= S_028040_TILE_SURFACE_ENABLE(1);
3799 if (!iview->image->surface.has_stencil &&
3800 !iview->image->tc_compatible_htile)
3801 /* Use all of the htile_buffer for depth if there's no stencil. */
3802 ds->db_stencil_info |= S_028044_TILE_STENCIL_DISABLE(1);
3804 va = radv_buffer_get_va(iview->bo) + iview->image->offset +
3805 iview->image->htile_offset;
3806 ds->db_htile_data_base = va >> 8;
3807 ds->db_htile_surface = S_028ABC_FULL_CACHE(1);
3809 if (iview->image->tc_compatible_htile) {
3810 unsigned max_zplanes =
3811 radv_calc_decompress_on_z_planes(device, iview);
3813 ds->db_htile_surface |= S_028ABC_TC_COMPATIBLE(1);
3814 ds->db_z_info |= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes);
3819 ds->db_z_read_base = ds->db_z_write_base = z_offs >> 8;
3820 ds->db_stencil_read_base = ds->db_stencil_write_base = s_offs >> 8;
3823 VkResult radv_CreateFramebuffer(
3825 const VkFramebufferCreateInfo* pCreateInfo,
3826 const VkAllocationCallbacks* pAllocator,
3827 VkFramebuffer* pFramebuffer)
3829 RADV_FROM_HANDLE(radv_device, device, _device);
3830 struct radv_framebuffer *framebuffer;
3832 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
3834 size_t size = sizeof(*framebuffer) +
3835 sizeof(struct radv_attachment_info) * pCreateInfo->attachmentCount;
3836 framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8,
3837 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
3838 if (framebuffer == NULL)
3839 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
3841 framebuffer->attachment_count = pCreateInfo->attachmentCount;
3842 framebuffer->width = pCreateInfo->width;
3843 framebuffer->height = pCreateInfo->height;
3844 framebuffer->layers = pCreateInfo->layers;
3845 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
3846 VkImageView _iview = pCreateInfo->pAttachments[i];
3847 struct radv_image_view *iview = radv_image_view_from_handle(_iview);
3848 framebuffer->attachments[i].attachment = iview;
3849 if (iview->aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) {
3850 radv_initialise_color_surface(device, &framebuffer->attachments[i].cb, iview);
3851 } else if (iview->aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
3852 radv_initialise_ds_surface(device, &framebuffer->attachments[i].ds, iview);
3854 framebuffer->width = MIN2(framebuffer->width, iview->extent.width);
3855 framebuffer->height = MIN2(framebuffer->height, iview->extent.height);
3856 framebuffer->layers = MIN2(framebuffer->layers, radv_surface_max_layer_count(iview));
3859 *pFramebuffer = radv_framebuffer_to_handle(framebuffer);
3863 void radv_DestroyFramebuffer(
3866 const VkAllocationCallbacks* pAllocator)
3868 RADV_FROM_HANDLE(radv_device, device, _device);
3869 RADV_FROM_HANDLE(radv_framebuffer, fb, _fb);
3873 vk_free2(&device->alloc, pAllocator, fb);
3876 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode)
3878 switch (address_mode) {
3879 case VK_SAMPLER_ADDRESS_MODE_REPEAT:
3880 return V_008F30_SQ_TEX_WRAP;
3881 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT:
3882 return V_008F30_SQ_TEX_MIRROR;
3883 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE:
3884 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL;
3885 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER:
3886 return V_008F30_SQ_TEX_CLAMP_BORDER;
3887 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE:
3888 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL;
3890 unreachable("illegal tex wrap mode");
3896 radv_tex_compare(VkCompareOp op)
3899 case VK_COMPARE_OP_NEVER:
3900 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER;
3901 case VK_COMPARE_OP_LESS:
3902 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS;
3903 case VK_COMPARE_OP_EQUAL:
3904 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL;
3905 case VK_COMPARE_OP_LESS_OR_EQUAL:
3906 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL;
3907 case VK_COMPARE_OP_GREATER:
3908 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER;
3909 case VK_COMPARE_OP_NOT_EQUAL:
3910 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL;
3911 case VK_COMPARE_OP_GREATER_OR_EQUAL:
3912 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL;
3913 case VK_COMPARE_OP_ALWAYS:
3914 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS;
3916 unreachable("illegal compare mode");
3922 radv_tex_filter(VkFilter filter, unsigned max_ansio)
3925 case VK_FILTER_NEAREST:
3926 return (max_ansio > 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT :
3927 V_008F38_SQ_TEX_XY_FILTER_POINT);
3928 case VK_FILTER_LINEAR:
3929 return (max_ansio > 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR :
3930 V_008F38_SQ_TEX_XY_FILTER_BILINEAR);
3931 case VK_FILTER_CUBIC_IMG:
3933 fprintf(stderr, "illegal texture filter");
3939 radv_tex_mipfilter(VkSamplerMipmapMode mode)
3942 case VK_SAMPLER_MIPMAP_MODE_NEAREST:
3943 return V_008F38_SQ_TEX_Z_FILTER_POINT;
3944 case VK_SAMPLER_MIPMAP_MODE_LINEAR:
3945 return V_008F38_SQ_TEX_Z_FILTER_LINEAR;
3947 return V_008F38_SQ_TEX_Z_FILTER_NONE;
3952 radv_tex_bordercolor(VkBorderColor bcolor)
3955 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
3956 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
3957 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK;
3958 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
3959 case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
3960 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK;
3961 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
3962 case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
3963 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE;
3971 radv_tex_aniso_filter(unsigned filter)
3985 radv_tex_filter_mode(VkSamplerReductionModeEXT mode)
3988 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT:
3989 return SQ_IMG_FILTER_MODE_BLEND;
3990 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT:
3991 return SQ_IMG_FILTER_MODE_MIN;
3992 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT:
3993 return SQ_IMG_FILTER_MODE_MAX;
4001 radv_init_sampler(struct radv_device *device,
4002 struct radv_sampler *sampler,
4003 const VkSamplerCreateInfo *pCreateInfo)
4005 uint32_t max_aniso = pCreateInfo->anisotropyEnable && pCreateInfo->maxAnisotropy > 1.0 ?
4006 (uint32_t) pCreateInfo->maxAnisotropy : 0;
4007 uint32_t max_aniso_ratio = radv_tex_aniso_filter(max_aniso);
4008 bool is_vi = (device->physical_device->rad_info.chip_class >= VI);
4009 unsigned filter_mode = SQ_IMG_FILTER_MODE_BLEND;
4011 const struct VkSamplerReductionModeCreateInfoEXT *sampler_reduction =
4012 vk_find_struct_const(pCreateInfo->pNext,
4013 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT);
4014 if (sampler_reduction)
4015 filter_mode = radv_tex_filter_mode(sampler_reduction->reductionMode);
4017 sampler->state[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo->addressModeU)) |
4018 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo->addressModeV)) |
4019 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo->addressModeW)) |
4020 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio) |
4021 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo->compareOp)) |
4022 S_008F30_FORCE_UNNORMALIZED(pCreateInfo->unnormalizedCoordinates ? 1 : 0) |
4023 S_008F30_ANISO_THRESHOLD(max_aniso_ratio >> 1) |
4024 S_008F30_ANISO_BIAS(max_aniso_ratio) |
4025 S_008F30_DISABLE_CUBE_WRAP(0) |
4026 S_008F30_COMPAT_MODE(is_vi) |
4027 S_008F30_FILTER_MODE(filter_mode));
4028 sampler->state[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo->minLod, 0, 15), 8)) |
4029 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo->maxLod, 0, 15), 8)) |
4030 S_008F34_PERF_MIP(max_aniso_ratio ? max_aniso_ratio + 6 : 0));
4031 sampler->state[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo->mipLodBias, -16, 16), 8)) |
4032 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo->magFilter, max_aniso)) |
4033 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo->minFilter, max_aniso)) |
4034 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo->mipmapMode)) |
4035 S_008F38_MIP_POINT_PRECLAMP(0) |
4036 S_008F38_DISABLE_LSB_CEIL(device->physical_device->rad_info.chip_class <= VI) |
4037 S_008F38_FILTER_PREC_FIX(1) |
4038 S_008F38_ANISO_OVERRIDE(is_vi));
4039 sampler->state[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4040 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo->borderColor)));
4043 VkResult radv_CreateSampler(
4045 const VkSamplerCreateInfo* pCreateInfo,
4046 const VkAllocationCallbacks* pAllocator,
4047 VkSampler* pSampler)
4049 RADV_FROM_HANDLE(radv_device, device, _device);
4050 struct radv_sampler *sampler;
4052 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
4054 sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
4055 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
4057 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
4059 radv_init_sampler(device, sampler, pCreateInfo);
4060 *pSampler = radv_sampler_to_handle(sampler);
4065 void radv_DestroySampler(
4068 const VkAllocationCallbacks* pAllocator)
4070 RADV_FROM_HANDLE(radv_device, device, _device);
4071 RADV_FROM_HANDLE(radv_sampler, sampler, _sampler);
4075 vk_free2(&device->alloc, pAllocator, sampler);
4078 /* vk_icd.h does not declare this function, so we declare it here to
4079 * suppress Wmissing-prototypes.
4081 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4082 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion);
4084 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4085 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion)
4087 /* For the full details on loader interface versioning, see
4088 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4089 * What follows is a condensed summary, to help you navigate the large and
4090 * confusing official doc.
4092 * - Loader interface v0 is incompatible with later versions. We don't
4095 * - In loader interface v1:
4096 * - The first ICD entrypoint called by the loader is
4097 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4099 * - The ICD must statically expose no other Vulkan symbol unless it is
4100 * linked with -Bsymbolic.
4101 * - Each dispatchable Vulkan handle created by the ICD must be
4102 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4103 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4104 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4105 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4106 * such loader-managed surfaces.
4108 * - Loader interface v2 differs from v1 in:
4109 * - The first ICD entrypoint called by the loader is
4110 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4111 * statically expose this entrypoint.
4113 * - Loader interface v3 differs from v2 in:
4114 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4115 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4116 * because the loader no longer does so.
4118 *pSupportedVersion = MIN2(*pSupportedVersion, 3u);
4122 VkResult radv_GetMemoryFdKHR(VkDevice _device,
4123 const VkMemoryGetFdInfoKHR *pGetFdInfo,
4126 RADV_FROM_HANDLE(radv_device, device, _device);
4127 RADV_FROM_HANDLE(radv_device_memory, memory, pGetFdInfo->memory);
4129 assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
4131 /* At the moment, we support only the below handle types. */
4132 assert(pGetFdInfo->handleType ==
4133 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR ||
4134 pGetFdInfo->handleType ==
4135 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
4137 bool ret = radv_get_memory_fd(device, memory, pFD);
4139 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
4143 VkResult radv_GetMemoryFdPropertiesKHR(VkDevice _device,
4144 VkExternalMemoryHandleTypeFlagBitsKHR handleType,
4146 VkMemoryFdPropertiesKHR *pMemoryFdProperties)
4148 switch (handleType) {
4149 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
4150 pMemoryFdProperties->memoryTypeBits = (1 << RADV_MEM_TYPE_COUNT) - 1;
4154 /* The valid usage section for this function says:
4156 * "handleType must not be one of the handle types defined as
4159 * So opaque handle types fall into the default "unsupported" case.
4161 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
4165 static VkResult radv_import_opaque_fd(struct radv_device *device,
4169 uint32_t syncobj_handle = 0;
4170 int ret = device->ws->import_syncobj(device->ws, fd, &syncobj_handle);
4172 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
4175 device->ws->destroy_syncobj(device->ws, *syncobj);
4177 *syncobj = syncobj_handle;
4183 static VkResult radv_import_sync_fd(struct radv_device *device,
4187 /* If we create a syncobj we do it locally so that if we have an error, we don't
4188 * leave a syncobj in an undetermined state in the fence. */
4189 uint32_t syncobj_handle = *syncobj;
4190 if (!syncobj_handle) {
4191 int ret = device->ws->create_syncobj(device->ws, &syncobj_handle);
4193 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
4198 device->ws->signal_syncobj(device->ws, syncobj_handle);
4200 int ret = device->ws->import_syncobj_from_sync_file(device->ws, syncobj_handle, fd);
4202 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
4205 *syncobj = syncobj_handle;
4212 VkResult radv_ImportSemaphoreFdKHR(VkDevice _device,
4213 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo)
4215 RADV_FROM_HANDLE(radv_device, device, _device);
4216 RADV_FROM_HANDLE(radv_semaphore, sem, pImportSemaphoreFdInfo->semaphore);
4217 uint32_t *syncobj_dst = NULL;
4219 if (pImportSemaphoreFdInfo->flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR) {
4220 syncobj_dst = &sem->temp_syncobj;
4222 syncobj_dst = &sem->syncobj;
4225 switch(pImportSemaphoreFdInfo->handleType) {
4226 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
4227 return radv_import_opaque_fd(device, pImportSemaphoreFdInfo->fd, syncobj_dst);
4228 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR:
4229 return radv_import_sync_fd(device, pImportSemaphoreFdInfo->fd, syncobj_dst);
4231 unreachable("Unhandled semaphore handle type");
4235 VkResult radv_GetSemaphoreFdKHR(VkDevice _device,
4236 const VkSemaphoreGetFdInfoKHR *pGetFdInfo,
4239 RADV_FROM_HANDLE(radv_device, device, _device);
4240 RADV_FROM_HANDLE(radv_semaphore, sem, pGetFdInfo->semaphore);
4242 uint32_t syncobj_handle;
4244 if (sem->temp_syncobj)
4245 syncobj_handle = sem->temp_syncobj;
4247 syncobj_handle = sem->syncobj;
4249 switch(pGetFdInfo->handleType) {
4250 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
4251 ret = device->ws->export_syncobj(device->ws, syncobj_handle, pFd);
4253 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR:
4254 ret = device->ws->export_syncobj_to_sync_file(device->ws, syncobj_handle, pFd);
4256 if (sem->temp_syncobj) {
4257 close (sem->temp_syncobj);
4258 sem->temp_syncobj = 0;
4260 device->ws->reset_syncobj(device->ws, syncobj_handle);
4265 unreachable("Unhandled semaphore handle type");
4269 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
4273 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4274 VkPhysicalDevice physicalDevice,
4275 const VkPhysicalDeviceExternalSemaphoreInfoKHR* pExternalSemaphoreInfo,
4276 VkExternalSemaphorePropertiesKHR* pExternalSemaphoreProperties)
4278 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
4280 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4281 if (pdevice->rad_info.has_syncobj_wait_for_submit &&
4282 (pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR ||
4283 pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR)) {
4284 pExternalSemaphoreProperties->exportFromImportedHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR | VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
4285 pExternalSemaphoreProperties->compatibleHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR | VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
4286 pExternalSemaphoreProperties->externalSemaphoreFeatures = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR |
4287 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR;
4288 } else if (pExternalSemaphoreInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR) {
4289 pExternalSemaphoreProperties->exportFromImportedHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
4290 pExternalSemaphoreProperties->compatibleHandleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
4291 pExternalSemaphoreProperties->externalSemaphoreFeatures = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR |
4292 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR;
4294 pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
4295 pExternalSemaphoreProperties->compatibleHandleTypes = 0;
4296 pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
4300 VkResult radv_ImportFenceFdKHR(VkDevice _device,
4301 const VkImportFenceFdInfoKHR *pImportFenceFdInfo)
4303 RADV_FROM_HANDLE(radv_device, device, _device);
4304 RADV_FROM_HANDLE(radv_fence, fence, pImportFenceFdInfo->fence);
4305 uint32_t *syncobj_dst = NULL;
4308 if (pImportFenceFdInfo->flags & VK_FENCE_IMPORT_TEMPORARY_BIT_KHR) {
4309 syncobj_dst = &fence->temp_syncobj;
4311 syncobj_dst = &fence->syncobj;
4314 switch(pImportFenceFdInfo->handleType) {
4315 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
4316 return radv_import_opaque_fd(device, pImportFenceFdInfo->fd, syncobj_dst);
4317 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR:
4318 return radv_import_sync_fd(device, pImportFenceFdInfo->fd, syncobj_dst);
4320 unreachable("Unhandled fence handle type");
4324 VkResult radv_GetFenceFdKHR(VkDevice _device,
4325 const VkFenceGetFdInfoKHR *pGetFdInfo,
4328 RADV_FROM_HANDLE(radv_device, device, _device);
4329 RADV_FROM_HANDLE(radv_fence, fence, pGetFdInfo->fence);
4331 uint32_t syncobj_handle;
4333 if (fence->temp_syncobj)
4334 syncobj_handle = fence->temp_syncobj;
4336 syncobj_handle = fence->syncobj;
4338 switch(pGetFdInfo->handleType) {
4339 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
4340 ret = device->ws->export_syncobj(device->ws, syncobj_handle, pFd);
4342 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR:
4343 ret = device->ws->export_syncobj_to_sync_file(device->ws, syncobj_handle, pFd);
4345 if (fence->temp_syncobj) {
4346 close (fence->temp_syncobj);
4347 fence->temp_syncobj = 0;
4349 device->ws->reset_syncobj(device->ws, syncobj_handle);
4354 unreachable("Unhandled fence handle type");
4358 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
4362 void radv_GetPhysicalDeviceExternalFenceProperties(
4363 VkPhysicalDevice physicalDevice,
4364 const VkPhysicalDeviceExternalFenceInfoKHR* pExternalFenceInfo,
4365 VkExternalFencePropertiesKHR* pExternalFenceProperties)
4367 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
4369 if (pdevice->rad_info.has_syncobj_wait_for_submit &&
4370 (pExternalFenceInfo->handleType == VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR ||
4371 pExternalFenceInfo->handleType == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR)) {
4372 pExternalFenceProperties->exportFromImportedHandleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR | VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
4373 pExternalFenceProperties->compatibleHandleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR | VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
4374 pExternalFenceProperties->externalFenceFeatures = VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR |
4375 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR;
4377 pExternalFenceProperties->exportFromImportedHandleTypes = 0;
4378 pExternalFenceProperties->compatibleHandleTypes = 0;
4379 pExternalFenceProperties->externalFenceFeatures = 0;
4384 radv_CreateDebugReportCallbackEXT(VkInstance _instance,
4385 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
4386 const VkAllocationCallbacks* pAllocator,
4387 VkDebugReportCallbackEXT* pCallback)
4389 RADV_FROM_HANDLE(radv_instance, instance, _instance);
4390 return vk_create_debug_report_callback(&instance->debug_report_callbacks,
4391 pCreateInfo, pAllocator, &instance->alloc,
4396 radv_DestroyDebugReportCallbackEXT(VkInstance _instance,
4397 VkDebugReportCallbackEXT _callback,
4398 const VkAllocationCallbacks* pAllocator)
4400 RADV_FROM_HANDLE(radv_instance, instance, _instance);
4401 vk_destroy_debug_report_callback(&instance->debug_report_callbacks,
4402 _callback, pAllocator, &instance->alloc);
4406 radv_DebugReportMessageEXT(VkInstance _instance,
4407 VkDebugReportFlagsEXT flags,
4408 VkDebugReportObjectTypeEXT objectType,
4411 int32_t messageCode,
4412 const char* pLayerPrefix,
4413 const char* pMessage)
4415 RADV_FROM_HANDLE(radv_instance, instance, _instance);
4416 vk_debug_report(&instance->debug_report_callbacks, flags, objectType,
4417 object, location, messageCode, pLayerPrefix, pMessage);
4421 radv_GetDeviceGroupPeerMemoryFeatures(
4424 uint32_t localDeviceIndex,
4425 uint32_t remoteDeviceIndex,
4426 VkPeerMemoryFeatureFlags* pPeerMemoryFeatures)
4428 assert(localDeviceIndex == remoteDeviceIndex);
4430 *pPeerMemoryFeatures = VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT |
4431 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT |
4432 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT |
4433 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT;