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;
112 snprintf(llvm_string
, sizeof(llvm_string
),
113 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
114 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
117 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
121 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
123 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
124 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
125 device
->rad_info
.vram_vis_size
);
127 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
128 device
->memory_properties
.memoryHeapCount
= 0;
129 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
130 vram_index
= device
->memory_properties
.memoryHeapCount
++;
131 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
132 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
133 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
136 if (visible_vram_size
) {
137 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
138 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
139 .size
= visible_vram_size
,
140 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
143 if (device
->rad_info
.gart_size
> 0) {
144 gart_index
= device
->memory_properties
.memoryHeapCount
++;
145 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
146 .size
= device
->rad_info
.gart_size
,
151 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
152 unsigned type_count
= 0;
153 if (vram_index
>= 0) {
154 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
155 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
156 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
157 .heapIndex
= vram_index
,
160 if (gart_index
>= 0) {
161 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
162 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
163 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
164 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
165 .heapIndex
= gart_index
,
168 if (visible_vram_index
>= 0) {
169 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
170 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
171 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
172 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
173 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
174 .heapIndex
= visible_vram_index
,
177 if (gart_index
>= 0) {
178 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
179 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
180 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
181 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
182 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
183 .heapIndex
= gart_index
,
186 device
->memory_properties
.memoryTypeCount
= type_count
;
190 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
192 const char *family
= getenv("RADV_FORCE_FAMILY");
198 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
199 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
200 /* Override family and chip_class. */
201 device
->rad_info
.family
= i
;
203 if (i
>= CHIP_VEGA10
)
204 device
->rad_info
.chip_class
= GFX9
;
205 else if (i
>= CHIP_TONGA
)
206 device
->rad_info
.chip_class
= VI
;
207 else if (i
>= CHIP_BONAIRE
)
208 device
->rad_info
.chip_class
= CIK
;
210 device
->rad_info
.chip_class
= SI
;
216 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
221 radv_physical_device_init(struct radv_physical_device
*device
,
222 struct radv_instance
*instance
,
223 drmDevicePtr drm_device
)
225 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
227 drmVersionPtr version
;
230 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
232 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
234 version
= drmGetVersion(fd
);
237 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
238 "failed to get version %s: %m", path
);
241 if (strcmp(version
->name
, "amdgpu")) {
242 drmFreeVersion(version
);
244 return VK_ERROR_INCOMPATIBLE_DRIVER
;
246 drmFreeVersion(version
);
248 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
249 device
->instance
= instance
;
250 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
251 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
253 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
254 instance
->perftest_flags
);
256 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
260 device
->local_fd
= fd
;
261 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
263 radv_handle_env_var_force_family(device
);
265 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
267 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
268 device
->ws
->destroy(device
->ws
);
269 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
270 "cannot generate UUID");
274 /* These flags affect shader compilation. */
275 uint64_t shader_env_flags
=
276 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
277 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
279 /* The gpu id is already embeded in the uuid so we just pass "radv"
280 * when creating the cache.
282 char buf
[VK_UUID_SIZE
* 2 + 1];
283 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
284 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
286 if (device
->rad_info
.chip_class
< VI
||
287 device
->rad_info
.chip_class
> GFX9
)
288 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
290 radv_get_driver_uuid(&device
->device_uuid
);
291 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
293 if (device
->rad_info
.family
== CHIP_STONEY
||
294 device
->rad_info
.chip_class
>= GFX9
) {
295 device
->has_rbplus
= true;
296 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
297 device
->rad_info
.family
== CHIP_VEGA12
||
298 device
->rad_info
.family
== CHIP_RAVEN
;
301 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
304 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
306 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
308 /* Vega10/Raven need a special workaround for a hardware bug. */
309 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
310 device
->rad_info
.family
== CHIP_RAVEN
;
312 /* Out-of-order primitive rasterization. */
313 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
314 device
->rad_info
.max_se
>= 2;
315 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
316 (device
->instance
->perftest_flags
& RADV_PERFTEST_OUT_OF_ORDER
);
318 device
->dcc_msaa_allowed
= device
->rad_info
.chip_class
== VI
&&
319 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
321 radv_physical_device_init_mem_types(device
);
322 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
324 result
= radv_init_wsi(device
);
325 if (result
!= VK_SUCCESS
) {
326 device
->ws
->destroy(device
->ws
);
338 radv_physical_device_finish(struct radv_physical_device
*device
)
340 radv_finish_wsi(device
);
341 device
->ws
->destroy(device
->ws
);
342 disk_cache_destroy(device
->disk_cache
);
343 close(device
->local_fd
);
347 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
348 VkSystemAllocationScope allocationScope
)
354 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
355 size_t align
, VkSystemAllocationScope allocationScope
)
357 return realloc(pOriginal
, size
);
361 default_free_func(void *pUserData
, void *pMemory
)
366 static const VkAllocationCallbacks default_alloc
= {
368 .pfnAllocation
= default_alloc_func
,
369 .pfnReallocation
= default_realloc_func
,
370 .pfnFree
= default_free_func
,
373 static const struct debug_control radv_debug_options
[] = {
374 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
375 {"nodcc", RADV_DEBUG_NO_DCC
},
376 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
377 {"nocache", RADV_DEBUG_NO_CACHE
},
378 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
379 {"nohiz", RADV_DEBUG_NO_HIZ
},
380 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
381 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
382 {"allbos", RADV_DEBUG_ALL_BOS
},
383 {"noibs", RADV_DEBUG_NO_IBS
},
384 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
385 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
386 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
387 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
388 {"nosisched", RADV_DEBUG_NO_SISCHED
},
389 {"preoptir", RADV_DEBUG_PREOPTIR
},
390 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
395 radv_get_debug_option_name(int id
)
397 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
398 return radv_debug_options
[id
].string
;
401 static const struct debug_control radv_perftest_options
[] = {
402 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
403 {"sisched", RADV_PERFTEST_SISCHED
},
404 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
405 {"binning", RADV_PERFTEST_BINNING
},
406 {"outoforderrast", RADV_PERFTEST_OUT_OF_ORDER
},
407 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
412 radv_get_perftest_option_name(int id
)
414 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
415 return radv_perftest_options
[id
].string
;
419 radv_handle_per_app_options(struct radv_instance
*instance
,
420 const VkApplicationInfo
*info
)
422 const char *name
= info
? info
->pApplicationName
: NULL
;
427 if (!strcmp(name
, "Talos - Linux - 32bit") ||
428 !strcmp(name
, "Talos - Linux - 64bit")) {
429 /* Force enable LLVM sisched for Talos because it looks safe
430 * and it gives few more FPS.
432 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
436 static int radv_get_instance_extension_index(const char *name
)
438 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
439 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
446 VkResult
radv_CreateInstance(
447 const VkInstanceCreateInfo
* pCreateInfo
,
448 const VkAllocationCallbacks
* pAllocator
,
449 VkInstance
* pInstance
)
451 struct radv_instance
*instance
;
454 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
456 uint32_t client_version
;
457 if (pCreateInfo
->pApplicationInfo
&&
458 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
459 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
461 client_version
= VK_MAKE_VERSION(1, 0, 0);
464 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
465 client_version
> VK_MAKE_VERSION(1, 1, 0xfff)) {
466 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
467 "Client requested version %d.%d.%d",
468 VK_VERSION_MAJOR(client_version
),
469 VK_VERSION_MINOR(client_version
),
470 VK_VERSION_PATCH(client_version
));
473 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
474 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
476 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
478 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
481 instance
->alloc
= *pAllocator
;
483 instance
->alloc
= default_alloc
;
485 instance
->apiVersion
= client_version
;
486 instance
->physicalDeviceCount
= -1;
488 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
489 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
490 int index
= radv_get_instance_extension_index(ext_name
);
492 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
493 vk_free2(&default_alloc
, pAllocator
, instance
);
494 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
497 instance
->enabled_extensions
.extensions
[index
] = true;
500 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
501 if (result
!= VK_SUCCESS
) {
502 vk_free2(&default_alloc
, pAllocator
, instance
);
503 return vk_error(result
);
508 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
510 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
513 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
514 radv_perftest_options
);
516 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
518 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
519 /* Disable sisched when the user requests it, this is mostly
520 * useful when the driver force-enable sisched for the given
523 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
526 *pInstance
= radv_instance_to_handle(instance
);
531 void radv_DestroyInstance(
532 VkInstance _instance
,
533 const VkAllocationCallbacks
* pAllocator
)
535 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
540 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
541 radv_physical_device_finish(instance
->physicalDevices
+ i
);
544 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
548 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
550 vk_free(&instance
->alloc
, instance
);
554 radv_enumerate_devices(struct radv_instance
*instance
)
556 /* TODO: Check for more devices ? */
557 drmDevicePtr devices
[8];
558 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
561 instance
->physicalDeviceCount
= 0;
563 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
565 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
567 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
568 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
569 devices
[i
]->bustype
== DRM_BUS_PCI
&&
570 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
572 result
= radv_physical_device_init(instance
->physicalDevices
+
573 instance
->physicalDeviceCount
,
576 if (result
== VK_SUCCESS
)
577 ++instance
->physicalDeviceCount
;
578 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
582 drmFreeDevices(devices
, max_devices
);
587 VkResult
radv_EnumeratePhysicalDevices(
588 VkInstance _instance
,
589 uint32_t* pPhysicalDeviceCount
,
590 VkPhysicalDevice
* pPhysicalDevices
)
592 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
595 if (instance
->physicalDeviceCount
< 0) {
596 result
= radv_enumerate_devices(instance
);
597 if (result
!= VK_SUCCESS
&&
598 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
602 if (!pPhysicalDevices
) {
603 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
605 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
606 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
607 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
610 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
614 VkResult
radv_EnumeratePhysicalDeviceGroups(
615 VkInstance _instance
,
616 uint32_t* pPhysicalDeviceGroupCount
,
617 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
619 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
622 if (instance
->physicalDeviceCount
< 0) {
623 result
= radv_enumerate_devices(instance
);
624 if (result
!= VK_SUCCESS
&&
625 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
629 if (!pPhysicalDeviceGroupProperties
) {
630 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
632 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
633 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
634 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
635 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
636 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
639 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
643 void radv_GetPhysicalDeviceFeatures(
644 VkPhysicalDevice physicalDevice
,
645 VkPhysicalDeviceFeatures
* pFeatures
)
647 memset(pFeatures
, 0, sizeof(*pFeatures
));
649 *pFeatures
= (VkPhysicalDeviceFeatures
) {
650 .robustBufferAccess
= true,
651 .fullDrawIndexUint32
= true,
652 .imageCubeArray
= true,
653 .independentBlend
= true,
654 .geometryShader
= true,
655 .tessellationShader
= true,
656 .sampleRateShading
= true,
657 .dualSrcBlend
= true,
659 .multiDrawIndirect
= true,
660 .drawIndirectFirstInstance
= true,
662 .depthBiasClamp
= true,
663 .fillModeNonSolid
= true,
668 .multiViewport
= true,
669 .samplerAnisotropy
= true,
670 .textureCompressionETC2
= false,
671 .textureCompressionASTC_LDR
= false,
672 .textureCompressionBC
= true,
673 .occlusionQueryPrecise
= true,
674 .pipelineStatisticsQuery
= true,
675 .vertexPipelineStoresAndAtomics
= true,
676 .fragmentStoresAndAtomics
= true,
677 .shaderTessellationAndGeometryPointSize
= true,
678 .shaderImageGatherExtended
= true,
679 .shaderStorageImageExtendedFormats
= true,
680 .shaderStorageImageMultisample
= false,
681 .shaderUniformBufferArrayDynamicIndexing
= true,
682 .shaderSampledImageArrayDynamicIndexing
= true,
683 .shaderStorageBufferArrayDynamicIndexing
= true,
684 .shaderStorageImageArrayDynamicIndexing
= true,
685 .shaderStorageImageReadWithoutFormat
= true,
686 .shaderStorageImageWriteWithoutFormat
= true,
687 .shaderClipDistance
= true,
688 .shaderCullDistance
= true,
689 .shaderFloat64
= true,
691 .shaderInt16
= false,
692 .sparseBinding
= true,
693 .variableMultisampleRate
= true,
694 .inheritedQueries
= true,
698 void radv_GetPhysicalDeviceFeatures2(
699 VkPhysicalDevice physicalDevice
,
700 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
702 vk_foreach_struct(ext
, pFeatures
->pNext
) {
703 switch (ext
->sType
) {
704 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
705 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
706 features
->variablePointersStorageBuffer
= true;
707 features
->variablePointers
= false;
710 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
711 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
712 features
->multiview
= true;
713 features
->multiviewGeometryShader
= true;
714 features
->multiviewTessellationShader
= true;
717 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
718 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
719 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
720 features
->shaderDrawParameters
= true;
723 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
724 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
725 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
726 features
->protectedMemory
= false;
729 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
730 VkPhysicalDevice16BitStorageFeatures
*features
=
731 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
732 features
->storageBuffer16BitAccess
= false;
733 features
->uniformAndStorageBuffer16BitAccess
= false;
734 features
->storagePushConstant16
= false;
735 features
->storageInputOutput16
= false;
738 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
739 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
740 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
741 features
->samplerYcbcrConversion
= false;
744 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
745 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
746 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)features
;
747 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
748 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
749 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
750 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
751 features
->shaderSampledImageArrayNonUniformIndexing
= false;
752 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
753 features
->shaderStorageImageArrayNonUniformIndexing
= false;
754 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
755 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
756 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
757 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
758 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
759 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
760 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
761 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
762 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
763 features
->descriptorBindingUpdateUnusedWhilePending
= true;
764 features
->descriptorBindingPartiallyBound
= true;
765 features
->descriptorBindingVariableDescriptorCount
= true;
766 features
->runtimeDescriptorArray
= true;
773 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
776 void radv_GetPhysicalDeviceProperties(
777 VkPhysicalDevice physicalDevice
,
778 VkPhysicalDeviceProperties
* pProperties
)
780 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
781 VkSampleCountFlags sample_counts
= 0xf;
783 /* make sure that the entire descriptor set is addressable with a signed
784 * 32-bit int. So the sum of all limits scaled by descriptor size has to
785 * be at most 2 GiB. the combined image & samples object count as one of
786 * both. This limit is for the pipeline layout, not for the set layout, but
787 * there is no set limit, so we just set a pipeline limit. I don't think
788 * any app is going to hit this soon. */
789 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
790 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
791 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
792 32 /* sampler, largest when combined with image */ +
793 64 /* sampled image */ +
794 64 /* storage image */);
796 VkPhysicalDeviceLimits limits
= {
797 .maxImageDimension1D
= (1 << 14),
798 .maxImageDimension2D
= (1 << 14),
799 .maxImageDimension3D
= (1 << 11),
800 .maxImageDimensionCube
= (1 << 14),
801 .maxImageArrayLayers
= (1 << 11),
802 .maxTexelBufferElements
= 128 * 1024 * 1024,
803 .maxUniformBufferRange
= UINT32_MAX
,
804 .maxStorageBufferRange
= UINT32_MAX
,
805 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
806 .maxMemoryAllocationCount
= UINT32_MAX
,
807 .maxSamplerAllocationCount
= 64 * 1024,
808 .bufferImageGranularity
= 64, /* A cache line */
809 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
810 .maxBoundDescriptorSets
= MAX_SETS
,
811 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
812 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
813 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
814 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
815 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
816 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
817 .maxPerStageResources
= max_descriptor_set_size
,
818 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
819 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
820 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
821 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
822 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
823 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
824 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
825 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
826 .maxVertexInputAttributes
= 32,
827 .maxVertexInputBindings
= 32,
828 .maxVertexInputAttributeOffset
= 2047,
829 .maxVertexInputBindingStride
= 2048,
830 .maxVertexOutputComponents
= 128,
831 .maxTessellationGenerationLevel
= 64,
832 .maxTessellationPatchSize
= 32,
833 .maxTessellationControlPerVertexInputComponents
= 128,
834 .maxTessellationControlPerVertexOutputComponents
= 128,
835 .maxTessellationControlPerPatchOutputComponents
= 120,
836 .maxTessellationControlTotalOutputComponents
= 4096,
837 .maxTessellationEvaluationInputComponents
= 128,
838 .maxTessellationEvaluationOutputComponents
= 128,
839 .maxGeometryShaderInvocations
= 127,
840 .maxGeometryInputComponents
= 64,
841 .maxGeometryOutputComponents
= 128,
842 .maxGeometryOutputVertices
= 256,
843 .maxGeometryTotalOutputComponents
= 1024,
844 .maxFragmentInputComponents
= 128,
845 .maxFragmentOutputAttachments
= 8,
846 .maxFragmentDualSrcAttachments
= 1,
847 .maxFragmentCombinedOutputResources
= 8,
848 .maxComputeSharedMemorySize
= 32768,
849 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
850 .maxComputeWorkGroupInvocations
= 2048,
851 .maxComputeWorkGroupSize
= {
856 .subPixelPrecisionBits
= 4 /* FIXME */,
857 .subTexelPrecisionBits
= 4 /* FIXME */,
858 .mipmapPrecisionBits
= 4 /* FIXME */,
859 .maxDrawIndexedIndexValue
= UINT32_MAX
,
860 .maxDrawIndirectCount
= UINT32_MAX
,
861 .maxSamplerLodBias
= 16,
862 .maxSamplerAnisotropy
= 16,
863 .maxViewports
= MAX_VIEWPORTS
,
864 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
865 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
866 .viewportSubPixelBits
= 13, /* We take a float? */
867 .minMemoryMapAlignment
= 4096, /* A page */
868 .minTexelBufferOffsetAlignment
= 1,
869 .minUniformBufferOffsetAlignment
= 4,
870 .minStorageBufferOffsetAlignment
= 4,
871 .minTexelOffset
= -32,
872 .maxTexelOffset
= 31,
873 .minTexelGatherOffset
= -32,
874 .maxTexelGatherOffset
= 31,
875 .minInterpolationOffset
= -2,
876 .maxInterpolationOffset
= 2,
877 .subPixelInterpolationOffsetBits
= 8,
878 .maxFramebufferWidth
= (1 << 14),
879 .maxFramebufferHeight
= (1 << 14),
880 .maxFramebufferLayers
= (1 << 10),
881 .framebufferColorSampleCounts
= sample_counts
,
882 .framebufferDepthSampleCounts
= sample_counts
,
883 .framebufferStencilSampleCounts
= sample_counts
,
884 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
885 .maxColorAttachments
= MAX_RTS
,
886 .sampledImageColorSampleCounts
= sample_counts
,
887 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
888 .sampledImageDepthSampleCounts
= sample_counts
,
889 .sampledImageStencilSampleCounts
= sample_counts
,
890 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
891 .maxSampleMaskWords
= 1,
892 .timestampComputeAndGraphics
= true,
893 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
894 .maxClipDistances
= 8,
895 .maxCullDistances
= 8,
896 .maxCombinedClipAndCullDistances
= 8,
897 .discreteQueuePriorities
= 1,
898 .pointSizeRange
= { 0.125, 255.875 },
899 .lineWidthRange
= { 0.0, 7.9921875 },
900 .pointSizeGranularity
= (1.0 / 8.0),
901 .lineWidthGranularity
= (1.0 / 128.0),
902 .strictLines
= false, /* FINISHME */
903 .standardSampleLocations
= true,
904 .optimalBufferCopyOffsetAlignment
= 128,
905 .optimalBufferCopyRowPitchAlignment
= 128,
906 .nonCoherentAtomSize
= 64,
909 *pProperties
= (VkPhysicalDeviceProperties
) {
910 .apiVersion
= radv_physical_device_api_version(pdevice
),
911 .driverVersion
= vk_get_driver_version(),
912 .vendorID
= ATI_VENDOR_ID
,
913 .deviceID
= pdevice
->rad_info
.pci_id
,
914 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
916 .sparseProperties
= {0},
919 strcpy(pProperties
->deviceName
, pdevice
->name
);
920 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
923 void radv_GetPhysicalDeviceProperties2(
924 VkPhysicalDevice physicalDevice
,
925 VkPhysicalDeviceProperties2KHR
*pProperties
)
927 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
928 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
930 vk_foreach_struct(ext
, pProperties
->pNext
) {
931 switch (ext
->sType
) {
932 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
933 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
934 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
935 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
938 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
939 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
940 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
941 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
942 properties
->deviceLUIDValid
= false;
945 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
946 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
947 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
948 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
951 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
952 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
953 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
954 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
957 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
958 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
959 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
960 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
963 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
964 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
965 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
966 properties
->minImportedHostPointerAlignment
= 4096;
969 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
970 VkPhysicalDeviceSubgroupProperties
*properties
=
971 (VkPhysicalDeviceSubgroupProperties
*)ext
;
972 properties
->subgroupSize
= 64;
973 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
974 properties
->supportedOperations
=
975 VK_SUBGROUP_FEATURE_BASIC_BIT
|
976 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
977 VK_SUBGROUP_FEATURE_QUAD_BIT
|
978 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
979 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
980 VK_SUBGROUP_FEATURE_VOTE_BIT
;
981 properties
->quadOperationsInAllStages
= true;
984 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
985 VkPhysicalDeviceMaintenance3Properties
*properties
=
986 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
987 /* Make sure everything is addressable by a signed 32-bit int, and
988 * our largest descriptors are 96 bytes. */
989 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
990 /* Our buffer size fields allow only this much */
991 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
994 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
995 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
996 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
997 /* GFX6-8 only support single channel min/max filter. */
998 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
999 properties
->filterMinmaxSingleComponentFormats
= true;
1002 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1003 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1004 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1006 /* Shader engines. */
1007 properties
->shaderEngineCount
=
1008 pdevice
->rad_info
.max_se
;
1009 properties
->shaderArraysPerEngineCount
=
1010 pdevice
->rad_info
.max_sh_per_se
;
1011 properties
->computeUnitsPerShaderArray
=
1012 pdevice
->rad_info
.num_good_compute_units
/
1013 (pdevice
->rad_info
.max_se
*
1014 pdevice
->rad_info
.max_sh_per_se
);
1015 properties
->simdPerComputeUnit
= 4;
1016 properties
->wavefrontsPerSimd
=
1017 pdevice
->rad_info
.family
== CHIP_TONGA
||
1018 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1019 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1020 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1021 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1022 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1023 properties
->wavefrontSize
= 64;
1026 properties
->sgprsPerSimd
=
1027 radv_get_num_physical_sgprs(pdevice
);
1028 properties
->minSgprAllocation
=
1029 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1030 properties
->maxSgprAllocation
=
1031 pdevice
->rad_info
.family
== CHIP_TONGA
||
1032 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1033 properties
->sgprAllocationGranularity
=
1034 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1037 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1038 properties
->minVgprAllocation
= 4;
1039 properties
->maxVgprAllocation
= 256;
1040 properties
->vgprAllocationGranularity
= 4;
1043 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1044 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1045 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1046 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1049 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1050 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1051 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1052 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1053 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1054 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1055 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1056 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1057 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1058 properties
->robustBufferAccessUpdateAfterBind
= false;
1059 properties
->quadDivergentImplicitLod
= false;
1061 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1062 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1063 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1064 32 /* sampler, largest when combined with image */ +
1065 64 /* sampled image */ +
1066 64 /* storage image */);
1067 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1068 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1069 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1070 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1071 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1072 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1073 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1074 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1075 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1076 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1077 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1078 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1079 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1080 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1081 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1090 static void radv_get_physical_device_queue_family_properties(
1091 struct radv_physical_device
* pdevice
,
1093 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1095 int num_queue_families
= 1;
1097 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1098 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1099 num_queue_families
++;
1101 if (pQueueFamilyProperties
== NULL
) {
1102 *pCount
= num_queue_families
;
1111 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1112 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1113 VK_QUEUE_COMPUTE_BIT
|
1114 VK_QUEUE_TRANSFER_BIT
|
1115 VK_QUEUE_SPARSE_BINDING_BIT
,
1117 .timestampValidBits
= 64,
1118 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1123 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1124 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1125 if (*pCount
> idx
) {
1126 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1127 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1128 VK_QUEUE_TRANSFER_BIT
|
1129 VK_QUEUE_SPARSE_BINDING_BIT
,
1130 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1131 .timestampValidBits
= 64,
1132 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1140 void radv_GetPhysicalDeviceQueueFamilyProperties(
1141 VkPhysicalDevice physicalDevice
,
1143 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1145 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1146 if (!pQueueFamilyProperties
) {
1147 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1150 VkQueueFamilyProperties
*properties
[] = {
1151 pQueueFamilyProperties
+ 0,
1152 pQueueFamilyProperties
+ 1,
1153 pQueueFamilyProperties
+ 2,
1155 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1156 assert(*pCount
<= 3);
1159 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1160 VkPhysicalDevice physicalDevice
,
1162 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1164 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1165 if (!pQueueFamilyProperties
) {
1166 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1169 VkQueueFamilyProperties
*properties
[] = {
1170 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1171 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1172 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1174 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1175 assert(*pCount
<= 3);
1178 void radv_GetPhysicalDeviceMemoryProperties(
1179 VkPhysicalDevice physicalDevice
,
1180 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1182 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1184 *pMemoryProperties
= physical_device
->memory_properties
;
1187 void radv_GetPhysicalDeviceMemoryProperties2(
1188 VkPhysicalDevice physicalDevice
,
1189 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1191 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1192 &pMemoryProperties
->memoryProperties
);
1195 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1197 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1198 const void *pHostPointer
,
1199 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1201 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1205 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1206 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1207 uint32_t memoryTypeBits
= 0;
1208 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1209 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1210 memoryTypeBits
= (1 << i
);
1214 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1218 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1222 static enum radeon_ctx_priority
1223 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1225 /* Default to MEDIUM when a specific global priority isn't requested */
1227 return RADEON_CTX_PRIORITY_MEDIUM
;
1229 switch(pObj
->globalPriority
) {
1230 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1231 return RADEON_CTX_PRIORITY_REALTIME
;
1232 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1233 return RADEON_CTX_PRIORITY_HIGH
;
1234 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1235 return RADEON_CTX_PRIORITY_MEDIUM
;
1236 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1237 return RADEON_CTX_PRIORITY_LOW
;
1239 unreachable("Illegal global priority value");
1240 return RADEON_CTX_PRIORITY_INVALID
;
1245 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1246 uint32_t queue_family_index
, int idx
,
1247 VkDeviceQueueCreateFlags flags
,
1248 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1250 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1251 queue
->device
= device
;
1252 queue
->queue_family_index
= queue_family_index
;
1253 queue
->queue_idx
= idx
;
1254 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1255 queue
->flags
= flags
;
1257 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1259 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1265 radv_queue_finish(struct radv_queue
*queue
)
1268 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1270 if (queue
->initial_full_flush_preamble_cs
)
1271 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1272 if (queue
->initial_preamble_cs
)
1273 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1274 if (queue
->continue_preamble_cs
)
1275 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1276 if (queue
->descriptor_bo
)
1277 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1278 if (queue
->scratch_bo
)
1279 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1280 if (queue
->esgs_ring_bo
)
1281 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1282 if (queue
->gsvs_ring_bo
)
1283 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1284 if (queue
->tess_rings_bo
)
1285 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1286 if (queue
->compute_scratch_bo
)
1287 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1291 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1293 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1294 bo_list
->list
.count
= bo_list
->capacity
= 0;
1295 bo_list
->list
.bos
= NULL
;
1299 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1301 free(bo_list
->list
.bos
);
1302 pthread_mutex_destroy(&bo_list
->mutex
);
1305 static VkResult
radv_bo_list_add(struct radv_bo_list
*bo_list
, struct radeon_winsys_bo
*bo
)
1307 pthread_mutex_lock(&bo_list
->mutex
);
1308 if (bo_list
->list
.count
== bo_list
->capacity
) {
1309 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1310 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1313 pthread_mutex_unlock(&bo_list
->mutex
);
1314 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1317 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1318 bo_list
->capacity
= capacity
;
1321 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1322 pthread_mutex_unlock(&bo_list
->mutex
);
1326 static void radv_bo_list_remove(struct radv_bo_list
*bo_list
, struct radeon_winsys_bo
*bo
)
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 switch (device
->physical_device
->rad_info
.family
) {
1351 device
->gs_table_depth
= 16;
1360 case CHIP_POLARIS10
:
1361 case CHIP_POLARIS11
:
1362 case CHIP_POLARIS12
:
1367 device
->gs_table_depth
= 32;
1370 unreachable("unknown GPU");
1374 static int radv_get_device_extension_index(const char *name
)
1376 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1377 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1383 VkResult
radv_CreateDevice(
1384 VkPhysicalDevice physicalDevice
,
1385 const VkDeviceCreateInfo
* pCreateInfo
,
1386 const VkAllocationCallbacks
* pAllocator
,
1389 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1391 struct radv_device
*device
;
1393 bool keep_shader_info
= false;
1395 /* Check enabled features */
1396 if (pCreateInfo
->pEnabledFeatures
) {
1397 VkPhysicalDeviceFeatures supported_features
;
1398 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1399 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1400 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1401 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1402 for (uint32_t i
= 0; i
< num_features
; i
++) {
1403 if (enabled_feature
[i
] && !supported_feature
[i
])
1404 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1408 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1410 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1412 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1414 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1415 device
->instance
= physical_device
->instance
;
1416 device
->physical_device
= physical_device
;
1418 device
->ws
= physical_device
->ws
;
1420 device
->alloc
= *pAllocator
;
1422 device
->alloc
= physical_device
->instance
->alloc
;
1424 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1425 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1426 int index
= radv_get_device_extension_index(ext_name
);
1427 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1428 vk_free(&device
->alloc
, device
);
1429 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1432 device
->enabled_extensions
.extensions
[index
] = true;
1435 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1437 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1438 list_inithead(&device
->shader_slabs
);
1440 radv_bo_list_init(&device
->bo_list
);
1442 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1443 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1444 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1445 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1446 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1448 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1450 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1451 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1452 if (!device
->queues
[qfi
]) {
1453 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1457 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1459 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1461 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1462 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1463 qfi
, q
, queue_create
->flags
,
1465 if (result
!= VK_SUCCESS
)
1470 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1471 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1473 /* Disabled and not implemented for now. */
1474 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1477 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1480 device
->llvm_supports_spill
= true;
1482 /* The maximum number of scratch waves. Scratch space isn't divided
1483 * evenly between CUs. The number is only a function of the number of CUs.
1484 * We can decrease the constant to decrease the scratch buffer size.
1486 * sctx->scratch_waves must be >= the maximum posible size of
1487 * 1 threadgroup, so that the hw doesn't hang from being unable
1490 * The recommended value is 4 per CU at most. Higher numbers don't
1491 * bring much benefit, but they still occupy chip resources (think
1492 * async compute). I've seen ~2% performance difference between 4 and 32.
1494 uint32_t max_threads_per_block
= 2048;
1495 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1496 max_threads_per_block
/ 64);
1498 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1500 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1501 /* If the KMD allows it (there is a KMD hw register for it),
1502 * allow launching waves out-of-order.
1504 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1507 radv_device_init_gs_info(device
);
1509 device
->tess_offchip_block_dw_size
=
1510 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1511 device
->has_distributed_tess
=
1512 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1513 device
->physical_device
->rad_info
.max_se
>= 2;
1515 if (getenv("RADV_TRACE_FILE")) {
1516 const char *filename
= getenv("RADV_TRACE_FILE");
1518 keep_shader_info
= true;
1520 if (!radv_init_trace(device
))
1523 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1524 radv_dump_enabled_options(device
, stderr
);
1527 device
->keep_shader_info
= keep_shader_info
;
1529 result
= radv_device_init_meta(device
);
1530 if (result
!= VK_SUCCESS
)
1533 radv_device_init_msaa(device
);
1535 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1536 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1538 case RADV_QUEUE_GENERAL
:
1539 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1540 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1541 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1543 case RADV_QUEUE_COMPUTE
:
1544 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1545 radeon_emit(device
->empty_cs
[family
], 0);
1548 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1551 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1552 cik_create_gfx_config(device
);
1554 VkPipelineCacheCreateInfo ci
;
1555 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1558 ci
.pInitialData
= NULL
;
1559 ci
.initialDataSize
= 0;
1561 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1563 if (result
!= VK_SUCCESS
)
1566 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1568 *pDevice
= radv_device_to_handle(device
);
1572 radv_device_finish_meta(device
);
1574 radv_bo_list_finish(&device
->bo_list
);
1576 if (device
->trace_bo
)
1577 device
->ws
->buffer_destroy(device
->trace_bo
);
1579 if (device
->gfx_init
)
1580 device
->ws
->buffer_destroy(device
->gfx_init
);
1582 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1583 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1584 radv_queue_finish(&device
->queues
[i
][q
]);
1585 if (device
->queue_count
[i
])
1586 vk_free(&device
->alloc
, device
->queues
[i
]);
1589 vk_free(&device
->alloc
, device
);
1593 void radv_DestroyDevice(
1595 const VkAllocationCallbacks
* pAllocator
)
1597 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1602 if (device
->trace_bo
)
1603 device
->ws
->buffer_destroy(device
->trace_bo
);
1605 if (device
->gfx_init
)
1606 device
->ws
->buffer_destroy(device
->gfx_init
);
1608 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1609 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1610 radv_queue_finish(&device
->queues
[i
][q
]);
1611 if (device
->queue_count
[i
])
1612 vk_free(&device
->alloc
, device
->queues
[i
]);
1613 if (device
->empty_cs
[i
])
1614 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1616 radv_device_finish_meta(device
);
1618 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1619 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1621 radv_destroy_shader_slabs(device
);
1623 radv_bo_list_finish(&device
->bo_list
);
1624 vk_free(&device
->alloc
, device
);
1627 VkResult
radv_EnumerateInstanceLayerProperties(
1628 uint32_t* pPropertyCount
,
1629 VkLayerProperties
* pProperties
)
1631 if (pProperties
== NULL
) {
1632 *pPropertyCount
= 0;
1636 /* None supported at this time */
1637 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1640 VkResult
radv_EnumerateDeviceLayerProperties(
1641 VkPhysicalDevice physicalDevice
,
1642 uint32_t* pPropertyCount
,
1643 VkLayerProperties
* pProperties
)
1645 if (pProperties
== NULL
) {
1646 *pPropertyCount
= 0;
1650 /* None supported at this time */
1651 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1654 void radv_GetDeviceQueue2(
1656 const VkDeviceQueueInfo2
* pQueueInfo
,
1659 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1660 struct radv_queue
*queue
;
1662 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1663 if (pQueueInfo
->flags
!= queue
->flags
) {
1664 /* From the Vulkan 1.1.70 spec:
1666 * "The queue returned by vkGetDeviceQueue2 must have the same
1667 * flags value from this structure as that used at device
1668 * creation time in a VkDeviceQueueCreateInfo instance. If no
1669 * matching flags were specified at device creation time then
1670 * pQueue will return VK_NULL_HANDLE."
1672 *pQueue
= VK_NULL_HANDLE
;
1676 *pQueue
= radv_queue_to_handle(queue
);
1679 void radv_GetDeviceQueue(
1681 uint32_t queueFamilyIndex
,
1682 uint32_t queueIndex
,
1685 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1686 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1687 .queueFamilyIndex
= queueFamilyIndex
,
1688 .queueIndex
= queueIndex
1691 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1695 fill_geom_tess_rings(struct radv_queue
*queue
,
1697 bool add_sample_positions
,
1698 uint32_t esgs_ring_size
,
1699 struct radeon_winsys_bo
*esgs_ring_bo
,
1700 uint32_t gsvs_ring_size
,
1701 struct radeon_winsys_bo
*gsvs_ring_bo
,
1702 uint32_t tess_factor_ring_size
,
1703 uint32_t tess_offchip_ring_offset
,
1704 uint32_t tess_offchip_ring_size
,
1705 struct radeon_winsys_bo
*tess_rings_bo
)
1707 uint64_t esgs_va
= 0, gsvs_va
= 0;
1708 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1709 uint32_t *desc
= &map
[4];
1712 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1714 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1715 if (tess_rings_bo
) {
1716 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1717 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1720 /* stride 0, num records - size, add tid, swizzle, elsize4,
1723 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1724 S_008F04_STRIDE(0) |
1725 S_008F04_SWIZZLE_ENABLE(true);
1726 desc
[2] = esgs_ring_size
;
1727 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1728 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1729 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1730 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1731 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1732 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1733 S_008F0C_ELEMENT_SIZE(1) |
1734 S_008F0C_INDEX_STRIDE(3) |
1735 S_008F0C_ADD_TID_ENABLE(true);
1738 /* GS entry for ES->GS ring */
1739 /* stride 0, num records - size, elsize0,
1742 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1743 S_008F04_STRIDE(0) |
1744 S_008F04_SWIZZLE_ENABLE(false);
1745 desc
[2] = esgs_ring_size
;
1746 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1747 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1748 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1749 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1750 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1751 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1752 S_008F0C_ELEMENT_SIZE(0) |
1753 S_008F0C_INDEX_STRIDE(0) |
1754 S_008F0C_ADD_TID_ENABLE(false);
1757 /* VS entry for GS->VS ring */
1758 /* stride 0, num records - size, elsize0,
1761 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1762 S_008F04_STRIDE(0) |
1763 S_008F04_SWIZZLE_ENABLE(false);
1764 desc
[2] = gsvs_ring_size
;
1765 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1766 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1767 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1768 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1769 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1770 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1771 S_008F0C_ELEMENT_SIZE(0) |
1772 S_008F0C_INDEX_STRIDE(0) |
1773 S_008F0C_ADD_TID_ENABLE(false);
1776 /* stride gsvs_itemsize, num records 64
1777 elsize 4, index stride 16 */
1778 /* shader will patch stride and desc[2] */
1780 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1781 S_008F04_STRIDE(0) |
1782 S_008F04_SWIZZLE_ENABLE(true);
1784 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1785 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1786 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1787 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1788 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1789 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1790 S_008F0C_ELEMENT_SIZE(1) |
1791 S_008F0C_INDEX_STRIDE(1) |
1792 S_008F0C_ADD_TID_ENABLE(true);
1796 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1797 S_008F04_STRIDE(0) |
1798 S_008F04_SWIZZLE_ENABLE(false);
1799 desc
[2] = tess_factor_ring_size
;
1800 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1801 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1802 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1803 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1804 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1805 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1806 S_008F0C_ELEMENT_SIZE(0) |
1807 S_008F0C_INDEX_STRIDE(0) |
1808 S_008F0C_ADD_TID_ENABLE(false);
1811 desc
[0] = tess_offchip_va
;
1812 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1813 S_008F04_STRIDE(0) |
1814 S_008F04_SWIZZLE_ENABLE(false);
1815 desc
[2] = tess_offchip_ring_size
;
1816 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1817 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1818 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1819 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1820 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1821 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1822 S_008F0C_ELEMENT_SIZE(0) |
1823 S_008F0C_INDEX_STRIDE(0) |
1824 S_008F0C_ADD_TID_ENABLE(false);
1827 /* add sample positions after all rings */
1828 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1830 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1832 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1834 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1836 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1840 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1842 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1843 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1844 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1845 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1846 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1847 device
->physical_device
->rad_info
.max_se
;
1848 unsigned offchip_granularity
;
1849 unsigned hs_offchip_param
;
1850 switch (device
->tess_offchip_block_dw_size
) {
1855 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1858 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1862 switch (device
->physical_device
->rad_info
.chip_class
) {
1864 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1870 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1874 *max_offchip_buffers_p
= max_offchip_buffers
;
1875 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1876 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1877 --max_offchip_buffers
;
1879 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1880 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1883 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1885 return hs_offchip_param
;
1889 radv_get_preamble_cs(struct radv_queue
*queue
,
1890 uint32_t scratch_size
,
1891 uint32_t compute_scratch_size
,
1892 uint32_t esgs_ring_size
,
1893 uint32_t gsvs_ring_size
,
1894 bool needs_tess_rings
,
1895 bool needs_sample_positions
,
1896 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1897 struct radeon_winsys_cs
**initial_preamble_cs
,
1898 struct radeon_winsys_cs
**continue_preamble_cs
)
1900 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1901 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1902 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1903 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1904 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1905 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1906 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1907 bool add_tess_rings
= false, add_sample_positions
= false;
1908 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1909 unsigned max_offchip_buffers
;
1910 unsigned hs_offchip_param
= 0;
1911 unsigned tess_offchip_ring_offset
;
1912 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1913 if (!queue
->has_tess_rings
) {
1914 if (needs_tess_rings
)
1915 add_tess_rings
= true;
1917 if (!queue
->has_sample_positions
) {
1918 if (needs_sample_positions
)
1919 add_sample_positions
= true;
1921 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1922 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1923 &max_offchip_buffers
);
1924 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1925 tess_offchip_ring_size
= max_offchip_buffers
*
1926 queue
->device
->tess_offchip_block_dw_size
* 4;
1928 if (scratch_size
<= queue
->scratch_size
&&
1929 compute_scratch_size
<= queue
->compute_scratch_size
&&
1930 esgs_ring_size
<= queue
->esgs_ring_size
&&
1931 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1932 !add_tess_rings
&& !add_sample_positions
&&
1933 queue
->initial_preamble_cs
) {
1934 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1935 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1936 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1937 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1938 *continue_preamble_cs
= NULL
;
1942 if (scratch_size
> queue
->scratch_size
) {
1943 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1951 scratch_bo
= queue
->scratch_bo
;
1953 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1954 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1955 compute_scratch_size
,
1959 if (!compute_scratch_bo
)
1963 compute_scratch_bo
= queue
->compute_scratch_bo
;
1965 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1966 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1974 esgs_ring_bo
= queue
->esgs_ring_bo
;
1975 esgs_ring_size
= queue
->esgs_ring_size
;
1978 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1979 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1987 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1988 gsvs_ring_size
= queue
->gsvs_ring_size
;
1991 if (add_tess_rings
) {
1992 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1993 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2000 tess_rings_bo
= queue
->tess_rings_bo
;
2003 if (scratch_bo
!= queue
->scratch_bo
||
2004 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2005 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2006 tess_rings_bo
!= queue
->tess_rings_bo
||
2007 add_sample_positions
) {
2009 if (gsvs_ring_bo
|| esgs_ring_bo
||
2010 tess_rings_bo
|| add_sample_positions
) {
2011 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2012 if (add_sample_positions
)
2013 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2015 else if (scratch_bo
)
2016 size
= 8; /* 2 dword */
2018 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2022 RADEON_FLAG_CPU_ACCESS
|
2023 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2024 RADEON_FLAG_READ_ONLY
);
2028 descriptor_bo
= queue
->descriptor_bo
;
2030 for(int i
= 0; i
< 3; ++i
) {
2031 struct radeon_winsys_cs
*cs
= NULL
;
2032 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2033 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2040 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2043 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
2046 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
2049 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
2052 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
2054 if (descriptor_bo
!= queue
->descriptor_bo
) {
2055 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2058 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2059 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2060 S_008F04_SWIZZLE_ENABLE(1);
2061 map
[0] = scratch_va
;
2065 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2066 add_sample_positions
)
2067 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2068 esgs_ring_size
, esgs_ring_bo
,
2069 gsvs_ring_size
, gsvs_ring_bo
,
2070 tess_factor_ring_size
,
2071 tess_offchip_ring_offset
,
2072 tess_offchip_ring_size
,
2075 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2078 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2079 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2080 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2081 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2082 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2085 if (esgs_ring_bo
|| gsvs_ring_bo
) {
2086 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2087 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2088 radeon_emit(cs
, esgs_ring_size
>> 8);
2089 radeon_emit(cs
, gsvs_ring_size
>> 8);
2091 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2092 radeon_emit(cs
, esgs_ring_size
>> 8);
2093 radeon_emit(cs
, gsvs_ring_size
>> 8);
2097 if (tess_rings_bo
) {
2098 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
2099 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2100 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2101 S_030938_SIZE(tess_factor_ring_size
/ 4));
2102 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2104 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2105 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2106 S_030944_BASE_HI(tf_va
>> 40));
2108 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
2110 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2111 S_008988_SIZE(tess_factor_ring_size
/ 4));
2112 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2114 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2119 if (descriptor_bo
) {
2120 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
2121 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2122 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2123 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2124 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2125 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2127 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2128 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2129 radeon_emit(cs
, va
);
2130 radeon_emit(cs
, va
>> 32);
2133 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2134 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2135 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2136 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2137 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2138 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2140 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2141 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2142 radeon_emit(cs
, va
);
2143 radeon_emit(cs
, va
>> 32);
2148 if (compute_scratch_bo
) {
2149 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2150 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2151 S_008F04_SWIZZLE_ENABLE(1);
2153 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2155 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2156 radeon_emit(cs
, scratch_va
);
2157 radeon_emit(cs
, rsrc1
);
2161 si_cs_emit_cache_flush(cs
,
2162 queue
->device
->physical_device
->rad_info
.chip_class
,
2164 queue
->queue_family_index
== RING_COMPUTE
&&
2165 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2166 (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
)) |
2167 RADV_CMD_FLAG_INV_ICACHE
|
2168 RADV_CMD_FLAG_INV_SMEM_L1
|
2169 RADV_CMD_FLAG_INV_VMEM_L1
|
2170 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2171 } else if (i
== 1) {
2172 si_cs_emit_cache_flush(cs
,
2173 queue
->device
->physical_device
->rad_info
.chip_class
,
2175 queue
->queue_family_index
== RING_COMPUTE
&&
2176 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2177 RADV_CMD_FLAG_INV_ICACHE
|
2178 RADV_CMD_FLAG_INV_SMEM_L1
|
2179 RADV_CMD_FLAG_INV_VMEM_L1
|
2180 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2183 if (!queue
->device
->ws
->cs_finalize(cs
))
2187 if (queue
->initial_full_flush_preamble_cs
)
2188 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2190 if (queue
->initial_preamble_cs
)
2191 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2193 if (queue
->continue_preamble_cs
)
2194 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2196 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2197 queue
->initial_preamble_cs
= dest_cs
[1];
2198 queue
->continue_preamble_cs
= dest_cs
[2];
2200 if (scratch_bo
!= queue
->scratch_bo
) {
2201 if (queue
->scratch_bo
)
2202 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2203 queue
->scratch_bo
= scratch_bo
;
2204 queue
->scratch_size
= scratch_size
;
2207 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2208 if (queue
->compute_scratch_bo
)
2209 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2210 queue
->compute_scratch_bo
= compute_scratch_bo
;
2211 queue
->compute_scratch_size
= compute_scratch_size
;
2214 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2215 if (queue
->esgs_ring_bo
)
2216 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2217 queue
->esgs_ring_bo
= esgs_ring_bo
;
2218 queue
->esgs_ring_size
= esgs_ring_size
;
2221 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2222 if (queue
->gsvs_ring_bo
)
2223 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2224 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2225 queue
->gsvs_ring_size
= gsvs_ring_size
;
2228 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2229 queue
->tess_rings_bo
= tess_rings_bo
;
2230 queue
->has_tess_rings
= true;
2233 if (descriptor_bo
!= queue
->descriptor_bo
) {
2234 if (queue
->descriptor_bo
)
2235 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2237 queue
->descriptor_bo
= descriptor_bo
;
2240 if (add_sample_positions
)
2241 queue
->has_sample_positions
= true;
2243 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2244 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2245 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2246 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2247 *continue_preamble_cs
= NULL
;
2250 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2252 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2253 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2254 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2255 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2256 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2257 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2258 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2259 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2260 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2261 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2262 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2263 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2264 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2265 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2268 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2270 const VkSemaphore
*sems
,
2274 int syncobj_idx
= 0, sem_idx
= 0;
2276 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2279 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2280 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2282 if (sem
->temp_syncobj
|| sem
->syncobj
)
2283 counts
->syncobj_count
++;
2285 counts
->sem_count
++;
2288 if (_fence
!= VK_NULL_HANDLE
) {
2289 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2290 if (fence
->temp_syncobj
|| fence
->syncobj
)
2291 counts
->syncobj_count
++;
2294 if (counts
->syncobj_count
) {
2295 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2296 if (!counts
->syncobj
)
2297 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2300 if (counts
->sem_count
) {
2301 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2303 free(counts
->syncobj
);
2304 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2308 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2309 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2311 if (sem
->temp_syncobj
) {
2312 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2314 else if (sem
->syncobj
)
2315 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2318 counts
->sem
[sem_idx
++] = sem
->sem
;
2322 if (_fence
!= VK_NULL_HANDLE
) {
2323 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2324 if (fence
->temp_syncobj
)
2325 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2326 else if (fence
->syncobj
)
2327 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2333 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2335 free(sem_info
->wait
.syncobj
);
2336 free(sem_info
->wait
.sem
);
2337 free(sem_info
->signal
.syncobj
);
2338 free(sem_info
->signal
.sem
);
2342 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2344 const VkSemaphore
*sems
)
2346 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2347 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2349 if (sem
->temp_syncobj
) {
2350 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2351 sem
->temp_syncobj
= 0;
2356 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2358 const VkSemaphore
*wait_sems
,
2359 int num_signal_sems
,
2360 const VkSemaphore
*signal_sems
,
2364 memset(sem_info
, 0, sizeof(*sem_info
));
2366 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2369 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2371 radv_free_sem_info(sem_info
);
2373 /* caller can override these */
2374 sem_info
->cs_emit_wait
= true;
2375 sem_info
->cs_emit_signal
= true;
2379 /* Signals fence as soon as all the work currently put on queue is done. */
2380 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2381 struct radv_fence
*fence
)
2385 struct radv_winsys_sem_info sem_info
;
2387 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2388 radv_fence_to_handle(fence
));
2389 if (result
!= VK_SUCCESS
)
2392 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2393 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2394 1, NULL
, NULL
, &sem_info
, NULL
,
2395 false, fence
->fence
);
2396 radv_free_sem_info(&sem_info
);
2398 /* TODO: find a better error */
2400 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2405 VkResult
radv_QueueSubmit(
2407 uint32_t submitCount
,
2408 const VkSubmitInfo
* pSubmits
,
2411 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2412 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2413 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2414 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2416 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2417 uint32_t scratch_size
= 0;
2418 uint32_t compute_scratch_size
= 0;
2419 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2420 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2422 bool fence_emitted
= false;
2423 bool tess_rings_needed
= false;
2424 bool sample_positions_needed
= false;
2426 /* Do this first so failing to allocate scratch buffers can't result in
2427 * partially executed submissions. */
2428 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2429 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2430 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2431 pSubmits
[i
].pCommandBuffers
[j
]);
2433 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2434 compute_scratch_size
= MAX2(compute_scratch_size
,
2435 cmd_buffer
->compute_scratch_size_needed
);
2436 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2437 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2438 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2439 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2443 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2444 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2445 sample_positions_needed
, &initial_flush_preamble_cs
,
2446 &initial_preamble_cs
, &continue_preamble_cs
);
2447 if (result
!= VK_SUCCESS
)
2450 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2451 struct radeon_winsys_cs
**cs_array
;
2452 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2453 bool can_patch
= true;
2455 struct radv_winsys_sem_info sem_info
;
2457 result
= radv_alloc_sem_info(&sem_info
,
2458 pSubmits
[i
].waitSemaphoreCount
,
2459 pSubmits
[i
].pWaitSemaphores
,
2460 pSubmits
[i
].signalSemaphoreCount
,
2461 pSubmits
[i
].pSignalSemaphores
,
2463 if (result
!= VK_SUCCESS
)
2466 if (!pSubmits
[i
].commandBufferCount
) {
2467 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2468 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2469 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2474 radv_loge("failed to submit CS %d\n", i
);
2477 fence_emitted
= true;
2479 radv_free_sem_info(&sem_info
);
2483 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2484 (pSubmits
[i
].commandBufferCount
));
2486 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2487 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2488 pSubmits
[i
].pCommandBuffers
[j
]);
2489 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2491 cs_array
[j
] = cmd_buffer
->cs
;
2492 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2495 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2498 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2499 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2500 advance
= MIN2(max_cs_submission
,
2501 pSubmits
[i
].commandBufferCount
- j
);
2503 if (queue
->device
->trace_bo
)
2504 *queue
->device
->trace_id_ptr
= 0;
2506 sem_info
.cs_emit_wait
= j
== 0;
2507 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2509 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2511 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2512 advance
, initial_preamble
, continue_preamble_cs
,
2513 &sem_info
, &queue
->device
->bo_list
.list
,
2514 can_patch
, base_fence
);
2516 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2519 radv_loge("failed to submit CS %d\n", i
);
2522 fence_emitted
= true;
2523 if (queue
->device
->trace_bo
) {
2524 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2528 radv_free_temp_syncobjs(queue
->device
,
2529 pSubmits
[i
].waitSemaphoreCount
,
2530 pSubmits
[i
].pWaitSemaphores
);
2531 radv_free_sem_info(&sem_info
);
2536 if (!fence_emitted
) {
2537 radv_signal_fence(queue
, fence
);
2539 fence
->submitted
= true;
2545 VkResult
radv_QueueWaitIdle(
2548 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2550 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2551 radv_queue_family_to_ring(queue
->queue_family_index
),
2556 VkResult
radv_DeviceWaitIdle(
2559 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2561 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2562 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2563 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2569 VkResult
radv_EnumerateInstanceExtensionProperties(
2570 const char* pLayerName
,
2571 uint32_t* pPropertyCount
,
2572 VkExtensionProperties
* pProperties
)
2574 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2576 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2577 if (radv_supported_instance_extensions
.extensions
[i
]) {
2578 vk_outarray_append(&out
, prop
) {
2579 *prop
= radv_instance_extensions
[i
];
2584 return vk_outarray_status(&out
);
2587 VkResult
radv_EnumerateDeviceExtensionProperties(
2588 VkPhysicalDevice physicalDevice
,
2589 const char* pLayerName
,
2590 uint32_t* pPropertyCount
,
2591 VkExtensionProperties
* pProperties
)
2593 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2594 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2596 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2597 if (device
->supported_extensions
.extensions
[i
]) {
2598 vk_outarray_append(&out
, prop
) {
2599 *prop
= radv_device_extensions
[i
];
2604 return vk_outarray_status(&out
);
2607 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2608 VkInstance _instance
,
2611 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2613 return radv_lookup_entrypoint_checked(pName
,
2614 instance
? instance
->apiVersion
: 0,
2615 instance
? &instance
->enabled_extensions
: NULL
,
2619 /* The loader wants us to expose a second GetInstanceProcAddr function
2620 * to work around certain LD_PRELOAD issues seen in apps.
2623 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2624 VkInstance instance
,
2628 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2629 VkInstance instance
,
2632 return radv_GetInstanceProcAddr(instance
, pName
);
2635 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2639 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2641 return radv_lookup_entrypoint_checked(pName
,
2642 device
->instance
->apiVersion
,
2643 &device
->instance
->enabled_extensions
,
2644 &device
->enabled_extensions
);
2647 bool radv_get_memory_fd(struct radv_device
*device
,
2648 struct radv_device_memory
*memory
,
2651 struct radeon_bo_metadata metadata
;
2653 if (memory
->image
) {
2654 radv_init_metadata(device
, memory
->image
, &metadata
);
2655 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2658 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2662 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2663 const VkMemoryAllocateInfo
* pAllocateInfo
,
2664 const VkAllocationCallbacks
* pAllocator
,
2665 VkDeviceMemory
* pMem
)
2667 struct radv_device_memory
*mem
;
2669 enum radeon_bo_domain domain
;
2671 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2673 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2675 if (pAllocateInfo
->allocationSize
== 0) {
2676 /* Apparently, this is allowed */
2677 *pMem
= VK_NULL_HANDLE
;
2681 const VkImportMemoryFdInfoKHR
*import_info
=
2682 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2683 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2684 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2685 const VkExportMemoryAllocateInfoKHR
*export_info
=
2686 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2687 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2688 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2690 const struct wsi_memory_allocate_info
*wsi_info
=
2691 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2693 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2694 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2696 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2698 if (wsi_info
&& wsi_info
->implicit_sync
)
2699 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2701 if (dedicate_info
) {
2702 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2703 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2709 mem
->user_ptr
= NULL
;
2712 assert(import_info
->handleType
==
2713 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2714 import_info
->handleType
==
2715 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2716 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2719 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2722 close(import_info
->fd
);
2724 } else if (host_ptr_info
) {
2725 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2726 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2727 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2728 pAllocateInfo
->allocationSize
);
2730 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2733 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2736 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2737 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2738 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2739 domain
= RADEON_DOMAIN_GTT
;
2741 domain
= RADEON_DOMAIN_VRAM
;
2743 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2744 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2746 flags
|= RADEON_FLAG_CPU_ACCESS
;
2748 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2749 flags
|= RADEON_FLAG_GTT_WC
;
2751 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2752 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2754 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2758 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2761 mem
->type_index
= mem_type_index
;
2764 result
= radv_bo_list_add(&device
->bo_list
, mem
->bo
);
2765 if (result
!= VK_SUCCESS
)
2768 *pMem
= radv_device_memory_to_handle(mem
);
2773 device
->ws
->buffer_destroy(mem
->bo
);
2775 vk_free2(&device
->alloc
, pAllocator
, mem
);
2780 VkResult
radv_AllocateMemory(
2782 const VkMemoryAllocateInfo
* pAllocateInfo
,
2783 const VkAllocationCallbacks
* pAllocator
,
2784 VkDeviceMemory
* pMem
)
2786 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2787 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2790 void radv_FreeMemory(
2792 VkDeviceMemory _mem
,
2793 const VkAllocationCallbacks
* pAllocator
)
2795 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2796 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2801 radv_bo_list_remove(&device
->bo_list
, mem
->bo
);
2802 device
->ws
->buffer_destroy(mem
->bo
);
2805 vk_free2(&device
->alloc
, pAllocator
, mem
);
2808 VkResult
radv_MapMemory(
2810 VkDeviceMemory _memory
,
2811 VkDeviceSize offset
,
2813 VkMemoryMapFlags flags
,
2816 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2817 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2825 *ppData
= mem
->user_ptr
;
2827 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2834 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2837 void radv_UnmapMemory(
2839 VkDeviceMemory _memory
)
2841 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2842 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2847 if (mem
->user_ptr
== NULL
)
2848 device
->ws
->buffer_unmap(mem
->bo
);
2851 VkResult
radv_FlushMappedMemoryRanges(
2853 uint32_t memoryRangeCount
,
2854 const VkMappedMemoryRange
* pMemoryRanges
)
2859 VkResult
radv_InvalidateMappedMemoryRanges(
2861 uint32_t memoryRangeCount
,
2862 const VkMappedMemoryRange
* pMemoryRanges
)
2867 void radv_GetBufferMemoryRequirements(
2870 VkMemoryRequirements
* pMemoryRequirements
)
2872 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2873 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2875 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2877 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2878 pMemoryRequirements
->alignment
= 4096;
2880 pMemoryRequirements
->alignment
= 16;
2882 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2885 void radv_GetBufferMemoryRequirements2(
2887 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2888 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2890 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2891 &pMemoryRequirements
->memoryRequirements
);
2892 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2893 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2894 switch (ext
->sType
) {
2895 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2896 VkMemoryDedicatedRequirementsKHR
*req
=
2897 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2898 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2899 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2908 void radv_GetImageMemoryRequirements(
2911 VkMemoryRequirements
* pMemoryRequirements
)
2913 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2914 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2916 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2918 pMemoryRequirements
->size
= image
->size
;
2919 pMemoryRequirements
->alignment
= image
->alignment
;
2922 void radv_GetImageMemoryRequirements2(
2924 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2925 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2927 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2928 &pMemoryRequirements
->memoryRequirements
);
2930 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2932 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2933 switch (ext
->sType
) {
2934 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2935 VkMemoryDedicatedRequirementsKHR
*req
=
2936 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2937 req
->requiresDedicatedAllocation
= image
->shareable
;
2938 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2947 void radv_GetImageSparseMemoryRequirements(
2950 uint32_t* pSparseMemoryRequirementCount
,
2951 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2956 void radv_GetImageSparseMemoryRequirements2(
2958 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2959 uint32_t* pSparseMemoryRequirementCount
,
2960 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2965 void radv_GetDeviceMemoryCommitment(
2967 VkDeviceMemory memory
,
2968 VkDeviceSize
* pCommittedMemoryInBytes
)
2970 *pCommittedMemoryInBytes
= 0;
2973 VkResult
radv_BindBufferMemory2(VkDevice device
,
2974 uint32_t bindInfoCount
,
2975 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2977 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2978 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2979 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2982 buffer
->bo
= mem
->bo
;
2983 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2991 VkResult
radv_BindBufferMemory(
2994 VkDeviceMemory memory
,
2995 VkDeviceSize memoryOffset
)
2997 const VkBindBufferMemoryInfoKHR info
= {
2998 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3001 .memoryOffset
= memoryOffset
3004 return radv_BindBufferMemory2(device
, 1, &info
);
3007 VkResult
radv_BindImageMemory2(VkDevice device
,
3008 uint32_t bindInfoCount
,
3009 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3011 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3012 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3013 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3016 image
->bo
= mem
->bo
;
3017 image
->offset
= pBindInfos
[i
].memoryOffset
;
3027 VkResult
radv_BindImageMemory(
3030 VkDeviceMemory memory
,
3031 VkDeviceSize memoryOffset
)
3033 const VkBindImageMemoryInfoKHR info
= {
3034 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3037 .memoryOffset
= memoryOffset
3040 return radv_BindImageMemory2(device
, 1, &info
);
3045 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3046 const VkSparseBufferMemoryBindInfo
*bind
)
3048 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3050 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3051 struct radv_device_memory
*mem
= NULL
;
3053 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3054 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3056 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3057 bind
->pBinds
[i
].resourceOffset
,
3058 bind
->pBinds
[i
].size
,
3059 mem
? mem
->bo
: NULL
,
3060 bind
->pBinds
[i
].memoryOffset
);
3065 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3066 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3068 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3070 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3071 struct radv_device_memory
*mem
= NULL
;
3073 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3074 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3076 device
->ws
->buffer_virtual_bind(image
->bo
,
3077 bind
->pBinds
[i
].resourceOffset
,
3078 bind
->pBinds
[i
].size
,
3079 mem
? mem
->bo
: NULL
,
3080 bind
->pBinds
[i
].memoryOffset
);
3084 VkResult
radv_QueueBindSparse(
3086 uint32_t bindInfoCount
,
3087 const VkBindSparseInfo
* pBindInfo
,
3090 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3091 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3092 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3093 bool fence_emitted
= false;
3095 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3096 struct radv_winsys_sem_info sem_info
;
3097 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3098 radv_sparse_buffer_bind_memory(queue
->device
,
3099 pBindInfo
[i
].pBufferBinds
+ j
);
3102 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3103 radv_sparse_image_opaque_bind_memory(queue
->device
,
3104 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3108 result
= radv_alloc_sem_info(&sem_info
,
3109 pBindInfo
[i
].waitSemaphoreCount
,
3110 pBindInfo
[i
].pWaitSemaphores
,
3111 pBindInfo
[i
].signalSemaphoreCount
,
3112 pBindInfo
[i
].pSignalSemaphores
,
3114 if (result
!= VK_SUCCESS
)
3117 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3118 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3119 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3123 fence_emitted
= true;
3125 fence
->submitted
= true;
3128 radv_free_sem_info(&sem_info
);
3133 if (!fence_emitted
) {
3134 radv_signal_fence(queue
, fence
);
3136 fence
->submitted
= true;
3142 VkResult
radv_CreateFence(
3144 const VkFenceCreateInfo
* pCreateInfo
,
3145 const VkAllocationCallbacks
* pAllocator
,
3148 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3149 const VkExportFenceCreateInfoKHR
*export
=
3150 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3151 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3152 export
? export
->handleTypes
: 0;
3154 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3156 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3159 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3161 fence
->submitted
= false;
3162 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3163 fence
->temp_syncobj
= 0;
3164 if (device
->always_use_syncobj
|| handleTypes
) {
3165 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3167 vk_free2(&device
->alloc
, pAllocator
, fence
);
3168 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3170 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3171 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3173 fence
->fence
= NULL
;
3175 fence
->fence
= device
->ws
->create_fence();
3176 if (!fence
->fence
) {
3177 vk_free2(&device
->alloc
, pAllocator
, fence
);
3178 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3183 *pFence
= radv_fence_to_handle(fence
);
3188 void radv_DestroyFence(
3191 const VkAllocationCallbacks
* pAllocator
)
3193 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3194 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3199 if (fence
->temp_syncobj
)
3200 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3202 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3204 device
->ws
->destroy_fence(fence
->fence
);
3205 vk_free2(&device
->alloc
, pAllocator
, fence
);
3209 static uint64_t radv_get_current_time()
3212 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3213 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3216 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3218 uint64_t current_time
= radv_get_current_time();
3220 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3222 return current_time
+ timeout
;
3226 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3228 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3229 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3230 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3236 VkResult
radv_WaitForFences(
3238 uint32_t fenceCount
,
3239 const VkFence
* pFences
,
3243 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3244 timeout
= radv_get_absolute_timeout(timeout
);
3246 if (device
->always_use_syncobj
) {
3247 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3249 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3251 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3252 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3253 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3256 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3259 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3262 if (!waitAll
&& fenceCount
> 1) {
3263 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3264 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3265 uint32_t wait_count
= 0;
3266 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3268 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3270 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3271 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3273 if (fence
->signalled
) {
3278 fences
[wait_count
++] = fence
->fence
;
3281 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3282 waitAll
, timeout
- radv_get_current_time());
3285 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3288 while(radv_get_current_time() <= timeout
) {
3289 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3290 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3297 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3298 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3299 bool expired
= false;
3301 if (fence
->temp_syncobj
) {
3302 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3307 if (fence
->syncobj
) {
3308 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3313 if (fence
->signalled
)
3316 if (!fence
->submitted
) {
3317 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3320 if (!fence
->submitted
)
3323 /* Recheck as it may have been set by submitting operations. */
3324 if (fence
->signalled
)
3328 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3332 fence
->signalled
= true;
3338 VkResult
radv_ResetFences(VkDevice _device
,
3339 uint32_t fenceCount
,
3340 const VkFence
*pFences
)
3342 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3344 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3345 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3346 fence
->submitted
= fence
->signalled
= false;
3348 /* Per spec, we first restore the permanent payload, and then reset, so
3349 * having a temp syncobj should not skip resetting the permanent syncobj. */
3350 if (fence
->temp_syncobj
) {
3351 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3352 fence
->temp_syncobj
= 0;
3355 if (fence
->syncobj
) {
3356 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3363 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3365 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3366 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3368 if (fence
->temp_syncobj
) {
3369 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3370 return success
? VK_SUCCESS
: VK_NOT_READY
;
3373 if (fence
->syncobj
) {
3374 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3375 return success
? VK_SUCCESS
: VK_NOT_READY
;
3378 if (fence
->signalled
)
3380 if (!fence
->submitted
)
3381 return VK_NOT_READY
;
3382 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3383 return VK_NOT_READY
;
3389 // Queue semaphore functions
3391 VkResult
radv_CreateSemaphore(
3393 const VkSemaphoreCreateInfo
* pCreateInfo
,
3394 const VkAllocationCallbacks
* pAllocator
,
3395 VkSemaphore
* pSemaphore
)
3397 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3398 const VkExportSemaphoreCreateInfoKHR
*export
=
3399 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3400 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3401 export
? export
->handleTypes
: 0;
3403 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3405 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3407 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3409 sem
->temp_syncobj
= 0;
3410 /* create a syncobject if we are going to export this semaphore */
3411 if (device
->always_use_syncobj
|| handleTypes
) {
3412 assert (device
->physical_device
->rad_info
.has_syncobj
);
3413 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3415 vk_free2(&device
->alloc
, pAllocator
, sem
);
3416 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3420 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3422 vk_free2(&device
->alloc
, pAllocator
, sem
);
3423 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3428 *pSemaphore
= radv_semaphore_to_handle(sem
);
3432 void radv_DestroySemaphore(
3434 VkSemaphore _semaphore
,
3435 const VkAllocationCallbacks
* pAllocator
)
3437 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3438 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3443 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3445 device
->ws
->destroy_sem(sem
->sem
);
3446 vk_free2(&device
->alloc
, pAllocator
, sem
);
3449 VkResult
radv_CreateEvent(
3451 const VkEventCreateInfo
* pCreateInfo
,
3452 const VkAllocationCallbacks
* pAllocator
,
3455 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3456 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3458 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3461 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3463 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3465 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3467 vk_free2(&device
->alloc
, pAllocator
, event
);
3468 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3471 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3473 *pEvent
= radv_event_to_handle(event
);
3478 void radv_DestroyEvent(
3481 const VkAllocationCallbacks
* pAllocator
)
3483 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3484 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3488 device
->ws
->buffer_destroy(event
->bo
);
3489 vk_free2(&device
->alloc
, pAllocator
, event
);
3492 VkResult
radv_GetEventStatus(
3496 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3498 if (*event
->map
== 1)
3499 return VK_EVENT_SET
;
3500 return VK_EVENT_RESET
;
3503 VkResult
radv_SetEvent(
3507 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3513 VkResult
radv_ResetEvent(
3517 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3523 VkResult
radv_CreateBuffer(
3525 const VkBufferCreateInfo
* pCreateInfo
,
3526 const VkAllocationCallbacks
* pAllocator
,
3529 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3530 struct radv_buffer
*buffer
;
3532 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3534 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3535 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3537 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3539 buffer
->size
= pCreateInfo
->size
;
3540 buffer
->usage
= pCreateInfo
->usage
;
3543 buffer
->flags
= pCreateInfo
->flags
;
3545 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3546 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3548 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3549 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3550 align64(buffer
->size
, 4096),
3551 4096, 0, RADEON_FLAG_VIRTUAL
);
3553 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3554 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3558 *pBuffer
= radv_buffer_to_handle(buffer
);
3563 void radv_DestroyBuffer(
3566 const VkAllocationCallbacks
* pAllocator
)
3568 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3569 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3574 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3575 device
->ws
->buffer_destroy(buffer
->bo
);
3577 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3580 static inline unsigned
3581 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3584 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3586 return image
->surface
.u
.legacy
.tiling_index
[level
];
3589 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3591 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3595 radv_init_dcc_control_reg(struct radv_device
*device
,
3596 struct radv_image_view
*iview
)
3598 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3599 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3600 unsigned max_compressed_block_size
;
3601 unsigned independent_64b_blocks
;
3603 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3606 if (iview
->image
->info
.samples
> 1) {
3607 if (iview
->image
->surface
.bpe
== 1)
3608 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3609 else if (iview
->image
->surface
.bpe
== 2)
3610 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3613 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3614 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3615 * dGPU and 64 for APU because all of our APUs to date use
3616 * DIMMs which have a request granularity size of 64B while all
3617 * other chips have a 32B request size.
3619 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3622 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3623 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3624 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3625 /* If this DCC image is potentially going to be used in texture
3626 * fetches, we need some special settings.
3628 independent_64b_blocks
= 1;
3629 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3631 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3632 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3633 * big as possible for better compression state.
3635 independent_64b_blocks
= 0;
3636 max_compressed_block_size
= max_uncompressed_block_size
;
3639 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3640 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3641 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3642 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3646 radv_initialise_color_surface(struct radv_device
*device
,
3647 struct radv_color_buffer_info
*cb
,
3648 struct radv_image_view
*iview
)
3650 const struct vk_format_description
*desc
;
3651 unsigned ntype
, format
, swap
, endian
;
3652 unsigned blend_clamp
= 0, blend_bypass
= 0;
3654 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3656 desc
= vk_format_description(iview
->vk_format
);
3658 memset(cb
, 0, sizeof(*cb
));
3660 /* Intensity is implemented as Red, so treat it that way. */
3661 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3663 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3665 cb
->cb_color_base
= va
>> 8;
3667 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3668 struct gfx9_surf_meta_flags meta
;
3669 if (iview
->image
->dcc_offset
)
3670 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3672 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3674 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3675 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3676 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3677 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3679 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3680 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3682 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3683 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3685 cb
->cb_color_base
+= level_info
->offset
>> 8;
3686 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3687 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3689 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3690 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3691 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3693 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3694 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3695 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3697 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3699 if (radv_image_has_fmask(iview
->image
)) {
3700 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3701 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3702 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3703 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3705 /* This must be set for fast clear to work without FMASK. */
3706 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3707 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3708 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3709 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3713 /* CMASK variables */
3714 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3715 va
+= iview
->image
->cmask
.offset
;
3716 cb
->cb_color_cmask
= va
>> 8;
3718 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3719 va
+= iview
->image
->dcc_offset
;
3720 cb
->cb_dcc_base
= va
>> 8;
3721 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3723 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3724 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3725 S_028C6C_SLICE_MAX(max_slice
);
3727 if (iview
->image
->info
.samples
> 1) {
3728 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3730 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3731 S_028C74_NUM_FRAGMENTS(log_samples
);
3734 if (radv_image_has_fmask(iview
->image
)) {
3735 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3736 cb
->cb_color_fmask
= va
>> 8;
3737 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3739 cb
->cb_color_fmask
= cb
->cb_color_base
;
3742 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3744 vk_format_get_first_non_void_channel(iview
->vk_format
));
3745 format
= radv_translate_colorformat(iview
->vk_format
);
3746 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3747 radv_finishme("Illegal color\n");
3748 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3749 endian
= radv_colorformat_endian_swap(format
);
3751 /* blend clamp should be set for all NORM/SRGB types */
3752 if (ntype
== V_028C70_NUMBER_UNORM
||
3753 ntype
== V_028C70_NUMBER_SNORM
||
3754 ntype
== V_028C70_NUMBER_SRGB
)
3757 /* set blend bypass according to docs if SINT/UINT or
3758 8/24 COLOR variants */
3759 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3760 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3761 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3766 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3767 (format
== V_028C70_COLOR_8
||
3768 format
== V_028C70_COLOR_8_8
||
3769 format
== V_028C70_COLOR_8_8_8_8
))
3770 ->color_is_int8
= true;
3772 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3773 S_028C70_COMP_SWAP(swap
) |
3774 S_028C70_BLEND_CLAMP(blend_clamp
) |
3775 S_028C70_BLEND_BYPASS(blend_bypass
) |
3776 S_028C70_SIMPLE_FLOAT(1) |
3777 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3778 ntype
!= V_028C70_NUMBER_SNORM
&&
3779 ntype
!= V_028C70_NUMBER_SRGB
&&
3780 format
!= V_028C70_COLOR_8_24
&&
3781 format
!= V_028C70_COLOR_24_8
) |
3782 S_028C70_NUMBER_TYPE(ntype
) |
3783 S_028C70_ENDIAN(endian
);
3784 if (radv_image_has_fmask(iview
->image
)) {
3785 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3786 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3787 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3788 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3792 if (radv_image_has_cmask(iview
->image
) &&
3793 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3794 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3796 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3797 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3799 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3801 /* This must be set for fast clear to work without FMASK. */
3802 if (!radv_image_has_fmask(iview
->image
) &&
3803 device
->physical_device
->rad_info
.chip_class
== SI
) {
3804 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3805 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3808 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3809 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3810 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3812 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3813 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3814 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3815 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3816 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3817 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3822 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3823 struct radv_image_view
*iview
)
3825 unsigned max_zplanes
= 0;
3827 assert(radv_image_is_tc_compat_htile(iview
->image
));
3829 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3830 /* Default value for 32-bit depth surfaces. */
3833 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3834 iview
->image
->info
.samples
> 1)
3837 max_zplanes
= max_zplanes
+ 1;
3839 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3840 /* Do not enable Z plane compression for 16-bit depth
3841 * surfaces because isn't supported on GFX8. Only
3842 * 32-bit depth surfaces are supported by the hardware.
3843 * This allows to maintain shader compatibility and to
3844 * reduce the number of depth decompressions.
3848 if (iview
->image
->info
.samples
<= 1)
3850 else if (iview
->image
->info
.samples
<= 4)
3861 radv_initialise_ds_surface(struct radv_device
*device
,
3862 struct radv_ds_buffer_info
*ds
,
3863 struct radv_image_view
*iview
)
3865 unsigned level
= iview
->base_mip
;
3866 unsigned format
, stencil_format
;
3867 uint64_t va
, s_offs
, z_offs
;
3868 bool stencil_only
= false;
3869 memset(ds
, 0, sizeof(*ds
));
3870 switch (iview
->image
->vk_format
) {
3871 case VK_FORMAT_D24_UNORM_S8_UINT
:
3872 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3873 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3874 ds
->offset_scale
= 2.0f
;
3876 case VK_FORMAT_D16_UNORM
:
3877 case VK_FORMAT_D16_UNORM_S8_UINT
:
3878 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3879 ds
->offset_scale
= 4.0f
;
3881 case VK_FORMAT_D32_SFLOAT
:
3882 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3883 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3884 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3885 ds
->offset_scale
= 1.0f
;
3887 case VK_FORMAT_S8_UINT
:
3888 stencil_only
= true;
3894 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3895 stencil_format
= iview
->image
->surface
.has_stencil
?
3896 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3898 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3899 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3900 S_028008_SLICE_MAX(max_slice
);
3902 ds
->db_htile_data_base
= 0;
3903 ds
->db_htile_surface
= 0;
3905 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3906 s_offs
= z_offs
= va
;
3908 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3909 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3910 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3912 ds
->db_z_info
= S_028038_FORMAT(format
) |
3913 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3914 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3915 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3916 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3917 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3919 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3920 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3921 ds
->db_depth_view
|= S_028008_MIPID(level
);
3923 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3924 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3926 if (radv_htile_enabled(iview
->image
, level
)) {
3927 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3929 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3930 unsigned max_zplanes
=
3931 radv_calc_decompress_on_z_planes(device
, iview
);
3933 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3934 S_028038_ITERATE_FLUSH(1);
3935 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3938 if (!iview
->image
->surface
.has_stencil
)
3939 /* Use all of the htile_buffer for depth if there's no stencil. */
3940 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3941 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3942 iview
->image
->htile_offset
;
3943 ds
->db_htile_data_base
= va
>> 8;
3944 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3945 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3946 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3949 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3952 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3954 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3955 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3957 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3958 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3959 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3961 if (iview
->image
->info
.samples
> 1)
3962 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3964 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3965 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3966 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3967 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3968 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3969 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3970 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3971 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3974 tile_mode
= stencil_tile_mode
;
3976 ds
->db_depth_info
|=
3977 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3978 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3979 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3980 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3981 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3982 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3983 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3984 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3986 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3987 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3988 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3989 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3991 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3994 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3995 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3996 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3998 if (radv_htile_enabled(iview
->image
, level
)) {
3999 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4001 if (!iview
->image
->surface
.has_stencil
&&
4002 !radv_image_is_tc_compat_htile(iview
->image
))
4003 /* Use all of the htile_buffer for depth if there's no stencil. */
4004 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4006 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4007 iview
->image
->htile_offset
;
4008 ds
->db_htile_data_base
= va
>> 8;
4009 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4011 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4012 unsigned max_zplanes
=
4013 radv_calc_decompress_on_z_planes(device
, iview
);
4015 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4016 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4021 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4022 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4025 VkResult
radv_CreateFramebuffer(
4027 const VkFramebufferCreateInfo
* pCreateInfo
,
4028 const VkAllocationCallbacks
* pAllocator
,
4029 VkFramebuffer
* pFramebuffer
)
4031 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4032 struct radv_framebuffer
*framebuffer
;
4034 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4036 size_t size
= sizeof(*framebuffer
) +
4037 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4038 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4039 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4040 if (framebuffer
== NULL
)
4041 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4043 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4044 framebuffer
->width
= pCreateInfo
->width
;
4045 framebuffer
->height
= pCreateInfo
->height
;
4046 framebuffer
->layers
= pCreateInfo
->layers
;
4047 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4048 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4049 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4050 framebuffer
->attachments
[i
].attachment
= iview
;
4051 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4052 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4053 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4054 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4056 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4057 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4058 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4061 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4065 void radv_DestroyFramebuffer(
4068 const VkAllocationCallbacks
* pAllocator
)
4070 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4071 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4075 vk_free2(&device
->alloc
, pAllocator
, fb
);
4078 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4080 switch (address_mode
) {
4081 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4082 return V_008F30_SQ_TEX_WRAP
;
4083 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4084 return V_008F30_SQ_TEX_MIRROR
;
4085 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4086 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4087 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4088 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4089 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4090 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4092 unreachable("illegal tex wrap mode");
4098 radv_tex_compare(VkCompareOp op
)
4101 case VK_COMPARE_OP_NEVER
:
4102 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4103 case VK_COMPARE_OP_LESS
:
4104 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4105 case VK_COMPARE_OP_EQUAL
:
4106 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4107 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4108 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4109 case VK_COMPARE_OP_GREATER
:
4110 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4111 case VK_COMPARE_OP_NOT_EQUAL
:
4112 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4113 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4114 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4115 case VK_COMPARE_OP_ALWAYS
:
4116 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4118 unreachable("illegal compare mode");
4124 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4127 case VK_FILTER_NEAREST
:
4128 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4129 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4130 case VK_FILTER_LINEAR
:
4131 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4132 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4133 case VK_FILTER_CUBIC_IMG
:
4135 fprintf(stderr
, "illegal texture filter");
4141 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4144 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4145 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4146 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4147 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4149 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4154 radv_tex_bordercolor(VkBorderColor bcolor
)
4157 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4158 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4159 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4160 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4161 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4162 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4163 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4164 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4165 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4173 radv_tex_aniso_filter(unsigned filter
)
4187 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4190 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4191 return SQ_IMG_FILTER_MODE_BLEND
;
4192 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4193 return SQ_IMG_FILTER_MODE_MIN
;
4194 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4195 return SQ_IMG_FILTER_MODE_MAX
;
4203 radv_init_sampler(struct radv_device
*device
,
4204 struct radv_sampler
*sampler
,
4205 const VkSamplerCreateInfo
*pCreateInfo
)
4207 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4208 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4209 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4210 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4211 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4213 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4214 vk_find_struct_const(pCreateInfo
->pNext
,
4215 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4216 if (sampler_reduction
)
4217 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4219 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4220 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4221 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4222 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4223 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4224 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4225 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4226 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4227 S_008F30_DISABLE_CUBE_WRAP(0) |
4228 S_008F30_COMPAT_MODE(is_vi
) |
4229 S_008F30_FILTER_MODE(filter_mode
));
4230 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4231 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4232 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4233 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4234 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4235 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4236 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4237 S_008F38_MIP_POINT_PRECLAMP(0) |
4238 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4239 S_008F38_FILTER_PREC_FIX(1) |
4240 S_008F38_ANISO_OVERRIDE(is_vi
));
4241 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4242 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4245 VkResult
radv_CreateSampler(
4247 const VkSamplerCreateInfo
* pCreateInfo
,
4248 const VkAllocationCallbacks
* pAllocator
,
4249 VkSampler
* pSampler
)
4251 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4252 struct radv_sampler
*sampler
;
4254 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4256 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4257 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4259 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4261 radv_init_sampler(device
, sampler
, pCreateInfo
);
4262 *pSampler
= radv_sampler_to_handle(sampler
);
4267 void radv_DestroySampler(
4270 const VkAllocationCallbacks
* pAllocator
)
4272 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4273 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4277 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4280 /* vk_icd.h does not declare this function, so we declare it here to
4281 * suppress Wmissing-prototypes.
4283 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4284 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4286 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4287 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4289 /* For the full details on loader interface versioning, see
4290 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4291 * What follows is a condensed summary, to help you navigate the large and
4292 * confusing official doc.
4294 * - Loader interface v0 is incompatible with later versions. We don't
4297 * - In loader interface v1:
4298 * - The first ICD entrypoint called by the loader is
4299 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4301 * - The ICD must statically expose no other Vulkan symbol unless it is
4302 * linked with -Bsymbolic.
4303 * - Each dispatchable Vulkan handle created by the ICD must be
4304 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4305 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4306 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4307 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4308 * such loader-managed surfaces.
4310 * - Loader interface v2 differs from v1 in:
4311 * - The first ICD entrypoint called by the loader is
4312 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4313 * statically expose this entrypoint.
4315 * - Loader interface v3 differs from v2 in:
4316 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4317 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4318 * because the loader no longer does so.
4320 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4324 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4325 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4328 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4329 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4331 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4333 /* At the moment, we support only the below handle types. */
4334 assert(pGetFdInfo
->handleType
==
4335 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4336 pGetFdInfo
->handleType
==
4337 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4339 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4341 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4345 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4346 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4348 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4350 switch (handleType
) {
4351 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4352 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4356 /* The valid usage section for this function says:
4358 * "handleType must not be one of the handle types defined as
4361 * So opaque handle types fall into the default "unsupported" case.
4363 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4367 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4371 uint32_t syncobj_handle
= 0;
4372 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4374 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4377 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4379 *syncobj
= syncobj_handle
;
4385 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4389 /* If we create a syncobj we do it locally so that if we have an error, we don't
4390 * leave a syncobj in an undetermined state in the fence. */
4391 uint32_t syncobj_handle
= *syncobj
;
4392 if (!syncobj_handle
) {
4393 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4395 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4400 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4402 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4404 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4407 *syncobj
= syncobj_handle
;
4414 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4415 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4417 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4418 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4419 uint32_t *syncobj_dst
= NULL
;
4421 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4422 syncobj_dst
= &sem
->temp_syncobj
;
4424 syncobj_dst
= &sem
->syncobj
;
4427 switch(pImportSemaphoreFdInfo
->handleType
) {
4428 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4429 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4430 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4431 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4433 unreachable("Unhandled semaphore handle type");
4437 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4438 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4441 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4442 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4444 uint32_t syncobj_handle
;
4446 if (sem
->temp_syncobj
)
4447 syncobj_handle
= sem
->temp_syncobj
;
4449 syncobj_handle
= sem
->syncobj
;
4451 switch(pGetFdInfo
->handleType
) {
4452 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4453 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4455 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4456 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4458 if (sem
->temp_syncobj
) {
4459 close (sem
->temp_syncobj
);
4460 sem
->temp_syncobj
= 0;
4462 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4467 unreachable("Unhandled semaphore handle type");
4471 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4475 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4476 VkPhysicalDevice physicalDevice
,
4477 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4478 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4480 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4482 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4483 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4484 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4485 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4486 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4487 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4488 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4489 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4490 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4491 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4492 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4493 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4494 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4496 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4497 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4498 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4502 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4503 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4505 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4506 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4507 uint32_t *syncobj_dst
= NULL
;
4510 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4511 syncobj_dst
= &fence
->temp_syncobj
;
4513 syncobj_dst
= &fence
->syncobj
;
4516 switch(pImportFenceFdInfo
->handleType
) {
4517 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4518 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4519 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4520 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4522 unreachable("Unhandled fence handle type");
4526 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4527 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4530 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4531 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4533 uint32_t syncobj_handle
;
4535 if (fence
->temp_syncobj
)
4536 syncobj_handle
= fence
->temp_syncobj
;
4538 syncobj_handle
= fence
->syncobj
;
4540 switch(pGetFdInfo
->handleType
) {
4541 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4542 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4544 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4545 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4547 if (fence
->temp_syncobj
) {
4548 close (fence
->temp_syncobj
);
4549 fence
->temp_syncobj
= 0;
4551 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4556 unreachable("Unhandled fence handle type");
4560 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4564 void radv_GetPhysicalDeviceExternalFenceProperties(
4565 VkPhysicalDevice physicalDevice
,
4566 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4567 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4569 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4571 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4572 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4573 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4574 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4575 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4576 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4577 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4579 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4580 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4581 pExternalFenceProperties
->externalFenceFeatures
= 0;
4586 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4587 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4588 const VkAllocationCallbacks
* pAllocator
,
4589 VkDebugReportCallbackEXT
* pCallback
)
4591 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4592 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4593 pCreateInfo
, pAllocator
, &instance
->alloc
,
4598 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4599 VkDebugReportCallbackEXT _callback
,
4600 const VkAllocationCallbacks
* pAllocator
)
4602 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4603 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4604 _callback
, pAllocator
, &instance
->alloc
);
4608 radv_DebugReportMessageEXT(VkInstance _instance
,
4609 VkDebugReportFlagsEXT flags
,
4610 VkDebugReportObjectTypeEXT objectType
,
4613 int32_t messageCode
,
4614 const char* pLayerPrefix
,
4615 const char* pMessage
)
4617 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4618 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4619 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4623 radv_GetDeviceGroupPeerMemoryFeatures(
4626 uint32_t localDeviceIndex
,
4627 uint32_t remoteDeviceIndex
,
4628 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4630 assert(localDeviceIndex
== remoteDeviceIndex
);
4632 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4633 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4634 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4635 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;