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 if (device
->rad_info
.chip_class
< VI
||
284 device
->rad_info
.chip_class
> GFX9
)
285 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
287 radv_get_driver_uuid(&device
->device_uuid
);
288 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
290 if (device
->rad_info
.family
== CHIP_STONEY
||
291 device
->rad_info
.chip_class
>= GFX9
) {
292 device
->has_rbplus
= true;
293 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
296 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
299 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
301 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
303 /* Vega10/Raven need a special workaround for a hardware bug. */
304 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
305 device
->rad_info
.family
== CHIP_RAVEN
;
307 radv_physical_device_init_mem_types(device
);
308 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
310 result
= radv_init_wsi(device
);
311 if (result
!= VK_SUCCESS
) {
312 device
->ws
->destroy(device
->ws
);
324 radv_physical_device_finish(struct radv_physical_device
*device
)
326 radv_finish_wsi(device
);
327 device
->ws
->destroy(device
->ws
);
328 disk_cache_destroy(device
->disk_cache
);
329 close(device
->local_fd
);
333 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
334 VkSystemAllocationScope allocationScope
)
340 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
341 size_t align
, VkSystemAllocationScope allocationScope
)
343 return realloc(pOriginal
, size
);
347 default_free_func(void *pUserData
, void *pMemory
)
352 static const VkAllocationCallbacks default_alloc
= {
354 .pfnAllocation
= default_alloc_func
,
355 .pfnReallocation
= default_realloc_func
,
356 .pfnFree
= default_free_func
,
359 static const struct debug_control radv_debug_options
[] = {
360 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
361 {"nodcc", RADV_DEBUG_NO_DCC
},
362 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
363 {"nocache", RADV_DEBUG_NO_CACHE
},
364 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
365 {"nohiz", RADV_DEBUG_NO_HIZ
},
366 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
367 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
368 {"allbos", RADV_DEBUG_ALL_BOS
},
369 {"noibs", RADV_DEBUG_NO_IBS
},
370 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
371 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
372 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
373 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
374 {"nosisched", RADV_DEBUG_NO_SISCHED
},
375 {"preoptir", RADV_DEBUG_PREOPTIR
},
380 radv_get_debug_option_name(int id
)
382 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
383 return radv_debug_options
[id
].string
;
386 static const struct debug_control radv_perftest_options
[] = {
387 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
388 {"sisched", RADV_PERFTEST_SISCHED
},
389 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
390 {"binning", RADV_PERFTEST_BINNING
},
395 radv_get_perftest_option_name(int id
)
397 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
398 return radv_perftest_options
[id
].string
;
402 radv_handle_per_app_options(struct radv_instance
*instance
,
403 const VkApplicationInfo
*info
)
405 const char *name
= info
? info
->pApplicationName
: NULL
;
410 if (!strcmp(name
, "Talos - Linux - 32bit") ||
411 !strcmp(name
, "Talos - Linux - 64bit")) {
412 /* Force enable LLVM sisched for Talos because it looks safe
413 * and it gives few more FPS.
415 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
419 static int radv_get_instance_extension_index(const char *name
)
421 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
422 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
429 VkResult
radv_CreateInstance(
430 const VkInstanceCreateInfo
* pCreateInfo
,
431 const VkAllocationCallbacks
* pAllocator
,
432 VkInstance
* pInstance
)
434 struct radv_instance
*instance
;
437 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
439 uint32_t client_version
;
440 if (pCreateInfo
->pApplicationInfo
&&
441 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
442 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
444 client_version
= VK_MAKE_VERSION(1, 0, 0);
447 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
448 client_version
> VK_MAKE_VERSION(1, 1, 0xfff)) {
449 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
450 "Client requested version %d.%d.%d",
451 VK_VERSION_MAJOR(client_version
),
452 VK_VERSION_MINOR(client_version
),
453 VK_VERSION_PATCH(client_version
));
456 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
457 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
459 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
461 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
464 instance
->alloc
= *pAllocator
;
466 instance
->alloc
= default_alloc
;
468 instance
->apiVersion
= client_version
;
469 instance
->physicalDeviceCount
= -1;
471 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
472 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
473 int index
= radv_get_instance_extension_index(ext_name
);
475 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
476 vk_free2(&default_alloc
, pAllocator
, instance
);
477 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
480 instance
->enabled_extensions
.extensions
[index
] = true;
483 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
484 if (result
!= VK_SUCCESS
) {
485 vk_free2(&default_alloc
, pAllocator
, instance
);
486 return vk_error(result
);
491 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
493 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
496 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
497 radv_perftest_options
);
499 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
501 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
502 /* Disable sisched when the user requests it, this is mostly
503 * useful when the driver force-enable sisched for the given
506 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
509 *pInstance
= radv_instance_to_handle(instance
);
514 void radv_DestroyInstance(
515 VkInstance _instance
,
516 const VkAllocationCallbacks
* pAllocator
)
518 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
523 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
524 radv_physical_device_finish(instance
->physicalDevices
+ i
);
527 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
531 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
533 vk_free(&instance
->alloc
, instance
);
537 radv_enumerate_devices(struct radv_instance
*instance
)
539 /* TODO: Check for more devices ? */
540 drmDevicePtr devices
[8];
541 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
544 instance
->physicalDeviceCount
= 0;
546 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
548 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
550 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
551 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
552 devices
[i
]->bustype
== DRM_BUS_PCI
&&
553 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
555 result
= radv_physical_device_init(instance
->physicalDevices
+
556 instance
->physicalDeviceCount
,
559 if (result
== VK_SUCCESS
)
560 ++instance
->physicalDeviceCount
;
561 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
565 drmFreeDevices(devices
, max_devices
);
570 VkResult
radv_EnumeratePhysicalDevices(
571 VkInstance _instance
,
572 uint32_t* pPhysicalDeviceCount
,
573 VkPhysicalDevice
* pPhysicalDevices
)
575 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
578 if (instance
->physicalDeviceCount
< 0) {
579 result
= radv_enumerate_devices(instance
);
580 if (result
!= VK_SUCCESS
&&
581 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
585 if (!pPhysicalDevices
) {
586 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
588 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
589 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
590 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
593 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
597 VkResult
radv_EnumeratePhysicalDeviceGroups(
598 VkInstance _instance
,
599 uint32_t* pPhysicalDeviceGroupCount
,
600 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
602 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
605 if (instance
->physicalDeviceCount
< 0) {
606 result
= radv_enumerate_devices(instance
);
607 if (result
!= VK_SUCCESS
&&
608 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
612 if (!pPhysicalDeviceGroupProperties
) {
613 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
615 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
616 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
617 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
618 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
619 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
622 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
626 void radv_GetPhysicalDeviceFeatures(
627 VkPhysicalDevice physicalDevice
,
628 VkPhysicalDeviceFeatures
* pFeatures
)
630 memset(pFeatures
, 0, sizeof(*pFeatures
));
632 *pFeatures
= (VkPhysicalDeviceFeatures
) {
633 .robustBufferAccess
= true,
634 .fullDrawIndexUint32
= true,
635 .imageCubeArray
= true,
636 .independentBlend
= true,
637 .geometryShader
= true,
638 .tessellationShader
= true,
639 .sampleRateShading
= true,
640 .dualSrcBlend
= true,
642 .multiDrawIndirect
= true,
643 .drawIndirectFirstInstance
= true,
645 .depthBiasClamp
= true,
646 .fillModeNonSolid
= true,
651 .multiViewport
= true,
652 .samplerAnisotropy
= true,
653 .textureCompressionETC2
= false,
654 .textureCompressionASTC_LDR
= false,
655 .textureCompressionBC
= true,
656 .occlusionQueryPrecise
= true,
657 .pipelineStatisticsQuery
= true,
658 .vertexPipelineStoresAndAtomics
= true,
659 .fragmentStoresAndAtomics
= true,
660 .shaderTessellationAndGeometryPointSize
= true,
661 .shaderImageGatherExtended
= true,
662 .shaderStorageImageExtendedFormats
= true,
663 .shaderStorageImageMultisample
= false,
664 .shaderUniformBufferArrayDynamicIndexing
= true,
665 .shaderSampledImageArrayDynamicIndexing
= true,
666 .shaderStorageBufferArrayDynamicIndexing
= true,
667 .shaderStorageImageArrayDynamicIndexing
= true,
668 .shaderStorageImageReadWithoutFormat
= true,
669 .shaderStorageImageWriteWithoutFormat
= true,
670 .shaderClipDistance
= true,
671 .shaderCullDistance
= true,
672 .shaderFloat64
= true,
674 .shaderInt16
= false,
675 .sparseBinding
= true,
676 .variableMultisampleRate
= true,
677 .inheritedQueries
= true,
681 void radv_GetPhysicalDeviceFeatures2(
682 VkPhysicalDevice physicalDevice
,
683 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
685 vk_foreach_struct(ext
, pFeatures
->pNext
) {
686 switch (ext
->sType
) {
687 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
688 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
689 features
->variablePointersStorageBuffer
= true;
690 features
->variablePointers
= false;
693 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
694 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
695 features
->multiview
= true;
696 features
->multiviewGeometryShader
= true;
697 features
->multiviewTessellationShader
= true;
700 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
701 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
702 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
703 features
->shaderDrawParameters
= true;
706 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
707 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
708 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
709 features
->protectedMemory
= false;
712 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
713 VkPhysicalDevice16BitStorageFeatures
*features
=
714 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
715 features
->storageBuffer16BitAccess
= false;
716 features
->uniformAndStorageBuffer16BitAccess
= false;
717 features
->storagePushConstant16
= false;
718 features
->storageInputOutput16
= false;
721 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
722 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
723 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
724 features
->samplerYcbcrConversion
= false;
731 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
734 void radv_GetPhysicalDeviceProperties(
735 VkPhysicalDevice physicalDevice
,
736 VkPhysicalDeviceProperties
* pProperties
)
738 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
739 VkSampleCountFlags sample_counts
= 0xf;
741 /* make sure that the entire descriptor set is addressable with a signed
742 * 32-bit int. So the sum of all limits scaled by descriptor size has to
743 * be at most 2 GiB. the combined image & samples object count as one of
744 * both. This limit is for the pipeline layout, not for the set layout, but
745 * there is no set limit, so we just set a pipeline limit. I don't think
746 * any app is going to hit this soon. */
747 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
748 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
749 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
750 32 /* sampler, largest when combined with image */ +
751 64 /* sampled image */ +
752 64 /* storage image */);
754 VkPhysicalDeviceLimits limits
= {
755 .maxImageDimension1D
= (1 << 14),
756 .maxImageDimension2D
= (1 << 14),
757 .maxImageDimension3D
= (1 << 11),
758 .maxImageDimensionCube
= (1 << 14),
759 .maxImageArrayLayers
= (1 << 11),
760 .maxTexelBufferElements
= 128 * 1024 * 1024,
761 .maxUniformBufferRange
= UINT32_MAX
,
762 .maxStorageBufferRange
= UINT32_MAX
,
763 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
764 .maxMemoryAllocationCount
= UINT32_MAX
,
765 .maxSamplerAllocationCount
= 64 * 1024,
766 .bufferImageGranularity
= 64, /* A cache line */
767 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
768 .maxBoundDescriptorSets
= MAX_SETS
,
769 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
770 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
771 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
772 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
773 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
774 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
775 .maxPerStageResources
= max_descriptor_set_size
,
776 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
777 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
778 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
779 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
780 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
781 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
782 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
783 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
784 .maxVertexInputAttributes
= 32,
785 .maxVertexInputBindings
= 32,
786 .maxVertexInputAttributeOffset
= 2047,
787 .maxVertexInputBindingStride
= 2048,
788 .maxVertexOutputComponents
= 128,
789 .maxTessellationGenerationLevel
= 64,
790 .maxTessellationPatchSize
= 32,
791 .maxTessellationControlPerVertexInputComponents
= 128,
792 .maxTessellationControlPerVertexOutputComponents
= 128,
793 .maxTessellationControlPerPatchOutputComponents
= 120,
794 .maxTessellationControlTotalOutputComponents
= 4096,
795 .maxTessellationEvaluationInputComponents
= 128,
796 .maxTessellationEvaluationOutputComponents
= 128,
797 .maxGeometryShaderInvocations
= 127,
798 .maxGeometryInputComponents
= 64,
799 .maxGeometryOutputComponents
= 128,
800 .maxGeometryOutputVertices
= 256,
801 .maxGeometryTotalOutputComponents
= 1024,
802 .maxFragmentInputComponents
= 128,
803 .maxFragmentOutputAttachments
= 8,
804 .maxFragmentDualSrcAttachments
= 1,
805 .maxFragmentCombinedOutputResources
= 8,
806 .maxComputeSharedMemorySize
= 32768,
807 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
808 .maxComputeWorkGroupInvocations
= 2048,
809 .maxComputeWorkGroupSize
= {
814 .subPixelPrecisionBits
= 4 /* FIXME */,
815 .subTexelPrecisionBits
= 4 /* FIXME */,
816 .mipmapPrecisionBits
= 4 /* FIXME */,
817 .maxDrawIndexedIndexValue
= UINT32_MAX
,
818 .maxDrawIndirectCount
= UINT32_MAX
,
819 .maxSamplerLodBias
= 16,
820 .maxSamplerAnisotropy
= 16,
821 .maxViewports
= MAX_VIEWPORTS
,
822 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
823 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
824 .viewportSubPixelBits
= 13, /* We take a float? */
825 .minMemoryMapAlignment
= 4096, /* A page */
826 .minTexelBufferOffsetAlignment
= 1,
827 .minUniformBufferOffsetAlignment
= 4,
828 .minStorageBufferOffsetAlignment
= 4,
829 .minTexelOffset
= -32,
830 .maxTexelOffset
= 31,
831 .minTexelGatherOffset
= -32,
832 .maxTexelGatherOffset
= 31,
833 .minInterpolationOffset
= -2,
834 .maxInterpolationOffset
= 2,
835 .subPixelInterpolationOffsetBits
= 8,
836 .maxFramebufferWidth
= (1 << 14),
837 .maxFramebufferHeight
= (1 << 14),
838 .maxFramebufferLayers
= (1 << 10),
839 .framebufferColorSampleCounts
= sample_counts
,
840 .framebufferDepthSampleCounts
= sample_counts
,
841 .framebufferStencilSampleCounts
= sample_counts
,
842 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
843 .maxColorAttachments
= MAX_RTS
,
844 .sampledImageColorSampleCounts
= sample_counts
,
845 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
846 .sampledImageDepthSampleCounts
= sample_counts
,
847 .sampledImageStencilSampleCounts
= sample_counts
,
848 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
849 .maxSampleMaskWords
= 1,
850 .timestampComputeAndGraphics
= true,
851 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
852 .maxClipDistances
= 8,
853 .maxCullDistances
= 8,
854 .maxCombinedClipAndCullDistances
= 8,
855 .discreteQueuePriorities
= 1,
856 .pointSizeRange
= { 0.125, 255.875 },
857 .lineWidthRange
= { 0.0, 7.9921875 },
858 .pointSizeGranularity
= (1.0 / 8.0),
859 .lineWidthGranularity
= (1.0 / 128.0),
860 .strictLines
= false, /* FINISHME */
861 .standardSampleLocations
= true,
862 .optimalBufferCopyOffsetAlignment
= 128,
863 .optimalBufferCopyRowPitchAlignment
= 128,
864 .nonCoherentAtomSize
= 64,
867 *pProperties
= (VkPhysicalDeviceProperties
) {
868 .apiVersion
= radv_physical_device_api_version(pdevice
),
869 .driverVersion
= vk_get_driver_version(),
870 .vendorID
= ATI_VENDOR_ID
,
871 .deviceID
= pdevice
->rad_info
.pci_id
,
872 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
874 .sparseProperties
= {0},
877 strcpy(pProperties
->deviceName
, pdevice
->name
);
878 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
881 void radv_GetPhysicalDeviceProperties2(
882 VkPhysicalDevice physicalDevice
,
883 VkPhysicalDeviceProperties2KHR
*pProperties
)
885 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
886 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
888 vk_foreach_struct(ext
, pProperties
->pNext
) {
889 switch (ext
->sType
) {
890 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
891 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
892 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
893 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
896 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
897 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
898 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
899 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
900 properties
->deviceLUIDValid
= false;
903 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
904 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
905 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
906 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
909 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
910 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
911 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
912 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
915 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
916 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
917 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
918 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
921 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
922 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
923 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
924 properties
->minImportedHostPointerAlignment
= 4096;
927 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
928 VkPhysicalDeviceSubgroupProperties
*properties
=
929 (VkPhysicalDeviceSubgroupProperties
*)ext
;
930 properties
->subgroupSize
= 64;
931 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
932 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
;
933 properties
->quadOperationsInAllStages
= false;
936 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
937 VkPhysicalDeviceMaintenance3Properties
*properties
=
938 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
939 /* Make sure everything is addressable by a signed 32-bit int, and
940 * our largest descriptors are 96 bytes. */
941 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
942 /* Our buffer size fields allow only this much */
943 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
952 static void radv_get_physical_device_queue_family_properties(
953 struct radv_physical_device
* pdevice
,
955 VkQueueFamilyProperties
** pQueueFamilyProperties
)
957 int num_queue_families
= 1;
959 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
960 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
961 num_queue_families
++;
963 if (pQueueFamilyProperties
== NULL
) {
964 *pCount
= num_queue_families
;
973 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
974 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
975 VK_QUEUE_COMPUTE_BIT
|
976 VK_QUEUE_TRANSFER_BIT
|
977 VK_QUEUE_SPARSE_BINDING_BIT
,
979 .timestampValidBits
= 64,
980 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
985 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
986 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
988 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
989 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
990 VK_QUEUE_TRANSFER_BIT
|
991 VK_QUEUE_SPARSE_BINDING_BIT
,
992 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
993 .timestampValidBits
= 64,
994 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1002 void radv_GetPhysicalDeviceQueueFamilyProperties(
1003 VkPhysicalDevice physicalDevice
,
1005 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1007 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1008 if (!pQueueFamilyProperties
) {
1009 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1012 VkQueueFamilyProperties
*properties
[] = {
1013 pQueueFamilyProperties
+ 0,
1014 pQueueFamilyProperties
+ 1,
1015 pQueueFamilyProperties
+ 2,
1017 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1018 assert(*pCount
<= 3);
1021 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1022 VkPhysicalDevice physicalDevice
,
1024 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1026 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1027 if (!pQueueFamilyProperties
) {
1028 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1031 VkQueueFamilyProperties
*properties
[] = {
1032 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1033 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1034 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1036 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1037 assert(*pCount
<= 3);
1040 void radv_GetPhysicalDeviceMemoryProperties(
1041 VkPhysicalDevice physicalDevice
,
1042 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1044 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1046 *pMemoryProperties
= physical_device
->memory_properties
;
1049 void radv_GetPhysicalDeviceMemoryProperties2(
1050 VkPhysicalDevice physicalDevice
,
1051 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1053 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1054 &pMemoryProperties
->memoryProperties
);
1057 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1059 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1060 const void *pHostPointer
,
1061 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1063 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1067 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1068 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1069 uint32_t memoryTypeBits
= 0;
1070 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1071 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1072 memoryTypeBits
= (1 << i
);
1076 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1080 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1084 static enum radeon_ctx_priority
1085 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1087 /* Default to MEDIUM when a specific global priority isn't requested */
1089 return RADEON_CTX_PRIORITY_MEDIUM
;
1091 switch(pObj
->globalPriority
) {
1092 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1093 return RADEON_CTX_PRIORITY_REALTIME
;
1094 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1095 return RADEON_CTX_PRIORITY_HIGH
;
1096 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1097 return RADEON_CTX_PRIORITY_MEDIUM
;
1098 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1099 return RADEON_CTX_PRIORITY_LOW
;
1101 unreachable("Illegal global priority value");
1102 return RADEON_CTX_PRIORITY_INVALID
;
1107 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1108 uint32_t queue_family_index
, int idx
,
1109 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1111 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1112 queue
->device
= device
;
1113 queue
->queue_family_index
= queue_family_index
;
1114 queue
->queue_idx
= idx
;
1115 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1117 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1119 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1125 radv_queue_finish(struct radv_queue
*queue
)
1128 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1130 if (queue
->initial_full_flush_preamble_cs
)
1131 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1132 if (queue
->initial_preamble_cs
)
1133 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1134 if (queue
->continue_preamble_cs
)
1135 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1136 if (queue
->descriptor_bo
)
1137 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1138 if (queue
->scratch_bo
)
1139 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1140 if (queue
->esgs_ring_bo
)
1141 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1142 if (queue
->gsvs_ring_bo
)
1143 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1144 if (queue
->tess_rings_bo
)
1145 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1146 if (queue
->compute_scratch_bo
)
1147 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1151 radv_device_init_gs_info(struct radv_device
*device
)
1153 switch (device
->physical_device
->rad_info
.family
) {
1162 device
->gs_table_depth
= 16;
1171 case CHIP_POLARIS10
:
1172 case CHIP_POLARIS11
:
1173 case CHIP_POLARIS12
:
1176 device
->gs_table_depth
= 32;
1179 unreachable("unknown GPU");
1183 static int radv_get_device_extension_index(const char *name
)
1185 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1186 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1192 VkResult
radv_CreateDevice(
1193 VkPhysicalDevice physicalDevice
,
1194 const VkDeviceCreateInfo
* pCreateInfo
,
1195 const VkAllocationCallbacks
* pAllocator
,
1198 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1200 struct radv_device
*device
;
1202 bool keep_shader_info
= false;
1204 /* Check enabled features */
1205 if (pCreateInfo
->pEnabledFeatures
) {
1206 VkPhysicalDeviceFeatures supported_features
;
1207 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1208 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1209 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1210 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1211 for (uint32_t i
= 0; i
< num_features
; i
++) {
1212 if (enabled_feature
[i
] && !supported_feature
[i
])
1213 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1217 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1219 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1221 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1223 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1224 device
->instance
= physical_device
->instance
;
1225 device
->physical_device
= physical_device
;
1227 device
->ws
= physical_device
->ws
;
1229 device
->alloc
= *pAllocator
;
1231 device
->alloc
= physical_device
->instance
->alloc
;
1233 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1234 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1235 int index
= radv_get_device_extension_index(ext_name
);
1236 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1237 vk_free(&device
->alloc
, device
);
1238 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1241 device
->enabled_extensions
.extensions
[index
] = true;
1244 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1246 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1247 list_inithead(&device
->shader_slabs
);
1249 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1250 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1251 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1252 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1253 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1255 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1257 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1258 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1259 if (!device
->queues
[qfi
]) {
1260 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1264 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1266 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1268 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1269 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
, global_priority
);
1270 if (result
!= VK_SUCCESS
)
1275 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1276 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1278 /* Disabled and not implemented for now. */
1279 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1282 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1285 device
->llvm_supports_spill
= true;
1287 /* The maximum number of scratch waves. Scratch space isn't divided
1288 * evenly between CUs. The number is only a function of the number of CUs.
1289 * We can decrease the constant to decrease the scratch buffer size.
1291 * sctx->scratch_waves must be >= the maximum posible size of
1292 * 1 threadgroup, so that the hw doesn't hang from being unable
1295 * The recommended value is 4 per CU at most. Higher numbers don't
1296 * bring much benefit, but they still occupy chip resources (think
1297 * async compute). I've seen ~2% performance difference between 4 and 32.
1299 uint32_t max_threads_per_block
= 2048;
1300 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1301 max_threads_per_block
/ 64);
1303 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1305 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1306 /* If the KMD allows it (there is a KMD hw register for it),
1307 * allow launching waves out-of-order.
1309 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1312 radv_device_init_gs_info(device
);
1314 device
->tess_offchip_block_dw_size
=
1315 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1316 device
->has_distributed_tess
=
1317 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1318 device
->physical_device
->rad_info
.max_se
>= 2;
1320 if (getenv("RADV_TRACE_FILE")) {
1321 keep_shader_info
= true;
1323 if (!radv_init_trace(device
))
1327 device
->keep_shader_info
= keep_shader_info
;
1329 result
= radv_device_init_meta(device
);
1330 if (result
!= VK_SUCCESS
)
1333 radv_device_init_msaa(device
);
1335 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1336 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1338 case RADV_QUEUE_GENERAL
:
1339 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1340 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1341 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1343 case RADV_QUEUE_COMPUTE
:
1344 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1345 radeon_emit(device
->empty_cs
[family
], 0);
1348 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1351 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1352 cik_create_gfx_config(device
);
1354 VkPipelineCacheCreateInfo ci
;
1355 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1358 ci
.pInitialData
= NULL
;
1359 ci
.initialDataSize
= 0;
1361 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1363 if (result
!= VK_SUCCESS
)
1366 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1368 *pDevice
= radv_device_to_handle(device
);
1372 radv_device_finish_meta(device
);
1374 if (device
->trace_bo
)
1375 device
->ws
->buffer_destroy(device
->trace_bo
);
1377 if (device
->gfx_init
)
1378 device
->ws
->buffer_destroy(device
->gfx_init
);
1380 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1381 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1382 radv_queue_finish(&device
->queues
[i
][q
]);
1383 if (device
->queue_count
[i
])
1384 vk_free(&device
->alloc
, device
->queues
[i
]);
1387 vk_free(&device
->alloc
, device
);
1391 void radv_DestroyDevice(
1393 const VkAllocationCallbacks
* pAllocator
)
1395 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1400 if (device
->trace_bo
)
1401 device
->ws
->buffer_destroy(device
->trace_bo
);
1403 if (device
->gfx_init
)
1404 device
->ws
->buffer_destroy(device
->gfx_init
);
1406 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1407 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1408 radv_queue_finish(&device
->queues
[i
][q
]);
1409 if (device
->queue_count
[i
])
1410 vk_free(&device
->alloc
, device
->queues
[i
]);
1411 if (device
->empty_cs
[i
])
1412 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1414 radv_device_finish_meta(device
);
1416 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1417 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1419 radv_destroy_shader_slabs(device
);
1421 vk_free(&device
->alloc
, device
);
1424 VkResult
radv_EnumerateInstanceLayerProperties(
1425 uint32_t* pPropertyCount
,
1426 VkLayerProperties
* pProperties
)
1428 if (pProperties
== NULL
) {
1429 *pPropertyCount
= 0;
1433 /* None supported at this time */
1434 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1437 VkResult
radv_EnumerateDeviceLayerProperties(
1438 VkPhysicalDevice physicalDevice
,
1439 uint32_t* pPropertyCount
,
1440 VkLayerProperties
* pProperties
)
1442 if (pProperties
== NULL
) {
1443 *pPropertyCount
= 0;
1447 /* None supported at this time */
1448 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1451 void radv_GetDeviceQueue2(
1453 const VkDeviceQueueInfo2
* pQueueInfo
,
1456 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1458 *pQueue
= radv_queue_to_handle(&device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
]);
1461 void radv_GetDeviceQueue(
1463 uint32_t queueFamilyIndex
,
1464 uint32_t queueIndex
,
1467 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1468 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1469 .queueFamilyIndex
= queueFamilyIndex
,
1470 .queueIndex
= queueIndex
1473 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1477 fill_geom_tess_rings(struct radv_queue
*queue
,
1479 bool add_sample_positions
,
1480 uint32_t esgs_ring_size
,
1481 struct radeon_winsys_bo
*esgs_ring_bo
,
1482 uint32_t gsvs_ring_size
,
1483 struct radeon_winsys_bo
*gsvs_ring_bo
,
1484 uint32_t tess_factor_ring_size
,
1485 uint32_t tess_offchip_ring_offset
,
1486 uint32_t tess_offchip_ring_size
,
1487 struct radeon_winsys_bo
*tess_rings_bo
)
1489 uint64_t esgs_va
= 0, gsvs_va
= 0;
1490 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1491 uint32_t *desc
= &map
[4];
1494 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1496 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1497 if (tess_rings_bo
) {
1498 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1499 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1502 /* stride 0, num records - size, add tid, swizzle, elsize4,
1505 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1506 S_008F04_STRIDE(0) |
1507 S_008F04_SWIZZLE_ENABLE(true);
1508 desc
[2] = esgs_ring_size
;
1509 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1510 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1511 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1512 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1513 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1514 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1515 S_008F0C_ELEMENT_SIZE(1) |
1516 S_008F0C_INDEX_STRIDE(3) |
1517 S_008F0C_ADD_TID_ENABLE(true);
1520 /* GS entry for ES->GS ring */
1521 /* stride 0, num records - size, elsize0,
1524 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1525 S_008F04_STRIDE(0) |
1526 S_008F04_SWIZZLE_ENABLE(false);
1527 desc
[2] = esgs_ring_size
;
1528 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1529 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1530 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1531 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1532 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1533 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1534 S_008F0C_ELEMENT_SIZE(0) |
1535 S_008F0C_INDEX_STRIDE(0) |
1536 S_008F0C_ADD_TID_ENABLE(false);
1539 /* VS entry for GS->VS ring */
1540 /* stride 0, num records - size, elsize0,
1543 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1544 S_008F04_STRIDE(0) |
1545 S_008F04_SWIZZLE_ENABLE(false);
1546 desc
[2] = gsvs_ring_size
;
1547 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1548 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1549 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1550 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1551 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1552 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1553 S_008F0C_ELEMENT_SIZE(0) |
1554 S_008F0C_INDEX_STRIDE(0) |
1555 S_008F0C_ADD_TID_ENABLE(false);
1558 /* stride gsvs_itemsize, num records 64
1559 elsize 4, index stride 16 */
1560 /* shader will patch stride and desc[2] */
1562 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1563 S_008F04_STRIDE(0) |
1564 S_008F04_SWIZZLE_ENABLE(true);
1566 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1567 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1568 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1569 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1570 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1571 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1572 S_008F0C_ELEMENT_SIZE(1) |
1573 S_008F0C_INDEX_STRIDE(1) |
1574 S_008F0C_ADD_TID_ENABLE(true);
1578 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1579 S_008F04_STRIDE(0) |
1580 S_008F04_SWIZZLE_ENABLE(false);
1581 desc
[2] = tess_factor_ring_size
;
1582 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1583 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1584 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1585 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1586 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1587 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1588 S_008F0C_ELEMENT_SIZE(0) |
1589 S_008F0C_INDEX_STRIDE(0) |
1590 S_008F0C_ADD_TID_ENABLE(false);
1593 desc
[0] = tess_offchip_va
;
1594 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1595 S_008F04_STRIDE(0) |
1596 S_008F04_SWIZZLE_ENABLE(false);
1597 desc
[2] = tess_offchip_ring_size
;
1598 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1599 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1600 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1601 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1602 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1603 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1604 S_008F0C_ELEMENT_SIZE(0) |
1605 S_008F0C_INDEX_STRIDE(0) |
1606 S_008F0C_ADD_TID_ENABLE(false);
1609 /* add sample positions after all rings */
1610 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1612 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1614 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1616 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1618 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1622 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1624 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1625 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1626 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1627 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1628 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1629 device
->physical_device
->rad_info
.max_se
;
1630 unsigned offchip_granularity
;
1631 unsigned hs_offchip_param
;
1632 switch (device
->tess_offchip_block_dw_size
) {
1637 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1640 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1644 switch (device
->physical_device
->rad_info
.chip_class
) {
1646 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1652 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1656 *max_offchip_buffers_p
= max_offchip_buffers
;
1657 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1658 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1659 --max_offchip_buffers
;
1661 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1662 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1665 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1667 return hs_offchip_param
;
1671 radv_get_preamble_cs(struct radv_queue
*queue
,
1672 uint32_t scratch_size
,
1673 uint32_t compute_scratch_size
,
1674 uint32_t esgs_ring_size
,
1675 uint32_t gsvs_ring_size
,
1676 bool needs_tess_rings
,
1677 bool needs_sample_positions
,
1678 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1679 struct radeon_winsys_cs
**initial_preamble_cs
,
1680 struct radeon_winsys_cs
**continue_preamble_cs
)
1682 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1683 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1684 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1685 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1686 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1687 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1688 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1689 bool add_tess_rings
= false, add_sample_positions
= false;
1690 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1691 unsigned max_offchip_buffers
;
1692 unsigned hs_offchip_param
= 0;
1693 unsigned tess_offchip_ring_offset
;
1694 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1695 if (!queue
->has_tess_rings
) {
1696 if (needs_tess_rings
)
1697 add_tess_rings
= true;
1699 if (!queue
->has_sample_positions
) {
1700 if (needs_sample_positions
)
1701 add_sample_positions
= true;
1703 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1704 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1705 &max_offchip_buffers
);
1706 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1707 tess_offchip_ring_size
= max_offchip_buffers
*
1708 queue
->device
->tess_offchip_block_dw_size
* 4;
1710 if (scratch_size
<= queue
->scratch_size
&&
1711 compute_scratch_size
<= queue
->compute_scratch_size
&&
1712 esgs_ring_size
<= queue
->esgs_ring_size
&&
1713 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1714 !add_tess_rings
&& !add_sample_positions
&&
1715 queue
->initial_preamble_cs
) {
1716 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1717 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1718 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1719 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1720 *continue_preamble_cs
= NULL
;
1724 if (scratch_size
> queue
->scratch_size
) {
1725 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1733 scratch_bo
= queue
->scratch_bo
;
1735 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1736 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1737 compute_scratch_size
,
1741 if (!compute_scratch_bo
)
1745 compute_scratch_bo
= queue
->compute_scratch_bo
;
1747 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1748 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1756 esgs_ring_bo
= queue
->esgs_ring_bo
;
1757 esgs_ring_size
= queue
->esgs_ring_size
;
1760 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1761 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1769 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1770 gsvs_ring_size
= queue
->gsvs_ring_size
;
1773 if (add_tess_rings
) {
1774 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1775 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
1782 tess_rings_bo
= queue
->tess_rings_bo
;
1785 if (scratch_bo
!= queue
->scratch_bo
||
1786 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1787 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1788 tess_rings_bo
!= queue
->tess_rings_bo
||
1789 add_sample_positions
) {
1791 if (gsvs_ring_bo
|| esgs_ring_bo
||
1792 tess_rings_bo
|| add_sample_positions
) {
1793 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1794 if (add_sample_positions
)
1795 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1797 else if (scratch_bo
)
1798 size
= 8; /* 2 dword */
1800 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1804 RADEON_FLAG_CPU_ACCESS
|
1805 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
1806 RADEON_FLAG_READ_ONLY
);
1810 descriptor_bo
= queue
->descriptor_bo
;
1812 for(int i
= 0; i
< 3; ++i
) {
1813 struct radeon_winsys_cs
*cs
= NULL
;
1814 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1815 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1822 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
1825 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1828 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1831 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1834 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1836 if (descriptor_bo
!= queue
->descriptor_bo
) {
1837 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1840 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1841 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1842 S_008F04_SWIZZLE_ENABLE(1);
1843 map
[0] = scratch_va
;
1847 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
1848 add_sample_positions
)
1849 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1850 esgs_ring_size
, esgs_ring_bo
,
1851 gsvs_ring_size
, gsvs_ring_bo
,
1852 tess_factor_ring_size
,
1853 tess_offchip_ring_offset
,
1854 tess_offchip_ring_size
,
1857 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1860 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
1861 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1862 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1863 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1864 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1867 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1868 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1869 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1870 radeon_emit(cs
, esgs_ring_size
>> 8);
1871 radeon_emit(cs
, gsvs_ring_size
>> 8);
1873 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1874 radeon_emit(cs
, esgs_ring_size
>> 8);
1875 radeon_emit(cs
, gsvs_ring_size
>> 8);
1879 if (tess_rings_bo
) {
1880 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
1881 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1882 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1883 S_030938_SIZE(tess_factor_ring_size
/ 4));
1884 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1886 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1887 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1890 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1892 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1893 S_008988_SIZE(tess_factor_ring_size
/ 4));
1894 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1896 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1901 if (descriptor_bo
) {
1902 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1903 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1904 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1905 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1906 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1907 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1909 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1910 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1911 radeon_emit(cs
, va
);
1912 radeon_emit(cs
, va
>> 32);
1915 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1916 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1917 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1918 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1919 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1920 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1922 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1923 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1924 radeon_emit(cs
, va
);
1925 radeon_emit(cs
, va
>> 32);
1930 if (compute_scratch_bo
) {
1931 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1932 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1933 S_008F04_SWIZZLE_ENABLE(1);
1935 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1937 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1938 radeon_emit(cs
, scratch_va
);
1939 radeon_emit(cs
, rsrc1
);
1943 si_cs_emit_cache_flush(cs
,
1944 queue
->device
->physical_device
->rad_info
.chip_class
,
1946 queue
->queue_family_index
== RING_COMPUTE
&&
1947 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1948 (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
)) |
1949 RADV_CMD_FLAG_INV_ICACHE
|
1950 RADV_CMD_FLAG_INV_SMEM_L1
|
1951 RADV_CMD_FLAG_INV_VMEM_L1
|
1952 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1953 } else if (i
== 1) {
1954 si_cs_emit_cache_flush(cs
,
1955 queue
->device
->physical_device
->rad_info
.chip_class
,
1957 queue
->queue_family_index
== RING_COMPUTE
&&
1958 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1959 RADV_CMD_FLAG_INV_ICACHE
|
1960 RADV_CMD_FLAG_INV_SMEM_L1
|
1961 RADV_CMD_FLAG_INV_VMEM_L1
|
1962 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1965 if (!queue
->device
->ws
->cs_finalize(cs
))
1969 if (queue
->initial_full_flush_preamble_cs
)
1970 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1972 if (queue
->initial_preamble_cs
)
1973 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1975 if (queue
->continue_preamble_cs
)
1976 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1978 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1979 queue
->initial_preamble_cs
= dest_cs
[1];
1980 queue
->continue_preamble_cs
= dest_cs
[2];
1982 if (scratch_bo
!= queue
->scratch_bo
) {
1983 if (queue
->scratch_bo
)
1984 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1985 queue
->scratch_bo
= scratch_bo
;
1986 queue
->scratch_size
= scratch_size
;
1989 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1990 if (queue
->compute_scratch_bo
)
1991 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1992 queue
->compute_scratch_bo
= compute_scratch_bo
;
1993 queue
->compute_scratch_size
= compute_scratch_size
;
1996 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1997 if (queue
->esgs_ring_bo
)
1998 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1999 queue
->esgs_ring_bo
= esgs_ring_bo
;
2000 queue
->esgs_ring_size
= esgs_ring_size
;
2003 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2004 if (queue
->gsvs_ring_bo
)
2005 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2006 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2007 queue
->gsvs_ring_size
= gsvs_ring_size
;
2010 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2011 queue
->tess_rings_bo
= tess_rings_bo
;
2012 queue
->has_tess_rings
= true;
2015 if (descriptor_bo
!= queue
->descriptor_bo
) {
2016 if (queue
->descriptor_bo
)
2017 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2019 queue
->descriptor_bo
= descriptor_bo
;
2022 if (add_sample_positions
)
2023 queue
->has_sample_positions
= true;
2025 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2026 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2027 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2028 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2029 *continue_preamble_cs
= NULL
;
2032 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2034 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2035 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2036 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2037 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2038 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2039 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2040 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2041 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2042 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2043 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2044 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2045 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2046 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2047 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2050 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2052 const VkSemaphore
*sems
,
2056 int syncobj_idx
= 0, sem_idx
= 0;
2058 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2061 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2062 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2064 if (sem
->temp_syncobj
|| sem
->syncobj
)
2065 counts
->syncobj_count
++;
2067 counts
->sem_count
++;
2070 if (_fence
!= VK_NULL_HANDLE
) {
2071 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2072 if (fence
->temp_syncobj
|| fence
->syncobj
)
2073 counts
->syncobj_count
++;
2076 if (counts
->syncobj_count
) {
2077 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2078 if (!counts
->syncobj
)
2079 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2082 if (counts
->sem_count
) {
2083 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2085 free(counts
->syncobj
);
2086 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2090 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2091 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2093 if (sem
->temp_syncobj
) {
2094 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2096 else if (sem
->syncobj
)
2097 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2100 counts
->sem
[sem_idx
++] = sem
->sem
;
2104 if (_fence
!= VK_NULL_HANDLE
) {
2105 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2106 if (fence
->temp_syncobj
)
2107 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2108 else if (fence
->syncobj
)
2109 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2115 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2117 free(sem_info
->wait
.syncobj
);
2118 free(sem_info
->wait
.sem
);
2119 free(sem_info
->signal
.syncobj
);
2120 free(sem_info
->signal
.sem
);
2124 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2126 const VkSemaphore
*sems
)
2128 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2129 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2131 if (sem
->temp_syncobj
) {
2132 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2133 sem
->temp_syncobj
= 0;
2138 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2140 const VkSemaphore
*wait_sems
,
2141 int num_signal_sems
,
2142 const VkSemaphore
*signal_sems
,
2146 memset(sem_info
, 0, sizeof(*sem_info
));
2148 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2151 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2153 radv_free_sem_info(sem_info
);
2155 /* caller can override these */
2156 sem_info
->cs_emit_wait
= true;
2157 sem_info
->cs_emit_signal
= true;
2161 /* Signals fence as soon as all the work currently put on queue is done. */
2162 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2163 struct radv_fence
*fence
)
2167 struct radv_winsys_sem_info sem_info
;
2169 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2170 radv_fence_to_handle(fence
));
2171 if (result
!= VK_SUCCESS
)
2174 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2175 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2176 1, NULL
, NULL
, &sem_info
,
2177 false, fence
->fence
);
2178 radv_free_sem_info(&sem_info
);
2180 /* TODO: find a better error */
2182 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2187 VkResult
radv_QueueSubmit(
2189 uint32_t submitCount
,
2190 const VkSubmitInfo
* pSubmits
,
2193 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2194 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2195 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2196 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2198 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2199 uint32_t scratch_size
= 0;
2200 uint32_t compute_scratch_size
= 0;
2201 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2202 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2204 bool fence_emitted
= false;
2205 bool tess_rings_needed
= false;
2206 bool sample_positions_needed
= false;
2208 /* Do this first so failing to allocate scratch buffers can't result in
2209 * partially executed submissions. */
2210 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2211 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2212 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2213 pSubmits
[i
].pCommandBuffers
[j
]);
2215 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2216 compute_scratch_size
= MAX2(compute_scratch_size
,
2217 cmd_buffer
->compute_scratch_size_needed
);
2218 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2219 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2220 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2221 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2225 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2226 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2227 sample_positions_needed
, &initial_flush_preamble_cs
,
2228 &initial_preamble_cs
, &continue_preamble_cs
);
2229 if (result
!= VK_SUCCESS
)
2232 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2233 struct radeon_winsys_cs
**cs_array
;
2234 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2235 bool can_patch
= true;
2237 struct radv_winsys_sem_info sem_info
;
2239 result
= radv_alloc_sem_info(&sem_info
,
2240 pSubmits
[i
].waitSemaphoreCount
,
2241 pSubmits
[i
].pWaitSemaphores
,
2242 pSubmits
[i
].signalSemaphoreCount
,
2243 pSubmits
[i
].pSignalSemaphores
,
2245 if (result
!= VK_SUCCESS
)
2248 if (!pSubmits
[i
].commandBufferCount
) {
2249 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2250 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2251 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2256 radv_loge("failed to submit CS %d\n", i
);
2259 fence_emitted
= true;
2261 radv_free_sem_info(&sem_info
);
2265 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2266 (pSubmits
[i
].commandBufferCount
));
2268 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2269 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2270 pSubmits
[i
].pCommandBuffers
[j
]);
2271 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2273 cs_array
[j
] = cmd_buffer
->cs
;
2274 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2277 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2280 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2281 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2282 advance
= MIN2(max_cs_submission
,
2283 pSubmits
[i
].commandBufferCount
- j
);
2285 if (queue
->device
->trace_bo
)
2286 *queue
->device
->trace_id_ptr
= 0;
2288 sem_info
.cs_emit_wait
= j
== 0;
2289 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2291 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2292 advance
, initial_preamble
, continue_preamble_cs
,
2294 can_patch
, base_fence
);
2297 radv_loge("failed to submit CS %d\n", i
);
2300 fence_emitted
= true;
2301 if (queue
->device
->trace_bo
) {
2302 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2306 radv_free_temp_syncobjs(queue
->device
,
2307 pSubmits
[i
].waitSemaphoreCount
,
2308 pSubmits
[i
].pWaitSemaphores
);
2309 radv_free_sem_info(&sem_info
);
2314 if (!fence_emitted
) {
2315 radv_signal_fence(queue
, fence
);
2317 fence
->submitted
= true;
2323 VkResult
radv_QueueWaitIdle(
2326 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2328 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2329 radv_queue_family_to_ring(queue
->queue_family_index
),
2334 VkResult
radv_DeviceWaitIdle(
2337 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2339 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2340 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2341 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2347 VkResult
radv_EnumerateInstanceExtensionProperties(
2348 const char* pLayerName
,
2349 uint32_t* pPropertyCount
,
2350 VkExtensionProperties
* pProperties
)
2352 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2354 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2355 if (radv_supported_instance_extensions
.extensions
[i
]) {
2356 vk_outarray_append(&out
, prop
) {
2357 *prop
= radv_instance_extensions
[i
];
2362 return vk_outarray_status(&out
);
2365 VkResult
radv_EnumerateDeviceExtensionProperties(
2366 VkPhysicalDevice physicalDevice
,
2367 const char* pLayerName
,
2368 uint32_t* pPropertyCount
,
2369 VkExtensionProperties
* pProperties
)
2371 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2372 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2374 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2375 if (device
->supported_extensions
.extensions
[i
]) {
2376 vk_outarray_append(&out
, prop
) {
2377 *prop
= radv_device_extensions
[i
];
2382 return vk_outarray_status(&out
);
2385 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2386 VkInstance _instance
,
2389 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2391 return radv_lookup_entrypoint_checked(pName
,
2392 instance
? instance
->apiVersion
: 0,
2393 instance
? &instance
->enabled_extensions
: NULL
,
2397 /* The loader wants us to expose a second GetInstanceProcAddr function
2398 * to work around certain LD_PRELOAD issues seen in apps.
2401 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2402 VkInstance instance
,
2406 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2407 VkInstance instance
,
2410 return radv_GetInstanceProcAddr(instance
, pName
);
2413 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2417 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2419 return radv_lookup_entrypoint_checked(pName
,
2420 device
->instance
->apiVersion
,
2421 &device
->instance
->enabled_extensions
,
2422 &device
->enabled_extensions
);
2425 bool radv_get_memory_fd(struct radv_device
*device
,
2426 struct radv_device_memory
*memory
,
2429 struct radeon_bo_metadata metadata
;
2431 if (memory
->image
) {
2432 radv_init_metadata(device
, memory
->image
, &metadata
);
2433 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2436 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2440 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2441 const VkMemoryAllocateInfo
* pAllocateInfo
,
2442 const VkAllocationCallbacks
* pAllocator
,
2443 VkDeviceMemory
* pMem
)
2445 struct radv_device_memory
*mem
;
2447 enum radeon_bo_domain domain
;
2449 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2451 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2453 if (pAllocateInfo
->allocationSize
== 0) {
2454 /* Apparently, this is allowed */
2455 *pMem
= VK_NULL_HANDLE
;
2459 const VkImportMemoryFdInfoKHR
*import_info
=
2460 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2461 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2462 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2463 const VkExportMemoryAllocateInfoKHR
*export_info
=
2464 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2465 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2466 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2468 const struct wsi_memory_allocate_info
*wsi_info
=
2469 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2471 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2472 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2474 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2476 if (wsi_info
&& wsi_info
->implicit_sync
)
2477 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2479 if (dedicate_info
) {
2480 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2481 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2487 mem
->user_ptr
= NULL
;
2490 assert(import_info
->handleType
==
2491 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2492 import_info
->handleType
==
2493 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2494 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2497 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2500 close(import_info
->fd
);
2505 if (host_ptr_info
) {
2506 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2507 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2508 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2509 pAllocateInfo
->allocationSize
);
2511 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2514 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2519 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2520 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2521 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2522 domain
= RADEON_DOMAIN_GTT
;
2524 domain
= RADEON_DOMAIN_VRAM
;
2526 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2527 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2529 flags
|= RADEON_FLAG_CPU_ACCESS
;
2531 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2532 flags
|= RADEON_FLAG_GTT_WC
;
2534 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2535 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2537 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2541 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2544 mem
->type_index
= mem_type_index
;
2546 *pMem
= radv_device_memory_to_handle(mem
);
2551 vk_free2(&device
->alloc
, pAllocator
, mem
);
2556 VkResult
radv_AllocateMemory(
2558 const VkMemoryAllocateInfo
* pAllocateInfo
,
2559 const VkAllocationCallbacks
* pAllocator
,
2560 VkDeviceMemory
* pMem
)
2562 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2563 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2566 void radv_FreeMemory(
2568 VkDeviceMemory _mem
,
2569 const VkAllocationCallbacks
* pAllocator
)
2571 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2572 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2577 device
->ws
->buffer_destroy(mem
->bo
);
2580 vk_free2(&device
->alloc
, pAllocator
, mem
);
2583 VkResult
radv_MapMemory(
2585 VkDeviceMemory _memory
,
2586 VkDeviceSize offset
,
2588 VkMemoryMapFlags flags
,
2591 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2592 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2600 *ppData
= mem
->user_ptr
;
2602 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2609 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2612 void radv_UnmapMemory(
2614 VkDeviceMemory _memory
)
2616 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2617 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2622 if (mem
->user_ptr
== NULL
)
2623 device
->ws
->buffer_unmap(mem
->bo
);
2626 VkResult
radv_FlushMappedMemoryRanges(
2628 uint32_t memoryRangeCount
,
2629 const VkMappedMemoryRange
* pMemoryRanges
)
2634 VkResult
radv_InvalidateMappedMemoryRanges(
2636 uint32_t memoryRangeCount
,
2637 const VkMappedMemoryRange
* pMemoryRanges
)
2642 void radv_GetBufferMemoryRequirements(
2645 VkMemoryRequirements
* pMemoryRequirements
)
2647 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2648 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2650 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2652 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2653 pMemoryRequirements
->alignment
= 4096;
2655 pMemoryRequirements
->alignment
= 16;
2657 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2660 void radv_GetBufferMemoryRequirements2(
2662 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2663 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2665 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2666 &pMemoryRequirements
->memoryRequirements
);
2667 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2668 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2669 switch (ext
->sType
) {
2670 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2671 VkMemoryDedicatedRequirementsKHR
*req
=
2672 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2673 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2674 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2683 void radv_GetImageMemoryRequirements(
2686 VkMemoryRequirements
* pMemoryRequirements
)
2688 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2689 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2691 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2693 pMemoryRequirements
->size
= image
->size
;
2694 pMemoryRequirements
->alignment
= image
->alignment
;
2697 void radv_GetImageMemoryRequirements2(
2699 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2700 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2702 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2703 &pMemoryRequirements
->memoryRequirements
);
2705 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2707 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2708 switch (ext
->sType
) {
2709 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2710 VkMemoryDedicatedRequirementsKHR
*req
=
2711 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2712 req
->requiresDedicatedAllocation
= image
->shareable
;
2713 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2722 void radv_GetImageSparseMemoryRequirements(
2725 uint32_t* pSparseMemoryRequirementCount
,
2726 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2731 void radv_GetImageSparseMemoryRequirements2(
2733 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2734 uint32_t* pSparseMemoryRequirementCount
,
2735 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2740 void radv_GetDeviceMemoryCommitment(
2742 VkDeviceMemory memory
,
2743 VkDeviceSize
* pCommittedMemoryInBytes
)
2745 *pCommittedMemoryInBytes
= 0;
2748 VkResult
radv_BindBufferMemory2(VkDevice device
,
2749 uint32_t bindInfoCount
,
2750 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2752 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2753 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2754 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2757 buffer
->bo
= mem
->bo
;
2758 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2766 VkResult
radv_BindBufferMemory(
2769 VkDeviceMemory memory
,
2770 VkDeviceSize memoryOffset
)
2772 const VkBindBufferMemoryInfoKHR info
= {
2773 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2776 .memoryOffset
= memoryOffset
2779 return radv_BindBufferMemory2(device
, 1, &info
);
2782 VkResult
radv_BindImageMemory2(VkDevice device
,
2783 uint32_t bindInfoCount
,
2784 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2786 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2787 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2788 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2791 image
->bo
= mem
->bo
;
2792 image
->offset
= pBindInfos
[i
].memoryOffset
;
2802 VkResult
radv_BindImageMemory(
2805 VkDeviceMemory memory
,
2806 VkDeviceSize memoryOffset
)
2808 const VkBindImageMemoryInfoKHR info
= {
2809 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2812 .memoryOffset
= memoryOffset
2815 return radv_BindImageMemory2(device
, 1, &info
);
2820 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2821 const VkSparseBufferMemoryBindInfo
*bind
)
2823 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2825 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2826 struct radv_device_memory
*mem
= NULL
;
2828 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2829 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2831 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2832 bind
->pBinds
[i
].resourceOffset
,
2833 bind
->pBinds
[i
].size
,
2834 mem
? mem
->bo
: NULL
,
2835 bind
->pBinds
[i
].memoryOffset
);
2840 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2841 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2843 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2845 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2846 struct radv_device_memory
*mem
= NULL
;
2848 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2849 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2851 device
->ws
->buffer_virtual_bind(image
->bo
,
2852 bind
->pBinds
[i
].resourceOffset
,
2853 bind
->pBinds
[i
].size
,
2854 mem
? mem
->bo
: NULL
,
2855 bind
->pBinds
[i
].memoryOffset
);
2859 VkResult
radv_QueueBindSparse(
2861 uint32_t bindInfoCount
,
2862 const VkBindSparseInfo
* pBindInfo
,
2865 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2866 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2867 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2868 bool fence_emitted
= false;
2870 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2871 struct radv_winsys_sem_info sem_info
;
2872 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2873 radv_sparse_buffer_bind_memory(queue
->device
,
2874 pBindInfo
[i
].pBufferBinds
+ j
);
2877 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2878 radv_sparse_image_opaque_bind_memory(queue
->device
,
2879 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2883 result
= radv_alloc_sem_info(&sem_info
,
2884 pBindInfo
[i
].waitSemaphoreCount
,
2885 pBindInfo
[i
].pWaitSemaphores
,
2886 pBindInfo
[i
].signalSemaphoreCount
,
2887 pBindInfo
[i
].pSignalSemaphores
,
2889 if (result
!= VK_SUCCESS
)
2892 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2893 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2894 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2898 fence_emitted
= true;
2900 fence
->submitted
= true;
2903 radv_free_sem_info(&sem_info
);
2908 if (!fence_emitted
) {
2909 radv_signal_fence(queue
, fence
);
2911 fence
->submitted
= true;
2917 VkResult
radv_CreateFence(
2919 const VkFenceCreateInfo
* pCreateInfo
,
2920 const VkAllocationCallbacks
* pAllocator
,
2923 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2924 const VkExportFenceCreateInfoKHR
*export
=
2925 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
2926 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
2927 export
? export
->handleTypes
: 0;
2929 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2931 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2934 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2936 fence
->submitted
= false;
2937 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2938 fence
->temp_syncobj
= 0;
2939 if (device
->always_use_syncobj
|| handleTypes
) {
2940 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
2942 vk_free2(&device
->alloc
, pAllocator
, fence
);
2943 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2945 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
2946 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
2948 fence
->fence
= NULL
;
2950 fence
->fence
= device
->ws
->create_fence();
2951 if (!fence
->fence
) {
2952 vk_free2(&device
->alloc
, pAllocator
, fence
);
2953 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2958 *pFence
= radv_fence_to_handle(fence
);
2963 void radv_DestroyFence(
2966 const VkAllocationCallbacks
* pAllocator
)
2968 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2969 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2974 if (fence
->temp_syncobj
)
2975 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
2977 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
2979 device
->ws
->destroy_fence(fence
->fence
);
2980 vk_free2(&device
->alloc
, pAllocator
, fence
);
2984 static uint64_t radv_get_current_time()
2987 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2988 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2991 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2993 uint64_t current_time
= radv_get_current_time();
2995 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2997 return current_time
+ timeout
;
3001 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3003 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3004 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3005 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3011 VkResult
radv_WaitForFences(
3013 uint32_t fenceCount
,
3014 const VkFence
* pFences
,
3018 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3019 timeout
= radv_get_absolute_timeout(timeout
);
3021 if (device
->always_use_syncobj
) {
3022 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3024 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3026 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3027 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3028 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3031 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3034 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3037 if (!waitAll
&& fenceCount
> 1) {
3038 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3039 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3040 uint32_t wait_count
= 0;
3041 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3043 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3045 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3046 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3048 if (fence
->signalled
) {
3053 fences
[wait_count
++] = fence
->fence
;
3056 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3057 waitAll
, timeout
- radv_get_current_time());
3060 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3063 while(radv_get_current_time() <= timeout
) {
3064 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3065 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3072 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3073 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3074 bool expired
= false;
3076 if (fence
->temp_syncobj
) {
3077 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3082 if (fence
->syncobj
) {
3083 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3088 if (fence
->signalled
)
3091 if (!fence
->submitted
) {
3092 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3095 if (!fence
->submitted
)
3098 /* Recheck as it may have been set by submitting operations. */
3099 if (fence
->signalled
)
3103 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3107 fence
->signalled
= true;
3113 VkResult
radv_ResetFences(VkDevice _device
,
3114 uint32_t fenceCount
,
3115 const VkFence
*pFences
)
3117 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3119 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3120 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3121 fence
->submitted
= fence
->signalled
= false;
3123 /* Per spec, we first restore the permanent payload, and then reset, so
3124 * having a temp syncobj should not skip resetting the permanent syncobj. */
3125 if (fence
->temp_syncobj
) {
3126 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3127 fence
->temp_syncobj
= 0;
3130 if (fence
->syncobj
) {
3131 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3138 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3140 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3141 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3143 if (fence
->temp_syncobj
) {
3144 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3145 return success
? VK_SUCCESS
: VK_NOT_READY
;
3148 if (fence
->syncobj
) {
3149 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3150 return success
? VK_SUCCESS
: VK_NOT_READY
;
3153 if (fence
->signalled
)
3155 if (!fence
->submitted
)
3156 return VK_NOT_READY
;
3157 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3158 return VK_NOT_READY
;
3164 // Queue semaphore functions
3166 VkResult
radv_CreateSemaphore(
3168 const VkSemaphoreCreateInfo
* pCreateInfo
,
3169 const VkAllocationCallbacks
* pAllocator
,
3170 VkSemaphore
* pSemaphore
)
3172 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3173 const VkExportSemaphoreCreateInfoKHR
*export
=
3174 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3175 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3176 export
? export
->handleTypes
: 0;
3178 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3180 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3182 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3184 sem
->temp_syncobj
= 0;
3185 /* create a syncobject if we are going to export this semaphore */
3186 if (device
->always_use_syncobj
|| handleTypes
) {
3187 assert (device
->physical_device
->rad_info
.has_syncobj
);
3188 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3190 vk_free2(&device
->alloc
, pAllocator
, sem
);
3191 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3195 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3197 vk_free2(&device
->alloc
, pAllocator
, sem
);
3198 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3203 *pSemaphore
= radv_semaphore_to_handle(sem
);
3207 void radv_DestroySemaphore(
3209 VkSemaphore _semaphore
,
3210 const VkAllocationCallbacks
* pAllocator
)
3212 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3213 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3218 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3220 device
->ws
->destroy_sem(sem
->sem
);
3221 vk_free2(&device
->alloc
, pAllocator
, sem
);
3224 VkResult
radv_CreateEvent(
3226 const VkEventCreateInfo
* pCreateInfo
,
3227 const VkAllocationCallbacks
* pAllocator
,
3230 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3231 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3233 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3236 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3238 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3240 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3242 vk_free2(&device
->alloc
, pAllocator
, event
);
3243 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3246 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3248 *pEvent
= radv_event_to_handle(event
);
3253 void radv_DestroyEvent(
3256 const VkAllocationCallbacks
* pAllocator
)
3258 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3259 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3263 device
->ws
->buffer_destroy(event
->bo
);
3264 vk_free2(&device
->alloc
, pAllocator
, event
);
3267 VkResult
radv_GetEventStatus(
3271 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3273 if (*event
->map
== 1)
3274 return VK_EVENT_SET
;
3275 return VK_EVENT_RESET
;
3278 VkResult
radv_SetEvent(
3282 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3288 VkResult
radv_ResetEvent(
3292 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3298 VkResult
radv_CreateBuffer(
3300 const VkBufferCreateInfo
* pCreateInfo
,
3301 const VkAllocationCallbacks
* pAllocator
,
3304 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3305 struct radv_buffer
*buffer
;
3307 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3309 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3310 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3312 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3314 buffer
->size
= pCreateInfo
->size
;
3315 buffer
->usage
= pCreateInfo
->usage
;
3318 buffer
->flags
= pCreateInfo
->flags
;
3320 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3321 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3323 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3324 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3325 align64(buffer
->size
, 4096),
3326 4096, 0, RADEON_FLAG_VIRTUAL
);
3328 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3329 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3333 *pBuffer
= radv_buffer_to_handle(buffer
);
3338 void radv_DestroyBuffer(
3341 const VkAllocationCallbacks
* pAllocator
)
3343 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3344 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3349 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3350 device
->ws
->buffer_destroy(buffer
->bo
);
3352 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3355 static inline unsigned
3356 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3359 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3361 return image
->surface
.u
.legacy
.tiling_index
[level
];
3364 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3366 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3370 radv_initialise_color_surface(struct radv_device
*device
,
3371 struct radv_color_buffer_info
*cb
,
3372 struct radv_image_view
*iview
)
3374 const struct vk_format_description
*desc
;
3375 unsigned ntype
, format
, swap
, endian
;
3376 unsigned blend_clamp
= 0, blend_bypass
= 0;
3378 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3380 desc
= vk_format_description(iview
->vk_format
);
3382 memset(cb
, 0, sizeof(*cb
));
3384 /* Intensity is implemented as Red, so treat it that way. */
3385 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3387 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3389 cb
->cb_color_base
= va
>> 8;
3391 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3392 struct gfx9_surf_meta_flags meta
;
3393 if (iview
->image
->dcc_offset
)
3394 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3396 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3398 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3399 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3400 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3401 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3403 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3404 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3406 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3407 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3409 cb
->cb_color_base
+= level_info
->offset
>> 8;
3410 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3411 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3413 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3414 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3415 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3417 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3418 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3419 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3421 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3423 if (iview
->image
->fmask
.size
) {
3424 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3425 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3426 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3427 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3429 /* This must be set for fast clear to work without FMASK. */
3430 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3431 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3432 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3433 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3437 /* CMASK variables */
3438 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3439 va
+= iview
->image
->cmask
.offset
;
3440 cb
->cb_color_cmask
= va
>> 8;
3442 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3443 va
+= iview
->image
->dcc_offset
;
3444 cb
->cb_dcc_base
= va
>> 8;
3445 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3447 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3448 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3449 S_028C6C_SLICE_MAX(max_slice
);
3451 if (iview
->image
->info
.samples
> 1) {
3452 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3454 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3455 S_028C74_NUM_FRAGMENTS(log_samples
);
3458 if (iview
->image
->fmask
.size
) {
3459 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3460 cb
->cb_color_fmask
= va
>> 8;
3461 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3463 cb
->cb_color_fmask
= cb
->cb_color_base
;
3466 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3468 vk_format_get_first_non_void_channel(iview
->vk_format
));
3469 format
= radv_translate_colorformat(iview
->vk_format
);
3470 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3471 radv_finishme("Illegal color\n");
3472 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3473 endian
= radv_colorformat_endian_swap(format
);
3475 /* blend clamp should be set for all NORM/SRGB types */
3476 if (ntype
== V_028C70_NUMBER_UNORM
||
3477 ntype
== V_028C70_NUMBER_SNORM
||
3478 ntype
== V_028C70_NUMBER_SRGB
)
3481 /* set blend bypass according to docs if SINT/UINT or
3482 8/24 COLOR variants */
3483 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3484 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3485 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3490 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3491 (format
== V_028C70_COLOR_8
||
3492 format
== V_028C70_COLOR_8_8
||
3493 format
== V_028C70_COLOR_8_8_8_8
))
3494 ->color_is_int8
= true;
3496 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3497 S_028C70_COMP_SWAP(swap
) |
3498 S_028C70_BLEND_CLAMP(blend_clamp
) |
3499 S_028C70_BLEND_BYPASS(blend_bypass
) |
3500 S_028C70_SIMPLE_FLOAT(1) |
3501 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3502 ntype
!= V_028C70_NUMBER_SNORM
&&
3503 ntype
!= V_028C70_NUMBER_SRGB
&&
3504 format
!= V_028C70_COLOR_8_24
&&
3505 format
!= V_028C70_COLOR_24_8
) |
3506 S_028C70_NUMBER_TYPE(ntype
) |
3507 S_028C70_ENDIAN(endian
);
3508 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3509 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3510 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3511 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3512 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3516 if (iview
->image
->cmask
.size
&&
3517 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3518 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3520 if (radv_vi_dcc_enabled(iview
->image
, iview
->base_mip
))
3521 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3523 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3524 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3525 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3526 unsigned independent_64b_blocks
= 0;
3527 unsigned max_compressed_block_size
;
3529 /* amdvlk: [min-compressed-block-size] should be set to 32 for dGPU and
3530 64 for APU because all of our APUs to date use DIMMs which have
3531 a request granularity size of 64B while all other chips have a
3533 if (!device
->physical_device
->rad_info
.has_dedicated_vram
)
3534 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3536 if (iview
->image
->info
.samples
> 1) {
3537 if (iview
->image
->surface
.bpe
== 1)
3538 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3539 else if (iview
->image
->surface
.bpe
== 2)
3540 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3543 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3544 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3545 independent_64b_blocks
= 1;
3546 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3548 max_compressed_block_size
= max_uncompressed_block_size
;
3550 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3551 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3552 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3553 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3556 /* This must be set for fast clear to work without FMASK. */
3557 if (!iview
->image
->fmask
.size
&&
3558 device
->physical_device
->rad_info
.chip_class
== SI
) {
3559 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3560 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3563 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3564 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3565 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3567 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3568 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3569 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3570 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3571 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3572 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3577 radv_initialise_ds_surface(struct radv_device
*device
,
3578 struct radv_ds_buffer_info
*ds
,
3579 struct radv_image_view
*iview
)
3581 unsigned level
= iview
->base_mip
;
3582 unsigned format
, stencil_format
;
3583 uint64_t va
, s_offs
, z_offs
;
3584 bool stencil_only
= false;
3585 memset(ds
, 0, sizeof(*ds
));
3586 switch (iview
->image
->vk_format
) {
3587 case VK_FORMAT_D24_UNORM_S8_UINT
:
3588 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3589 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3590 ds
->offset_scale
= 2.0f
;
3592 case VK_FORMAT_D16_UNORM
:
3593 case VK_FORMAT_D16_UNORM_S8_UINT
:
3594 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3595 ds
->offset_scale
= 4.0f
;
3597 case VK_FORMAT_D32_SFLOAT
:
3598 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3599 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3600 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3601 ds
->offset_scale
= 1.0f
;
3603 case VK_FORMAT_S8_UINT
:
3604 stencil_only
= true;
3610 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3611 stencil_format
= iview
->image
->surface
.has_stencil
?
3612 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3614 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3615 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3616 S_028008_SLICE_MAX(max_slice
);
3618 ds
->db_htile_data_base
= 0;
3619 ds
->db_htile_surface
= 0;
3621 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3622 s_offs
= z_offs
= va
;
3624 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3625 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3626 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3628 ds
->db_z_info
= S_028038_FORMAT(format
) |
3629 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3630 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3631 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3632 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3633 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3635 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3636 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3637 ds
->db_depth_view
|= S_028008_MIPID(level
);
3639 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3640 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3642 if (radv_htile_enabled(iview
->image
, level
)) {
3643 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3645 if (iview
->image
->tc_compatible_htile
) {
3646 unsigned max_zplanes
= 4;
3648 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3649 iview
->image
->info
.samples
> 1)
3652 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
+ 1) |
3653 S_028038_ITERATE_FLUSH(1);
3654 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3657 if (!iview
->image
->surface
.has_stencil
)
3658 /* Use all of the htile_buffer for depth if there's no stencil. */
3659 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3660 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3661 iview
->image
->htile_offset
;
3662 ds
->db_htile_data_base
= va
>> 8;
3663 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3664 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3665 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3668 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3671 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3673 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3674 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3676 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!iview
->image
->tc_compatible_htile
);
3677 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3678 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3680 if (iview
->image
->info
.samples
> 1)
3681 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3683 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3684 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3685 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3686 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3687 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3688 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3689 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3690 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3693 tile_mode
= stencil_tile_mode
;
3695 ds
->db_depth_info
|=
3696 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3697 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3698 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3699 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3700 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3701 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3702 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3703 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3705 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3706 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3707 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3708 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3710 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3713 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3714 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3715 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3717 if (radv_htile_enabled(iview
->image
, level
)) {
3718 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3720 if (!iview
->image
->surface
.has_stencil
&&
3721 !iview
->image
->tc_compatible_htile
)
3722 /* Use all of the htile_buffer for depth if there's no stencil. */
3723 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3725 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3726 iview
->image
->htile_offset
;
3727 ds
->db_htile_data_base
= va
>> 8;
3728 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3730 if (iview
->image
->tc_compatible_htile
) {
3731 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3733 if (iview
->image
->info
.samples
<= 1)
3734 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
3735 else if (iview
->image
->info
.samples
<= 4)
3736 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
3738 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
3743 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3744 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3747 VkResult
radv_CreateFramebuffer(
3749 const VkFramebufferCreateInfo
* pCreateInfo
,
3750 const VkAllocationCallbacks
* pAllocator
,
3751 VkFramebuffer
* pFramebuffer
)
3753 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3754 struct radv_framebuffer
*framebuffer
;
3756 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3758 size_t size
= sizeof(*framebuffer
) +
3759 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3760 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3761 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3762 if (framebuffer
== NULL
)
3763 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3765 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3766 framebuffer
->width
= pCreateInfo
->width
;
3767 framebuffer
->height
= pCreateInfo
->height
;
3768 framebuffer
->layers
= pCreateInfo
->layers
;
3769 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3770 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3771 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3772 framebuffer
->attachments
[i
].attachment
= iview
;
3773 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3774 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3775 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3776 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3778 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3779 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3780 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
3783 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3787 void radv_DestroyFramebuffer(
3790 const VkAllocationCallbacks
* pAllocator
)
3792 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3793 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3797 vk_free2(&device
->alloc
, pAllocator
, fb
);
3800 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3802 switch (address_mode
) {
3803 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3804 return V_008F30_SQ_TEX_WRAP
;
3805 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3806 return V_008F30_SQ_TEX_MIRROR
;
3807 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3808 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3809 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3810 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3811 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3812 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3814 unreachable("illegal tex wrap mode");
3820 radv_tex_compare(VkCompareOp op
)
3823 case VK_COMPARE_OP_NEVER
:
3824 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3825 case VK_COMPARE_OP_LESS
:
3826 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3827 case VK_COMPARE_OP_EQUAL
:
3828 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3829 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3830 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3831 case VK_COMPARE_OP_GREATER
:
3832 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3833 case VK_COMPARE_OP_NOT_EQUAL
:
3834 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3835 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3836 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3837 case VK_COMPARE_OP_ALWAYS
:
3838 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3840 unreachable("illegal compare mode");
3846 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3849 case VK_FILTER_NEAREST
:
3850 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3851 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3852 case VK_FILTER_LINEAR
:
3853 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3854 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3855 case VK_FILTER_CUBIC_IMG
:
3857 fprintf(stderr
, "illegal texture filter");
3863 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3866 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3867 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3868 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3869 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3871 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3876 radv_tex_bordercolor(VkBorderColor bcolor
)
3879 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3880 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3881 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3882 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3883 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3884 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3885 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3886 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3887 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3895 radv_tex_aniso_filter(unsigned filter
)
3909 radv_init_sampler(struct radv_device
*device
,
3910 struct radv_sampler
*sampler
,
3911 const VkSamplerCreateInfo
*pCreateInfo
)
3913 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3914 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3915 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3916 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3918 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3919 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3920 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3921 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3922 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3923 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3924 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3925 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3926 S_008F30_DISABLE_CUBE_WRAP(0) |
3927 S_008F30_COMPAT_MODE(is_vi
));
3928 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3929 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3930 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3931 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3932 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3933 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3934 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3935 S_008F38_MIP_POINT_PRECLAMP(0) |
3936 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
3937 S_008F38_FILTER_PREC_FIX(1) |
3938 S_008F38_ANISO_OVERRIDE(is_vi
));
3939 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3940 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3943 VkResult
radv_CreateSampler(
3945 const VkSamplerCreateInfo
* pCreateInfo
,
3946 const VkAllocationCallbacks
* pAllocator
,
3947 VkSampler
* pSampler
)
3949 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3950 struct radv_sampler
*sampler
;
3952 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3954 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3955 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3957 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3959 radv_init_sampler(device
, sampler
, pCreateInfo
);
3960 *pSampler
= radv_sampler_to_handle(sampler
);
3965 void radv_DestroySampler(
3968 const VkAllocationCallbacks
* pAllocator
)
3970 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3971 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3975 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3978 /* vk_icd.h does not declare this function, so we declare it here to
3979 * suppress Wmissing-prototypes.
3981 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3982 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3984 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3985 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3987 /* For the full details on loader interface versioning, see
3988 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3989 * What follows is a condensed summary, to help you navigate the large and
3990 * confusing official doc.
3992 * - Loader interface v0 is incompatible with later versions. We don't
3995 * - In loader interface v1:
3996 * - The first ICD entrypoint called by the loader is
3997 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3999 * - The ICD must statically expose no other Vulkan symbol unless it is
4000 * linked with -Bsymbolic.
4001 * - Each dispatchable Vulkan handle created by the ICD must be
4002 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4003 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4004 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4005 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4006 * such loader-managed surfaces.
4008 * - Loader interface v2 differs from v1 in:
4009 * - The first ICD entrypoint called by the loader is
4010 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4011 * statically expose this entrypoint.
4013 * - Loader interface v3 differs from v2 in:
4014 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4015 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4016 * because the loader no longer does so.
4018 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4022 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4023 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4026 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4027 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4029 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4031 /* At the moment, we support only the below handle types. */
4032 assert(pGetFdInfo
->handleType
==
4033 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4034 pGetFdInfo
->handleType
==
4035 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4037 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4039 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4043 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4044 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4046 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4048 switch (handleType
) {
4049 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4050 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4054 /* The valid usage section for this function says:
4056 * "handleType must not be one of the handle types defined as
4059 * So opaque handle types fall into the default "unsupported" case.
4061 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4065 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4069 uint32_t syncobj_handle
= 0;
4070 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4072 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4075 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4077 *syncobj
= syncobj_handle
;
4083 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4087 /* If we create a syncobj we do it locally so that if we have an error, we don't
4088 * leave a syncobj in an undetermined state in the fence. */
4089 uint32_t syncobj_handle
= *syncobj
;
4090 if (!syncobj_handle
) {
4091 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4093 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4098 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4100 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4102 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4105 *syncobj
= syncobj_handle
;
4112 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4113 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4115 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4116 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4117 uint32_t *syncobj_dst
= NULL
;
4119 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4120 syncobj_dst
= &sem
->temp_syncobj
;
4122 syncobj_dst
= &sem
->syncobj
;
4125 switch(pImportSemaphoreFdInfo
->handleType
) {
4126 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4127 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4128 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4129 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4131 unreachable("Unhandled semaphore handle type");
4135 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4136 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4139 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4140 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4142 uint32_t syncobj_handle
;
4144 if (sem
->temp_syncobj
)
4145 syncobj_handle
= sem
->temp_syncobj
;
4147 syncobj_handle
= sem
->syncobj
;
4149 switch(pGetFdInfo
->handleType
) {
4150 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4151 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4153 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4154 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4156 if (sem
->temp_syncobj
) {
4157 close (sem
->temp_syncobj
);
4158 sem
->temp_syncobj
= 0;
4160 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4165 unreachable("Unhandled semaphore handle type");
4169 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4173 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4174 VkPhysicalDevice physicalDevice
,
4175 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4176 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4178 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4180 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4181 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4182 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4183 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4184 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4185 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4186 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4187 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4188 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4189 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4190 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4191 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4192 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4194 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4195 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4196 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4200 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4201 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4203 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4204 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4205 uint32_t *syncobj_dst
= NULL
;
4208 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4209 syncobj_dst
= &fence
->temp_syncobj
;
4211 syncobj_dst
= &fence
->syncobj
;
4214 switch(pImportFenceFdInfo
->handleType
) {
4215 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4216 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4217 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4218 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4220 unreachable("Unhandled fence handle type");
4224 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4225 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4228 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4229 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4231 uint32_t syncobj_handle
;
4233 if (fence
->temp_syncobj
)
4234 syncobj_handle
= fence
->temp_syncobj
;
4236 syncobj_handle
= fence
->syncobj
;
4238 switch(pGetFdInfo
->handleType
) {
4239 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4240 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4242 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4243 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4245 if (fence
->temp_syncobj
) {
4246 close (fence
->temp_syncobj
);
4247 fence
->temp_syncobj
= 0;
4249 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4254 unreachable("Unhandled fence handle type");
4258 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4262 void radv_GetPhysicalDeviceExternalFenceProperties(
4263 VkPhysicalDevice physicalDevice
,
4264 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4265 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4267 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4269 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4270 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4271 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4272 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4273 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4274 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4275 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4277 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4278 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4279 pExternalFenceProperties
->externalFenceFeatures
= 0;
4284 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4285 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4286 const VkAllocationCallbacks
* pAllocator
,
4287 VkDebugReportCallbackEXT
* pCallback
)
4289 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4290 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4291 pCreateInfo
, pAllocator
, &instance
->alloc
,
4296 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4297 VkDebugReportCallbackEXT _callback
,
4298 const VkAllocationCallbacks
* pAllocator
)
4300 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4301 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4302 _callback
, pAllocator
, &instance
->alloc
);
4306 radv_DebugReportMessageEXT(VkInstance _instance
,
4307 VkDebugReportFlagsEXT flags
,
4308 VkDebugReportObjectTypeEXT objectType
,
4311 int32_t messageCode
,
4312 const char* pLayerPrefix
,
4313 const char* pMessage
)
4315 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4316 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4317 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4321 radv_GetDeviceGroupPeerMemoryFeatures(
4324 uint32_t localDeviceIndex
,
4325 uint32_t remoteDeviceIndex
,
4326 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4328 assert(localDeviceIndex
== remoteDeviceIndex
);
4330 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4331 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4332 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4333 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;