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 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
233 version
= drmGetVersion(fd
);
236 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
237 "failed to get version %s: %m", path
);
240 if (strcmp(version
->name
, "amdgpu")) {
241 drmFreeVersion(version
);
243 return VK_ERROR_INCOMPATIBLE_DRIVER
;
245 drmFreeVersion(version
);
247 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
248 device
->instance
= instance
;
249 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
250 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
252 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
253 instance
->perftest_flags
);
255 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
259 device
->local_fd
= fd
;
260 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
262 radv_handle_env_var_force_family(device
);
264 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
266 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
267 device
->ws
->destroy(device
->ws
);
268 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
269 "cannot generate UUID");
273 /* These flags affect shader compilation. */
274 uint64_t shader_env_flags
=
275 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
276 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
278 /* The gpu id is already embedded in the uuid so we just pass "radv"
279 * when creating the cache.
281 char buf
[VK_UUID_SIZE
* 2 + 1];
282 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
283 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
285 if (device
->rad_info
.chip_class
< VI
||
286 device
->rad_info
.chip_class
> GFX9
)
287 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
289 radv_get_driver_uuid(&device
->device_uuid
);
290 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
292 if (device
->rad_info
.family
== CHIP_STONEY
||
293 device
->rad_info
.chip_class
>= GFX9
) {
294 device
->has_rbplus
= true;
295 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
296 device
->rad_info
.family
== CHIP_VEGA12
||
297 device
->rad_info
.family
== CHIP_RAVEN
;
300 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
303 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
305 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
307 /* Vega10/Raven need a special workaround for a hardware bug. */
308 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
309 device
->rad_info
.family
== CHIP_RAVEN
;
311 /* Out-of-order primitive rasterization. */
312 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
313 device
->rad_info
.max_se
>= 2;
314 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
315 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
317 device
->dcc_msaa_allowed
= device
->rad_info
.chip_class
== VI
&&
318 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
320 radv_physical_device_init_mem_types(device
);
321 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
323 result
= radv_init_wsi(device
);
324 if (result
!= VK_SUCCESS
) {
325 device
->ws
->destroy(device
->ws
);
329 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
330 ac_print_gpu_info(&device
->rad_info
);
340 radv_physical_device_finish(struct radv_physical_device
*device
)
342 radv_finish_wsi(device
);
343 device
->ws
->destroy(device
->ws
);
344 disk_cache_destroy(device
->disk_cache
);
345 close(device
->local_fd
);
349 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
350 VkSystemAllocationScope allocationScope
)
356 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
357 size_t align
, VkSystemAllocationScope allocationScope
)
359 return realloc(pOriginal
, size
);
363 default_free_func(void *pUserData
, void *pMemory
)
368 static const VkAllocationCallbacks default_alloc
= {
370 .pfnAllocation
= default_alloc_func
,
371 .pfnReallocation
= default_realloc_func
,
372 .pfnFree
= default_free_func
,
375 static const struct debug_control radv_debug_options
[] = {
376 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
377 {"nodcc", RADV_DEBUG_NO_DCC
},
378 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
379 {"nocache", RADV_DEBUG_NO_CACHE
},
380 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
381 {"nohiz", RADV_DEBUG_NO_HIZ
},
382 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
383 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
384 {"allbos", RADV_DEBUG_ALL_BOS
},
385 {"noibs", RADV_DEBUG_NO_IBS
},
386 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
387 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
388 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
389 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
390 {"nosisched", RADV_DEBUG_NO_SISCHED
},
391 {"preoptir", RADV_DEBUG_PREOPTIR
},
392 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
393 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
394 {"info", RADV_DEBUG_INFO
},
399 radv_get_debug_option_name(int id
)
401 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
402 return radv_debug_options
[id
].string
;
405 static const struct debug_control radv_perftest_options
[] = {
406 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
407 {"sisched", RADV_PERFTEST_SISCHED
},
408 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
409 {"binning", RADV_PERFTEST_BINNING
},
410 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
415 radv_get_perftest_option_name(int id
)
417 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
418 return radv_perftest_options
[id
].string
;
422 radv_handle_per_app_options(struct radv_instance
*instance
,
423 const VkApplicationInfo
*info
)
425 const char *name
= info
? info
->pApplicationName
: NULL
;
430 if (!strcmp(name
, "Talos - Linux - 32bit") ||
431 !strcmp(name
, "Talos - Linux - 64bit")) {
432 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
433 /* Force enable LLVM sisched for Talos because it looks
434 * safe and it gives few more FPS.
436 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
441 static int radv_get_instance_extension_index(const char *name
)
443 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
444 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
451 VkResult
radv_CreateInstance(
452 const VkInstanceCreateInfo
* pCreateInfo
,
453 const VkAllocationCallbacks
* pAllocator
,
454 VkInstance
* pInstance
)
456 struct radv_instance
*instance
;
459 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
461 uint32_t client_version
;
462 if (pCreateInfo
->pApplicationInfo
&&
463 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
464 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
466 radv_EnumerateInstanceVersion(&client_version
);
469 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
470 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
472 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
474 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
477 instance
->alloc
= *pAllocator
;
479 instance
->alloc
= default_alloc
;
481 instance
->apiVersion
= client_version
;
482 instance
->physicalDeviceCount
= -1;
484 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
485 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
486 int index
= radv_get_instance_extension_index(ext_name
);
488 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
489 vk_free2(&default_alloc
, pAllocator
, instance
);
490 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
493 instance
->enabled_extensions
.extensions
[index
] = true;
496 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
497 if (result
!= VK_SUCCESS
) {
498 vk_free2(&default_alloc
, pAllocator
, instance
);
499 return vk_error(result
);
504 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
506 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
509 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
510 radv_perftest_options
);
512 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
514 *pInstance
= radv_instance_to_handle(instance
);
519 void radv_DestroyInstance(
520 VkInstance _instance
,
521 const VkAllocationCallbacks
* pAllocator
)
523 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
528 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
529 radv_physical_device_finish(instance
->physicalDevices
+ i
);
532 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
536 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
538 vk_free(&instance
->alloc
, instance
);
542 radv_enumerate_devices(struct radv_instance
*instance
)
544 /* TODO: Check for more devices ? */
545 drmDevicePtr devices
[8];
546 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
549 instance
->physicalDeviceCount
= 0;
551 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
553 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
555 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
556 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
557 devices
[i
]->bustype
== DRM_BUS_PCI
&&
558 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
560 result
= radv_physical_device_init(instance
->physicalDevices
+
561 instance
->physicalDeviceCount
,
564 if (result
== VK_SUCCESS
)
565 ++instance
->physicalDeviceCount
;
566 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
570 drmFreeDevices(devices
, max_devices
);
575 VkResult
radv_EnumeratePhysicalDevices(
576 VkInstance _instance
,
577 uint32_t* pPhysicalDeviceCount
,
578 VkPhysicalDevice
* pPhysicalDevices
)
580 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
583 if (instance
->physicalDeviceCount
< 0) {
584 result
= radv_enumerate_devices(instance
);
585 if (result
!= VK_SUCCESS
&&
586 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
590 if (!pPhysicalDevices
) {
591 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
593 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
594 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
595 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
598 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
602 VkResult
radv_EnumeratePhysicalDeviceGroups(
603 VkInstance _instance
,
604 uint32_t* pPhysicalDeviceGroupCount
,
605 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
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 (!pPhysicalDeviceGroupProperties
) {
618 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
620 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
621 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
622 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
623 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
624 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
627 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
631 void radv_GetPhysicalDeviceFeatures(
632 VkPhysicalDevice physicalDevice
,
633 VkPhysicalDeviceFeatures
* pFeatures
)
635 memset(pFeatures
, 0, sizeof(*pFeatures
));
637 *pFeatures
= (VkPhysicalDeviceFeatures
) {
638 .robustBufferAccess
= true,
639 .fullDrawIndexUint32
= true,
640 .imageCubeArray
= true,
641 .independentBlend
= true,
642 .geometryShader
= true,
643 .tessellationShader
= true,
644 .sampleRateShading
= true,
645 .dualSrcBlend
= true,
647 .multiDrawIndirect
= true,
648 .drawIndirectFirstInstance
= true,
650 .depthBiasClamp
= true,
651 .fillModeNonSolid
= true,
656 .multiViewport
= true,
657 .samplerAnisotropy
= true,
658 .textureCompressionETC2
= false,
659 .textureCompressionASTC_LDR
= false,
660 .textureCompressionBC
= true,
661 .occlusionQueryPrecise
= true,
662 .pipelineStatisticsQuery
= true,
663 .vertexPipelineStoresAndAtomics
= true,
664 .fragmentStoresAndAtomics
= true,
665 .shaderTessellationAndGeometryPointSize
= true,
666 .shaderImageGatherExtended
= true,
667 .shaderStorageImageExtendedFormats
= true,
668 .shaderStorageImageMultisample
= false,
669 .shaderUniformBufferArrayDynamicIndexing
= true,
670 .shaderSampledImageArrayDynamicIndexing
= true,
671 .shaderStorageBufferArrayDynamicIndexing
= true,
672 .shaderStorageImageArrayDynamicIndexing
= true,
673 .shaderStorageImageReadWithoutFormat
= true,
674 .shaderStorageImageWriteWithoutFormat
= true,
675 .shaderClipDistance
= true,
676 .shaderCullDistance
= true,
677 .shaderFloat64
= true,
679 .shaderInt16
= false,
680 .sparseBinding
= true,
681 .variableMultisampleRate
= true,
682 .inheritedQueries
= true,
686 void radv_GetPhysicalDeviceFeatures2(
687 VkPhysicalDevice physicalDevice
,
688 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
690 vk_foreach_struct(ext
, pFeatures
->pNext
) {
691 switch (ext
->sType
) {
692 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
693 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
694 features
->variablePointersStorageBuffer
= true;
695 features
->variablePointers
= false;
698 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
699 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
700 features
->multiview
= true;
701 features
->multiviewGeometryShader
= true;
702 features
->multiviewTessellationShader
= true;
705 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
706 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
707 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
708 features
->shaderDrawParameters
= true;
711 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
712 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
713 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
714 features
->protectedMemory
= false;
717 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
718 VkPhysicalDevice16BitStorageFeatures
*features
=
719 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
720 features
->storageBuffer16BitAccess
= false;
721 features
->uniformAndStorageBuffer16BitAccess
= false;
722 features
->storagePushConstant16
= false;
723 features
->storageInputOutput16
= false;
726 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
727 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
728 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
729 features
->samplerYcbcrConversion
= false;
732 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
733 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
734 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
735 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
736 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
737 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
738 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
739 features
->shaderSampledImageArrayNonUniformIndexing
= false;
740 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
741 features
->shaderStorageImageArrayNonUniformIndexing
= false;
742 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
743 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
744 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
745 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
746 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
747 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
748 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
749 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
750 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
751 features
->descriptorBindingUpdateUnusedWhilePending
= true;
752 features
->descriptorBindingPartiallyBound
= true;
753 features
->descriptorBindingVariableDescriptorCount
= true;
754 features
->runtimeDescriptorArray
= true;
761 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
764 void radv_GetPhysicalDeviceProperties(
765 VkPhysicalDevice physicalDevice
,
766 VkPhysicalDeviceProperties
* pProperties
)
768 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
769 VkSampleCountFlags sample_counts
= 0xf;
771 /* make sure that the entire descriptor set is addressable with a signed
772 * 32-bit int. So the sum of all limits scaled by descriptor size has to
773 * be at most 2 GiB. the combined image & samples object count as one of
774 * both. This limit is for the pipeline layout, not for the set layout, but
775 * there is no set limit, so we just set a pipeline limit. I don't think
776 * any app is going to hit this soon. */
777 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
778 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
779 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
780 32 /* sampler, largest when combined with image */ +
781 64 /* sampled image */ +
782 64 /* storage image */);
784 VkPhysicalDeviceLimits limits
= {
785 .maxImageDimension1D
= (1 << 14),
786 .maxImageDimension2D
= (1 << 14),
787 .maxImageDimension3D
= (1 << 11),
788 .maxImageDimensionCube
= (1 << 14),
789 .maxImageArrayLayers
= (1 << 11),
790 .maxTexelBufferElements
= 128 * 1024 * 1024,
791 .maxUniformBufferRange
= UINT32_MAX
,
792 .maxStorageBufferRange
= UINT32_MAX
,
793 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
794 .maxMemoryAllocationCount
= UINT32_MAX
,
795 .maxSamplerAllocationCount
= 64 * 1024,
796 .bufferImageGranularity
= 64, /* A cache line */
797 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
798 .maxBoundDescriptorSets
= MAX_SETS
,
799 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
800 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
801 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
802 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
803 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
804 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
805 .maxPerStageResources
= max_descriptor_set_size
,
806 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
807 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
808 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
809 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
810 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
811 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
812 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
813 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
814 .maxVertexInputAttributes
= 32,
815 .maxVertexInputBindings
= 32,
816 .maxVertexInputAttributeOffset
= 2047,
817 .maxVertexInputBindingStride
= 2048,
818 .maxVertexOutputComponents
= 128,
819 .maxTessellationGenerationLevel
= 64,
820 .maxTessellationPatchSize
= 32,
821 .maxTessellationControlPerVertexInputComponents
= 128,
822 .maxTessellationControlPerVertexOutputComponents
= 128,
823 .maxTessellationControlPerPatchOutputComponents
= 120,
824 .maxTessellationControlTotalOutputComponents
= 4096,
825 .maxTessellationEvaluationInputComponents
= 128,
826 .maxTessellationEvaluationOutputComponents
= 128,
827 .maxGeometryShaderInvocations
= 127,
828 .maxGeometryInputComponents
= 64,
829 .maxGeometryOutputComponents
= 128,
830 .maxGeometryOutputVertices
= 256,
831 .maxGeometryTotalOutputComponents
= 1024,
832 .maxFragmentInputComponents
= 128,
833 .maxFragmentOutputAttachments
= 8,
834 .maxFragmentDualSrcAttachments
= 1,
835 .maxFragmentCombinedOutputResources
= 8,
836 .maxComputeSharedMemorySize
= 32768,
837 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
838 .maxComputeWorkGroupInvocations
= 2048,
839 .maxComputeWorkGroupSize
= {
844 .subPixelPrecisionBits
= 4 /* FIXME */,
845 .subTexelPrecisionBits
= 4 /* FIXME */,
846 .mipmapPrecisionBits
= 4 /* FIXME */,
847 .maxDrawIndexedIndexValue
= UINT32_MAX
,
848 .maxDrawIndirectCount
= UINT32_MAX
,
849 .maxSamplerLodBias
= 16,
850 .maxSamplerAnisotropy
= 16,
851 .maxViewports
= MAX_VIEWPORTS
,
852 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
853 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
854 .viewportSubPixelBits
= 8,
855 .minMemoryMapAlignment
= 4096, /* A page */
856 .minTexelBufferOffsetAlignment
= 1,
857 .minUniformBufferOffsetAlignment
= 4,
858 .minStorageBufferOffsetAlignment
= 4,
859 .minTexelOffset
= -32,
860 .maxTexelOffset
= 31,
861 .minTexelGatherOffset
= -32,
862 .maxTexelGatherOffset
= 31,
863 .minInterpolationOffset
= -2,
864 .maxInterpolationOffset
= 2,
865 .subPixelInterpolationOffsetBits
= 8,
866 .maxFramebufferWidth
= (1 << 14),
867 .maxFramebufferHeight
= (1 << 14),
868 .maxFramebufferLayers
= (1 << 10),
869 .framebufferColorSampleCounts
= sample_counts
,
870 .framebufferDepthSampleCounts
= sample_counts
,
871 .framebufferStencilSampleCounts
= sample_counts
,
872 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
873 .maxColorAttachments
= MAX_RTS
,
874 .sampledImageColorSampleCounts
= sample_counts
,
875 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
876 .sampledImageDepthSampleCounts
= sample_counts
,
877 .sampledImageStencilSampleCounts
= sample_counts
,
878 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
879 .maxSampleMaskWords
= 1,
880 .timestampComputeAndGraphics
= true,
881 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
882 .maxClipDistances
= 8,
883 .maxCullDistances
= 8,
884 .maxCombinedClipAndCullDistances
= 8,
885 .discreteQueuePriorities
= 1,
886 .pointSizeRange
= { 0.125, 255.875 },
887 .lineWidthRange
= { 0.0, 7.9921875 },
888 .pointSizeGranularity
= (1.0 / 8.0),
889 .lineWidthGranularity
= (1.0 / 128.0),
890 .strictLines
= false, /* FINISHME */
891 .standardSampleLocations
= true,
892 .optimalBufferCopyOffsetAlignment
= 128,
893 .optimalBufferCopyRowPitchAlignment
= 128,
894 .nonCoherentAtomSize
= 64,
897 *pProperties
= (VkPhysicalDeviceProperties
) {
898 .apiVersion
= radv_physical_device_api_version(pdevice
),
899 .driverVersion
= vk_get_driver_version(),
900 .vendorID
= ATI_VENDOR_ID
,
901 .deviceID
= pdevice
->rad_info
.pci_id
,
902 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
904 .sparseProperties
= {0},
907 strcpy(pProperties
->deviceName
, pdevice
->name
);
908 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
911 void radv_GetPhysicalDeviceProperties2(
912 VkPhysicalDevice physicalDevice
,
913 VkPhysicalDeviceProperties2KHR
*pProperties
)
915 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
916 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
918 vk_foreach_struct(ext
, pProperties
->pNext
) {
919 switch (ext
->sType
) {
920 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
921 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
922 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
923 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
926 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
927 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
928 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
929 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
930 properties
->deviceLUIDValid
= false;
933 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
934 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
935 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
936 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
939 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
940 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
941 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
942 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
945 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
946 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
947 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
948 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
951 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
952 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
953 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
954 properties
->minImportedHostPointerAlignment
= 4096;
957 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
958 VkPhysicalDeviceSubgroupProperties
*properties
=
959 (VkPhysicalDeviceSubgroupProperties
*)ext
;
960 properties
->subgroupSize
= 64;
961 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
962 properties
->supportedOperations
=
963 VK_SUBGROUP_FEATURE_BASIC_BIT
|
964 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
965 VK_SUBGROUP_FEATURE_QUAD_BIT
|
966 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
967 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
968 VK_SUBGROUP_FEATURE_VOTE_BIT
;
969 properties
->quadOperationsInAllStages
= true;
972 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
973 VkPhysicalDeviceMaintenance3Properties
*properties
=
974 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
975 /* Make sure everything is addressable by a signed 32-bit int, and
976 * our largest descriptors are 96 bytes. */
977 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
978 /* Our buffer size fields allow only this much */
979 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
982 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
983 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
984 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
985 /* GFX6-8 only support single channel min/max filter. */
986 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
987 properties
->filterMinmaxSingleComponentFormats
= true;
990 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
991 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
992 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
994 /* Shader engines. */
995 properties
->shaderEngineCount
=
996 pdevice
->rad_info
.max_se
;
997 properties
->shaderArraysPerEngineCount
=
998 pdevice
->rad_info
.max_sh_per_se
;
999 properties
->computeUnitsPerShaderArray
=
1000 pdevice
->rad_info
.num_good_compute_units
/
1001 (pdevice
->rad_info
.max_se
*
1002 pdevice
->rad_info
.max_sh_per_se
);
1003 properties
->simdPerComputeUnit
= 4;
1004 properties
->wavefrontsPerSimd
=
1005 pdevice
->rad_info
.family
== CHIP_TONGA
||
1006 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1007 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1008 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1009 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1010 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1011 properties
->wavefrontSize
= 64;
1014 properties
->sgprsPerSimd
=
1015 radv_get_num_physical_sgprs(pdevice
);
1016 properties
->minSgprAllocation
=
1017 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1018 properties
->maxSgprAllocation
=
1019 pdevice
->rad_info
.family
== CHIP_TONGA
||
1020 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1021 properties
->sgprAllocationGranularity
=
1022 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1025 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1026 properties
->minVgprAllocation
= 4;
1027 properties
->maxVgprAllocation
= 256;
1028 properties
->vgprAllocationGranularity
= 4;
1031 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1032 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1033 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1034 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1037 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1038 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1039 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1040 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1041 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1042 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1043 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1044 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1045 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1046 properties
->robustBufferAccessUpdateAfterBind
= false;
1047 properties
->quadDivergentImplicitLod
= false;
1049 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1050 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1051 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1052 32 /* sampler, largest when combined with image */ +
1053 64 /* sampled image */ +
1054 64 /* storage image */);
1055 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1056 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1057 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1058 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1059 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1060 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1061 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1062 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1063 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1064 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1065 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1066 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1067 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1068 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1069 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1078 static void radv_get_physical_device_queue_family_properties(
1079 struct radv_physical_device
* pdevice
,
1081 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1083 int num_queue_families
= 1;
1085 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1086 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1087 num_queue_families
++;
1089 if (pQueueFamilyProperties
== NULL
) {
1090 *pCount
= num_queue_families
;
1099 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1100 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1101 VK_QUEUE_COMPUTE_BIT
|
1102 VK_QUEUE_TRANSFER_BIT
|
1103 VK_QUEUE_SPARSE_BINDING_BIT
,
1105 .timestampValidBits
= 64,
1106 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1111 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1112 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1113 if (*pCount
> idx
) {
1114 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1115 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1116 VK_QUEUE_TRANSFER_BIT
|
1117 VK_QUEUE_SPARSE_BINDING_BIT
,
1118 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1119 .timestampValidBits
= 64,
1120 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1128 void radv_GetPhysicalDeviceQueueFamilyProperties(
1129 VkPhysicalDevice physicalDevice
,
1131 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1133 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1134 if (!pQueueFamilyProperties
) {
1135 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1138 VkQueueFamilyProperties
*properties
[] = {
1139 pQueueFamilyProperties
+ 0,
1140 pQueueFamilyProperties
+ 1,
1141 pQueueFamilyProperties
+ 2,
1143 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1144 assert(*pCount
<= 3);
1147 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1148 VkPhysicalDevice physicalDevice
,
1150 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1152 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1153 if (!pQueueFamilyProperties
) {
1154 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1157 VkQueueFamilyProperties
*properties
[] = {
1158 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1159 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1160 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1162 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1163 assert(*pCount
<= 3);
1166 void radv_GetPhysicalDeviceMemoryProperties(
1167 VkPhysicalDevice physicalDevice
,
1168 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1170 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1172 *pMemoryProperties
= physical_device
->memory_properties
;
1175 void radv_GetPhysicalDeviceMemoryProperties2(
1176 VkPhysicalDevice physicalDevice
,
1177 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1179 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1180 &pMemoryProperties
->memoryProperties
);
1183 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1185 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1186 const void *pHostPointer
,
1187 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1189 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1193 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1194 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1195 uint32_t memoryTypeBits
= 0;
1196 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1197 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1198 memoryTypeBits
= (1 << i
);
1202 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1206 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1210 static enum radeon_ctx_priority
1211 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1213 /* Default to MEDIUM when a specific global priority isn't requested */
1215 return RADEON_CTX_PRIORITY_MEDIUM
;
1217 switch(pObj
->globalPriority
) {
1218 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1219 return RADEON_CTX_PRIORITY_REALTIME
;
1220 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1221 return RADEON_CTX_PRIORITY_HIGH
;
1222 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1223 return RADEON_CTX_PRIORITY_MEDIUM
;
1224 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1225 return RADEON_CTX_PRIORITY_LOW
;
1227 unreachable("Illegal global priority value");
1228 return RADEON_CTX_PRIORITY_INVALID
;
1233 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1234 uint32_t queue_family_index
, int idx
,
1235 VkDeviceQueueCreateFlags flags
,
1236 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1238 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1239 queue
->device
= device
;
1240 queue
->queue_family_index
= queue_family_index
;
1241 queue
->queue_idx
= idx
;
1242 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1243 queue
->flags
= flags
;
1245 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1247 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1253 radv_queue_finish(struct radv_queue
*queue
)
1256 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1258 if (queue
->initial_full_flush_preamble_cs
)
1259 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1260 if (queue
->initial_preamble_cs
)
1261 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1262 if (queue
->continue_preamble_cs
)
1263 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1264 if (queue
->descriptor_bo
)
1265 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1266 if (queue
->scratch_bo
)
1267 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1268 if (queue
->esgs_ring_bo
)
1269 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1270 if (queue
->gsvs_ring_bo
)
1271 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1272 if (queue
->tess_rings_bo
)
1273 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1274 if (queue
->compute_scratch_bo
)
1275 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1279 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1281 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1282 bo_list
->list
.count
= bo_list
->capacity
= 0;
1283 bo_list
->list
.bos
= NULL
;
1287 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1289 free(bo_list
->list
.bos
);
1290 pthread_mutex_destroy(&bo_list
->mutex
);
1293 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1294 struct radeon_winsys_bo
*bo
)
1296 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1298 if (unlikely(!device
->use_global_bo_list
))
1301 pthread_mutex_lock(&bo_list
->mutex
);
1302 if (bo_list
->list
.count
== bo_list
->capacity
) {
1303 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1304 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1307 pthread_mutex_unlock(&bo_list
->mutex
);
1308 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1311 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1312 bo_list
->capacity
= capacity
;
1315 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1316 pthread_mutex_unlock(&bo_list
->mutex
);
1320 static void radv_bo_list_remove(struct radv_device
*device
,
1321 struct radeon_winsys_bo
*bo
)
1323 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1325 if (unlikely(!device
->use_global_bo_list
))
1328 pthread_mutex_lock(&bo_list
->mutex
);
1329 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1330 if (bo_list
->list
.bos
[i
] == bo
) {
1331 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1332 --bo_list
->list
.count
;
1336 pthread_mutex_unlock(&bo_list
->mutex
);
1340 radv_device_init_gs_info(struct radv_device
*device
)
1342 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1343 device
->physical_device
->rad_info
.family
);
1346 static int radv_get_device_extension_index(const char *name
)
1348 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1349 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1355 VkResult
radv_CreateDevice(
1356 VkPhysicalDevice physicalDevice
,
1357 const VkDeviceCreateInfo
* pCreateInfo
,
1358 const VkAllocationCallbacks
* pAllocator
,
1361 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1363 struct radv_device
*device
;
1365 bool keep_shader_info
= false;
1367 /* Check enabled features */
1368 if (pCreateInfo
->pEnabledFeatures
) {
1369 VkPhysicalDeviceFeatures supported_features
;
1370 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1371 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1372 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1373 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1374 for (uint32_t i
= 0; i
< num_features
; i
++) {
1375 if (enabled_feature
[i
] && !supported_feature
[i
])
1376 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1380 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1382 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1384 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1386 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1387 device
->instance
= physical_device
->instance
;
1388 device
->physical_device
= physical_device
;
1390 device
->ws
= physical_device
->ws
;
1392 device
->alloc
= *pAllocator
;
1394 device
->alloc
= physical_device
->instance
->alloc
;
1396 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1397 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1398 int index
= radv_get_device_extension_index(ext_name
);
1399 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1400 vk_free(&device
->alloc
, device
);
1401 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1404 device
->enabled_extensions
.extensions
[index
] = true;
1407 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1409 /* With update after bind we can't attach bo's to the command buffer
1410 * from the descriptor set anymore, so we have to use a global BO list.
1412 device
->use_global_bo_list
=
1413 device
->enabled_extensions
.EXT_descriptor_indexing
;
1415 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1416 list_inithead(&device
->shader_slabs
);
1418 radv_bo_list_init(&device
->bo_list
);
1420 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1421 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1422 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1423 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1424 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1426 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1428 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1429 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1430 if (!device
->queues
[qfi
]) {
1431 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1435 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1437 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1439 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1440 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1441 qfi
, q
, queue_create
->flags
,
1443 if (result
!= VK_SUCCESS
)
1448 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1449 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1451 /* Disabled and not implemented for now. */
1452 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1455 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1458 /* The maximum number of scratch waves. Scratch space isn't divided
1459 * evenly between CUs. The number is only a function of the number of CUs.
1460 * We can decrease the constant to decrease the scratch buffer size.
1462 * sctx->scratch_waves must be >= the maximum possible size of
1463 * 1 threadgroup, so that the hw doesn't hang from being unable
1466 * The recommended value is 4 per CU at most. Higher numbers don't
1467 * bring much benefit, but they still occupy chip resources (think
1468 * async compute). I've seen ~2% performance difference between 4 and 32.
1470 uint32_t max_threads_per_block
= 2048;
1471 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1472 max_threads_per_block
/ 64);
1474 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1476 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1477 /* If the KMD allows it (there is a KMD hw register for it),
1478 * allow launching waves out-of-order.
1480 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1483 radv_device_init_gs_info(device
);
1485 device
->tess_offchip_block_dw_size
=
1486 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1487 device
->has_distributed_tess
=
1488 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1489 device
->physical_device
->rad_info
.max_se
>= 2;
1491 if (getenv("RADV_TRACE_FILE")) {
1492 const char *filename
= getenv("RADV_TRACE_FILE");
1494 keep_shader_info
= true;
1496 if (!radv_init_trace(device
))
1499 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1500 radv_dump_enabled_options(device
, stderr
);
1503 device
->keep_shader_info
= keep_shader_info
;
1505 result
= radv_device_init_meta(device
);
1506 if (result
!= VK_SUCCESS
)
1509 radv_device_init_msaa(device
);
1511 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1512 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1514 case RADV_QUEUE_GENERAL
:
1515 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1516 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1517 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1519 case RADV_QUEUE_COMPUTE
:
1520 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1521 radeon_emit(device
->empty_cs
[family
], 0);
1524 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1527 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1528 cik_create_gfx_config(device
);
1530 VkPipelineCacheCreateInfo ci
;
1531 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1534 ci
.pInitialData
= NULL
;
1535 ci
.initialDataSize
= 0;
1537 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1539 if (result
!= VK_SUCCESS
)
1542 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1544 *pDevice
= radv_device_to_handle(device
);
1548 radv_device_finish_meta(device
);
1550 radv_bo_list_finish(&device
->bo_list
);
1552 if (device
->trace_bo
)
1553 device
->ws
->buffer_destroy(device
->trace_bo
);
1555 if (device
->gfx_init
)
1556 device
->ws
->buffer_destroy(device
->gfx_init
);
1558 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1559 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1560 radv_queue_finish(&device
->queues
[i
][q
]);
1561 if (device
->queue_count
[i
])
1562 vk_free(&device
->alloc
, device
->queues
[i
]);
1565 vk_free(&device
->alloc
, device
);
1569 void radv_DestroyDevice(
1571 const VkAllocationCallbacks
* pAllocator
)
1573 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1578 if (device
->trace_bo
)
1579 device
->ws
->buffer_destroy(device
->trace_bo
);
1581 if (device
->gfx_init
)
1582 device
->ws
->buffer_destroy(device
->gfx_init
);
1584 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1585 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1586 radv_queue_finish(&device
->queues
[i
][q
]);
1587 if (device
->queue_count
[i
])
1588 vk_free(&device
->alloc
, device
->queues
[i
]);
1589 if (device
->empty_cs
[i
])
1590 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1592 radv_device_finish_meta(device
);
1594 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1595 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1597 radv_destroy_shader_slabs(device
);
1599 radv_bo_list_finish(&device
->bo_list
);
1600 vk_free(&device
->alloc
, device
);
1603 VkResult
radv_EnumerateInstanceLayerProperties(
1604 uint32_t* pPropertyCount
,
1605 VkLayerProperties
* pProperties
)
1607 if (pProperties
== NULL
) {
1608 *pPropertyCount
= 0;
1612 /* None supported at this time */
1613 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1616 VkResult
radv_EnumerateDeviceLayerProperties(
1617 VkPhysicalDevice physicalDevice
,
1618 uint32_t* pPropertyCount
,
1619 VkLayerProperties
* pProperties
)
1621 if (pProperties
== NULL
) {
1622 *pPropertyCount
= 0;
1626 /* None supported at this time */
1627 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1630 void radv_GetDeviceQueue2(
1632 const VkDeviceQueueInfo2
* pQueueInfo
,
1635 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1636 struct radv_queue
*queue
;
1638 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1639 if (pQueueInfo
->flags
!= queue
->flags
) {
1640 /* From the Vulkan 1.1.70 spec:
1642 * "The queue returned by vkGetDeviceQueue2 must have the same
1643 * flags value from this structure as that used at device
1644 * creation time in a VkDeviceQueueCreateInfo instance. If no
1645 * matching flags were specified at device creation time then
1646 * pQueue will return VK_NULL_HANDLE."
1648 *pQueue
= VK_NULL_HANDLE
;
1652 *pQueue
= radv_queue_to_handle(queue
);
1655 void radv_GetDeviceQueue(
1657 uint32_t queueFamilyIndex
,
1658 uint32_t queueIndex
,
1661 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1662 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1663 .queueFamilyIndex
= queueFamilyIndex
,
1664 .queueIndex
= queueIndex
1667 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1671 fill_geom_tess_rings(struct radv_queue
*queue
,
1673 bool add_sample_positions
,
1674 uint32_t esgs_ring_size
,
1675 struct radeon_winsys_bo
*esgs_ring_bo
,
1676 uint32_t gsvs_ring_size
,
1677 struct radeon_winsys_bo
*gsvs_ring_bo
,
1678 uint32_t tess_factor_ring_size
,
1679 uint32_t tess_offchip_ring_offset
,
1680 uint32_t tess_offchip_ring_size
,
1681 struct radeon_winsys_bo
*tess_rings_bo
)
1683 uint64_t esgs_va
= 0, gsvs_va
= 0;
1684 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1685 uint32_t *desc
= &map
[4];
1688 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1690 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1691 if (tess_rings_bo
) {
1692 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1693 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1696 /* stride 0, num records - size, add tid, swizzle, elsize4,
1699 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1700 S_008F04_STRIDE(0) |
1701 S_008F04_SWIZZLE_ENABLE(true);
1702 desc
[2] = esgs_ring_size
;
1703 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1704 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1705 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1706 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1707 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1708 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1709 S_008F0C_ELEMENT_SIZE(1) |
1710 S_008F0C_INDEX_STRIDE(3) |
1711 S_008F0C_ADD_TID_ENABLE(true);
1714 /* GS entry for ES->GS ring */
1715 /* stride 0, num records - size, elsize0,
1718 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1719 S_008F04_STRIDE(0) |
1720 S_008F04_SWIZZLE_ENABLE(false);
1721 desc
[2] = esgs_ring_size
;
1722 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1723 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1724 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1725 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1726 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1727 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1728 S_008F0C_ELEMENT_SIZE(0) |
1729 S_008F0C_INDEX_STRIDE(0) |
1730 S_008F0C_ADD_TID_ENABLE(false);
1733 /* VS entry for GS->VS ring */
1734 /* stride 0, num records - size, elsize0,
1737 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1738 S_008F04_STRIDE(0) |
1739 S_008F04_SWIZZLE_ENABLE(false);
1740 desc
[2] = gsvs_ring_size
;
1741 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1742 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1743 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1744 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1745 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1746 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1747 S_008F0C_ELEMENT_SIZE(0) |
1748 S_008F0C_INDEX_STRIDE(0) |
1749 S_008F0C_ADD_TID_ENABLE(false);
1752 /* stride gsvs_itemsize, num records 64
1753 elsize 4, index stride 16 */
1754 /* shader will patch stride and desc[2] */
1756 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1757 S_008F04_STRIDE(0) |
1758 S_008F04_SWIZZLE_ENABLE(true);
1760 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1761 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1762 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1763 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1764 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1765 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1766 S_008F0C_ELEMENT_SIZE(1) |
1767 S_008F0C_INDEX_STRIDE(1) |
1768 S_008F0C_ADD_TID_ENABLE(true);
1772 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1773 S_008F04_STRIDE(0) |
1774 S_008F04_SWIZZLE_ENABLE(false);
1775 desc
[2] = tess_factor_ring_size
;
1776 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1777 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1778 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1779 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1780 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1781 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1782 S_008F0C_ELEMENT_SIZE(0) |
1783 S_008F0C_INDEX_STRIDE(0) |
1784 S_008F0C_ADD_TID_ENABLE(false);
1787 desc
[0] = tess_offchip_va
;
1788 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1789 S_008F04_STRIDE(0) |
1790 S_008F04_SWIZZLE_ENABLE(false);
1791 desc
[2] = tess_offchip_ring_size
;
1792 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1793 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1794 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1795 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1796 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1797 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1798 S_008F0C_ELEMENT_SIZE(0) |
1799 S_008F0C_INDEX_STRIDE(0) |
1800 S_008F0C_ADD_TID_ENABLE(false);
1803 /* add sample positions after all rings */
1804 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1806 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1808 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1810 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1812 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1816 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1818 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1819 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1820 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1821 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1822 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1823 device
->physical_device
->rad_info
.max_se
;
1824 unsigned offchip_granularity
;
1825 unsigned hs_offchip_param
;
1826 switch (device
->tess_offchip_block_dw_size
) {
1831 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1834 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1838 switch (device
->physical_device
->rad_info
.chip_class
) {
1840 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1846 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1850 *max_offchip_buffers_p
= max_offchip_buffers
;
1851 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1852 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1853 --max_offchip_buffers
;
1855 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1856 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1859 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1861 return hs_offchip_param
;
1865 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
,
1866 struct radeon_winsys_bo
*esgs_ring_bo
,
1867 uint32_t esgs_ring_size
,
1868 struct radeon_winsys_bo
*gsvs_ring_bo
,
1869 uint32_t gsvs_ring_size
)
1871 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
1875 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1878 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1880 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1881 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1882 radeon_emit(cs
, esgs_ring_size
>> 8);
1883 radeon_emit(cs
, gsvs_ring_size
>> 8);
1885 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1886 radeon_emit(cs
, esgs_ring_size
>> 8);
1887 radeon_emit(cs
, gsvs_ring_size
>> 8);
1892 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
,
1893 unsigned hs_offchip_param
, unsigned tf_ring_size
,
1894 struct radeon_winsys_bo
*tess_rings_bo
)
1901 tf_va
= radv_buffer_get_va(tess_rings_bo
);
1903 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1905 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1906 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1907 S_030938_SIZE(tf_ring_size
/ 4));
1908 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1910 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1911 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1912 S_030944_BASE_HI(tf_va
>> 40));
1914 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
1917 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1918 S_008988_SIZE(tf_ring_size
/ 4));
1919 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1921 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1927 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_winsys_cs
*cs
,
1928 struct radeon_winsys_bo
*compute_scratch_bo
)
1930 uint64_t scratch_va
;
1932 if (!compute_scratch_bo
)
1935 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1937 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1939 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1940 radeon_emit(cs
, scratch_va
);
1941 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1942 S_008F04_SWIZZLE_ENABLE(1));
1946 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
1947 struct radeon_winsys_cs
*cs
,
1948 struct radeon_winsys_bo
*descriptor_bo
)
1955 va
= radv_buffer_get_va(descriptor_bo
);
1957 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1959 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1960 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1961 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1962 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1963 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1965 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1966 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
1970 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1971 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1972 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1973 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1974 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1975 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1977 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1978 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
1985 radv_get_preamble_cs(struct radv_queue
*queue
,
1986 uint32_t scratch_size
,
1987 uint32_t compute_scratch_size
,
1988 uint32_t esgs_ring_size
,
1989 uint32_t gsvs_ring_size
,
1990 bool needs_tess_rings
,
1991 bool needs_sample_positions
,
1992 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1993 struct radeon_winsys_cs
**initial_preamble_cs
,
1994 struct radeon_winsys_cs
**continue_preamble_cs
)
1996 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1997 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1998 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1999 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2000 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2001 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2002 struct radeon_winsys_cs
*dest_cs
[3] = {0};
2003 bool add_tess_rings
= false, add_sample_positions
= false;
2004 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2005 unsigned max_offchip_buffers
;
2006 unsigned hs_offchip_param
= 0;
2007 unsigned tess_offchip_ring_offset
;
2008 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2009 if (!queue
->has_tess_rings
) {
2010 if (needs_tess_rings
)
2011 add_tess_rings
= true;
2013 if (!queue
->has_sample_positions
) {
2014 if (needs_sample_positions
)
2015 add_sample_positions
= true;
2017 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2018 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2019 &max_offchip_buffers
);
2020 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2021 tess_offchip_ring_size
= max_offchip_buffers
*
2022 queue
->device
->tess_offchip_block_dw_size
* 4;
2024 if (scratch_size
<= queue
->scratch_size
&&
2025 compute_scratch_size
<= queue
->compute_scratch_size
&&
2026 esgs_ring_size
<= queue
->esgs_ring_size
&&
2027 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2028 !add_tess_rings
&& !add_sample_positions
&&
2029 queue
->initial_preamble_cs
) {
2030 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2031 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2032 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2033 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2034 *continue_preamble_cs
= NULL
;
2038 if (scratch_size
> queue
->scratch_size
) {
2039 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2047 scratch_bo
= queue
->scratch_bo
;
2049 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2050 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2051 compute_scratch_size
,
2055 if (!compute_scratch_bo
)
2059 compute_scratch_bo
= queue
->compute_scratch_bo
;
2061 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2062 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2070 esgs_ring_bo
= queue
->esgs_ring_bo
;
2071 esgs_ring_size
= queue
->esgs_ring_size
;
2074 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2075 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2083 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2084 gsvs_ring_size
= queue
->gsvs_ring_size
;
2087 if (add_tess_rings
) {
2088 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2089 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2096 tess_rings_bo
= queue
->tess_rings_bo
;
2099 if (scratch_bo
!= queue
->scratch_bo
||
2100 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2101 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2102 tess_rings_bo
!= queue
->tess_rings_bo
||
2103 add_sample_positions
) {
2105 if (gsvs_ring_bo
|| esgs_ring_bo
||
2106 tess_rings_bo
|| add_sample_positions
) {
2107 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2108 if (add_sample_positions
)
2109 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2111 else if (scratch_bo
)
2112 size
= 8; /* 2 dword */
2114 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2118 RADEON_FLAG_CPU_ACCESS
|
2119 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2120 RADEON_FLAG_READ_ONLY
);
2124 descriptor_bo
= queue
->descriptor_bo
;
2126 for(int i
= 0; i
< 3; ++i
) {
2127 struct radeon_winsys_cs
*cs
= NULL
;
2128 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2129 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2136 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2138 if (descriptor_bo
!= queue
->descriptor_bo
) {
2139 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2142 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2143 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2144 S_008F04_SWIZZLE_ENABLE(1);
2145 map
[0] = scratch_va
;
2149 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2150 add_sample_positions
)
2151 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2152 esgs_ring_size
, esgs_ring_bo
,
2153 gsvs_ring_size
, gsvs_ring_bo
,
2154 tess_factor_ring_size
,
2155 tess_offchip_ring_offset
,
2156 tess_offchip_ring_size
,
2159 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2162 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2163 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2164 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2165 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2166 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2169 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2170 gsvs_ring_bo
, gsvs_ring_size
);
2171 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2172 tess_factor_ring_size
, tess_rings_bo
);
2173 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2174 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2177 si_cs_emit_cache_flush(cs
,
2178 queue
->device
->physical_device
->rad_info
.chip_class
,
2180 queue
->queue_family_index
== RING_COMPUTE
&&
2181 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2182 (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
)) |
2183 RADV_CMD_FLAG_INV_ICACHE
|
2184 RADV_CMD_FLAG_INV_SMEM_L1
|
2185 RADV_CMD_FLAG_INV_VMEM_L1
|
2186 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2187 } else if (i
== 1) {
2188 si_cs_emit_cache_flush(cs
,
2189 queue
->device
->physical_device
->rad_info
.chip_class
,
2191 queue
->queue_family_index
== RING_COMPUTE
&&
2192 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2193 RADV_CMD_FLAG_INV_ICACHE
|
2194 RADV_CMD_FLAG_INV_SMEM_L1
|
2195 RADV_CMD_FLAG_INV_VMEM_L1
|
2196 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2199 if (!queue
->device
->ws
->cs_finalize(cs
))
2203 if (queue
->initial_full_flush_preamble_cs
)
2204 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2206 if (queue
->initial_preamble_cs
)
2207 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2209 if (queue
->continue_preamble_cs
)
2210 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2212 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2213 queue
->initial_preamble_cs
= dest_cs
[1];
2214 queue
->continue_preamble_cs
= dest_cs
[2];
2216 if (scratch_bo
!= queue
->scratch_bo
) {
2217 if (queue
->scratch_bo
)
2218 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2219 queue
->scratch_bo
= scratch_bo
;
2220 queue
->scratch_size
= scratch_size
;
2223 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2224 if (queue
->compute_scratch_bo
)
2225 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2226 queue
->compute_scratch_bo
= compute_scratch_bo
;
2227 queue
->compute_scratch_size
= compute_scratch_size
;
2230 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2231 if (queue
->esgs_ring_bo
)
2232 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2233 queue
->esgs_ring_bo
= esgs_ring_bo
;
2234 queue
->esgs_ring_size
= esgs_ring_size
;
2237 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2238 if (queue
->gsvs_ring_bo
)
2239 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2240 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2241 queue
->gsvs_ring_size
= gsvs_ring_size
;
2244 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2245 queue
->tess_rings_bo
= tess_rings_bo
;
2246 queue
->has_tess_rings
= true;
2249 if (descriptor_bo
!= queue
->descriptor_bo
) {
2250 if (queue
->descriptor_bo
)
2251 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2253 queue
->descriptor_bo
= descriptor_bo
;
2256 if (add_sample_positions
)
2257 queue
->has_sample_positions
= true;
2259 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2260 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2261 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2262 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2263 *continue_preamble_cs
= NULL
;
2266 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2268 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2269 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2270 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2271 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2272 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2273 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2274 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2275 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2276 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2277 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2278 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2279 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2280 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2281 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2284 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2286 const VkSemaphore
*sems
,
2290 int syncobj_idx
= 0, sem_idx
= 0;
2292 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2295 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2296 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2298 if (sem
->temp_syncobj
|| sem
->syncobj
)
2299 counts
->syncobj_count
++;
2301 counts
->sem_count
++;
2304 if (_fence
!= VK_NULL_HANDLE
) {
2305 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2306 if (fence
->temp_syncobj
|| fence
->syncobj
)
2307 counts
->syncobj_count
++;
2310 if (counts
->syncobj_count
) {
2311 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2312 if (!counts
->syncobj
)
2313 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2316 if (counts
->sem_count
) {
2317 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2319 free(counts
->syncobj
);
2320 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2324 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2325 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2327 if (sem
->temp_syncobj
) {
2328 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2330 else if (sem
->syncobj
)
2331 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2334 counts
->sem
[sem_idx
++] = sem
->sem
;
2338 if (_fence
!= VK_NULL_HANDLE
) {
2339 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2340 if (fence
->temp_syncobj
)
2341 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2342 else if (fence
->syncobj
)
2343 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2349 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2351 free(sem_info
->wait
.syncobj
);
2352 free(sem_info
->wait
.sem
);
2353 free(sem_info
->signal
.syncobj
);
2354 free(sem_info
->signal
.sem
);
2358 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2360 const VkSemaphore
*sems
)
2362 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2363 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2365 if (sem
->temp_syncobj
) {
2366 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2367 sem
->temp_syncobj
= 0;
2372 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2374 const VkSemaphore
*wait_sems
,
2375 int num_signal_sems
,
2376 const VkSemaphore
*signal_sems
,
2380 memset(sem_info
, 0, sizeof(*sem_info
));
2382 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2385 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2387 radv_free_sem_info(sem_info
);
2389 /* caller can override these */
2390 sem_info
->cs_emit_wait
= true;
2391 sem_info
->cs_emit_signal
= true;
2395 /* Signals fence as soon as all the work currently put on queue is done. */
2396 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2397 struct radv_fence
*fence
)
2401 struct radv_winsys_sem_info sem_info
;
2403 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2404 radv_fence_to_handle(fence
));
2405 if (result
!= VK_SUCCESS
)
2408 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2409 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2410 1, NULL
, NULL
, &sem_info
, NULL
,
2411 false, fence
->fence
);
2412 radv_free_sem_info(&sem_info
);
2414 /* TODO: find a better error */
2416 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2421 VkResult
radv_QueueSubmit(
2423 uint32_t submitCount
,
2424 const VkSubmitInfo
* pSubmits
,
2427 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2428 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2429 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2430 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2432 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2433 uint32_t scratch_size
= 0;
2434 uint32_t compute_scratch_size
= 0;
2435 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2436 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2438 bool fence_emitted
= false;
2439 bool tess_rings_needed
= false;
2440 bool sample_positions_needed
= false;
2442 /* Do this first so failing to allocate scratch buffers can't result in
2443 * partially executed submissions. */
2444 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2445 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2446 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2447 pSubmits
[i
].pCommandBuffers
[j
]);
2449 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2450 compute_scratch_size
= MAX2(compute_scratch_size
,
2451 cmd_buffer
->compute_scratch_size_needed
);
2452 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2453 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2454 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2455 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2459 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2460 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2461 sample_positions_needed
, &initial_flush_preamble_cs
,
2462 &initial_preamble_cs
, &continue_preamble_cs
);
2463 if (result
!= VK_SUCCESS
)
2466 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2467 struct radeon_winsys_cs
**cs_array
;
2468 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2469 bool can_patch
= true;
2471 struct radv_winsys_sem_info sem_info
;
2473 result
= radv_alloc_sem_info(&sem_info
,
2474 pSubmits
[i
].waitSemaphoreCount
,
2475 pSubmits
[i
].pWaitSemaphores
,
2476 pSubmits
[i
].signalSemaphoreCount
,
2477 pSubmits
[i
].pSignalSemaphores
,
2479 if (result
!= VK_SUCCESS
)
2482 if (!pSubmits
[i
].commandBufferCount
) {
2483 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2484 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2485 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2490 radv_loge("failed to submit CS %d\n", i
);
2493 fence_emitted
= true;
2495 radv_free_sem_info(&sem_info
);
2499 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2500 (pSubmits
[i
].commandBufferCount
));
2502 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2503 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2504 pSubmits
[i
].pCommandBuffers
[j
]);
2505 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2507 cs_array
[j
] = cmd_buffer
->cs
;
2508 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2511 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2514 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2515 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2516 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2518 advance
= MIN2(max_cs_submission
,
2519 pSubmits
[i
].commandBufferCount
- j
);
2521 if (queue
->device
->trace_bo
)
2522 *queue
->device
->trace_id_ptr
= 0;
2524 sem_info
.cs_emit_wait
= j
== 0;
2525 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2527 if (unlikely(queue
->device
->use_global_bo_list
)) {
2528 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2529 bo_list
= &queue
->device
->bo_list
.list
;
2532 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2533 advance
, initial_preamble
, continue_preamble_cs
,
2535 can_patch
, base_fence
);
2537 if (unlikely(queue
->device
->use_global_bo_list
))
2538 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2541 radv_loge("failed to submit CS %d\n", i
);
2544 fence_emitted
= true;
2545 if (queue
->device
->trace_bo
) {
2546 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2550 radv_free_temp_syncobjs(queue
->device
,
2551 pSubmits
[i
].waitSemaphoreCount
,
2552 pSubmits
[i
].pWaitSemaphores
);
2553 radv_free_sem_info(&sem_info
);
2558 if (!fence_emitted
) {
2559 radv_signal_fence(queue
, fence
);
2561 fence
->submitted
= true;
2567 VkResult
radv_QueueWaitIdle(
2570 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2572 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2573 radv_queue_family_to_ring(queue
->queue_family_index
),
2578 VkResult
radv_DeviceWaitIdle(
2581 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2583 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2584 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2585 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2591 VkResult
radv_EnumerateInstanceExtensionProperties(
2592 const char* pLayerName
,
2593 uint32_t* pPropertyCount
,
2594 VkExtensionProperties
* pProperties
)
2596 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2598 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2599 if (radv_supported_instance_extensions
.extensions
[i
]) {
2600 vk_outarray_append(&out
, prop
) {
2601 *prop
= radv_instance_extensions
[i
];
2606 return vk_outarray_status(&out
);
2609 VkResult
radv_EnumerateDeviceExtensionProperties(
2610 VkPhysicalDevice physicalDevice
,
2611 const char* pLayerName
,
2612 uint32_t* pPropertyCount
,
2613 VkExtensionProperties
* pProperties
)
2615 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2616 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2618 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2619 if (device
->supported_extensions
.extensions
[i
]) {
2620 vk_outarray_append(&out
, prop
) {
2621 *prop
= radv_device_extensions
[i
];
2626 return vk_outarray_status(&out
);
2629 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2630 VkInstance _instance
,
2633 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2635 return radv_lookup_entrypoint_checked(pName
,
2636 instance
? instance
->apiVersion
: 0,
2637 instance
? &instance
->enabled_extensions
: NULL
,
2641 /* The loader wants us to expose a second GetInstanceProcAddr function
2642 * to work around certain LD_PRELOAD issues seen in apps.
2645 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2646 VkInstance instance
,
2650 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2651 VkInstance instance
,
2654 return radv_GetInstanceProcAddr(instance
, pName
);
2657 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2661 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2663 return radv_lookup_entrypoint_checked(pName
,
2664 device
->instance
->apiVersion
,
2665 &device
->instance
->enabled_extensions
,
2666 &device
->enabled_extensions
);
2669 bool radv_get_memory_fd(struct radv_device
*device
,
2670 struct radv_device_memory
*memory
,
2673 struct radeon_bo_metadata metadata
;
2675 if (memory
->image
) {
2676 radv_init_metadata(device
, memory
->image
, &metadata
);
2677 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2680 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2684 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2685 const VkMemoryAllocateInfo
* pAllocateInfo
,
2686 const VkAllocationCallbacks
* pAllocator
,
2687 VkDeviceMemory
* pMem
)
2689 struct radv_device_memory
*mem
;
2691 enum radeon_bo_domain domain
;
2693 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2695 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2697 if (pAllocateInfo
->allocationSize
== 0) {
2698 /* Apparently, this is allowed */
2699 *pMem
= VK_NULL_HANDLE
;
2703 const VkImportMemoryFdInfoKHR
*import_info
=
2704 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2705 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2706 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2707 const VkExportMemoryAllocateInfoKHR
*export_info
=
2708 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2709 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2710 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2712 const struct wsi_memory_allocate_info
*wsi_info
=
2713 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2715 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2716 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2718 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2720 if (wsi_info
&& wsi_info
->implicit_sync
)
2721 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2723 if (dedicate_info
) {
2724 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2725 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2731 mem
->user_ptr
= NULL
;
2734 assert(import_info
->handleType
==
2735 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2736 import_info
->handleType
==
2737 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2738 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2741 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2744 close(import_info
->fd
);
2746 } else if (host_ptr_info
) {
2747 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2748 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2749 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2750 pAllocateInfo
->allocationSize
);
2752 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2755 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2758 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2759 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2760 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2761 domain
= RADEON_DOMAIN_GTT
;
2763 domain
= RADEON_DOMAIN_VRAM
;
2765 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2766 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2768 flags
|= RADEON_FLAG_CPU_ACCESS
;
2770 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2771 flags
|= RADEON_FLAG_GTT_WC
;
2773 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2774 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2776 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2780 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2783 mem
->type_index
= mem_type_index
;
2786 result
= radv_bo_list_add(device
, mem
->bo
);
2787 if (result
!= VK_SUCCESS
)
2790 *pMem
= radv_device_memory_to_handle(mem
);
2795 device
->ws
->buffer_destroy(mem
->bo
);
2797 vk_free2(&device
->alloc
, pAllocator
, mem
);
2802 VkResult
radv_AllocateMemory(
2804 const VkMemoryAllocateInfo
* pAllocateInfo
,
2805 const VkAllocationCallbacks
* pAllocator
,
2806 VkDeviceMemory
* pMem
)
2808 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2809 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2812 void radv_FreeMemory(
2814 VkDeviceMemory _mem
,
2815 const VkAllocationCallbacks
* pAllocator
)
2817 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2818 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2823 radv_bo_list_remove(device
, mem
->bo
);
2824 device
->ws
->buffer_destroy(mem
->bo
);
2827 vk_free2(&device
->alloc
, pAllocator
, mem
);
2830 VkResult
radv_MapMemory(
2832 VkDeviceMemory _memory
,
2833 VkDeviceSize offset
,
2835 VkMemoryMapFlags flags
,
2838 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2839 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2847 *ppData
= mem
->user_ptr
;
2849 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2856 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2859 void radv_UnmapMemory(
2861 VkDeviceMemory _memory
)
2863 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2864 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2869 if (mem
->user_ptr
== NULL
)
2870 device
->ws
->buffer_unmap(mem
->bo
);
2873 VkResult
radv_FlushMappedMemoryRanges(
2875 uint32_t memoryRangeCount
,
2876 const VkMappedMemoryRange
* pMemoryRanges
)
2881 VkResult
radv_InvalidateMappedMemoryRanges(
2883 uint32_t memoryRangeCount
,
2884 const VkMappedMemoryRange
* pMemoryRanges
)
2889 void radv_GetBufferMemoryRequirements(
2892 VkMemoryRequirements
* pMemoryRequirements
)
2894 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2895 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2897 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2899 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2900 pMemoryRequirements
->alignment
= 4096;
2902 pMemoryRequirements
->alignment
= 16;
2904 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2907 void radv_GetBufferMemoryRequirements2(
2909 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2910 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2912 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2913 &pMemoryRequirements
->memoryRequirements
);
2914 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2915 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2916 switch (ext
->sType
) {
2917 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2918 VkMemoryDedicatedRequirementsKHR
*req
=
2919 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2920 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2921 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2930 void radv_GetImageMemoryRequirements(
2933 VkMemoryRequirements
* pMemoryRequirements
)
2935 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2936 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2938 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2940 pMemoryRequirements
->size
= image
->size
;
2941 pMemoryRequirements
->alignment
= image
->alignment
;
2944 void radv_GetImageMemoryRequirements2(
2946 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2947 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2949 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2950 &pMemoryRequirements
->memoryRequirements
);
2952 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2954 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2955 switch (ext
->sType
) {
2956 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2957 VkMemoryDedicatedRequirementsKHR
*req
=
2958 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2959 req
->requiresDedicatedAllocation
= image
->shareable
;
2960 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2969 void radv_GetImageSparseMemoryRequirements(
2972 uint32_t* pSparseMemoryRequirementCount
,
2973 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2978 void radv_GetImageSparseMemoryRequirements2(
2980 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2981 uint32_t* pSparseMemoryRequirementCount
,
2982 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2987 void radv_GetDeviceMemoryCommitment(
2989 VkDeviceMemory memory
,
2990 VkDeviceSize
* pCommittedMemoryInBytes
)
2992 *pCommittedMemoryInBytes
= 0;
2995 VkResult
radv_BindBufferMemory2(VkDevice device
,
2996 uint32_t bindInfoCount
,
2997 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2999 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3000 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3001 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3004 buffer
->bo
= mem
->bo
;
3005 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3013 VkResult
radv_BindBufferMemory(
3016 VkDeviceMemory memory
,
3017 VkDeviceSize memoryOffset
)
3019 const VkBindBufferMemoryInfoKHR info
= {
3020 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3023 .memoryOffset
= memoryOffset
3026 return radv_BindBufferMemory2(device
, 1, &info
);
3029 VkResult
radv_BindImageMemory2(VkDevice device
,
3030 uint32_t bindInfoCount
,
3031 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3033 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3034 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3035 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3038 image
->bo
= mem
->bo
;
3039 image
->offset
= pBindInfos
[i
].memoryOffset
;
3049 VkResult
radv_BindImageMemory(
3052 VkDeviceMemory memory
,
3053 VkDeviceSize memoryOffset
)
3055 const VkBindImageMemoryInfoKHR info
= {
3056 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3059 .memoryOffset
= memoryOffset
3062 return radv_BindImageMemory2(device
, 1, &info
);
3067 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3068 const VkSparseBufferMemoryBindInfo
*bind
)
3070 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3072 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3073 struct radv_device_memory
*mem
= NULL
;
3075 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3076 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3078 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3079 bind
->pBinds
[i
].resourceOffset
,
3080 bind
->pBinds
[i
].size
,
3081 mem
? mem
->bo
: NULL
,
3082 bind
->pBinds
[i
].memoryOffset
);
3087 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3088 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3090 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3092 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3093 struct radv_device_memory
*mem
= NULL
;
3095 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3096 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3098 device
->ws
->buffer_virtual_bind(image
->bo
,
3099 bind
->pBinds
[i
].resourceOffset
,
3100 bind
->pBinds
[i
].size
,
3101 mem
? mem
->bo
: NULL
,
3102 bind
->pBinds
[i
].memoryOffset
);
3106 VkResult
radv_QueueBindSparse(
3108 uint32_t bindInfoCount
,
3109 const VkBindSparseInfo
* pBindInfo
,
3112 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3113 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3114 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3115 bool fence_emitted
= false;
3117 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3118 struct radv_winsys_sem_info sem_info
;
3119 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3120 radv_sparse_buffer_bind_memory(queue
->device
,
3121 pBindInfo
[i
].pBufferBinds
+ j
);
3124 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3125 radv_sparse_image_opaque_bind_memory(queue
->device
,
3126 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3130 result
= radv_alloc_sem_info(&sem_info
,
3131 pBindInfo
[i
].waitSemaphoreCount
,
3132 pBindInfo
[i
].pWaitSemaphores
,
3133 pBindInfo
[i
].signalSemaphoreCount
,
3134 pBindInfo
[i
].pSignalSemaphores
,
3136 if (result
!= VK_SUCCESS
)
3139 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3140 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3141 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3145 fence_emitted
= true;
3147 fence
->submitted
= true;
3150 radv_free_sem_info(&sem_info
);
3155 if (!fence_emitted
) {
3156 radv_signal_fence(queue
, fence
);
3158 fence
->submitted
= true;
3164 VkResult
radv_CreateFence(
3166 const VkFenceCreateInfo
* pCreateInfo
,
3167 const VkAllocationCallbacks
* pAllocator
,
3170 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3171 const VkExportFenceCreateInfoKHR
*export
=
3172 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3173 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3174 export
? export
->handleTypes
: 0;
3176 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3178 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3181 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3183 fence
->submitted
= false;
3184 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3185 fence
->temp_syncobj
= 0;
3186 if (device
->always_use_syncobj
|| handleTypes
) {
3187 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3189 vk_free2(&device
->alloc
, pAllocator
, fence
);
3190 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3192 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3193 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3195 fence
->fence
= NULL
;
3197 fence
->fence
= device
->ws
->create_fence();
3198 if (!fence
->fence
) {
3199 vk_free2(&device
->alloc
, pAllocator
, fence
);
3200 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3205 *pFence
= radv_fence_to_handle(fence
);
3210 void radv_DestroyFence(
3213 const VkAllocationCallbacks
* pAllocator
)
3215 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3216 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3221 if (fence
->temp_syncobj
)
3222 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3224 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3226 device
->ws
->destroy_fence(fence
->fence
);
3227 vk_free2(&device
->alloc
, pAllocator
, fence
);
3231 static uint64_t radv_get_current_time()
3234 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3235 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3238 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3240 uint64_t current_time
= radv_get_current_time();
3242 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3244 return current_time
+ timeout
;
3248 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3250 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3251 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3252 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3258 VkResult
radv_WaitForFences(
3260 uint32_t fenceCount
,
3261 const VkFence
* pFences
,
3265 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3266 timeout
= radv_get_absolute_timeout(timeout
);
3268 if (device
->always_use_syncobj
) {
3269 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3271 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3273 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3274 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3275 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3278 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3281 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3284 if (!waitAll
&& fenceCount
> 1) {
3285 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3286 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3287 uint32_t wait_count
= 0;
3288 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3290 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3292 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3293 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3295 if (fence
->signalled
) {
3300 fences
[wait_count
++] = fence
->fence
;
3303 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3304 waitAll
, timeout
- radv_get_current_time());
3307 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3310 while(radv_get_current_time() <= timeout
) {
3311 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3312 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3319 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3320 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3321 bool expired
= false;
3323 if (fence
->temp_syncobj
) {
3324 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3329 if (fence
->syncobj
) {
3330 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3335 if (fence
->signalled
)
3338 if (!fence
->submitted
) {
3339 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3342 if (!fence
->submitted
)
3345 /* Recheck as it may have been set by submitting operations. */
3346 if (fence
->signalled
)
3350 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3354 fence
->signalled
= true;
3360 VkResult
radv_ResetFences(VkDevice _device
,
3361 uint32_t fenceCount
,
3362 const VkFence
*pFences
)
3364 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3366 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3367 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3368 fence
->submitted
= fence
->signalled
= false;
3370 /* Per spec, we first restore the permanent payload, and then reset, so
3371 * having a temp syncobj should not skip resetting the permanent syncobj. */
3372 if (fence
->temp_syncobj
) {
3373 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3374 fence
->temp_syncobj
= 0;
3377 if (fence
->syncobj
) {
3378 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3385 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3387 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3388 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3390 if (fence
->temp_syncobj
) {
3391 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3392 return success
? VK_SUCCESS
: VK_NOT_READY
;
3395 if (fence
->syncobj
) {
3396 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3397 return success
? VK_SUCCESS
: VK_NOT_READY
;
3400 if (fence
->signalled
)
3402 if (!fence
->submitted
)
3403 return VK_NOT_READY
;
3404 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3405 return VK_NOT_READY
;
3411 // Queue semaphore functions
3413 VkResult
radv_CreateSemaphore(
3415 const VkSemaphoreCreateInfo
* pCreateInfo
,
3416 const VkAllocationCallbacks
* pAllocator
,
3417 VkSemaphore
* pSemaphore
)
3419 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3420 const VkExportSemaphoreCreateInfoKHR
*export
=
3421 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3422 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3423 export
? export
->handleTypes
: 0;
3425 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3427 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3429 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3431 sem
->temp_syncobj
= 0;
3432 /* create a syncobject if we are going to export this semaphore */
3433 if (device
->always_use_syncobj
|| handleTypes
) {
3434 assert (device
->physical_device
->rad_info
.has_syncobj
);
3435 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3437 vk_free2(&device
->alloc
, pAllocator
, sem
);
3438 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3442 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3444 vk_free2(&device
->alloc
, pAllocator
, sem
);
3445 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3450 *pSemaphore
= radv_semaphore_to_handle(sem
);
3454 void radv_DestroySemaphore(
3456 VkSemaphore _semaphore
,
3457 const VkAllocationCallbacks
* pAllocator
)
3459 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3460 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3465 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3467 device
->ws
->destroy_sem(sem
->sem
);
3468 vk_free2(&device
->alloc
, pAllocator
, sem
);
3471 VkResult
radv_CreateEvent(
3473 const VkEventCreateInfo
* pCreateInfo
,
3474 const VkAllocationCallbacks
* pAllocator
,
3477 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3478 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3480 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3483 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3485 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3487 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3489 vk_free2(&device
->alloc
, pAllocator
, event
);
3490 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3493 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3495 *pEvent
= radv_event_to_handle(event
);
3500 void radv_DestroyEvent(
3503 const VkAllocationCallbacks
* pAllocator
)
3505 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3506 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3510 device
->ws
->buffer_destroy(event
->bo
);
3511 vk_free2(&device
->alloc
, pAllocator
, event
);
3514 VkResult
radv_GetEventStatus(
3518 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3520 if (*event
->map
== 1)
3521 return VK_EVENT_SET
;
3522 return VK_EVENT_RESET
;
3525 VkResult
radv_SetEvent(
3529 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3535 VkResult
radv_ResetEvent(
3539 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3545 VkResult
radv_CreateBuffer(
3547 const VkBufferCreateInfo
* pCreateInfo
,
3548 const VkAllocationCallbacks
* pAllocator
,
3551 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3552 struct radv_buffer
*buffer
;
3554 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3556 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3557 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3559 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3561 buffer
->size
= pCreateInfo
->size
;
3562 buffer
->usage
= pCreateInfo
->usage
;
3565 buffer
->flags
= pCreateInfo
->flags
;
3567 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3568 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3570 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3571 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3572 align64(buffer
->size
, 4096),
3573 4096, 0, RADEON_FLAG_VIRTUAL
);
3575 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3576 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3580 *pBuffer
= radv_buffer_to_handle(buffer
);
3585 void radv_DestroyBuffer(
3588 const VkAllocationCallbacks
* pAllocator
)
3590 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3591 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3596 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3597 device
->ws
->buffer_destroy(buffer
->bo
);
3599 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3602 static inline unsigned
3603 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3606 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3608 return image
->surface
.u
.legacy
.tiling_index
[level
];
3611 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3613 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3617 radv_init_dcc_control_reg(struct radv_device
*device
,
3618 struct radv_image_view
*iview
)
3620 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3621 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3622 unsigned max_compressed_block_size
;
3623 unsigned independent_64b_blocks
;
3625 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3628 if (iview
->image
->info
.samples
> 1) {
3629 if (iview
->image
->surface
.bpe
== 1)
3630 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3631 else if (iview
->image
->surface
.bpe
== 2)
3632 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3635 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3636 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3637 * dGPU and 64 for APU because all of our APUs to date use
3638 * DIMMs which have a request granularity size of 64B while all
3639 * other chips have a 32B request size.
3641 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3644 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3645 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3646 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3647 /* If this DCC image is potentially going to be used in texture
3648 * fetches, we need some special settings.
3650 independent_64b_blocks
= 1;
3651 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3653 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3654 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3655 * big as possible for better compression state.
3657 independent_64b_blocks
= 0;
3658 max_compressed_block_size
= max_uncompressed_block_size
;
3661 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3662 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3663 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3664 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3668 radv_initialise_color_surface(struct radv_device
*device
,
3669 struct radv_color_buffer_info
*cb
,
3670 struct radv_image_view
*iview
)
3672 const struct vk_format_description
*desc
;
3673 unsigned ntype
, format
, swap
, endian
;
3674 unsigned blend_clamp
= 0, blend_bypass
= 0;
3676 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3678 desc
= vk_format_description(iview
->vk_format
);
3680 memset(cb
, 0, sizeof(*cb
));
3682 /* Intensity is implemented as Red, so treat it that way. */
3683 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3685 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3687 cb
->cb_color_base
= va
>> 8;
3689 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3690 struct gfx9_surf_meta_flags meta
;
3691 if (iview
->image
->dcc_offset
)
3692 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3694 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3696 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3697 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3698 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3699 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3701 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3702 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3704 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3705 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3707 cb
->cb_color_base
+= level_info
->offset
>> 8;
3708 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3709 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3711 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3712 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3713 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3715 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3716 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3717 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3719 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3721 if (radv_image_has_fmask(iview
->image
)) {
3722 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3723 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3724 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3725 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3727 /* This must be set for fast clear to work without FMASK. */
3728 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3729 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3730 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3731 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3735 /* CMASK variables */
3736 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3737 va
+= iview
->image
->cmask
.offset
;
3738 cb
->cb_color_cmask
= va
>> 8;
3740 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3741 va
+= iview
->image
->dcc_offset
;
3742 cb
->cb_dcc_base
= va
>> 8;
3743 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3745 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3746 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3747 S_028C6C_SLICE_MAX(max_slice
);
3749 if (iview
->image
->info
.samples
> 1) {
3750 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3752 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3753 S_028C74_NUM_FRAGMENTS(log_samples
);
3756 if (radv_image_has_fmask(iview
->image
)) {
3757 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3758 cb
->cb_color_fmask
= va
>> 8;
3759 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3761 cb
->cb_color_fmask
= cb
->cb_color_base
;
3764 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3766 vk_format_get_first_non_void_channel(iview
->vk_format
));
3767 format
= radv_translate_colorformat(iview
->vk_format
);
3768 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3769 radv_finishme("Illegal color\n");
3770 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3771 endian
= radv_colorformat_endian_swap(format
);
3773 /* blend clamp should be set for all NORM/SRGB types */
3774 if (ntype
== V_028C70_NUMBER_UNORM
||
3775 ntype
== V_028C70_NUMBER_SNORM
||
3776 ntype
== V_028C70_NUMBER_SRGB
)
3779 /* set blend bypass according to docs if SINT/UINT or
3780 8/24 COLOR variants */
3781 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3782 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3783 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3788 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3789 (format
== V_028C70_COLOR_8
||
3790 format
== V_028C70_COLOR_8_8
||
3791 format
== V_028C70_COLOR_8_8_8_8
))
3792 ->color_is_int8
= true;
3794 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3795 S_028C70_COMP_SWAP(swap
) |
3796 S_028C70_BLEND_CLAMP(blend_clamp
) |
3797 S_028C70_BLEND_BYPASS(blend_bypass
) |
3798 S_028C70_SIMPLE_FLOAT(1) |
3799 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3800 ntype
!= V_028C70_NUMBER_SNORM
&&
3801 ntype
!= V_028C70_NUMBER_SRGB
&&
3802 format
!= V_028C70_COLOR_8_24
&&
3803 format
!= V_028C70_COLOR_24_8
) |
3804 S_028C70_NUMBER_TYPE(ntype
) |
3805 S_028C70_ENDIAN(endian
);
3806 if (radv_image_has_fmask(iview
->image
)) {
3807 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3808 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3809 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3810 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3814 if (radv_image_has_cmask(iview
->image
) &&
3815 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3816 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3818 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3819 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3821 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3823 /* This must be set for fast clear to work without FMASK. */
3824 if (!radv_image_has_fmask(iview
->image
) &&
3825 device
->physical_device
->rad_info
.chip_class
== SI
) {
3826 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3827 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3830 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3831 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3832 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3834 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3835 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3836 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3837 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3838 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3839 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3844 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3845 struct radv_image_view
*iview
)
3847 unsigned max_zplanes
= 0;
3849 assert(radv_image_is_tc_compat_htile(iview
->image
));
3851 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3852 /* Default value for 32-bit depth surfaces. */
3855 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3856 iview
->image
->info
.samples
> 1)
3859 max_zplanes
= max_zplanes
+ 1;
3861 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3862 /* Do not enable Z plane compression for 16-bit depth
3863 * surfaces because isn't supported on GFX8. Only
3864 * 32-bit depth surfaces are supported by the hardware.
3865 * This allows to maintain shader compatibility and to
3866 * reduce the number of depth decompressions.
3870 if (iview
->image
->info
.samples
<= 1)
3872 else if (iview
->image
->info
.samples
<= 4)
3883 radv_initialise_ds_surface(struct radv_device
*device
,
3884 struct radv_ds_buffer_info
*ds
,
3885 struct radv_image_view
*iview
)
3887 unsigned level
= iview
->base_mip
;
3888 unsigned format
, stencil_format
;
3889 uint64_t va
, s_offs
, z_offs
;
3890 bool stencil_only
= false;
3891 memset(ds
, 0, sizeof(*ds
));
3892 switch (iview
->image
->vk_format
) {
3893 case VK_FORMAT_D24_UNORM_S8_UINT
:
3894 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3895 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3896 ds
->offset_scale
= 2.0f
;
3898 case VK_FORMAT_D16_UNORM
:
3899 case VK_FORMAT_D16_UNORM_S8_UINT
:
3900 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3901 ds
->offset_scale
= 4.0f
;
3903 case VK_FORMAT_D32_SFLOAT
:
3904 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3905 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3906 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3907 ds
->offset_scale
= 1.0f
;
3909 case VK_FORMAT_S8_UINT
:
3910 stencil_only
= true;
3916 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3917 stencil_format
= iview
->image
->surface
.has_stencil
?
3918 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3920 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3921 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3922 S_028008_SLICE_MAX(max_slice
);
3924 ds
->db_htile_data_base
= 0;
3925 ds
->db_htile_surface
= 0;
3927 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3928 s_offs
= z_offs
= va
;
3930 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3931 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3932 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3934 ds
->db_z_info
= S_028038_FORMAT(format
) |
3935 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3936 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3937 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3938 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3939 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3941 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3942 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3943 ds
->db_depth_view
|= S_028008_MIPID(level
);
3945 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3946 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3948 if (radv_htile_enabled(iview
->image
, level
)) {
3949 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3951 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3952 unsigned max_zplanes
=
3953 radv_calc_decompress_on_z_planes(device
, iview
);
3955 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3956 S_028038_ITERATE_FLUSH(1);
3957 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3960 if (!iview
->image
->surface
.has_stencil
)
3961 /* Use all of the htile_buffer for depth if there's no stencil. */
3962 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3963 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3964 iview
->image
->htile_offset
;
3965 ds
->db_htile_data_base
= va
>> 8;
3966 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3967 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3968 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3971 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3974 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3976 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3977 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3979 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3980 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3981 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3983 if (iview
->image
->info
.samples
> 1)
3984 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3986 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3987 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3988 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3989 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3990 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3991 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3992 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3993 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3996 tile_mode
= stencil_tile_mode
;
3998 ds
->db_depth_info
|=
3999 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4000 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4001 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4002 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4003 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4004 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4005 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4006 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4008 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4009 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4010 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4011 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4013 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4016 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4017 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4018 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4020 if (radv_htile_enabled(iview
->image
, level
)) {
4021 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4023 if (!iview
->image
->surface
.has_stencil
&&
4024 !radv_image_is_tc_compat_htile(iview
->image
))
4025 /* Use all of the htile_buffer for depth if there's no stencil. */
4026 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4028 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4029 iview
->image
->htile_offset
;
4030 ds
->db_htile_data_base
= va
>> 8;
4031 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4033 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4034 unsigned max_zplanes
=
4035 radv_calc_decompress_on_z_planes(device
, iview
);
4037 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4038 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4043 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4044 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4047 VkResult
radv_CreateFramebuffer(
4049 const VkFramebufferCreateInfo
* pCreateInfo
,
4050 const VkAllocationCallbacks
* pAllocator
,
4051 VkFramebuffer
* pFramebuffer
)
4053 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4054 struct radv_framebuffer
*framebuffer
;
4056 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4058 size_t size
= sizeof(*framebuffer
) +
4059 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4060 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4061 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4062 if (framebuffer
== NULL
)
4063 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4065 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4066 framebuffer
->width
= pCreateInfo
->width
;
4067 framebuffer
->height
= pCreateInfo
->height
;
4068 framebuffer
->layers
= pCreateInfo
->layers
;
4069 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4070 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4071 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4072 framebuffer
->attachments
[i
].attachment
= iview
;
4073 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4074 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4075 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4076 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4078 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4079 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4080 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4083 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4087 void radv_DestroyFramebuffer(
4090 const VkAllocationCallbacks
* pAllocator
)
4092 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4093 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4097 vk_free2(&device
->alloc
, pAllocator
, fb
);
4100 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4102 switch (address_mode
) {
4103 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4104 return V_008F30_SQ_TEX_WRAP
;
4105 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4106 return V_008F30_SQ_TEX_MIRROR
;
4107 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4108 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4109 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4110 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4111 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4112 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4114 unreachable("illegal tex wrap mode");
4120 radv_tex_compare(VkCompareOp op
)
4123 case VK_COMPARE_OP_NEVER
:
4124 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4125 case VK_COMPARE_OP_LESS
:
4126 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4127 case VK_COMPARE_OP_EQUAL
:
4128 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4129 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4130 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4131 case VK_COMPARE_OP_GREATER
:
4132 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4133 case VK_COMPARE_OP_NOT_EQUAL
:
4134 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4135 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4136 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4137 case VK_COMPARE_OP_ALWAYS
:
4138 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4140 unreachable("illegal compare mode");
4146 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4149 case VK_FILTER_NEAREST
:
4150 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4151 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4152 case VK_FILTER_LINEAR
:
4153 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4154 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4155 case VK_FILTER_CUBIC_IMG
:
4157 fprintf(stderr
, "illegal texture filter");
4163 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4166 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4167 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4168 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4169 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4171 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4176 radv_tex_bordercolor(VkBorderColor bcolor
)
4179 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4180 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4181 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4182 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4183 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4184 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4185 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4186 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4187 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4195 radv_tex_aniso_filter(unsigned filter
)
4209 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4212 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4213 return SQ_IMG_FILTER_MODE_BLEND
;
4214 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4215 return SQ_IMG_FILTER_MODE_MIN
;
4216 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4217 return SQ_IMG_FILTER_MODE_MAX
;
4225 radv_init_sampler(struct radv_device
*device
,
4226 struct radv_sampler
*sampler
,
4227 const VkSamplerCreateInfo
*pCreateInfo
)
4229 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4230 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4231 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4232 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4233 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4235 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4236 vk_find_struct_const(pCreateInfo
->pNext
,
4237 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4238 if (sampler_reduction
)
4239 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4241 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4242 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4243 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4244 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4245 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4246 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4247 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4248 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4249 S_008F30_DISABLE_CUBE_WRAP(0) |
4250 S_008F30_COMPAT_MODE(is_vi
) |
4251 S_008F30_FILTER_MODE(filter_mode
));
4252 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4253 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4254 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4255 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4256 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4257 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4258 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4259 S_008F38_MIP_POINT_PRECLAMP(0) |
4260 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4261 S_008F38_FILTER_PREC_FIX(1) |
4262 S_008F38_ANISO_OVERRIDE(is_vi
));
4263 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4264 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4267 VkResult
radv_CreateSampler(
4269 const VkSamplerCreateInfo
* pCreateInfo
,
4270 const VkAllocationCallbacks
* pAllocator
,
4271 VkSampler
* pSampler
)
4273 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4274 struct radv_sampler
*sampler
;
4276 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4278 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4279 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4281 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4283 radv_init_sampler(device
, sampler
, pCreateInfo
);
4284 *pSampler
= radv_sampler_to_handle(sampler
);
4289 void radv_DestroySampler(
4292 const VkAllocationCallbacks
* pAllocator
)
4294 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4295 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4299 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4302 /* vk_icd.h does not declare this function, so we declare it here to
4303 * suppress Wmissing-prototypes.
4305 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4306 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4308 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4309 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4311 /* For the full details on loader interface versioning, see
4312 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4313 * What follows is a condensed summary, to help you navigate the large and
4314 * confusing official doc.
4316 * - Loader interface v0 is incompatible with later versions. We don't
4319 * - In loader interface v1:
4320 * - The first ICD entrypoint called by the loader is
4321 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4323 * - The ICD must statically expose no other Vulkan symbol unless it is
4324 * linked with -Bsymbolic.
4325 * - Each dispatchable Vulkan handle created by the ICD must be
4326 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4327 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4328 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4329 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4330 * such loader-managed surfaces.
4332 * - Loader interface v2 differs from v1 in:
4333 * - The first ICD entrypoint called by the loader is
4334 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4335 * statically expose this entrypoint.
4337 * - Loader interface v3 differs from v2 in:
4338 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4339 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4340 * because the loader no longer does so.
4342 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4346 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4347 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4350 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4351 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4353 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4355 /* At the moment, we support only the below handle types. */
4356 assert(pGetFdInfo
->handleType
==
4357 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4358 pGetFdInfo
->handleType
==
4359 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4361 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4363 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4367 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4368 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4370 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4372 switch (handleType
) {
4373 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4374 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4378 /* The valid usage section for this function says:
4380 * "handleType must not be one of the handle types defined as
4383 * So opaque handle types fall into the default "unsupported" case.
4385 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4389 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4393 uint32_t syncobj_handle
= 0;
4394 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4396 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4399 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4401 *syncobj
= syncobj_handle
;
4407 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4411 /* If we create a syncobj we do it locally so that if we have an error, we don't
4412 * leave a syncobj in an undetermined state in the fence. */
4413 uint32_t syncobj_handle
= *syncobj
;
4414 if (!syncobj_handle
) {
4415 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4417 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4422 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4424 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4426 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4429 *syncobj
= syncobj_handle
;
4436 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4437 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4439 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4440 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4441 uint32_t *syncobj_dst
= NULL
;
4443 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4444 syncobj_dst
= &sem
->temp_syncobj
;
4446 syncobj_dst
= &sem
->syncobj
;
4449 switch(pImportSemaphoreFdInfo
->handleType
) {
4450 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4451 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4452 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4453 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4455 unreachable("Unhandled semaphore handle type");
4459 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4460 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4463 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4464 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4466 uint32_t syncobj_handle
;
4468 if (sem
->temp_syncobj
)
4469 syncobj_handle
= sem
->temp_syncobj
;
4471 syncobj_handle
= sem
->syncobj
;
4473 switch(pGetFdInfo
->handleType
) {
4474 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4475 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4477 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4478 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4480 if (sem
->temp_syncobj
) {
4481 close (sem
->temp_syncobj
);
4482 sem
->temp_syncobj
= 0;
4484 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4489 unreachable("Unhandled semaphore handle type");
4493 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4497 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4498 VkPhysicalDevice physicalDevice
,
4499 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4500 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4502 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4504 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4505 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4506 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4507 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4508 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4509 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4510 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4511 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4512 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4513 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4514 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4515 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4516 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4518 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4519 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4520 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4524 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4525 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4527 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4528 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4529 uint32_t *syncobj_dst
= NULL
;
4532 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4533 syncobj_dst
= &fence
->temp_syncobj
;
4535 syncobj_dst
= &fence
->syncobj
;
4538 switch(pImportFenceFdInfo
->handleType
) {
4539 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4540 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4541 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4542 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4544 unreachable("Unhandled fence handle type");
4548 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4549 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4552 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4553 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4555 uint32_t syncobj_handle
;
4557 if (fence
->temp_syncobj
)
4558 syncobj_handle
= fence
->temp_syncobj
;
4560 syncobj_handle
= fence
->syncobj
;
4562 switch(pGetFdInfo
->handleType
) {
4563 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4564 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4566 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4567 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4569 if (fence
->temp_syncobj
) {
4570 close (fence
->temp_syncobj
);
4571 fence
->temp_syncobj
= 0;
4573 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4578 unreachable("Unhandled fence handle type");
4582 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4586 void radv_GetPhysicalDeviceExternalFenceProperties(
4587 VkPhysicalDevice physicalDevice
,
4588 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4589 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4591 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4593 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4594 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4595 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4596 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4597 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4598 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4599 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4601 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4602 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4603 pExternalFenceProperties
->externalFenceFeatures
= 0;
4608 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4609 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4610 const VkAllocationCallbacks
* pAllocator
,
4611 VkDebugReportCallbackEXT
* pCallback
)
4613 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4614 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4615 pCreateInfo
, pAllocator
, &instance
->alloc
,
4620 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4621 VkDebugReportCallbackEXT _callback
,
4622 const VkAllocationCallbacks
* pAllocator
)
4624 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4625 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4626 _callback
, pAllocator
, &instance
->alloc
);
4630 radv_DebugReportMessageEXT(VkInstance _instance
,
4631 VkDebugReportFlagsEXT flags
,
4632 VkDebugReportObjectTypeEXT objectType
,
4635 int32_t messageCode
,
4636 const char* pLayerPrefix
,
4637 const char* pMessage
)
4639 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4640 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4641 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4645 radv_GetDeviceGroupPeerMemoryFeatures(
4648 uint32_t localDeviceIndex
,
4649 uint32_t remoteDeviceIndex
,
4650 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4652 assert(localDeviceIndex
== remoteDeviceIndex
);
4654 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4655 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4656 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4657 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;