2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
53 uint32_t mesa_timestamp
, llvm_timestamp
;
55 memset(uuid
, 0, VK_UUID_SIZE
);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
60 memcpy(uuid
, &mesa_timestamp
, 4);
61 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
62 memcpy((char*)uuid
+ 8, &f
, 2);
63 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
68 radv_get_driver_uuid(void *uuid
)
70 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
74 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
76 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
80 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
82 const char *chip_string
;
83 char llvm_string
[32] = {};
86 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
87 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
88 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
89 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
90 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
91 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
92 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
93 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
94 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
95 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
96 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
97 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
98 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
99 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
100 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
101 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
102 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
103 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
104 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
105 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
106 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
107 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
108 default: chip_string
= "AMD RADV unknown"; break;
111 snprintf(llvm_string
, sizeof(llvm_string
),
112 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
113 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
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
,
144 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
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 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
163 .heapIndex
= gart_index
,
166 if (visible_vram_index
>= 0) {
167 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
168 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
169 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
170 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
171 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
172 .heapIndex
= visible_vram_index
,
175 if (gart_index
>= 0) {
176 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
177 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
178 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
179 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
180 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
181 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
182 .heapIndex
= gart_index
,
185 device
->memory_properties
.memoryTypeCount
= type_count
;
189 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
191 const char *family
= getenv("RADV_FORCE_FAMILY");
197 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
198 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
199 /* Override family and chip_class. */
200 device
->rad_info
.family
= i
;
202 if (i
>= CHIP_VEGA10
)
203 device
->rad_info
.chip_class
= GFX9
;
204 else if (i
>= CHIP_TONGA
)
205 device
->rad_info
.chip_class
= VI
;
206 else if (i
>= CHIP_BONAIRE
)
207 device
->rad_info
.chip_class
= CIK
;
209 device
->rad_info
.chip_class
= SI
;
215 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
220 radv_physical_device_init(struct radv_physical_device
*device
,
221 struct radv_instance
*instance
,
222 drmDevicePtr drm_device
)
224 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
226 drmVersionPtr version
;
229 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
231 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
232 radv_logi("Could not open device '%s'", path
);
234 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
237 version
= drmGetVersion(fd
);
241 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
242 radv_logi("Could not get the kernel driver version for device '%s'", path
);
244 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
245 "failed to get version %s: %m", path
);
248 if (strcmp(version
->name
, "amdgpu")) {
249 drmFreeVersion(version
);
252 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
253 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
255 return VK_ERROR_INCOMPATIBLE_DRIVER
;
257 drmFreeVersion(version
);
259 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
260 radv_logi("Found compatible device '%s'.", path
);
262 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
263 device
->instance
= instance
;
264 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
265 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
267 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
268 instance
->perftest_flags
);
270 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
274 device
->local_fd
= fd
;
275 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
277 radv_handle_env_var_force_family(device
);
279 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
281 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
282 device
->ws
->destroy(device
->ws
);
283 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
284 "cannot generate UUID");
288 /* These flags affect shader compilation. */
289 uint64_t shader_env_flags
=
290 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
291 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
293 /* The gpu id is already embedded in the uuid so we just pass "radv"
294 * when creating the cache.
296 char buf
[VK_UUID_SIZE
* 2 + 1];
297 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
298 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
300 if (device
->rad_info
.chip_class
< VI
||
301 device
->rad_info
.chip_class
> GFX9
)
302 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
304 radv_get_driver_uuid(&device
->device_uuid
);
305 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
307 if (device
->rad_info
.family
== CHIP_STONEY
||
308 device
->rad_info
.chip_class
>= GFX9
) {
309 device
->has_rbplus
= true;
310 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
311 device
->rad_info
.family
== CHIP_VEGA12
||
312 device
->rad_info
.family
== CHIP_RAVEN
;
315 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
318 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
320 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
322 /* Vega10/Raven need a special workaround for a hardware bug. */
323 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
324 device
->rad_info
.family
== CHIP_RAVEN
;
326 /* Out-of-order primitive rasterization. */
327 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
328 device
->rad_info
.max_se
>= 2;
329 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
330 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
332 device
->dcc_msaa_allowed
= device
->rad_info
.chip_class
== VI
&&
333 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
335 radv_physical_device_init_mem_types(device
);
336 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
338 result
= radv_init_wsi(device
);
339 if (result
!= VK_SUCCESS
) {
340 device
->ws
->destroy(device
->ws
);
341 vk_error(instance
, result
);
345 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
346 ac_print_gpu_info(&device
->rad_info
);
356 radv_physical_device_finish(struct radv_physical_device
*device
)
358 radv_finish_wsi(device
);
359 device
->ws
->destroy(device
->ws
);
360 disk_cache_destroy(device
->disk_cache
);
361 close(device
->local_fd
);
365 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
366 VkSystemAllocationScope allocationScope
)
372 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
373 size_t align
, VkSystemAllocationScope allocationScope
)
375 return realloc(pOriginal
, size
);
379 default_free_func(void *pUserData
, void *pMemory
)
384 static const VkAllocationCallbacks default_alloc
= {
386 .pfnAllocation
= default_alloc_func
,
387 .pfnReallocation
= default_realloc_func
,
388 .pfnFree
= default_free_func
,
391 static const struct debug_control radv_debug_options
[] = {
392 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
393 {"nodcc", RADV_DEBUG_NO_DCC
},
394 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
395 {"nocache", RADV_DEBUG_NO_CACHE
},
396 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
397 {"nohiz", RADV_DEBUG_NO_HIZ
},
398 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
399 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
400 {"allbos", RADV_DEBUG_ALL_BOS
},
401 {"noibs", RADV_DEBUG_NO_IBS
},
402 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
403 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
404 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
405 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
406 {"nosisched", RADV_DEBUG_NO_SISCHED
},
407 {"preoptir", RADV_DEBUG_PREOPTIR
},
408 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
409 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
410 {"info", RADV_DEBUG_INFO
},
411 {"errors", RADV_DEBUG_ERRORS
},
412 {"startup", RADV_DEBUG_STARTUP
},
417 radv_get_debug_option_name(int id
)
419 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
420 return radv_debug_options
[id
].string
;
423 static const struct debug_control radv_perftest_options
[] = {
424 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
425 {"sisched", RADV_PERFTEST_SISCHED
},
426 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
427 {"binning", RADV_PERFTEST_BINNING
},
428 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
433 radv_get_perftest_option_name(int id
)
435 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
436 return radv_perftest_options
[id
].string
;
440 radv_handle_per_app_options(struct radv_instance
*instance
,
441 const VkApplicationInfo
*info
)
443 const char *name
= info
? info
->pApplicationName
: NULL
;
448 if (!strcmp(name
, "Talos - Linux - 32bit") ||
449 !strcmp(name
, "Talos - Linux - 64bit")) {
450 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
451 /* Force enable LLVM sisched for Talos because it looks
452 * safe and it gives few more FPS.
454 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
459 static int radv_get_instance_extension_index(const char *name
)
461 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
462 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
469 VkResult
radv_CreateInstance(
470 const VkInstanceCreateInfo
* pCreateInfo
,
471 const VkAllocationCallbacks
* pAllocator
,
472 VkInstance
* pInstance
)
474 struct radv_instance
*instance
;
477 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
479 uint32_t client_version
;
480 if (pCreateInfo
->pApplicationInfo
&&
481 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
482 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
484 radv_EnumerateInstanceVersion(&client_version
);
487 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
488 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
490 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
492 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
495 instance
->alloc
= *pAllocator
;
497 instance
->alloc
= default_alloc
;
499 instance
->apiVersion
= client_version
;
500 instance
->physicalDeviceCount
= -1;
502 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
505 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
506 radv_perftest_options
);
509 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
510 radv_logi("Created an instance");
512 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
513 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
514 int index
= radv_get_instance_extension_index(ext_name
);
516 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
517 vk_free2(&default_alloc
, pAllocator
, instance
);
518 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
521 instance
->enabled_extensions
.extensions
[index
] = true;
524 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
525 if (result
!= VK_SUCCESS
) {
526 vk_free2(&default_alloc
, pAllocator
, instance
);
527 return vk_error(instance
, result
);
532 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
534 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
536 *pInstance
= radv_instance_to_handle(instance
);
541 void radv_DestroyInstance(
542 VkInstance _instance
,
543 const VkAllocationCallbacks
* pAllocator
)
545 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
550 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
551 radv_physical_device_finish(instance
->physicalDevices
+ i
);
554 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
558 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
560 vk_free(&instance
->alloc
, instance
);
564 radv_enumerate_devices(struct radv_instance
*instance
)
566 /* TODO: Check for more devices ? */
567 drmDevicePtr devices
[8];
568 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
571 instance
->physicalDeviceCount
= 0;
573 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
575 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
576 radv_logi("Found %d drm nodes", max_devices
);
579 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
581 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
582 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
583 devices
[i
]->bustype
== DRM_BUS_PCI
&&
584 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
586 result
= radv_physical_device_init(instance
->physicalDevices
+
587 instance
->physicalDeviceCount
,
590 if (result
== VK_SUCCESS
)
591 ++instance
->physicalDeviceCount
;
592 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
596 drmFreeDevices(devices
, max_devices
);
601 VkResult
radv_EnumeratePhysicalDevices(
602 VkInstance _instance
,
603 uint32_t* pPhysicalDeviceCount
,
604 VkPhysicalDevice
* pPhysicalDevices
)
606 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
609 if (instance
->physicalDeviceCount
< 0) {
610 result
= radv_enumerate_devices(instance
);
611 if (result
!= VK_SUCCESS
&&
612 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
616 if (!pPhysicalDevices
) {
617 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
619 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
620 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
621 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
624 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
628 VkResult
radv_EnumeratePhysicalDeviceGroups(
629 VkInstance _instance
,
630 uint32_t* pPhysicalDeviceGroupCount
,
631 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
633 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
636 if (instance
->physicalDeviceCount
< 0) {
637 result
= radv_enumerate_devices(instance
);
638 if (result
!= VK_SUCCESS
&&
639 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
643 if (!pPhysicalDeviceGroupProperties
) {
644 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
646 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
647 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
648 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
649 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
650 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
653 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
657 void radv_GetPhysicalDeviceFeatures(
658 VkPhysicalDevice physicalDevice
,
659 VkPhysicalDeviceFeatures
* pFeatures
)
661 memset(pFeatures
, 0, sizeof(*pFeatures
));
663 *pFeatures
= (VkPhysicalDeviceFeatures
) {
664 .robustBufferAccess
= true,
665 .fullDrawIndexUint32
= true,
666 .imageCubeArray
= true,
667 .independentBlend
= true,
668 .geometryShader
= true,
669 .tessellationShader
= true,
670 .sampleRateShading
= true,
671 .dualSrcBlend
= true,
673 .multiDrawIndirect
= true,
674 .drawIndirectFirstInstance
= true,
676 .depthBiasClamp
= true,
677 .fillModeNonSolid
= true,
682 .multiViewport
= true,
683 .samplerAnisotropy
= true,
684 .textureCompressionETC2
= false,
685 .textureCompressionASTC_LDR
= false,
686 .textureCompressionBC
= true,
687 .occlusionQueryPrecise
= true,
688 .pipelineStatisticsQuery
= true,
689 .vertexPipelineStoresAndAtomics
= true,
690 .fragmentStoresAndAtomics
= true,
691 .shaderTessellationAndGeometryPointSize
= true,
692 .shaderImageGatherExtended
= true,
693 .shaderStorageImageExtendedFormats
= true,
694 .shaderStorageImageMultisample
= false,
695 .shaderUniformBufferArrayDynamicIndexing
= true,
696 .shaderSampledImageArrayDynamicIndexing
= true,
697 .shaderStorageBufferArrayDynamicIndexing
= true,
698 .shaderStorageImageArrayDynamicIndexing
= true,
699 .shaderStorageImageReadWithoutFormat
= true,
700 .shaderStorageImageWriteWithoutFormat
= true,
701 .shaderClipDistance
= true,
702 .shaderCullDistance
= true,
703 .shaderFloat64
= true,
705 .shaderInt16
= false,
706 .sparseBinding
= true,
707 .variableMultisampleRate
= true,
708 .inheritedQueries
= true,
712 void radv_GetPhysicalDeviceFeatures2(
713 VkPhysicalDevice physicalDevice
,
714 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
716 vk_foreach_struct(ext
, pFeatures
->pNext
) {
717 switch (ext
->sType
) {
718 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
719 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
720 features
->variablePointersStorageBuffer
= true;
721 features
->variablePointers
= false;
724 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
725 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
726 features
->multiview
= true;
727 features
->multiviewGeometryShader
= true;
728 features
->multiviewTessellationShader
= true;
731 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
732 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
733 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
734 features
->shaderDrawParameters
= true;
737 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
738 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
739 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
740 features
->protectedMemory
= false;
743 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
744 VkPhysicalDevice16BitStorageFeatures
*features
=
745 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
746 features
->storageBuffer16BitAccess
= false;
747 features
->uniformAndStorageBuffer16BitAccess
= false;
748 features
->storagePushConstant16
= false;
749 features
->storageInputOutput16
= false;
752 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
753 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
754 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
755 features
->samplerYcbcrConversion
= false;
758 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
759 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
760 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
761 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
762 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
763 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
764 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
765 features
->shaderSampledImageArrayNonUniformIndexing
= false;
766 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
767 features
->shaderStorageImageArrayNonUniformIndexing
= false;
768 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
769 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
770 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
771 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
772 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
773 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
774 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
775 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
776 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
777 features
->descriptorBindingUpdateUnusedWhilePending
= true;
778 features
->descriptorBindingPartiallyBound
= true;
779 features
->descriptorBindingVariableDescriptorCount
= true;
780 features
->runtimeDescriptorArray
= true;
787 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
790 void radv_GetPhysicalDeviceProperties(
791 VkPhysicalDevice physicalDevice
,
792 VkPhysicalDeviceProperties
* pProperties
)
794 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
795 VkSampleCountFlags sample_counts
= 0xf;
797 /* make sure that the entire descriptor set is addressable with a signed
798 * 32-bit int. So the sum of all limits scaled by descriptor size has to
799 * be at most 2 GiB. the combined image & samples object count as one of
800 * both. This limit is for the pipeline layout, not for the set layout, but
801 * there is no set limit, so we just set a pipeline limit. I don't think
802 * any app is going to hit this soon. */
803 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
804 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
805 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
806 32 /* sampler, largest when combined with image */ +
807 64 /* sampled image */ +
808 64 /* storage image */);
810 VkPhysicalDeviceLimits limits
= {
811 .maxImageDimension1D
= (1 << 14),
812 .maxImageDimension2D
= (1 << 14),
813 .maxImageDimension3D
= (1 << 11),
814 .maxImageDimensionCube
= (1 << 14),
815 .maxImageArrayLayers
= (1 << 11),
816 .maxTexelBufferElements
= 128 * 1024 * 1024,
817 .maxUniformBufferRange
= UINT32_MAX
,
818 .maxStorageBufferRange
= UINT32_MAX
,
819 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
820 .maxMemoryAllocationCount
= UINT32_MAX
,
821 .maxSamplerAllocationCount
= 64 * 1024,
822 .bufferImageGranularity
= 64, /* A cache line */
823 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
824 .maxBoundDescriptorSets
= MAX_SETS
,
825 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
826 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
827 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
828 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
829 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
830 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
831 .maxPerStageResources
= max_descriptor_set_size
,
832 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
833 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
834 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
835 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
836 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
837 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
838 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
839 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
840 .maxVertexInputAttributes
= 32,
841 .maxVertexInputBindings
= 32,
842 .maxVertexInputAttributeOffset
= 2047,
843 .maxVertexInputBindingStride
= 2048,
844 .maxVertexOutputComponents
= 128,
845 .maxTessellationGenerationLevel
= 64,
846 .maxTessellationPatchSize
= 32,
847 .maxTessellationControlPerVertexInputComponents
= 128,
848 .maxTessellationControlPerVertexOutputComponents
= 128,
849 .maxTessellationControlPerPatchOutputComponents
= 120,
850 .maxTessellationControlTotalOutputComponents
= 4096,
851 .maxTessellationEvaluationInputComponents
= 128,
852 .maxTessellationEvaluationOutputComponents
= 128,
853 .maxGeometryShaderInvocations
= 127,
854 .maxGeometryInputComponents
= 64,
855 .maxGeometryOutputComponents
= 128,
856 .maxGeometryOutputVertices
= 256,
857 .maxGeometryTotalOutputComponents
= 1024,
858 .maxFragmentInputComponents
= 128,
859 .maxFragmentOutputAttachments
= 8,
860 .maxFragmentDualSrcAttachments
= 1,
861 .maxFragmentCombinedOutputResources
= 8,
862 .maxComputeSharedMemorySize
= 32768,
863 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
864 .maxComputeWorkGroupInvocations
= 2048,
865 .maxComputeWorkGroupSize
= {
870 .subPixelPrecisionBits
= 4 /* FIXME */,
871 .subTexelPrecisionBits
= 4 /* FIXME */,
872 .mipmapPrecisionBits
= 4 /* FIXME */,
873 .maxDrawIndexedIndexValue
= UINT32_MAX
,
874 .maxDrawIndirectCount
= UINT32_MAX
,
875 .maxSamplerLodBias
= 16,
876 .maxSamplerAnisotropy
= 16,
877 .maxViewports
= MAX_VIEWPORTS
,
878 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
879 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
880 .viewportSubPixelBits
= 8,
881 .minMemoryMapAlignment
= 4096, /* A page */
882 .minTexelBufferOffsetAlignment
= 1,
883 .minUniformBufferOffsetAlignment
= 4,
884 .minStorageBufferOffsetAlignment
= 4,
885 .minTexelOffset
= -32,
886 .maxTexelOffset
= 31,
887 .minTexelGatherOffset
= -32,
888 .maxTexelGatherOffset
= 31,
889 .minInterpolationOffset
= -2,
890 .maxInterpolationOffset
= 2,
891 .subPixelInterpolationOffsetBits
= 8,
892 .maxFramebufferWidth
= (1 << 14),
893 .maxFramebufferHeight
= (1 << 14),
894 .maxFramebufferLayers
= (1 << 10),
895 .framebufferColorSampleCounts
= sample_counts
,
896 .framebufferDepthSampleCounts
= sample_counts
,
897 .framebufferStencilSampleCounts
= sample_counts
,
898 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
899 .maxColorAttachments
= MAX_RTS
,
900 .sampledImageColorSampleCounts
= sample_counts
,
901 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
902 .sampledImageDepthSampleCounts
= sample_counts
,
903 .sampledImageStencilSampleCounts
= sample_counts
,
904 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
905 .maxSampleMaskWords
= 1,
906 .timestampComputeAndGraphics
= true,
907 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
908 .maxClipDistances
= 8,
909 .maxCullDistances
= 8,
910 .maxCombinedClipAndCullDistances
= 8,
911 .discreteQueuePriorities
= 1,
912 .pointSizeRange
= { 0.125, 255.875 },
913 .lineWidthRange
= { 0.0, 7.9921875 },
914 .pointSizeGranularity
= (1.0 / 8.0),
915 .lineWidthGranularity
= (1.0 / 128.0),
916 .strictLines
= false, /* FINISHME */
917 .standardSampleLocations
= true,
918 .optimalBufferCopyOffsetAlignment
= 128,
919 .optimalBufferCopyRowPitchAlignment
= 128,
920 .nonCoherentAtomSize
= 64,
923 *pProperties
= (VkPhysicalDeviceProperties
) {
924 .apiVersion
= radv_physical_device_api_version(pdevice
),
925 .driverVersion
= vk_get_driver_version(),
926 .vendorID
= ATI_VENDOR_ID
,
927 .deviceID
= pdevice
->rad_info
.pci_id
,
928 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
930 .sparseProperties
= {0},
933 strcpy(pProperties
->deviceName
, pdevice
->name
);
934 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
937 void radv_GetPhysicalDeviceProperties2(
938 VkPhysicalDevice physicalDevice
,
939 VkPhysicalDeviceProperties2KHR
*pProperties
)
941 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
942 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
944 vk_foreach_struct(ext
, pProperties
->pNext
) {
945 switch (ext
->sType
) {
946 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
947 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
948 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
949 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
952 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
953 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
954 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
955 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
956 properties
->deviceLUIDValid
= false;
959 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
960 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
961 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
962 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
965 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
966 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
967 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
968 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
972 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
973 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
974 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
977 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
978 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
979 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
980 properties
->minImportedHostPointerAlignment
= 4096;
983 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
984 VkPhysicalDeviceSubgroupProperties
*properties
=
985 (VkPhysicalDeviceSubgroupProperties
*)ext
;
986 properties
->subgroupSize
= 64;
987 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
988 properties
->supportedOperations
=
989 VK_SUBGROUP_FEATURE_BASIC_BIT
|
990 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
991 VK_SUBGROUP_FEATURE_QUAD_BIT
|
992 VK_SUBGROUP_FEATURE_VOTE_BIT
;
993 if (pdevice
->rad_info
.chip_class
>= VI
) {
994 properties
->supportedOperations
|=
995 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
996 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
998 properties
->quadOperationsInAllStages
= true;
1001 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1002 VkPhysicalDeviceMaintenance3Properties
*properties
=
1003 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1004 /* Make sure everything is addressable by a signed 32-bit int, and
1005 * our largest descriptors are 96 bytes. */
1006 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1007 /* Our buffer size fields allow only this much */
1008 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1011 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1012 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1013 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1014 /* GFX6-8 only support single channel min/max filter. */
1015 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1016 properties
->filterMinmaxSingleComponentFormats
= true;
1019 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1020 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1021 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1023 /* Shader engines. */
1024 properties
->shaderEngineCount
=
1025 pdevice
->rad_info
.max_se
;
1026 properties
->shaderArraysPerEngineCount
=
1027 pdevice
->rad_info
.max_sh_per_se
;
1028 properties
->computeUnitsPerShaderArray
=
1029 pdevice
->rad_info
.num_good_compute_units
/
1030 (pdevice
->rad_info
.max_se
*
1031 pdevice
->rad_info
.max_sh_per_se
);
1032 properties
->simdPerComputeUnit
= 4;
1033 properties
->wavefrontsPerSimd
=
1034 pdevice
->rad_info
.family
== CHIP_TONGA
||
1035 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1036 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1037 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1038 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1039 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1040 properties
->wavefrontSize
= 64;
1043 properties
->sgprsPerSimd
=
1044 radv_get_num_physical_sgprs(pdevice
);
1045 properties
->minSgprAllocation
=
1046 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1047 properties
->maxSgprAllocation
=
1048 pdevice
->rad_info
.family
== CHIP_TONGA
||
1049 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1050 properties
->sgprAllocationGranularity
=
1051 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1054 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1055 properties
->minVgprAllocation
= 4;
1056 properties
->maxVgprAllocation
= 256;
1057 properties
->vgprAllocationGranularity
= 4;
1060 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1061 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1062 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1063 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1066 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1067 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1068 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1069 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1070 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1071 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1072 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1073 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1074 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1075 properties
->robustBufferAccessUpdateAfterBind
= false;
1076 properties
->quadDivergentImplicitLod
= false;
1078 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1079 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1080 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1081 32 /* sampler, largest when combined with image */ +
1082 64 /* sampled image */ +
1083 64 /* storage image */);
1084 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1085 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1086 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1087 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1088 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1089 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1090 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1091 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1092 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1093 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1094 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1095 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1096 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1097 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1098 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1107 static void radv_get_physical_device_queue_family_properties(
1108 struct radv_physical_device
* pdevice
,
1110 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1112 int num_queue_families
= 1;
1114 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1115 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1116 num_queue_families
++;
1118 if (pQueueFamilyProperties
== NULL
) {
1119 *pCount
= num_queue_families
;
1128 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1129 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1130 VK_QUEUE_COMPUTE_BIT
|
1131 VK_QUEUE_TRANSFER_BIT
|
1132 VK_QUEUE_SPARSE_BINDING_BIT
,
1134 .timestampValidBits
= 64,
1135 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1140 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1141 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1142 if (*pCount
> idx
) {
1143 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1144 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1145 VK_QUEUE_TRANSFER_BIT
|
1146 VK_QUEUE_SPARSE_BINDING_BIT
,
1147 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1148 .timestampValidBits
= 64,
1149 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1157 void radv_GetPhysicalDeviceQueueFamilyProperties(
1158 VkPhysicalDevice physicalDevice
,
1160 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1162 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1163 if (!pQueueFamilyProperties
) {
1164 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1167 VkQueueFamilyProperties
*properties
[] = {
1168 pQueueFamilyProperties
+ 0,
1169 pQueueFamilyProperties
+ 1,
1170 pQueueFamilyProperties
+ 2,
1172 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1173 assert(*pCount
<= 3);
1176 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1177 VkPhysicalDevice physicalDevice
,
1179 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1181 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1182 if (!pQueueFamilyProperties
) {
1183 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1186 VkQueueFamilyProperties
*properties
[] = {
1187 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1188 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1189 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1191 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1192 assert(*pCount
<= 3);
1195 void radv_GetPhysicalDeviceMemoryProperties(
1196 VkPhysicalDevice physicalDevice
,
1197 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1199 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1201 *pMemoryProperties
= physical_device
->memory_properties
;
1204 void radv_GetPhysicalDeviceMemoryProperties2(
1205 VkPhysicalDevice physicalDevice
,
1206 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1208 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1209 &pMemoryProperties
->memoryProperties
);
1212 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1214 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1215 const void *pHostPointer
,
1216 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1218 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1222 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1223 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1224 uint32_t memoryTypeBits
= 0;
1225 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1226 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1227 memoryTypeBits
= (1 << i
);
1231 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1235 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1239 static enum radeon_ctx_priority
1240 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1242 /* Default to MEDIUM when a specific global priority isn't requested */
1244 return RADEON_CTX_PRIORITY_MEDIUM
;
1246 switch(pObj
->globalPriority
) {
1247 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1248 return RADEON_CTX_PRIORITY_REALTIME
;
1249 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1250 return RADEON_CTX_PRIORITY_HIGH
;
1251 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1252 return RADEON_CTX_PRIORITY_MEDIUM
;
1253 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1254 return RADEON_CTX_PRIORITY_LOW
;
1256 unreachable("Illegal global priority value");
1257 return RADEON_CTX_PRIORITY_INVALID
;
1262 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1263 uint32_t queue_family_index
, int idx
,
1264 VkDeviceQueueCreateFlags flags
,
1265 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1267 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1268 queue
->device
= device
;
1269 queue
->queue_family_index
= queue_family_index
;
1270 queue
->queue_idx
= idx
;
1271 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1272 queue
->flags
= flags
;
1274 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1276 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1282 radv_queue_finish(struct radv_queue
*queue
)
1285 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1287 if (queue
->initial_full_flush_preamble_cs
)
1288 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1289 if (queue
->initial_preamble_cs
)
1290 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1291 if (queue
->continue_preamble_cs
)
1292 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1293 if (queue
->descriptor_bo
)
1294 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1295 if (queue
->scratch_bo
)
1296 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1297 if (queue
->esgs_ring_bo
)
1298 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1299 if (queue
->gsvs_ring_bo
)
1300 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1301 if (queue
->tess_rings_bo
)
1302 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1303 if (queue
->compute_scratch_bo
)
1304 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1308 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1310 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1311 bo_list
->list
.count
= bo_list
->capacity
= 0;
1312 bo_list
->list
.bos
= NULL
;
1316 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1318 free(bo_list
->list
.bos
);
1319 pthread_mutex_destroy(&bo_list
->mutex
);
1322 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1323 struct radeon_winsys_bo
*bo
)
1325 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1327 if (unlikely(!device
->use_global_bo_list
))
1330 pthread_mutex_lock(&bo_list
->mutex
);
1331 if (bo_list
->list
.count
== bo_list
->capacity
) {
1332 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1333 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1336 pthread_mutex_unlock(&bo_list
->mutex
);
1337 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1340 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1341 bo_list
->capacity
= capacity
;
1344 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1345 pthread_mutex_unlock(&bo_list
->mutex
);
1349 static void radv_bo_list_remove(struct radv_device
*device
,
1350 struct radeon_winsys_bo
*bo
)
1352 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1354 if (unlikely(!device
->use_global_bo_list
))
1357 pthread_mutex_lock(&bo_list
->mutex
);
1358 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1359 if (bo_list
->list
.bos
[i
] == bo
) {
1360 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1361 --bo_list
->list
.count
;
1365 pthread_mutex_unlock(&bo_list
->mutex
);
1369 radv_device_init_gs_info(struct radv_device
*device
)
1371 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1372 device
->physical_device
->rad_info
.family
);
1375 static int radv_get_device_extension_index(const char *name
)
1377 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1378 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1384 VkResult
radv_CreateDevice(
1385 VkPhysicalDevice physicalDevice
,
1386 const VkDeviceCreateInfo
* pCreateInfo
,
1387 const VkAllocationCallbacks
* pAllocator
,
1390 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1392 struct radv_device
*device
;
1394 bool keep_shader_info
= false;
1396 /* Check enabled features */
1397 if (pCreateInfo
->pEnabledFeatures
) {
1398 VkPhysicalDeviceFeatures supported_features
;
1399 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1400 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1401 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1402 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1403 for (uint32_t i
= 0; i
< num_features
; i
++) {
1404 if (enabled_feature
[i
] && !supported_feature
[i
])
1405 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1409 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1411 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1413 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1415 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1416 device
->instance
= physical_device
->instance
;
1417 device
->physical_device
= physical_device
;
1419 device
->ws
= physical_device
->ws
;
1421 device
->alloc
= *pAllocator
;
1423 device
->alloc
= physical_device
->instance
->alloc
;
1425 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1426 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1427 int index
= radv_get_device_extension_index(ext_name
);
1428 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1429 vk_free(&device
->alloc
, device
);
1430 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1433 device
->enabled_extensions
.extensions
[index
] = true;
1436 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1438 /* With update after bind we can't attach bo's to the command buffer
1439 * from the descriptor set anymore, so we have to use a global BO list.
1441 device
->use_global_bo_list
=
1442 device
->enabled_extensions
.EXT_descriptor_indexing
;
1444 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1445 list_inithead(&device
->shader_slabs
);
1447 radv_bo_list_init(&device
->bo_list
);
1449 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1450 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1451 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1452 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1453 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1455 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1457 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1458 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1459 if (!device
->queues
[qfi
]) {
1460 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1464 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1466 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1468 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1469 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1470 qfi
, q
, queue_create
->flags
,
1472 if (result
!= VK_SUCCESS
)
1477 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1478 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1480 /* Disabled and not implemented for now. */
1481 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1484 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1487 /* The maximum number of scratch waves. Scratch space isn't divided
1488 * evenly between CUs. The number is only a function of the number of CUs.
1489 * We can decrease the constant to decrease the scratch buffer size.
1491 * sctx->scratch_waves must be >= the maximum possible size of
1492 * 1 threadgroup, so that the hw doesn't hang from being unable
1495 * The recommended value is 4 per CU at most. Higher numbers don't
1496 * bring much benefit, but they still occupy chip resources (think
1497 * async compute). I've seen ~2% performance difference between 4 and 32.
1499 uint32_t max_threads_per_block
= 2048;
1500 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1501 max_threads_per_block
/ 64);
1503 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1505 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1506 /* If the KMD allows it (there is a KMD hw register for it),
1507 * allow launching waves out-of-order.
1509 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1512 radv_device_init_gs_info(device
);
1514 device
->tess_offchip_block_dw_size
=
1515 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1516 device
->has_distributed_tess
=
1517 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1518 device
->physical_device
->rad_info
.max_se
>= 2;
1520 if (getenv("RADV_TRACE_FILE")) {
1521 const char *filename
= getenv("RADV_TRACE_FILE");
1523 keep_shader_info
= true;
1525 if (!radv_init_trace(device
))
1528 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1529 radv_dump_enabled_options(device
, stderr
);
1532 device
->keep_shader_info
= keep_shader_info
;
1534 result
= radv_device_init_meta(device
);
1535 if (result
!= VK_SUCCESS
)
1538 radv_device_init_msaa(device
);
1540 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1541 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1543 case RADV_QUEUE_GENERAL
:
1544 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1545 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1546 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1548 case RADV_QUEUE_COMPUTE
:
1549 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1550 radeon_emit(device
->empty_cs
[family
], 0);
1553 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1556 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1557 cik_create_gfx_config(device
);
1559 VkPipelineCacheCreateInfo ci
;
1560 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1563 ci
.pInitialData
= NULL
;
1564 ci
.initialDataSize
= 0;
1566 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1568 if (result
!= VK_SUCCESS
)
1571 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1573 *pDevice
= radv_device_to_handle(device
);
1577 radv_device_finish_meta(device
);
1579 radv_bo_list_finish(&device
->bo_list
);
1581 if (device
->trace_bo
)
1582 device
->ws
->buffer_destroy(device
->trace_bo
);
1584 if (device
->gfx_init
)
1585 device
->ws
->buffer_destroy(device
->gfx_init
);
1587 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1588 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1589 radv_queue_finish(&device
->queues
[i
][q
]);
1590 if (device
->queue_count
[i
])
1591 vk_free(&device
->alloc
, device
->queues
[i
]);
1594 vk_free(&device
->alloc
, device
);
1598 void radv_DestroyDevice(
1600 const VkAllocationCallbacks
* pAllocator
)
1602 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1607 if (device
->trace_bo
)
1608 device
->ws
->buffer_destroy(device
->trace_bo
);
1610 if (device
->gfx_init
)
1611 device
->ws
->buffer_destroy(device
->gfx_init
);
1613 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1614 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1615 radv_queue_finish(&device
->queues
[i
][q
]);
1616 if (device
->queue_count
[i
])
1617 vk_free(&device
->alloc
, device
->queues
[i
]);
1618 if (device
->empty_cs
[i
])
1619 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1621 radv_device_finish_meta(device
);
1623 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1624 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1626 radv_destroy_shader_slabs(device
);
1628 radv_bo_list_finish(&device
->bo_list
);
1629 vk_free(&device
->alloc
, device
);
1632 VkResult
radv_EnumerateInstanceLayerProperties(
1633 uint32_t* pPropertyCount
,
1634 VkLayerProperties
* pProperties
)
1636 if (pProperties
== NULL
) {
1637 *pPropertyCount
= 0;
1641 /* None supported at this time */
1642 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1645 VkResult
radv_EnumerateDeviceLayerProperties(
1646 VkPhysicalDevice physicalDevice
,
1647 uint32_t* pPropertyCount
,
1648 VkLayerProperties
* pProperties
)
1650 if (pProperties
== NULL
) {
1651 *pPropertyCount
= 0;
1655 /* None supported at this time */
1656 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1659 void radv_GetDeviceQueue2(
1661 const VkDeviceQueueInfo2
* pQueueInfo
,
1664 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1665 struct radv_queue
*queue
;
1667 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1668 if (pQueueInfo
->flags
!= queue
->flags
) {
1669 /* From the Vulkan 1.1.70 spec:
1671 * "The queue returned by vkGetDeviceQueue2 must have the same
1672 * flags value from this structure as that used at device
1673 * creation time in a VkDeviceQueueCreateInfo instance. If no
1674 * matching flags were specified at device creation time then
1675 * pQueue will return VK_NULL_HANDLE."
1677 *pQueue
= VK_NULL_HANDLE
;
1681 *pQueue
= radv_queue_to_handle(queue
);
1684 void radv_GetDeviceQueue(
1686 uint32_t queueFamilyIndex
,
1687 uint32_t queueIndex
,
1690 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1691 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1692 .queueFamilyIndex
= queueFamilyIndex
,
1693 .queueIndex
= queueIndex
1696 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1700 fill_geom_tess_rings(struct radv_queue
*queue
,
1702 bool add_sample_positions
,
1703 uint32_t esgs_ring_size
,
1704 struct radeon_winsys_bo
*esgs_ring_bo
,
1705 uint32_t gsvs_ring_size
,
1706 struct radeon_winsys_bo
*gsvs_ring_bo
,
1707 uint32_t tess_factor_ring_size
,
1708 uint32_t tess_offchip_ring_offset
,
1709 uint32_t tess_offchip_ring_size
,
1710 struct radeon_winsys_bo
*tess_rings_bo
)
1712 uint64_t esgs_va
= 0, gsvs_va
= 0;
1713 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1714 uint32_t *desc
= &map
[4];
1717 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1719 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1720 if (tess_rings_bo
) {
1721 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1722 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1725 /* stride 0, num records - size, add tid, swizzle, elsize4,
1728 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1729 S_008F04_STRIDE(0) |
1730 S_008F04_SWIZZLE_ENABLE(true);
1731 desc
[2] = esgs_ring_size
;
1732 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1733 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1734 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1735 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1736 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1737 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1738 S_008F0C_ELEMENT_SIZE(1) |
1739 S_008F0C_INDEX_STRIDE(3) |
1740 S_008F0C_ADD_TID_ENABLE(true);
1743 /* GS entry for ES->GS ring */
1744 /* stride 0, num records - size, elsize0,
1747 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1748 S_008F04_STRIDE(0) |
1749 S_008F04_SWIZZLE_ENABLE(false);
1750 desc
[2] = esgs_ring_size
;
1751 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1752 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1753 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1754 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1755 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1756 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1757 S_008F0C_ELEMENT_SIZE(0) |
1758 S_008F0C_INDEX_STRIDE(0) |
1759 S_008F0C_ADD_TID_ENABLE(false);
1762 /* VS entry for GS->VS ring */
1763 /* stride 0, num records - size, elsize0,
1766 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1767 S_008F04_STRIDE(0) |
1768 S_008F04_SWIZZLE_ENABLE(false);
1769 desc
[2] = gsvs_ring_size
;
1770 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1771 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1772 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1773 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1774 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1775 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1776 S_008F0C_ELEMENT_SIZE(0) |
1777 S_008F0C_INDEX_STRIDE(0) |
1778 S_008F0C_ADD_TID_ENABLE(false);
1781 /* stride gsvs_itemsize, num records 64
1782 elsize 4, index stride 16 */
1783 /* shader will patch stride and desc[2] */
1785 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1786 S_008F04_STRIDE(0) |
1787 S_008F04_SWIZZLE_ENABLE(true);
1789 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1790 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1791 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1792 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1793 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1794 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1795 S_008F0C_ELEMENT_SIZE(1) |
1796 S_008F0C_INDEX_STRIDE(1) |
1797 S_008F0C_ADD_TID_ENABLE(true);
1801 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1802 S_008F04_STRIDE(0) |
1803 S_008F04_SWIZZLE_ENABLE(false);
1804 desc
[2] = tess_factor_ring_size
;
1805 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1806 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1807 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1808 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1809 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1810 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1811 S_008F0C_ELEMENT_SIZE(0) |
1812 S_008F0C_INDEX_STRIDE(0) |
1813 S_008F0C_ADD_TID_ENABLE(false);
1816 desc
[0] = tess_offchip_va
;
1817 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1818 S_008F04_STRIDE(0) |
1819 S_008F04_SWIZZLE_ENABLE(false);
1820 desc
[2] = tess_offchip_ring_size
;
1821 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1822 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1823 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1824 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1825 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1826 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1827 S_008F0C_ELEMENT_SIZE(0) |
1828 S_008F0C_INDEX_STRIDE(0) |
1829 S_008F0C_ADD_TID_ENABLE(false);
1832 /* add sample positions after all rings */
1833 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1835 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1837 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1839 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1841 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1845 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1847 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1848 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1849 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1850 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1851 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1852 device
->physical_device
->rad_info
.max_se
;
1853 unsigned offchip_granularity
;
1854 unsigned hs_offchip_param
;
1855 switch (device
->tess_offchip_block_dw_size
) {
1860 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1863 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1867 switch (device
->physical_device
->rad_info
.chip_class
) {
1869 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1875 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1879 *max_offchip_buffers_p
= max_offchip_buffers
;
1880 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1881 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1882 --max_offchip_buffers
;
1884 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1885 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1888 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1890 return hs_offchip_param
;
1894 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
,
1895 struct radeon_winsys_bo
*esgs_ring_bo
,
1896 uint32_t esgs_ring_size
,
1897 struct radeon_winsys_bo
*gsvs_ring_bo
,
1898 uint32_t gsvs_ring_size
)
1900 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
1904 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1907 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1909 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1910 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1911 radeon_emit(cs
, esgs_ring_size
>> 8);
1912 radeon_emit(cs
, gsvs_ring_size
>> 8);
1914 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1915 radeon_emit(cs
, esgs_ring_size
>> 8);
1916 radeon_emit(cs
, gsvs_ring_size
>> 8);
1921 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
,
1922 unsigned hs_offchip_param
, unsigned tf_ring_size
,
1923 struct radeon_winsys_bo
*tess_rings_bo
)
1930 tf_va
= radv_buffer_get_va(tess_rings_bo
);
1932 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1934 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1935 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1936 S_030938_SIZE(tf_ring_size
/ 4));
1937 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1939 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1940 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1941 S_030944_BASE_HI(tf_va
>> 40));
1943 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
1946 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1947 S_008988_SIZE(tf_ring_size
/ 4));
1948 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1950 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1956 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
,
1957 struct radeon_winsys_bo
*compute_scratch_bo
)
1959 uint64_t scratch_va
;
1961 if (!compute_scratch_bo
)
1964 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1966 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1968 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1969 radeon_emit(cs
, scratch_va
);
1970 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1971 S_008F04_SWIZZLE_ENABLE(1));
1975 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
1976 struct radeon_winsys_cs
*cs
,
1977 struct radeon_winsys_bo
*descriptor_bo
)
1984 va
= radv_buffer_get_va(descriptor_bo
);
1986 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1988 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1989 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1990 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1991 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1992 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1994 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1995 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
1999 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2000 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2001 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2002 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2003 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2004 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2006 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2007 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2014 radv_get_preamble_cs(struct radv_queue
*queue
,
2015 uint32_t scratch_size
,
2016 uint32_t compute_scratch_size
,
2017 uint32_t esgs_ring_size
,
2018 uint32_t gsvs_ring_size
,
2019 bool needs_tess_rings
,
2020 bool needs_sample_positions
,
2021 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
2022 struct radeon_winsys_cs
**initial_preamble_cs
,
2023 struct radeon_winsys_cs
**continue_preamble_cs
)
2025 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2026 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2027 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2028 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2029 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2030 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2031 struct radeon_winsys_cs
*dest_cs
[3] = {0};
2032 bool add_tess_rings
= false, add_sample_positions
= false;
2033 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2034 unsigned max_offchip_buffers
;
2035 unsigned hs_offchip_param
= 0;
2036 unsigned tess_offchip_ring_offset
;
2037 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2038 if (!queue
->has_tess_rings
) {
2039 if (needs_tess_rings
)
2040 add_tess_rings
= true;
2042 if (!queue
->has_sample_positions
) {
2043 if (needs_sample_positions
)
2044 add_sample_positions
= true;
2046 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2047 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2048 &max_offchip_buffers
);
2049 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2050 tess_offchip_ring_size
= max_offchip_buffers
*
2051 queue
->device
->tess_offchip_block_dw_size
* 4;
2053 if (scratch_size
<= queue
->scratch_size
&&
2054 compute_scratch_size
<= queue
->compute_scratch_size
&&
2055 esgs_ring_size
<= queue
->esgs_ring_size
&&
2056 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2057 !add_tess_rings
&& !add_sample_positions
&&
2058 queue
->initial_preamble_cs
) {
2059 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2060 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2061 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2062 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2063 *continue_preamble_cs
= NULL
;
2067 if (scratch_size
> queue
->scratch_size
) {
2068 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2076 scratch_bo
= queue
->scratch_bo
;
2078 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2079 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2080 compute_scratch_size
,
2084 if (!compute_scratch_bo
)
2088 compute_scratch_bo
= queue
->compute_scratch_bo
;
2090 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2091 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2099 esgs_ring_bo
= queue
->esgs_ring_bo
;
2100 esgs_ring_size
= queue
->esgs_ring_size
;
2103 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2104 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2112 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2113 gsvs_ring_size
= queue
->gsvs_ring_size
;
2116 if (add_tess_rings
) {
2117 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2118 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2125 tess_rings_bo
= queue
->tess_rings_bo
;
2128 if (scratch_bo
!= queue
->scratch_bo
||
2129 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2130 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2131 tess_rings_bo
!= queue
->tess_rings_bo
||
2132 add_sample_positions
) {
2134 if (gsvs_ring_bo
|| esgs_ring_bo
||
2135 tess_rings_bo
|| add_sample_positions
) {
2136 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2137 if (add_sample_positions
)
2138 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2140 else if (scratch_bo
)
2141 size
= 8; /* 2 dword */
2143 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2147 RADEON_FLAG_CPU_ACCESS
|
2148 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2149 RADEON_FLAG_READ_ONLY
);
2153 descriptor_bo
= queue
->descriptor_bo
;
2155 for(int i
= 0; i
< 3; ++i
) {
2156 struct radeon_winsys_cs
*cs
= NULL
;
2157 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2158 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2165 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2167 if (descriptor_bo
!= queue
->descriptor_bo
) {
2168 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2171 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2172 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2173 S_008F04_SWIZZLE_ENABLE(1);
2174 map
[0] = scratch_va
;
2178 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2179 add_sample_positions
)
2180 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2181 esgs_ring_size
, esgs_ring_bo
,
2182 gsvs_ring_size
, gsvs_ring_bo
,
2183 tess_factor_ring_size
,
2184 tess_offchip_ring_offset
,
2185 tess_offchip_ring_size
,
2188 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2191 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2192 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2193 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2194 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2195 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2198 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2199 gsvs_ring_bo
, gsvs_ring_size
);
2200 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2201 tess_factor_ring_size
, tess_rings_bo
);
2202 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2203 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2206 si_cs_emit_cache_flush(cs
,
2207 queue
->device
->physical_device
->rad_info
.chip_class
,
2209 queue
->queue_family_index
== RING_COMPUTE
&&
2210 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2211 (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
)) |
2212 RADV_CMD_FLAG_INV_ICACHE
|
2213 RADV_CMD_FLAG_INV_SMEM_L1
|
2214 RADV_CMD_FLAG_INV_VMEM_L1
|
2215 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2216 } else if (i
== 1) {
2217 si_cs_emit_cache_flush(cs
,
2218 queue
->device
->physical_device
->rad_info
.chip_class
,
2220 queue
->queue_family_index
== RING_COMPUTE
&&
2221 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2222 RADV_CMD_FLAG_INV_ICACHE
|
2223 RADV_CMD_FLAG_INV_SMEM_L1
|
2224 RADV_CMD_FLAG_INV_VMEM_L1
|
2225 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2228 if (!queue
->device
->ws
->cs_finalize(cs
))
2232 if (queue
->initial_full_flush_preamble_cs
)
2233 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2235 if (queue
->initial_preamble_cs
)
2236 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2238 if (queue
->continue_preamble_cs
)
2239 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2241 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2242 queue
->initial_preamble_cs
= dest_cs
[1];
2243 queue
->continue_preamble_cs
= dest_cs
[2];
2245 if (scratch_bo
!= queue
->scratch_bo
) {
2246 if (queue
->scratch_bo
)
2247 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2248 queue
->scratch_bo
= scratch_bo
;
2249 queue
->scratch_size
= scratch_size
;
2252 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2253 if (queue
->compute_scratch_bo
)
2254 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2255 queue
->compute_scratch_bo
= compute_scratch_bo
;
2256 queue
->compute_scratch_size
= compute_scratch_size
;
2259 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2260 if (queue
->esgs_ring_bo
)
2261 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2262 queue
->esgs_ring_bo
= esgs_ring_bo
;
2263 queue
->esgs_ring_size
= esgs_ring_size
;
2266 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2267 if (queue
->gsvs_ring_bo
)
2268 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2269 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2270 queue
->gsvs_ring_size
= gsvs_ring_size
;
2273 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2274 queue
->tess_rings_bo
= tess_rings_bo
;
2275 queue
->has_tess_rings
= true;
2278 if (descriptor_bo
!= queue
->descriptor_bo
) {
2279 if (queue
->descriptor_bo
)
2280 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2282 queue
->descriptor_bo
= descriptor_bo
;
2285 if (add_sample_positions
)
2286 queue
->has_sample_positions
= true;
2288 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2289 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2290 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2291 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2292 *continue_preamble_cs
= NULL
;
2295 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2297 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2298 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2299 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2300 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2301 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2302 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2303 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2304 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2305 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2306 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2307 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2308 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2309 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2310 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2313 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2314 struct radv_winsys_sem_counts
*counts
,
2316 const VkSemaphore
*sems
,
2320 int syncobj_idx
= 0, sem_idx
= 0;
2322 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2325 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2326 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2328 if (sem
->temp_syncobj
|| sem
->syncobj
)
2329 counts
->syncobj_count
++;
2331 counts
->sem_count
++;
2334 if (_fence
!= VK_NULL_HANDLE
) {
2335 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2336 if (fence
->temp_syncobj
|| fence
->syncobj
)
2337 counts
->syncobj_count
++;
2340 if (counts
->syncobj_count
) {
2341 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2342 if (!counts
->syncobj
)
2343 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2346 if (counts
->sem_count
) {
2347 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2349 free(counts
->syncobj
);
2350 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2354 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2355 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2357 if (sem
->temp_syncobj
) {
2358 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2360 else if (sem
->syncobj
)
2361 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2364 counts
->sem
[sem_idx
++] = sem
->sem
;
2368 if (_fence
!= VK_NULL_HANDLE
) {
2369 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2370 if (fence
->temp_syncobj
)
2371 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2372 else if (fence
->syncobj
)
2373 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2380 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2382 free(sem_info
->wait
.syncobj
);
2383 free(sem_info
->wait
.sem
);
2384 free(sem_info
->signal
.syncobj
);
2385 free(sem_info
->signal
.sem
);
2389 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2391 const VkSemaphore
*sems
)
2393 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2394 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2396 if (sem
->temp_syncobj
) {
2397 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2398 sem
->temp_syncobj
= 0;
2404 radv_alloc_sem_info(struct radv_instance
*instance
,
2405 struct radv_winsys_sem_info
*sem_info
,
2407 const VkSemaphore
*wait_sems
,
2408 int num_signal_sems
,
2409 const VkSemaphore
*signal_sems
,
2413 memset(sem_info
, 0, sizeof(*sem_info
));
2415 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2418 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2420 radv_free_sem_info(sem_info
);
2422 /* caller can override these */
2423 sem_info
->cs_emit_wait
= true;
2424 sem_info
->cs_emit_signal
= true;
2428 /* Signals fence as soon as all the work currently put on queue is done. */
2429 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2430 struct radv_fence
*fence
)
2434 struct radv_winsys_sem_info sem_info
;
2436 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2437 radv_fence_to_handle(fence
));
2438 if (result
!= VK_SUCCESS
)
2441 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2442 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2443 1, NULL
, NULL
, &sem_info
, NULL
,
2444 false, fence
->fence
);
2445 radv_free_sem_info(&sem_info
);
2447 /* TODO: find a better error */
2449 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2454 VkResult
radv_QueueSubmit(
2456 uint32_t submitCount
,
2457 const VkSubmitInfo
* pSubmits
,
2460 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2461 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2462 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2463 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2465 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2466 uint32_t scratch_size
= 0;
2467 uint32_t compute_scratch_size
= 0;
2468 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2469 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2471 bool fence_emitted
= false;
2472 bool tess_rings_needed
= false;
2473 bool sample_positions_needed
= false;
2475 /* Do this first so failing to allocate scratch buffers can't result in
2476 * partially executed submissions. */
2477 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2478 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2479 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2480 pSubmits
[i
].pCommandBuffers
[j
]);
2482 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2483 compute_scratch_size
= MAX2(compute_scratch_size
,
2484 cmd_buffer
->compute_scratch_size_needed
);
2485 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2486 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2487 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2488 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2492 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2493 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2494 sample_positions_needed
, &initial_flush_preamble_cs
,
2495 &initial_preamble_cs
, &continue_preamble_cs
);
2496 if (result
!= VK_SUCCESS
)
2499 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2500 struct radeon_winsys_cs
**cs_array
;
2501 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2502 bool can_patch
= true;
2504 struct radv_winsys_sem_info sem_info
;
2506 result
= radv_alloc_sem_info(queue
->device
->instance
,
2508 pSubmits
[i
].waitSemaphoreCount
,
2509 pSubmits
[i
].pWaitSemaphores
,
2510 pSubmits
[i
].signalSemaphoreCount
,
2511 pSubmits
[i
].pSignalSemaphores
,
2513 if (result
!= VK_SUCCESS
)
2516 if (!pSubmits
[i
].commandBufferCount
) {
2517 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2518 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2519 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2524 radv_loge("failed to submit CS %d\n", i
);
2527 fence_emitted
= true;
2529 radv_free_sem_info(&sem_info
);
2533 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2534 (pSubmits
[i
].commandBufferCount
));
2536 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2537 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2538 pSubmits
[i
].pCommandBuffers
[j
]);
2539 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2541 cs_array
[j
] = cmd_buffer
->cs
;
2542 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2545 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2548 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2549 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2550 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2552 advance
= MIN2(max_cs_submission
,
2553 pSubmits
[i
].commandBufferCount
- j
);
2555 if (queue
->device
->trace_bo
)
2556 *queue
->device
->trace_id_ptr
= 0;
2558 sem_info
.cs_emit_wait
= j
== 0;
2559 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2561 if (unlikely(queue
->device
->use_global_bo_list
)) {
2562 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2563 bo_list
= &queue
->device
->bo_list
.list
;
2566 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2567 advance
, initial_preamble
, continue_preamble_cs
,
2569 can_patch
, base_fence
);
2571 if (unlikely(queue
->device
->use_global_bo_list
))
2572 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2575 radv_loge("failed to submit CS %d\n", i
);
2578 fence_emitted
= true;
2579 if (queue
->device
->trace_bo
) {
2580 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2584 radv_free_temp_syncobjs(queue
->device
,
2585 pSubmits
[i
].waitSemaphoreCount
,
2586 pSubmits
[i
].pWaitSemaphores
);
2587 radv_free_sem_info(&sem_info
);
2592 if (!fence_emitted
) {
2593 radv_signal_fence(queue
, fence
);
2595 fence
->submitted
= true;
2601 VkResult
radv_QueueWaitIdle(
2604 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2606 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2607 radv_queue_family_to_ring(queue
->queue_family_index
),
2612 VkResult
radv_DeviceWaitIdle(
2615 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2617 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2618 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2619 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2625 VkResult
radv_EnumerateInstanceExtensionProperties(
2626 const char* pLayerName
,
2627 uint32_t* pPropertyCount
,
2628 VkExtensionProperties
* pProperties
)
2630 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2632 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2633 if (radv_supported_instance_extensions
.extensions
[i
]) {
2634 vk_outarray_append(&out
, prop
) {
2635 *prop
= radv_instance_extensions
[i
];
2640 return vk_outarray_status(&out
);
2643 VkResult
radv_EnumerateDeviceExtensionProperties(
2644 VkPhysicalDevice physicalDevice
,
2645 const char* pLayerName
,
2646 uint32_t* pPropertyCount
,
2647 VkExtensionProperties
* pProperties
)
2649 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2650 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2652 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2653 if (device
->supported_extensions
.extensions
[i
]) {
2654 vk_outarray_append(&out
, prop
) {
2655 *prop
= radv_device_extensions
[i
];
2660 return vk_outarray_status(&out
);
2663 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2664 VkInstance _instance
,
2667 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2669 return radv_lookup_entrypoint_checked(pName
,
2670 instance
? instance
->apiVersion
: 0,
2671 instance
? &instance
->enabled_extensions
: NULL
,
2675 /* The loader wants us to expose a second GetInstanceProcAddr function
2676 * to work around certain LD_PRELOAD issues seen in apps.
2679 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2680 VkInstance instance
,
2684 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2685 VkInstance instance
,
2688 return radv_GetInstanceProcAddr(instance
, pName
);
2691 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2695 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2697 return radv_lookup_entrypoint_checked(pName
,
2698 device
->instance
->apiVersion
,
2699 &device
->instance
->enabled_extensions
,
2700 &device
->enabled_extensions
);
2703 bool radv_get_memory_fd(struct radv_device
*device
,
2704 struct radv_device_memory
*memory
,
2707 struct radeon_bo_metadata metadata
;
2709 if (memory
->image
) {
2710 radv_init_metadata(device
, memory
->image
, &metadata
);
2711 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2714 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2718 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2719 const VkMemoryAllocateInfo
* pAllocateInfo
,
2720 const VkAllocationCallbacks
* pAllocator
,
2721 VkDeviceMemory
* pMem
)
2723 struct radv_device_memory
*mem
;
2725 enum radeon_bo_domain domain
;
2727 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2729 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2731 if (pAllocateInfo
->allocationSize
== 0) {
2732 /* Apparently, this is allowed */
2733 *pMem
= VK_NULL_HANDLE
;
2737 const VkImportMemoryFdInfoKHR
*import_info
=
2738 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2739 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2740 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2741 const VkExportMemoryAllocateInfoKHR
*export_info
=
2742 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2743 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2744 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2746 const struct wsi_memory_allocate_info
*wsi_info
=
2747 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2749 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2750 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2752 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2754 if (wsi_info
&& wsi_info
->implicit_sync
)
2755 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2757 if (dedicate_info
) {
2758 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2759 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2765 mem
->user_ptr
= NULL
;
2768 assert(import_info
->handleType
==
2769 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2770 import_info
->handleType
==
2771 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2772 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2775 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2778 close(import_info
->fd
);
2780 } else if (host_ptr_info
) {
2781 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2782 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2783 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2784 pAllocateInfo
->allocationSize
);
2786 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2789 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2792 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2793 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2794 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2795 domain
= RADEON_DOMAIN_GTT
;
2797 domain
= RADEON_DOMAIN_VRAM
;
2799 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2800 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2802 flags
|= RADEON_FLAG_CPU_ACCESS
;
2804 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2805 flags
|= RADEON_FLAG_GTT_WC
;
2807 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2808 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2810 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2814 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2817 mem
->type_index
= mem_type_index
;
2820 result
= radv_bo_list_add(device
, mem
->bo
);
2821 if (result
!= VK_SUCCESS
)
2824 *pMem
= radv_device_memory_to_handle(mem
);
2829 device
->ws
->buffer_destroy(mem
->bo
);
2831 vk_free2(&device
->alloc
, pAllocator
, mem
);
2836 VkResult
radv_AllocateMemory(
2838 const VkMemoryAllocateInfo
* pAllocateInfo
,
2839 const VkAllocationCallbacks
* pAllocator
,
2840 VkDeviceMemory
* pMem
)
2842 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2843 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2846 void radv_FreeMemory(
2848 VkDeviceMemory _mem
,
2849 const VkAllocationCallbacks
* pAllocator
)
2851 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2852 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2857 radv_bo_list_remove(device
, mem
->bo
);
2858 device
->ws
->buffer_destroy(mem
->bo
);
2861 vk_free2(&device
->alloc
, pAllocator
, mem
);
2864 VkResult
radv_MapMemory(
2866 VkDeviceMemory _memory
,
2867 VkDeviceSize offset
,
2869 VkMemoryMapFlags flags
,
2872 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2873 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2881 *ppData
= mem
->user_ptr
;
2883 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2890 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
2893 void radv_UnmapMemory(
2895 VkDeviceMemory _memory
)
2897 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2898 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2903 if (mem
->user_ptr
== NULL
)
2904 device
->ws
->buffer_unmap(mem
->bo
);
2907 VkResult
radv_FlushMappedMemoryRanges(
2909 uint32_t memoryRangeCount
,
2910 const VkMappedMemoryRange
* pMemoryRanges
)
2915 VkResult
radv_InvalidateMappedMemoryRanges(
2917 uint32_t memoryRangeCount
,
2918 const VkMappedMemoryRange
* pMemoryRanges
)
2923 void radv_GetBufferMemoryRequirements(
2926 VkMemoryRequirements
* pMemoryRequirements
)
2928 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2929 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2931 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2933 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2934 pMemoryRequirements
->alignment
= 4096;
2936 pMemoryRequirements
->alignment
= 16;
2938 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2941 void radv_GetBufferMemoryRequirements2(
2943 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2944 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2946 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2947 &pMemoryRequirements
->memoryRequirements
);
2948 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2949 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2950 switch (ext
->sType
) {
2951 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2952 VkMemoryDedicatedRequirementsKHR
*req
=
2953 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2954 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2955 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2964 void radv_GetImageMemoryRequirements(
2967 VkMemoryRequirements
* pMemoryRequirements
)
2969 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2970 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2972 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2974 pMemoryRequirements
->size
= image
->size
;
2975 pMemoryRequirements
->alignment
= image
->alignment
;
2978 void radv_GetImageMemoryRequirements2(
2980 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2981 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2983 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2984 &pMemoryRequirements
->memoryRequirements
);
2986 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2988 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2989 switch (ext
->sType
) {
2990 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2991 VkMemoryDedicatedRequirementsKHR
*req
=
2992 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2993 req
->requiresDedicatedAllocation
= image
->shareable
;
2994 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3003 void radv_GetImageSparseMemoryRequirements(
3006 uint32_t* pSparseMemoryRequirementCount
,
3007 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3012 void radv_GetImageSparseMemoryRequirements2(
3014 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
3015 uint32_t* pSparseMemoryRequirementCount
,
3016 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
3021 void radv_GetDeviceMemoryCommitment(
3023 VkDeviceMemory memory
,
3024 VkDeviceSize
* pCommittedMemoryInBytes
)
3026 *pCommittedMemoryInBytes
= 0;
3029 VkResult
radv_BindBufferMemory2(VkDevice device
,
3030 uint32_t bindInfoCount
,
3031 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
3033 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3034 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3035 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3038 buffer
->bo
= mem
->bo
;
3039 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3047 VkResult
radv_BindBufferMemory(
3050 VkDeviceMemory memory
,
3051 VkDeviceSize memoryOffset
)
3053 const VkBindBufferMemoryInfoKHR info
= {
3054 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3057 .memoryOffset
= memoryOffset
3060 return radv_BindBufferMemory2(device
, 1, &info
);
3063 VkResult
radv_BindImageMemory2(VkDevice device
,
3064 uint32_t bindInfoCount
,
3065 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3067 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3068 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3069 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3072 image
->bo
= mem
->bo
;
3073 image
->offset
= pBindInfos
[i
].memoryOffset
;
3083 VkResult
radv_BindImageMemory(
3086 VkDeviceMemory memory
,
3087 VkDeviceSize memoryOffset
)
3089 const VkBindImageMemoryInfoKHR info
= {
3090 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3093 .memoryOffset
= memoryOffset
3096 return radv_BindImageMemory2(device
, 1, &info
);
3101 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3102 const VkSparseBufferMemoryBindInfo
*bind
)
3104 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3106 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3107 struct radv_device_memory
*mem
= NULL
;
3109 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3110 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3112 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3113 bind
->pBinds
[i
].resourceOffset
,
3114 bind
->pBinds
[i
].size
,
3115 mem
? mem
->bo
: NULL
,
3116 bind
->pBinds
[i
].memoryOffset
);
3121 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3122 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3124 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3126 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3127 struct radv_device_memory
*mem
= NULL
;
3129 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3130 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3132 device
->ws
->buffer_virtual_bind(image
->bo
,
3133 bind
->pBinds
[i
].resourceOffset
,
3134 bind
->pBinds
[i
].size
,
3135 mem
? mem
->bo
: NULL
,
3136 bind
->pBinds
[i
].memoryOffset
);
3140 VkResult
radv_QueueBindSparse(
3142 uint32_t bindInfoCount
,
3143 const VkBindSparseInfo
* pBindInfo
,
3146 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3147 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3148 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3149 bool fence_emitted
= false;
3151 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3152 struct radv_winsys_sem_info sem_info
;
3153 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3154 radv_sparse_buffer_bind_memory(queue
->device
,
3155 pBindInfo
[i
].pBufferBinds
+ j
);
3158 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3159 radv_sparse_image_opaque_bind_memory(queue
->device
,
3160 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3164 result
= radv_alloc_sem_info(queue
->device
->instance
,
3166 pBindInfo
[i
].waitSemaphoreCount
,
3167 pBindInfo
[i
].pWaitSemaphores
,
3168 pBindInfo
[i
].signalSemaphoreCount
,
3169 pBindInfo
[i
].pSignalSemaphores
,
3171 if (result
!= VK_SUCCESS
)
3174 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3175 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3176 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3180 fence_emitted
= true;
3182 fence
->submitted
= true;
3185 radv_free_sem_info(&sem_info
);
3190 if (!fence_emitted
) {
3191 radv_signal_fence(queue
, fence
);
3193 fence
->submitted
= true;
3199 VkResult
radv_CreateFence(
3201 const VkFenceCreateInfo
* pCreateInfo
,
3202 const VkAllocationCallbacks
* pAllocator
,
3205 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3206 const VkExportFenceCreateInfoKHR
*export
=
3207 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3208 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3209 export
? export
->handleTypes
: 0;
3211 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3213 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3216 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3218 fence
->submitted
= false;
3219 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3220 fence
->temp_syncobj
= 0;
3221 if (device
->always_use_syncobj
|| handleTypes
) {
3222 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3224 vk_free2(&device
->alloc
, pAllocator
, fence
);
3225 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3227 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3228 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3230 fence
->fence
= NULL
;
3232 fence
->fence
= device
->ws
->create_fence();
3233 if (!fence
->fence
) {
3234 vk_free2(&device
->alloc
, pAllocator
, fence
);
3235 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3240 *pFence
= radv_fence_to_handle(fence
);
3245 void radv_DestroyFence(
3248 const VkAllocationCallbacks
* pAllocator
)
3250 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3251 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3256 if (fence
->temp_syncobj
)
3257 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3259 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3261 device
->ws
->destroy_fence(fence
->fence
);
3262 vk_free2(&device
->alloc
, pAllocator
, fence
);
3266 static uint64_t radv_get_current_time()
3269 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3270 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3273 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3275 uint64_t current_time
= radv_get_current_time();
3277 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3279 return current_time
+ timeout
;
3283 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3285 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3286 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3287 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3293 VkResult
radv_WaitForFences(
3295 uint32_t fenceCount
,
3296 const VkFence
* pFences
,
3300 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3301 timeout
= radv_get_absolute_timeout(timeout
);
3303 if (device
->always_use_syncobj
) {
3304 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3306 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3308 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3309 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3310 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3313 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3316 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3319 if (!waitAll
&& fenceCount
> 1) {
3320 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3321 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3322 uint32_t wait_count
= 0;
3323 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3325 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3327 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3328 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3330 if (fence
->signalled
) {
3335 fences
[wait_count
++] = fence
->fence
;
3338 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3339 waitAll
, timeout
- radv_get_current_time());
3342 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3345 while(radv_get_current_time() <= timeout
) {
3346 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3347 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3354 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3355 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3356 bool expired
= false;
3358 if (fence
->temp_syncobj
) {
3359 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3364 if (fence
->syncobj
) {
3365 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3370 if (fence
->signalled
)
3373 if (!fence
->submitted
) {
3374 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3377 if (!fence
->submitted
)
3380 /* Recheck as it may have been set by submitting operations. */
3381 if (fence
->signalled
)
3385 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3389 fence
->signalled
= true;
3395 VkResult
radv_ResetFences(VkDevice _device
,
3396 uint32_t fenceCount
,
3397 const VkFence
*pFences
)
3399 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3401 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3402 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3403 fence
->submitted
= fence
->signalled
= false;
3405 /* Per spec, we first restore the permanent payload, and then reset, so
3406 * having a temp syncobj should not skip resetting the permanent syncobj. */
3407 if (fence
->temp_syncobj
) {
3408 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3409 fence
->temp_syncobj
= 0;
3412 if (fence
->syncobj
) {
3413 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3420 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3422 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3423 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3425 if (fence
->temp_syncobj
) {
3426 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3427 return success
? VK_SUCCESS
: VK_NOT_READY
;
3430 if (fence
->syncobj
) {
3431 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3432 return success
? VK_SUCCESS
: VK_NOT_READY
;
3435 if (fence
->signalled
)
3437 if (!fence
->submitted
)
3438 return VK_NOT_READY
;
3439 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3440 return VK_NOT_READY
;
3446 // Queue semaphore functions
3448 VkResult
radv_CreateSemaphore(
3450 const VkSemaphoreCreateInfo
* pCreateInfo
,
3451 const VkAllocationCallbacks
* pAllocator
,
3452 VkSemaphore
* pSemaphore
)
3454 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3455 const VkExportSemaphoreCreateInfoKHR
*export
=
3456 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3457 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3458 export
? export
->handleTypes
: 0;
3460 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3462 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3464 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3466 sem
->temp_syncobj
= 0;
3467 /* create a syncobject if we are going to export this semaphore */
3468 if (device
->always_use_syncobj
|| handleTypes
) {
3469 assert (device
->physical_device
->rad_info
.has_syncobj
);
3470 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3472 vk_free2(&device
->alloc
, pAllocator
, sem
);
3473 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3477 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3479 vk_free2(&device
->alloc
, pAllocator
, sem
);
3480 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3485 *pSemaphore
= radv_semaphore_to_handle(sem
);
3489 void radv_DestroySemaphore(
3491 VkSemaphore _semaphore
,
3492 const VkAllocationCallbacks
* pAllocator
)
3494 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3495 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3500 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3502 device
->ws
->destroy_sem(sem
->sem
);
3503 vk_free2(&device
->alloc
, pAllocator
, sem
);
3506 VkResult
radv_CreateEvent(
3508 const VkEventCreateInfo
* pCreateInfo
,
3509 const VkAllocationCallbacks
* pAllocator
,
3512 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3513 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3515 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3518 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3520 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3522 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3524 vk_free2(&device
->alloc
, pAllocator
, event
);
3525 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3528 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3530 *pEvent
= radv_event_to_handle(event
);
3535 void radv_DestroyEvent(
3538 const VkAllocationCallbacks
* pAllocator
)
3540 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3541 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3545 device
->ws
->buffer_destroy(event
->bo
);
3546 vk_free2(&device
->alloc
, pAllocator
, event
);
3549 VkResult
radv_GetEventStatus(
3553 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3555 if (*event
->map
== 1)
3556 return VK_EVENT_SET
;
3557 return VK_EVENT_RESET
;
3560 VkResult
radv_SetEvent(
3564 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3570 VkResult
radv_ResetEvent(
3574 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3580 VkResult
radv_CreateBuffer(
3582 const VkBufferCreateInfo
* pCreateInfo
,
3583 const VkAllocationCallbacks
* pAllocator
,
3586 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3587 struct radv_buffer
*buffer
;
3589 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3591 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3592 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3594 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3596 buffer
->size
= pCreateInfo
->size
;
3597 buffer
->usage
= pCreateInfo
->usage
;
3600 buffer
->flags
= pCreateInfo
->flags
;
3602 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3603 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3605 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3606 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3607 align64(buffer
->size
, 4096),
3608 4096, 0, RADEON_FLAG_VIRTUAL
);
3610 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3611 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3615 *pBuffer
= radv_buffer_to_handle(buffer
);
3620 void radv_DestroyBuffer(
3623 const VkAllocationCallbacks
* pAllocator
)
3625 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3626 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3631 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3632 device
->ws
->buffer_destroy(buffer
->bo
);
3634 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3637 static inline unsigned
3638 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3641 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3643 return image
->surface
.u
.legacy
.tiling_index
[level
];
3646 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3648 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3652 radv_init_dcc_control_reg(struct radv_device
*device
,
3653 struct radv_image_view
*iview
)
3655 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3656 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3657 unsigned max_compressed_block_size
;
3658 unsigned independent_64b_blocks
;
3660 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3663 if (iview
->image
->info
.samples
> 1) {
3664 if (iview
->image
->surface
.bpe
== 1)
3665 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3666 else if (iview
->image
->surface
.bpe
== 2)
3667 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3670 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3671 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3672 * dGPU and 64 for APU because all of our APUs to date use
3673 * DIMMs which have a request granularity size of 64B while all
3674 * other chips have a 32B request size.
3676 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3679 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3680 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3681 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3682 /* If this DCC image is potentially going to be used in texture
3683 * fetches, we need some special settings.
3685 independent_64b_blocks
= 1;
3686 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3688 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3689 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3690 * big as possible for better compression state.
3692 independent_64b_blocks
= 0;
3693 max_compressed_block_size
= max_uncompressed_block_size
;
3696 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3697 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3698 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3699 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3703 radv_initialise_color_surface(struct radv_device
*device
,
3704 struct radv_color_buffer_info
*cb
,
3705 struct radv_image_view
*iview
)
3707 const struct vk_format_description
*desc
;
3708 unsigned ntype
, format
, swap
, endian
;
3709 unsigned blend_clamp
= 0, blend_bypass
= 0;
3711 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3713 desc
= vk_format_description(iview
->vk_format
);
3715 memset(cb
, 0, sizeof(*cb
));
3717 /* Intensity is implemented as Red, so treat it that way. */
3718 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3720 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3722 cb
->cb_color_base
= va
>> 8;
3724 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3725 struct gfx9_surf_meta_flags meta
;
3726 if (iview
->image
->dcc_offset
)
3727 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3729 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3731 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3732 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3733 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3734 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3736 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3737 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3739 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3740 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3742 cb
->cb_color_base
+= level_info
->offset
>> 8;
3743 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3744 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3746 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3747 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3748 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3750 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3751 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3752 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3754 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3756 if (radv_image_has_fmask(iview
->image
)) {
3757 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3758 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3759 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3760 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3762 /* This must be set for fast clear to work without FMASK. */
3763 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3764 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3765 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3766 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3770 /* CMASK variables */
3771 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3772 va
+= iview
->image
->cmask
.offset
;
3773 cb
->cb_color_cmask
= va
>> 8;
3775 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3776 va
+= iview
->image
->dcc_offset
;
3777 cb
->cb_dcc_base
= va
>> 8;
3778 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3780 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3781 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3782 S_028C6C_SLICE_MAX(max_slice
);
3784 if (iview
->image
->info
.samples
> 1) {
3785 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3787 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3788 S_028C74_NUM_FRAGMENTS(log_samples
);
3791 if (radv_image_has_fmask(iview
->image
)) {
3792 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3793 cb
->cb_color_fmask
= va
>> 8;
3794 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3796 cb
->cb_color_fmask
= cb
->cb_color_base
;
3799 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3801 vk_format_get_first_non_void_channel(iview
->vk_format
));
3802 format
= radv_translate_colorformat(iview
->vk_format
);
3803 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3804 radv_finishme("Illegal color\n");
3805 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3806 endian
= radv_colorformat_endian_swap(format
);
3808 /* blend clamp should be set for all NORM/SRGB types */
3809 if (ntype
== V_028C70_NUMBER_UNORM
||
3810 ntype
== V_028C70_NUMBER_SNORM
||
3811 ntype
== V_028C70_NUMBER_SRGB
)
3814 /* set blend bypass according to docs if SINT/UINT or
3815 8/24 COLOR variants */
3816 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3817 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3818 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3823 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3824 (format
== V_028C70_COLOR_8
||
3825 format
== V_028C70_COLOR_8_8
||
3826 format
== V_028C70_COLOR_8_8_8_8
))
3827 ->color_is_int8
= true;
3829 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3830 S_028C70_COMP_SWAP(swap
) |
3831 S_028C70_BLEND_CLAMP(blend_clamp
) |
3832 S_028C70_BLEND_BYPASS(blend_bypass
) |
3833 S_028C70_SIMPLE_FLOAT(1) |
3834 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3835 ntype
!= V_028C70_NUMBER_SNORM
&&
3836 ntype
!= V_028C70_NUMBER_SRGB
&&
3837 format
!= V_028C70_COLOR_8_24
&&
3838 format
!= V_028C70_COLOR_24_8
) |
3839 S_028C70_NUMBER_TYPE(ntype
) |
3840 S_028C70_ENDIAN(endian
);
3841 if (radv_image_has_fmask(iview
->image
)) {
3842 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3843 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3844 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3845 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3849 if (radv_image_has_cmask(iview
->image
) &&
3850 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3851 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3853 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3854 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3856 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3858 /* This must be set for fast clear to work without FMASK. */
3859 if (!radv_image_has_fmask(iview
->image
) &&
3860 device
->physical_device
->rad_info
.chip_class
== SI
) {
3861 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3862 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3865 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3866 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3867 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3869 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3870 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3871 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3872 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3873 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3874 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3879 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3880 struct radv_image_view
*iview
)
3882 unsigned max_zplanes
= 0;
3884 assert(radv_image_is_tc_compat_htile(iview
->image
));
3886 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3887 /* Default value for 32-bit depth surfaces. */
3890 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3891 iview
->image
->info
.samples
> 1)
3894 max_zplanes
= max_zplanes
+ 1;
3896 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3897 /* Do not enable Z plane compression for 16-bit depth
3898 * surfaces because isn't supported on GFX8. Only
3899 * 32-bit depth surfaces are supported by the hardware.
3900 * This allows to maintain shader compatibility and to
3901 * reduce the number of depth decompressions.
3905 if (iview
->image
->info
.samples
<= 1)
3907 else if (iview
->image
->info
.samples
<= 4)
3918 radv_initialise_ds_surface(struct radv_device
*device
,
3919 struct radv_ds_buffer_info
*ds
,
3920 struct radv_image_view
*iview
)
3922 unsigned level
= iview
->base_mip
;
3923 unsigned format
, stencil_format
;
3924 uint64_t va
, s_offs
, z_offs
;
3925 bool stencil_only
= false;
3926 memset(ds
, 0, sizeof(*ds
));
3927 switch (iview
->image
->vk_format
) {
3928 case VK_FORMAT_D24_UNORM_S8_UINT
:
3929 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3930 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3931 ds
->offset_scale
= 2.0f
;
3933 case VK_FORMAT_D16_UNORM
:
3934 case VK_FORMAT_D16_UNORM_S8_UINT
:
3935 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3936 ds
->offset_scale
= 4.0f
;
3938 case VK_FORMAT_D32_SFLOAT
:
3939 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3940 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3941 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3942 ds
->offset_scale
= 1.0f
;
3944 case VK_FORMAT_S8_UINT
:
3945 stencil_only
= true;
3951 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3952 stencil_format
= iview
->image
->surface
.has_stencil
?
3953 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3955 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3956 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3957 S_028008_SLICE_MAX(max_slice
);
3959 ds
->db_htile_data_base
= 0;
3960 ds
->db_htile_surface
= 0;
3962 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3963 s_offs
= z_offs
= va
;
3965 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3966 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3967 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3969 ds
->db_z_info
= S_028038_FORMAT(format
) |
3970 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3971 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3972 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3973 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3974 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3976 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3977 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3978 ds
->db_depth_view
|= S_028008_MIPID(level
);
3980 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3981 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3983 if (radv_htile_enabled(iview
->image
, level
)) {
3984 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3986 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3987 unsigned max_zplanes
=
3988 radv_calc_decompress_on_z_planes(device
, iview
);
3990 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3991 S_028038_ITERATE_FLUSH(1);
3992 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3995 if (!iview
->image
->surface
.has_stencil
)
3996 /* Use all of the htile_buffer for depth if there's no stencil. */
3997 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3998 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3999 iview
->image
->htile_offset
;
4000 ds
->db_htile_data_base
= va
>> 8;
4001 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4002 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4003 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4006 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4009 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4011 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4012 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4014 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4015 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4016 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4018 if (iview
->image
->info
.samples
> 1)
4019 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4021 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4022 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4023 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4024 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4025 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4026 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4027 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4028 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4031 tile_mode
= stencil_tile_mode
;
4033 ds
->db_depth_info
|=
4034 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4035 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4036 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4037 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4038 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4039 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4040 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4041 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4043 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4044 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4045 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4046 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4048 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4051 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4052 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4053 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4055 if (radv_htile_enabled(iview
->image
, level
)) {
4056 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4058 if (!iview
->image
->surface
.has_stencil
&&
4059 !radv_image_is_tc_compat_htile(iview
->image
))
4060 /* Use all of the htile_buffer for depth if there's no stencil. */
4061 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4063 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4064 iview
->image
->htile_offset
;
4065 ds
->db_htile_data_base
= va
>> 8;
4066 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4068 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4069 unsigned max_zplanes
=
4070 radv_calc_decompress_on_z_planes(device
, iview
);
4072 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4073 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4078 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4079 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4082 VkResult
radv_CreateFramebuffer(
4084 const VkFramebufferCreateInfo
* pCreateInfo
,
4085 const VkAllocationCallbacks
* pAllocator
,
4086 VkFramebuffer
* pFramebuffer
)
4088 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4089 struct radv_framebuffer
*framebuffer
;
4091 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4093 size_t size
= sizeof(*framebuffer
) +
4094 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4095 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4096 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4097 if (framebuffer
== NULL
)
4098 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4100 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4101 framebuffer
->width
= pCreateInfo
->width
;
4102 framebuffer
->height
= pCreateInfo
->height
;
4103 framebuffer
->layers
= pCreateInfo
->layers
;
4104 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4105 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4106 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4107 framebuffer
->attachments
[i
].attachment
= iview
;
4108 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4109 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4110 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4111 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4113 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4114 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4115 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4118 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4122 void radv_DestroyFramebuffer(
4125 const VkAllocationCallbacks
* pAllocator
)
4127 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4128 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4132 vk_free2(&device
->alloc
, pAllocator
, fb
);
4135 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4137 switch (address_mode
) {
4138 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4139 return V_008F30_SQ_TEX_WRAP
;
4140 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4141 return V_008F30_SQ_TEX_MIRROR
;
4142 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4143 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4144 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4145 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4146 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4147 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4149 unreachable("illegal tex wrap mode");
4155 radv_tex_compare(VkCompareOp op
)
4158 case VK_COMPARE_OP_NEVER
:
4159 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4160 case VK_COMPARE_OP_LESS
:
4161 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4162 case VK_COMPARE_OP_EQUAL
:
4163 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4164 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4165 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4166 case VK_COMPARE_OP_GREATER
:
4167 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4168 case VK_COMPARE_OP_NOT_EQUAL
:
4169 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4170 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4171 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4172 case VK_COMPARE_OP_ALWAYS
:
4173 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4175 unreachable("illegal compare mode");
4181 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4184 case VK_FILTER_NEAREST
:
4185 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4186 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4187 case VK_FILTER_LINEAR
:
4188 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4189 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4190 case VK_FILTER_CUBIC_IMG
:
4192 fprintf(stderr
, "illegal texture filter");
4198 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4201 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4202 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4203 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4204 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4206 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4211 radv_tex_bordercolor(VkBorderColor bcolor
)
4214 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4215 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4216 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4217 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4218 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4219 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4220 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4221 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4222 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4230 radv_tex_aniso_filter(unsigned filter
)
4244 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4247 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4248 return SQ_IMG_FILTER_MODE_BLEND
;
4249 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4250 return SQ_IMG_FILTER_MODE_MIN
;
4251 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4252 return SQ_IMG_FILTER_MODE_MAX
;
4260 radv_init_sampler(struct radv_device
*device
,
4261 struct radv_sampler
*sampler
,
4262 const VkSamplerCreateInfo
*pCreateInfo
)
4264 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4265 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4266 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4267 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4268 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4270 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4271 vk_find_struct_const(pCreateInfo
->pNext
,
4272 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4273 if (sampler_reduction
)
4274 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4276 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4277 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4278 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4279 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4280 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4281 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4282 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4283 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4284 S_008F30_DISABLE_CUBE_WRAP(0) |
4285 S_008F30_COMPAT_MODE(is_vi
) |
4286 S_008F30_FILTER_MODE(filter_mode
));
4287 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4288 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4289 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4290 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4291 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4292 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4293 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4294 S_008F38_MIP_POINT_PRECLAMP(0) |
4295 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4296 S_008F38_FILTER_PREC_FIX(1) |
4297 S_008F38_ANISO_OVERRIDE(is_vi
));
4298 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4299 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4302 VkResult
radv_CreateSampler(
4304 const VkSamplerCreateInfo
* pCreateInfo
,
4305 const VkAllocationCallbacks
* pAllocator
,
4306 VkSampler
* pSampler
)
4308 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4309 struct radv_sampler
*sampler
;
4311 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4313 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4314 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4316 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4318 radv_init_sampler(device
, sampler
, pCreateInfo
);
4319 *pSampler
= radv_sampler_to_handle(sampler
);
4324 void radv_DestroySampler(
4327 const VkAllocationCallbacks
* pAllocator
)
4329 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4330 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4334 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4337 /* vk_icd.h does not declare this function, so we declare it here to
4338 * suppress Wmissing-prototypes.
4340 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4341 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4343 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4344 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4346 /* For the full details on loader interface versioning, see
4347 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4348 * What follows is a condensed summary, to help you navigate the large and
4349 * confusing official doc.
4351 * - Loader interface v0 is incompatible with later versions. We don't
4354 * - In loader interface v1:
4355 * - The first ICD entrypoint called by the loader is
4356 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4358 * - The ICD must statically expose no other Vulkan symbol unless it is
4359 * linked with -Bsymbolic.
4360 * - Each dispatchable Vulkan handle created by the ICD must be
4361 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4362 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4363 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4364 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4365 * such loader-managed surfaces.
4367 * - Loader interface v2 differs from v1 in:
4368 * - The first ICD entrypoint called by the loader is
4369 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4370 * statically expose this entrypoint.
4372 * - Loader interface v3 differs from v2 in:
4373 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4374 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4375 * because the loader no longer does so.
4377 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4381 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4382 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4385 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4386 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4388 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4390 /* At the moment, we support only the below handle types. */
4391 assert(pGetFdInfo
->handleType
==
4392 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4393 pGetFdInfo
->handleType
==
4394 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4396 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4398 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4402 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4403 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4405 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4407 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4409 switch (handleType
) {
4410 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4411 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4415 /* The valid usage section for this function says:
4417 * "handleType must not be one of the handle types defined as
4420 * So opaque handle types fall into the default "unsupported" case.
4422 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4426 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4430 uint32_t syncobj_handle
= 0;
4431 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4433 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4436 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4438 *syncobj
= syncobj_handle
;
4444 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4448 /* If we create a syncobj we do it locally so that if we have an error, we don't
4449 * leave a syncobj in an undetermined state in the fence. */
4450 uint32_t syncobj_handle
= *syncobj
;
4451 if (!syncobj_handle
) {
4452 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4454 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4459 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4461 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4463 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4466 *syncobj
= syncobj_handle
;
4473 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4474 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4476 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4477 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4478 uint32_t *syncobj_dst
= NULL
;
4480 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4481 syncobj_dst
= &sem
->temp_syncobj
;
4483 syncobj_dst
= &sem
->syncobj
;
4486 switch(pImportSemaphoreFdInfo
->handleType
) {
4487 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4488 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4489 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4490 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4492 unreachable("Unhandled semaphore handle type");
4496 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4497 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4500 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4501 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4503 uint32_t syncobj_handle
;
4505 if (sem
->temp_syncobj
)
4506 syncobj_handle
= sem
->temp_syncobj
;
4508 syncobj_handle
= sem
->syncobj
;
4510 switch(pGetFdInfo
->handleType
) {
4511 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4512 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4514 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4515 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4517 if (sem
->temp_syncobj
) {
4518 close (sem
->temp_syncobj
);
4519 sem
->temp_syncobj
= 0;
4521 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4526 unreachable("Unhandled semaphore handle type");
4530 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4534 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4535 VkPhysicalDevice physicalDevice
,
4536 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4537 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4539 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4541 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4542 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4543 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4544 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4545 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4546 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4547 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4548 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4549 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4550 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4551 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4552 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4553 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4555 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4556 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4557 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4561 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4562 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4564 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4565 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4566 uint32_t *syncobj_dst
= NULL
;
4569 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4570 syncobj_dst
= &fence
->temp_syncobj
;
4572 syncobj_dst
= &fence
->syncobj
;
4575 switch(pImportFenceFdInfo
->handleType
) {
4576 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4577 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4578 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4579 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4581 unreachable("Unhandled fence handle type");
4585 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4586 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4589 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4590 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4592 uint32_t syncobj_handle
;
4594 if (fence
->temp_syncobj
)
4595 syncobj_handle
= fence
->temp_syncobj
;
4597 syncobj_handle
= fence
->syncobj
;
4599 switch(pGetFdInfo
->handleType
) {
4600 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4601 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4603 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4604 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4606 if (fence
->temp_syncobj
) {
4607 close (fence
->temp_syncobj
);
4608 fence
->temp_syncobj
= 0;
4610 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4615 unreachable("Unhandled fence handle type");
4619 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4623 void radv_GetPhysicalDeviceExternalFenceProperties(
4624 VkPhysicalDevice physicalDevice
,
4625 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4626 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4628 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4630 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4631 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4632 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4633 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4634 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4635 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4636 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4638 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4639 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4640 pExternalFenceProperties
->externalFenceFeatures
= 0;
4645 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4646 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4647 const VkAllocationCallbacks
* pAllocator
,
4648 VkDebugReportCallbackEXT
* pCallback
)
4650 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4651 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4652 pCreateInfo
, pAllocator
, &instance
->alloc
,
4657 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4658 VkDebugReportCallbackEXT _callback
,
4659 const VkAllocationCallbacks
* pAllocator
)
4661 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4662 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4663 _callback
, pAllocator
, &instance
->alloc
);
4667 radv_DebugReportMessageEXT(VkInstance _instance
,
4668 VkDebugReportFlagsEXT flags
,
4669 VkDebugReportObjectTypeEXT objectType
,
4672 int32_t messageCode
,
4673 const char* pLayerPrefix
,
4674 const char* pMessage
)
4676 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4677 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4678 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4682 radv_GetDeviceGroupPeerMemoryFeatures(
4685 uint32_t localDeviceIndex
,
4686 uint32_t remoteDeviceIndex
,
4687 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4689 assert(localDeviceIndex
== remoteDeviceIndex
);
4691 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4692 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4693 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4694 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;