2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
53 uint32_t mesa_timestamp
, llvm_timestamp
;
55 memset(uuid
, 0, VK_UUID_SIZE
);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
60 memcpy(uuid
, &mesa_timestamp
, 4);
61 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
62 memcpy((char*)uuid
+ 8, &f
, 2);
63 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
68 radv_get_driver_uuid(void *uuid
)
70 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
74 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
76 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
80 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
82 const char *chip_string
;
83 char llvm_string
[32] = {};
86 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
87 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
88 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
89 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
90 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
91 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
92 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
93 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
94 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
95 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
96 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
97 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
98 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
99 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
100 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
101 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
102 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
103 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
104 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
105 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
106 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
107 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
108 default: chip_string
= "AMD RADV unknown"; break;
112 snprintf(llvm_string
, sizeof(llvm_string
),
113 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
114 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
117 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
121 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
123 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
124 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
125 device
->rad_info
.vram_vis_size
);
127 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
128 device
->memory_properties
.memoryHeapCount
= 0;
129 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
130 vram_index
= device
->memory_properties
.memoryHeapCount
++;
131 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
132 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
133 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
136 if (visible_vram_size
) {
137 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
138 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
139 .size
= visible_vram_size
,
140 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
143 if (device
->rad_info
.gart_size
> 0) {
144 gart_index
= device
->memory_properties
.memoryHeapCount
++;
145 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
146 .size
= device
->rad_info
.gart_size
,
147 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
151 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
152 unsigned type_count
= 0;
153 if (vram_index
>= 0) {
154 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
155 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
156 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
157 .heapIndex
= vram_index
,
160 if (gart_index
>= 0) {
161 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
162 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
163 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
164 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
165 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
166 .heapIndex
= gart_index
,
169 if (visible_vram_index
>= 0) {
170 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
171 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
172 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
173 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
174 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
175 .heapIndex
= visible_vram_index
,
178 if (gart_index
>= 0) {
179 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
180 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
181 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
182 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
183 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
184 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
185 .heapIndex
= gart_index
,
188 device
->memory_properties
.memoryTypeCount
= type_count
;
192 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
194 const char *family
= getenv("RADV_FORCE_FAMILY");
200 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
201 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
202 /* Override family and chip_class. */
203 device
->rad_info
.family
= i
;
205 if (i
>= CHIP_VEGA10
)
206 device
->rad_info
.chip_class
= GFX9
;
207 else if (i
>= CHIP_TONGA
)
208 device
->rad_info
.chip_class
= VI
;
209 else if (i
>= CHIP_BONAIRE
)
210 device
->rad_info
.chip_class
= CIK
;
212 device
->rad_info
.chip_class
= SI
;
218 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
223 radv_physical_device_init(struct radv_physical_device
*device
,
224 struct radv_instance
*instance
,
225 drmDevicePtr drm_device
)
227 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
229 drmVersionPtr version
;
232 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
234 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
236 version
= drmGetVersion(fd
);
239 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
240 "failed to get version %s: %m", path
);
243 if (strcmp(version
->name
, "amdgpu")) {
244 drmFreeVersion(version
);
246 return VK_ERROR_INCOMPATIBLE_DRIVER
;
248 drmFreeVersion(version
);
250 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
251 device
->instance
= instance
;
252 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
253 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
255 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
256 instance
->perftest_flags
);
258 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
262 device
->local_fd
= fd
;
263 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
265 radv_handle_env_var_force_family(device
);
267 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
269 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
270 device
->ws
->destroy(device
->ws
);
271 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
272 "cannot generate UUID");
276 /* These flags affect shader compilation. */
277 uint64_t shader_env_flags
=
278 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
279 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
281 /* The gpu id is already embedded in the uuid so we just pass "radv"
282 * when creating the cache.
284 char buf
[VK_UUID_SIZE
* 2 + 1];
285 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
286 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
288 if (device
->rad_info
.chip_class
< VI
||
289 device
->rad_info
.chip_class
> GFX9
)
290 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
292 radv_get_driver_uuid(&device
->device_uuid
);
293 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
295 if (device
->rad_info
.family
== CHIP_STONEY
||
296 device
->rad_info
.chip_class
>= GFX9
) {
297 device
->has_rbplus
= true;
298 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
299 device
->rad_info
.family
== CHIP_VEGA12
||
300 device
->rad_info
.family
== CHIP_RAVEN
;
303 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
306 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
308 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
310 /* Vega10/Raven need a special workaround for a hardware bug. */
311 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
312 device
->rad_info
.family
== CHIP_RAVEN
;
314 /* Out-of-order primitive rasterization. */
315 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
316 device
->rad_info
.max_se
>= 2;
317 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
318 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
320 device
->dcc_msaa_allowed
= device
->rad_info
.chip_class
== VI
&&
321 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
323 radv_physical_device_init_mem_types(device
);
324 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
326 result
= radv_init_wsi(device
);
327 if (result
!= VK_SUCCESS
) {
328 device
->ws
->destroy(device
->ws
);
340 radv_physical_device_finish(struct radv_physical_device
*device
)
342 radv_finish_wsi(device
);
343 device
->ws
->destroy(device
->ws
);
344 disk_cache_destroy(device
->disk_cache
);
345 close(device
->local_fd
);
349 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
350 VkSystemAllocationScope allocationScope
)
356 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
357 size_t align
, VkSystemAllocationScope allocationScope
)
359 return realloc(pOriginal
, size
);
363 default_free_func(void *pUserData
, void *pMemory
)
368 static const VkAllocationCallbacks default_alloc
= {
370 .pfnAllocation
= default_alloc_func
,
371 .pfnReallocation
= default_realloc_func
,
372 .pfnFree
= default_free_func
,
375 static const struct debug_control radv_debug_options
[] = {
376 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
377 {"nodcc", RADV_DEBUG_NO_DCC
},
378 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
379 {"nocache", RADV_DEBUG_NO_CACHE
},
380 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
381 {"nohiz", RADV_DEBUG_NO_HIZ
},
382 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
383 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
384 {"allbos", RADV_DEBUG_ALL_BOS
},
385 {"noibs", RADV_DEBUG_NO_IBS
},
386 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
387 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
388 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
389 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
390 {"nosisched", RADV_DEBUG_NO_SISCHED
},
391 {"preoptir", RADV_DEBUG_PREOPTIR
},
392 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
393 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
398 radv_get_debug_option_name(int id
)
400 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
401 return radv_debug_options
[id
].string
;
404 static const struct debug_control radv_perftest_options
[] = {
405 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
406 {"sisched", RADV_PERFTEST_SISCHED
},
407 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
408 {"binning", RADV_PERFTEST_BINNING
},
409 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
414 radv_get_perftest_option_name(int id
)
416 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
417 return radv_perftest_options
[id
].string
;
421 radv_handle_per_app_options(struct radv_instance
*instance
,
422 const VkApplicationInfo
*info
)
424 const char *name
= info
? info
->pApplicationName
: NULL
;
429 if (!strcmp(name
, "Talos - Linux - 32bit") ||
430 !strcmp(name
, "Talos - Linux - 64bit")) {
431 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
432 /* Force enable LLVM sisched for Talos because it looks
433 * safe and it gives few more FPS.
435 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
440 static int radv_get_instance_extension_index(const char *name
)
442 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
443 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
450 VkResult
radv_CreateInstance(
451 const VkInstanceCreateInfo
* pCreateInfo
,
452 const VkAllocationCallbacks
* pAllocator
,
453 VkInstance
* pInstance
)
455 struct radv_instance
*instance
;
458 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
460 uint32_t client_version
;
461 if (pCreateInfo
->pApplicationInfo
&&
462 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
463 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
465 radv_EnumerateInstanceVersion(&client_version
);
468 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
469 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
471 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
473 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
476 instance
->alloc
= *pAllocator
;
478 instance
->alloc
= default_alloc
;
480 instance
->apiVersion
= client_version
;
481 instance
->physicalDeviceCount
= -1;
483 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
484 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
485 int index
= radv_get_instance_extension_index(ext_name
);
487 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
488 vk_free2(&default_alloc
, pAllocator
, instance
);
489 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
492 instance
->enabled_extensions
.extensions
[index
] = true;
495 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
496 if (result
!= VK_SUCCESS
) {
497 vk_free2(&default_alloc
, pAllocator
, instance
);
498 return vk_error(result
);
503 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
505 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
508 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
509 radv_perftest_options
);
511 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
513 *pInstance
= radv_instance_to_handle(instance
);
518 void radv_DestroyInstance(
519 VkInstance _instance
,
520 const VkAllocationCallbacks
* pAllocator
)
522 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
527 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
528 radv_physical_device_finish(instance
->physicalDevices
+ i
);
531 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
535 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
537 vk_free(&instance
->alloc
, instance
);
541 radv_enumerate_devices(struct radv_instance
*instance
)
543 /* TODO: Check for more devices ? */
544 drmDevicePtr devices
[8];
545 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
548 instance
->physicalDeviceCount
= 0;
550 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
552 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
554 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
555 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
556 devices
[i
]->bustype
== DRM_BUS_PCI
&&
557 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
559 result
= radv_physical_device_init(instance
->physicalDevices
+
560 instance
->physicalDeviceCount
,
563 if (result
== VK_SUCCESS
)
564 ++instance
->physicalDeviceCount
;
565 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
569 drmFreeDevices(devices
, max_devices
);
574 VkResult
radv_EnumeratePhysicalDevices(
575 VkInstance _instance
,
576 uint32_t* pPhysicalDeviceCount
,
577 VkPhysicalDevice
* pPhysicalDevices
)
579 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
582 if (instance
->physicalDeviceCount
< 0) {
583 result
= radv_enumerate_devices(instance
);
584 if (result
!= VK_SUCCESS
&&
585 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
589 if (!pPhysicalDevices
) {
590 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
592 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
593 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
594 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
597 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
601 VkResult
radv_EnumeratePhysicalDeviceGroups(
602 VkInstance _instance
,
603 uint32_t* pPhysicalDeviceGroupCount
,
604 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
606 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
609 if (instance
->physicalDeviceCount
< 0) {
610 result
= radv_enumerate_devices(instance
);
611 if (result
!= VK_SUCCESS
&&
612 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
616 if (!pPhysicalDeviceGroupProperties
) {
617 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
619 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
620 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
621 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
622 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
623 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
626 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
630 void radv_GetPhysicalDeviceFeatures(
631 VkPhysicalDevice physicalDevice
,
632 VkPhysicalDeviceFeatures
* pFeatures
)
634 memset(pFeatures
, 0, sizeof(*pFeatures
));
636 *pFeatures
= (VkPhysicalDeviceFeatures
) {
637 .robustBufferAccess
= true,
638 .fullDrawIndexUint32
= true,
639 .imageCubeArray
= true,
640 .independentBlend
= true,
641 .geometryShader
= true,
642 .tessellationShader
= true,
643 .sampleRateShading
= true,
644 .dualSrcBlend
= true,
646 .multiDrawIndirect
= true,
647 .drawIndirectFirstInstance
= true,
649 .depthBiasClamp
= true,
650 .fillModeNonSolid
= true,
655 .multiViewport
= true,
656 .samplerAnisotropy
= true,
657 .textureCompressionETC2
= false,
658 .textureCompressionASTC_LDR
= false,
659 .textureCompressionBC
= true,
660 .occlusionQueryPrecise
= true,
661 .pipelineStatisticsQuery
= true,
662 .vertexPipelineStoresAndAtomics
= true,
663 .fragmentStoresAndAtomics
= true,
664 .shaderTessellationAndGeometryPointSize
= true,
665 .shaderImageGatherExtended
= true,
666 .shaderStorageImageExtendedFormats
= true,
667 .shaderStorageImageMultisample
= false,
668 .shaderUniformBufferArrayDynamicIndexing
= true,
669 .shaderSampledImageArrayDynamicIndexing
= true,
670 .shaderStorageBufferArrayDynamicIndexing
= true,
671 .shaderStorageImageArrayDynamicIndexing
= true,
672 .shaderStorageImageReadWithoutFormat
= true,
673 .shaderStorageImageWriteWithoutFormat
= true,
674 .shaderClipDistance
= true,
675 .shaderCullDistance
= true,
676 .shaderFloat64
= true,
678 .shaderInt16
= false,
679 .sparseBinding
= true,
680 .variableMultisampleRate
= true,
681 .inheritedQueries
= true,
685 void radv_GetPhysicalDeviceFeatures2(
686 VkPhysicalDevice physicalDevice
,
687 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
689 vk_foreach_struct(ext
, pFeatures
->pNext
) {
690 switch (ext
->sType
) {
691 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
692 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
693 features
->variablePointersStorageBuffer
= true;
694 features
->variablePointers
= false;
697 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
698 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
699 features
->multiview
= true;
700 features
->multiviewGeometryShader
= true;
701 features
->multiviewTessellationShader
= true;
704 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
705 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
706 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
707 features
->shaderDrawParameters
= true;
710 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
711 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
712 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
713 features
->protectedMemory
= false;
716 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
717 VkPhysicalDevice16BitStorageFeatures
*features
=
718 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
719 features
->storageBuffer16BitAccess
= false;
720 features
->uniformAndStorageBuffer16BitAccess
= false;
721 features
->storagePushConstant16
= false;
722 features
->storageInputOutput16
= false;
725 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
726 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
727 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
728 features
->samplerYcbcrConversion
= false;
731 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
732 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
733 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)features
;
734 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
735 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
736 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
737 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
738 features
->shaderSampledImageArrayNonUniformIndexing
= false;
739 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
740 features
->shaderStorageImageArrayNonUniformIndexing
= false;
741 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
742 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
743 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
744 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
745 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
746 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
747 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
748 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
749 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
750 features
->descriptorBindingUpdateUnusedWhilePending
= true;
751 features
->descriptorBindingPartiallyBound
= true;
752 features
->descriptorBindingVariableDescriptorCount
= true;
753 features
->runtimeDescriptorArray
= true;
760 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
763 void radv_GetPhysicalDeviceProperties(
764 VkPhysicalDevice physicalDevice
,
765 VkPhysicalDeviceProperties
* pProperties
)
767 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
768 VkSampleCountFlags sample_counts
= 0xf;
770 /* make sure that the entire descriptor set is addressable with a signed
771 * 32-bit int. So the sum of all limits scaled by descriptor size has to
772 * be at most 2 GiB. the combined image & samples object count as one of
773 * both. This limit is for the pipeline layout, not for the set layout, but
774 * there is no set limit, so we just set a pipeline limit. I don't think
775 * any app is going to hit this soon. */
776 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
777 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
778 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
779 32 /* sampler, largest when combined with image */ +
780 64 /* sampled image */ +
781 64 /* storage image */);
783 VkPhysicalDeviceLimits limits
= {
784 .maxImageDimension1D
= (1 << 14),
785 .maxImageDimension2D
= (1 << 14),
786 .maxImageDimension3D
= (1 << 11),
787 .maxImageDimensionCube
= (1 << 14),
788 .maxImageArrayLayers
= (1 << 11),
789 .maxTexelBufferElements
= 128 * 1024 * 1024,
790 .maxUniformBufferRange
= UINT32_MAX
,
791 .maxStorageBufferRange
= UINT32_MAX
,
792 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
793 .maxMemoryAllocationCount
= UINT32_MAX
,
794 .maxSamplerAllocationCount
= 64 * 1024,
795 .bufferImageGranularity
= 64, /* A cache line */
796 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
797 .maxBoundDescriptorSets
= MAX_SETS
,
798 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
799 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
800 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
801 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
802 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
803 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
804 .maxPerStageResources
= max_descriptor_set_size
,
805 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
806 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
807 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
808 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
809 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
810 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
811 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
812 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
813 .maxVertexInputAttributes
= 32,
814 .maxVertexInputBindings
= 32,
815 .maxVertexInputAttributeOffset
= 2047,
816 .maxVertexInputBindingStride
= 2048,
817 .maxVertexOutputComponents
= 128,
818 .maxTessellationGenerationLevel
= 64,
819 .maxTessellationPatchSize
= 32,
820 .maxTessellationControlPerVertexInputComponents
= 128,
821 .maxTessellationControlPerVertexOutputComponents
= 128,
822 .maxTessellationControlPerPatchOutputComponents
= 120,
823 .maxTessellationControlTotalOutputComponents
= 4096,
824 .maxTessellationEvaluationInputComponents
= 128,
825 .maxTessellationEvaluationOutputComponents
= 128,
826 .maxGeometryShaderInvocations
= 127,
827 .maxGeometryInputComponents
= 64,
828 .maxGeometryOutputComponents
= 128,
829 .maxGeometryOutputVertices
= 256,
830 .maxGeometryTotalOutputComponents
= 1024,
831 .maxFragmentInputComponents
= 128,
832 .maxFragmentOutputAttachments
= 8,
833 .maxFragmentDualSrcAttachments
= 1,
834 .maxFragmentCombinedOutputResources
= 8,
835 .maxComputeSharedMemorySize
= 32768,
836 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
837 .maxComputeWorkGroupInvocations
= 2048,
838 .maxComputeWorkGroupSize
= {
843 .subPixelPrecisionBits
= 4 /* FIXME */,
844 .subTexelPrecisionBits
= 4 /* FIXME */,
845 .mipmapPrecisionBits
= 4 /* FIXME */,
846 .maxDrawIndexedIndexValue
= UINT32_MAX
,
847 .maxDrawIndirectCount
= UINT32_MAX
,
848 .maxSamplerLodBias
= 16,
849 .maxSamplerAnisotropy
= 16,
850 .maxViewports
= MAX_VIEWPORTS
,
851 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
852 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
853 .viewportSubPixelBits
= 8,
854 .minMemoryMapAlignment
= 4096, /* A page */
855 .minTexelBufferOffsetAlignment
= 1,
856 .minUniformBufferOffsetAlignment
= 4,
857 .minStorageBufferOffsetAlignment
= 4,
858 .minTexelOffset
= -32,
859 .maxTexelOffset
= 31,
860 .minTexelGatherOffset
= -32,
861 .maxTexelGatherOffset
= 31,
862 .minInterpolationOffset
= -2,
863 .maxInterpolationOffset
= 2,
864 .subPixelInterpolationOffsetBits
= 8,
865 .maxFramebufferWidth
= (1 << 14),
866 .maxFramebufferHeight
= (1 << 14),
867 .maxFramebufferLayers
= (1 << 10),
868 .framebufferColorSampleCounts
= sample_counts
,
869 .framebufferDepthSampleCounts
= sample_counts
,
870 .framebufferStencilSampleCounts
= sample_counts
,
871 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
872 .maxColorAttachments
= MAX_RTS
,
873 .sampledImageColorSampleCounts
= sample_counts
,
874 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
875 .sampledImageDepthSampleCounts
= sample_counts
,
876 .sampledImageStencilSampleCounts
= sample_counts
,
877 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
878 .maxSampleMaskWords
= 1,
879 .timestampComputeAndGraphics
= true,
880 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
881 .maxClipDistances
= 8,
882 .maxCullDistances
= 8,
883 .maxCombinedClipAndCullDistances
= 8,
884 .discreteQueuePriorities
= 1,
885 .pointSizeRange
= { 0.125, 255.875 },
886 .lineWidthRange
= { 0.0, 7.9921875 },
887 .pointSizeGranularity
= (1.0 / 8.0),
888 .lineWidthGranularity
= (1.0 / 128.0),
889 .strictLines
= false, /* FINISHME */
890 .standardSampleLocations
= true,
891 .optimalBufferCopyOffsetAlignment
= 128,
892 .optimalBufferCopyRowPitchAlignment
= 128,
893 .nonCoherentAtomSize
= 64,
896 *pProperties
= (VkPhysicalDeviceProperties
) {
897 .apiVersion
= radv_physical_device_api_version(pdevice
),
898 .driverVersion
= vk_get_driver_version(),
899 .vendorID
= ATI_VENDOR_ID
,
900 .deviceID
= pdevice
->rad_info
.pci_id
,
901 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
903 .sparseProperties
= {0},
906 strcpy(pProperties
->deviceName
, pdevice
->name
);
907 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
910 void radv_GetPhysicalDeviceProperties2(
911 VkPhysicalDevice physicalDevice
,
912 VkPhysicalDeviceProperties2KHR
*pProperties
)
914 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
915 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
917 vk_foreach_struct(ext
, pProperties
->pNext
) {
918 switch (ext
->sType
) {
919 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
920 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
921 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
922 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
925 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
926 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
927 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
928 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
929 properties
->deviceLUIDValid
= false;
932 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
933 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
934 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
935 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
938 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
939 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
940 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
941 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
944 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
945 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
946 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
947 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
950 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
951 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
952 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
953 properties
->minImportedHostPointerAlignment
= 4096;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
957 VkPhysicalDeviceSubgroupProperties
*properties
=
958 (VkPhysicalDeviceSubgroupProperties
*)ext
;
959 properties
->subgroupSize
= 64;
960 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
961 properties
->supportedOperations
=
962 VK_SUBGROUP_FEATURE_BASIC_BIT
|
963 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
964 VK_SUBGROUP_FEATURE_QUAD_BIT
|
965 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
966 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
967 VK_SUBGROUP_FEATURE_VOTE_BIT
;
968 properties
->quadOperationsInAllStages
= true;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
972 VkPhysicalDeviceMaintenance3Properties
*properties
=
973 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
974 /* Make sure everything is addressable by a signed 32-bit int, and
975 * our largest descriptors are 96 bytes. */
976 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
977 /* Our buffer size fields allow only this much */
978 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
981 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
982 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
983 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
984 /* GFX6-8 only support single channel min/max filter. */
985 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
986 properties
->filterMinmaxSingleComponentFormats
= true;
989 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
990 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
991 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
993 /* Shader engines. */
994 properties
->shaderEngineCount
=
995 pdevice
->rad_info
.max_se
;
996 properties
->shaderArraysPerEngineCount
=
997 pdevice
->rad_info
.max_sh_per_se
;
998 properties
->computeUnitsPerShaderArray
=
999 pdevice
->rad_info
.num_good_compute_units
/
1000 (pdevice
->rad_info
.max_se
*
1001 pdevice
->rad_info
.max_sh_per_se
);
1002 properties
->simdPerComputeUnit
= 4;
1003 properties
->wavefrontsPerSimd
=
1004 pdevice
->rad_info
.family
== CHIP_TONGA
||
1005 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1006 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1007 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1008 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1009 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1010 properties
->wavefrontSize
= 64;
1013 properties
->sgprsPerSimd
=
1014 radv_get_num_physical_sgprs(pdevice
);
1015 properties
->minSgprAllocation
=
1016 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1017 properties
->maxSgprAllocation
=
1018 pdevice
->rad_info
.family
== CHIP_TONGA
||
1019 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1020 properties
->sgprAllocationGranularity
=
1021 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1024 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1025 properties
->minVgprAllocation
= 4;
1026 properties
->maxVgprAllocation
= 256;
1027 properties
->vgprAllocationGranularity
= 4;
1030 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1031 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1032 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1033 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1036 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1037 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1038 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1039 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1040 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1041 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1042 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1043 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1044 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1045 properties
->robustBufferAccessUpdateAfterBind
= false;
1046 properties
->quadDivergentImplicitLod
= false;
1048 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1049 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1050 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1051 32 /* sampler, largest when combined with image */ +
1052 64 /* sampled image */ +
1053 64 /* storage image */);
1054 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1055 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1056 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1057 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1058 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1059 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1060 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1061 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1062 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1063 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1064 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1065 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1066 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1067 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1068 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1077 static void radv_get_physical_device_queue_family_properties(
1078 struct radv_physical_device
* pdevice
,
1080 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1082 int num_queue_families
= 1;
1084 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1085 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1086 num_queue_families
++;
1088 if (pQueueFamilyProperties
== NULL
) {
1089 *pCount
= num_queue_families
;
1098 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1099 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1100 VK_QUEUE_COMPUTE_BIT
|
1101 VK_QUEUE_TRANSFER_BIT
|
1102 VK_QUEUE_SPARSE_BINDING_BIT
,
1104 .timestampValidBits
= 64,
1105 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1110 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1111 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1112 if (*pCount
> idx
) {
1113 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1114 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1115 VK_QUEUE_TRANSFER_BIT
|
1116 VK_QUEUE_SPARSE_BINDING_BIT
,
1117 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1118 .timestampValidBits
= 64,
1119 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1127 void radv_GetPhysicalDeviceQueueFamilyProperties(
1128 VkPhysicalDevice physicalDevice
,
1130 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1132 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1133 if (!pQueueFamilyProperties
) {
1134 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1137 VkQueueFamilyProperties
*properties
[] = {
1138 pQueueFamilyProperties
+ 0,
1139 pQueueFamilyProperties
+ 1,
1140 pQueueFamilyProperties
+ 2,
1142 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1143 assert(*pCount
<= 3);
1146 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1147 VkPhysicalDevice physicalDevice
,
1149 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1151 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1152 if (!pQueueFamilyProperties
) {
1153 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1156 VkQueueFamilyProperties
*properties
[] = {
1157 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1158 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1159 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1161 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1162 assert(*pCount
<= 3);
1165 void radv_GetPhysicalDeviceMemoryProperties(
1166 VkPhysicalDevice physicalDevice
,
1167 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1169 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1171 *pMemoryProperties
= physical_device
->memory_properties
;
1174 void radv_GetPhysicalDeviceMemoryProperties2(
1175 VkPhysicalDevice physicalDevice
,
1176 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1178 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1179 &pMemoryProperties
->memoryProperties
);
1182 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1184 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1185 const void *pHostPointer
,
1186 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1188 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1192 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1193 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1194 uint32_t memoryTypeBits
= 0;
1195 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1196 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1197 memoryTypeBits
= (1 << i
);
1201 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1205 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1209 static enum radeon_ctx_priority
1210 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1212 /* Default to MEDIUM when a specific global priority isn't requested */
1214 return RADEON_CTX_PRIORITY_MEDIUM
;
1216 switch(pObj
->globalPriority
) {
1217 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1218 return RADEON_CTX_PRIORITY_REALTIME
;
1219 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1220 return RADEON_CTX_PRIORITY_HIGH
;
1221 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1222 return RADEON_CTX_PRIORITY_MEDIUM
;
1223 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1224 return RADEON_CTX_PRIORITY_LOW
;
1226 unreachable("Illegal global priority value");
1227 return RADEON_CTX_PRIORITY_INVALID
;
1232 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1233 uint32_t queue_family_index
, int idx
,
1234 VkDeviceQueueCreateFlags flags
,
1235 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1237 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1238 queue
->device
= device
;
1239 queue
->queue_family_index
= queue_family_index
;
1240 queue
->queue_idx
= idx
;
1241 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1242 queue
->flags
= flags
;
1244 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1246 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1252 radv_queue_finish(struct radv_queue
*queue
)
1255 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1257 if (queue
->initial_full_flush_preamble_cs
)
1258 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1259 if (queue
->initial_preamble_cs
)
1260 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1261 if (queue
->continue_preamble_cs
)
1262 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1263 if (queue
->descriptor_bo
)
1264 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1265 if (queue
->scratch_bo
)
1266 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1267 if (queue
->esgs_ring_bo
)
1268 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1269 if (queue
->gsvs_ring_bo
)
1270 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1271 if (queue
->tess_rings_bo
)
1272 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1273 if (queue
->compute_scratch_bo
)
1274 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1278 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1280 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1281 bo_list
->list
.count
= bo_list
->capacity
= 0;
1282 bo_list
->list
.bos
= NULL
;
1286 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1288 free(bo_list
->list
.bos
);
1289 pthread_mutex_destroy(&bo_list
->mutex
);
1292 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1293 struct radeon_winsys_bo
*bo
)
1295 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1297 if (unlikely(!device
->use_global_bo_list
))
1300 pthread_mutex_lock(&bo_list
->mutex
);
1301 if (bo_list
->list
.count
== bo_list
->capacity
) {
1302 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1303 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1306 pthread_mutex_unlock(&bo_list
->mutex
);
1307 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1310 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1311 bo_list
->capacity
= capacity
;
1314 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1315 pthread_mutex_unlock(&bo_list
->mutex
);
1319 static void radv_bo_list_remove(struct radv_device
*device
,
1320 struct radeon_winsys_bo
*bo
)
1322 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1324 if (unlikely(!device
->use_global_bo_list
))
1327 pthread_mutex_lock(&bo_list
->mutex
);
1328 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1329 if (bo_list
->list
.bos
[i
] == bo
) {
1330 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1331 --bo_list
->list
.count
;
1335 pthread_mutex_unlock(&bo_list
->mutex
);
1339 radv_device_init_gs_info(struct radv_device
*device
)
1341 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1342 device
->physical_device
->rad_info
.family
);
1345 static int radv_get_device_extension_index(const char *name
)
1347 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1348 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1354 VkResult
radv_CreateDevice(
1355 VkPhysicalDevice physicalDevice
,
1356 const VkDeviceCreateInfo
* pCreateInfo
,
1357 const VkAllocationCallbacks
* pAllocator
,
1360 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1362 struct radv_device
*device
;
1364 bool keep_shader_info
= false;
1366 /* Check enabled features */
1367 if (pCreateInfo
->pEnabledFeatures
) {
1368 VkPhysicalDeviceFeatures supported_features
;
1369 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1370 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1371 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1372 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1373 for (uint32_t i
= 0; i
< num_features
; i
++) {
1374 if (enabled_feature
[i
] && !supported_feature
[i
])
1375 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1379 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1381 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1383 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1385 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1386 device
->instance
= physical_device
->instance
;
1387 device
->physical_device
= physical_device
;
1389 device
->ws
= physical_device
->ws
;
1391 device
->alloc
= *pAllocator
;
1393 device
->alloc
= physical_device
->instance
->alloc
;
1395 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1396 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1397 int index
= radv_get_device_extension_index(ext_name
);
1398 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1399 vk_free(&device
->alloc
, device
);
1400 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1403 device
->enabled_extensions
.extensions
[index
] = true;
1406 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1408 /* With update after bind we can't attach bo's to the command buffer
1409 * from the descriptor set anymore, so we have to use a global BO list.
1411 device
->use_global_bo_list
=
1412 device
->enabled_extensions
.EXT_descriptor_indexing
;
1414 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1415 list_inithead(&device
->shader_slabs
);
1417 radv_bo_list_init(&device
->bo_list
);
1419 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1420 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1421 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1422 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1423 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1425 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1427 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1428 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1429 if (!device
->queues
[qfi
]) {
1430 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1434 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1436 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1438 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1439 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1440 qfi
, q
, queue_create
->flags
,
1442 if (result
!= VK_SUCCESS
)
1447 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1448 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1450 /* Disabled and not implemented for now. */
1451 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1454 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1457 /* The maximum number of scratch waves. Scratch space isn't divided
1458 * evenly between CUs. The number is only a function of the number of CUs.
1459 * We can decrease the constant to decrease the scratch buffer size.
1461 * sctx->scratch_waves must be >= the maximum possible size of
1462 * 1 threadgroup, so that the hw doesn't hang from being unable
1465 * The recommended value is 4 per CU at most. Higher numbers don't
1466 * bring much benefit, but they still occupy chip resources (think
1467 * async compute). I've seen ~2% performance difference between 4 and 32.
1469 uint32_t max_threads_per_block
= 2048;
1470 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1471 max_threads_per_block
/ 64);
1473 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1475 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1476 /* If the KMD allows it (there is a KMD hw register for it),
1477 * allow launching waves out-of-order.
1479 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1482 radv_device_init_gs_info(device
);
1484 device
->tess_offchip_block_dw_size
=
1485 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1486 device
->has_distributed_tess
=
1487 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1488 device
->physical_device
->rad_info
.max_se
>= 2;
1490 if (getenv("RADV_TRACE_FILE")) {
1491 const char *filename
= getenv("RADV_TRACE_FILE");
1493 keep_shader_info
= true;
1495 if (!radv_init_trace(device
))
1498 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1499 radv_dump_enabled_options(device
, stderr
);
1502 device
->keep_shader_info
= keep_shader_info
;
1504 result
= radv_device_init_meta(device
);
1505 if (result
!= VK_SUCCESS
)
1508 radv_device_init_msaa(device
);
1510 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1511 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1513 case RADV_QUEUE_GENERAL
:
1514 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1515 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1516 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1518 case RADV_QUEUE_COMPUTE
:
1519 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1520 radeon_emit(device
->empty_cs
[family
], 0);
1523 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1526 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1527 cik_create_gfx_config(device
);
1529 VkPipelineCacheCreateInfo ci
;
1530 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1533 ci
.pInitialData
= NULL
;
1534 ci
.initialDataSize
= 0;
1536 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1538 if (result
!= VK_SUCCESS
)
1541 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1543 *pDevice
= radv_device_to_handle(device
);
1547 radv_device_finish_meta(device
);
1549 radv_bo_list_finish(&device
->bo_list
);
1551 if (device
->trace_bo
)
1552 device
->ws
->buffer_destroy(device
->trace_bo
);
1554 if (device
->gfx_init
)
1555 device
->ws
->buffer_destroy(device
->gfx_init
);
1557 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1558 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1559 radv_queue_finish(&device
->queues
[i
][q
]);
1560 if (device
->queue_count
[i
])
1561 vk_free(&device
->alloc
, device
->queues
[i
]);
1564 vk_free(&device
->alloc
, device
);
1568 void radv_DestroyDevice(
1570 const VkAllocationCallbacks
* pAllocator
)
1572 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1577 if (device
->trace_bo
)
1578 device
->ws
->buffer_destroy(device
->trace_bo
);
1580 if (device
->gfx_init
)
1581 device
->ws
->buffer_destroy(device
->gfx_init
);
1583 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1584 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1585 radv_queue_finish(&device
->queues
[i
][q
]);
1586 if (device
->queue_count
[i
])
1587 vk_free(&device
->alloc
, device
->queues
[i
]);
1588 if (device
->empty_cs
[i
])
1589 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1591 radv_device_finish_meta(device
);
1593 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1594 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1596 radv_destroy_shader_slabs(device
);
1598 radv_bo_list_finish(&device
->bo_list
);
1599 vk_free(&device
->alloc
, device
);
1602 VkResult
radv_EnumerateInstanceLayerProperties(
1603 uint32_t* pPropertyCount
,
1604 VkLayerProperties
* pProperties
)
1606 if (pProperties
== NULL
) {
1607 *pPropertyCount
= 0;
1611 /* None supported at this time */
1612 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1615 VkResult
radv_EnumerateDeviceLayerProperties(
1616 VkPhysicalDevice physicalDevice
,
1617 uint32_t* pPropertyCount
,
1618 VkLayerProperties
* pProperties
)
1620 if (pProperties
== NULL
) {
1621 *pPropertyCount
= 0;
1625 /* None supported at this time */
1626 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1629 void radv_GetDeviceQueue2(
1631 const VkDeviceQueueInfo2
* pQueueInfo
,
1634 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1635 struct radv_queue
*queue
;
1637 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1638 if (pQueueInfo
->flags
!= queue
->flags
) {
1639 /* From the Vulkan 1.1.70 spec:
1641 * "The queue returned by vkGetDeviceQueue2 must have the same
1642 * flags value from this structure as that used at device
1643 * creation time in a VkDeviceQueueCreateInfo instance. If no
1644 * matching flags were specified at device creation time then
1645 * pQueue will return VK_NULL_HANDLE."
1647 *pQueue
= VK_NULL_HANDLE
;
1651 *pQueue
= radv_queue_to_handle(queue
);
1654 void radv_GetDeviceQueue(
1656 uint32_t queueFamilyIndex
,
1657 uint32_t queueIndex
,
1660 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1661 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1662 .queueFamilyIndex
= queueFamilyIndex
,
1663 .queueIndex
= queueIndex
1666 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1670 fill_geom_tess_rings(struct radv_queue
*queue
,
1672 bool add_sample_positions
,
1673 uint32_t esgs_ring_size
,
1674 struct radeon_winsys_bo
*esgs_ring_bo
,
1675 uint32_t gsvs_ring_size
,
1676 struct radeon_winsys_bo
*gsvs_ring_bo
,
1677 uint32_t tess_factor_ring_size
,
1678 uint32_t tess_offchip_ring_offset
,
1679 uint32_t tess_offchip_ring_size
,
1680 struct radeon_winsys_bo
*tess_rings_bo
)
1682 uint64_t esgs_va
= 0, gsvs_va
= 0;
1683 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1684 uint32_t *desc
= &map
[4];
1687 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1689 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1690 if (tess_rings_bo
) {
1691 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1692 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1695 /* stride 0, num records - size, add tid, swizzle, elsize4,
1698 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1699 S_008F04_STRIDE(0) |
1700 S_008F04_SWIZZLE_ENABLE(true);
1701 desc
[2] = esgs_ring_size
;
1702 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1703 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1704 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1705 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1706 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1707 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1708 S_008F0C_ELEMENT_SIZE(1) |
1709 S_008F0C_INDEX_STRIDE(3) |
1710 S_008F0C_ADD_TID_ENABLE(true);
1713 /* GS entry for ES->GS ring */
1714 /* stride 0, num records - size, elsize0,
1717 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1718 S_008F04_STRIDE(0) |
1719 S_008F04_SWIZZLE_ENABLE(false);
1720 desc
[2] = esgs_ring_size
;
1721 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1722 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1723 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1724 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1725 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1726 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1727 S_008F0C_ELEMENT_SIZE(0) |
1728 S_008F0C_INDEX_STRIDE(0) |
1729 S_008F0C_ADD_TID_ENABLE(false);
1732 /* VS entry for GS->VS ring */
1733 /* stride 0, num records - size, elsize0,
1736 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1737 S_008F04_STRIDE(0) |
1738 S_008F04_SWIZZLE_ENABLE(false);
1739 desc
[2] = gsvs_ring_size
;
1740 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1741 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1742 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1743 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1744 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1745 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1746 S_008F0C_ELEMENT_SIZE(0) |
1747 S_008F0C_INDEX_STRIDE(0) |
1748 S_008F0C_ADD_TID_ENABLE(false);
1751 /* stride gsvs_itemsize, num records 64
1752 elsize 4, index stride 16 */
1753 /* shader will patch stride and desc[2] */
1755 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1756 S_008F04_STRIDE(0) |
1757 S_008F04_SWIZZLE_ENABLE(true);
1759 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1760 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1761 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1762 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1763 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1764 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1765 S_008F0C_ELEMENT_SIZE(1) |
1766 S_008F0C_INDEX_STRIDE(1) |
1767 S_008F0C_ADD_TID_ENABLE(true);
1771 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1772 S_008F04_STRIDE(0) |
1773 S_008F04_SWIZZLE_ENABLE(false);
1774 desc
[2] = tess_factor_ring_size
;
1775 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1776 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1777 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1778 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1779 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1780 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1781 S_008F0C_ELEMENT_SIZE(0) |
1782 S_008F0C_INDEX_STRIDE(0) |
1783 S_008F0C_ADD_TID_ENABLE(false);
1786 desc
[0] = tess_offchip_va
;
1787 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1788 S_008F04_STRIDE(0) |
1789 S_008F04_SWIZZLE_ENABLE(false);
1790 desc
[2] = tess_offchip_ring_size
;
1791 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1792 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1793 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1794 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1795 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1796 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1797 S_008F0C_ELEMENT_SIZE(0) |
1798 S_008F0C_INDEX_STRIDE(0) |
1799 S_008F0C_ADD_TID_ENABLE(false);
1802 /* add sample positions after all rings */
1803 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1805 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1807 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1809 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1811 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1815 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1817 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1818 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1819 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1820 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1821 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1822 device
->physical_device
->rad_info
.max_se
;
1823 unsigned offchip_granularity
;
1824 unsigned hs_offchip_param
;
1825 switch (device
->tess_offchip_block_dw_size
) {
1830 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1833 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1837 switch (device
->physical_device
->rad_info
.chip_class
) {
1839 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1845 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1849 *max_offchip_buffers_p
= max_offchip_buffers
;
1850 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1851 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1852 --max_offchip_buffers
;
1854 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1855 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1858 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1860 return hs_offchip_param
;
1864 radv_get_preamble_cs(struct radv_queue
*queue
,
1865 uint32_t scratch_size
,
1866 uint32_t compute_scratch_size
,
1867 uint32_t esgs_ring_size
,
1868 uint32_t gsvs_ring_size
,
1869 bool needs_tess_rings
,
1870 bool needs_sample_positions
,
1871 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1872 struct radeon_winsys_cs
**initial_preamble_cs
,
1873 struct radeon_winsys_cs
**continue_preamble_cs
)
1875 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1876 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1877 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1878 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1879 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1880 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1881 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1882 bool add_tess_rings
= false, add_sample_positions
= false;
1883 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1884 unsigned max_offchip_buffers
;
1885 unsigned hs_offchip_param
= 0;
1886 unsigned tess_offchip_ring_offset
;
1887 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1888 if (!queue
->has_tess_rings
) {
1889 if (needs_tess_rings
)
1890 add_tess_rings
= true;
1892 if (!queue
->has_sample_positions
) {
1893 if (needs_sample_positions
)
1894 add_sample_positions
= true;
1896 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1897 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1898 &max_offchip_buffers
);
1899 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1900 tess_offchip_ring_size
= max_offchip_buffers
*
1901 queue
->device
->tess_offchip_block_dw_size
* 4;
1903 if (scratch_size
<= queue
->scratch_size
&&
1904 compute_scratch_size
<= queue
->compute_scratch_size
&&
1905 esgs_ring_size
<= queue
->esgs_ring_size
&&
1906 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1907 !add_tess_rings
&& !add_sample_positions
&&
1908 queue
->initial_preamble_cs
) {
1909 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1910 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1911 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1912 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1913 *continue_preamble_cs
= NULL
;
1917 if (scratch_size
> queue
->scratch_size
) {
1918 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1926 scratch_bo
= queue
->scratch_bo
;
1928 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1929 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1930 compute_scratch_size
,
1934 if (!compute_scratch_bo
)
1938 compute_scratch_bo
= queue
->compute_scratch_bo
;
1940 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1941 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1949 esgs_ring_bo
= queue
->esgs_ring_bo
;
1950 esgs_ring_size
= queue
->esgs_ring_size
;
1953 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1954 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1962 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1963 gsvs_ring_size
= queue
->gsvs_ring_size
;
1966 if (add_tess_rings
) {
1967 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1968 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
1975 tess_rings_bo
= queue
->tess_rings_bo
;
1978 if (scratch_bo
!= queue
->scratch_bo
||
1979 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1980 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1981 tess_rings_bo
!= queue
->tess_rings_bo
||
1982 add_sample_positions
) {
1984 if (gsvs_ring_bo
|| esgs_ring_bo
||
1985 tess_rings_bo
|| add_sample_positions
) {
1986 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1987 if (add_sample_positions
)
1988 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1990 else if (scratch_bo
)
1991 size
= 8; /* 2 dword */
1993 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1997 RADEON_FLAG_CPU_ACCESS
|
1998 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
1999 RADEON_FLAG_READ_ONLY
);
2003 descriptor_bo
= queue
->descriptor_bo
;
2005 for(int i
= 0; i
< 3; ++i
) {
2006 struct radeon_winsys_cs
*cs
= NULL
;
2007 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2008 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2015 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2018 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
2021 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
2024 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
2027 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
2029 if (descriptor_bo
!= queue
->descriptor_bo
) {
2030 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2033 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2034 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2035 S_008F04_SWIZZLE_ENABLE(1);
2036 map
[0] = scratch_va
;
2040 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2041 add_sample_positions
)
2042 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2043 esgs_ring_size
, esgs_ring_bo
,
2044 gsvs_ring_size
, gsvs_ring_bo
,
2045 tess_factor_ring_size
,
2046 tess_offchip_ring_offset
,
2047 tess_offchip_ring_size
,
2050 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2053 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2054 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2055 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2056 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2057 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2060 if (esgs_ring_bo
|| gsvs_ring_bo
) {
2061 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2062 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2063 radeon_emit(cs
, esgs_ring_size
>> 8);
2064 radeon_emit(cs
, gsvs_ring_size
>> 8);
2066 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2067 radeon_emit(cs
, esgs_ring_size
>> 8);
2068 radeon_emit(cs
, gsvs_ring_size
>> 8);
2072 if (tess_rings_bo
) {
2073 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
2074 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2075 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2076 S_030938_SIZE(tess_factor_ring_size
/ 4));
2077 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2079 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2080 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2081 S_030944_BASE_HI(tf_va
>> 40));
2083 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
2085 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2086 S_008988_SIZE(tess_factor_ring_size
/ 4));
2087 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2089 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2094 if (descriptor_bo
) {
2095 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
2096 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2097 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2098 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2099 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2100 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2102 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2103 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2104 radeon_emit(cs
, va
);
2105 radeon_emit(cs
, va
>> 32);
2108 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2109 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2110 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2111 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2112 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2113 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2115 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2116 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2117 radeon_emit(cs
, va
);
2118 radeon_emit(cs
, va
>> 32);
2123 if (compute_scratch_bo
) {
2124 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2125 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2126 S_008F04_SWIZZLE_ENABLE(1);
2128 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2130 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2131 radeon_emit(cs
, scratch_va
);
2132 radeon_emit(cs
, rsrc1
);
2136 si_cs_emit_cache_flush(cs
,
2137 queue
->device
->physical_device
->rad_info
.chip_class
,
2139 queue
->queue_family_index
== RING_COMPUTE
&&
2140 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2141 (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
)) |
2142 RADV_CMD_FLAG_INV_ICACHE
|
2143 RADV_CMD_FLAG_INV_SMEM_L1
|
2144 RADV_CMD_FLAG_INV_VMEM_L1
|
2145 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2146 } else if (i
== 1) {
2147 si_cs_emit_cache_flush(cs
,
2148 queue
->device
->physical_device
->rad_info
.chip_class
,
2150 queue
->queue_family_index
== RING_COMPUTE
&&
2151 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2152 RADV_CMD_FLAG_INV_ICACHE
|
2153 RADV_CMD_FLAG_INV_SMEM_L1
|
2154 RADV_CMD_FLAG_INV_VMEM_L1
|
2155 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2158 if (!queue
->device
->ws
->cs_finalize(cs
))
2162 if (queue
->initial_full_flush_preamble_cs
)
2163 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2165 if (queue
->initial_preamble_cs
)
2166 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2168 if (queue
->continue_preamble_cs
)
2169 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2171 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2172 queue
->initial_preamble_cs
= dest_cs
[1];
2173 queue
->continue_preamble_cs
= dest_cs
[2];
2175 if (scratch_bo
!= queue
->scratch_bo
) {
2176 if (queue
->scratch_bo
)
2177 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2178 queue
->scratch_bo
= scratch_bo
;
2179 queue
->scratch_size
= scratch_size
;
2182 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2183 if (queue
->compute_scratch_bo
)
2184 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2185 queue
->compute_scratch_bo
= compute_scratch_bo
;
2186 queue
->compute_scratch_size
= compute_scratch_size
;
2189 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2190 if (queue
->esgs_ring_bo
)
2191 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2192 queue
->esgs_ring_bo
= esgs_ring_bo
;
2193 queue
->esgs_ring_size
= esgs_ring_size
;
2196 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2197 if (queue
->gsvs_ring_bo
)
2198 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2199 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2200 queue
->gsvs_ring_size
= gsvs_ring_size
;
2203 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2204 queue
->tess_rings_bo
= tess_rings_bo
;
2205 queue
->has_tess_rings
= true;
2208 if (descriptor_bo
!= queue
->descriptor_bo
) {
2209 if (queue
->descriptor_bo
)
2210 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2212 queue
->descriptor_bo
= descriptor_bo
;
2215 if (add_sample_positions
)
2216 queue
->has_sample_positions
= true;
2218 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2219 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2220 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2221 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2222 *continue_preamble_cs
= NULL
;
2225 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2227 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2228 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2229 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2230 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2231 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2232 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2233 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2234 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2235 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2236 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2237 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2238 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2239 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2240 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2243 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2245 const VkSemaphore
*sems
,
2249 int syncobj_idx
= 0, sem_idx
= 0;
2251 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2254 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2255 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2257 if (sem
->temp_syncobj
|| sem
->syncobj
)
2258 counts
->syncobj_count
++;
2260 counts
->sem_count
++;
2263 if (_fence
!= VK_NULL_HANDLE
) {
2264 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2265 if (fence
->temp_syncobj
|| fence
->syncobj
)
2266 counts
->syncobj_count
++;
2269 if (counts
->syncobj_count
) {
2270 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2271 if (!counts
->syncobj
)
2272 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2275 if (counts
->sem_count
) {
2276 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2278 free(counts
->syncobj
);
2279 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2283 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2284 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2286 if (sem
->temp_syncobj
) {
2287 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2289 else if (sem
->syncobj
)
2290 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2293 counts
->sem
[sem_idx
++] = sem
->sem
;
2297 if (_fence
!= VK_NULL_HANDLE
) {
2298 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2299 if (fence
->temp_syncobj
)
2300 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2301 else if (fence
->syncobj
)
2302 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2308 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2310 free(sem_info
->wait
.syncobj
);
2311 free(sem_info
->wait
.sem
);
2312 free(sem_info
->signal
.syncobj
);
2313 free(sem_info
->signal
.sem
);
2317 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2319 const VkSemaphore
*sems
)
2321 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2322 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2324 if (sem
->temp_syncobj
) {
2325 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2326 sem
->temp_syncobj
= 0;
2331 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2333 const VkSemaphore
*wait_sems
,
2334 int num_signal_sems
,
2335 const VkSemaphore
*signal_sems
,
2339 memset(sem_info
, 0, sizeof(*sem_info
));
2341 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2344 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2346 radv_free_sem_info(sem_info
);
2348 /* caller can override these */
2349 sem_info
->cs_emit_wait
= true;
2350 sem_info
->cs_emit_signal
= true;
2354 /* Signals fence as soon as all the work currently put on queue is done. */
2355 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2356 struct radv_fence
*fence
)
2360 struct radv_winsys_sem_info sem_info
;
2362 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2363 radv_fence_to_handle(fence
));
2364 if (result
!= VK_SUCCESS
)
2367 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2368 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2369 1, NULL
, NULL
, &sem_info
, NULL
,
2370 false, fence
->fence
);
2371 radv_free_sem_info(&sem_info
);
2373 /* TODO: find a better error */
2375 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2380 VkResult
radv_QueueSubmit(
2382 uint32_t submitCount
,
2383 const VkSubmitInfo
* pSubmits
,
2386 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2387 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2388 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2389 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2391 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2392 uint32_t scratch_size
= 0;
2393 uint32_t compute_scratch_size
= 0;
2394 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2395 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2397 bool fence_emitted
= false;
2398 bool tess_rings_needed
= false;
2399 bool sample_positions_needed
= false;
2401 /* Do this first so failing to allocate scratch buffers can't result in
2402 * partially executed submissions. */
2403 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2404 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2405 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2406 pSubmits
[i
].pCommandBuffers
[j
]);
2408 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2409 compute_scratch_size
= MAX2(compute_scratch_size
,
2410 cmd_buffer
->compute_scratch_size_needed
);
2411 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2412 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2413 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2414 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2418 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2419 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2420 sample_positions_needed
, &initial_flush_preamble_cs
,
2421 &initial_preamble_cs
, &continue_preamble_cs
);
2422 if (result
!= VK_SUCCESS
)
2425 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2426 struct radeon_winsys_cs
**cs_array
;
2427 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2428 bool can_patch
= true;
2430 struct radv_winsys_sem_info sem_info
;
2432 result
= radv_alloc_sem_info(&sem_info
,
2433 pSubmits
[i
].waitSemaphoreCount
,
2434 pSubmits
[i
].pWaitSemaphores
,
2435 pSubmits
[i
].signalSemaphoreCount
,
2436 pSubmits
[i
].pSignalSemaphores
,
2438 if (result
!= VK_SUCCESS
)
2441 if (!pSubmits
[i
].commandBufferCount
) {
2442 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2443 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2444 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2449 radv_loge("failed to submit CS %d\n", i
);
2452 fence_emitted
= true;
2454 radv_free_sem_info(&sem_info
);
2458 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2459 (pSubmits
[i
].commandBufferCount
));
2461 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2462 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2463 pSubmits
[i
].pCommandBuffers
[j
]);
2464 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2466 cs_array
[j
] = cmd_buffer
->cs
;
2467 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2470 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2473 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2474 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2475 advance
= MIN2(max_cs_submission
,
2476 pSubmits
[i
].commandBufferCount
- j
);
2478 if (queue
->device
->trace_bo
)
2479 *queue
->device
->trace_id_ptr
= 0;
2481 sem_info
.cs_emit_wait
= j
== 0;
2482 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2484 if (unlikely(queue
->device
->use_global_bo_list
))
2485 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2487 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2488 advance
, initial_preamble
, continue_preamble_cs
,
2489 &sem_info
, &queue
->device
->bo_list
.list
,
2490 can_patch
, base_fence
);
2492 if (unlikely(queue
->device
->use_global_bo_list
))
2493 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2496 radv_loge("failed to submit CS %d\n", i
);
2499 fence_emitted
= true;
2500 if (queue
->device
->trace_bo
) {
2501 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2505 radv_free_temp_syncobjs(queue
->device
,
2506 pSubmits
[i
].waitSemaphoreCount
,
2507 pSubmits
[i
].pWaitSemaphores
);
2508 radv_free_sem_info(&sem_info
);
2513 if (!fence_emitted
) {
2514 radv_signal_fence(queue
, fence
);
2516 fence
->submitted
= true;
2522 VkResult
radv_QueueWaitIdle(
2525 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2527 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2528 radv_queue_family_to_ring(queue
->queue_family_index
),
2533 VkResult
radv_DeviceWaitIdle(
2536 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2538 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2539 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2540 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2546 VkResult
radv_EnumerateInstanceExtensionProperties(
2547 const char* pLayerName
,
2548 uint32_t* pPropertyCount
,
2549 VkExtensionProperties
* pProperties
)
2551 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2553 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2554 if (radv_supported_instance_extensions
.extensions
[i
]) {
2555 vk_outarray_append(&out
, prop
) {
2556 *prop
= radv_instance_extensions
[i
];
2561 return vk_outarray_status(&out
);
2564 VkResult
radv_EnumerateDeviceExtensionProperties(
2565 VkPhysicalDevice physicalDevice
,
2566 const char* pLayerName
,
2567 uint32_t* pPropertyCount
,
2568 VkExtensionProperties
* pProperties
)
2570 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2571 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2573 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2574 if (device
->supported_extensions
.extensions
[i
]) {
2575 vk_outarray_append(&out
, prop
) {
2576 *prop
= radv_device_extensions
[i
];
2581 return vk_outarray_status(&out
);
2584 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2585 VkInstance _instance
,
2588 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2590 return radv_lookup_entrypoint_checked(pName
,
2591 instance
? instance
->apiVersion
: 0,
2592 instance
? &instance
->enabled_extensions
: NULL
,
2596 /* The loader wants us to expose a second GetInstanceProcAddr function
2597 * to work around certain LD_PRELOAD issues seen in apps.
2600 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2601 VkInstance instance
,
2605 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2606 VkInstance instance
,
2609 return radv_GetInstanceProcAddr(instance
, pName
);
2612 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2616 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2618 return radv_lookup_entrypoint_checked(pName
,
2619 device
->instance
->apiVersion
,
2620 &device
->instance
->enabled_extensions
,
2621 &device
->enabled_extensions
);
2624 bool radv_get_memory_fd(struct radv_device
*device
,
2625 struct radv_device_memory
*memory
,
2628 struct radeon_bo_metadata metadata
;
2630 if (memory
->image
) {
2631 radv_init_metadata(device
, memory
->image
, &metadata
);
2632 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2635 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2639 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2640 const VkMemoryAllocateInfo
* pAllocateInfo
,
2641 const VkAllocationCallbacks
* pAllocator
,
2642 VkDeviceMemory
* pMem
)
2644 struct radv_device_memory
*mem
;
2646 enum radeon_bo_domain domain
;
2648 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2650 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2652 if (pAllocateInfo
->allocationSize
== 0) {
2653 /* Apparently, this is allowed */
2654 *pMem
= VK_NULL_HANDLE
;
2658 const VkImportMemoryFdInfoKHR
*import_info
=
2659 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2660 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2661 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2662 const VkExportMemoryAllocateInfoKHR
*export_info
=
2663 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2664 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2665 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2667 const struct wsi_memory_allocate_info
*wsi_info
=
2668 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2670 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2671 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2673 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2675 if (wsi_info
&& wsi_info
->implicit_sync
)
2676 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2678 if (dedicate_info
) {
2679 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2680 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2686 mem
->user_ptr
= NULL
;
2689 assert(import_info
->handleType
==
2690 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2691 import_info
->handleType
==
2692 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2693 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2696 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2699 close(import_info
->fd
);
2701 } else if (host_ptr_info
) {
2702 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2703 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2704 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2705 pAllocateInfo
->allocationSize
);
2707 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2710 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2713 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2714 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2715 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2716 domain
= RADEON_DOMAIN_GTT
;
2718 domain
= RADEON_DOMAIN_VRAM
;
2720 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2721 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2723 flags
|= RADEON_FLAG_CPU_ACCESS
;
2725 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2726 flags
|= RADEON_FLAG_GTT_WC
;
2728 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2729 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2731 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2735 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2738 mem
->type_index
= mem_type_index
;
2741 result
= radv_bo_list_add(device
, mem
->bo
);
2742 if (result
!= VK_SUCCESS
)
2745 *pMem
= radv_device_memory_to_handle(mem
);
2750 device
->ws
->buffer_destroy(mem
->bo
);
2752 vk_free2(&device
->alloc
, pAllocator
, mem
);
2757 VkResult
radv_AllocateMemory(
2759 const VkMemoryAllocateInfo
* pAllocateInfo
,
2760 const VkAllocationCallbacks
* pAllocator
,
2761 VkDeviceMemory
* pMem
)
2763 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2764 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2767 void radv_FreeMemory(
2769 VkDeviceMemory _mem
,
2770 const VkAllocationCallbacks
* pAllocator
)
2772 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2773 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2778 radv_bo_list_remove(device
, mem
->bo
);
2779 device
->ws
->buffer_destroy(mem
->bo
);
2782 vk_free2(&device
->alloc
, pAllocator
, mem
);
2785 VkResult
radv_MapMemory(
2787 VkDeviceMemory _memory
,
2788 VkDeviceSize offset
,
2790 VkMemoryMapFlags flags
,
2793 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2794 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2802 *ppData
= mem
->user_ptr
;
2804 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2811 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2814 void radv_UnmapMemory(
2816 VkDeviceMemory _memory
)
2818 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2819 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2824 if (mem
->user_ptr
== NULL
)
2825 device
->ws
->buffer_unmap(mem
->bo
);
2828 VkResult
radv_FlushMappedMemoryRanges(
2830 uint32_t memoryRangeCount
,
2831 const VkMappedMemoryRange
* pMemoryRanges
)
2836 VkResult
radv_InvalidateMappedMemoryRanges(
2838 uint32_t memoryRangeCount
,
2839 const VkMappedMemoryRange
* pMemoryRanges
)
2844 void radv_GetBufferMemoryRequirements(
2847 VkMemoryRequirements
* pMemoryRequirements
)
2849 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2850 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2852 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2854 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2855 pMemoryRequirements
->alignment
= 4096;
2857 pMemoryRequirements
->alignment
= 16;
2859 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2862 void radv_GetBufferMemoryRequirements2(
2864 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2865 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2867 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2868 &pMemoryRequirements
->memoryRequirements
);
2869 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2870 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2871 switch (ext
->sType
) {
2872 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2873 VkMemoryDedicatedRequirementsKHR
*req
=
2874 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2875 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2876 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2885 void radv_GetImageMemoryRequirements(
2888 VkMemoryRequirements
* pMemoryRequirements
)
2890 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2891 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2893 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2895 pMemoryRequirements
->size
= image
->size
;
2896 pMemoryRequirements
->alignment
= image
->alignment
;
2899 void radv_GetImageMemoryRequirements2(
2901 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2902 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2904 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2905 &pMemoryRequirements
->memoryRequirements
);
2907 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2909 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2910 switch (ext
->sType
) {
2911 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2912 VkMemoryDedicatedRequirementsKHR
*req
=
2913 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2914 req
->requiresDedicatedAllocation
= image
->shareable
;
2915 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2924 void radv_GetImageSparseMemoryRequirements(
2927 uint32_t* pSparseMemoryRequirementCount
,
2928 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2933 void radv_GetImageSparseMemoryRequirements2(
2935 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2936 uint32_t* pSparseMemoryRequirementCount
,
2937 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2942 void radv_GetDeviceMemoryCommitment(
2944 VkDeviceMemory memory
,
2945 VkDeviceSize
* pCommittedMemoryInBytes
)
2947 *pCommittedMemoryInBytes
= 0;
2950 VkResult
radv_BindBufferMemory2(VkDevice device
,
2951 uint32_t bindInfoCount
,
2952 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2954 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2955 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2956 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2959 buffer
->bo
= mem
->bo
;
2960 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2968 VkResult
radv_BindBufferMemory(
2971 VkDeviceMemory memory
,
2972 VkDeviceSize memoryOffset
)
2974 const VkBindBufferMemoryInfoKHR info
= {
2975 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2978 .memoryOffset
= memoryOffset
2981 return radv_BindBufferMemory2(device
, 1, &info
);
2984 VkResult
radv_BindImageMemory2(VkDevice device
,
2985 uint32_t bindInfoCount
,
2986 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2988 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2989 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2990 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2993 image
->bo
= mem
->bo
;
2994 image
->offset
= pBindInfos
[i
].memoryOffset
;
3004 VkResult
radv_BindImageMemory(
3007 VkDeviceMemory memory
,
3008 VkDeviceSize memoryOffset
)
3010 const VkBindImageMemoryInfoKHR info
= {
3011 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3014 .memoryOffset
= memoryOffset
3017 return radv_BindImageMemory2(device
, 1, &info
);
3022 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3023 const VkSparseBufferMemoryBindInfo
*bind
)
3025 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3027 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3028 struct radv_device_memory
*mem
= NULL
;
3030 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3031 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3033 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3034 bind
->pBinds
[i
].resourceOffset
,
3035 bind
->pBinds
[i
].size
,
3036 mem
? mem
->bo
: NULL
,
3037 bind
->pBinds
[i
].memoryOffset
);
3042 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3043 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3045 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3047 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3048 struct radv_device_memory
*mem
= NULL
;
3050 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3051 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3053 device
->ws
->buffer_virtual_bind(image
->bo
,
3054 bind
->pBinds
[i
].resourceOffset
,
3055 bind
->pBinds
[i
].size
,
3056 mem
? mem
->bo
: NULL
,
3057 bind
->pBinds
[i
].memoryOffset
);
3061 VkResult
radv_QueueBindSparse(
3063 uint32_t bindInfoCount
,
3064 const VkBindSparseInfo
* pBindInfo
,
3067 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3068 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3069 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3070 bool fence_emitted
= false;
3072 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3073 struct radv_winsys_sem_info sem_info
;
3074 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3075 radv_sparse_buffer_bind_memory(queue
->device
,
3076 pBindInfo
[i
].pBufferBinds
+ j
);
3079 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3080 radv_sparse_image_opaque_bind_memory(queue
->device
,
3081 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3085 result
= radv_alloc_sem_info(&sem_info
,
3086 pBindInfo
[i
].waitSemaphoreCount
,
3087 pBindInfo
[i
].pWaitSemaphores
,
3088 pBindInfo
[i
].signalSemaphoreCount
,
3089 pBindInfo
[i
].pSignalSemaphores
,
3091 if (result
!= VK_SUCCESS
)
3094 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3095 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3096 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3100 fence_emitted
= true;
3102 fence
->submitted
= true;
3105 radv_free_sem_info(&sem_info
);
3110 if (!fence_emitted
) {
3111 radv_signal_fence(queue
, fence
);
3113 fence
->submitted
= true;
3119 VkResult
radv_CreateFence(
3121 const VkFenceCreateInfo
* pCreateInfo
,
3122 const VkAllocationCallbacks
* pAllocator
,
3125 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3126 const VkExportFenceCreateInfoKHR
*export
=
3127 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3128 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3129 export
? export
->handleTypes
: 0;
3131 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3133 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3136 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3138 fence
->submitted
= false;
3139 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3140 fence
->temp_syncobj
= 0;
3141 if (device
->always_use_syncobj
|| handleTypes
) {
3142 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3144 vk_free2(&device
->alloc
, pAllocator
, fence
);
3145 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3147 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3148 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3150 fence
->fence
= NULL
;
3152 fence
->fence
= device
->ws
->create_fence();
3153 if (!fence
->fence
) {
3154 vk_free2(&device
->alloc
, pAllocator
, fence
);
3155 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3160 *pFence
= radv_fence_to_handle(fence
);
3165 void radv_DestroyFence(
3168 const VkAllocationCallbacks
* pAllocator
)
3170 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3171 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3176 if (fence
->temp_syncobj
)
3177 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3179 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3181 device
->ws
->destroy_fence(fence
->fence
);
3182 vk_free2(&device
->alloc
, pAllocator
, fence
);
3186 static uint64_t radv_get_current_time()
3189 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3190 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3193 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3195 uint64_t current_time
= radv_get_current_time();
3197 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3199 return current_time
+ timeout
;
3203 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3205 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3206 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3207 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3213 VkResult
radv_WaitForFences(
3215 uint32_t fenceCount
,
3216 const VkFence
* pFences
,
3220 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3221 timeout
= radv_get_absolute_timeout(timeout
);
3223 if (device
->always_use_syncobj
) {
3224 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3226 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3228 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3229 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3230 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3233 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3236 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3239 if (!waitAll
&& fenceCount
> 1) {
3240 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3241 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3242 uint32_t wait_count
= 0;
3243 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3245 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3247 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3248 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3250 if (fence
->signalled
) {
3255 fences
[wait_count
++] = fence
->fence
;
3258 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3259 waitAll
, timeout
- radv_get_current_time());
3262 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3265 while(radv_get_current_time() <= timeout
) {
3266 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3267 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3274 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3275 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3276 bool expired
= false;
3278 if (fence
->temp_syncobj
) {
3279 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3284 if (fence
->syncobj
) {
3285 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3290 if (fence
->signalled
)
3293 if (!fence
->submitted
) {
3294 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3297 if (!fence
->submitted
)
3300 /* Recheck as it may have been set by submitting operations. */
3301 if (fence
->signalled
)
3305 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3309 fence
->signalled
= true;
3315 VkResult
radv_ResetFences(VkDevice _device
,
3316 uint32_t fenceCount
,
3317 const VkFence
*pFences
)
3319 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3321 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3322 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3323 fence
->submitted
= fence
->signalled
= false;
3325 /* Per spec, we first restore the permanent payload, and then reset, so
3326 * having a temp syncobj should not skip resetting the permanent syncobj. */
3327 if (fence
->temp_syncobj
) {
3328 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3329 fence
->temp_syncobj
= 0;
3332 if (fence
->syncobj
) {
3333 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3340 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3342 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3343 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3345 if (fence
->temp_syncobj
) {
3346 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3347 return success
? VK_SUCCESS
: VK_NOT_READY
;
3350 if (fence
->syncobj
) {
3351 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3352 return success
? VK_SUCCESS
: VK_NOT_READY
;
3355 if (fence
->signalled
)
3357 if (!fence
->submitted
)
3358 return VK_NOT_READY
;
3359 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3360 return VK_NOT_READY
;
3366 // Queue semaphore functions
3368 VkResult
radv_CreateSemaphore(
3370 const VkSemaphoreCreateInfo
* pCreateInfo
,
3371 const VkAllocationCallbacks
* pAllocator
,
3372 VkSemaphore
* pSemaphore
)
3374 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3375 const VkExportSemaphoreCreateInfoKHR
*export
=
3376 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3377 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3378 export
? export
->handleTypes
: 0;
3380 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3382 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3384 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3386 sem
->temp_syncobj
= 0;
3387 /* create a syncobject if we are going to export this semaphore */
3388 if (device
->always_use_syncobj
|| handleTypes
) {
3389 assert (device
->physical_device
->rad_info
.has_syncobj
);
3390 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3392 vk_free2(&device
->alloc
, pAllocator
, sem
);
3393 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3397 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3399 vk_free2(&device
->alloc
, pAllocator
, sem
);
3400 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3405 *pSemaphore
= radv_semaphore_to_handle(sem
);
3409 void radv_DestroySemaphore(
3411 VkSemaphore _semaphore
,
3412 const VkAllocationCallbacks
* pAllocator
)
3414 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3415 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3420 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3422 device
->ws
->destroy_sem(sem
->sem
);
3423 vk_free2(&device
->alloc
, pAllocator
, sem
);
3426 VkResult
radv_CreateEvent(
3428 const VkEventCreateInfo
* pCreateInfo
,
3429 const VkAllocationCallbacks
* pAllocator
,
3432 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3433 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3435 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3438 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3440 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3442 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3444 vk_free2(&device
->alloc
, pAllocator
, event
);
3445 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3448 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3450 *pEvent
= radv_event_to_handle(event
);
3455 void radv_DestroyEvent(
3458 const VkAllocationCallbacks
* pAllocator
)
3460 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3461 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3465 device
->ws
->buffer_destroy(event
->bo
);
3466 vk_free2(&device
->alloc
, pAllocator
, event
);
3469 VkResult
radv_GetEventStatus(
3473 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3475 if (*event
->map
== 1)
3476 return VK_EVENT_SET
;
3477 return VK_EVENT_RESET
;
3480 VkResult
radv_SetEvent(
3484 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3490 VkResult
radv_ResetEvent(
3494 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3500 VkResult
radv_CreateBuffer(
3502 const VkBufferCreateInfo
* pCreateInfo
,
3503 const VkAllocationCallbacks
* pAllocator
,
3506 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3507 struct radv_buffer
*buffer
;
3509 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3511 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3512 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3514 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3516 buffer
->size
= pCreateInfo
->size
;
3517 buffer
->usage
= pCreateInfo
->usage
;
3520 buffer
->flags
= pCreateInfo
->flags
;
3522 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3523 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3525 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3526 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3527 align64(buffer
->size
, 4096),
3528 4096, 0, RADEON_FLAG_VIRTUAL
);
3530 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3531 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3535 *pBuffer
= radv_buffer_to_handle(buffer
);
3540 void radv_DestroyBuffer(
3543 const VkAllocationCallbacks
* pAllocator
)
3545 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3546 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3551 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3552 device
->ws
->buffer_destroy(buffer
->bo
);
3554 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3557 static inline unsigned
3558 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3561 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3563 return image
->surface
.u
.legacy
.tiling_index
[level
];
3566 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3568 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3572 radv_init_dcc_control_reg(struct radv_device
*device
,
3573 struct radv_image_view
*iview
)
3575 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3576 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3577 unsigned max_compressed_block_size
;
3578 unsigned independent_64b_blocks
;
3580 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3583 if (iview
->image
->info
.samples
> 1) {
3584 if (iview
->image
->surface
.bpe
== 1)
3585 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3586 else if (iview
->image
->surface
.bpe
== 2)
3587 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3590 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3591 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3592 * dGPU and 64 for APU because all of our APUs to date use
3593 * DIMMs which have a request granularity size of 64B while all
3594 * other chips have a 32B request size.
3596 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3599 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3600 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3601 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3602 /* If this DCC image is potentially going to be used in texture
3603 * fetches, we need some special settings.
3605 independent_64b_blocks
= 1;
3606 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3608 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3609 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3610 * big as possible for better compression state.
3612 independent_64b_blocks
= 0;
3613 max_compressed_block_size
= max_uncompressed_block_size
;
3616 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3617 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3618 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3619 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3623 radv_initialise_color_surface(struct radv_device
*device
,
3624 struct radv_color_buffer_info
*cb
,
3625 struct radv_image_view
*iview
)
3627 const struct vk_format_description
*desc
;
3628 unsigned ntype
, format
, swap
, endian
;
3629 unsigned blend_clamp
= 0, blend_bypass
= 0;
3631 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3633 desc
= vk_format_description(iview
->vk_format
);
3635 memset(cb
, 0, sizeof(*cb
));
3637 /* Intensity is implemented as Red, so treat it that way. */
3638 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3640 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3642 cb
->cb_color_base
= va
>> 8;
3644 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3645 struct gfx9_surf_meta_flags meta
;
3646 if (iview
->image
->dcc_offset
)
3647 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3649 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3651 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3652 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3653 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3654 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3656 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3657 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3659 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3660 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3662 cb
->cb_color_base
+= level_info
->offset
>> 8;
3663 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3664 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3666 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3667 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3668 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3670 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3671 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3672 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3674 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3676 if (radv_image_has_fmask(iview
->image
)) {
3677 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3678 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3679 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3680 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3682 /* This must be set for fast clear to work without FMASK. */
3683 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3684 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3685 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3686 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3690 /* CMASK variables */
3691 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3692 va
+= iview
->image
->cmask
.offset
;
3693 cb
->cb_color_cmask
= va
>> 8;
3695 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3696 va
+= iview
->image
->dcc_offset
;
3697 cb
->cb_dcc_base
= va
>> 8;
3698 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3700 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3701 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3702 S_028C6C_SLICE_MAX(max_slice
);
3704 if (iview
->image
->info
.samples
> 1) {
3705 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3707 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3708 S_028C74_NUM_FRAGMENTS(log_samples
);
3711 if (radv_image_has_fmask(iview
->image
)) {
3712 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3713 cb
->cb_color_fmask
= va
>> 8;
3714 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3716 cb
->cb_color_fmask
= cb
->cb_color_base
;
3719 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3721 vk_format_get_first_non_void_channel(iview
->vk_format
));
3722 format
= radv_translate_colorformat(iview
->vk_format
);
3723 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3724 radv_finishme("Illegal color\n");
3725 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3726 endian
= radv_colorformat_endian_swap(format
);
3728 /* blend clamp should be set for all NORM/SRGB types */
3729 if (ntype
== V_028C70_NUMBER_UNORM
||
3730 ntype
== V_028C70_NUMBER_SNORM
||
3731 ntype
== V_028C70_NUMBER_SRGB
)
3734 /* set blend bypass according to docs if SINT/UINT or
3735 8/24 COLOR variants */
3736 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3737 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3738 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3743 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3744 (format
== V_028C70_COLOR_8
||
3745 format
== V_028C70_COLOR_8_8
||
3746 format
== V_028C70_COLOR_8_8_8_8
))
3747 ->color_is_int8
= true;
3749 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3750 S_028C70_COMP_SWAP(swap
) |
3751 S_028C70_BLEND_CLAMP(blend_clamp
) |
3752 S_028C70_BLEND_BYPASS(blend_bypass
) |
3753 S_028C70_SIMPLE_FLOAT(1) |
3754 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3755 ntype
!= V_028C70_NUMBER_SNORM
&&
3756 ntype
!= V_028C70_NUMBER_SRGB
&&
3757 format
!= V_028C70_COLOR_8_24
&&
3758 format
!= V_028C70_COLOR_24_8
) |
3759 S_028C70_NUMBER_TYPE(ntype
) |
3760 S_028C70_ENDIAN(endian
);
3761 if (radv_image_has_fmask(iview
->image
)) {
3762 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3763 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3764 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3765 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3769 if (radv_image_has_cmask(iview
->image
) &&
3770 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3771 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3773 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3774 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3776 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3778 /* This must be set for fast clear to work without FMASK. */
3779 if (!radv_image_has_fmask(iview
->image
) &&
3780 device
->physical_device
->rad_info
.chip_class
== SI
) {
3781 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3782 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3785 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3786 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3787 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3789 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3790 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3791 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3792 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3793 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3794 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3799 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3800 struct radv_image_view
*iview
)
3802 unsigned max_zplanes
= 0;
3804 assert(radv_image_is_tc_compat_htile(iview
->image
));
3806 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3807 /* Default value for 32-bit depth surfaces. */
3810 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3811 iview
->image
->info
.samples
> 1)
3814 max_zplanes
= max_zplanes
+ 1;
3816 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3817 /* Do not enable Z plane compression for 16-bit depth
3818 * surfaces because isn't supported on GFX8. Only
3819 * 32-bit depth surfaces are supported by the hardware.
3820 * This allows to maintain shader compatibility and to
3821 * reduce the number of depth decompressions.
3825 if (iview
->image
->info
.samples
<= 1)
3827 else if (iview
->image
->info
.samples
<= 4)
3838 radv_initialise_ds_surface(struct radv_device
*device
,
3839 struct radv_ds_buffer_info
*ds
,
3840 struct radv_image_view
*iview
)
3842 unsigned level
= iview
->base_mip
;
3843 unsigned format
, stencil_format
;
3844 uint64_t va
, s_offs
, z_offs
;
3845 bool stencil_only
= false;
3846 memset(ds
, 0, sizeof(*ds
));
3847 switch (iview
->image
->vk_format
) {
3848 case VK_FORMAT_D24_UNORM_S8_UINT
:
3849 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3850 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3851 ds
->offset_scale
= 2.0f
;
3853 case VK_FORMAT_D16_UNORM
:
3854 case VK_FORMAT_D16_UNORM_S8_UINT
:
3855 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3856 ds
->offset_scale
= 4.0f
;
3858 case VK_FORMAT_D32_SFLOAT
:
3859 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3860 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3861 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3862 ds
->offset_scale
= 1.0f
;
3864 case VK_FORMAT_S8_UINT
:
3865 stencil_only
= true;
3871 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3872 stencil_format
= iview
->image
->surface
.has_stencil
?
3873 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3875 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3876 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3877 S_028008_SLICE_MAX(max_slice
);
3879 ds
->db_htile_data_base
= 0;
3880 ds
->db_htile_surface
= 0;
3882 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3883 s_offs
= z_offs
= va
;
3885 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3886 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3887 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3889 ds
->db_z_info
= S_028038_FORMAT(format
) |
3890 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3891 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3892 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3893 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3894 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3896 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3897 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3898 ds
->db_depth_view
|= S_028008_MIPID(level
);
3900 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3901 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3903 if (radv_htile_enabled(iview
->image
, level
)) {
3904 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3906 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3907 unsigned max_zplanes
=
3908 radv_calc_decompress_on_z_planes(device
, iview
);
3910 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3911 S_028038_ITERATE_FLUSH(1);
3912 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3915 if (!iview
->image
->surface
.has_stencil
)
3916 /* Use all of the htile_buffer for depth if there's no stencil. */
3917 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3918 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3919 iview
->image
->htile_offset
;
3920 ds
->db_htile_data_base
= va
>> 8;
3921 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3922 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3923 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3926 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3929 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3931 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3932 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3934 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3935 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3936 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3938 if (iview
->image
->info
.samples
> 1)
3939 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3941 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3942 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3943 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3944 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3945 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3946 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3947 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3948 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3951 tile_mode
= stencil_tile_mode
;
3953 ds
->db_depth_info
|=
3954 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3955 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3956 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3957 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3958 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3959 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3960 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3961 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3963 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3964 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3965 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3966 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3968 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3971 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3972 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3973 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3975 if (radv_htile_enabled(iview
->image
, level
)) {
3976 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3978 if (!iview
->image
->surface
.has_stencil
&&
3979 !radv_image_is_tc_compat_htile(iview
->image
))
3980 /* Use all of the htile_buffer for depth if there's no stencil. */
3981 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3983 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3984 iview
->image
->htile_offset
;
3985 ds
->db_htile_data_base
= va
>> 8;
3986 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3988 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3989 unsigned max_zplanes
=
3990 radv_calc_decompress_on_z_planes(device
, iview
);
3992 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3993 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
3998 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3999 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4002 VkResult
radv_CreateFramebuffer(
4004 const VkFramebufferCreateInfo
* pCreateInfo
,
4005 const VkAllocationCallbacks
* pAllocator
,
4006 VkFramebuffer
* pFramebuffer
)
4008 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4009 struct radv_framebuffer
*framebuffer
;
4011 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4013 size_t size
= sizeof(*framebuffer
) +
4014 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4015 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4016 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4017 if (framebuffer
== NULL
)
4018 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4020 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4021 framebuffer
->width
= pCreateInfo
->width
;
4022 framebuffer
->height
= pCreateInfo
->height
;
4023 framebuffer
->layers
= pCreateInfo
->layers
;
4024 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4025 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4026 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4027 framebuffer
->attachments
[i
].attachment
= iview
;
4028 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4029 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4030 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4031 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4033 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4034 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4035 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4038 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4042 void radv_DestroyFramebuffer(
4045 const VkAllocationCallbacks
* pAllocator
)
4047 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4048 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4052 vk_free2(&device
->alloc
, pAllocator
, fb
);
4055 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4057 switch (address_mode
) {
4058 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4059 return V_008F30_SQ_TEX_WRAP
;
4060 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4061 return V_008F30_SQ_TEX_MIRROR
;
4062 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4063 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4064 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4065 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4066 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4067 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4069 unreachable("illegal tex wrap mode");
4075 radv_tex_compare(VkCompareOp op
)
4078 case VK_COMPARE_OP_NEVER
:
4079 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4080 case VK_COMPARE_OP_LESS
:
4081 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4082 case VK_COMPARE_OP_EQUAL
:
4083 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4084 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4085 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4086 case VK_COMPARE_OP_GREATER
:
4087 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4088 case VK_COMPARE_OP_NOT_EQUAL
:
4089 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4090 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4091 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4092 case VK_COMPARE_OP_ALWAYS
:
4093 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4095 unreachable("illegal compare mode");
4101 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4104 case VK_FILTER_NEAREST
:
4105 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4106 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4107 case VK_FILTER_LINEAR
:
4108 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4109 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4110 case VK_FILTER_CUBIC_IMG
:
4112 fprintf(stderr
, "illegal texture filter");
4118 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4121 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4122 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4123 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4124 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4126 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4131 radv_tex_bordercolor(VkBorderColor bcolor
)
4134 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4135 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4136 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4137 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4138 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4139 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4140 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4141 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4142 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4150 radv_tex_aniso_filter(unsigned filter
)
4164 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4167 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4168 return SQ_IMG_FILTER_MODE_BLEND
;
4169 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4170 return SQ_IMG_FILTER_MODE_MIN
;
4171 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4172 return SQ_IMG_FILTER_MODE_MAX
;
4180 radv_init_sampler(struct radv_device
*device
,
4181 struct radv_sampler
*sampler
,
4182 const VkSamplerCreateInfo
*pCreateInfo
)
4184 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4185 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4186 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4187 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4188 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4190 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4191 vk_find_struct_const(pCreateInfo
->pNext
,
4192 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4193 if (sampler_reduction
)
4194 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4196 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4197 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4198 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4199 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4200 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4201 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4202 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4203 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4204 S_008F30_DISABLE_CUBE_WRAP(0) |
4205 S_008F30_COMPAT_MODE(is_vi
) |
4206 S_008F30_FILTER_MODE(filter_mode
));
4207 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4208 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4209 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4210 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4211 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4212 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4213 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4214 S_008F38_MIP_POINT_PRECLAMP(0) |
4215 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4216 S_008F38_FILTER_PREC_FIX(1) |
4217 S_008F38_ANISO_OVERRIDE(is_vi
));
4218 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4219 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4222 VkResult
radv_CreateSampler(
4224 const VkSamplerCreateInfo
* pCreateInfo
,
4225 const VkAllocationCallbacks
* pAllocator
,
4226 VkSampler
* pSampler
)
4228 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4229 struct radv_sampler
*sampler
;
4231 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4233 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4234 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4236 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4238 radv_init_sampler(device
, sampler
, pCreateInfo
);
4239 *pSampler
= radv_sampler_to_handle(sampler
);
4244 void radv_DestroySampler(
4247 const VkAllocationCallbacks
* pAllocator
)
4249 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4250 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4254 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4257 /* vk_icd.h does not declare this function, so we declare it here to
4258 * suppress Wmissing-prototypes.
4260 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4261 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4263 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4264 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4266 /* For the full details on loader interface versioning, see
4267 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4268 * What follows is a condensed summary, to help you navigate the large and
4269 * confusing official doc.
4271 * - Loader interface v0 is incompatible with later versions. We don't
4274 * - In loader interface v1:
4275 * - The first ICD entrypoint called by the loader is
4276 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4278 * - The ICD must statically expose no other Vulkan symbol unless it is
4279 * linked with -Bsymbolic.
4280 * - Each dispatchable Vulkan handle created by the ICD must be
4281 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4282 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4283 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4284 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4285 * such loader-managed surfaces.
4287 * - Loader interface v2 differs from v1 in:
4288 * - The first ICD entrypoint called by the loader is
4289 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4290 * statically expose this entrypoint.
4292 * - Loader interface v3 differs from v2 in:
4293 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4294 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4295 * because the loader no longer does so.
4297 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4301 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4302 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4305 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4306 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4308 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4310 /* At the moment, we support only the below handle types. */
4311 assert(pGetFdInfo
->handleType
==
4312 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4313 pGetFdInfo
->handleType
==
4314 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4316 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4318 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4322 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4323 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4325 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4327 switch (handleType
) {
4328 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4329 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4333 /* The valid usage section for this function says:
4335 * "handleType must not be one of the handle types defined as
4338 * So opaque handle types fall into the default "unsupported" case.
4340 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4344 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4348 uint32_t syncobj_handle
= 0;
4349 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4351 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4354 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4356 *syncobj
= syncobj_handle
;
4362 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4366 /* If we create a syncobj we do it locally so that if we have an error, we don't
4367 * leave a syncobj in an undetermined state in the fence. */
4368 uint32_t syncobj_handle
= *syncobj
;
4369 if (!syncobj_handle
) {
4370 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4372 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4377 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4379 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4381 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4384 *syncobj
= syncobj_handle
;
4391 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4392 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4394 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4395 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4396 uint32_t *syncobj_dst
= NULL
;
4398 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4399 syncobj_dst
= &sem
->temp_syncobj
;
4401 syncobj_dst
= &sem
->syncobj
;
4404 switch(pImportSemaphoreFdInfo
->handleType
) {
4405 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4406 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4407 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4408 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4410 unreachable("Unhandled semaphore handle type");
4414 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4415 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4418 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4419 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4421 uint32_t syncobj_handle
;
4423 if (sem
->temp_syncobj
)
4424 syncobj_handle
= sem
->temp_syncobj
;
4426 syncobj_handle
= sem
->syncobj
;
4428 switch(pGetFdInfo
->handleType
) {
4429 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4430 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4432 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4433 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4435 if (sem
->temp_syncobj
) {
4436 close (sem
->temp_syncobj
);
4437 sem
->temp_syncobj
= 0;
4439 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4444 unreachable("Unhandled semaphore handle type");
4448 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4452 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4453 VkPhysicalDevice physicalDevice
,
4454 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4455 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4457 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4459 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4460 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4461 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4462 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4463 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4464 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4465 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4466 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4467 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4468 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4469 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4470 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4471 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4473 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4474 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4475 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4479 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4480 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4482 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4483 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4484 uint32_t *syncobj_dst
= NULL
;
4487 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4488 syncobj_dst
= &fence
->temp_syncobj
;
4490 syncobj_dst
= &fence
->syncobj
;
4493 switch(pImportFenceFdInfo
->handleType
) {
4494 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4495 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4496 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4497 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4499 unreachable("Unhandled fence handle type");
4503 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4504 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4507 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4508 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4510 uint32_t syncobj_handle
;
4512 if (fence
->temp_syncobj
)
4513 syncobj_handle
= fence
->temp_syncobj
;
4515 syncobj_handle
= fence
->syncobj
;
4517 switch(pGetFdInfo
->handleType
) {
4518 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4519 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4521 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4522 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4524 if (fence
->temp_syncobj
) {
4525 close (fence
->temp_syncobj
);
4526 fence
->temp_syncobj
= 0;
4528 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4533 unreachable("Unhandled fence handle type");
4537 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4541 void radv_GetPhysicalDeviceExternalFenceProperties(
4542 VkPhysicalDevice physicalDevice
,
4543 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4544 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4546 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4548 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4549 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4550 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4551 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4552 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4553 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4554 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4556 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4557 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4558 pExternalFenceProperties
->externalFenceFeatures
= 0;
4563 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4564 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4565 const VkAllocationCallbacks
* pAllocator
,
4566 VkDebugReportCallbackEXT
* pCallback
)
4568 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4569 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4570 pCreateInfo
, pAllocator
, &instance
->alloc
,
4575 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4576 VkDebugReportCallbackEXT _callback
,
4577 const VkAllocationCallbacks
* pAllocator
)
4579 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4580 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4581 _callback
, pAllocator
, &instance
->alloc
);
4585 radv_DebugReportMessageEXT(VkInstance _instance
,
4586 VkDebugReportFlagsEXT flags
,
4587 VkDebugReportObjectTypeEXT objectType
,
4590 int32_t messageCode
,
4591 const char* pLayerPrefix
,
4592 const char* pMessage
)
4594 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4595 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4596 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4600 radv_GetDeviceGroupPeerMemoryFeatures(
4603 uint32_t localDeviceIndex
,
4604 uint32_t remoteDeviceIndex
,
4605 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4607 assert(localDeviceIndex
== remoteDeviceIndex
);
4609 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4610 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4611 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4612 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;