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_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
105 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
106 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
107 default: chip_string
= "AMD RADV unknown"; break;
111 snprintf(llvm_string
, sizeof(llvm_string
),
112 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
113 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
116 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
120 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
122 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
123 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
124 device
->rad_info
.vram_vis_size
);
126 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
127 device
->memory_properties
.memoryHeapCount
= 0;
128 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
129 vram_index
= device
->memory_properties
.memoryHeapCount
++;
130 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
131 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
132 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
135 if (visible_vram_size
) {
136 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
137 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
138 .size
= visible_vram_size
,
139 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
142 if (device
->rad_info
.gart_size
> 0) {
143 gart_index
= device
->memory_properties
.memoryHeapCount
++;
144 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
145 .size
= device
->rad_info
.gart_size
,
150 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
151 unsigned type_count
= 0;
152 if (vram_index
>= 0) {
153 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
154 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
155 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
156 .heapIndex
= vram_index
,
159 if (gart_index
>= 0) {
160 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
161 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
162 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
163 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
164 .heapIndex
= gart_index
,
167 if (visible_vram_index
>= 0) {
168 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
169 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
170 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
171 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
172 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
173 .heapIndex
= visible_vram_index
,
176 if (gart_index
>= 0) {
177 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
178 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
179 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
181 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
182 .heapIndex
= gart_index
,
185 device
->memory_properties
.memoryTypeCount
= type_count
;
189 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
191 const char *family
= getenv("RADV_FORCE_FAMILY");
197 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
198 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
199 /* Override family and chip_class. */
200 device
->rad_info
.family
= i
;
202 if (i
>= CHIP_VEGA10
)
203 device
->rad_info
.chip_class
= GFX9
;
204 else if (i
>= CHIP_TONGA
)
205 device
->rad_info
.chip_class
= VI
;
206 else if (i
>= CHIP_BONAIRE
)
207 device
->rad_info
.chip_class
= CIK
;
209 device
->rad_info
.chip_class
= SI
;
215 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
220 radv_physical_device_init(struct radv_physical_device
*device
,
221 struct radv_instance
*instance
,
222 drmDevicePtr drm_device
)
224 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
226 drmVersionPtr version
;
229 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
231 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
233 version
= drmGetVersion(fd
);
236 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
237 "failed to get version %s: %m", path
);
240 if (strcmp(version
->name
, "amdgpu")) {
241 drmFreeVersion(version
);
243 return VK_ERROR_INCOMPATIBLE_DRIVER
;
245 drmFreeVersion(version
);
247 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
248 device
->instance
= instance
;
249 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
250 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
252 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
253 instance
->perftest_flags
);
255 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
259 device
->local_fd
= fd
;
260 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
262 radv_handle_env_var_force_family(device
);
264 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
266 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
267 device
->ws
->destroy(device
->ws
);
268 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
269 "cannot generate UUID");
273 /* These flags affect shader compilation. */
274 uint64_t shader_env_flags
=
275 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
276 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
278 /* The gpu id is already embeded in the uuid so we just pass "radv"
279 * when creating the cache.
281 char buf
[VK_UUID_SIZE
* 2 + 1];
282 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
283 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
285 if (device
->rad_info
.chip_class
< VI
||
286 device
->rad_info
.chip_class
> GFX9
)
287 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
289 radv_get_driver_uuid(&device
->device_uuid
);
290 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
292 if (device
->rad_info
.family
== CHIP_STONEY
||
293 device
->rad_info
.chip_class
>= GFX9
) {
294 device
->has_rbplus
= true;
295 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
296 device
->rad_info
.family
== CHIP_VEGA12
||
297 device
->rad_info
.family
== CHIP_RAVEN
;
300 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
303 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
305 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
307 /* Vega10/Raven need a special workaround for a hardware bug. */
308 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
309 device
->rad_info
.family
== CHIP_RAVEN
;
311 /* Out-of-order primitive rasterization. */
312 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
313 device
->rad_info
.max_se
>= 2;
314 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
315 (device
->instance
->perftest_flags
& RADV_PERFTEST_OUT_OF_ORDER
);
317 radv_physical_device_init_mem_types(device
);
318 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
320 result
= radv_init_wsi(device
);
321 if (result
!= VK_SUCCESS
) {
322 device
->ws
->destroy(device
->ws
);
334 radv_physical_device_finish(struct radv_physical_device
*device
)
336 radv_finish_wsi(device
);
337 device
->ws
->destroy(device
->ws
);
338 disk_cache_destroy(device
->disk_cache
);
339 close(device
->local_fd
);
343 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
344 VkSystemAllocationScope allocationScope
)
350 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
351 size_t align
, VkSystemAllocationScope allocationScope
)
353 return realloc(pOriginal
, size
);
357 default_free_func(void *pUserData
, void *pMemory
)
362 static const VkAllocationCallbacks default_alloc
= {
364 .pfnAllocation
= default_alloc_func
,
365 .pfnReallocation
= default_realloc_func
,
366 .pfnFree
= default_free_func
,
369 static const struct debug_control radv_debug_options
[] = {
370 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
371 {"nodcc", RADV_DEBUG_NO_DCC
},
372 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
373 {"nocache", RADV_DEBUG_NO_CACHE
},
374 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
375 {"nohiz", RADV_DEBUG_NO_HIZ
},
376 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
377 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
378 {"allbos", RADV_DEBUG_ALL_BOS
},
379 {"noibs", RADV_DEBUG_NO_IBS
},
380 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
381 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
382 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
383 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
384 {"nosisched", RADV_DEBUG_NO_SISCHED
},
385 {"preoptir", RADV_DEBUG_PREOPTIR
},
390 radv_get_debug_option_name(int id
)
392 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
393 return radv_debug_options
[id
].string
;
396 static const struct debug_control radv_perftest_options
[] = {
397 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
398 {"sisched", RADV_PERFTEST_SISCHED
},
399 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
400 {"binning", RADV_PERFTEST_BINNING
},
401 {"outoforderrast", RADV_PERFTEST_OUT_OF_ORDER
},
406 radv_get_perftest_option_name(int id
)
408 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
409 return radv_perftest_options
[id
].string
;
413 radv_handle_per_app_options(struct radv_instance
*instance
,
414 const VkApplicationInfo
*info
)
416 const char *name
= info
? info
->pApplicationName
: NULL
;
421 if (!strcmp(name
, "Talos - Linux - 32bit") ||
422 !strcmp(name
, "Talos - Linux - 64bit")) {
423 /* Force enable LLVM sisched for Talos because it looks safe
424 * and it gives few more FPS.
426 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
430 static int radv_get_instance_extension_index(const char *name
)
432 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
433 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
440 VkResult
radv_CreateInstance(
441 const VkInstanceCreateInfo
* pCreateInfo
,
442 const VkAllocationCallbacks
* pAllocator
,
443 VkInstance
* pInstance
)
445 struct radv_instance
*instance
;
448 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
450 uint32_t client_version
;
451 if (pCreateInfo
->pApplicationInfo
&&
452 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
453 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
455 client_version
= VK_MAKE_VERSION(1, 0, 0);
458 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
459 client_version
> VK_MAKE_VERSION(1, 1, 0xfff)) {
460 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
461 "Client requested version %d.%d.%d",
462 VK_VERSION_MAJOR(client_version
),
463 VK_VERSION_MINOR(client_version
),
464 VK_VERSION_PATCH(client_version
));
467 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
468 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
470 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
472 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
475 instance
->alloc
= *pAllocator
;
477 instance
->alloc
= default_alloc
;
479 instance
->apiVersion
= client_version
;
480 instance
->physicalDeviceCount
= -1;
482 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
483 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
484 int index
= radv_get_instance_extension_index(ext_name
);
486 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
487 vk_free2(&default_alloc
, pAllocator
, instance
);
488 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
491 instance
->enabled_extensions
.extensions
[index
] = true;
494 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
495 if (result
!= VK_SUCCESS
) {
496 vk_free2(&default_alloc
, pAllocator
, instance
);
497 return vk_error(result
);
502 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
504 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
507 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
508 radv_perftest_options
);
510 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
512 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
513 /* Disable sisched when the user requests it, this is mostly
514 * useful when the driver force-enable sisched for the given
517 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
520 *pInstance
= radv_instance_to_handle(instance
);
525 void radv_DestroyInstance(
526 VkInstance _instance
,
527 const VkAllocationCallbacks
* pAllocator
)
529 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
534 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
535 radv_physical_device_finish(instance
->physicalDevices
+ i
);
538 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
542 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
544 vk_free(&instance
->alloc
, instance
);
548 radv_enumerate_devices(struct radv_instance
*instance
)
550 /* TODO: Check for more devices ? */
551 drmDevicePtr devices
[8];
552 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
555 instance
->physicalDeviceCount
= 0;
557 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
559 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
561 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
562 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
563 devices
[i
]->bustype
== DRM_BUS_PCI
&&
564 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
566 result
= radv_physical_device_init(instance
->physicalDevices
+
567 instance
->physicalDeviceCount
,
570 if (result
== VK_SUCCESS
)
571 ++instance
->physicalDeviceCount
;
572 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
576 drmFreeDevices(devices
, max_devices
);
581 VkResult
radv_EnumeratePhysicalDevices(
582 VkInstance _instance
,
583 uint32_t* pPhysicalDeviceCount
,
584 VkPhysicalDevice
* pPhysicalDevices
)
586 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
589 if (instance
->physicalDeviceCount
< 0) {
590 result
= radv_enumerate_devices(instance
);
591 if (result
!= VK_SUCCESS
&&
592 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
596 if (!pPhysicalDevices
) {
597 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
599 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
600 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
601 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
604 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
608 VkResult
radv_EnumeratePhysicalDeviceGroups(
609 VkInstance _instance
,
610 uint32_t* pPhysicalDeviceGroupCount
,
611 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
613 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
616 if (instance
->physicalDeviceCount
< 0) {
617 result
= radv_enumerate_devices(instance
);
618 if (result
!= VK_SUCCESS
&&
619 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
623 if (!pPhysicalDeviceGroupProperties
) {
624 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
626 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
627 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
628 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
629 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
630 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
633 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
637 void radv_GetPhysicalDeviceFeatures(
638 VkPhysicalDevice physicalDevice
,
639 VkPhysicalDeviceFeatures
* pFeatures
)
641 memset(pFeatures
, 0, sizeof(*pFeatures
));
643 *pFeatures
= (VkPhysicalDeviceFeatures
) {
644 .robustBufferAccess
= true,
645 .fullDrawIndexUint32
= true,
646 .imageCubeArray
= true,
647 .independentBlend
= true,
648 .geometryShader
= true,
649 .tessellationShader
= true,
650 .sampleRateShading
= true,
651 .dualSrcBlend
= true,
653 .multiDrawIndirect
= true,
654 .drawIndirectFirstInstance
= true,
656 .depthBiasClamp
= true,
657 .fillModeNonSolid
= true,
662 .multiViewport
= true,
663 .samplerAnisotropy
= true,
664 .textureCompressionETC2
= false,
665 .textureCompressionASTC_LDR
= false,
666 .textureCompressionBC
= true,
667 .occlusionQueryPrecise
= true,
668 .pipelineStatisticsQuery
= true,
669 .vertexPipelineStoresAndAtomics
= true,
670 .fragmentStoresAndAtomics
= true,
671 .shaderTessellationAndGeometryPointSize
= true,
672 .shaderImageGatherExtended
= true,
673 .shaderStorageImageExtendedFormats
= true,
674 .shaderStorageImageMultisample
= false,
675 .shaderUniformBufferArrayDynamicIndexing
= true,
676 .shaderSampledImageArrayDynamicIndexing
= true,
677 .shaderStorageBufferArrayDynamicIndexing
= true,
678 .shaderStorageImageArrayDynamicIndexing
= true,
679 .shaderStorageImageReadWithoutFormat
= true,
680 .shaderStorageImageWriteWithoutFormat
= true,
681 .shaderClipDistance
= true,
682 .shaderCullDistance
= true,
683 .shaderFloat64
= true,
685 .shaderInt16
= false,
686 .sparseBinding
= true,
687 .variableMultisampleRate
= true,
688 .inheritedQueries
= true,
692 void radv_GetPhysicalDeviceFeatures2(
693 VkPhysicalDevice physicalDevice
,
694 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
696 vk_foreach_struct(ext
, pFeatures
->pNext
) {
697 switch (ext
->sType
) {
698 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
699 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
700 features
->variablePointersStorageBuffer
= true;
701 features
->variablePointers
= false;
704 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
705 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
706 features
->multiview
= true;
707 features
->multiviewGeometryShader
= true;
708 features
->multiviewTessellationShader
= true;
711 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
712 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
713 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
714 features
->shaderDrawParameters
= true;
717 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
718 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
719 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
720 features
->protectedMemory
= false;
723 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
724 VkPhysicalDevice16BitStorageFeatures
*features
=
725 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
726 features
->storageBuffer16BitAccess
= false;
727 features
->uniformAndStorageBuffer16BitAccess
= false;
728 features
->storagePushConstant16
= false;
729 features
->storageInputOutput16
= false;
732 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
733 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
734 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
735 features
->samplerYcbcrConversion
= false;
742 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
745 void radv_GetPhysicalDeviceProperties(
746 VkPhysicalDevice physicalDevice
,
747 VkPhysicalDeviceProperties
* pProperties
)
749 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
750 VkSampleCountFlags sample_counts
= 0xf;
752 /* make sure that the entire descriptor set is addressable with a signed
753 * 32-bit int. So the sum of all limits scaled by descriptor size has to
754 * be at most 2 GiB. the combined image & samples object count as one of
755 * both. This limit is for the pipeline layout, not for the set layout, but
756 * there is no set limit, so we just set a pipeline limit. I don't think
757 * any app is going to hit this soon. */
758 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
759 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
760 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
761 32 /* sampler, largest when combined with image */ +
762 64 /* sampled image */ +
763 64 /* storage image */);
765 VkPhysicalDeviceLimits limits
= {
766 .maxImageDimension1D
= (1 << 14),
767 .maxImageDimension2D
= (1 << 14),
768 .maxImageDimension3D
= (1 << 11),
769 .maxImageDimensionCube
= (1 << 14),
770 .maxImageArrayLayers
= (1 << 11),
771 .maxTexelBufferElements
= 128 * 1024 * 1024,
772 .maxUniformBufferRange
= UINT32_MAX
,
773 .maxStorageBufferRange
= UINT32_MAX
,
774 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
775 .maxMemoryAllocationCount
= UINT32_MAX
,
776 .maxSamplerAllocationCount
= 64 * 1024,
777 .bufferImageGranularity
= 64, /* A cache line */
778 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
779 .maxBoundDescriptorSets
= MAX_SETS
,
780 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
781 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
782 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
783 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
784 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
785 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
786 .maxPerStageResources
= max_descriptor_set_size
,
787 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
788 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
789 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
790 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
791 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
792 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
793 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
794 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
795 .maxVertexInputAttributes
= 32,
796 .maxVertexInputBindings
= 32,
797 .maxVertexInputAttributeOffset
= 2047,
798 .maxVertexInputBindingStride
= 2048,
799 .maxVertexOutputComponents
= 128,
800 .maxTessellationGenerationLevel
= 64,
801 .maxTessellationPatchSize
= 32,
802 .maxTessellationControlPerVertexInputComponents
= 128,
803 .maxTessellationControlPerVertexOutputComponents
= 128,
804 .maxTessellationControlPerPatchOutputComponents
= 120,
805 .maxTessellationControlTotalOutputComponents
= 4096,
806 .maxTessellationEvaluationInputComponents
= 128,
807 .maxTessellationEvaluationOutputComponents
= 128,
808 .maxGeometryShaderInvocations
= 127,
809 .maxGeometryInputComponents
= 64,
810 .maxGeometryOutputComponents
= 128,
811 .maxGeometryOutputVertices
= 256,
812 .maxGeometryTotalOutputComponents
= 1024,
813 .maxFragmentInputComponents
= 128,
814 .maxFragmentOutputAttachments
= 8,
815 .maxFragmentDualSrcAttachments
= 1,
816 .maxFragmentCombinedOutputResources
= 8,
817 .maxComputeSharedMemorySize
= 32768,
818 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
819 .maxComputeWorkGroupInvocations
= 2048,
820 .maxComputeWorkGroupSize
= {
825 .subPixelPrecisionBits
= 4 /* FIXME */,
826 .subTexelPrecisionBits
= 4 /* FIXME */,
827 .mipmapPrecisionBits
= 4 /* FIXME */,
828 .maxDrawIndexedIndexValue
= UINT32_MAX
,
829 .maxDrawIndirectCount
= UINT32_MAX
,
830 .maxSamplerLodBias
= 16,
831 .maxSamplerAnisotropy
= 16,
832 .maxViewports
= MAX_VIEWPORTS
,
833 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
834 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
835 .viewportSubPixelBits
= 13, /* We take a float? */
836 .minMemoryMapAlignment
= 4096, /* A page */
837 .minTexelBufferOffsetAlignment
= 1,
838 .minUniformBufferOffsetAlignment
= 4,
839 .minStorageBufferOffsetAlignment
= 4,
840 .minTexelOffset
= -32,
841 .maxTexelOffset
= 31,
842 .minTexelGatherOffset
= -32,
843 .maxTexelGatherOffset
= 31,
844 .minInterpolationOffset
= -2,
845 .maxInterpolationOffset
= 2,
846 .subPixelInterpolationOffsetBits
= 8,
847 .maxFramebufferWidth
= (1 << 14),
848 .maxFramebufferHeight
= (1 << 14),
849 .maxFramebufferLayers
= (1 << 10),
850 .framebufferColorSampleCounts
= sample_counts
,
851 .framebufferDepthSampleCounts
= sample_counts
,
852 .framebufferStencilSampleCounts
= sample_counts
,
853 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
854 .maxColorAttachments
= MAX_RTS
,
855 .sampledImageColorSampleCounts
= sample_counts
,
856 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
857 .sampledImageDepthSampleCounts
= sample_counts
,
858 .sampledImageStencilSampleCounts
= sample_counts
,
859 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
860 .maxSampleMaskWords
= 1,
861 .timestampComputeAndGraphics
= true,
862 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
863 .maxClipDistances
= 8,
864 .maxCullDistances
= 8,
865 .maxCombinedClipAndCullDistances
= 8,
866 .discreteQueuePriorities
= 1,
867 .pointSizeRange
= { 0.125, 255.875 },
868 .lineWidthRange
= { 0.0, 7.9921875 },
869 .pointSizeGranularity
= (1.0 / 8.0),
870 .lineWidthGranularity
= (1.0 / 128.0),
871 .strictLines
= false, /* FINISHME */
872 .standardSampleLocations
= true,
873 .optimalBufferCopyOffsetAlignment
= 128,
874 .optimalBufferCopyRowPitchAlignment
= 128,
875 .nonCoherentAtomSize
= 64,
878 *pProperties
= (VkPhysicalDeviceProperties
) {
879 .apiVersion
= radv_physical_device_api_version(pdevice
),
880 .driverVersion
= vk_get_driver_version(),
881 .vendorID
= ATI_VENDOR_ID
,
882 .deviceID
= pdevice
->rad_info
.pci_id
,
883 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
885 .sparseProperties
= {0},
888 strcpy(pProperties
->deviceName
, pdevice
->name
);
889 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
892 void radv_GetPhysicalDeviceProperties2(
893 VkPhysicalDevice physicalDevice
,
894 VkPhysicalDeviceProperties2KHR
*pProperties
)
896 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
897 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
899 vk_foreach_struct(ext
, pProperties
->pNext
) {
900 switch (ext
->sType
) {
901 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
902 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
903 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
904 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
907 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
908 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
909 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
910 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
911 properties
->deviceLUIDValid
= false;
914 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
915 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
916 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
917 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
920 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
921 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
922 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
923 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
926 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
927 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
928 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
929 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
932 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
933 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
934 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
935 properties
->minImportedHostPointerAlignment
= 4096;
938 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
939 VkPhysicalDeviceSubgroupProperties
*properties
=
940 (VkPhysicalDeviceSubgroupProperties
*)ext
;
941 properties
->subgroupSize
= 64;
942 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
943 properties
->supportedOperations
=
944 VK_SUBGROUP_FEATURE_BASIC_BIT
|
945 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
946 VK_SUBGROUP_FEATURE_QUAD_BIT
|
947 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
948 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
949 VK_SUBGROUP_FEATURE_VOTE_BIT
;
950 properties
->quadOperationsInAllStages
= true;
953 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
954 VkPhysicalDeviceMaintenance3Properties
*properties
=
955 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
956 /* Make sure everything is addressable by a signed 32-bit int, and
957 * our largest descriptors are 96 bytes. */
958 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
959 /* Our buffer size fields allow only this much */
960 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
963 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
964 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
965 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
966 /* GFX6-8 only support single channel min/max filter. */
967 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
968 properties
->filterMinmaxSingleComponentFormats
= true;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
972 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
973 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
975 /* Shader engines. */
976 properties
->shaderEngineCount
=
977 pdevice
->rad_info
.max_se
;
978 properties
->shaderArraysPerEngineCount
=
979 pdevice
->rad_info
.max_sh_per_se
;
980 properties
->computeUnitsPerShaderArray
=
981 pdevice
->rad_info
.num_good_compute_units
/
982 (pdevice
->rad_info
.max_se
*
983 pdevice
->rad_info
.max_sh_per_se
);
984 properties
->simdPerComputeUnit
= 4;
985 properties
->wavefrontsPerSimd
=
986 pdevice
->rad_info
.family
== CHIP_TONGA
||
987 pdevice
->rad_info
.family
== CHIP_ICELAND
||
988 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
989 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
990 pdevice
->rad_info
.family
== CHIP_POLARIS12
? 8 : 10;
991 properties
->wavefrontSize
= 64;
994 properties
->sgprsPerSimd
=
995 radv_get_num_physical_sgprs(pdevice
);
996 properties
->minSgprAllocation
=
997 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
998 properties
->maxSgprAllocation
=
999 pdevice
->rad_info
.family
== CHIP_TONGA
||
1000 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1001 properties
->sgprAllocationGranularity
=
1002 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1005 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1006 properties
->minVgprAllocation
= 4;
1007 properties
->maxVgprAllocation
= 256;
1008 properties
->vgprAllocationGranularity
= 4;
1011 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1012 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1013 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1014 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1023 static void radv_get_physical_device_queue_family_properties(
1024 struct radv_physical_device
* pdevice
,
1026 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1028 int num_queue_families
= 1;
1030 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1031 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1032 num_queue_families
++;
1034 if (pQueueFamilyProperties
== NULL
) {
1035 *pCount
= num_queue_families
;
1044 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1045 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1046 VK_QUEUE_COMPUTE_BIT
|
1047 VK_QUEUE_TRANSFER_BIT
|
1048 VK_QUEUE_SPARSE_BINDING_BIT
,
1050 .timestampValidBits
= 64,
1051 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1056 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1057 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1058 if (*pCount
> idx
) {
1059 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1060 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1061 VK_QUEUE_TRANSFER_BIT
|
1062 VK_QUEUE_SPARSE_BINDING_BIT
,
1063 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1064 .timestampValidBits
= 64,
1065 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1073 void radv_GetPhysicalDeviceQueueFamilyProperties(
1074 VkPhysicalDevice physicalDevice
,
1076 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1078 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1079 if (!pQueueFamilyProperties
) {
1080 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1083 VkQueueFamilyProperties
*properties
[] = {
1084 pQueueFamilyProperties
+ 0,
1085 pQueueFamilyProperties
+ 1,
1086 pQueueFamilyProperties
+ 2,
1088 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1089 assert(*pCount
<= 3);
1092 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1093 VkPhysicalDevice physicalDevice
,
1095 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1097 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1098 if (!pQueueFamilyProperties
) {
1099 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1102 VkQueueFamilyProperties
*properties
[] = {
1103 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1104 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1105 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1107 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1108 assert(*pCount
<= 3);
1111 void radv_GetPhysicalDeviceMemoryProperties(
1112 VkPhysicalDevice physicalDevice
,
1113 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1115 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1117 *pMemoryProperties
= physical_device
->memory_properties
;
1120 void radv_GetPhysicalDeviceMemoryProperties2(
1121 VkPhysicalDevice physicalDevice
,
1122 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1124 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1125 &pMemoryProperties
->memoryProperties
);
1128 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1130 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1131 const void *pHostPointer
,
1132 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1134 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1138 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1139 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1140 uint32_t memoryTypeBits
= 0;
1141 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1142 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1143 memoryTypeBits
= (1 << i
);
1147 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1151 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1155 static enum radeon_ctx_priority
1156 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1158 /* Default to MEDIUM when a specific global priority isn't requested */
1160 return RADEON_CTX_PRIORITY_MEDIUM
;
1162 switch(pObj
->globalPriority
) {
1163 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1164 return RADEON_CTX_PRIORITY_REALTIME
;
1165 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1166 return RADEON_CTX_PRIORITY_HIGH
;
1167 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1168 return RADEON_CTX_PRIORITY_MEDIUM
;
1169 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1170 return RADEON_CTX_PRIORITY_LOW
;
1172 unreachable("Illegal global priority value");
1173 return RADEON_CTX_PRIORITY_INVALID
;
1178 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1179 uint32_t queue_family_index
, int idx
,
1180 VkDeviceQueueCreateFlags flags
,
1181 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1183 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1184 queue
->device
= device
;
1185 queue
->queue_family_index
= queue_family_index
;
1186 queue
->queue_idx
= idx
;
1187 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1188 queue
->flags
= flags
;
1190 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1192 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1198 radv_queue_finish(struct radv_queue
*queue
)
1201 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1203 if (queue
->initial_full_flush_preamble_cs
)
1204 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1205 if (queue
->initial_preamble_cs
)
1206 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1207 if (queue
->continue_preamble_cs
)
1208 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1209 if (queue
->descriptor_bo
)
1210 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1211 if (queue
->scratch_bo
)
1212 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1213 if (queue
->esgs_ring_bo
)
1214 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1215 if (queue
->gsvs_ring_bo
)
1216 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1217 if (queue
->tess_rings_bo
)
1218 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1219 if (queue
->compute_scratch_bo
)
1220 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1224 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1226 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1227 bo_list
->list
.count
= bo_list
->capacity
= 0;
1228 bo_list
->list
.bos
= NULL
;
1232 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1234 free(bo_list
->list
.bos
);
1235 pthread_mutex_destroy(&bo_list
->mutex
);
1238 static VkResult
radv_bo_list_add(struct radv_bo_list
*bo_list
, struct radeon_winsys_bo
*bo
)
1240 pthread_mutex_lock(&bo_list
->mutex
);
1241 if (bo_list
->list
.count
== bo_list
->capacity
) {
1242 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1243 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1246 pthread_mutex_unlock(&bo_list
->mutex
);
1247 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1250 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1251 bo_list
->capacity
= capacity
;
1254 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1255 pthread_mutex_unlock(&bo_list
->mutex
);
1259 static void radv_bo_list_remove(struct radv_bo_list
*bo_list
, struct radeon_winsys_bo
*bo
)
1261 pthread_mutex_lock(&bo_list
->mutex
);
1262 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1263 if (bo_list
->list
.bos
[i
] == bo
) {
1264 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1265 --bo_list
->list
.count
;
1269 pthread_mutex_unlock(&bo_list
->mutex
);
1273 radv_device_init_gs_info(struct radv_device
*device
)
1275 switch (device
->physical_device
->rad_info
.family
) {
1284 device
->gs_table_depth
= 16;
1293 case CHIP_POLARIS10
:
1294 case CHIP_POLARIS11
:
1295 case CHIP_POLARIS12
:
1299 device
->gs_table_depth
= 32;
1302 unreachable("unknown GPU");
1306 static int radv_get_device_extension_index(const char *name
)
1308 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1309 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1315 VkResult
radv_CreateDevice(
1316 VkPhysicalDevice physicalDevice
,
1317 const VkDeviceCreateInfo
* pCreateInfo
,
1318 const VkAllocationCallbacks
* pAllocator
,
1321 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1323 struct radv_device
*device
;
1325 bool keep_shader_info
= false;
1327 /* Check enabled features */
1328 if (pCreateInfo
->pEnabledFeatures
) {
1329 VkPhysicalDeviceFeatures supported_features
;
1330 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1331 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1332 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1333 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1334 for (uint32_t i
= 0; i
< num_features
; i
++) {
1335 if (enabled_feature
[i
] && !supported_feature
[i
])
1336 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1340 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1342 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1344 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1346 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1347 device
->instance
= physical_device
->instance
;
1348 device
->physical_device
= physical_device
;
1350 device
->ws
= physical_device
->ws
;
1352 device
->alloc
= *pAllocator
;
1354 device
->alloc
= physical_device
->instance
->alloc
;
1356 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1357 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1358 int index
= radv_get_device_extension_index(ext_name
);
1359 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1360 vk_free(&device
->alloc
, device
);
1361 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1364 device
->enabled_extensions
.extensions
[index
] = true;
1367 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1369 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1370 list_inithead(&device
->shader_slabs
);
1372 radv_bo_list_init(&device
->bo_list
);
1374 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1375 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1376 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1377 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1378 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1380 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1382 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1383 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1384 if (!device
->queues
[qfi
]) {
1385 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1389 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1391 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1393 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1394 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1395 qfi
, q
, queue_create
->flags
,
1397 if (result
!= VK_SUCCESS
)
1402 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1403 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1405 /* Disabled and not implemented for now. */
1406 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1409 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1412 device
->llvm_supports_spill
= true;
1414 /* The maximum number of scratch waves. Scratch space isn't divided
1415 * evenly between CUs. The number is only a function of the number of CUs.
1416 * We can decrease the constant to decrease the scratch buffer size.
1418 * sctx->scratch_waves must be >= the maximum posible size of
1419 * 1 threadgroup, so that the hw doesn't hang from being unable
1422 * The recommended value is 4 per CU at most. Higher numbers don't
1423 * bring much benefit, but they still occupy chip resources (think
1424 * async compute). I've seen ~2% performance difference between 4 and 32.
1426 uint32_t max_threads_per_block
= 2048;
1427 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1428 max_threads_per_block
/ 64);
1430 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1432 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1433 /* If the KMD allows it (there is a KMD hw register for it),
1434 * allow launching waves out-of-order.
1436 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1439 radv_device_init_gs_info(device
);
1441 device
->tess_offchip_block_dw_size
=
1442 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1443 device
->has_distributed_tess
=
1444 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1445 device
->physical_device
->rad_info
.max_se
>= 2;
1447 if (getenv("RADV_TRACE_FILE")) {
1448 const char *filename
= getenv("RADV_TRACE_FILE");
1450 keep_shader_info
= true;
1452 if (!radv_init_trace(device
))
1455 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1456 radv_dump_enabled_options(device
, stderr
);
1459 device
->keep_shader_info
= keep_shader_info
;
1461 result
= radv_device_init_meta(device
);
1462 if (result
!= VK_SUCCESS
)
1465 radv_device_init_msaa(device
);
1467 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1468 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1470 case RADV_QUEUE_GENERAL
:
1471 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1472 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1473 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1475 case RADV_QUEUE_COMPUTE
:
1476 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1477 radeon_emit(device
->empty_cs
[family
], 0);
1480 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1483 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1484 cik_create_gfx_config(device
);
1486 VkPipelineCacheCreateInfo ci
;
1487 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1490 ci
.pInitialData
= NULL
;
1491 ci
.initialDataSize
= 0;
1493 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1495 if (result
!= VK_SUCCESS
)
1498 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1500 *pDevice
= radv_device_to_handle(device
);
1504 radv_device_finish_meta(device
);
1506 radv_bo_list_finish(&device
->bo_list
);
1508 if (device
->trace_bo
)
1509 device
->ws
->buffer_destroy(device
->trace_bo
);
1511 if (device
->gfx_init
)
1512 device
->ws
->buffer_destroy(device
->gfx_init
);
1514 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1515 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1516 radv_queue_finish(&device
->queues
[i
][q
]);
1517 if (device
->queue_count
[i
])
1518 vk_free(&device
->alloc
, device
->queues
[i
]);
1521 vk_free(&device
->alloc
, device
);
1525 void radv_DestroyDevice(
1527 const VkAllocationCallbacks
* pAllocator
)
1529 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1534 if (device
->trace_bo
)
1535 device
->ws
->buffer_destroy(device
->trace_bo
);
1537 if (device
->gfx_init
)
1538 device
->ws
->buffer_destroy(device
->gfx_init
);
1540 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1541 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1542 radv_queue_finish(&device
->queues
[i
][q
]);
1543 if (device
->queue_count
[i
])
1544 vk_free(&device
->alloc
, device
->queues
[i
]);
1545 if (device
->empty_cs
[i
])
1546 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1548 radv_device_finish_meta(device
);
1550 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1551 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1553 radv_destroy_shader_slabs(device
);
1555 radv_bo_list_finish(&device
->bo_list
);
1556 vk_free(&device
->alloc
, device
);
1559 VkResult
radv_EnumerateInstanceLayerProperties(
1560 uint32_t* pPropertyCount
,
1561 VkLayerProperties
* pProperties
)
1563 if (pProperties
== NULL
) {
1564 *pPropertyCount
= 0;
1568 /* None supported at this time */
1569 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1572 VkResult
radv_EnumerateDeviceLayerProperties(
1573 VkPhysicalDevice physicalDevice
,
1574 uint32_t* pPropertyCount
,
1575 VkLayerProperties
* pProperties
)
1577 if (pProperties
== NULL
) {
1578 *pPropertyCount
= 0;
1582 /* None supported at this time */
1583 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1586 void radv_GetDeviceQueue2(
1588 const VkDeviceQueueInfo2
* pQueueInfo
,
1591 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1592 struct radv_queue
*queue
;
1594 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1595 if (pQueueInfo
->flags
!= queue
->flags
) {
1596 /* From the Vulkan 1.1.70 spec:
1598 * "The queue returned by vkGetDeviceQueue2 must have the same
1599 * flags value from this structure as that used at device
1600 * creation time in a VkDeviceQueueCreateInfo instance. If no
1601 * matching flags were specified at device creation time then
1602 * pQueue will return VK_NULL_HANDLE."
1604 *pQueue
= VK_NULL_HANDLE
;
1608 *pQueue
= radv_queue_to_handle(queue
);
1611 void radv_GetDeviceQueue(
1613 uint32_t queueFamilyIndex
,
1614 uint32_t queueIndex
,
1617 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1618 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1619 .queueFamilyIndex
= queueFamilyIndex
,
1620 .queueIndex
= queueIndex
1623 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1627 fill_geom_tess_rings(struct radv_queue
*queue
,
1629 bool add_sample_positions
,
1630 uint32_t esgs_ring_size
,
1631 struct radeon_winsys_bo
*esgs_ring_bo
,
1632 uint32_t gsvs_ring_size
,
1633 struct radeon_winsys_bo
*gsvs_ring_bo
,
1634 uint32_t tess_factor_ring_size
,
1635 uint32_t tess_offchip_ring_offset
,
1636 uint32_t tess_offchip_ring_size
,
1637 struct radeon_winsys_bo
*tess_rings_bo
)
1639 uint64_t esgs_va
= 0, gsvs_va
= 0;
1640 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1641 uint32_t *desc
= &map
[4];
1644 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1646 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1647 if (tess_rings_bo
) {
1648 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1649 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1652 /* stride 0, num records - size, add tid, swizzle, elsize4,
1655 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1656 S_008F04_STRIDE(0) |
1657 S_008F04_SWIZZLE_ENABLE(true);
1658 desc
[2] = esgs_ring_size
;
1659 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1660 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1661 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1662 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1663 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1664 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1665 S_008F0C_ELEMENT_SIZE(1) |
1666 S_008F0C_INDEX_STRIDE(3) |
1667 S_008F0C_ADD_TID_ENABLE(true);
1670 /* GS entry for ES->GS ring */
1671 /* stride 0, num records - size, elsize0,
1674 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1675 S_008F04_STRIDE(0) |
1676 S_008F04_SWIZZLE_ENABLE(false);
1677 desc
[2] = esgs_ring_size
;
1678 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1679 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1680 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1681 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1682 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1683 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1684 S_008F0C_ELEMENT_SIZE(0) |
1685 S_008F0C_INDEX_STRIDE(0) |
1686 S_008F0C_ADD_TID_ENABLE(false);
1689 /* VS entry for GS->VS ring */
1690 /* stride 0, num records - size, elsize0,
1693 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1694 S_008F04_STRIDE(0) |
1695 S_008F04_SWIZZLE_ENABLE(false);
1696 desc
[2] = gsvs_ring_size
;
1697 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1698 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1699 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1700 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1701 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1702 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1703 S_008F0C_ELEMENT_SIZE(0) |
1704 S_008F0C_INDEX_STRIDE(0) |
1705 S_008F0C_ADD_TID_ENABLE(false);
1708 /* stride gsvs_itemsize, num records 64
1709 elsize 4, index stride 16 */
1710 /* shader will patch stride and desc[2] */
1712 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1713 S_008F04_STRIDE(0) |
1714 S_008F04_SWIZZLE_ENABLE(true);
1716 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1717 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1718 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1719 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1720 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1721 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1722 S_008F0C_ELEMENT_SIZE(1) |
1723 S_008F0C_INDEX_STRIDE(1) |
1724 S_008F0C_ADD_TID_ENABLE(true);
1728 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1729 S_008F04_STRIDE(0) |
1730 S_008F04_SWIZZLE_ENABLE(false);
1731 desc
[2] = tess_factor_ring_size
;
1732 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1733 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1734 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1735 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1736 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1737 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1738 S_008F0C_ELEMENT_SIZE(0) |
1739 S_008F0C_INDEX_STRIDE(0) |
1740 S_008F0C_ADD_TID_ENABLE(false);
1743 desc
[0] = tess_offchip_va
;
1744 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1745 S_008F04_STRIDE(0) |
1746 S_008F04_SWIZZLE_ENABLE(false);
1747 desc
[2] = tess_offchip_ring_size
;
1748 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1749 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1750 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1751 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1752 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1753 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1754 S_008F0C_ELEMENT_SIZE(0) |
1755 S_008F0C_INDEX_STRIDE(0) |
1756 S_008F0C_ADD_TID_ENABLE(false);
1759 /* add sample positions after all rings */
1760 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1762 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1764 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1766 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1768 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1772 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1774 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1775 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1776 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1777 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1778 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1779 device
->physical_device
->rad_info
.max_se
;
1780 unsigned offchip_granularity
;
1781 unsigned hs_offchip_param
;
1782 switch (device
->tess_offchip_block_dw_size
) {
1787 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1790 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1794 switch (device
->physical_device
->rad_info
.chip_class
) {
1796 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1802 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1806 *max_offchip_buffers_p
= max_offchip_buffers
;
1807 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1808 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1809 --max_offchip_buffers
;
1811 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1812 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1815 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1817 return hs_offchip_param
;
1821 radv_get_preamble_cs(struct radv_queue
*queue
,
1822 uint32_t scratch_size
,
1823 uint32_t compute_scratch_size
,
1824 uint32_t esgs_ring_size
,
1825 uint32_t gsvs_ring_size
,
1826 bool needs_tess_rings
,
1827 bool needs_sample_positions
,
1828 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1829 struct radeon_winsys_cs
**initial_preamble_cs
,
1830 struct radeon_winsys_cs
**continue_preamble_cs
)
1832 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1833 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1834 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1835 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1836 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1837 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1838 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1839 bool add_tess_rings
= false, add_sample_positions
= false;
1840 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1841 unsigned max_offchip_buffers
;
1842 unsigned hs_offchip_param
= 0;
1843 unsigned tess_offchip_ring_offset
;
1844 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1845 if (!queue
->has_tess_rings
) {
1846 if (needs_tess_rings
)
1847 add_tess_rings
= true;
1849 if (!queue
->has_sample_positions
) {
1850 if (needs_sample_positions
)
1851 add_sample_positions
= true;
1853 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1854 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1855 &max_offchip_buffers
);
1856 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1857 tess_offchip_ring_size
= max_offchip_buffers
*
1858 queue
->device
->tess_offchip_block_dw_size
* 4;
1860 if (scratch_size
<= queue
->scratch_size
&&
1861 compute_scratch_size
<= queue
->compute_scratch_size
&&
1862 esgs_ring_size
<= queue
->esgs_ring_size
&&
1863 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1864 !add_tess_rings
&& !add_sample_positions
&&
1865 queue
->initial_preamble_cs
) {
1866 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1867 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1868 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1869 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1870 *continue_preamble_cs
= NULL
;
1874 if (scratch_size
> queue
->scratch_size
) {
1875 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1883 scratch_bo
= queue
->scratch_bo
;
1885 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1886 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1887 compute_scratch_size
,
1891 if (!compute_scratch_bo
)
1895 compute_scratch_bo
= queue
->compute_scratch_bo
;
1897 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1898 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1906 esgs_ring_bo
= queue
->esgs_ring_bo
;
1907 esgs_ring_size
= queue
->esgs_ring_size
;
1910 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1911 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1919 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1920 gsvs_ring_size
= queue
->gsvs_ring_size
;
1923 if (add_tess_rings
) {
1924 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1925 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
1932 tess_rings_bo
= queue
->tess_rings_bo
;
1935 if (scratch_bo
!= queue
->scratch_bo
||
1936 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1937 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1938 tess_rings_bo
!= queue
->tess_rings_bo
||
1939 add_sample_positions
) {
1941 if (gsvs_ring_bo
|| esgs_ring_bo
||
1942 tess_rings_bo
|| add_sample_positions
) {
1943 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1944 if (add_sample_positions
)
1945 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1947 else if (scratch_bo
)
1948 size
= 8; /* 2 dword */
1950 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1954 RADEON_FLAG_CPU_ACCESS
|
1955 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
1956 RADEON_FLAG_READ_ONLY
);
1960 descriptor_bo
= queue
->descriptor_bo
;
1962 for(int i
= 0; i
< 3; ++i
) {
1963 struct radeon_winsys_cs
*cs
= NULL
;
1964 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1965 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1972 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
1975 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1978 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1981 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1984 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1986 if (descriptor_bo
!= queue
->descriptor_bo
) {
1987 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1990 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1991 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1992 S_008F04_SWIZZLE_ENABLE(1);
1993 map
[0] = scratch_va
;
1997 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
1998 add_sample_positions
)
1999 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2000 esgs_ring_size
, esgs_ring_bo
,
2001 gsvs_ring_size
, gsvs_ring_bo
,
2002 tess_factor_ring_size
,
2003 tess_offchip_ring_offset
,
2004 tess_offchip_ring_size
,
2007 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2010 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2011 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2012 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2013 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2014 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2017 if (esgs_ring_bo
|| gsvs_ring_bo
) {
2018 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2019 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2020 radeon_emit(cs
, esgs_ring_size
>> 8);
2021 radeon_emit(cs
, gsvs_ring_size
>> 8);
2023 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2024 radeon_emit(cs
, esgs_ring_size
>> 8);
2025 radeon_emit(cs
, gsvs_ring_size
>> 8);
2029 if (tess_rings_bo
) {
2030 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
2031 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2032 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2033 S_030938_SIZE(tess_factor_ring_size
/ 4));
2034 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2036 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2037 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2038 S_030944_BASE_HI(tf_va
>> 40));
2040 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
2042 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2043 S_008988_SIZE(tess_factor_ring_size
/ 4));
2044 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2046 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2051 if (descriptor_bo
) {
2052 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
2053 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2054 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2055 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2056 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2057 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2059 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2060 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2061 radeon_emit(cs
, va
);
2062 radeon_emit(cs
, va
>> 32);
2065 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2066 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2067 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2068 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2069 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2070 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2072 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2073 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2074 radeon_emit(cs
, va
);
2075 radeon_emit(cs
, va
>> 32);
2080 if (compute_scratch_bo
) {
2081 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2082 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2083 S_008F04_SWIZZLE_ENABLE(1);
2085 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2087 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2088 radeon_emit(cs
, scratch_va
);
2089 radeon_emit(cs
, rsrc1
);
2093 si_cs_emit_cache_flush(cs
,
2094 queue
->device
->physical_device
->rad_info
.chip_class
,
2096 queue
->queue_family_index
== RING_COMPUTE
&&
2097 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2098 (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
)) |
2099 RADV_CMD_FLAG_INV_ICACHE
|
2100 RADV_CMD_FLAG_INV_SMEM_L1
|
2101 RADV_CMD_FLAG_INV_VMEM_L1
|
2102 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2103 } else if (i
== 1) {
2104 si_cs_emit_cache_flush(cs
,
2105 queue
->device
->physical_device
->rad_info
.chip_class
,
2107 queue
->queue_family_index
== RING_COMPUTE
&&
2108 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2109 RADV_CMD_FLAG_INV_ICACHE
|
2110 RADV_CMD_FLAG_INV_SMEM_L1
|
2111 RADV_CMD_FLAG_INV_VMEM_L1
|
2112 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2115 if (!queue
->device
->ws
->cs_finalize(cs
))
2119 if (queue
->initial_full_flush_preamble_cs
)
2120 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2122 if (queue
->initial_preamble_cs
)
2123 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2125 if (queue
->continue_preamble_cs
)
2126 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2128 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2129 queue
->initial_preamble_cs
= dest_cs
[1];
2130 queue
->continue_preamble_cs
= dest_cs
[2];
2132 if (scratch_bo
!= queue
->scratch_bo
) {
2133 if (queue
->scratch_bo
)
2134 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2135 queue
->scratch_bo
= scratch_bo
;
2136 queue
->scratch_size
= scratch_size
;
2139 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2140 if (queue
->compute_scratch_bo
)
2141 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2142 queue
->compute_scratch_bo
= compute_scratch_bo
;
2143 queue
->compute_scratch_size
= compute_scratch_size
;
2146 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2147 if (queue
->esgs_ring_bo
)
2148 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2149 queue
->esgs_ring_bo
= esgs_ring_bo
;
2150 queue
->esgs_ring_size
= esgs_ring_size
;
2153 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2154 if (queue
->gsvs_ring_bo
)
2155 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2156 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2157 queue
->gsvs_ring_size
= gsvs_ring_size
;
2160 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2161 queue
->tess_rings_bo
= tess_rings_bo
;
2162 queue
->has_tess_rings
= true;
2165 if (descriptor_bo
!= queue
->descriptor_bo
) {
2166 if (queue
->descriptor_bo
)
2167 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2169 queue
->descriptor_bo
= descriptor_bo
;
2172 if (add_sample_positions
)
2173 queue
->has_sample_positions
= true;
2175 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2176 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2177 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2178 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2179 *continue_preamble_cs
= NULL
;
2182 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2184 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2185 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2186 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2187 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2188 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2189 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2190 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2191 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2192 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2193 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2194 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2195 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2196 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2197 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2200 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2202 const VkSemaphore
*sems
,
2206 int syncobj_idx
= 0, sem_idx
= 0;
2208 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2211 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2212 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2214 if (sem
->temp_syncobj
|| sem
->syncobj
)
2215 counts
->syncobj_count
++;
2217 counts
->sem_count
++;
2220 if (_fence
!= VK_NULL_HANDLE
) {
2221 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2222 if (fence
->temp_syncobj
|| fence
->syncobj
)
2223 counts
->syncobj_count
++;
2226 if (counts
->syncobj_count
) {
2227 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2228 if (!counts
->syncobj
)
2229 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2232 if (counts
->sem_count
) {
2233 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2235 free(counts
->syncobj
);
2236 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2240 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2241 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2243 if (sem
->temp_syncobj
) {
2244 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2246 else if (sem
->syncobj
)
2247 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2250 counts
->sem
[sem_idx
++] = sem
->sem
;
2254 if (_fence
!= VK_NULL_HANDLE
) {
2255 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2256 if (fence
->temp_syncobj
)
2257 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2258 else if (fence
->syncobj
)
2259 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2265 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2267 free(sem_info
->wait
.syncobj
);
2268 free(sem_info
->wait
.sem
);
2269 free(sem_info
->signal
.syncobj
);
2270 free(sem_info
->signal
.sem
);
2274 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2276 const VkSemaphore
*sems
)
2278 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2279 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2281 if (sem
->temp_syncobj
) {
2282 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2283 sem
->temp_syncobj
= 0;
2288 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2290 const VkSemaphore
*wait_sems
,
2291 int num_signal_sems
,
2292 const VkSemaphore
*signal_sems
,
2296 memset(sem_info
, 0, sizeof(*sem_info
));
2298 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2301 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2303 radv_free_sem_info(sem_info
);
2305 /* caller can override these */
2306 sem_info
->cs_emit_wait
= true;
2307 sem_info
->cs_emit_signal
= true;
2311 /* Signals fence as soon as all the work currently put on queue is done. */
2312 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2313 struct radv_fence
*fence
)
2317 struct radv_winsys_sem_info sem_info
;
2319 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2320 radv_fence_to_handle(fence
));
2321 if (result
!= VK_SUCCESS
)
2324 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2325 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2326 1, NULL
, NULL
, &sem_info
, NULL
,
2327 false, fence
->fence
);
2328 radv_free_sem_info(&sem_info
);
2330 /* TODO: find a better error */
2332 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2337 VkResult
radv_QueueSubmit(
2339 uint32_t submitCount
,
2340 const VkSubmitInfo
* pSubmits
,
2343 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2344 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2345 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2346 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2348 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2349 uint32_t scratch_size
= 0;
2350 uint32_t compute_scratch_size
= 0;
2351 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2352 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2354 bool fence_emitted
= false;
2355 bool tess_rings_needed
= false;
2356 bool sample_positions_needed
= false;
2358 /* Do this first so failing to allocate scratch buffers can't result in
2359 * partially executed submissions. */
2360 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2361 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2362 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2363 pSubmits
[i
].pCommandBuffers
[j
]);
2365 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2366 compute_scratch_size
= MAX2(compute_scratch_size
,
2367 cmd_buffer
->compute_scratch_size_needed
);
2368 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2369 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2370 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2371 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2375 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2376 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2377 sample_positions_needed
, &initial_flush_preamble_cs
,
2378 &initial_preamble_cs
, &continue_preamble_cs
);
2379 if (result
!= VK_SUCCESS
)
2382 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2383 struct radeon_winsys_cs
**cs_array
;
2384 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2385 bool can_patch
= true;
2387 struct radv_winsys_sem_info sem_info
;
2389 result
= radv_alloc_sem_info(&sem_info
,
2390 pSubmits
[i
].waitSemaphoreCount
,
2391 pSubmits
[i
].pWaitSemaphores
,
2392 pSubmits
[i
].signalSemaphoreCount
,
2393 pSubmits
[i
].pSignalSemaphores
,
2395 if (result
!= VK_SUCCESS
)
2398 if (!pSubmits
[i
].commandBufferCount
) {
2399 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2400 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2401 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2406 radv_loge("failed to submit CS %d\n", i
);
2409 fence_emitted
= true;
2411 radv_free_sem_info(&sem_info
);
2415 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2416 (pSubmits
[i
].commandBufferCount
));
2418 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2419 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2420 pSubmits
[i
].pCommandBuffers
[j
]);
2421 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2423 cs_array
[j
] = cmd_buffer
->cs
;
2424 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2427 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2430 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2431 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2432 advance
= MIN2(max_cs_submission
,
2433 pSubmits
[i
].commandBufferCount
- j
);
2435 if (queue
->device
->trace_bo
)
2436 *queue
->device
->trace_id_ptr
= 0;
2438 sem_info
.cs_emit_wait
= j
== 0;
2439 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2441 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2443 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2444 advance
, initial_preamble
, continue_preamble_cs
,
2445 &sem_info
, &queue
->device
->bo_list
.list
,
2446 can_patch
, base_fence
);
2448 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2451 radv_loge("failed to submit CS %d\n", i
);
2454 fence_emitted
= true;
2455 if (queue
->device
->trace_bo
) {
2456 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2460 radv_free_temp_syncobjs(queue
->device
,
2461 pSubmits
[i
].waitSemaphoreCount
,
2462 pSubmits
[i
].pWaitSemaphores
);
2463 radv_free_sem_info(&sem_info
);
2468 if (!fence_emitted
) {
2469 radv_signal_fence(queue
, fence
);
2471 fence
->submitted
= true;
2477 VkResult
radv_QueueWaitIdle(
2480 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2482 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2483 radv_queue_family_to_ring(queue
->queue_family_index
),
2488 VkResult
radv_DeviceWaitIdle(
2491 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2493 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2494 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2495 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2501 VkResult
radv_EnumerateInstanceExtensionProperties(
2502 const char* pLayerName
,
2503 uint32_t* pPropertyCount
,
2504 VkExtensionProperties
* pProperties
)
2506 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2508 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2509 if (radv_supported_instance_extensions
.extensions
[i
]) {
2510 vk_outarray_append(&out
, prop
) {
2511 *prop
= radv_instance_extensions
[i
];
2516 return vk_outarray_status(&out
);
2519 VkResult
radv_EnumerateDeviceExtensionProperties(
2520 VkPhysicalDevice physicalDevice
,
2521 const char* pLayerName
,
2522 uint32_t* pPropertyCount
,
2523 VkExtensionProperties
* pProperties
)
2525 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2526 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2528 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2529 if (device
->supported_extensions
.extensions
[i
]) {
2530 vk_outarray_append(&out
, prop
) {
2531 *prop
= radv_device_extensions
[i
];
2536 return vk_outarray_status(&out
);
2539 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2540 VkInstance _instance
,
2543 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2545 return radv_lookup_entrypoint_checked(pName
,
2546 instance
? instance
->apiVersion
: 0,
2547 instance
? &instance
->enabled_extensions
: NULL
,
2551 /* The loader wants us to expose a second GetInstanceProcAddr function
2552 * to work around certain LD_PRELOAD issues seen in apps.
2555 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2556 VkInstance instance
,
2560 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2561 VkInstance instance
,
2564 return radv_GetInstanceProcAddr(instance
, pName
);
2567 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2571 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2573 return radv_lookup_entrypoint_checked(pName
,
2574 device
->instance
->apiVersion
,
2575 &device
->instance
->enabled_extensions
,
2576 &device
->enabled_extensions
);
2579 bool radv_get_memory_fd(struct radv_device
*device
,
2580 struct radv_device_memory
*memory
,
2583 struct radeon_bo_metadata metadata
;
2585 if (memory
->image
) {
2586 radv_init_metadata(device
, memory
->image
, &metadata
);
2587 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2590 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2594 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2595 const VkMemoryAllocateInfo
* pAllocateInfo
,
2596 const VkAllocationCallbacks
* pAllocator
,
2597 VkDeviceMemory
* pMem
)
2599 struct radv_device_memory
*mem
;
2601 enum radeon_bo_domain domain
;
2603 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2605 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2607 if (pAllocateInfo
->allocationSize
== 0) {
2608 /* Apparently, this is allowed */
2609 *pMem
= VK_NULL_HANDLE
;
2613 const VkImportMemoryFdInfoKHR
*import_info
=
2614 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2615 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2616 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2617 const VkExportMemoryAllocateInfoKHR
*export_info
=
2618 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2619 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2620 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2622 const struct wsi_memory_allocate_info
*wsi_info
=
2623 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2625 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2626 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2628 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2630 if (wsi_info
&& wsi_info
->implicit_sync
)
2631 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2633 if (dedicate_info
) {
2634 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2635 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2641 mem
->user_ptr
= NULL
;
2644 assert(import_info
->handleType
==
2645 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2646 import_info
->handleType
==
2647 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2648 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2651 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2654 close(import_info
->fd
);
2656 } else if (host_ptr_info
) {
2657 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2658 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2659 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2660 pAllocateInfo
->allocationSize
);
2662 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2665 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2668 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2669 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2670 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2671 domain
= RADEON_DOMAIN_GTT
;
2673 domain
= RADEON_DOMAIN_VRAM
;
2675 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2676 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2678 flags
|= RADEON_FLAG_CPU_ACCESS
;
2680 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2681 flags
|= RADEON_FLAG_GTT_WC
;
2683 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2684 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2686 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2690 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2693 mem
->type_index
= mem_type_index
;
2696 result
= radv_bo_list_add(&device
->bo_list
, mem
->bo
);
2697 if (result
!= VK_SUCCESS
)
2700 *pMem
= radv_device_memory_to_handle(mem
);
2705 device
->ws
->buffer_destroy(mem
->bo
);
2707 vk_free2(&device
->alloc
, pAllocator
, mem
);
2712 VkResult
radv_AllocateMemory(
2714 const VkMemoryAllocateInfo
* pAllocateInfo
,
2715 const VkAllocationCallbacks
* pAllocator
,
2716 VkDeviceMemory
* pMem
)
2718 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2719 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2722 void radv_FreeMemory(
2724 VkDeviceMemory _mem
,
2725 const VkAllocationCallbacks
* pAllocator
)
2727 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2728 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2733 radv_bo_list_remove(&device
->bo_list
, mem
->bo
);
2734 device
->ws
->buffer_destroy(mem
->bo
);
2737 vk_free2(&device
->alloc
, pAllocator
, mem
);
2740 VkResult
radv_MapMemory(
2742 VkDeviceMemory _memory
,
2743 VkDeviceSize offset
,
2745 VkMemoryMapFlags flags
,
2748 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2749 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2757 *ppData
= mem
->user_ptr
;
2759 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2766 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2769 void radv_UnmapMemory(
2771 VkDeviceMemory _memory
)
2773 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2774 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2779 if (mem
->user_ptr
== NULL
)
2780 device
->ws
->buffer_unmap(mem
->bo
);
2783 VkResult
radv_FlushMappedMemoryRanges(
2785 uint32_t memoryRangeCount
,
2786 const VkMappedMemoryRange
* pMemoryRanges
)
2791 VkResult
radv_InvalidateMappedMemoryRanges(
2793 uint32_t memoryRangeCount
,
2794 const VkMappedMemoryRange
* pMemoryRanges
)
2799 void radv_GetBufferMemoryRequirements(
2802 VkMemoryRequirements
* pMemoryRequirements
)
2804 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2805 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2807 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2809 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2810 pMemoryRequirements
->alignment
= 4096;
2812 pMemoryRequirements
->alignment
= 16;
2814 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2817 void radv_GetBufferMemoryRequirements2(
2819 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2820 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2822 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2823 &pMemoryRequirements
->memoryRequirements
);
2824 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2825 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2826 switch (ext
->sType
) {
2827 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2828 VkMemoryDedicatedRequirementsKHR
*req
=
2829 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2830 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2831 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2840 void radv_GetImageMemoryRequirements(
2843 VkMemoryRequirements
* pMemoryRequirements
)
2845 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2846 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2848 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2850 pMemoryRequirements
->size
= image
->size
;
2851 pMemoryRequirements
->alignment
= image
->alignment
;
2854 void radv_GetImageMemoryRequirements2(
2856 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2857 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2859 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2860 &pMemoryRequirements
->memoryRequirements
);
2862 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2864 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2865 switch (ext
->sType
) {
2866 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2867 VkMemoryDedicatedRequirementsKHR
*req
=
2868 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2869 req
->requiresDedicatedAllocation
= image
->shareable
;
2870 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2879 void radv_GetImageSparseMemoryRequirements(
2882 uint32_t* pSparseMemoryRequirementCount
,
2883 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2888 void radv_GetImageSparseMemoryRequirements2(
2890 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2891 uint32_t* pSparseMemoryRequirementCount
,
2892 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2897 void radv_GetDeviceMemoryCommitment(
2899 VkDeviceMemory memory
,
2900 VkDeviceSize
* pCommittedMemoryInBytes
)
2902 *pCommittedMemoryInBytes
= 0;
2905 VkResult
radv_BindBufferMemory2(VkDevice device
,
2906 uint32_t bindInfoCount
,
2907 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2909 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2910 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2911 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2914 buffer
->bo
= mem
->bo
;
2915 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2923 VkResult
radv_BindBufferMemory(
2926 VkDeviceMemory memory
,
2927 VkDeviceSize memoryOffset
)
2929 const VkBindBufferMemoryInfoKHR info
= {
2930 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2933 .memoryOffset
= memoryOffset
2936 return radv_BindBufferMemory2(device
, 1, &info
);
2939 VkResult
radv_BindImageMemory2(VkDevice device
,
2940 uint32_t bindInfoCount
,
2941 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2943 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2944 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2945 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2948 image
->bo
= mem
->bo
;
2949 image
->offset
= pBindInfos
[i
].memoryOffset
;
2959 VkResult
radv_BindImageMemory(
2962 VkDeviceMemory memory
,
2963 VkDeviceSize memoryOffset
)
2965 const VkBindImageMemoryInfoKHR info
= {
2966 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2969 .memoryOffset
= memoryOffset
2972 return radv_BindImageMemory2(device
, 1, &info
);
2977 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2978 const VkSparseBufferMemoryBindInfo
*bind
)
2980 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2982 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2983 struct radv_device_memory
*mem
= NULL
;
2985 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2986 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2988 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2989 bind
->pBinds
[i
].resourceOffset
,
2990 bind
->pBinds
[i
].size
,
2991 mem
? mem
->bo
: NULL
,
2992 bind
->pBinds
[i
].memoryOffset
);
2997 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2998 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3000 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3002 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3003 struct radv_device_memory
*mem
= NULL
;
3005 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3006 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3008 device
->ws
->buffer_virtual_bind(image
->bo
,
3009 bind
->pBinds
[i
].resourceOffset
,
3010 bind
->pBinds
[i
].size
,
3011 mem
? mem
->bo
: NULL
,
3012 bind
->pBinds
[i
].memoryOffset
);
3016 VkResult
radv_QueueBindSparse(
3018 uint32_t bindInfoCount
,
3019 const VkBindSparseInfo
* pBindInfo
,
3022 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3023 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3024 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3025 bool fence_emitted
= false;
3027 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3028 struct radv_winsys_sem_info sem_info
;
3029 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3030 radv_sparse_buffer_bind_memory(queue
->device
,
3031 pBindInfo
[i
].pBufferBinds
+ j
);
3034 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3035 radv_sparse_image_opaque_bind_memory(queue
->device
,
3036 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3040 result
= radv_alloc_sem_info(&sem_info
,
3041 pBindInfo
[i
].waitSemaphoreCount
,
3042 pBindInfo
[i
].pWaitSemaphores
,
3043 pBindInfo
[i
].signalSemaphoreCount
,
3044 pBindInfo
[i
].pSignalSemaphores
,
3046 if (result
!= VK_SUCCESS
)
3049 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3050 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3051 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3055 fence_emitted
= true;
3057 fence
->submitted
= true;
3060 radv_free_sem_info(&sem_info
);
3065 if (!fence_emitted
) {
3066 radv_signal_fence(queue
, fence
);
3068 fence
->submitted
= true;
3074 VkResult
radv_CreateFence(
3076 const VkFenceCreateInfo
* pCreateInfo
,
3077 const VkAllocationCallbacks
* pAllocator
,
3080 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3081 const VkExportFenceCreateInfoKHR
*export
=
3082 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3083 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3084 export
? export
->handleTypes
: 0;
3086 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3088 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3091 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3093 fence
->submitted
= false;
3094 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3095 fence
->temp_syncobj
= 0;
3096 if (device
->always_use_syncobj
|| handleTypes
) {
3097 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3099 vk_free2(&device
->alloc
, pAllocator
, fence
);
3100 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3102 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3103 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3105 fence
->fence
= NULL
;
3107 fence
->fence
= device
->ws
->create_fence();
3108 if (!fence
->fence
) {
3109 vk_free2(&device
->alloc
, pAllocator
, fence
);
3110 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3115 *pFence
= radv_fence_to_handle(fence
);
3120 void radv_DestroyFence(
3123 const VkAllocationCallbacks
* pAllocator
)
3125 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3126 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3131 if (fence
->temp_syncobj
)
3132 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3134 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3136 device
->ws
->destroy_fence(fence
->fence
);
3137 vk_free2(&device
->alloc
, pAllocator
, fence
);
3141 static uint64_t radv_get_current_time()
3144 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3145 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3148 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3150 uint64_t current_time
= radv_get_current_time();
3152 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3154 return current_time
+ timeout
;
3158 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3160 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3161 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3162 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3168 VkResult
radv_WaitForFences(
3170 uint32_t fenceCount
,
3171 const VkFence
* pFences
,
3175 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3176 timeout
= radv_get_absolute_timeout(timeout
);
3178 if (device
->always_use_syncobj
) {
3179 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3181 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3183 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3184 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3185 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3188 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3191 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3194 if (!waitAll
&& fenceCount
> 1) {
3195 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3196 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3197 uint32_t wait_count
= 0;
3198 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3200 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3202 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3203 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3205 if (fence
->signalled
) {
3210 fences
[wait_count
++] = fence
->fence
;
3213 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3214 waitAll
, timeout
- radv_get_current_time());
3217 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3220 while(radv_get_current_time() <= timeout
) {
3221 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3222 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3229 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3230 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3231 bool expired
= false;
3233 if (fence
->temp_syncobj
) {
3234 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3239 if (fence
->syncobj
) {
3240 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3245 if (fence
->signalled
)
3248 if (!fence
->submitted
) {
3249 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3252 if (!fence
->submitted
)
3255 /* Recheck as it may have been set by submitting operations. */
3256 if (fence
->signalled
)
3260 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3264 fence
->signalled
= true;
3270 VkResult
radv_ResetFences(VkDevice _device
,
3271 uint32_t fenceCount
,
3272 const VkFence
*pFences
)
3274 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3276 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3277 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3278 fence
->submitted
= fence
->signalled
= false;
3280 /* Per spec, we first restore the permanent payload, and then reset, so
3281 * having a temp syncobj should not skip resetting the permanent syncobj. */
3282 if (fence
->temp_syncobj
) {
3283 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3284 fence
->temp_syncobj
= 0;
3287 if (fence
->syncobj
) {
3288 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3295 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3297 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3298 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3300 if (fence
->temp_syncobj
) {
3301 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3302 return success
? VK_SUCCESS
: VK_NOT_READY
;
3305 if (fence
->syncobj
) {
3306 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3307 return success
? VK_SUCCESS
: VK_NOT_READY
;
3310 if (fence
->signalled
)
3312 if (!fence
->submitted
)
3313 return VK_NOT_READY
;
3314 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3315 return VK_NOT_READY
;
3321 // Queue semaphore functions
3323 VkResult
radv_CreateSemaphore(
3325 const VkSemaphoreCreateInfo
* pCreateInfo
,
3326 const VkAllocationCallbacks
* pAllocator
,
3327 VkSemaphore
* pSemaphore
)
3329 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3330 const VkExportSemaphoreCreateInfoKHR
*export
=
3331 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3332 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3333 export
? export
->handleTypes
: 0;
3335 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3337 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3339 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3341 sem
->temp_syncobj
= 0;
3342 /* create a syncobject if we are going to export this semaphore */
3343 if (device
->always_use_syncobj
|| handleTypes
) {
3344 assert (device
->physical_device
->rad_info
.has_syncobj
);
3345 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3347 vk_free2(&device
->alloc
, pAllocator
, sem
);
3348 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3352 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3354 vk_free2(&device
->alloc
, pAllocator
, sem
);
3355 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3360 *pSemaphore
= radv_semaphore_to_handle(sem
);
3364 void radv_DestroySemaphore(
3366 VkSemaphore _semaphore
,
3367 const VkAllocationCallbacks
* pAllocator
)
3369 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3370 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3375 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3377 device
->ws
->destroy_sem(sem
->sem
);
3378 vk_free2(&device
->alloc
, pAllocator
, sem
);
3381 VkResult
radv_CreateEvent(
3383 const VkEventCreateInfo
* pCreateInfo
,
3384 const VkAllocationCallbacks
* pAllocator
,
3387 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3388 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3390 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3393 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3395 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3397 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3399 vk_free2(&device
->alloc
, pAllocator
, event
);
3400 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3403 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3405 *pEvent
= radv_event_to_handle(event
);
3410 void radv_DestroyEvent(
3413 const VkAllocationCallbacks
* pAllocator
)
3415 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3416 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3420 device
->ws
->buffer_destroy(event
->bo
);
3421 vk_free2(&device
->alloc
, pAllocator
, event
);
3424 VkResult
radv_GetEventStatus(
3428 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3430 if (*event
->map
== 1)
3431 return VK_EVENT_SET
;
3432 return VK_EVENT_RESET
;
3435 VkResult
radv_SetEvent(
3439 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3445 VkResult
radv_ResetEvent(
3449 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3455 VkResult
radv_CreateBuffer(
3457 const VkBufferCreateInfo
* pCreateInfo
,
3458 const VkAllocationCallbacks
* pAllocator
,
3461 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3462 struct radv_buffer
*buffer
;
3464 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3466 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3467 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3469 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3471 buffer
->size
= pCreateInfo
->size
;
3472 buffer
->usage
= pCreateInfo
->usage
;
3475 buffer
->flags
= pCreateInfo
->flags
;
3477 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3478 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3480 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3481 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3482 align64(buffer
->size
, 4096),
3483 4096, 0, RADEON_FLAG_VIRTUAL
);
3485 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3486 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3490 *pBuffer
= radv_buffer_to_handle(buffer
);
3495 void radv_DestroyBuffer(
3498 const VkAllocationCallbacks
* pAllocator
)
3500 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3501 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3506 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3507 device
->ws
->buffer_destroy(buffer
->bo
);
3509 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3512 static inline unsigned
3513 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3516 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3518 return image
->surface
.u
.legacy
.tiling_index
[level
];
3521 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3523 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3527 radv_init_dcc_control_reg(struct radv_device
*device
,
3528 struct radv_image_view
*iview
)
3530 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3531 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3532 unsigned max_compressed_block_size
;
3533 unsigned independent_64b_blocks
;
3535 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3538 if (iview
->image
->info
.samples
> 1) {
3539 if (iview
->image
->surface
.bpe
== 1)
3540 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3541 else if (iview
->image
->surface
.bpe
== 2)
3542 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3545 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3546 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3547 * dGPU and 64 for APU because all of our APUs to date use
3548 * DIMMs which have a request granularity size of 64B while all
3549 * other chips have a 32B request size.
3551 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3554 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3555 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3556 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3557 /* If this DCC image is potentially going to be used in texture
3558 * fetches, we need some special settings.
3560 independent_64b_blocks
= 1;
3561 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3563 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3564 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3565 * big as possible for better compression state.
3567 independent_64b_blocks
= 0;
3568 max_compressed_block_size
= max_uncompressed_block_size
;
3571 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3572 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3573 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3574 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3578 radv_initialise_color_surface(struct radv_device
*device
,
3579 struct radv_color_buffer_info
*cb
,
3580 struct radv_image_view
*iview
)
3582 const struct vk_format_description
*desc
;
3583 unsigned ntype
, format
, swap
, endian
;
3584 unsigned blend_clamp
= 0, blend_bypass
= 0;
3586 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3588 desc
= vk_format_description(iview
->vk_format
);
3590 memset(cb
, 0, sizeof(*cb
));
3592 /* Intensity is implemented as Red, so treat it that way. */
3593 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3595 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3597 cb
->cb_color_base
= va
>> 8;
3599 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3600 struct gfx9_surf_meta_flags meta
;
3601 if (iview
->image
->dcc_offset
)
3602 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3604 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3606 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3607 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3608 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3609 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3611 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3612 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3614 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3615 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3617 cb
->cb_color_base
+= level_info
->offset
>> 8;
3618 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3619 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3621 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3622 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3623 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3625 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3626 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3627 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3629 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3631 if (radv_image_has_fmask(iview
->image
)) {
3632 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3633 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3634 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3635 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3637 /* This must be set for fast clear to work without FMASK. */
3638 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3639 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3640 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3641 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3645 /* CMASK variables */
3646 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3647 va
+= iview
->image
->cmask
.offset
;
3648 cb
->cb_color_cmask
= va
>> 8;
3650 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3651 va
+= iview
->image
->dcc_offset
;
3652 cb
->cb_dcc_base
= va
>> 8;
3653 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3655 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3656 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3657 S_028C6C_SLICE_MAX(max_slice
);
3659 if (iview
->image
->info
.samples
> 1) {
3660 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3662 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3663 S_028C74_NUM_FRAGMENTS(log_samples
);
3666 if (radv_image_has_fmask(iview
->image
)) {
3667 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3668 cb
->cb_color_fmask
= va
>> 8;
3669 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3671 cb
->cb_color_fmask
= cb
->cb_color_base
;
3674 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3676 vk_format_get_first_non_void_channel(iview
->vk_format
));
3677 format
= radv_translate_colorformat(iview
->vk_format
);
3678 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3679 radv_finishme("Illegal color\n");
3680 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3681 endian
= radv_colorformat_endian_swap(format
);
3683 /* blend clamp should be set for all NORM/SRGB types */
3684 if (ntype
== V_028C70_NUMBER_UNORM
||
3685 ntype
== V_028C70_NUMBER_SNORM
||
3686 ntype
== V_028C70_NUMBER_SRGB
)
3689 /* set blend bypass according to docs if SINT/UINT or
3690 8/24 COLOR variants */
3691 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3692 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3693 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3698 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3699 (format
== V_028C70_COLOR_8
||
3700 format
== V_028C70_COLOR_8_8
||
3701 format
== V_028C70_COLOR_8_8_8_8
))
3702 ->color_is_int8
= true;
3704 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3705 S_028C70_COMP_SWAP(swap
) |
3706 S_028C70_BLEND_CLAMP(blend_clamp
) |
3707 S_028C70_BLEND_BYPASS(blend_bypass
) |
3708 S_028C70_SIMPLE_FLOAT(1) |
3709 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3710 ntype
!= V_028C70_NUMBER_SNORM
&&
3711 ntype
!= V_028C70_NUMBER_SRGB
&&
3712 format
!= V_028C70_COLOR_8_24
&&
3713 format
!= V_028C70_COLOR_24_8
) |
3714 S_028C70_NUMBER_TYPE(ntype
) |
3715 S_028C70_ENDIAN(endian
);
3716 if (radv_image_has_fmask(iview
->image
)) {
3717 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3718 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3719 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3720 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3724 if (radv_image_has_cmask(iview
->image
) &&
3725 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3726 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3728 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3729 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3731 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3733 /* This must be set for fast clear to work without FMASK. */
3734 if (!radv_image_has_fmask(iview
->image
) &&
3735 device
->physical_device
->rad_info
.chip_class
== SI
) {
3736 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3737 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3740 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3741 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3742 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3744 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3745 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3746 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3747 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3748 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3749 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3754 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3755 struct radv_image_view
*iview
)
3757 unsigned max_zplanes
= 0;
3759 assert(radv_image_is_tc_compat_htile(iview
->image
));
3761 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3762 /* Default value for 32-bit depth surfaces. */
3765 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3766 iview
->image
->info
.samples
> 1)
3769 max_zplanes
= max_zplanes
+ 1;
3771 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3772 /* Do not enable Z plane compression for 16-bit depth
3773 * surfaces because isn't supported on GFX8. Only
3774 * 32-bit depth surfaces are supported by the hardware.
3775 * This allows to maintain shader compatibility and to
3776 * reduce the number of depth decompressions.
3780 if (iview
->image
->info
.samples
<= 1)
3782 else if (iview
->image
->info
.samples
<= 4)
3793 radv_initialise_ds_surface(struct radv_device
*device
,
3794 struct radv_ds_buffer_info
*ds
,
3795 struct radv_image_view
*iview
)
3797 unsigned level
= iview
->base_mip
;
3798 unsigned format
, stencil_format
;
3799 uint64_t va
, s_offs
, z_offs
;
3800 bool stencil_only
= false;
3801 memset(ds
, 0, sizeof(*ds
));
3802 switch (iview
->image
->vk_format
) {
3803 case VK_FORMAT_D24_UNORM_S8_UINT
:
3804 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3805 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3806 ds
->offset_scale
= 2.0f
;
3808 case VK_FORMAT_D16_UNORM
:
3809 case VK_FORMAT_D16_UNORM_S8_UINT
:
3810 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3811 ds
->offset_scale
= 4.0f
;
3813 case VK_FORMAT_D32_SFLOAT
:
3814 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3815 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3816 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3817 ds
->offset_scale
= 1.0f
;
3819 case VK_FORMAT_S8_UINT
:
3820 stencil_only
= true;
3826 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3827 stencil_format
= iview
->image
->surface
.has_stencil
?
3828 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3830 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3831 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3832 S_028008_SLICE_MAX(max_slice
);
3834 ds
->db_htile_data_base
= 0;
3835 ds
->db_htile_surface
= 0;
3837 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3838 s_offs
= z_offs
= va
;
3840 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3841 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3842 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3844 ds
->db_z_info
= S_028038_FORMAT(format
) |
3845 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3846 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3847 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3848 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3849 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3851 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3852 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3853 ds
->db_depth_view
|= S_028008_MIPID(level
);
3855 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3856 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3858 if (radv_htile_enabled(iview
->image
, level
)) {
3859 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3861 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3862 unsigned max_zplanes
=
3863 radv_calc_decompress_on_z_planes(device
, iview
);
3865 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3866 S_028038_ITERATE_FLUSH(1);
3867 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3870 if (!iview
->image
->surface
.has_stencil
)
3871 /* Use all of the htile_buffer for depth if there's no stencil. */
3872 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3873 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3874 iview
->image
->htile_offset
;
3875 ds
->db_htile_data_base
= va
>> 8;
3876 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3877 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3878 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3881 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3884 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3886 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3887 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3889 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3890 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3891 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3893 if (iview
->image
->info
.samples
> 1)
3894 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3896 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3897 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3898 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3899 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3900 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3901 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3902 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3903 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3906 tile_mode
= stencil_tile_mode
;
3908 ds
->db_depth_info
|=
3909 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3910 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3911 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3912 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3913 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3914 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3915 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3916 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3918 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3919 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3920 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3921 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3923 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3926 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3927 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3928 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3930 if (radv_htile_enabled(iview
->image
, level
)) {
3931 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3933 if (!iview
->image
->surface
.has_stencil
&&
3934 !radv_image_is_tc_compat_htile(iview
->image
))
3935 /* Use all of the htile_buffer for depth if there's no stencil. */
3936 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3938 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3939 iview
->image
->htile_offset
;
3940 ds
->db_htile_data_base
= va
>> 8;
3941 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3943 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3944 unsigned max_zplanes
=
3945 radv_calc_decompress_on_z_planes(device
, iview
);
3947 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3948 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
3953 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3954 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3957 VkResult
radv_CreateFramebuffer(
3959 const VkFramebufferCreateInfo
* pCreateInfo
,
3960 const VkAllocationCallbacks
* pAllocator
,
3961 VkFramebuffer
* pFramebuffer
)
3963 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3964 struct radv_framebuffer
*framebuffer
;
3966 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3968 size_t size
= sizeof(*framebuffer
) +
3969 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3970 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3971 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3972 if (framebuffer
== NULL
)
3973 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3975 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3976 framebuffer
->width
= pCreateInfo
->width
;
3977 framebuffer
->height
= pCreateInfo
->height
;
3978 framebuffer
->layers
= pCreateInfo
->layers
;
3979 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3980 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3981 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3982 framebuffer
->attachments
[i
].attachment
= iview
;
3983 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3984 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3985 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3986 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3988 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3989 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3990 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
3993 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3997 void radv_DestroyFramebuffer(
4000 const VkAllocationCallbacks
* pAllocator
)
4002 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4003 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4007 vk_free2(&device
->alloc
, pAllocator
, fb
);
4010 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4012 switch (address_mode
) {
4013 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4014 return V_008F30_SQ_TEX_WRAP
;
4015 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4016 return V_008F30_SQ_TEX_MIRROR
;
4017 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4018 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4019 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4020 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4021 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4022 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4024 unreachable("illegal tex wrap mode");
4030 radv_tex_compare(VkCompareOp op
)
4033 case VK_COMPARE_OP_NEVER
:
4034 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4035 case VK_COMPARE_OP_LESS
:
4036 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4037 case VK_COMPARE_OP_EQUAL
:
4038 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4039 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4040 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4041 case VK_COMPARE_OP_GREATER
:
4042 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4043 case VK_COMPARE_OP_NOT_EQUAL
:
4044 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4045 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4046 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4047 case VK_COMPARE_OP_ALWAYS
:
4048 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4050 unreachable("illegal compare mode");
4056 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4059 case VK_FILTER_NEAREST
:
4060 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4061 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4062 case VK_FILTER_LINEAR
:
4063 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4064 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4065 case VK_FILTER_CUBIC_IMG
:
4067 fprintf(stderr
, "illegal texture filter");
4073 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4076 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4077 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4078 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4079 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4081 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4086 radv_tex_bordercolor(VkBorderColor bcolor
)
4089 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4090 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4091 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4092 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4093 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4094 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4095 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4096 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4097 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4105 radv_tex_aniso_filter(unsigned filter
)
4119 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4122 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4123 return SQ_IMG_FILTER_MODE_BLEND
;
4124 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4125 return SQ_IMG_FILTER_MODE_MIN
;
4126 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4127 return SQ_IMG_FILTER_MODE_MAX
;
4135 radv_init_sampler(struct radv_device
*device
,
4136 struct radv_sampler
*sampler
,
4137 const VkSamplerCreateInfo
*pCreateInfo
)
4139 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4140 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4141 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4142 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4143 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4145 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4146 vk_find_struct_const(pCreateInfo
->pNext
,
4147 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4148 if (sampler_reduction
)
4149 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4151 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4152 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4153 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4154 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4155 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4156 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4157 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4158 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4159 S_008F30_DISABLE_CUBE_WRAP(0) |
4160 S_008F30_COMPAT_MODE(is_vi
) |
4161 S_008F30_FILTER_MODE(filter_mode
));
4162 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4163 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4164 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4165 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4166 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4167 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4168 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4169 S_008F38_MIP_POINT_PRECLAMP(0) |
4170 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4171 S_008F38_FILTER_PREC_FIX(1) |
4172 S_008F38_ANISO_OVERRIDE(is_vi
));
4173 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4174 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4177 VkResult
radv_CreateSampler(
4179 const VkSamplerCreateInfo
* pCreateInfo
,
4180 const VkAllocationCallbacks
* pAllocator
,
4181 VkSampler
* pSampler
)
4183 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4184 struct radv_sampler
*sampler
;
4186 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4188 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4189 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4191 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4193 radv_init_sampler(device
, sampler
, pCreateInfo
);
4194 *pSampler
= radv_sampler_to_handle(sampler
);
4199 void radv_DestroySampler(
4202 const VkAllocationCallbacks
* pAllocator
)
4204 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4205 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4209 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4212 /* vk_icd.h does not declare this function, so we declare it here to
4213 * suppress Wmissing-prototypes.
4215 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4216 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4218 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4219 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4221 /* For the full details on loader interface versioning, see
4222 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4223 * What follows is a condensed summary, to help you navigate the large and
4224 * confusing official doc.
4226 * - Loader interface v0 is incompatible with later versions. We don't
4229 * - In loader interface v1:
4230 * - The first ICD entrypoint called by the loader is
4231 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4233 * - The ICD must statically expose no other Vulkan symbol unless it is
4234 * linked with -Bsymbolic.
4235 * - Each dispatchable Vulkan handle created by the ICD must be
4236 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4237 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4238 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4239 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4240 * such loader-managed surfaces.
4242 * - Loader interface v2 differs from v1 in:
4243 * - The first ICD entrypoint called by the loader is
4244 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4245 * statically expose this entrypoint.
4247 * - Loader interface v3 differs from v2 in:
4248 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4249 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4250 * because the loader no longer does so.
4252 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4256 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4257 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4260 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4261 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4263 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4265 /* At the moment, we support only the below handle types. */
4266 assert(pGetFdInfo
->handleType
==
4267 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4268 pGetFdInfo
->handleType
==
4269 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4271 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4273 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4277 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4278 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4280 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4282 switch (handleType
) {
4283 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4284 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4288 /* The valid usage section for this function says:
4290 * "handleType must not be one of the handle types defined as
4293 * So opaque handle types fall into the default "unsupported" case.
4295 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4299 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4303 uint32_t syncobj_handle
= 0;
4304 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4306 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4309 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4311 *syncobj
= syncobj_handle
;
4317 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4321 /* If we create a syncobj we do it locally so that if we have an error, we don't
4322 * leave a syncobj in an undetermined state in the fence. */
4323 uint32_t syncobj_handle
= *syncobj
;
4324 if (!syncobj_handle
) {
4325 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4327 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4332 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4334 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4336 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4339 *syncobj
= syncobj_handle
;
4346 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4347 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4349 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4350 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4351 uint32_t *syncobj_dst
= NULL
;
4353 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4354 syncobj_dst
= &sem
->temp_syncobj
;
4356 syncobj_dst
= &sem
->syncobj
;
4359 switch(pImportSemaphoreFdInfo
->handleType
) {
4360 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4361 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4362 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4363 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4365 unreachable("Unhandled semaphore handle type");
4369 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4370 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4373 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4374 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4376 uint32_t syncobj_handle
;
4378 if (sem
->temp_syncobj
)
4379 syncobj_handle
= sem
->temp_syncobj
;
4381 syncobj_handle
= sem
->syncobj
;
4383 switch(pGetFdInfo
->handleType
) {
4384 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4385 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4387 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4388 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4390 if (sem
->temp_syncobj
) {
4391 close (sem
->temp_syncobj
);
4392 sem
->temp_syncobj
= 0;
4394 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4399 unreachable("Unhandled semaphore handle type");
4403 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4407 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4408 VkPhysicalDevice physicalDevice
,
4409 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4410 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4412 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4414 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4415 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4416 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4417 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4418 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4419 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4420 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4421 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4422 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4423 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4424 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4425 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4426 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4428 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4429 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4430 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4434 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4435 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4437 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4438 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4439 uint32_t *syncobj_dst
= NULL
;
4442 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4443 syncobj_dst
= &fence
->temp_syncobj
;
4445 syncobj_dst
= &fence
->syncobj
;
4448 switch(pImportFenceFdInfo
->handleType
) {
4449 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4450 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4451 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4452 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4454 unreachable("Unhandled fence handle type");
4458 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4459 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4462 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4463 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4465 uint32_t syncobj_handle
;
4467 if (fence
->temp_syncobj
)
4468 syncobj_handle
= fence
->temp_syncobj
;
4470 syncobj_handle
= fence
->syncobj
;
4472 switch(pGetFdInfo
->handleType
) {
4473 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4474 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4476 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4477 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4479 if (fence
->temp_syncobj
) {
4480 close (fence
->temp_syncobj
);
4481 fence
->temp_syncobj
= 0;
4483 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4488 unreachable("Unhandled fence handle type");
4492 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4496 void radv_GetPhysicalDeviceExternalFenceProperties(
4497 VkPhysicalDevice physicalDevice
,
4498 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4499 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4501 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4503 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4504 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4505 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4506 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4507 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4508 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4509 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4511 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4512 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4513 pExternalFenceProperties
->externalFenceFeatures
= 0;
4518 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4519 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4520 const VkAllocationCallbacks
* pAllocator
,
4521 VkDebugReportCallbackEXT
* pCallback
)
4523 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4524 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4525 pCreateInfo
, pAllocator
, &instance
->alloc
,
4530 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4531 VkDebugReportCallbackEXT _callback
,
4532 const VkAllocationCallbacks
* pAllocator
)
4534 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4535 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4536 _callback
, pAllocator
, &instance
->alloc
);
4540 radv_DebugReportMessageEXT(VkInstance _instance
,
4541 VkDebugReportFlagsEXT flags
,
4542 VkDebugReportObjectTypeEXT objectType
,
4545 int32_t messageCode
,
4546 const char* pLayerPrefix
,
4547 const char* pMessage
)
4549 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4550 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4551 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4555 radv_GetDeviceGroupPeerMemoryFeatures(
4558 uint32_t localDeviceIndex
,
4559 uint32_t remoteDeviceIndex
,
4560 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4562 assert(localDeviceIndex
== remoteDeviceIndex
);
4564 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4565 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4566 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4567 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;