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
=
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
},
413 {"checkir", RADV_DEBUG_CHECKIR
},
418 radv_get_debug_option_name(int id
)
420 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
421 return radv_debug_options
[id
].string
;
424 static const struct debug_control radv_perftest_options
[] = {
425 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
426 {"sisched", RADV_PERFTEST_SISCHED
},
427 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
428 {"binning", RADV_PERFTEST_BINNING
},
429 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
434 radv_get_perftest_option_name(int id
)
436 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
437 return radv_perftest_options
[id
].string
;
441 radv_handle_per_app_options(struct radv_instance
*instance
,
442 const VkApplicationInfo
*info
)
444 const char *name
= info
? info
->pApplicationName
: NULL
;
449 if (!strcmp(name
, "Talos - Linux - 32bit") ||
450 !strcmp(name
, "Talos - Linux - 64bit")) {
451 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
452 /* Force enable LLVM sisched for Talos because it looks
453 * safe and it gives few more FPS.
455 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
460 static int radv_get_instance_extension_index(const char *name
)
462 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
463 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
470 VkResult
radv_CreateInstance(
471 const VkInstanceCreateInfo
* pCreateInfo
,
472 const VkAllocationCallbacks
* pAllocator
,
473 VkInstance
* pInstance
)
475 struct radv_instance
*instance
;
478 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
480 uint32_t client_version
;
481 if (pCreateInfo
->pApplicationInfo
&&
482 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
483 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
485 radv_EnumerateInstanceVersion(&client_version
);
488 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
489 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
491 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
493 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
496 instance
->alloc
= *pAllocator
;
498 instance
->alloc
= default_alloc
;
500 instance
->apiVersion
= client_version
;
501 instance
->physicalDeviceCount
= -1;
503 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
506 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
507 radv_perftest_options
);
510 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
511 radv_logi("Created an instance");
513 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
514 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
515 int index
= radv_get_instance_extension_index(ext_name
);
517 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
518 vk_free2(&default_alloc
, pAllocator
, instance
);
519 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
522 instance
->enabled_extensions
.extensions
[index
] = true;
525 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
526 if (result
!= VK_SUCCESS
) {
527 vk_free2(&default_alloc
, pAllocator
, instance
);
528 return vk_error(instance
, result
);
533 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
535 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
537 *pInstance
= radv_instance_to_handle(instance
);
542 void radv_DestroyInstance(
543 VkInstance _instance
,
544 const VkAllocationCallbacks
* pAllocator
)
546 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
551 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
552 radv_physical_device_finish(instance
->physicalDevices
+ i
);
555 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
559 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
561 vk_free(&instance
->alloc
, instance
);
565 radv_enumerate_devices(struct radv_instance
*instance
)
567 /* TODO: Check for more devices ? */
568 drmDevicePtr devices
[8];
569 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
572 instance
->physicalDeviceCount
= 0;
574 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
576 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
577 radv_logi("Found %d drm nodes", max_devices
);
580 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
582 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
583 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
584 devices
[i
]->bustype
== DRM_BUS_PCI
&&
585 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
587 result
= radv_physical_device_init(instance
->physicalDevices
+
588 instance
->physicalDeviceCount
,
591 if (result
== VK_SUCCESS
)
592 ++instance
->physicalDeviceCount
;
593 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
597 drmFreeDevices(devices
, max_devices
);
602 VkResult
radv_EnumeratePhysicalDevices(
603 VkInstance _instance
,
604 uint32_t* pPhysicalDeviceCount
,
605 VkPhysicalDevice
* pPhysicalDevices
)
607 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
610 if (instance
->physicalDeviceCount
< 0) {
611 result
= radv_enumerate_devices(instance
);
612 if (result
!= VK_SUCCESS
&&
613 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
617 if (!pPhysicalDevices
) {
618 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
620 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
621 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
622 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
625 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
629 VkResult
radv_EnumeratePhysicalDeviceGroups(
630 VkInstance _instance
,
631 uint32_t* pPhysicalDeviceGroupCount
,
632 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
634 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
637 if (instance
->physicalDeviceCount
< 0) {
638 result
= radv_enumerate_devices(instance
);
639 if (result
!= VK_SUCCESS
&&
640 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
644 if (!pPhysicalDeviceGroupProperties
) {
645 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
647 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
648 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
649 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
650 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
651 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
654 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
658 void radv_GetPhysicalDeviceFeatures(
659 VkPhysicalDevice physicalDevice
,
660 VkPhysicalDeviceFeatures
* pFeatures
)
662 memset(pFeatures
, 0, sizeof(*pFeatures
));
664 *pFeatures
= (VkPhysicalDeviceFeatures
) {
665 .robustBufferAccess
= true,
666 .fullDrawIndexUint32
= true,
667 .imageCubeArray
= true,
668 .independentBlend
= true,
669 .geometryShader
= true,
670 .tessellationShader
= true,
671 .sampleRateShading
= true,
672 .dualSrcBlend
= true,
674 .multiDrawIndirect
= true,
675 .drawIndirectFirstInstance
= true,
677 .depthBiasClamp
= true,
678 .fillModeNonSolid
= true,
683 .multiViewport
= true,
684 .samplerAnisotropy
= true,
685 .textureCompressionETC2
= false,
686 .textureCompressionASTC_LDR
= false,
687 .textureCompressionBC
= true,
688 .occlusionQueryPrecise
= true,
689 .pipelineStatisticsQuery
= true,
690 .vertexPipelineStoresAndAtomics
= true,
691 .fragmentStoresAndAtomics
= true,
692 .shaderTessellationAndGeometryPointSize
= true,
693 .shaderImageGatherExtended
= true,
694 .shaderStorageImageExtendedFormats
= true,
695 .shaderStorageImageMultisample
= false,
696 .shaderUniformBufferArrayDynamicIndexing
= true,
697 .shaderSampledImageArrayDynamicIndexing
= true,
698 .shaderStorageBufferArrayDynamicIndexing
= true,
699 .shaderStorageImageArrayDynamicIndexing
= true,
700 .shaderStorageImageReadWithoutFormat
= true,
701 .shaderStorageImageWriteWithoutFormat
= true,
702 .shaderClipDistance
= true,
703 .shaderCullDistance
= true,
704 .shaderFloat64
= true,
706 .shaderInt16
= false,
707 .sparseBinding
= true,
708 .variableMultisampleRate
= true,
709 .inheritedQueries
= true,
713 void radv_GetPhysicalDeviceFeatures2(
714 VkPhysicalDevice physicalDevice
,
715 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
717 vk_foreach_struct(ext
, pFeatures
->pNext
) {
718 switch (ext
->sType
) {
719 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
720 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
721 features
->variablePointersStorageBuffer
= true;
722 features
->variablePointers
= false;
725 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
726 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
727 features
->multiview
= true;
728 features
->multiviewGeometryShader
= true;
729 features
->multiviewTessellationShader
= true;
732 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
733 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
734 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
735 features
->shaderDrawParameters
= true;
738 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
739 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
740 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
741 features
->protectedMemory
= false;
744 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
745 VkPhysicalDevice16BitStorageFeatures
*features
=
746 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
747 features
->storageBuffer16BitAccess
= false;
748 features
->uniformAndStorageBuffer16BitAccess
= false;
749 features
->storagePushConstant16
= false;
750 features
->storageInputOutput16
= false;
753 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
754 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
755 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
756 features
->samplerYcbcrConversion
= false;
759 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
760 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
761 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
762 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
763 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
764 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
765 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
766 features
->shaderSampledImageArrayNonUniformIndexing
= false;
767 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
768 features
->shaderStorageImageArrayNonUniformIndexing
= false;
769 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
770 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
771 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
772 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
773 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
774 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
775 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
776 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
777 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
778 features
->descriptorBindingUpdateUnusedWhilePending
= true;
779 features
->descriptorBindingPartiallyBound
= true;
780 features
->descriptorBindingVariableDescriptorCount
= true;
781 features
->runtimeDescriptorArray
= true;
788 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
791 void radv_GetPhysicalDeviceProperties(
792 VkPhysicalDevice physicalDevice
,
793 VkPhysicalDeviceProperties
* pProperties
)
795 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
796 VkSampleCountFlags sample_counts
= 0xf;
798 /* make sure that the entire descriptor set is addressable with a signed
799 * 32-bit int. So the sum of all limits scaled by descriptor size has to
800 * be at most 2 GiB. the combined image & samples object count as one of
801 * both. This limit is for the pipeline layout, not for the set layout, but
802 * there is no set limit, so we just set a pipeline limit. I don't think
803 * any app is going to hit this soon. */
804 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
805 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
806 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
807 32 /* sampler, largest when combined with image */ +
808 64 /* sampled image */ +
809 64 /* storage image */);
811 VkPhysicalDeviceLimits limits
= {
812 .maxImageDimension1D
= (1 << 14),
813 .maxImageDimension2D
= (1 << 14),
814 .maxImageDimension3D
= (1 << 11),
815 .maxImageDimensionCube
= (1 << 14),
816 .maxImageArrayLayers
= (1 << 11),
817 .maxTexelBufferElements
= 128 * 1024 * 1024,
818 .maxUniformBufferRange
= UINT32_MAX
,
819 .maxStorageBufferRange
= UINT32_MAX
,
820 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
821 .maxMemoryAllocationCount
= UINT32_MAX
,
822 .maxSamplerAllocationCount
= 64 * 1024,
823 .bufferImageGranularity
= 64, /* A cache line */
824 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
825 .maxBoundDescriptorSets
= MAX_SETS
,
826 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
827 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
828 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
829 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
830 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
831 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
832 .maxPerStageResources
= max_descriptor_set_size
,
833 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
834 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
835 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
836 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
837 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
838 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
839 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
840 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
841 .maxVertexInputAttributes
= 32,
842 .maxVertexInputBindings
= 32,
843 .maxVertexInputAttributeOffset
= 2047,
844 .maxVertexInputBindingStride
= 2048,
845 .maxVertexOutputComponents
= 128,
846 .maxTessellationGenerationLevel
= 64,
847 .maxTessellationPatchSize
= 32,
848 .maxTessellationControlPerVertexInputComponents
= 128,
849 .maxTessellationControlPerVertexOutputComponents
= 128,
850 .maxTessellationControlPerPatchOutputComponents
= 120,
851 .maxTessellationControlTotalOutputComponents
= 4096,
852 .maxTessellationEvaluationInputComponents
= 128,
853 .maxTessellationEvaluationOutputComponents
= 128,
854 .maxGeometryShaderInvocations
= 127,
855 .maxGeometryInputComponents
= 64,
856 .maxGeometryOutputComponents
= 128,
857 .maxGeometryOutputVertices
= 256,
858 .maxGeometryTotalOutputComponents
= 1024,
859 .maxFragmentInputComponents
= 128,
860 .maxFragmentOutputAttachments
= 8,
861 .maxFragmentDualSrcAttachments
= 1,
862 .maxFragmentCombinedOutputResources
= 8,
863 .maxComputeSharedMemorySize
= 32768,
864 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
865 .maxComputeWorkGroupInvocations
= 2048,
866 .maxComputeWorkGroupSize
= {
871 .subPixelPrecisionBits
= 4 /* FIXME */,
872 .subTexelPrecisionBits
= 4 /* FIXME */,
873 .mipmapPrecisionBits
= 4 /* FIXME */,
874 .maxDrawIndexedIndexValue
= UINT32_MAX
,
875 .maxDrawIndirectCount
= UINT32_MAX
,
876 .maxSamplerLodBias
= 16,
877 .maxSamplerAnisotropy
= 16,
878 .maxViewports
= MAX_VIEWPORTS
,
879 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
880 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
881 .viewportSubPixelBits
= 8,
882 .minMemoryMapAlignment
= 4096, /* A page */
883 .minTexelBufferOffsetAlignment
= 1,
884 .minUniformBufferOffsetAlignment
= 4,
885 .minStorageBufferOffsetAlignment
= 4,
886 .minTexelOffset
= -32,
887 .maxTexelOffset
= 31,
888 .minTexelGatherOffset
= -32,
889 .maxTexelGatherOffset
= 31,
890 .minInterpolationOffset
= -2,
891 .maxInterpolationOffset
= 2,
892 .subPixelInterpolationOffsetBits
= 8,
893 .maxFramebufferWidth
= (1 << 14),
894 .maxFramebufferHeight
= (1 << 14),
895 .maxFramebufferLayers
= (1 << 10),
896 .framebufferColorSampleCounts
= sample_counts
,
897 .framebufferDepthSampleCounts
= sample_counts
,
898 .framebufferStencilSampleCounts
= sample_counts
,
899 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
900 .maxColorAttachments
= MAX_RTS
,
901 .sampledImageColorSampleCounts
= sample_counts
,
902 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
903 .sampledImageDepthSampleCounts
= sample_counts
,
904 .sampledImageStencilSampleCounts
= sample_counts
,
905 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
906 .maxSampleMaskWords
= 1,
907 .timestampComputeAndGraphics
= true,
908 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
909 .maxClipDistances
= 8,
910 .maxCullDistances
= 8,
911 .maxCombinedClipAndCullDistances
= 8,
912 .discreteQueuePriorities
= 1,
913 .pointSizeRange
= { 0.125, 255.875 },
914 .lineWidthRange
= { 0.0, 7.9921875 },
915 .pointSizeGranularity
= (1.0 / 8.0),
916 .lineWidthGranularity
= (1.0 / 128.0),
917 .strictLines
= false, /* FINISHME */
918 .standardSampleLocations
= true,
919 .optimalBufferCopyOffsetAlignment
= 128,
920 .optimalBufferCopyRowPitchAlignment
= 128,
921 .nonCoherentAtomSize
= 64,
924 *pProperties
= (VkPhysicalDeviceProperties
) {
925 .apiVersion
= radv_physical_device_api_version(pdevice
),
926 .driverVersion
= vk_get_driver_version(),
927 .vendorID
= ATI_VENDOR_ID
,
928 .deviceID
= pdevice
->rad_info
.pci_id
,
929 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
931 .sparseProperties
= {0},
934 strcpy(pProperties
->deviceName
, pdevice
->name
);
935 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
938 void radv_GetPhysicalDeviceProperties2(
939 VkPhysicalDevice physicalDevice
,
940 VkPhysicalDeviceProperties2KHR
*pProperties
)
942 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
943 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
945 vk_foreach_struct(ext
, pProperties
->pNext
) {
946 switch (ext
->sType
) {
947 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
948 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
949 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
950 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
953 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
954 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
955 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
956 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
957 properties
->deviceLUIDValid
= false;
960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
961 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
962 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
963 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
966 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
967 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
968 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
969 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
972 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
973 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
974 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
975 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
978 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
979 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
980 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
981 properties
->minImportedHostPointerAlignment
= 4096;
984 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
985 VkPhysicalDeviceSubgroupProperties
*properties
=
986 (VkPhysicalDeviceSubgroupProperties
*)ext
;
987 properties
->subgroupSize
= 64;
988 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
989 properties
->supportedOperations
=
990 VK_SUBGROUP_FEATURE_BASIC_BIT
|
991 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
992 VK_SUBGROUP_FEATURE_QUAD_BIT
|
993 VK_SUBGROUP_FEATURE_VOTE_BIT
;
994 if (pdevice
->rad_info
.chip_class
>= VI
) {
995 properties
->supportedOperations
|=
996 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
997 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
999 properties
->quadOperationsInAllStages
= true;
1002 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1003 VkPhysicalDeviceMaintenance3Properties
*properties
=
1004 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1005 /* Make sure everything is addressable by a signed 32-bit int, and
1006 * our largest descriptors are 96 bytes. */
1007 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1008 /* Our buffer size fields allow only this much */
1009 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1012 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1013 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1014 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1015 /* GFX6-8 only support single channel min/max filter. */
1016 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1017 properties
->filterMinmaxSingleComponentFormats
= true;
1020 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1021 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1022 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1024 /* Shader engines. */
1025 properties
->shaderEngineCount
=
1026 pdevice
->rad_info
.max_se
;
1027 properties
->shaderArraysPerEngineCount
=
1028 pdevice
->rad_info
.max_sh_per_se
;
1029 properties
->computeUnitsPerShaderArray
=
1030 pdevice
->rad_info
.num_good_compute_units
/
1031 (pdevice
->rad_info
.max_se
*
1032 pdevice
->rad_info
.max_sh_per_se
);
1033 properties
->simdPerComputeUnit
= 4;
1034 properties
->wavefrontsPerSimd
=
1035 pdevice
->rad_info
.family
== CHIP_TONGA
||
1036 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1037 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1038 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1039 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1040 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1041 properties
->wavefrontSize
= 64;
1044 properties
->sgprsPerSimd
=
1045 radv_get_num_physical_sgprs(pdevice
);
1046 properties
->minSgprAllocation
=
1047 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1048 properties
->maxSgprAllocation
=
1049 pdevice
->rad_info
.family
== CHIP_TONGA
||
1050 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1051 properties
->sgprAllocationGranularity
=
1052 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1055 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1056 properties
->minVgprAllocation
= 4;
1057 properties
->maxVgprAllocation
= 256;
1058 properties
->vgprAllocationGranularity
= 4;
1061 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1062 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1063 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1064 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1067 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1068 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1069 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1070 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1071 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1072 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1073 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1074 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1075 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1076 properties
->robustBufferAccessUpdateAfterBind
= false;
1077 properties
->quadDivergentImplicitLod
= false;
1079 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1080 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1081 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1082 32 /* sampler, largest when combined with image */ +
1083 64 /* sampled image */ +
1084 64 /* storage image */);
1085 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1086 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1087 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1088 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1089 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1090 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1091 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1092 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1093 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1094 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1095 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1096 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1097 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1098 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1099 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1108 static void radv_get_physical_device_queue_family_properties(
1109 struct radv_physical_device
* pdevice
,
1111 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1113 int num_queue_families
= 1;
1115 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1116 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1117 num_queue_families
++;
1119 if (pQueueFamilyProperties
== NULL
) {
1120 *pCount
= num_queue_families
;
1129 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1130 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1131 VK_QUEUE_COMPUTE_BIT
|
1132 VK_QUEUE_TRANSFER_BIT
|
1133 VK_QUEUE_SPARSE_BINDING_BIT
,
1135 .timestampValidBits
= 64,
1136 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1141 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1142 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1143 if (*pCount
> idx
) {
1144 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1145 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1146 VK_QUEUE_TRANSFER_BIT
|
1147 VK_QUEUE_SPARSE_BINDING_BIT
,
1148 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1149 .timestampValidBits
= 64,
1150 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1158 void radv_GetPhysicalDeviceQueueFamilyProperties(
1159 VkPhysicalDevice physicalDevice
,
1161 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1163 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1164 if (!pQueueFamilyProperties
) {
1165 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1168 VkQueueFamilyProperties
*properties
[] = {
1169 pQueueFamilyProperties
+ 0,
1170 pQueueFamilyProperties
+ 1,
1171 pQueueFamilyProperties
+ 2,
1173 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1174 assert(*pCount
<= 3);
1177 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1178 VkPhysicalDevice physicalDevice
,
1180 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1182 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1183 if (!pQueueFamilyProperties
) {
1184 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1187 VkQueueFamilyProperties
*properties
[] = {
1188 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1189 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1190 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1192 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1193 assert(*pCount
<= 3);
1196 void radv_GetPhysicalDeviceMemoryProperties(
1197 VkPhysicalDevice physicalDevice
,
1198 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1200 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1202 *pMemoryProperties
= physical_device
->memory_properties
;
1205 void radv_GetPhysicalDeviceMemoryProperties2(
1206 VkPhysicalDevice physicalDevice
,
1207 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1209 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1210 &pMemoryProperties
->memoryProperties
);
1213 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1215 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1216 const void *pHostPointer
,
1217 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1219 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1223 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1224 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1225 uint32_t memoryTypeBits
= 0;
1226 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1227 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1228 memoryTypeBits
= (1 << i
);
1232 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1236 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1240 static enum radeon_ctx_priority
1241 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1243 /* Default to MEDIUM when a specific global priority isn't requested */
1245 return RADEON_CTX_PRIORITY_MEDIUM
;
1247 switch(pObj
->globalPriority
) {
1248 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1249 return RADEON_CTX_PRIORITY_REALTIME
;
1250 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1251 return RADEON_CTX_PRIORITY_HIGH
;
1252 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1253 return RADEON_CTX_PRIORITY_MEDIUM
;
1254 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1255 return RADEON_CTX_PRIORITY_LOW
;
1257 unreachable("Illegal global priority value");
1258 return RADEON_CTX_PRIORITY_INVALID
;
1263 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1264 uint32_t queue_family_index
, int idx
,
1265 VkDeviceQueueCreateFlags flags
,
1266 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1268 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1269 queue
->device
= device
;
1270 queue
->queue_family_index
= queue_family_index
;
1271 queue
->queue_idx
= idx
;
1272 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1273 queue
->flags
= flags
;
1275 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1277 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1283 radv_queue_finish(struct radv_queue
*queue
)
1286 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1288 if (queue
->initial_full_flush_preamble_cs
)
1289 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1290 if (queue
->initial_preamble_cs
)
1291 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1292 if (queue
->continue_preamble_cs
)
1293 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1294 if (queue
->descriptor_bo
)
1295 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1296 if (queue
->scratch_bo
)
1297 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1298 if (queue
->esgs_ring_bo
)
1299 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1300 if (queue
->gsvs_ring_bo
)
1301 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1302 if (queue
->tess_rings_bo
)
1303 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1304 if (queue
->compute_scratch_bo
)
1305 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1309 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1311 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1312 bo_list
->list
.count
= bo_list
->capacity
= 0;
1313 bo_list
->list
.bos
= NULL
;
1317 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1319 free(bo_list
->list
.bos
);
1320 pthread_mutex_destroy(&bo_list
->mutex
);
1323 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1324 struct radeon_winsys_bo
*bo
)
1326 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1328 if (unlikely(!device
->use_global_bo_list
))
1331 pthread_mutex_lock(&bo_list
->mutex
);
1332 if (bo_list
->list
.count
== bo_list
->capacity
) {
1333 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1334 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1337 pthread_mutex_unlock(&bo_list
->mutex
);
1338 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1341 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1342 bo_list
->capacity
= capacity
;
1345 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1346 pthread_mutex_unlock(&bo_list
->mutex
);
1350 static void radv_bo_list_remove(struct radv_device
*device
,
1351 struct radeon_winsys_bo
*bo
)
1353 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1355 if (unlikely(!device
->use_global_bo_list
))
1358 pthread_mutex_lock(&bo_list
->mutex
);
1359 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1360 if (bo_list
->list
.bos
[i
] == bo
) {
1361 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1362 --bo_list
->list
.count
;
1366 pthread_mutex_unlock(&bo_list
->mutex
);
1370 radv_device_init_gs_info(struct radv_device
*device
)
1372 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1373 device
->physical_device
->rad_info
.family
);
1376 static int radv_get_device_extension_index(const char *name
)
1378 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1379 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1385 VkResult
radv_CreateDevice(
1386 VkPhysicalDevice physicalDevice
,
1387 const VkDeviceCreateInfo
* pCreateInfo
,
1388 const VkAllocationCallbacks
* pAllocator
,
1391 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1393 struct radv_device
*device
;
1395 bool keep_shader_info
= false;
1397 /* Check enabled features */
1398 if (pCreateInfo
->pEnabledFeatures
) {
1399 VkPhysicalDeviceFeatures supported_features
;
1400 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1401 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1402 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1403 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1404 for (uint32_t i
= 0; i
< num_features
; i
++) {
1405 if (enabled_feature
[i
] && !supported_feature
[i
])
1406 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1410 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1412 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1414 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1416 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1417 device
->instance
= physical_device
->instance
;
1418 device
->physical_device
= physical_device
;
1420 device
->ws
= physical_device
->ws
;
1422 device
->alloc
= *pAllocator
;
1424 device
->alloc
= physical_device
->instance
->alloc
;
1426 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1427 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1428 int index
= radv_get_device_extension_index(ext_name
);
1429 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1430 vk_free(&device
->alloc
, device
);
1431 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1434 device
->enabled_extensions
.extensions
[index
] = true;
1437 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1439 /* With update after bind we can't attach bo's to the command buffer
1440 * from the descriptor set anymore, so we have to use a global BO list.
1442 device
->use_global_bo_list
=
1443 device
->enabled_extensions
.EXT_descriptor_indexing
;
1445 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1446 list_inithead(&device
->shader_slabs
);
1448 radv_bo_list_init(&device
->bo_list
);
1450 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1451 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1452 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1453 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1454 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1456 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1458 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1459 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1460 if (!device
->queues
[qfi
]) {
1461 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1465 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1467 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1469 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1470 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1471 qfi
, q
, queue_create
->flags
,
1473 if (result
!= VK_SUCCESS
)
1478 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1479 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1481 /* Disabled and not implemented for now. */
1482 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1485 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1488 /* The maximum number of scratch waves. Scratch space isn't divided
1489 * evenly between CUs. The number is only a function of the number of CUs.
1490 * We can decrease the constant to decrease the scratch buffer size.
1492 * sctx->scratch_waves must be >= the maximum possible size of
1493 * 1 threadgroup, so that the hw doesn't hang from being unable
1496 * The recommended value is 4 per CU at most. Higher numbers don't
1497 * bring much benefit, but they still occupy chip resources (think
1498 * async compute). I've seen ~2% performance difference between 4 and 32.
1500 uint32_t max_threads_per_block
= 2048;
1501 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1502 max_threads_per_block
/ 64);
1504 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1506 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1507 /* If the KMD allows it (there is a KMD hw register for it),
1508 * allow launching waves out-of-order.
1510 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1513 radv_device_init_gs_info(device
);
1515 device
->tess_offchip_block_dw_size
=
1516 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1517 device
->has_distributed_tess
=
1518 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1519 device
->physical_device
->rad_info
.max_se
>= 2;
1521 if (getenv("RADV_TRACE_FILE")) {
1522 const char *filename
= getenv("RADV_TRACE_FILE");
1524 keep_shader_info
= true;
1526 if (!radv_init_trace(device
))
1529 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1530 radv_dump_enabled_options(device
, stderr
);
1533 device
->keep_shader_info
= keep_shader_info
;
1535 result
= radv_device_init_meta(device
);
1536 if (result
!= VK_SUCCESS
)
1539 radv_device_init_msaa(device
);
1541 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1542 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1544 case RADV_QUEUE_GENERAL
:
1545 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1546 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1547 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1549 case RADV_QUEUE_COMPUTE
:
1550 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1551 radeon_emit(device
->empty_cs
[family
], 0);
1554 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1557 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1558 cik_create_gfx_config(device
);
1560 VkPipelineCacheCreateInfo ci
;
1561 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1564 ci
.pInitialData
= NULL
;
1565 ci
.initialDataSize
= 0;
1567 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1569 if (result
!= VK_SUCCESS
)
1572 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1574 *pDevice
= radv_device_to_handle(device
);
1578 radv_device_finish_meta(device
);
1580 radv_bo_list_finish(&device
->bo_list
);
1582 if (device
->trace_bo
)
1583 device
->ws
->buffer_destroy(device
->trace_bo
);
1585 if (device
->gfx_init
)
1586 device
->ws
->buffer_destroy(device
->gfx_init
);
1588 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1589 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1590 radv_queue_finish(&device
->queues
[i
][q
]);
1591 if (device
->queue_count
[i
])
1592 vk_free(&device
->alloc
, device
->queues
[i
]);
1595 vk_free(&device
->alloc
, device
);
1599 void radv_DestroyDevice(
1601 const VkAllocationCallbacks
* pAllocator
)
1603 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1608 if (device
->trace_bo
)
1609 device
->ws
->buffer_destroy(device
->trace_bo
);
1611 if (device
->gfx_init
)
1612 device
->ws
->buffer_destroy(device
->gfx_init
);
1614 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1615 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1616 radv_queue_finish(&device
->queues
[i
][q
]);
1617 if (device
->queue_count
[i
])
1618 vk_free(&device
->alloc
, device
->queues
[i
]);
1619 if (device
->empty_cs
[i
])
1620 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1622 radv_device_finish_meta(device
);
1624 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1625 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1627 radv_destroy_shader_slabs(device
);
1629 radv_bo_list_finish(&device
->bo_list
);
1630 vk_free(&device
->alloc
, device
);
1633 VkResult
radv_EnumerateInstanceLayerProperties(
1634 uint32_t* pPropertyCount
,
1635 VkLayerProperties
* pProperties
)
1637 if (pProperties
== NULL
) {
1638 *pPropertyCount
= 0;
1642 /* None supported at this time */
1643 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1646 VkResult
radv_EnumerateDeviceLayerProperties(
1647 VkPhysicalDevice physicalDevice
,
1648 uint32_t* pPropertyCount
,
1649 VkLayerProperties
* pProperties
)
1651 if (pProperties
== NULL
) {
1652 *pPropertyCount
= 0;
1656 /* None supported at this time */
1657 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1660 void radv_GetDeviceQueue2(
1662 const VkDeviceQueueInfo2
* pQueueInfo
,
1665 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1666 struct radv_queue
*queue
;
1668 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1669 if (pQueueInfo
->flags
!= queue
->flags
) {
1670 /* From the Vulkan 1.1.70 spec:
1672 * "The queue returned by vkGetDeviceQueue2 must have the same
1673 * flags value from this structure as that used at device
1674 * creation time in a VkDeviceQueueCreateInfo instance. If no
1675 * matching flags were specified at device creation time then
1676 * pQueue will return VK_NULL_HANDLE."
1678 *pQueue
= VK_NULL_HANDLE
;
1682 *pQueue
= radv_queue_to_handle(queue
);
1685 void radv_GetDeviceQueue(
1687 uint32_t queueFamilyIndex
,
1688 uint32_t queueIndex
,
1691 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1692 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1693 .queueFamilyIndex
= queueFamilyIndex
,
1694 .queueIndex
= queueIndex
1697 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1701 fill_geom_tess_rings(struct radv_queue
*queue
,
1703 bool add_sample_positions
,
1704 uint32_t esgs_ring_size
,
1705 struct radeon_winsys_bo
*esgs_ring_bo
,
1706 uint32_t gsvs_ring_size
,
1707 struct radeon_winsys_bo
*gsvs_ring_bo
,
1708 uint32_t tess_factor_ring_size
,
1709 uint32_t tess_offchip_ring_offset
,
1710 uint32_t tess_offchip_ring_size
,
1711 struct radeon_winsys_bo
*tess_rings_bo
)
1713 uint64_t esgs_va
= 0, gsvs_va
= 0;
1714 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1715 uint32_t *desc
= &map
[4];
1718 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1720 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1721 if (tess_rings_bo
) {
1722 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1723 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1726 /* stride 0, num records - size, add tid, swizzle, elsize4,
1729 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1730 S_008F04_STRIDE(0) |
1731 S_008F04_SWIZZLE_ENABLE(true);
1732 desc
[2] = esgs_ring_size
;
1733 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1734 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1735 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1736 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1737 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1738 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1739 S_008F0C_ELEMENT_SIZE(1) |
1740 S_008F0C_INDEX_STRIDE(3) |
1741 S_008F0C_ADD_TID_ENABLE(true);
1744 /* GS entry for ES->GS ring */
1745 /* stride 0, num records - size, elsize0,
1748 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1749 S_008F04_STRIDE(0) |
1750 S_008F04_SWIZZLE_ENABLE(false);
1751 desc
[2] = esgs_ring_size
;
1752 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1753 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1754 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1755 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1756 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1757 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1758 S_008F0C_ELEMENT_SIZE(0) |
1759 S_008F0C_INDEX_STRIDE(0) |
1760 S_008F0C_ADD_TID_ENABLE(false);
1763 /* VS entry for GS->VS ring */
1764 /* stride 0, num records - size, elsize0,
1767 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1768 S_008F04_STRIDE(0) |
1769 S_008F04_SWIZZLE_ENABLE(false);
1770 desc
[2] = gsvs_ring_size
;
1771 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1772 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1773 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1774 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1775 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1776 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1777 S_008F0C_ELEMENT_SIZE(0) |
1778 S_008F0C_INDEX_STRIDE(0) |
1779 S_008F0C_ADD_TID_ENABLE(false);
1782 /* stride gsvs_itemsize, num records 64
1783 elsize 4, index stride 16 */
1784 /* shader will patch stride and desc[2] */
1786 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1787 S_008F04_STRIDE(0) |
1788 S_008F04_SWIZZLE_ENABLE(true);
1790 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1791 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1792 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1793 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1794 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1795 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1796 S_008F0C_ELEMENT_SIZE(1) |
1797 S_008F0C_INDEX_STRIDE(1) |
1798 S_008F0C_ADD_TID_ENABLE(true);
1802 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1803 S_008F04_STRIDE(0) |
1804 S_008F04_SWIZZLE_ENABLE(false);
1805 desc
[2] = tess_factor_ring_size
;
1806 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1807 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1808 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1809 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1810 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1811 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1812 S_008F0C_ELEMENT_SIZE(0) |
1813 S_008F0C_INDEX_STRIDE(0) |
1814 S_008F0C_ADD_TID_ENABLE(false);
1817 desc
[0] = tess_offchip_va
;
1818 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1819 S_008F04_STRIDE(0) |
1820 S_008F04_SWIZZLE_ENABLE(false);
1821 desc
[2] = tess_offchip_ring_size
;
1822 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1823 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1824 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1825 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1826 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1827 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1828 S_008F0C_ELEMENT_SIZE(0) |
1829 S_008F0C_INDEX_STRIDE(0) |
1830 S_008F0C_ADD_TID_ENABLE(false);
1833 /* add sample positions after all rings */
1834 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1836 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1838 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1840 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1842 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1846 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1848 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1849 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1850 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1851 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1852 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1853 device
->physical_device
->rad_info
.max_se
;
1854 unsigned offchip_granularity
;
1855 unsigned hs_offchip_param
;
1856 switch (device
->tess_offchip_block_dw_size
) {
1861 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1864 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1868 switch (device
->physical_device
->rad_info
.chip_class
) {
1870 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1876 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1880 *max_offchip_buffers_p
= max_offchip_buffers
;
1881 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1882 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1883 --max_offchip_buffers
;
1885 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1886 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1889 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1891 return hs_offchip_param
;
1895 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
1896 struct radeon_winsys_bo
*esgs_ring_bo
,
1897 uint32_t esgs_ring_size
,
1898 struct radeon_winsys_bo
*gsvs_ring_bo
,
1899 uint32_t gsvs_ring_size
)
1901 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
1905 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1908 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1910 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1911 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1912 radeon_emit(cs
, esgs_ring_size
>> 8);
1913 radeon_emit(cs
, gsvs_ring_size
>> 8);
1915 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1916 radeon_emit(cs
, esgs_ring_size
>> 8);
1917 radeon_emit(cs
, gsvs_ring_size
>> 8);
1922 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
1923 unsigned hs_offchip_param
, unsigned tf_ring_size
,
1924 struct radeon_winsys_bo
*tess_rings_bo
)
1931 tf_va
= radv_buffer_get_va(tess_rings_bo
);
1933 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1935 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1936 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1937 S_030938_SIZE(tf_ring_size
/ 4));
1938 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1940 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1941 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1942 S_030944_BASE_HI(tf_va
>> 40));
1944 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
1947 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1948 S_008988_SIZE(tf_ring_size
/ 4));
1949 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1951 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1957 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
1958 struct radeon_winsys_bo
*compute_scratch_bo
)
1960 uint64_t scratch_va
;
1962 if (!compute_scratch_bo
)
1965 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1967 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1969 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1970 radeon_emit(cs
, scratch_va
);
1971 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1972 S_008F04_SWIZZLE_ENABLE(1));
1976 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
1977 struct radeon_cmdbuf
*cs
,
1978 struct radeon_winsys_bo
*descriptor_bo
)
1985 va
= radv_buffer_get_va(descriptor_bo
);
1987 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1989 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1990 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1991 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1992 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1993 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1995 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1996 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2000 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2001 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2002 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2003 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2004 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2005 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2007 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2008 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2015 radv_get_preamble_cs(struct radv_queue
*queue
,
2016 uint32_t scratch_size
,
2017 uint32_t compute_scratch_size
,
2018 uint32_t esgs_ring_size
,
2019 uint32_t gsvs_ring_size
,
2020 bool needs_tess_rings
,
2021 bool needs_sample_positions
,
2022 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2023 struct radeon_cmdbuf
**initial_preamble_cs
,
2024 struct radeon_cmdbuf
**continue_preamble_cs
)
2026 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2027 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2028 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2029 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2030 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2031 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2032 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2033 bool add_tess_rings
= false, add_sample_positions
= false;
2034 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2035 unsigned max_offchip_buffers
;
2036 unsigned hs_offchip_param
= 0;
2037 unsigned tess_offchip_ring_offset
;
2038 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2039 if (!queue
->has_tess_rings
) {
2040 if (needs_tess_rings
)
2041 add_tess_rings
= true;
2043 if (!queue
->has_sample_positions
) {
2044 if (needs_sample_positions
)
2045 add_sample_positions
= true;
2047 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2048 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2049 &max_offchip_buffers
);
2050 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2051 tess_offchip_ring_size
= max_offchip_buffers
*
2052 queue
->device
->tess_offchip_block_dw_size
* 4;
2054 if (scratch_size
<= queue
->scratch_size
&&
2055 compute_scratch_size
<= queue
->compute_scratch_size
&&
2056 esgs_ring_size
<= queue
->esgs_ring_size
&&
2057 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2058 !add_tess_rings
&& !add_sample_positions
&&
2059 queue
->initial_preamble_cs
) {
2060 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2061 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2062 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2063 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2064 *continue_preamble_cs
= NULL
;
2068 if (scratch_size
> queue
->scratch_size
) {
2069 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2077 scratch_bo
= queue
->scratch_bo
;
2079 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2080 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2081 compute_scratch_size
,
2085 if (!compute_scratch_bo
)
2089 compute_scratch_bo
= queue
->compute_scratch_bo
;
2091 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2092 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2100 esgs_ring_bo
= queue
->esgs_ring_bo
;
2101 esgs_ring_size
= queue
->esgs_ring_size
;
2104 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2105 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2113 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2114 gsvs_ring_size
= queue
->gsvs_ring_size
;
2117 if (add_tess_rings
) {
2118 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2119 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2126 tess_rings_bo
= queue
->tess_rings_bo
;
2129 if (scratch_bo
!= queue
->scratch_bo
||
2130 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2131 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2132 tess_rings_bo
!= queue
->tess_rings_bo
||
2133 add_sample_positions
) {
2135 if (gsvs_ring_bo
|| esgs_ring_bo
||
2136 tess_rings_bo
|| add_sample_positions
) {
2137 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2138 if (add_sample_positions
)
2139 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2141 else if (scratch_bo
)
2142 size
= 8; /* 2 dword */
2144 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2148 RADEON_FLAG_CPU_ACCESS
|
2149 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2150 RADEON_FLAG_READ_ONLY
);
2154 descriptor_bo
= queue
->descriptor_bo
;
2156 for(int i
= 0; i
< 3; ++i
) {
2157 struct radeon_cmdbuf
*cs
= NULL
;
2158 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2159 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2166 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2168 if (descriptor_bo
!= queue
->descriptor_bo
) {
2169 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2172 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2173 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2174 S_008F04_SWIZZLE_ENABLE(1);
2175 map
[0] = scratch_va
;
2179 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2180 add_sample_positions
)
2181 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2182 esgs_ring_size
, esgs_ring_bo
,
2183 gsvs_ring_size
, gsvs_ring_bo
,
2184 tess_factor_ring_size
,
2185 tess_offchip_ring_offset
,
2186 tess_offchip_ring_size
,
2189 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2192 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2193 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2194 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2195 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2196 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2199 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2200 gsvs_ring_bo
, gsvs_ring_size
);
2201 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2202 tess_factor_ring_size
, tess_rings_bo
);
2203 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2204 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2207 si_cs_emit_cache_flush(cs
,
2208 queue
->device
->physical_device
->rad_info
.chip_class
,
2210 queue
->queue_family_index
== RING_COMPUTE
&&
2211 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2212 (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
)) |
2213 RADV_CMD_FLAG_INV_ICACHE
|
2214 RADV_CMD_FLAG_INV_SMEM_L1
|
2215 RADV_CMD_FLAG_INV_VMEM_L1
|
2216 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2217 } else if (i
== 1) {
2218 si_cs_emit_cache_flush(cs
,
2219 queue
->device
->physical_device
->rad_info
.chip_class
,
2221 queue
->queue_family_index
== RING_COMPUTE
&&
2222 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2223 RADV_CMD_FLAG_INV_ICACHE
|
2224 RADV_CMD_FLAG_INV_SMEM_L1
|
2225 RADV_CMD_FLAG_INV_VMEM_L1
|
2226 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2229 if (!queue
->device
->ws
->cs_finalize(cs
))
2233 if (queue
->initial_full_flush_preamble_cs
)
2234 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2236 if (queue
->initial_preamble_cs
)
2237 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2239 if (queue
->continue_preamble_cs
)
2240 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2242 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2243 queue
->initial_preamble_cs
= dest_cs
[1];
2244 queue
->continue_preamble_cs
= dest_cs
[2];
2246 if (scratch_bo
!= queue
->scratch_bo
) {
2247 if (queue
->scratch_bo
)
2248 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2249 queue
->scratch_bo
= scratch_bo
;
2250 queue
->scratch_size
= scratch_size
;
2253 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2254 if (queue
->compute_scratch_bo
)
2255 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2256 queue
->compute_scratch_bo
= compute_scratch_bo
;
2257 queue
->compute_scratch_size
= compute_scratch_size
;
2260 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2261 if (queue
->esgs_ring_bo
)
2262 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2263 queue
->esgs_ring_bo
= esgs_ring_bo
;
2264 queue
->esgs_ring_size
= esgs_ring_size
;
2267 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2268 if (queue
->gsvs_ring_bo
)
2269 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2270 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2271 queue
->gsvs_ring_size
= gsvs_ring_size
;
2274 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2275 queue
->tess_rings_bo
= tess_rings_bo
;
2276 queue
->has_tess_rings
= true;
2279 if (descriptor_bo
!= queue
->descriptor_bo
) {
2280 if (queue
->descriptor_bo
)
2281 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2283 queue
->descriptor_bo
= descriptor_bo
;
2286 if (add_sample_positions
)
2287 queue
->has_sample_positions
= true;
2289 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2290 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2291 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2292 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2293 *continue_preamble_cs
= NULL
;
2296 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2298 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2299 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2300 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2301 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2302 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2303 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2304 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2305 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2306 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2307 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2308 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2309 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2310 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2311 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2314 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2315 struct radv_winsys_sem_counts
*counts
,
2317 const VkSemaphore
*sems
,
2321 int syncobj_idx
= 0, sem_idx
= 0;
2323 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2326 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2327 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2329 if (sem
->temp_syncobj
|| sem
->syncobj
)
2330 counts
->syncobj_count
++;
2332 counts
->sem_count
++;
2335 if (_fence
!= VK_NULL_HANDLE
) {
2336 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2337 if (fence
->temp_syncobj
|| fence
->syncobj
)
2338 counts
->syncobj_count
++;
2341 if (counts
->syncobj_count
) {
2342 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2343 if (!counts
->syncobj
)
2344 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2347 if (counts
->sem_count
) {
2348 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2350 free(counts
->syncobj
);
2351 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2355 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2356 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2358 if (sem
->temp_syncobj
) {
2359 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2361 else if (sem
->syncobj
)
2362 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2365 counts
->sem
[sem_idx
++] = sem
->sem
;
2369 if (_fence
!= VK_NULL_HANDLE
) {
2370 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2371 if (fence
->temp_syncobj
)
2372 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2373 else if (fence
->syncobj
)
2374 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2381 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2383 free(sem_info
->wait
.syncobj
);
2384 free(sem_info
->wait
.sem
);
2385 free(sem_info
->signal
.syncobj
);
2386 free(sem_info
->signal
.sem
);
2390 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2392 const VkSemaphore
*sems
)
2394 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2395 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2397 if (sem
->temp_syncobj
) {
2398 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2399 sem
->temp_syncobj
= 0;
2405 radv_alloc_sem_info(struct radv_instance
*instance
,
2406 struct radv_winsys_sem_info
*sem_info
,
2408 const VkSemaphore
*wait_sems
,
2409 int num_signal_sems
,
2410 const VkSemaphore
*signal_sems
,
2414 memset(sem_info
, 0, sizeof(*sem_info
));
2416 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2419 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2421 radv_free_sem_info(sem_info
);
2423 /* caller can override these */
2424 sem_info
->cs_emit_wait
= true;
2425 sem_info
->cs_emit_signal
= true;
2429 /* Signals fence as soon as all the work currently put on queue is done. */
2430 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2431 struct radv_fence
*fence
)
2435 struct radv_winsys_sem_info sem_info
;
2437 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2438 radv_fence_to_handle(fence
));
2439 if (result
!= VK_SUCCESS
)
2442 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2443 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2444 1, NULL
, NULL
, &sem_info
, NULL
,
2445 false, fence
->fence
);
2446 radv_free_sem_info(&sem_info
);
2448 /* TODO: find a better error */
2450 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2455 VkResult
radv_QueueSubmit(
2457 uint32_t submitCount
,
2458 const VkSubmitInfo
* pSubmits
,
2461 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2462 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2463 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2464 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2466 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2467 uint32_t scratch_size
= 0;
2468 uint32_t compute_scratch_size
= 0;
2469 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2470 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2472 bool fence_emitted
= false;
2473 bool tess_rings_needed
= false;
2474 bool sample_positions_needed
= false;
2476 /* Do this first so failing to allocate scratch buffers can't result in
2477 * partially executed submissions. */
2478 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2479 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2480 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2481 pSubmits
[i
].pCommandBuffers
[j
]);
2483 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2484 compute_scratch_size
= MAX2(compute_scratch_size
,
2485 cmd_buffer
->compute_scratch_size_needed
);
2486 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2487 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2488 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2489 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2493 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2494 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2495 sample_positions_needed
, &initial_flush_preamble_cs
,
2496 &initial_preamble_cs
, &continue_preamble_cs
);
2497 if (result
!= VK_SUCCESS
)
2500 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2501 struct radeon_cmdbuf
**cs_array
;
2502 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2503 bool can_patch
= true;
2505 struct radv_winsys_sem_info sem_info
;
2507 result
= radv_alloc_sem_info(queue
->device
->instance
,
2509 pSubmits
[i
].waitSemaphoreCount
,
2510 pSubmits
[i
].pWaitSemaphores
,
2511 pSubmits
[i
].signalSemaphoreCount
,
2512 pSubmits
[i
].pSignalSemaphores
,
2514 if (result
!= VK_SUCCESS
)
2517 if (!pSubmits
[i
].commandBufferCount
) {
2518 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2519 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2520 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2525 radv_loge("failed to submit CS %d\n", i
);
2528 fence_emitted
= true;
2530 radv_free_sem_info(&sem_info
);
2534 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2535 (pSubmits
[i
].commandBufferCount
));
2537 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2538 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2539 pSubmits
[i
].pCommandBuffers
[j
]);
2540 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2542 cs_array
[j
] = cmd_buffer
->cs
;
2543 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2546 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2549 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2550 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2551 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2553 advance
= MIN2(max_cs_submission
,
2554 pSubmits
[i
].commandBufferCount
- j
);
2556 if (queue
->device
->trace_bo
)
2557 *queue
->device
->trace_id_ptr
= 0;
2559 sem_info
.cs_emit_wait
= j
== 0;
2560 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2562 if (unlikely(queue
->device
->use_global_bo_list
)) {
2563 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2564 bo_list
= &queue
->device
->bo_list
.list
;
2567 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2568 advance
, initial_preamble
, continue_preamble_cs
,
2570 can_patch
, base_fence
);
2572 if (unlikely(queue
->device
->use_global_bo_list
))
2573 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2576 radv_loge("failed to submit CS %d\n", i
);
2579 fence_emitted
= true;
2580 if (queue
->device
->trace_bo
) {
2581 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2585 radv_free_temp_syncobjs(queue
->device
,
2586 pSubmits
[i
].waitSemaphoreCount
,
2587 pSubmits
[i
].pWaitSemaphores
);
2588 radv_free_sem_info(&sem_info
);
2593 if (!fence_emitted
) {
2594 radv_signal_fence(queue
, fence
);
2596 fence
->submitted
= true;
2602 VkResult
radv_QueueWaitIdle(
2605 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2607 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2608 radv_queue_family_to_ring(queue
->queue_family_index
),
2613 VkResult
radv_DeviceWaitIdle(
2616 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2618 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2619 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2620 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2626 VkResult
radv_EnumerateInstanceExtensionProperties(
2627 const char* pLayerName
,
2628 uint32_t* pPropertyCount
,
2629 VkExtensionProperties
* pProperties
)
2631 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2633 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2634 if (radv_supported_instance_extensions
.extensions
[i
]) {
2635 vk_outarray_append(&out
, prop
) {
2636 *prop
= radv_instance_extensions
[i
];
2641 return vk_outarray_status(&out
);
2644 VkResult
radv_EnumerateDeviceExtensionProperties(
2645 VkPhysicalDevice physicalDevice
,
2646 const char* pLayerName
,
2647 uint32_t* pPropertyCount
,
2648 VkExtensionProperties
* pProperties
)
2650 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2651 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2653 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2654 if (device
->supported_extensions
.extensions
[i
]) {
2655 vk_outarray_append(&out
, prop
) {
2656 *prop
= radv_device_extensions
[i
];
2661 return vk_outarray_status(&out
);
2664 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2665 VkInstance _instance
,
2668 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2670 return radv_lookup_entrypoint_checked(pName
,
2671 instance
? instance
->apiVersion
: 0,
2672 instance
? &instance
->enabled_extensions
: NULL
,
2676 /* The loader wants us to expose a second GetInstanceProcAddr function
2677 * to work around certain LD_PRELOAD issues seen in apps.
2680 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2681 VkInstance instance
,
2685 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2686 VkInstance instance
,
2689 return radv_GetInstanceProcAddr(instance
, pName
);
2692 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2696 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2698 return radv_lookup_entrypoint_checked(pName
,
2699 device
->instance
->apiVersion
,
2700 &device
->instance
->enabled_extensions
,
2701 &device
->enabled_extensions
);
2704 bool radv_get_memory_fd(struct radv_device
*device
,
2705 struct radv_device_memory
*memory
,
2708 struct radeon_bo_metadata metadata
;
2710 if (memory
->image
) {
2711 radv_init_metadata(device
, memory
->image
, &metadata
);
2712 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2715 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2719 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2720 const VkMemoryAllocateInfo
* pAllocateInfo
,
2721 const VkAllocationCallbacks
* pAllocator
,
2722 VkDeviceMemory
* pMem
)
2724 struct radv_device_memory
*mem
;
2726 enum radeon_bo_domain domain
;
2728 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2730 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2732 if (pAllocateInfo
->allocationSize
== 0) {
2733 /* Apparently, this is allowed */
2734 *pMem
= VK_NULL_HANDLE
;
2738 const VkImportMemoryFdInfoKHR
*import_info
=
2739 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2740 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2741 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2742 const VkExportMemoryAllocateInfoKHR
*export_info
=
2743 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2744 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2745 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2747 const struct wsi_memory_allocate_info
*wsi_info
=
2748 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2750 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2751 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2753 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2755 if (wsi_info
&& wsi_info
->implicit_sync
)
2756 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2758 if (dedicate_info
) {
2759 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2760 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2766 mem
->user_ptr
= NULL
;
2769 assert(import_info
->handleType
==
2770 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2771 import_info
->handleType
==
2772 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2773 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2776 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2779 close(import_info
->fd
);
2781 } else if (host_ptr_info
) {
2782 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2783 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2784 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2785 pAllocateInfo
->allocationSize
);
2787 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2790 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2793 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2794 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2795 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2796 domain
= RADEON_DOMAIN_GTT
;
2798 domain
= RADEON_DOMAIN_VRAM
;
2800 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2801 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2803 flags
|= RADEON_FLAG_CPU_ACCESS
;
2805 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2806 flags
|= RADEON_FLAG_GTT_WC
;
2808 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2809 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2811 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2815 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2818 mem
->type_index
= mem_type_index
;
2821 result
= radv_bo_list_add(device
, mem
->bo
);
2822 if (result
!= VK_SUCCESS
)
2825 *pMem
= radv_device_memory_to_handle(mem
);
2830 device
->ws
->buffer_destroy(mem
->bo
);
2832 vk_free2(&device
->alloc
, pAllocator
, mem
);
2837 VkResult
radv_AllocateMemory(
2839 const VkMemoryAllocateInfo
* pAllocateInfo
,
2840 const VkAllocationCallbacks
* pAllocator
,
2841 VkDeviceMemory
* pMem
)
2843 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2844 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2847 void radv_FreeMemory(
2849 VkDeviceMemory _mem
,
2850 const VkAllocationCallbacks
* pAllocator
)
2852 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2853 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2858 radv_bo_list_remove(device
, mem
->bo
);
2859 device
->ws
->buffer_destroy(mem
->bo
);
2862 vk_free2(&device
->alloc
, pAllocator
, mem
);
2865 VkResult
radv_MapMemory(
2867 VkDeviceMemory _memory
,
2868 VkDeviceSize offset
,
2870 VkMemoryMapFlags flags
,
2873 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2874 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2882 *ppData
= mem
->user_ptr
;
2884 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2891 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
2894 void radv_UnmapMemory(
2896 VkDeviceMemory _memory
)
2898 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2899 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2904 if (mem
->user_ptr
== NULL
)
2905 device
->ws
->buffer_unmap(mem
->bo
);
2908 VkResult
radv_FlushMappedMemoryRanges(
2910 uint32_t memoryRangeCount
,
2911 const VkMappedMemoryRange
* pMemoryRanges
)
2916 VkResult
radv_InvalidateMappedMemoryRanges(
2918 uint32_t memoryRangeCount
,
2919 const VkMappedMemoryRange
* pMemoryRanges
)
2924 void radv_GetBufferMemoryRequirements(
2927 VkMemoryRequirements
* pMemoryRequirements
)
2929 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2930 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2932 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2934 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2935 pMemoryRequirements
->alignment
= 4096;
2937 pMemoryRequirements
->alignment
= 16;
2939 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2942 void radv_GetBufferMemoryRequirements2(
2944 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2945 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2947 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2948 &pMemoryRequirements
->memoryRequirements
);
2949 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2950 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2951 switch (ext
->sType
) {
2952 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2953 VkMemoryDedicatedRequirementsKHR
*req
=
2954 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2955 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2956 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2965 void radv_GetImageMemoryRequirements(
2968 VkMemoryRequirements
* pMemoryRequirements
)
2970 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2971 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2973 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2975 pMemoryRequirements
->size
= image
->size
;
2976 pMemoryRequirements
->alignment
= image
->alignment
;
2979 void radv_GetImageMemoryRequirements2(
2981 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2982 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2984 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2985 &pMemoryRequirements
->memoryRequirements
);
2987 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2989 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2990 switch (ext
->sType
) {
2991 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2992 VkMemoryDedicatedRequirementsKHR
*req
=
2993 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2994 req
->requiresDedicatedAllocation
= image
->shareable
;
2995 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3004 void radv_GetImageSparseMemoryRequirements(
3007 uint32_t* pSparseMemoryRequirementCount
,
3008 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3013 void radv_GetImageSparseMemoryRequirements2(
3015 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
3016 uint32_t* pSparseMemoryRequirementCount
,
3017 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
3022 void radv_GetDeviceMemoryCommitment(
3024 VkDeviceMemory memory
,
3025 VkDeviceSize
* pCommittedMemoryInBytes
)
3027 *pCommittedMemoryInBytes
= 0;
3030 VkResult
radv_BindBufferMemory2(VkDevice device
,
3031 uint32_t bindInfoCount
,
3032 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
3034 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3035 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3036 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3039 buffer
->bo
= mem
->bo
;
3040 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3048 VkResult
radv_BindBufferMemory(
3051 VkDeviceMemory memory
,
3052 VkDeviceSize memoryOffset
)
3054 const VkBindBufferMemoryInfoKHR info
= {
3055 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3058 .memoryOffset
= memoryOffset
3061 return radv_BindBufferMemory2(device
, 1, &info
);
3064 VkResult
radv_BindImageMemory2(VkDevice device
,
3065 uint32_t bindInfoCount
,
3066 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3068 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3069 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3070 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3073 image
->bo
= mem
->bo
;
3074 image
->offset
= pBindInfos
[i
].memoryOffset
;
3084 VkResult
radv_BindImageMemory(
3087 VkDeviceMemory memory
,
3088 VkDeviceSize memoryOffset
)
3090 const VkBindImageMemoryInfoKHR info
= {
3091 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3094 .memoryOffset
= memoryOffset
3097 return radv_BindImageMemory2(device
, 1, &info
);
3102 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3103 const VkSparseBufferMemoryBindInfo
*bind
)
3105 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3107 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3108 struct radv_device_memory
*mem
= NULL
;
3110 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3111 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3113 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3114 bind
->pBinds
[i
].resourceOffset
,
3115 bind
->pBinds
[i
].size
,
3116 mem
? mem
->bo
: NULL
,
3117 bind
->pBinds
[i
].memoryOffset
);
3122 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3123 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3125 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3127 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3128 struct radv_device_memory
*mem
= NULL
;
3130 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3131 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3133 device
->ws
->buffer_virtual_bind(image
->bo
,
3134 bind
->pBinds
[i
].resourceOffset
,
3135 bind
->pBinds
[i
].size
,
3136 mem
? mem
->bo
: NULL
,
3137 bind
->pBinds
[i
].memoryOffset
);
3141 VkResult
radv_QueueBindSparse(
3143 uint32_t bindInfoCount
,
3144 const VkBindSparseInfo
* pBindInfo
,
3147 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3148 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3149 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3150 bool fence_emitted
= false;
3152 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3153 struct radv_winsys_sem_info sem_info
;
3154 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3155 radv_sparse_buffer_bind_memory(queue
->device
,
3156 pBindInfo
[i
].pBufferBinds
+ j
);
3159 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3160 radv_sparse_image_opaque_bind_memory(queue
->device
,
3161 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3165 result
= radv_alloc_sem_info(queue
->device
->instance
,
3167 pBindInfo
[i
].waitSemaphoreCount
,
3168 pBindInfo
[i
].pWaitSemaphores
,
3169 pBindInfo
[i
].signalSemaphoreCount
,
3170 pBindInfo
[i
].pSignalSemaphores
,
3172 if (result
!= VK_SUCCESS
)
3175 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3176 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3177 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3181 fence_emitted
= true;
3183 fence
->submitted
= true;
3186 radv_free_sem_info(&sem_info
);
3191 if (!fence_emitted
) {
3192 radv_signal_fence(queue
, fence
);
3194 fence
->submitted
= true;
3200 VkResult
radv_CreateFence(
3202 const VkFenceCreateInfo
* pCreateInfo
,
3203 const VkAllocationCallbacks
* pAllocator
,
3206 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3207 const VkExportFenceCreateInfoKHR
*export
=
3208 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3209 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3210 export
? export
->handleTypes
: 0;
3212 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3214 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3217 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3219 fence
->submitted
= false;
3220 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3221 fence
->temp_syncobj
= 0;
3222 if (device
->always_use_syncobj
|| handleTypes
) {
3223 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3225 vk_free2(&device
->alloc
, pAllocator
, fence
);
3226 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3228 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3229 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3231 fence
->fence
= NULL
;
3233 fence
->fence
= device
->ws
->create_fence();
3234 if (!fence
->fence
) {
3235 vk_free2(&device
->alloc
, pAllocator
, fence
);
3236 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3241 *pFence
= radv_fence_to_handle(fence
);
3246 void radv_DestroyFence(
3249 const VkAllocationCallbacks
* pAllocator
)
3251 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3252 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3257 if (fence
->temp_syncobj
)
3258 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3260 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3262 device
->ws
->destroy_fence(fence
->fence
);
3263 vk_free2(&device
->alloc
, pAllocator
, fence
);
3267 static uint64_t radv_get_current_time()
3270 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3271 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3274 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3276 uint64_t current_time
= radv_get_current_time();
3278 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3280 return current_time
+ timeout
;
3284 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3286 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3287 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3288 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3294 VkResult
radv_WaitForFences(
3296 uint32_t fenceCount
,
3297 const VkFence
* pFences
,
3301 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3302 timeout
= radv_get_absolute_timeout(timeout
);
3304 if (device
->always_use_syncobj
) {
3305 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3307 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3309 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3310 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3311 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3314 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3317 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3320 if (!waitAll
&& fenceCount
> 1) {
3321 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3322 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3323 uint32_t wait_count
= 0;
3324 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3326 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3328 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3329 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3331 if (fence
->signalled
) {
3336 fences
[wait_count
++] = fence
->fence
;
3339 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3340 waitAll
, timeout
- radv_get_current_time());
3343 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3346 while(radv_get_current_time() <= timeout
) {
3347 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3348 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3355 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3356 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3357 bool expired
= false;
3359 if (fence
->temp_syncobj
) {
3360 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3365 if (fence
->syncobj
) {
3366 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3371 if (fence
->signalled
)
3374 if (!fence
->submitted
) {
3375 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3378 if (!fence
->submitted
)
3381 /* Recheck as it may have been set by submitting operations. */
3382 if (fence
->signalled
)
3386 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3390 fence
->signalled
= true;
3396 VkResult
radv_ResetFences(VkDevice _device
,
3397 uint32_t fenceCount
,
3398 const VkFence
*pFences
)
3400 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3402 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3403 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3404 fence
->submitted
= fence
->signalled
= false;
3406 /* Per spec, we first restore the permanent payload, and then reset, so
3407 * having a temp syncobj should not skip resetting the permanent syncobj. */
3408 if (fence
->temp_syncobj
) {
3409 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3410 fence
->temp_syncobj
= 0;
3413 if (fence
->syncobj
) {
3414 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3421 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3423 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3424 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3426 if (fence
->temp_syncobj
) {
3427 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3428 return success
? VK_SUCCESS
: VK_NOT_READY
;
3431 if (fence
->syncobj
) {
3432 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3433 return success
? VK_SUCCESS
: VK_NOT_READY
;
3436 if (fence
->signalled
)
3438 if (!fence
->submitted
)
3439 return VK_NOT_READY
;
3440 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3441 return VK_NOT_READY
;
3447 // Queue semaphore functions
3449 VkResult
radv_CreateSemaphore(
3451 const VkSemaphoreCreateInfo
* pCreateInfo
,
3452 const VkAllocationCallbacks
* pAllocator
,
3453 VkSemaphore
* pSemaphore
)
3455 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3456 const VkExportSemaphoreCreateInfoKHR
*export
=
3457 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3458 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3459 export
? export
->handleTypes
: 0;
3461 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3463 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3465 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3467 sem
->temp_syncobj
= 0;
3468 /* create a syncobject if we are going to export this semaphore */
3469 if (device
->always_use_syncobj
|| handleTypes
) {
3470 assert (device
->physical_device
->rad_info
.has_syncobj
);
3471 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3473 vk_free2(&device
->alloc
, pAllocator
, sem
);
3474 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3478 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3480 vk_free2(&device
->alloc
, pAllocator
, sem
);
3481 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3486 *pSemaphore
= radv_semaphore_to_handle(sem
);
3490 void radv_DestroySemaphore(
3492 VkSemaphore _semaphore
,
3493 const VkAllocationCallbacks
* pAllocator
)
3495 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3496 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3501 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3503 device
->ws
->destroy_sem(sem
->sem
);
3504 vk_free2(&device
->alloc
, pAllocator
, sem
);
3507 VkResult
radv_CreateEvent(
3509 const VkEventCreateInfo
* pCreateInfo
,
3510 const VkAllocationCallbacks
* pAllocator
,
3513 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3514 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3516 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3519 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3521 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3523 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3525 vk_free2(&device
->alloc
, pAllocator
, event
);
3526 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3529 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3531 *pEvent
= radv_event_to_handle(event
);
3536 void radv_DestroyEvent(
3539 const VkAllocationCallbacks
* pAllocator
)
3541 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3542 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3546 device
->ws
->buffer_destroy(event
->bo
);
3547 vk_free2(&device
->alloc
, pAllocator
, event
);
3550 VkResult
radv_GetEventStatus(
3554 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3556 if (*event
->map
== 1)
3557 return VK_EVENT_SET
;
3558 return VK_EVENT_RESET
;
3561 VkResult
radv_SetEvent(
3565 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3571 VkResult
radv_ResetEvent(
3575 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3581 VkResult
radv_CreateBuffer(
3583 const VkBufferCreateInfo
* pCreateInfo
,
3584 const VkAllocationCallbacks
* pAllocator
,
3587 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3588 struct radv_buffer
*buffer
;
3590 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3592 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3593 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3595 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3597 buffer
->size
= pCreateInfo
->size
;
3598 buffer
->usage
= pCreateInfo
->usage
;
3601 buffer
->flags
= pCreateInfo
->flags
;
3603 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3604 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3606 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3607 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3608 align64(buffer
->size
, 4096),
3609 4096, 0, RADEON_FLAG_VIRTUAL
);
3611 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3612 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3616 *pBuffer
= radv_buffer_to_handle(buffer
);
3621 void radv_DestroyBuffer(
3624 const VkAllocationCallbacks
* pAllocator
)
3626 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3627 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3632 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3633 device
->ws
->buffer_destroy(buffer
->bo
);
3635 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3638 static inline unsigned
3639 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3642 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3644 return image
->surface
.u
.legacy
.tiling_index
[level
];
3647 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3649 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3653 radv_init_dcc_control_reg(struct radv_device
*device
,
3654 struct radv_image_view
*iview
)
3656 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3657 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3658 unsigned max_compressed_block_size
;
3659 unsigned independent_64b_blocks
;
3661 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3664 if (iview
->image
->info
.samples
> 1) {
3665 if (iview
->image
->surface
.bpe
== 1)
3666 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3667 else if (iview
->image
->surface
.bpe
== 2)
3668 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3671 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3672 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3673 * dGPU and 64 for APU because all of our APUs to date use
3674 * DIMMs which have a request granularity size of 64B while all
3675 * other chips have a 32B request size.
3677 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3680 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3681 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3682 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3683 /* If this DCC image is potentially going to be used in texture
3684 * fetches, we need some special settings.
3686 independent_64b_blocks
= 1;
3687 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3689 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3690 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3691 * big as possible for better compression state.
3693 independent_64b_blocks
= 0;
3694 max_compressed_block_size
= max_uncompressed_block_size
;
3697 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3698 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3699 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3700 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3704 radv_initialise_color_surface(struct radv_device
*device
,
3705 struct radv_color_buffer_info
*cb
,
3706 struct radv_image_view
*iview
)
3708 const struct vk_format_description
*desc
;
3709 unsigned ntype
, format
, swap
, endian
;
3710 unsigned blend_clamp
= 0, blend_bypass
= 0;
3712 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3714 desc
= vk_format_description(iview
->vk_format
);
3716 memset(cb
, 0, sizeof(*cb
));
3718 /* Intensity is implemented as Red, so treat it that way. */
3719 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3721 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3723 cb
->cb_color_base
= va
>> 8;
3725 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3726 struct gfx9_surf_meta_flags meta
;
3727 if (iview
->image
->dcc_offset
)
3728 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3730 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3732 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3733 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3734 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3735 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3737 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3738 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3740 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3741 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3743 cb
->cb_color_base
+= level_info
->offset
>> 8;
3744 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3745 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3747 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3748 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3749 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3751 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3752 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3753 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3755 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3757 if (radv_image_has_fmask(iview
->image
)) {
3758 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3759 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3760 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3761 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3763 /* This must be set for fast clear to work without FMASK. */
3764 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3765 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3766 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3767 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3771 /* CMASK variables */
3772 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3773 va
+= iview
->image
->cmask
.offset
;
3774 cb
->cb_color_cmask
= va
>> 8;
3776 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3777 va
+= iview
->image
->dcc_offset
;
3778 cb
->cb_dcc_base
= va
>> 8;
3779 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3781 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3782 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3783 S_028C6C_SLICE_MAX(max_slice
);
3785 if (iview
->image
->info
.samples
> 1) {
3786 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3788 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3789 S_028C74_NUM_FRAGMENTS(log_samples
);
3792 if (radv_image_has_fmask(iview
->image
)) {
3793 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3794 cb
->cb_color_fmask
= va
>> 8;
3795 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3797 cb
->cb_color_fmask
= cb
->cb_color_base
;
3800 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3802 vk_format_get_first_non_void_channel(iview
->vk_format
));
3803 format
= radv_translate_colorformat(iview
->vk_format
);
3804 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3805 radv_finishme("Illegal color\n");
3806 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3807 endian
= radv_colorformat_endian_swap(format
);
3809 /* blend clamp should be set for all NORM/SRGB types */
3810 if (ntype
== V_028C70_NUMBER_UNORM
||
3811 ntype
== V_028C70_NUMBER_SNORM
||
3812 ntype
== V_028C70_NUMBER_SRGB
)
3815 /* set blend bypass according to docs if SINT/UINT or
3816 8/24 COLOR variants */
3817 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3818 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3819 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3824 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3825 (format
== V_028C70_COLOR_8
||
3826 format
== V_028C70_COLOR_8_8
||
3827 format
== V_028C70_COLOR_8_8_8_8
))
3828 ->color_is_int8
= true;
3830 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3831 S_028C70_COMP_SWAP(swap
) |
3832 S_028C70_BLEND_CLAMP(blend_clamp
) |
3833 S_028C70_BLEND_BYPASS(blend_bypass
) |
3834 S_028C70_SIMPLE_FLOAT(1) |
3835 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3836 ntype
!= V_028C70_NUMBER_SNORM
&&
3837 ntype
!= V_028C70_NUMBER_SRGB
&&
3838 format
!= V_028C70_COLOR_8_24
&&
3839 format
!= V_028C70_COLOR_24_8
) |
3840 S_028C70_NUMBER_TYPE(ntype
) |
3841 S_028C70_ENDIAN(endian
);
3842 if (radv_image_has_fmask(iview
->image
)) {
3843 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3844 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3845 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3846 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3850 if (radv_image_has_cmask(iview
->image
) &&
3851 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3852 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3854 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3855 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3857 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3859 /* This must be set for fast clear to work without FMASK. */
3860 if (!radv_image_has_fmask(iview
->image
) &&
3861 device
->physical_device
->rad_info
.chip_class
== SI
) {
3862 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3863 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3866 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3867 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3868 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3870 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3871 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3872 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3873 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3874 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3875 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3880 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3881 struct radv_image_view
*iview
)
3883 unsigned max_zplanes
= 0;
3885 assert(radv_image_is_tc_compat_htile(iview
->image
));
3887 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3888 /* Default value for 32-bit depth surfaces. */
3891 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3892 iview
->image
->info
.samples
> 1)
3895 max_zplanes
= max_zplanes
+ 1;
3897 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3898 /* Do not enable Z plane compression for 16-bit depth
3899 * surfaces because isn't supported on GFX8. Only
3900 * 32-bit depth surfaces are supported by the hardware.
3901 * This allows to maintain shader compatibility and to
3902 * reduce the number of depth decompressions.
3906 if (iview
->image
->info
.samples
<= 1)
3908 else if (iview
->image
->info
.samples
<= 4)
3919 radv_initialise_ds_surface(struct radv_device
*device
,
3920 struct radv_ds_buffer_info
*ds
,
3921 struct radv_image_view
*iview
)
3923 unsigned level
= iview
->base_mip
;
3924 unsigned format
, stencil_format
;
3925 uint64_t va
, s_offs
, z_offs
;
3926 bool stencil_only
= false;
3927 memset(ds
, 0, sizeof(*ds
));
3928 switch (iview
->image
->vk_format
) {
3929 case VK_FORMAT_D24_UNORM_S8_UINT
:
3930 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3931 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3932 ds
->offset_scale
= 2.0f
;
3934 case VK_FORMAT_D16_UNORM
:
3935 case VK_FORMAT_D16_UNORM_S8_UINT
:
3936 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3937 ds
->offset_scale
= 4.0f
;
3939 case VK_FORMAT_D32_SFLOAT
:
3940 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3941 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3942 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3943 ds
->offset_scale
= 1.0f
;
3945 case VK_FORMAT_S8_UINT
:
3946 stencil_only
= true;
3952 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3953 stencil_format
= iview
->image
->surface
.has_stencil
?
3954 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3956 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3957 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3958 S_028008_SLICE_MAX(max_slice
);
3960 ds
->db_htile_data_base
= 0;
3961 ds
->db_htile_surface
= 0;
3963 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3964 s_offs
= z_offs
= va
;
3966 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3967 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3968 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3970 ds
->db_z_info
= S_028038_FORMAT(format
) |
3971 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3972 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3973 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
3974 S_028038_ZRANGE_PRECISION(1);
3975 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3976 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3978 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3979 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3980 ds
->db_depth_view
|= S_028008_MIPID(level
);
3982 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3983 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3985 if (radv_htile_enabled(iview
->image
, level
)) {
3986 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3988 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3989 unsigned max_zplanes
=
3990 radv_calc_decompress_on_z_planes(device
, iview
);
3992 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3993 S_028038_ITERATE_FLUSH(1);
3994 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3997 if (!iview
->image
->surface
.has_stencil
)
3998 /* Use all of the htile_buffer for depth if there's no stencil. */
3999 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4000 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4001 iview
->image
->htile_offset
;
4002 ds
->db_htile_data_base
= va
>> 8;
4003 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4004 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4005 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4008 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4011 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4013 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4014 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4016 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4017 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4018 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4020 if (iview
->image
->info
.samples
> 1)
4021 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4023 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4024 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4025 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4026 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4027 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4028 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4029 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4030 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4033 tile_mode
= stencil_tile_mode
;
4035 ds
->db_depth_info
|=
4036 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4037 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4038 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4039 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4040 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4041 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4042 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4043 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4045 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4046 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4047 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4048 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4050 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4053 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4054 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4055 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4057 if (radv_htile_enabled(iview
->image
, level
)) {
4058 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4060 if (!iview
->image
->surface
.has_stencil
&&
4061 !radv_image_is_tc_compat_htile(iview
->image
))
4062 /* Use all of the htile_buffer for depth if there's no stencil. */
4063 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4065 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4066 iview
->image
->htile_offset
;
4067 ds
->db_htile_data_base
= va
>> 8;
4068 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4070 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4071 unsigned max_zplanes
=
4072 radv_calc_decompress_on_z_planes(device
, iview
);
4074 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4075 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4080 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4081 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4084 VkResult
radv_CreateFramebuffer(
4086 const VkFramebufferCreateInfo
* pCreateInfo
,
4087 const VkAllocationCallbacks
* pAllocator
,
4088 VkFramebuffer
* pFramebuffer
)
4090 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4091 struct radv_framebuffer
*framebuffer
;
4093 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4095 size_t size
= sizeof(*framebuffer
) +
4096 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4097 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4098 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4099 if (framebuffer
== NULL
)
4100 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4102 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4103 framebuffer
->width
= pCreateInfo
->width
;
4104 framebuffer
->height
= pCreateInfo
->height
;
4105 framebuffer
->layers
= pCreateInfo
->layers
;
4106 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4107 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4108 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4109 framebuffer
->attachments
[i
].attachment
= iview
;
4110 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4111 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4112 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4113 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4115 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4116 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4117 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4120 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4124 void radv_DestroyFramebuffer(
4127 const VkAllocationCallbacks
* pAllocator
)
4129 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4130 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4134 vk_free2(&device
->alloc
, pAllocator
, fb
);
4137 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4139 switch (address_mode
) {
4140 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4141 return V_008F30_SQ_TEX_WRAP
;
4142 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4143 return V_008F30_SQ_TEX_MIRROR
;
4144 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4145 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4146 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4147 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4148 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4149 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4151 unreachable("illegal tex wrap mode");
4157 radv_tex_compare(VkCompareOp op
)
4160 case VK_COMPARE_OP_NEVER
:
4161 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4162 case VK_COMPARE_OP_LESS
:
4163 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4164 case VK_COMPARE_OP_EQUAL
:
4165 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4166 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4167 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4168 case VK_COMPARE_OP_GREATER
:
4169 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4170 case VK_COMPARE_OP_NOT_EQUAL
:
4171 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4172 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4173 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4174 case VK_COMPARE_OP_ALWAYS
:
4175 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4177 unreachable("illegal compare mode");
4183 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4186 case VK_FILTER_NEAREST
:
4187 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4188 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4189 case VK_FILTER_LINEAR
:
4190 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4191 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4192 case VK_FILTER_CUBIC_IMG
:
4194 fprintf(stderr
, "illegal texture filter");
4200 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4203 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4204 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4205 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4206 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4208 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4213 radv_tex_bordercolor(VkBorderColor bcolor
)
4216 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4217 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4218 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4219 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4220 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4221 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4222 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4223 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4224 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4232 radv_tex_aniso_filter(unsigned filter
)
4246 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4249 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4250 return SQ_IMG_FILTER_MODE_BLEND
;
4251 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4252 return SQ_IMG_FILTER_MODE_MIN
;
4253 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4254 return SQ_IMG_FILTER_MODE_MAX
;
4262 radv_init_sampler(struct radv_device
*device
,
4263 struct radv_sampler
*sampler
,
4264 const VkSamplerCreateInfo
*pCreateInfo
)
4266 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4267 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4268 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4269 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4270 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4272 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4273 vk_find_struct_const(pCreateInfo
->pNext
,
4274 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4275 if (sampler_reduction
)
4276 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4278 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4279 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4280 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4281 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4282 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4283 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4284 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4285 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4286 S_008F30_DISABLE_CUBE_WRAP(0) |
4287 S_008F30_COMPAT_MODE(is_vi
) |
4288 S_008F30_FILTER_MODE(filter_mode
));
4289 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4290 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4291 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4292 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4293 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4294 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4295 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4296 S_008F38_MIP_POINT_PRECLAMP(0) |
4297 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4298 S_008F38_FILTER_PREC_FIX(1) |
4299 S_008F38_ANISO_OVERRIDE(is_vi
));
4300 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4301 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4304 VkResult
radv_CreateSampler(
4306 const VkSamplerCreateInfo
* pCreateInfo
,
4307 const VkAllocationCallbacks
* pAllocator
,
4308 VkSampler
* pSampler
)
4310 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4311 struct radv_sampler
*sampler
;
4313 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4315 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4316 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4318 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4320 radv_init_sampler(device
, sampler
, pCreateInfo
);
4321 *pSampler
= radv_sampler_to_handle(sampler
);
4326 void radv_DestroySampler(
4329 const VkAllocationCallbacks
* pAllocator
)
4331 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4332 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4336 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4339 /* vk_icd.h does not declare this function, so we declare it here to
4340 * suppress Wmissing-prototypes.
4342 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4343 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4345 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4346 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4348 /* For the full details on loader interface versioning, see
4349 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4350 * What follows is a condensed summary, to help you navigate the large and
4351 * confusing official doc.
4353 * - Loader interface v0 is incompatible with later versions. We don't
4356 * - In loader interface v1:
4357 * - The first ICD entrypoint called by the loader is
4358 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4360 * - The ICD must statically expose no other Vulkan symbol unless it is
4361 * linked with -Bsymbolic.
4362 * - Each dispatchable Vulkan handle created by the ICD must be
4363 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4364 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4365 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4366 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4367 * such loader-managed surfaces.
4369 * - Loader interface v2 differs from v1 in:
4370 * - The first ICD entrypoint called by the loader is
4371 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4372 * statically expose this entrypoint.
4374 * - Loader interface v3 differs from v2 in:
4375 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4376 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4377 * because the loader no longer does so.
4379 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4383 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4384 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4387 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4388 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4390 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4392 /* At the moment, we support only the below handle types. */
4393 assert(pGetFdInfo
->handleType
==
4394 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4395 pGetFdInfo
->handleType
==
4396 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4398 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4400 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4404 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4405 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4407 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4409 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4411 switch (handleType
) {
4412 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4413 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4417 /* The valid usage section for this function says:
4419 * "handleType must not be one of the handle types defined as
4422 * So opaque handle types fall into the default "unsupported" case.
4424 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4428 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4432 uint32_t syncobj_handle
= 0;
4433 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4435 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4438 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4440 *syncobj
= syncobj_handle
;
4446 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4450 /* If we create a syncobj we do it locally so that if we have an error, we don't
4451 * leave a syncobj in an undetermined state in the fence. */
4452 uint32_t syncobj_handle
= *syncobj
;
4453 if (!syncobj_handle
) {
4454 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4456 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4461 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4463 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4465 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4468 *syncobj
= syncobj_handle
;
4475 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4476 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4478 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4479 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4480 uint32_t *syncobj_dst
= NULL
;
4482 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4483 syncobj_dst
= &sem
->temp_syncobj
;
4485 syncobj_dst
= &sem
->syncobj
;
4488 switch(pImportSemaphoreFdInfo
->handleType
) {
4489 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4490 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4491 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4492 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4494 unreachable("Unhandled semaphore handle type");
4498 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4499 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4502 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4503 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4505 uint32_t syncobj_handle
;
4507 if (sem
->temp_syncobj
)
4508 syncobj_handle
= sem
->temp_syncobj
;
4510 syncobj_handle
= sem
->syncobj
;
4512 switch(pGetFdInfo
->handleType
) {
4513 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4514 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4516 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4517 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4519 if (sem
->temp_syncobj
) {
4520 close (sem
->temp_syncobj
);
4521 sem
->temp_syncobj
= 0;
4523 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4528 unreachable("Unhandled semaphore handle type");
4532 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4536 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4537 VkPhysicalDevice physicalDevice
,
4538 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4539 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4541 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4543 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4544 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4545 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4546 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4547 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4548 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4549 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4550 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4551 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4552 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4553 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4554 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4555 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4557 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4558 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4559 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4563 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4564 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4566 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4567 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4568 uint32_t *syncobj_dst
= NULL
;
4571 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4572 syncobj_dst
= &fence
->temp_syncobj
;
4574 syncobj_dst
= &fence
->syncobj
;
4577 switch(pImportFenceFdInfo
->handleType
) {
4578 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4579 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4580 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4581 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4583 unreachable("Unhandled fence handle type");
4587 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4588 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4591 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4592 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4594 uint32_t syncobj_handle
;
4596 if (fence
->temp_syncobj
)
4597 syncobj_handle
= fence
->temp_syncobj
;
4599 syncobj_handle
= fence
->syncobj
;
4601 switch(pGetFdInfo
->handleType
) {
4602 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4603 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4605 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4606 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4608 if (fence
->temp_syncobj
) {
4609 close (fence
->temp_syncobj
);
4610 fence
->temp_syncobj
= 0;
4612 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4617 unreachable("Unhandled fence handle type");
4621 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4625 void radv_GetPhysicalDeviceExternalFenceProperties(
4626 VkPhysicalDevice physicalDevice
,
4627 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4628 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4630 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4632 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4633 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4634 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4635 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4636 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4637 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4638 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4640 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4641 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4642 pExternalFenceProperties
->externalFenceFeatures
= 0;
4647 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4648 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4649 const VkAllocationCallbacks
* pAllocator
,
4650 VkDebugReportCallbackEXT
* pCallback
)
4652 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4653 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4654 pCreateInfo
, pAllocator
, &instance
->alloc
,
4659 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4660 VkDebugReportCallbackEXT _callback
,
4661 const VkAllocationCallbacks
* pAllocator
)
4663 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4664 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4665 _callback
, pAllocator
, &instance
->alloc
);
4669 radv_DebugReportMessageEXT(VkInstance _instance
,
4670 VkDebugReportFlagsEXT flags
,
4671 VkDebugReportObjectTypeEXT objectType
,
4674 int32_t messageCode
,
4675 const char* pLayerPrefix
,
4676 const char* pMessage
)
4678 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4679 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4680 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4684 radv_GetDeviceGroupPeerMemoryFeatures(
4687 uint32_t localDeviceIndex
,
4688 uint32_t remoteDeviceIndex
,
4689 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4691 assert(localDeviceIndex
== remoteDeviceIndex
);
4693 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4694 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4695 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4696 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;