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 "util/debug.h"
50 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
52 uint32_t mesa_timestamp
, llvm_timestamp
;
54 memset(uuid
, 0, VK_UUID_SIZE
);
55 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
56 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
59 memcpy(uuid
, &mesa_timestamp
, 4);
60 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
61 memcpy((char*)uuid
+ 8, &f
, 2);
62 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
67 radv_get_driver_uuid(void *uuid
)
69 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
73 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
75 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
79 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
81 const char *chip_string
;
82 char llvm_string
[32] = {};
85 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
86 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
87 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
88 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
89 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
90 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
91 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
92 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
93 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
94 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
95 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
96 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
97 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
98 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
99 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
100 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
101 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
102 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
103 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA"; break;
104 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
105 default: chip_string
= "AMD RADV unknown"; break;
109 snprintf(llvm_string
, sizeof(llvm_string
),
110 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
111 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
114 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
118 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
120 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
121 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
122 device
->rad_info
.vram_vis_size
);
124 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
125 device
->memory_properties
.memoryHeapCount
= 0;
126 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
127 vram_index
= device
->memory_properties
.memoryHeapCount
++;
128 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
129 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
130 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
133 if (visible_vram_size
) {
134 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
135 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
136 .size
= visible_vram_size
,
137 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
140 if (device
->rad_info
.gart_size
> 0) {
141 gart_index
= device
->memory_properties
.memoryHeapCount
++;
142 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
143 .size
= device
->rad_info
.gart_size
,
148 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
149 unsigned type_count
= 0;
150 if (vram_index
>= 0) {
151 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
152 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
153 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
154 .heapIndex
= vram_index
,
157 if (gart_index
>= 0) {
158 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
159 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
160 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
161 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
162 .heapIndex
= gart_index
,
165 if (visible_vram_index
>= 0) {
166 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
167 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
168 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
169 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
170 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
171 .heapIndex
= visible_vram_index
,
174 if (gart_index
>= 0) {
175 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
176 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
177 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
178 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
179 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
180 .heapIndex
= gart_index
,
183 device
->memory_properties
.memoryTypeCount
= type_count
;
187 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
189 const char *family
= getenv("RADV_FORCE_FAMILY");
195 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
196 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
197 /* Override family and chip_class. */
198 device
->rad_info
.family
= i
;
200 if (i
>= CHIP_VEGA10
)
201 device
->rad_info
.chip_class
= GFX9
;
202 else if (i
>= CHIP_TONGA
)
203 device
->rad_info
.chip_class
= VI
;
204 else if (i
>= CHIP_BONAIRE
)
205 device
->rad_info
.chip_class
= CIK
;
207 device
->rad_info
.chip_class
= SI
;
213 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
218 radv_physical_device_init(struct radv_physical_device
*device
,
219 struct radv_instance
*instance
,
220 drmDevicePtr drm_device
)
222 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
224 drmVersionPtr version
;
227 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
229 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
231 version
= drmGetVersion(fd
);
234 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
235 "failed to get version %s: %m", path
);
238 if (strcmp(version
->name
, "amdgpu")) {
239 drmFreeVersion(version
);
241 return VK_ERROR_INCOMPATIBLE_DRIVER
;
243 drmFreeVersion(version
);
245 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
246 device
->instance
= instance
;
247 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
248 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
250 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
251 instance
->perftest_flags
);
253 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
257 device
->local_fd
= fd
;
258 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
260 radv_handle_env_var_force_family(device
);
262 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
264 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
265 device
->ws
->destroy(device
->ws
);
266 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
267 "cannot generate UUID");
271 /* These flags affect shader compilation. */
272 uint64_t shader_env_flags
=
273 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
274 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
276 /* The gpu id is already embeded in the uuid so we just pass "radv"
277 * when creating the cache.
279 char buf
[VK_UUID_SIZE
* 2 + 1];
280 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
281 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
283 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
285 radv_get_driver_uuid(&device
->device_uuid
);
286 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
288 if (device
->rad_info
.family
== CHIP_STONEY
||
289 device
->rad_info
.chip_class
>= GFX9
) {
290 device
->has_rbplus
= true;
291 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
294 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
297 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
299 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
301 /* Vega10/Raven need a special workaround for a hardware bug. */
302 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
303 device
->rad_info
.family
== CHIP_RAVEN
;
305 radv_physical_device_init_mem_types(device
);
307 result
= radv_init_wsi(device
);
308 if (result
!= VK_SUCCESS
) {
309 device
->ws
->destroy(device
->ws
);
321 radv_physical_device_finish(struct radv_physical_device
*device
)
323 radv_finish_wsi(device
);
324 device
->ws
->destroy(device
->ws
);
325 disk_cache_destroy(device
->disk_cache
);
326 close(device
->local_fd
);
330 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
331 VkSystemAllocationScope allocationScope
)
337 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
338 size_t align
, VkSystemAllocationScope allocationScope
)
340 return realloc(pOriginal
, size
);
344 default_free_func(void *pUserData
, void *pMemory
)
349 static const VkAllocationCallbacks default_alloc
= {
351 .pfnAllocation
= default_alloc_func
,
352 .pfnReallocation
= default_realloc_func
,
353 .pfnFree
= default_free_func
,
356 static const struct debug_control radv_debug_options
[] = {
357 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
358 {"nodcc", RADV_DEBUG_NO_DCC
},
359 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
360 {"nocache", RADV_DEBUG_NO_CACHE
},
361 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
362 {"nohiz", RADV_DEBUG_NO_HIZ
},
363 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
364 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
365 {"allbos", RADV_DEBUG_ALL_BOS
},
366 {"noibs", RADV_DEBUG_NO_IBS
},
367 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
368 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
369 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
370 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
371 {"nosisched", RADV_DEBUG_NO_SISCHED
},
372 {"preoptir", RADV_DEBUG_PREOPTIR
},
377 radv_get_debug_option_name(int id
)
379 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
380 return radv_debug_options
[id
].string
;
383 static const struct debug_control radv_perftest_options
[] = {
384 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
385 {"sisched", RADV_PERFTEST_SISCHED
},
386 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
387 {"binning", RADV_PERFTEST_BINNING
},
392 radv_get_perftest_option_name(int id
)
394 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
395 return radv_perftest_options
[id
].string
;
399 radv_handle_per_app_options(struct radv_instance
*instance
,
400 const VkApplicationInfo
*info
)
402 const char *name
= info
? info
->pApplicationName
: NULL
;
407 if (!strcmp(name
, "Talos - Linux - 32bit") ||
408 !strcmp(name
, "Talos - Linux - 64bit")) {
409 /* Force enable LLVM sisched for Talos because it looks safe
410 * and it gives few more FPS.
412 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
416 VkResult
radv_CreateInstance(
417 const VkInstanceCreateInfo
* pCreateInfo
,
418 const VkAllocationCallbacks
* pAllocator
,
419 VkInstance
* pInstance
)
421 struct radv_instance
*instance
;
424 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
426 uint32_t client_version
;
427 if (pCreateInfo
->pApplicationInfo
&&
428 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
429 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
431 client_version
= VK_MAKE_VERSION(1, 0, 0);
434 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
435 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
436 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
437 "Client requested version %d.%d.%d",
438 VK_VERSION_MAJOR(client_version
),
439 VK_VERSION_MINOR(client_version
),
440 VK_VERSION_PATCH(client_version
));
443 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
444 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
445 if (!radv_instance_extension_supported(ext_name
))
446 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
449 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
450 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
452 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
454 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
457 instance
->alloc
= *pAllocator
;
459 instance
->alloc
= default_alloc
;
461 instance
->apiVersion
= client_version
;
462 instance
->physicalDeviceCount
= -1;
464 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
465 if (result
!= VK_SUCCESS
) {
466 vk_free2(&default_alloc
, pAllocator
, instance
);
467 return vk_error(result
);
472 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
474 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
477 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
478 radv_perftest_options
);
480 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
482 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
483 /* Disable sisched when the user requests it, this is mostly
484 * useful when the driver force-enable sisched for the given
487 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
490 *pInstance
= radv_instance_to_handle(instance
);
495 void radv_DestroyInstance(
496 VkInstance _instance
,
497 const VkAllocationCallbacks
* pAllocator
)
499 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
504 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
505 radv_physical_device_finish(instance
->physicalDevices
+ i
);
508 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
512 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
514 vk_free(&instance
->alloc
, instance
);
518 radv_enumerate_devices(struct radv_instance
*instance
)
520 /* TODO: Check for more devices ? */
521 drmDevicePtr devices
[8];
522 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
525 instance
->physicalDeviceCount
= 0;
527 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
529 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
531 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
532 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
533 devices
[i
]->bustype
== DRM_BUS_PCI
&&
534 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
536 result
= radv_physical_device_init(instance
->physicalDevices
+
537 instance
->physicalDeviceCount
,
540 if (result
== VK_SUCCESS
)
541 ++instance
->physicalDeviceCount
;
542 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
546 drmFreeDevices(devices
, max_devices
);
551 VkResult
radv_EnumeratePhysicalDevices(
552 VkInstance _instance
,
553 uint32_t* pPhysicalDeviceCount
,
554 VkPhysicalDevice
* pPhysicalDevices
)
556 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
559 if (instance
->physicalDeviceCount
< 0) {
560 result
= radv_enumerate_devices(instance
);
561 if (result
!= VK_SUCCESS
&&
562 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
566 if (!pPhysicalDevices
) {
567 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
569 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
570 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
571 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
574 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
578 void radv_GetPhysicalDeviceFeatures(
579 VkPhysicalDevice physicalDevice
,
580 VkPhysicalDeviceFeatures
* pFeatures
)
582 memset(pFeatures
, 0, sizeof(*pFeatures
));
584 *pFeatures
= (VkPhysicalDeviceFeatures
) {
585 .robustBufferAccess
= true,
586 .fullDrawIndexUint32
= true,
587 .imageCubeArray
= true,
588 .independentBlend
= true,
589 .geometryShader
= true,
590 .tessellationShader
= true,
591 .sampleRateShading
= true,
592 .dualSrcBlend
= true,
594 .multiDrawIndirect
= true,
595 .drawIndirectFirstInstance
= true,
597 .depthBiasClamp
= true,
598 .fillModeNonSolid
= true,
603 .multiViewport
= true,
604 .samplerAnisotropy
= true,
605 .textureCompressionETC2
= false,
606 .textureCompressionASTC_LDR
= false,
607 .textureCompressionBC
= true,
608 .occlusionQueryPrecise
= true,
609 .pipelineStatisticsQuery
= true,
610 .vertexPipelineStoresAndAtomics
= true,
611 .fragmentStoresAndAtomics
= true,
612 .shaderTessellationAndGeometryPointSize
= true,
613 .shaderImageGatherExtended
= true,
614 .shaderStorageImageExtendedFormats
= true,
615 .shaderStorageImageMultisample
= false,
616 .shaderUniformBufferArrayDynamicIndexing
= true,
617 .shaderSampledImageArrayDynamicIndexing
= true,
618 .shaderStorageBufferArrayDynamicIndexing
= true,
619 .shaderStorageImageArrayDynamicIndexing
= true,
620 .shaderStorageImageReadWithoutFormat
= true,
621 .shaderStorageImageWriteWithoutFormat
= true,
622 .shaderClipDistance
= true,
623 .shaderCullDistance
= true,
624 .shaderFloat64
= true,
626 .shaderInt16
= false,
627 .sparseBinding
= true,
628 .variableMultisampleRate
= true,
629 .inheritedQueries
= true,
633 void radv_GetPhysicalDeviceFeatures2KHR(
634 VkPhysicalDevice physicalDevice
,
635 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
637 vk_foreach_struct(ext
, pFeatures
->pNext
) {
638 switch (ext
->sType
) {
639 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
640 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
641 features
->variablePointersStorageBuffer
= true;
642 features
->variablePointers
= false;
645 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
646 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
647 features
->multiview
= true;
648 features
->multiviewGeometryShader
= true;
649 features
->multiviewTessellationShader
= true;
656 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
659 void radv_GetPhysicalDeviceProperties(
660 VkPhysicalDevice physicalDevice
,
661 VkPhysicalDeviceProperties
* pProperties
)
663 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
664 VkSampleCountFlags sample_counts
= 0xf;
666 /* make sure that the entire descriptor set is addressable with a signed
667 * 32-bit int. So the sum of all limits scaled by descriptor size has to
668 * be at most 2 GiB. the combined image & samples object count as one of
669 * both. This limit is for the pipeline layout, not for the set layout, but
670 * there is no set limit, so we just set a pipeline limit. I don't think
671 * any app is going to hit this soon. */
672 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
673 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
674 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
675 32 /* sampler, largest when combined with image */ +
676 64 /* sampled image */ +
677 64 /* storage image */);
679 VkPhysicalDeviceLimits limits
= {
680 .maxImageDimension1D
= (1 << 14),
681 .maxImageDimension2D
= (1 << 14),
682 .maxImageDimension3D
= (1 << 11),
683 .maxImageDimensionCube
= (1 << 14),
684 .maxImageArrayLayers
= (1 << 11),
685 .maxTexelBufferElements
= 128 * 1024 * 1024,
686 .maxUniformBufferRange
= UINT32_MAX
,
687 .maxStorageBufferRange
= UINT32_MAX
,
688 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
689 .maxMemoryAllocationCount
= UINT32_MAX
,
690 .maxSamplerAllocationCount
= 64 * 1024,
691 .bufferImageGranularity
= 64, /* A cache line */
692 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
693 .maxBoundDescriptorSets
= MAX_SETS
,
694 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
695 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
696 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
697 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
698 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
699 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
700 .maxPerStageResources
= max_descriptor_set_size
,
701 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
702 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
703 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
704 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
705 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
706 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
707 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
708 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
709 .maxVertexInputAttributes
= 32,
710 .maxVertexInputBindings
= 32,
711 .maxVertexInputAttributeOffset
= 2047,
712 .maxVertexInputBindingStride
= 2048,
713 .maxVertexOutputComponents
= 128,
714 .maxTessellationGenerationLevel
= 64,
715 .maxTessellationPatchSize
= 32,
716 .maxTessellationControlPerVertexInputComponents
= 128,
717 .maxTessellationControlPerVertexOutputComponents
= 128,
718 .maxTessellationControlPerPatchOutputComponents
= 120,
719 .maxTessellationControlTotalOutputComponents
= 4096,
720 .maxTessellationEvaluationInputComponents
= 128,
721 .maxTessellationEvaluationOutputComponents
= 128,
722 .maxGeometryShaderInvocations
= 127,
723 .maxGeometryInputComponents
= 64,
724 .maxGeometryOutputComponents
= 128,
725 .maxGeometryOutputVertices
= 256,
726 .maxGeometryTotalOutputComponents
= 1024,
727 .maxFragmentInputComponents
= 128,
728 .maxFragmentOutputAttachments
= 8,
729 .maxFragmentDualSrcAttachments
= 1,
730 .maxFragmentCombinedOutputResources
= 8,
731 .maxComputeSharedMemorySize
= 32768,
732 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
733 .maxComputeWorkGroupInvocations
= 2048,
734 .maxComputeWorkGroupSize
= {
739 .subPixelPrecisionBits
= 4 /* FIXME */,
740 .subTexelPrecisionBits
= 4 /* FIXME */,
741 .mipmapPrecisionBits
= 4 /* FIXME */,
742 .maxDrawIndexedIndexValue
= UINT32_MAX
,
743 .maxDrawIndirectCount
= UINT32_MAX
,
744 .maxSamplerLodBias
= 16,
745 .maxSamplerAnisotropy
= 16,
746 .maxViewports
= MAX_VIEWPORTS
,
747 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
748 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
749 .viewportSubPixelBits
= 13, /* We take a float? */
750 .minMemoryMapAlignment
= 4096, /* A page */
751 .minTexelBufferOffsetAlignment
= 1,
752 .minUniformBufferOffsetAlignment
= 4,
753 .minStorageBufferOffsetAlignment
= 4,
754 .minTexelOffset
= -32,
755 .maxTexelOffset
= 31,
756 .minTexelGatherOffset
= -32,
757 .maxTexelGatherOffset
= 31,
758 .minInterpolationOffset
= -2,
759 .maxInterpolationOffset
= 2,
760 .subPixelInterpolationOffsetBits
= 8,
761 .maxFramebufferWidth
= (1 << 14),
762 .maxFramebufferHeight
= (1 << 14),
763 .maxFramebufferLayers
= (1 << 10),
764 .framebufferColorSampleCounts
= sample_counts
,
765 .framebufferDepthSampleCounts
= sample_counts
,
766 .framebufferStencilSampleCounts
= sample_counts
,
767 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
768 .maxColorAttachments
= MAX_RTS
,
769 .sampledImageColorSampleCounts
= sample_counts
,
770 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
771 .sampledImageDepthSampleCounts
= sample_counts
,
772 .sampledImageStencilSampleCounts
= sample_counts
,
773 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
774 .maxSampleMaskWords
= 1,
775 .timestampComputeAndGraphics
= true,
776 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
777 .maxClipDistances
= 8,
778 .maxCullDistances
= 8,
779 .maxCombinedClipAndCullDistances
= 8,
780 .discreteQueuePriorities
= 1,
781 .pointSizeRange
= { 0.125, 255.875 },
782 .lineWidthRange
= { 0.0, 7.9921875 },
783 .pointSizeGranularity
= (1.0 / 8.0),
784 .lineWidthGranularity
= (1.0 / 128.0),
785 .strictLines
= false, /* FINISHME */
786 .standardSampleLocations
= true,
787 .optimalBufferCopyOffsetAlignment
= 128,
788 .optimalBufferCopyRowPitchAlignment
= 128,
789 .nonCoherentAtomSize
= 64,
792 *pProperties
= (VkPhysicalDeviceProperties
) {
793 .apiVersion
= radv_physical_device_api_version(pdevice
),
794 .driverVersion
= vk_get_driver_version(),
795 .vendorID
= ATI_VENDOR_ID
,
796 .deviceID
= pdevice
->rad_info
.pci_id
,
797 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
799 .sparseProperties
= {0},
802 strcpy(pProperties
->deviceName
, pdevice
->name
);
803 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
806 void radv_GetPhysicalDeviceProperties2KHR(
807 VkPhysicalDevice physicalDevice
,
808 VkPhysicalDeviceProperties2KHR
*pProperties
)
810 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
811 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
813 vk_foreach_struct(ext
, pProperties
->pNext
) {
814 switch (ext
->sType
) {
815 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
816 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
817 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
818 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
821 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
822 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
823 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
824 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
825 properties
->deviceLUIDValid
= false;
828 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
829 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
830 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
831 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
834 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
835 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
836 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
837 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
840 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
841 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
842 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
843 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
846 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
847 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
848 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
849 properties
->minImportedHostPointerAlignment
= 4096;
858 static void radv_get_physical_device_queue_family_properties(
859 struct radv_physical_device
* pdevice
,
861 VkQueueFamilyProperties
** pQueueFamilyProperties
)
863 int num_queue_families
= 1;
865 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
866 pdevice
->rad_info
.chip_class
>= CIK
&&
867 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
868 num_queue_families
++;
870 if (pQueueFamilyProperties
== NULL
) {
871 *pCount
= num_queue_families
;
880 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
881 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
882 VK_QUEUE_COMPUTE_BIT
|
883 VK_QUEUE_TRANSFER_BIT
|
884 VK_QUEUE_SPARSE_BINDING_BIT
,
886 .timestampValidBits
= 64,
887 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
892 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
893 pdevice
->rad_info
.chip_class
>= CIK
&&
894 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
896 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
897 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
898 VK_QUEUE_TRANSFER_BIT
|
899 VK_QUEUE_SPARSE_BINDING_BIT
,
900 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
901 .timestampValidBits
= 64,
902 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
910 void radv_GetPhysicalDeviceQueueFamilyProperties(
911 VkPhysicalDevice physicalDevice
,
913 VkQueueFamilyProperties
* pQueueFamilyProperties
)
915 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
916 if (!pQueueFamilyProperties
) {
917 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
920 VkQueueFamilyProperties
*properties
[] = {
921 pQueueFamilyProperties
+ 0,
922 pQueueFamilyProperties
+ 1,
923 pQueueFamilyProperties
+ 2,
925 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
926 assert(*pCount
<= 3);
929 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
930 VkPhysicalDevice physicalDevice
,
932 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
934 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
935 if (!pQueueFamilyProperties
) {
936 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
939 VkQueueFamilyProperties
*properties
[] = {
940 &pQueueFamilyProperties
[0].queueFamilyProperties
,
941 &pQueueFamilyProperties
[1].queueFamilyProperties
,
942 &pQueueFamilyProperties
[2].queueFamilyProperties
,
944 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
945 assert(*pCount
<= 3);
948 void radv_GetPhysicalDeviceMemoryProperties(
949 VkPhysicalDevice physicalDevice
,
950 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
952 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
954 *pMemoryProperties
= physical_device
->memory_properties
;
957 void radv_GetPhysicalDeviceMemoryProperties2KHR(
958 VkPhysicalDevice physicalDevice
,
959 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
961 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
962 &pMemoryProperties
->memoryProperties
);
965 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
967 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
968 const void *pHostPointer
,
969 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
971 RADV_FROM_HANDLE(radv_device
, device
, _device
);
975 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
976 const struct radv_physical_device
*physical_device
= device
->physical_device
;
977 uint32_t memoryTypeBits
= 0;
978 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
979 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
980 memoryTypeBits
= (1 << i
);
984 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
988 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
992 static enum radeon_ctx_priority
993 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
995 /* Default to MEDIUM when a specific global priority isn't requested */
997 return RADEON_CTX_PRIORITY_MEDIUM
;
999 switch(pObj
->globalPriority
) {
1000 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1001 return RADEON_CTX_PRIORITY_REALTIME
;
1002 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1003 return RADEON_CTX_PRIORITY_HIGH
;
1004 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1005 return RADEON_CTX_PRIORITY_MEDIUM
;
1006 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1007 return RADEON_CTX_PRIORITY_LOW
;
1009 unreachable("Illegal global priority value");
1010 return RADEON_CTX_PRIORITY_INVALID
;
1015 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1016 uint32_t queue_family_index
, int idx
,
1017 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1019 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1020 queue
->device
= device
;
1021 queue
->queue_family_index
= queue_family_index
;
1022 queue
->queue_idx
= idx
;
1023 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1025 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1027 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1033 radv_queue_finish(struct radv_queue
*queue
)
1036 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1038 if (queue
->initial_full_flush_preamble_cs
)
1039 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1040 if (queue
->initial_preamble_cs
)
1041 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1042 if (queue
->continue_preamble_cs
)
1043 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1044 if (queue
->descriptor_bo
)
1045 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1046 if (queue
->scratch_bo
)
1047 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1048 if (queue
->esgs_ring_bo
)
1049 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1050 if (queue
->gsvs_ring_bo
)
1051 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1052 if (queue
->tess_factor_ring_bo
)
1053 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
1054 if (queue
->tess_offchip_ring_bo
)
1055 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
1056 if (queue
->compute_scratch_bo
)
1057 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1061 radv_device_init_gs_info(struct radv_device
*device
)
1063 switch (device
->physical_device
->rad_info
.family
) {
1072 device
->gs_table_depth
= 16;
1081 case CHIP_POLARIS10
:
1082 case CHIP_POLARIS11
:
1083 case CHIP_POLARIS12
:
1086 device
->gs_table_depth
= 32;
1089 unreachable("unknown GPU");
1093 VkResult
radv_CreateDevice(
1094 VkPhysicalDevice physicalDevice
,
1095 const VkDeviceCreateInfo
* pCreateInfo
,
1096 const VkAllocationCallbacks
* pAllocator
,
1099 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1101 struct radv_device
*device
;
1103 bool keep_shader_info
= false;
1105 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1106 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1107 if (!radv_physical_device_extension_supported(physical_device
, ext_name
))
1108 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1110 if (strcmp(ext_name
, VK_AMD_SHADER_INFO_EXTENSION_NAME
) == 0)
1111 keep_shader_info
= true;
1114 /* Check enabled features */
1115 if (pCreateInfo
->pEnabledFeatures
) {
1116 VkPhysicalDeviceFeatures supported_features
;
1117 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1118 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1119 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1120 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1121 for (uint32_t i
= 0; i
< num_features
; i
++) {
1122 if (enabled_feature
[i
] && !supported_feature
[i
])
1123 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1127 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1129 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1131 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1133 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1134 device
->instance
= physical_device
->instance
;
1135 device
->physical_device
= physical_device
;
1137 device
->ws
= physical_device
->ws
;
1139 device
->alloc
= *pAllocator
;
1141 device
->alloc
= physical_device
->instance
->alloc
;
1143 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1144 list_inithead(&device
->shader_slabs
);
1146 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1147 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1148 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1149 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1150 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1152 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1154 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1155 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1156 if (!device
->queues
[qfi
]) {
1157 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1161 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1163 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1165 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1166 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
, global_priority
);
1167 if (result
!= VK_SUCCESS
)
1172 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1173 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1175 /* Disabled and not implemented for now. */
1176 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1179 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1182 device
->llvm_supports_spill
= true;
1184 /* The maximum number of scratch waves. Scratch space isn't divided
1185 * evenly between CUs. The number is only a function of the number of CUs.
1186 * We can decrease the constant to decrease the scratch buffer size.
1188 * sctx->scratch_waves must be >= the maximum posible size of
1189 * 1 threadgroup, so that the hw doesn't hang from being unable
1192 * The recommended value is 4 per CU at most. Higher numbers don't
1193 * bring much benefit, but they still occupy chip resources (think
1194 * async compute). I've seen ~2% performance difference between 4 and 32.
1196 uint32_t max_threads_per_block
= 2048;
1197 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1198 max_threads_per_block
/ 64);
1200 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
1201 S_00B800_FORCE_START_AT_000(1);
1203 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1204 /* If the KMD allows it (there is a KMD hw register for it),
1205 * allow launching waves out-of-order.
1207 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1210 radv_device_init_gs_info(device
);
1212 device
->tess_offchip_block_dw_size
=
1213 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1214 device
->has_distributed_tess
=
1215 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1216 device
->physical_device
->rad_info
.max_se
>= 2;
1218 if (getenv("RADV_TRACE_FILE")) {
1219 keep_shader_info
= true;
1221 if (!radv_init_trace(device
))
1225 device
->keep_shader_info
= keep_shader_info
;
1227 result
= radv_device_init_meta(device
);
1228 if (result
!= VK_SUCCESS
)
1231 radv_device_init_msaa(device
);
1233 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1234 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1236 case RADV_QUEUE_GENERAL
:
1237 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1238 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1239 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1241 case RADV_QUEUE_COMPUTE
:
1242 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1243 radeon_emit(device
->empty_cs
[family
], 0);
1246 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1249 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1250 cik_create_gfx_config(device
);
1252 VkPipelineCacheCreateInfo ci
;
1253 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1256 ci
.pInitialData
= NULL
;
1257 ci
.initialDataSize
= 0;
1259 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1261 if (result
!= VK_SUCCESS
)
1264 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1266 *pDevice
= radv_device_to_handle(device
);
1270 radv_device_finish_meta(device
);
1272 if (device
->trace_bo
)
1273 device
->ws
->buffer_destroy(device
->trace_bo
);
1275 if (device
->gfx_init
)
1276 device
->ws
->buffer_destroy(device
->gfx_init
);
1278 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1279 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1280 radv_queue_finish(&device
->queues
[i
][q
]);
1281 if (device
->queue_count
[i
])
1282 vk_free(&device
->alloc
, device
->queues
[i
]);
1285 vk_free(&device
->alloc
, device
);
1289 void radv_DestroyDevice(
1291 const VkAllocationCallbacks
* pAllocator
)
1293 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1298 if (device
->trace_bo
)
1299 device
->ws
->buffer_destroy(device
->trace_bo
);
1301 if (device
->gfx_init
)
1302 device
->ws
->buffer_destroy(device
->gfx_init
);
1304 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1305 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1306 radv_queue_finish(&device
->queues
[i
][q
]);
1307 if (device
->queue_count
[i
])
1308 vk_free(&device
->alloc
, device
->queues
[i
]);
1309 if (device
->empty_cs
[i
])
1310 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1312 radv_device_finish_meta(device
);
1314 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1315 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1317 radv_destroy_shader_slabs(device
);
1319 vk_free(&device
->alloc
, device
);
1322 VkResult
radv_EnumerateInstanceLayerProperties(
1323 uint32_t* pPropertyCount
,
1324 VkLayerProperties
* pProperties
)
1326 if (pProperties
== NULL
) {
1327 *pPropertyCount
= 0;
1331 /* None supported at this time */
1332 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1335 VkResult
radv_EnumerateDeviceLayerProperties(
1336 VkPhysicalDevice physicalDevice
,
1337 uint32_t* pPropertyCount
,
1338 VkLayerProperties
* pProperties
)
1340 if (pProperties
== NULL
) {
1341 *pPropertyCount
= 0;
1345 /* None supported at this time */
1346 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1349 void radv_GetDeviceQueue(
1351 uint32_t queueFamilyIndex
,
1352 uint32_t queueIndex
,
1355 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1357 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1361 fill_geom_tess_rings(struct radv_queue
*queue
,
1363 bool add_sample_positions
,
1364 uint32_t esgs_ring_size
,
1365 struct radeon_winsys_bo
*esgs_ring_bo
,
1366 uint32_t gsvs_ring_size
,
1367 struct radeon_winsys_bo
*gsvs_ring_bo
,
1368 uint32_t tess_factor_ring_size
,
1369 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1370 uint32_t tess_offchip_ring_size
,
1371 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1373 uint64_t esgs_va
= 0, gsvs_va
= 0;
1374 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1375 uint32_t *desc
= &map
[4];
1378 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1380 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1381 if (tess_factor_ring_bo
)
1382 tess_factor_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1383 if (tess_offchip_ring_bo
)
1384 tess_offchip_va
= radv_buffer_get_va(tess_offchip_ring_bo
);
1386 /* stride 0, num records - size, add tid, swizzle, elsize4,
1389 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1390 S_008F04_STRIDE(0) |
1391 S_008F04_SWIZZLE_ENABLE(true);
1392 desc
[2] = esgs_ring_size
;
1393 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1394 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1395 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1396 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1397 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1398 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1399 S_008F0C_ELEMENT_SIZE(1) |
1400 S_008F0C_INDEX_STRIDE(3) |
1401 S_008F0C_ADD_TID_ENABLE(true);
1404 /* GS entry for ES->GS ring */
1405 /* stride 0, num records - size, elsize0,
1408 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1409 S_008F04_STRIDE(0) |
1410 S_008F04_SWIZZLE_ENABLE(false);
1411 desc
[2] = esgs_ring_size
;
1412 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1413 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1414 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1415 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1416 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1417 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1418 S_008F0C_ELEMENT_SIZE(0) |
1419 S_008F0C_INDEX_STRIDE(0) |
1420 S_008F0C_ADD_TID_ENABLE(false);
1423 /* VS entry for GS->VS ring */
1424 /* stride 0, num records - size, elsize0,
1427 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1428 S_008F04_STRIDE(0) |
1429 S_008F04_SWIZZLE_ENABLE(false);
1430 desc
[2] = gsvs_ring_size
;
1431 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1432 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1433 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1434 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1435 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1436 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1437 S_008F0C_ELEMENT_SIZE(0) |
1438 S_008F0C_INDEX_STRIDE(0) |
1439 S_008F0C_ADD_TID_ENABLE(false);
1442 /* stride gsvs_itemsize, num records 64
1443 elsize 4, index stride 16 */
1444 /* shader will patch stride and desc[2] */
1446 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1447 S_008F04_STRIDE(0) |
1448 S_008F04_SWIZZLE_ENABLE(true);
1450 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1451 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1452 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1453 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1454 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1455 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1456 S_008F0C_ELEMENT_SIZE(1) |
1457 S_008F0C_INDEX_STRIDE(1) |
1458 S_008F0C_ADD_TID_ENABLE(true);
1461 desc
[0] = tess_factor_va
;
1462 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1463 S_008F04_STRIDE(0) |
1464 S_008F04_SWIZZLE_ENABLE(false);
1465 desc
[2] = tess_factor_ring_size
;
1466 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1467 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1468 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1469 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1470 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1471 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1472 S_008F0C_ELEMENT_SIZE(0) |
1473 S_008F0C_INDEX_STRIDE(0) |
1474 S_008F0C_ADD_TID_ENABLE(false);
1477 desc
[0] = tess_offchip_va
;
1478 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1479 S_008F04_STRIDE(0) |
1480 S_008F04_SWIZZLE_ENABLE(false);
1481 desc
[2] = tess_offchip_ring_size
;
1482 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1483 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1484 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1485 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1486 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1487 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1488 S_008F0C_ELEMENT_SIZE(0) |
1489 S_008F0C_INDEX_STRIDE(0) |
1490 S_008F0C_ADD_TID_ENABLE(false);
1493 /* add sample positions after all rings */
1494 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1496 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1498 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1500 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1502 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1506 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1508 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1509 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1510 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1511 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1512 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1513 device
->physical_device
->rad_info
.max_se
;
1514 unsigned offchip_granularity
;
1515 unsigned hs_offchip_param
;
1516 switch (device
->tess_offchip_block_dw_size
) {
1521 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1524 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1528 switch (device
->physical_device
->rad_info
.chip_class
) {
1530 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1536 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1540 *max_offchip_buffers_p
= max_offchip_buffers
;
1541 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1542 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1543 --max_offchip_buffers
;
1545 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1546 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1549 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1551 return hs_offchip_param
;
1555 radv_get_preamble_cs(struct radv_queue
*queue
,
1556 uint32_t scratch_size
,
1557 uint32_t compute_scratch_size
,
1558 uint32_t esgs_ring_size
,
1559 uint32_t gsvs_ring_size
,
1560 bool needs_tess_rings
,
1561 bool needs_sample_positions
,
1562 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1563 struct radeon_winsys_cs
**initial_preamble_cs
,
1564 struct radeon_winsys_cs
**continue_preamble_cs
)
1566 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1567 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1568 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1569 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1570 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1571 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1572 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1573 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1574 bool add_tess_rings
= false, add_sample_positions
= false;
1575 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1576 unsigned max_offchip_buffers
;
1577 unsigned hs_offchip_param
= 0;
1578 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1579 if (!queue
->has_tess_rings
) {
1580 if (needs_tess_rings
)
1581 add_tess_rings
= true;
1583 if (!queue
->has_sample_positions
) {
1584 if (needs_sample_positions
)
1585 add_sample_positions
= true;
1587 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1588 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1589 &max_offchip_buffers
);
1590 tess_offchip_ring_size
= max_offchip_buffers
*
1591 queue
->device
->tess_offchip_block_dw_size
* 4;
1593 if (scratch_size
<= queue
->scratch_size
&&
1594 compute_scratch_size
<= queue
->compute_scratch_size
&&
1595 esgs_ring_size
<= queue
->esgs_ring_size
&&
1596 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1597 !add_tess_rings
&& !add_sample_positions
&&
1598 queue
->initial_preamble_cs
) {
1599 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1600 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1601 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1602 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1603 *continue_preamble_cs
= NULL
;
1607 if (scratch_size
> queue
->scratch_size
) {
1608 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1616 scratch_bo
= queue
->scratch_bo
;
1618 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1619 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1620 compute_scratch_size
,
1624 if (!compute_scratch_bo
)
1628 compute_scratch_bo
= queue
->compute_scratch_bo
;
1630 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1631 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1639 esgs_ring_bo
= queue
->esgs_ring_bo
;
1640 esgs_ring_size
= queue
->esgs_ring_size
;
1643 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1644 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1652 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1653 gsvs_ring_size
= queue
->gsvs_ring_size
;
1656 if (add_tess_rings
) {
1657 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1658 tess_factor_ring_size
,
1662 if (!tess_factor_ring_bo
)
1664 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1665 tess_offchip_ring_size
,
1669 if (!tess_offchip_ring_bo
)
1672 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1673 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1676 if (scratch_bo
!= queue
->scratch_bo
||
1677 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1678 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1679 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1680 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1682 if (gsvs_ring_bo
|| esgs_ring_bo
||
1683 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1684 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1685 if (add_sample_positions
)
1686 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1688 else if (scratch_bo
)
1689 size
= 8; /* 2 dword */
1691 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1695 RADEON_FLAG_CPU_ACCESS
|
1696 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
1697 RADEON_FLAG_READ_ONLY
);
1701 descriptor_bo
= queue
->descriptor_bo
;
1703 for(int i
= 0; i
< 3; ++i
) {
1704 struct radeon_winsys_cs
*cs
= NULL
;
1705 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1706 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1713 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
1716 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1719 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1721 if (tess_factor_ring_bo
)
1722 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_factor_ring_bo
, 8);
1724 if (tess_offchip_ring_bo
)
1725 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_offchip_ring_bo
, 8);
1728 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1730 if (descriptor_bo
!= queue
->descriptor_bo
) {
1731 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1734 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1735 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1736 S_008F04_SWIZZLE_ENABLE(1);
1737 map
[0] = scratch_va
;
1741 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1742 add_sample_positions
)
1743 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1744 esgs_ring_size
, esgs_ring_bo
,
1745 gsvs_ring_size
, gsvs_ring_bo
,
1746 tess_factor_ring_size
, tess_factor_ring_bo
,
1747 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1749 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1752 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1753 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1754 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1755 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1756 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1759 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1760 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1761 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1762 radeon_emit(cs
, esgs_ring_size
>> 8);
1763 radeon_emit(cs
, gsvs_ring_size
>> 8);
1765 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1766 radeon_emit(cs
, esgs_ring_size
>> 8);
1767 radeon_emit(cs
, gsvs_ring_size
>> 8);
1771 if (tess_factor_ring_bo
) {
1772 uint64_t tf_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1773 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1774 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1775 S_030938_SIZE(tess_factor_ring_size
/ 4));
1776 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1778 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1779 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1782 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1784 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1785 S_008988_SIZE(tess_factor_ring_size
/ 4));
1786 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1788 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1793 if (descriptor_bo
) {
1794 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1795 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1796 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1797 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1798 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1799 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1801 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1802 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1803 radeon_emit(cs
, va
);
1804 radeon_emit(cs
, va
>> 32);
1807 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1808 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1809 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1810 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1811 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1812 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1814 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1815 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1816 radeon_emit(cs
, va
);
1817 radeon_emit(cs
, va
>> 32);
1822 if (compute_scratch_bo
) {
1823 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1824 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1825 S_008F04_SWIZZLE_ENABLE(1);
1827 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1829 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1830 radeon_emit(cs
, scratch_va
);
1831 radeon_emit(cs
, rsrc1
);
1835 si_cs_emit_cache_flush(cs
,
1836 queue
->device
->physical_device
->rad_info
.chip_class
,
1838 queue
->queue_family_index
== RING_COMPUTE
&&
1839 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1840 (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
)) |
1841 RADV_CMD_FLAG_INV_ICACHE
|
1842 RADV_CMD_FLAG_INV_SMEM_L1
|
1843 RADV_CMD_FLAG_INV_VMEM_L1
|
1844 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1845 } else if (i
== 1) {
1846 si_cs_emit_cache_flush(cs
,
1847 queue
->device
->physical_device
->rad_info
.chip_class
,
1849 queue
->queue_family_index
== RING_COMPUTE
&&
1850 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1851 RADV_CMD_FLAG_INV_ICACHE
|
1852 RADV_CMD_FLAG_INV_SMEM_L1
|
1853 RADV_CMD_FLAG_INV_VMEM_L1
|
1854 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1857 if (!queue
->device
->ws
->cs_finalize(cs
))
1861 if (queue
->initial_full_flush_preamble_cs
)
1862 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1864 if (queue
->initial_preamble_cs
)
1865 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1867 if (queue
->continue_preamble_cs
)
1868 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1870 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1871 queue
->initial_preamble_cs
= dest_cs
[1];
1872 queue
->continue_preamble_cs
= dest_cs
[2];
1874 if (scratch_bo
!= queue
->scratch_bo
) {
1875 if (queue
->scratch_bo
)
1876 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1877 queue
->scratch_bo
= scratch_bo
;
1878 queue
->scratch_size
= scratch_size
;
1881 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1882 if (queue
->compute_scratch_bo
)
1883 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1884 queue
->compute_scratch_bo
= compute_scratch_bo
;
1885 queue
->compute_scratch_size
= compute_scratch_size
;
1888 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1889 if (queue
->esgs_ring_bo
)
1890 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1891 queue
->esgs_ring_bo
= esgs_ring_bo
;
1892 queue
->esgs_ring_size
= esgs_ring_size
;
1895 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1896 if (queue
->gsvs_ring_bo
)
1897 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1898 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1899 queue
->gsvs_ring_size
= gsvs_ring_size
;
1902 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1903 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1906 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1907 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1908 queue
->has_tess_rings
= true;
1911 if (descriptor_bo
!= queue
->descriptor_bo
) {
1912 if (queue
->descriptor_bo
)
1913 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1915 queue
->descriptor_bo
= descriptor_bo
;
1918 if (add_sample_positions
)
1919 queue
->has_sample_positions
= true;
1921 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1922 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1923 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1924 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1925 *continue_preamble_cs
= NULL
;
1928 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1930 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1931 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1932 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1933 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1934 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1935 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1936 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1937 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1938 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1939 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1940 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1941 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1942 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1943 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1944 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1945 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1948 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1950 const VkSemaphore
*sems
,
1954 int syncobj_idx
= 0, sem_idx
= 0;
1956 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
1959 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1960 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1962 if (sem
->temp_syncobj
|| sem
->syncobj
)
1963 counts
->syncobj_count
++;
1965 counts
->sem_count
++;
1968 if (_fence
!= VK_NULL_HANDLE
) {
1969 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1970 if (fence
->temp_syncobj
|| fence
->syncobj
)
1971 counts
->syncobj_count
++;
1974 if (counts
->syncobj_count
) {
1975 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
1976 if (!counts
->syncobj
)
1977 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1980 if (counts
->sem_count
) {
1981 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
1983 free(counts
->syncobj
);
1984 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1988 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1989 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1991 if (sem
->temp_syncobj
) {
1992 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
1994 else if (sem
->syncobj
)
1995 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
1998 counts
->sem
[sem_idx
++] = sem
->sem
;
2002 if (_fence
!= VK_NULL_HANDLE
) {
2003 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2004 if (fence
->temp_syncobj
)
2005 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2006 else if (fence
->syncobj
)
2007 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2013 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2015 free(sem_info
->wait
.syncobj
);
2016 free(sem_info
->wait
.sem
);
2017 free(sem_info
->signal
.syncobj
);
2018 free(sem_info
->signal
.sem
);
2022 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2024 const VkSemaphore
*sems
)
2026 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2027 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2029 if (sem
->temp_syncobj
) {
2030 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2031 sem
->temp_syncobj
= 0;
2036 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2038 const VkSemaphore
*wait_sems
,
2039 int num_signal_sems
,
2040 const VkSemaphore
*signal_sems
,
2044 memset(sem_info
, 0, sizeof(*sem_info
));
2046 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2049 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2051 radv_free_sem_info(sem_info
);
2053 /* caller can override these */
2054 sem_info
->cs_emit_wait
= true;
2055 sem_info
->cs_emit_signal
= true;
2059 /* Signals fence as soon as all the work currently put on queue is done. */
2060 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2061 struct radv_fence
*fence
)
2065 struct radv_winsys_sem_info sem_info
;
2067 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2068 radv_fence_to_handle(fence
));
2069 if (result
!= VK_SUCCESS
)
2072 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2073 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2074 1, NULL
, NULL
, &sem_info
,
2075 false, fence
->fence
);
2076 radv_free_sem_info(&sem_info
);
2078 /* TODO: find a better error */
2080 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2085 VkResult
radv_QueueSubmit(
2087 uint32_t submitCount
,
2088 const VkSubmitInfo
* pSubmits
,
2091 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2092 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2093 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2094 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2096 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2097 uint32_t scratch_size
= 0;
2098 uint32_t compute_scratch_size
= 0;
2099 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2100 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2102 bool fence_emitted
= false;
2103 bool tess_rings_needed
= false;
2104 bool sample_positions_needed
= false;
2106 /* Do this first so failing to allocate scratch buffers can't result in
2107 * partially executed submissions. */
2108 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2109 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2110 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2111 pSubmits
[i
].pCommandBuffers
[j
]);
2113 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2114 compute_scratch_size
= MAX2(compute_scratch_size
,
2115 cmd_buffer
->compute_scratch_size_needed
);
2116 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2117 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2118 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2119 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2123 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2124 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2125 sample_positions_needed
, &initial_flush_preamble_cs
,
2126 &initial_preamble_cs
, &continue_preamble_cs
);
2127 if (result
!= VK_SUCCESS
)
2130 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2131 struct radeon_winsys_cs
**cs_array
;
2132 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2133 bool can_patch
= true;
2135 struct radv_winsys_sem_info sem_info
;
2137 result
= radv_alloc_sem_info(&sem_info
,
2138 pSubmits
[i
].waitSemaphoreCount
,
2139 pSubmits
[i
].pWaitSemaphores
,
2140 pSubmits
[i
].signalSemaphoreCount
,
2141 pSubmits
[i
].pSignalSemaphores
,
2143 if (result
!= VK_SUCCESS
)
2146 if (!pSubmits
[i
].commandBufferCount
) {
2147 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2148 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2149 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2154 radv_loge("failed to submit CS %d\n", i
);
2157 fence_emitted
= true;
2159 radv_free_sem_info(&sem_info
);
2163 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2164 (pSubmits
[i
].commandBufferCount
));
2166 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2167 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2168 pSubmits
[i
].pCommandBuffers
[j
]);
2169 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2171 cs_array
[j
] = cmd_buffer
->cs
;
2172 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2175 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2178 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2179 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2180 advance
= MIN2(max_cs_submission
,
2181 pSubmits
[i
].commandBufferCount
- j
);
2183 if (queue
->device
->trace_bo
)
2184 *queue
->device
->trace_id_ptr
= 0;
2186 sem_info
.cs_emit_wait
= j
== 0;
2187 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2189 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2190 advance
, initial_preamble
, continue_preamble_cs
,
2192 can_patch
, base_fence
);
2195 radv_loge("failed to submit CS %d\n", i
);
2198 fence_emitted
= true;
2199 if (queue
->device
->trace_bo
) {
2200 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2204 radv_free_temp_syncobjs(queue
->device
,
2205 pSubmits
[i
].waitSemaphoreCount
,
2206 pSubmits
[i
].pWaitSemaphores
);
2207 radv_free_sem_info(&sem_info
);
2212 if (!fence_emitted
) {
2213 radv_signal_fence(queue
, fence
);
2215 fence
->submitted
= true;
2221 VkResult
radv_QueueWaitIdle(
2224 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2226 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2227 radv_queue_family_to_ring(queue
->queue_family_index
),
2232 VkResult
radv_DeviceWaitIdle(
2235 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2237 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2238 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2239 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2245 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2246 VkInstance instance
,
2249 return radv_lookup_entrypoint(pName
);
2252 /* The loader wants us to expose a second GetInstanceProcAddr function
2253 * to work around certain LD_PRELOAD issues seen in apps.
2256 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2257 VkInstance instance
,
2261 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2262 VkInstance instance
,
2265 return radv_GetInstanceProcAddr(instance
, pName
);
2268 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2272 return radv_lookup_entrypoint(pName
);
2275 bool radv_get_memory_fd(struct radv_device
*device
,
2276 struct radv_device_memory
*memory
,
2279 struct radeon_bo_metadata metadata
;
2281 if (memory
->image
) {
2282 radv_init_metadata(device
, memory
->image
, &metadata
);
2283 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2286 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2290 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2291 const VkMemoryAllocateInfo
* pAllocateInfo
,
2292 const VkAllocationCallbacks
* pAllocator
,
2293 VkDeviceMemory
* pMem
)
2295 struct radv_device_memory
*mem
;
2297 enum radeon_bo_domain domain
;
2299 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2301 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2303 if (pAllocateInfo
->allocationSize
== 0) {
2304 /* Apparently, this is allowed */
2305 *pMem
= VK_NULL_HANDLE
;
2309 const VkImportMemoryFdInfoKHR
*import_info
=
2310 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2311 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2312 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2313 const VkExportMemoryAllocateInfoKHR
*export_info
=
2314 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2315 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2316 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2318 const struct wsi_memory_allocate_info
*wsi_info
=
2319 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2321 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2322 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2324 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2326 if (wsi_info
&& wsi_info
->implicit_sync
)
2327 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2329 if (dedicate_info
) {
2330 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2331 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2337 mem
->user_ptr
= NULL
;
2340 assert(import_info
->handleType
==
2341 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2342 import_info
->handleType
==
2343 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2344 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2347 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2350 close(import_info
->fd
);
2355 if (host_ptr_info
) {
2356 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2357 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2358 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2359 pAllocateInfo
->allocationSize
);
2361 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2364 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2369 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2370 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2371 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2372 domain
= RADEON_DOMAIN_GTT
;
2374 domain
= RADEON_DOMAIN_VRAM
;
2376 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2377 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2379 flags
|= RADEON_FLAG_CPU_ACCESS
;
2381 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2382 flags
|= RADEON_FLAG_GTT_WC
;
2384 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2385 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2387 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2391 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2394 mem
->type_index
= mem_type_index
;
2396 *pMem
= radv_device_memory_to_handle(mem
);
2401 vk_free2(&device
->alloc
, pAllocator
, mem
);
2406 VkResult
radv_AllocateMemory(
2408 const VkMemoryAllocateInfo
* pAllocateInfo
,
2409 const VkAllocationCallbacks
* pAllocator
,
2410 VkDeviceMemory
* pMem
)
2412 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2413 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2416 void radv_FreeMemory(
2418 VkDeviceMemory _mem
,
2419 const VkAllocationCallbacks
* pAllocator
)
2421 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2422 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2427 device
->ws
->buffer_destroy(mem
->bo
);
2430 vk_free2(&device
->alloc
, pAllocator
, mem
);
2433 VkResult
radv_MapMemory(
2435 VkDeviceMemory _memory
,
2436 VkDeviceSize offset
,
2438 VkMemoryMapFlags flags
,
2441 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2442 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2450 *ppData
= mem
->user_ptr
;
2452 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2459 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2462 void radv_UnmapMemory(
2464 VkDeviceMemory _memory
)
2466 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2467 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2472 if (mem
->user_ptr
== NULL
)
2473 device
->ws
->buffer_unmap(mem
->bo
);
2476 VkResult
radv_FlushMappedMemoryRanges(
2478 uint32_t memoryRangeCount
,
2479 const VkMappedMemoryRange
* pMemoryRanges
)
2484 VkResult
radv_InvalidateMappedMemoryRanges(
2486 uint32_t memoryRangeCount
,
2487 const VkMappedMemoryRange
* pMemoryRanges
)
2492 void radv_GetBufferMemoryRequirements(
2495 VkMemoryRequirements
* pMemoryRequirements
)
2497 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2498 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2500 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2502 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2503 pMemoryRequirements
->alignment
= 4096;
2505 pMemoryRequirements
->alignment
= 16;
2507 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2510 void radv_GetBufferMemoryRequirements2KHR(
2512 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2513 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2515 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2516 &pMemoryRequirements
->memoryRequirements
);
2517 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2518 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2519 switch (ext
->sType
) {
2520 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2521 VkMemoryDedicatedRequirementsKHR
*req
=
2522 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2523 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2524 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2533 void radv_GetImageMemoryRequirements(
2536 VkMemoryRequirements
* pMemoryRequirements
)
2538 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2539 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2541 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2543 pMemoryRequirements
->size
= image
->size
;
2544 pMemoryRequirements
->alignment
= image
->alignment
;
2547 void radv_GetImageMemoryRequirements2KHR(
2549 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2550 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2552 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2553 &pMemoryRequirements
->memoryRequirements
);
2555 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2557 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2558 switch (ext
->sType
) {
2559 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2560 VkMemoryDedicatedRequirementsKHR
*req
=
2561 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2562 req
->requiresDedicatedAllocation
= image
->shareable
;
2563 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2572 void radv_GetImageSparseMemoryRequirements(
2575 uint32_t* pSparseMemoryRequirementCount
,
2576 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2581 void radv_GetImageSparseMemoryRequirements2KHR(
2583 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2584 uint32_t* pSparseMemoryRequirementCount
,
2585 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2590 void radv_GetDeviceMemoryCommitment(
2592 VkDeviceMemory memory
,
2593 VkDeviceSize
* pCommittedMemoryInBytes
)
2595 *pCommittedMemoryInBytes
= 0;
2598 VkResult
radv_BindBufferMemory2KHR(VkDevice device
,
2599 uint32_t bindInfoCount
,
2600 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2602 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2603 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2604 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2607 buffer
->bo
= mem
->bo
;
2608 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2616 VkResult
radv_BindBufferMemory(
2619 VkDeviceMemory memory
,
2620 VkDeviceSize memoryOffset
)
2622 const VkBindBufferMemoryInfoKHR info
= {
2623 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2626 .memoryOffset
= memoryOffset
2629 return radv_BindBufferMemory2KHR(device
, 1, &info
);
2632 VkResult
radv_BindImageMemory2KHR(VkDevice device
,
2633 uint32_t bindInfoCount
,
2634 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2636 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2637 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2638 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2641 image
->bo
= mem
->bo
;
2642 image
->offset
= pBindInfos
[i
].memoryOffset
;
2652 VkResult
radv_BindImageMemory(
2655 VkDeviceMemory memory
,
2656 VkDeviceSize memoryOffset
)
2658 const VkBindImageMemoryInfoKHR info
= {
2659 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2662 .memoryOffset
= memoryOffset
2665 return radv_BindImageMemory2KHR(device
, 1, &info
);
2670 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2671 const VkSparseBufferMemoryBindInfo
*bind
)
2673 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2675 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2676 struct radv_device_memory
*mem
= NULL
;
2678 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2679 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2681 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2682 bind
->pBinds
[i
].resourceOffset
,
2683 bind
->pBinds
[i
].size
,
2684 mem
? mem
->bo
: NULL
,
2685 bind
->pBinds
[i
].memoryOffset
);
2690 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2691 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2693 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2695 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2696 struct radv_device_memory
*mem
= NULL
;
2698 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2699 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2701 device
->ws
->buffer_virtual_bind(image
->bo
,
2702 bind
->pBinds
[i
].resourceOffset
,
2703 bind
->pBinds
[i
].size
,
2704 mem
? mem
->bo
: NULL
,
2705 bind
->pBinds
[i
].memoryOffset
);
2709 VkResult
radv_QueueBindSparse(
2711 uint32_t bindInfoCount
,
2712 const VkBindSparseInfo
* pBindInfo
,
2715 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2716 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2717 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2718 bool fence_emitted
= false;
2720 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2721 struct radv_winsys_sem_info sem_info
;
2722 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2723 radv_sparse_buffer_bind_memory(queue
->device
,
2724 pBindInfo
[i
].pBufferBinds
+ j
);
2727 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2728 radv_sparse_image_opaque_bind_memory(queue
->device
,
2729 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2733 result
= radv_alloc_sem_info(&sem_info
,
2734 pBindInfo
[i
].waitSemaphoreCount
,
2735 pBindInfo
[i
].pWaitSemaphores
,
2736 pBindInfo
[i
].signalSemaphoreCount
,
2737 pBindInfo
[i
].pSignalSemaphores
,
2739 if (result
!= VK_SUCCESS
)
2742 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2743 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2744 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2748 fence_emitted
= true;
2750 fence
->submitted
= true;
2753 radv_free_sem_info(&sem_info
);
2758 if (!fence_emitted
) {
2759 radv_signal_fence(queue
, fence
);
2761 fence
->submitted
= true;
2767 VkResult
radv_CreateFence(
2769 const VkFenceCreateInfo
* pCreateInfo
,
2770 const VkAllocationCallbacks
* pAllocator
,
2773 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2774 const VkExportFenceCreateInfoKHR
*export
=
2775 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
2776 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
2777 export
? export
->handleTypes
: 0;
2779 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2781 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2784 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2786 fence
->submitted
= false;
2787 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2788 fence
->temp_syncobj
= 0;
2789 if (device
->always_use_syncobj
|| handleTypes
) {
2790 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
2792 vk_free2(&device
->alloc
, pAllocator
, fence
);
2793 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2795 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
2796 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
2798 fence
->fence
= NULL
;
2800 fence
->fence
= device
->ws
->create_fence();
2801 if (!fence
->fence
) {
2802 vk_free2(&device
->alloc
, pAllocator
, fence
);
2803 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2808 *pFence
= radv_fence_to_handle(fence
);
2813 void radv_DestroyFence(
2816 const VkAllocationCallbacks
* pAllocator
)
2818 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2819 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2824 if (fence
->temp_syncobj
)
2825 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
2827 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
2829 device
->ws
->destroy_fence(fence
->fence
);
2830 vk_free2(&device
->alloc
, pAllocator
, fence
);
2833 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2835 uint64_t current_time
;
2838 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2839 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2841 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2843 return current_time
+ timeout
;
2846 VkResult
radv_WaitForFences(
2848 uint32_t fenceCount
,
2849 const VkFence
* pFences
,
2853 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2854 timeout
= radv_get_absolute_timeout(timeout
);
2856 if (!waitAll
&& fenceCount
> 1) {
2857 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2860 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2861 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2862 bool expired
= false;
2864 if (fence
->temp_syncobj
) {
2865 if (!device
->ws
->wait_syncobj(device
->ws
, fence
->temp_syncobj
, timeout
))
2870 if (fence
->syncobj
) {
2871 if (!device
->ws
->wait_syncobj(device
->ws
, fence
->syncobj
, timeout
))
2876 if (fence
->signalled
)
2879 if (!fence
->submitted
)
2882 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2886 fence
->signalled
= true;
2892 VkResult
radv_ResetFences(VkDevice _device
,
2893 uint32_t fenceCount
,
2894 const VkFence
*pFences
)
2896 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2898 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2899 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2900 fence
->submitted
= fence
->signalled
= false;
2902 /* Per spec, we first restore the permanent payload, and then reset, so
2903 * having a temp syncobj should not skip resetting the permanent syncobj. */
2904 if (fence
->temp_syncobj
) {
2905 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
2906 fence
->temp_syncobj
= 0;
2909 if (fence
->syncobj
) {
2910 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
2917 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2919 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2920 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2922 if (fence
->temp_syncobj
) {
2923 bool success
= device
->ws
->wait_syncobj(device
->ws
, fence
->temp_syncobj
, 0);
2924 return success
? VK_SUCCESS
: VK_NOT_READY
;
2927 if (fence
->syncobj
) {
2928 bool success
= device
->ws
->wait_syncobj(device
->ws
, fence
->syncobj
, 0);
2929 return success
? VK_SUCCESS
: VK_NOT_READY
;
2932 if (fence
->signalled
)
2934 if (!fence
->submitted
)
2935 return VK_NOT_READY
;
2936 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2937 return VK_NOT_READY
;
2943 // Queue semaphore functions
2945 VkResult
radv_CreateSemaphore(
2947 const VkSemaphoreCreateInfo
* pCreateInfo
,
2948 const VkAllocationCallbacks
* pAllocator
,
2949 VkSemaphore
* pSemaphore
)
2951 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2952 const VkExportSemaphoreCreateInfoKHR
*export
=
2953 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2954 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2955 export
? export
->handleTypes
: 0;
2957 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2959 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2961 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2963 sem
->temp_syncobj
= 0;
2964 /* create a syncobject if we are going to export this semaphore */
2965 if (device
->always_use_syncobj
|| handleTypes
) {
2966 assert (device
->physical_device
->rad_info
.has_syncobj
);
2967 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2969 vk_free2(&device
->alloc
, pAllocator
, sem
);
2970 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2974 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2976 vk_free2(&device
->alloc
, pAllocator
, sem
);
2977 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2982 *pSemaphore
= radv_semaphore_to_handle(sem
);
2986 void radv_DestroySemaphore(
2988 VkSemaphore _semaphore
,
2989 const VkAllocationCallbacks
* pAllocator
)
2991 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2992 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2997 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2999 device
->ws
->destroy_sem(sem
->sem
);
3000 vk_free2(&device
->alloc
, pAllocator
, sem
);
3003 VkResult
radv_CreateEvent(
3005 const VkEventCreateInfo
* pCreateInfo
,
3006 const VkAllocationCallbacks
* pAllocator
,
3009 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3010 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3012 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3015 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3017 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3019 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3021 vk_free2(&device
->alloc
, pAllocator
, event
);
3022 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3025 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3027 *pEvent
= radv_event_to_handle(event
);
3032 void radv_DestroyEvent(
3035 const VkAllocationCallbacks
* pAllocator
)
3037 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3038 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3042 device
->ws
->buffer_destroy(event
->bo
);
3043 vk_free2(&device
->alloc
, pAllocator
, event
);
3046 VkResult
radv_GetEventStatus(
3050 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3052 if (*event
->map
== 1)
3053 return VK_EVENT_SET
;
3054 return VK_EVENT_RESET
;
3057 VkResult
radv_SetEvent(
3061 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3067 VkResult
radv_ResetEvent(
3071 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3077 VkResult
radv_CreateBuffer(
3079 const VkBufferCreateInfo
* pCreateInfo
,
3080 const VkAllocationCallbacks
* pAllocator
,
3083 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3084 struct radv_buffer
*buffer
;
3086 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3088 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3089 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3091 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3093 buffer
->size
= pCreateInfo
->size
;
3094 buffer
->usage
= pCreateInfo
->usage
;
3097 buffer
->flags
= pCreateInfo
->flags
;
3099 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3100 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3102 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3103 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3104 align64(buffer
->size
, 4096),
3105 4096, 0, RADEON_FLAG_VIRTUAL
);
3107 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3108 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3112 *pBuffer
= radv_buffer_to_handle(buffer
);
3117 void radv_DestroyBuffer(
3120 const VkAllocationCallbacks
* pAllocator
)
3122 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3123 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3128 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3129 device
->ws
->buffer_destroy(buffer
->bo
);
3131 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3134 static inline unsigned
3135 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3138 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3140 return image
->surface
.u
.legacy
.tiling_index
[level
];
3143 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3145 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3149 radv_initialise_color_surface(struct radv_device
*device
,
3150 struct radv_color_buffer_info
*cb
,
3151 struct radv_image_view
*iview
)
3153 const struct vk_format_description
*desc
;
3154 unsigned ntype
, format
, swap
, endian
;
3155 unsigned blend_clamp
= 0, blend_bypass
= 0;
3157 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3159 desc
= vk_format_description(iview
->vk_format
);
3161 memset(cb
, 0, sizeof(*cb
));
3163 /* Intensity is implemented as Red, so treat it that way. */
3164 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3166 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3168 cb
->cb_color_base
= va
>> 8;
3170 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3171 struct gfx9_surf_meta_flags meta
;
3172 if (iview
->image
->dcc_offset
)
3173 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3175 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3177 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3178 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3179 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3180 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3182 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3183 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3185 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3186 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3188 cb
->cb_color_base
+= level_info
->offset
>> 8;
3189 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3190 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3192 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3193 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3194 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3196 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3197 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3198 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3200 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3202 if (iview
->image
->fmask
.size
) {
3203 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3204 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3205 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3206 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3208 /* This must be set for fast clear to work without FMASK. */
3209 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3210 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3211 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3212 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3216 /* CMASK variables */
3217 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3218 va
+= iview
->image
->cmask
.offset
;
3219 cb
->cb_color_cmask
= va
>> 8;
3221 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3222 va
+= iview
->image
->dcc_offset
;
3223 cb
->cb_dcc_base
= va
>> 8;
3224 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3226 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3227 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3228 S_028C6C_SLICE_MAX(max_slice
);
3230 if (iview
->image
->info
.samples
> 1) {
3231 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3233 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3234 S_028C74_NUM_FRAGMENTS(log_samples
);
3237 if (iview
->image
->fmask
.size
) {
3238 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3239 cb
->cb_color_fmask
= va
>> 8;
3240 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3242 cb
->cb_color_fmask
= cb
->cb_color_base
;
3245 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3247 vk_format_get_first_non_void_channel(iview
->vk_format
));
3248 format
= radv_translate_colorformat(iview
->vk_format
);
3249 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3250 radv_finishme("Illegal color\n");
3251 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3252 endian
= radv_colorformat_endian_swap(format
);
3254 /* blend clamp should be set for all NORM/SRGB types */
3255 if (ntype
== V_028C70_NUMBER_UNORM
||
3256 ntype
== V_028C70_NUMBER_SNORM
||
3257 ntype
== V_028C70_NUMBER_SRGB
)
3260 /* set blend bypass according to docs if SINT/UINT or
3261 8/24 COLOR variants */
3262 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3263 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3264 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3269 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3270 (format
== V_028C70_COLOR_8
||
3271 format
== V_028C70_COLOR_8_8
||
3272 format
== V_028C70_COLOR_8_8_8_8
))
3273 ->color_is_int8
= true;
3275 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3276 S_028C70_COMP_SWAP(swap
) |
3277 S_028C70_BLEND_CLAMP(blend_clamp
) |
3278 S_028C70_BLEND_BYPASS(blend_bypass
) |
3279 S_028C70_SIMPLE_FLOAT(1) |
3280 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3281 ntype
!= V_028C70_NUMBER_SNORM
&&
3282 ntype
!= V_028C70_NUMBER_SRGB
&&
3283 format
!= V_028C70_COLOR_8_24
&&
3284 format
!= V_028C70_COLOR_24_8
) |
3285 S_028C70_NUMBER_TYPE(ntype
) |
3286 S_028C70_ENDIAN(endian
);
3287 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3288 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3289 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3290 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3291 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3295 if (iview
->image
->cmask
.size
&&
3296 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3297 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3299 if (radv_vi_dcc_enabled(iview
->image
, iview
->base_mip
))
3300 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3302 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3303 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3304 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3305 unsigned independent_64b_blocks
= 0;
3306 unsigned max_compressed_block_size
;
3308 /* amdvlk: [min-compressed-block-size] should be set to 32 for dGPU and
3309 64 for APU because all of our APUs to date use DIMMs which have
3310 a request granularity size of 64B while all other chips have a
3312 if (!device
->physical_device
->rad_info
.has_dedicated_vram
)
3313 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3315 if (iview
->image
->info
.samples
> 1) {
3316 if (iview
->image
->surface
.bpe
== 1)
3317 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3318 else if (iview
->image
->surface
.bpe
== 2)
3319 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3322 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3323 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3324 independent_64b_blocks
= 1;
3325 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3327 max_compressed_block_size
= max_uncompressed_block_size
;
3329 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3330 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3331 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3332 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3335 /* This must be set for fast clear to work without FMASK. */
3336 if (!iview
->image
->fmask
.size
&&
3337 device
->physical_device
->rad_info
.chip_class
== SI
) {
3338 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3339 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3342 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3343 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3344 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3346 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3347 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3348 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3349 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3350 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3351 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3356 radv_initialise_ds_surface(struct radv_device
*device
,
3357 struct radv_ds_buffer_info
*ds
,
3358 struct radv_image_view
*iview
)
3360 unsigned level
= iview
->base_mip
;
3361 unsigned format
, stencil_format
;
3362 uint64_t va
, s_offs
, z_offs
;
3363 bool stencil_only
= false;
3364 memset(ds
, 0, sizeof(*ds
));
3365 switch (iview
->image
->vk_format
) {
3366 case VK_FORMAT_D24_UNORM_S8_UINT
:
3367 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3368 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3369 ds
->offset_scale
= 2.0f
;
3371 case VK_FORMAT_D16_UNORM
:
3372 case VK_FORMAT_D16_UNORM_S8_UINT
:
3373 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3374 ds
->offset_scale
= 4.0f
;
3376 case VK_FORMAT_D32_SFLOAT
:
3377 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3378 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3379 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3380 ds
->offset_scale
= 1.0f
;
3382 case VK_FORMAT_S8_UINT
:
3383 stencil_only
= true;
3389 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3390 stencil_format
= iview
->image
->surface
.has_stencil
?
3391 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3393 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3394 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3395 S_028008_SLICE_MAX(max_slice
);
3397 ds
->db_htile_data_base
= 0;
3398 ds
->db_htile_surface
= 0;
3400 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3401 s_offs
= z_offs
= va
;
3403 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3404 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3405 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3407 ds
->db_z_info
= S_028038_FORMAT(format
) |
3408 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3409 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3410 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3411 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3412 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3414 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3415 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3416 ds
->db_depth_view
|= S_028008_MIPID(level
);
3418 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3419 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3421 if (radv_htile_enabled(iview
->image
, level
)) {
3422 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3424 if (iview
->image
->tc_compatible_htile
) {
3425 unsigned max_zplanes
= 4;
3427 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3428 iview
->image
->info
.samples
> 1)
3431 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
+ 1) |
3432 S_028038_ITERATE_FLUSH(1);
3433 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3436 if (!iview
->image
->surface
.has_stencil
)
3437 /* Use all of the htile_buffer for depth if there's no stencil. */
3438 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3439 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3440 iview
->image
->htile_offset
;
3441 ds
->db_htile_data_base
= va
>> 8;
3442 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3443 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3444 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3447 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3450 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3452 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3453 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3455 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!iview
->image
->tc_compatible_htile
);
3456 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3457 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3459 if (iview
->image
->info
.samples
> 1)
3460 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3462 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3463 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3464 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3465 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3466 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3467 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3468 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3469 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3472 tile_mode
= stencil_tile_mode
;
3474 ds
->db_depth_info
|=
3475 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3476 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3477 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3478 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3479 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3480 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3481 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3482 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3484 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3485 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3486 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3487 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3489 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3492 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3493 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3494 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3496 if (radv_htile_enabled(iview
->image
, level
)) {
3497 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3499 if (!iview
->image
->surface
.has_stencil
&&
3500 !iview
->image
->tc_compatible_htile
)
3501 /* Use all of the htile_buffer for depth if there's no stencil. */
3502 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3504 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3505 iview
->image
->htile_offset
;
3506 ds
->db_htile_data_base
= va
>> 8;
3507 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3509 if (iview
->image
->tc_compatible_htile
) {
3510 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3512 if (iview
->image
->info
.samples
<= 1)
3513 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
3514 else if (iview
->image
->info
.samples
<= 4)
3515 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
3517 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
3522 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3523 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3526 VkResult
radv_CreateFramebuffer(
3528 const VkFramebufferCreateInfo
* pCreateInfo
,
3529 const VkAllocationCallbacks
* pAllocator
,
3530 VkFramebuffer
* pFramebuffer
)
3532 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3533 struct radv_framebuffer
*framebuffer
;
3535 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3537 size_t size
= sizeof(*framebuffer
) +
3538 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3539 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3540 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3541 if (framebuffer
== NULL
)
3542 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3544 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3545 framebuffer
->width
= pCreateInfo
->width
;
3546 framebuffer
->height
= pCreateInfo
->height
;
3547 framebuffer
->layers
= pCreateInfo
->layers
;
3548 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3549 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3550 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3551 framebuffer
->attachments
[i
].attachment
= iview
;
3552 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3553 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3554 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3555 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3557 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3558 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3559 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
3562 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3566 void radv_DestroyFramebuffer(
3569 const VkAllocationCallbacks
* pAllocator
)
3571 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3572 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3576 vk_free2(&device
->alloc
, pAllocator
, fb
);
3579 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3581 switch (address_mode
) {
3582 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3583 return V_008F30_SQ_TEX_WRAP
;
3584 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3585 return V_008F30_SQ_TEX_MIRROR
;
3586 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3587 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3588 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3589 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3590 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3591 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3593 unreachable("illegal tex wrap mode");
3599 radv_tex_compare(VkCompareOp op
)
3602 case VK_COMPARE_OP_NEVER
:
3603 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3604 case VK_COMPARE_OP_LESS
:
3605 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3606 case VK_COMPARE_OP_EQUAL
:
3607 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3608 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3609 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3610 case VK_COMPARE_OP_GREATER
:
3611 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3612 case VK_COMPARE_OP_NOT_EQUAL
:
3613 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3614 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3615 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3616 case VK_COMPARE_OP_ALWAYS
:
3617 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3619 unreachable("illegal compare mode");
3625 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3628 case VK_FILTER_NEAREST
:
3629 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3630 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3631 case VK_FILTER_LINEAR
:
3632 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3633 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3634 case VK_FILTER_CUBIC_IMG
:
3636 fprintf(stderr
, "illegal texture filter");
3642 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3645 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3646 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3647 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3648 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3650 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3655 radv_tex_bordercolor(VkBorderColor bcolor
)
3658 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3659 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3660 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3661 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3662 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3663 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3664 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3665 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3666 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3674 radv_tex_aniso_filter(unsigned filter
)
3688 radv_init_sampler(struct radv_device
*device
,
3689 struct radv_sampler
*sampler
,
3690 const VkSamplerCreateInfo
*pCreateInfo
)
3692 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3693 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3694 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3695 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3697 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3698 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3699 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3700 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3701 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3702 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3703 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3704 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3705 S_008F30_DISABLE_CUBE_WRAP(0) |
3706 S_008F30_COMPAT_MODE(is_vi
));
3707 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3708 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3709 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3710 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3711 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3712 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3713 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3714 S_008F38_MIP_POINT_PRECLAMP(0) |
3715 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
3716 S_008F38_FILTER_PREC_FIX(1) |
3717 S_008F38_ANISO_OVERRIDE(is_vi
));
3718 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3719 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3722 VkResult
radv_CreateSampler(
3724 const VkSamplerCreateInfo
* pCreateInfo
,
3725 const VkAllocationCallbacks
* pAllocator
,
3726 VkSampler
* pSampler
)
3728 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3729 struct radv_sampler
*sampler
;
3731 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3733 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3734 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3736 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3738 radv_init_sampler(device
, sampler
, pCreateInfo
);
3739 *pSampler
= radv_sampler_to_handle(sampler
);
3744 void radv_DestroySampler(
3747 const VkAllocationCallbacks
* pAllocator
)
3749 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3750 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3754 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3757 /* vk_icd.h does not declare this function, so we declare it here to
3758 * suppress Wmissing-prototypes.
3760 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3761 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3763 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3764 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3766 /* For the full details on loader interface versioning, see
3767 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3768 * What follows is a condensed summary, to help you navigate the large and
3769 * confusing official doc.
3771 * - Loader interface v0 is incompatible with later versions. We don't
3774 * - In loader interface v1:
3775 * - The first ICD entrypoint called by the loader is
3776 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3778 * - The ICD must statically expose no other Vulkan symbol unless it is
3779 * linked with -Bsymbolic.
3780 * - Each dispatchable Vulkan handle created by the ICD must be
3781 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3782 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3783 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3784 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3785 * such loader-managed surfaces.
3787 * - Loader interface v2 differs from v1 in:
3788 * - The first ICD entrypoint called by the loader is
3789 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3790 * statically expose this entrypoint.
3792 * - Loader interface v3 differs from v2 in:
3793 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3794 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3795 * because the loader no longer does so.
3797 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3801 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3802 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3805 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3806 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3808 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3810 /* At the moment, we support only the below handle types. */
3811 assert(pGetFdInfo
->handleType
==
3812 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
3813 pGetFdInfo
->handleType
==
3814 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3816 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3818 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3822 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3823 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3825 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3827 switch (handleType
) {
3828 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
3829 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
3833 /* The valid usage section for this function says:
3835 * "handleType must not be one of the handle types defined as
3838 * So opaque handle types fall into the default "unsupported" case.
3840 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3844 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
3848 uint32_t syncobj_handle
= 0;
3849 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
3851 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3854 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
3856 *syncobj
= syncobj_handle
;
3862 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
3866 /* If we create a syncobj we do it locally so that if we have an error, we don't
3867 * leave a syncobj in an undetermined state in the fence. */
3868 uint32_t syncobj_handle
= *syncobj
;
3869 if (!syncobj_handle
) {
3870 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
3872 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3877 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
3879 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
3881 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3884 *syncobj
= syncobj_handle
;
3891 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3892 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3894 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3895 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3896 uint32_t *syncobj_dst
= NULL
;
3898 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3899 syncobj_dst
= &sem
->temp_syncobj
;
3901 syncobj_dst
= &sem
->syncobj
;
3904 switch(pImportSemaphoreFdInfo
->handleType
) {
3905 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3906 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
3907 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3908 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
3910 unreachable("Unhandled semaphore handle type");
3914 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3915 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3918 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3919 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3921 uint32_t syncobj_handle
;
3923 if (sem
->temp_syncobj
)
3924 syncobj_handle
= sem
->temp_syncobj
;
3926 syncobj_handle
= sem
->syncobj
;
3928 switch(pGetFdInfo
->handleType
) {
3929 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3930 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3932 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3933 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
3935 if (sem
->temp_syncobj
) {
3936 close (sem
->temp_syncobj
);
3937 sem
->temp_syncobj
= 0;
3939 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
3944 unreachable("Unhandled semaphore handle type");
3948 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3952 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3953 VkPhysicalDevice physicalDevice
,
3954 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3955 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3957 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
3959 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
3960 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
3961 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
3962 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
3963 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
3964 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
3965 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3966 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3967 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3968 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3969 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3970 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3971 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3973 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3974 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3975 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
3979 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
3980 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
3982 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3983 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
3984 uint32_t *syncobj_dst
= NULL
;
3987 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
3988 syncobj_dst
= &fence
->temp_syncobj
;
3990 syncobj_dst
= &fence
->syncobj
;
3993 switch(pImportFenceFdInfo
->handleType
) {
3994 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3995 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
3996 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3997 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
3999 unreachable("Unhandled fence handle type");
4003 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4004 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4007 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4008 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4010 uint32_t syncobj_handle
;
4012 if (fence
->temp_syncobj
)
4013 syncobj_handle
= fence
->temp_syncobj
;
4015 syncobj_handle
= fence
->syncobj
;
4017 switch(pGetFdInfo
->handleType
) {
4018 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4019 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4021 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4022 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4024 if (fence
->temp_syncobj
) {
4025 close (fence
->temp_syncobj
);
4026 fence
->temp_syncobj
= 0;
4028 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4033 unreachable("Unhandled fence handle type");
4037 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4041 void radv_GetPhysicalDeviceExternalFencePropertiesKHR(
4042 VkPhysicalDevice physicalDevice
,
4043 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4044 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4046 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4048 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4049 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4050 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4051 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4052 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4053 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4054 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4056 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4057 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4058 pExternalFenceProperties
->externalFenceFeatures
= 0;
4063 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4064 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4065 const VkAllocationCallbacks
* pAllocator
,
4066 VkDebugReportCallbackEXT
* pCallback
)
4068 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4069 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4070 pCreateInfo
, pAllocator
, &instance
->alloc
,
4075 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4076 VkDebugReportCallbackEXT _callback
,
4077 const VkAllocationCallbacks
* pAllocator
)
4079 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4080 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4081 _callback
, pAllocator
, &instance
->alloc
);
4085 radv_DebugReportMessageEXT(VkInstance _instance
,
4086 VkDebugReportFlagsEXT flags
,
4087 VkDebugReportObjectTypeEXT objectType
,
4090 int32_t messageCode
,
4091 const char* pLayerPrefix
,
4092 const char* pMessage
)
4094 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4095 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4096 object
, location
, messageCode
, pLayerPrefix
, pMessage
);