2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
53 uint32_t mesa_timestamp
, llvm_timestamp
;
55 memset(uuid
, 0, VK_UUID_SIZE
);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
60 memcpy(uuid
, &mesa_timestamp
, 4);
61 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
62 memcpy((char*)uuid
+ 8, &f
, 2);
63 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
68 radv_get_driver_uuid(void *uuid
)
70 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
74 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
76 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
80 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
82 const char *chip_string
;
83 char llvm_string
[32] = {};
86 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
87 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
88 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
89 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
90 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
91 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
92 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
93 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
94 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
95 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
96 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
97 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
98 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
99 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
100 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
101 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
102 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
103 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
104 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
105 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
106 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
107 default: chip_string
= "AMD RADV unknown"; break;
111 snprintf(llvm_string
, sizeof(llvm_string
),
112 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
113 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
116 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
120 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
122 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
123 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
124 device
->rad_info
.vram_vis_size
);
126 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
127 device
->memory_properties
.memoryHeapCount
= 0;
128 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
129 vram_index
= device
->memory_properties
.memoryHeapCount
++;
130 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
131 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
132 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
135 if (visible_vram_size
) {
136 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
137 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
138 .size
= visible_vram_size
,
139 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
142 if (device
->rad_info
.gart_size
> 0) {
143 gart_index
= device
->memory_properties
.memoryHeapCount
++;
144 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
145 .size
= device
->rad_info
.gart_size
,
150 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
151 unsigned type_count
= 0;
152 if (vram_index
>= 0) {
153 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
154 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
155 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
156 .heapIndex
= vram_index
,
159 if (gart_index
>= 0) {
160 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
161 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
162 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
163 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
164 .heapIndex
= gart_index
,
167 if (visible_vram_index
>= 0) {
168 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
169 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
170 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
171 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
172 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
173 .heapIndex
= visible_vram_index
,
176 if (gart_index
>= 0) {
177 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
178 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
179 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
181 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
182 .heapIndex
= gart_index
,
185 device
->memory_properties
.memoryTypeCount
= type_count
;
189 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
191 const char *family
= getenv("RADV_FORCE_FAMILY");
197 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
198 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
199 /* Override family and chip_class. */
200 device
->rad_info
.family
= i
;
202 if (i
>= CHIP_VEGA10
)
203 device
->rad_info
.chip_class
= GFX9
;
204 else if (i
>= CHIP_TONGA
)
205 device
->rad_info
.chip_class
= VI
;
206 else if (i
>= CHIP_BONAIRE
)
207 device
->rad_info
.chip_class
= CIK
;
209 device
->rad_info
.chip_class
= SI
;
215 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
220 radv_physical_device_init(struct radv_physical_device
*device
,
221 struct radv_instance
*instance
,
222 drmDevicePtr drm_device
)
224 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
226 drmVersionPtr version
;
229 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
231 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
233 version
= drmGetVersion(fd
);
236 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
237 "failed to get version %s: %m", path
);
240 if (strcmp(version
->name
, "amdgpu")) {
241 drmFreeVersion(version
);
243 return VK_ERROR_INCOMPATIBLE_DRIVER
;
245 drmFreeVersion(version
);
247 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
248 device
->instance
= instance
;
249 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
250 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
252 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
253 instance
->perftest_flags
);
255 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
259 device
->local_fd
= fd
;
260 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
262 radv_handle_env_var_force_family(device
);
264 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
266 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
267 device
->ws
->destroy(device
->ws
);
268 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
269 "cannot generate UUID");
273 /* These flags affect shader compilation. */
274 uint64_t shader_env_flags
=
275 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
276 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
278 /* The gpu id is already embeded in the uuid so we just pass "radv"
279 * when creating the cache.
281 char buf
[VK_UUID_SIZE
* 2 + 1];
282 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
283 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
285 if (device
->rad_info
.chip_class
< VI
||
286 device
->rad_info
.chip_class
> GFX9
)
287 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
289 radv_get_driver_uuid(&device
->device_uuid
);
290 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
292 if (device
->rad_info
.family
== CHIP_STONEY
||
293 device
->rad_info
.chip_class
>= GFX9
) {
294 device
->has_rbplus
= true;
295 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
296 device
->rad_info
.family
== CHIP_VEGA12
||
297 device
->rad_info
.family
== CHIP_RAVEN
;
300 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
303 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
305 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
307 /* Vega10/Raven need a special workaround for a hardware bug. */
308 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
309 device
->rad_info
.family
== CHIP_RAVEN
;
311 /* Out-of-order primitive rasterization. */
312 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
313 device
->rad_info
.max_se
>= 2;
314 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
315 (device
->instance
->perftest_flags
& RADV_PERFTEST_OUT_OF_ORDER
);
317 device
->dcc_msaa_allowed
= device
->rad_info
.chip_class
== VI
&&
318 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
320 radv_physical_device_init_mem_types(device
);
321 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
323 result
= radv_init_wsi(device
);
324 if (result
!= VK_SUCCESS
) {
325 device
->ws
->destroy(device
->ws
);
337 radv_physical_device_finish(struct radv_physical_device
*device
)
339 radv_finish_wsi(device
);
340 device
->ws
->destroy(device
->ws
);
341 disk_cache_destroy(device
->disk_cache
);
342 close(device
->local_fd
);
346 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
347 VkSystemAllocationScope allocationScope
)
353 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
354 size_t align
, VkSystemAllocationScope allocationScope
)
356 return realloc(pOriginal
, size
);
360 default_free_func(void *pUserData
, void *pMemory
)
365 static const VkAllocationCallbacks default_alloc
= {
367 .pfnAllocation
= default_alloc_func
,
368 .pfnReallocation
= default_realloc_func
,
369 .pfnFree
= default_free_func
,
372 static const struct debug_control radv_debug_options
[] = {
373 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
374 {"nodcc", RADV_DEBUG_NO_DCC
},
375 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
376 {"nocache", RADV_DEBUG_NO_CACHE
},
377 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
378 {"nohiz", RADV_DEBUG_NO_HIZ
},
379 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
380 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
381 {"allbos", RADV_DEBUG_ALL_BOS
},
382 {"noibs", RADV_DEBUG_NO_IBS
},
383 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
384 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
385 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
386 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
387 {"nosisched", RADV_DEBUG_NO_SISCHED
},
388 {"preoptir", RADV_DEBUG_PREOPTIR
},
393 radv_get_debug_option_name(int id
)
395 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
396 return radv_debug_options
[id
].string
;
399 static const struct debug_control radv_perftest_options
[] = {
400 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
401 {"sisched", RADV_PERFTEST_SISCHED
},
402 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
403 {"binning", RADV_PERFTEST_BINNING
},
404 {"outoforderrast", RADV_PERFTEST_OUT_OF_ORDER
},
405 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
410 radv_get_perftest_option_name(int id
)
412 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
413 return radv_perftest_options
[id
].string
;
417 radv_handle_per_app_options(struct radv_instance
*instance
,
418 const VkApplicationInfo
*info
)
420 const char *name
= info
? info
->pApplicationName
: NULL
;
425 if (!strcmp(name
, "Talos - Linux - 32bit") ||
426 !strcmp(name
, "Talos - Linux - 64bit")) {
427 /* Force enable LLVM sisched for Talos because it looks safe
428 * and it gives few more FPS.
430 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
434 static int radv_get_instance_extension_index(const char *name
)
436 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
437 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
444 VkResult
radv_CreateInstance(
445 const VkInstanceCreateInfo
* pCreateInfo
,
446 const VkAllocationCallbacks
* pAllocator
,
447 VkInstance
* pInstance
)
449 struct radv_instance
*instance
;
452 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
454 uint32_t client_version
;
455 if (pCreateInfo
->pApplicationInfo
&&
456 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
457 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
459 client_version
= VK_MAKE_VERSION(1, 0, 0);
462 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
463 client_version
> VK_MAKE_VERSION(1, 1, 0xfff)) {
464 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
465 "Client requested version %d.%d.%d",
466 VK_VERSION_MAJOR(client_version
),
467 VK_VERSION_MINOR(client_version
),
468 VK_VERSION_PATCH(client_version
));
471 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
472 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
474 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
476 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
479 instance
->alloc
= *pAllocator
;
481 instance
->alloc
= default_alloc
;
483 instance
->apiVersion
= client_version
;
484 instance
->physicalDeviceCount
= -1;
486 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
487 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
488 int index
= radv_get_instance_extension_index(ext_name
);
490 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
491 vk_free2(&default_alloc
, pAllocator
, instance
);
492 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
495 instance
->enabled_extensions
.extensions
[index
] = true;
498 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
499 if (result
!= VK_SUCCESS
) {
500 vk_free2(&default_alloc
, pAllocator
, instance
);
501 return vk_error(result
);
506 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
508 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
511 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
512 radv_perftest_options
);
514 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
516 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
517 /* Disable sisched when the user requests it, this is mostly
518 * useful when the driver force-enable sisched for the given
521 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
524 *pInstance
= radv_instance_to_handle(instance
);
529 void radv_DestroyInstance(
530 VkInstance _instance
,
531 const VkAllocationCallbacks
* pAllocator
)
533 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
538 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
539 radv_physical_device_finish(instance
->physicalDevices
+ i
);
542 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
546 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
548 vk_free(&instance
->alloc
, instance
);
552 radv_enumerate_devices(struct radv_instance
*instance
)
554 /* TODO: Check for more devices ? */
555 drmDevicePtr devices
[8];
556 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
559 instance
->physicalDeviceCount
= 0;
561 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
563 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
565 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
566 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
567 devices
[i
]->bustype
== DRM_BUS_PCI
&&
568 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
570 result
= radv_physical_device_init(instance
->physicalDevices
+
571 instance
->physicalDeviceCount
,
574 if (result
== VK_SUCCESS
)
575 ++instance
->physicalDeviceCount
;
576 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
580 drmFreeDevices(devices
, max_devices
);
585 VkResult
radv_EnumeratePhysicalDevices(
586 VkInstance _instance
,
587 uint32_t* pPhysicalDeviceCount
,
588 VkPhysicalDevice
* pPhysicalDevices
)
590 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
593 if (instance
->physicalDeviceCount
< 0) {
594 result
= radv_enumerate_devices(instance
);
595 if (result
!= VK_SUCCESS
&&
596 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
600 if (!pPhysicalDevices
) {
601 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
603 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
604 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
605 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
608 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
612 VkResult
radv_EnumeratePhysicalDeviceGroups(
613 VkInstance _instance
,
614 uint32_t* pPhysicalDeviceGroupCount
,
615 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
617 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
620 if (instance
->physicalDeviceCount
< 0) {
621 result
= radv_enumerate_devices(instance
);
622 if (result
!= VK_SUCCESS
&&
623 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
627 if (!pPhysicalDeviceGroupProperties
) {
628 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
630 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
631 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
632 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
633 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
634 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
637 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
641 void radv_GetPhysicalDeviceFeatures(
642 VkPhysicalDevice physicalDevice
,
643 VkPhysicalDeviceFeatures
* pFeatures
)
645 memset(pFeatures
, 0, sizeof(*pFeatures
));
647 *pFeatures
= (VkPhysicalDeviceFeatures
) {
648 .robustBufferAccess
= true,
649 .fullDrawIndexUint32
= true,
650 .imageCubeArray
= true,
651 .independentBlend
= true,
652 .geometryShader
= true,
653 .tessellationShader
= true,
654 .sampleRateShading
= true,
655 .dualSrcBlend
= true,
657 .multiDrawIndirect
= true,
658 .drawIndirectFirstInstance
= true,
660 .depthBiasClamp
= true,
661 .fillModeNonSolid
= true,
666 .multiViewport
= true,
667 .samplerAnisotropy
= true,
668 .textureCompressionETC2
= false,
669 .textureCompressionASTC_LDR
= false,
670 .textureCompressionBC
= true,
671 .occlusionQueryPrecise
= true,
672 .pipelineStatisticsQuery
= true,
673 .vertexPipelineStoresAndAtomics
= true,
674 .fragmentStoresAndAtomics
= true,
675 .shaderTessellationAndGeometryPointSize
= true,
676 .shaderImageGatherExtended
= true,
677 .shaderStorageImageExtendedFormats
= true,
678 .shaderStorageImageMultisample
= false,
679 .shaderUniformBufferArrayDynamicIndexing
= true,
680 .shaderSampledImageArrayDynamicIndexing
= true,
681 .shaderStorageBufferArrayDynamicIndexing
= true,
682 .shaderStorageImageArrayDynamicIndexing
= true,
683 .shaderStorageImageReadWithoutFormat
= true,
684 .shaderStorageImageWriteWithoutFormat
= true,
685 .shaderClipDistance
= true,
686 .shaderCullDistance
= true,
687 .shaderFloat64
= true,
689 .shaderInt16
= false,
690 .sparseBinding
= true,
691 .variableMultisampleRate
= true,
692 .inheritedQueries
= true,
696 void radv_GetPhysicalDeviceFeatures2(
697 VkPhysicalDevice physicalDevice
,
698 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
700 vk_foreach_struct(ext
, pFeatures
->pNext
) {
701 switch (ext
->sType
) {
702 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
703 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
704 features
->variablePointersStorageBuffer
= true;
705 features
->variablePointers
= false;
708 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
709 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
710 features
->multiview
= true;
711 features
->multiviewGeometryShader
= true;
712 features
->multiviewTessellationShader
= true;
715 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
716 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
717 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
718 features
->shaderDrawParameters
= true;
721 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
722 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
723 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
724 features
->protectedMemory
= false;
727 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
728 VkPhysicalDevice16BitStorageFeatures
*features
=
729 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
730 features
->storageBuffer16BitAccess
= false;
731 features
->uniformAndStorageBuffer16BitAccess
= false;
732 features
->storagePushConstant16
= false;
733 features
->storageInputOutput16
= false;
736 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
737 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
738 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
739 features
->samplerYcbcrConversion
= false;
742 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
743 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
744 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)features
;
745 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
746 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
747 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
748 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
749 features
->shaderSampledImageArrayNonUniformIndexing
= false;
750 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
751 features
->shaderStorageImageArrayNonUniformIndexing
= false;
752 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
753 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
754 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
755 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
756 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
757 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
758 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
759 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
760 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
761 features
->descriptorBindingUpdateUnusedWhilePending
= true;
762 features
->descriptorBindingPartiallyBound
= true;
763 features
->descriptorBindingVariableDescriptorCount
= true;
764 features
->runtimeDescriptorArray
= true;
771 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
774 void radv_GetPhysicalDeviceProperties(
775 VkPhysicalDevice physicalDevice
,
776 VkPhysicalDeviceProperties
* pProperties
)
778 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
779 VkSampleCountFlags sample_counts
= 0xf;
781 /* make sure that the entire descriptor set is addressable with a signed
782 * 32-bit int. So the sum of all limits scaled by descriptor size has to
783 * be at most 2 GiB. the combined image & samples object count as one of
784 * both. This limit is for the pipeline layout, not for the set layout, but
785 * there is no set limit, so we just set a pipeline limit. I don't think
786 * any app is going to hit this soon. */
787 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
788 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
789 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
790 32 /* sampler, largest when combined with image */ +
791 64 /* sampled image */ +
792 64 /* storage image */);
794 VkPhysicalDeviceLimits limits
= {
795 .maxImageDimension1D
= (1 << 14),
796 .maxImageDimension2D
= (1 << 14),
797 .maxImageDimension3D
= (1 << 11),
798 .maxImageDimensionCube
= (1 << 14),
799 .maxImageArrayLayers
= (1 << 11),
800 .maxTexelBufferElements
= 128 * 1024 * 1024,
801 .maxUniformBufferRange
= UINT32_MAX
,
802 .maxStorageBufferRange
= UINT32_MAX
,
803 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
804 .maxMemoryAllocationCount
= UINT32_MAX
,
805 .maxSamplerAllocationCount
= 64 * 1024,
806 .bufferImageGranularity
= 64, /* A cache line */
807 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
808 .maxBoundDescriptorSets
= MAX_SETS
,
809 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
810 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
811 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
812 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
813 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
814 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
815 .maxPerStageResources
= max_descriptor_set_size
,
816 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
817 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
818 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
819 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
820 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
821 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
822 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
823 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
824 .maxVertexInputAttributes
= 32,
825 .maxVertexInputBindings
= 32,
826 .maxVertexInputAttributeOffset
= 2047,
827 .maxVertexInputBindingStride
= 2048,
828 .maxVertexOutputComponents
= 128,
829 .maxTessellationGenerationLevel
= 64,
830 .maxTessellationPatchSize
= 32,
831 .maxTessellationControlPerVertexInputComponents
= 128,
832 .maxTessellationControlPerVertexOutputComponents
= 128,
833 .maxTessellationControlPerPatchOutputComponents
= 120,
834 .maxTessellationControlTotalOutputComponents
= 4096,
835 .maxTessellationEvaluationInputComponents
= 128,
836 .maxTessellationEvaluationOutputComponents
= 128,
837 .maxGeometryShaderInvocations
= 127,
838 .maxGeometryInputComponents
= 64,
839 .maxGeometryOutputComponents
= 128,
840 .maxGeometryOutputVertices
= 256,
841 .maxGeometryTotalOutputComponents
= 1024,
842 .maxFragmentInputComponents
= 128,
843 .maxFragmentOutputAttachments
= 8,
844 .maxFragmentDualSrcAttachments
= 1,
845 .maxFragmentCombinedOutputResources
= 8,
846 .maxComputeSharedMemorySize
= 32768,
847 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
848 .maxComputeWorkGroupInvocations
= 2048,
849 .maxComputeWorkGroupSize
= {
854 .subPixelPrecisionBits
= 4 /* FIXME */,
855 .subTexelPrecisionBits
= 4 /* FIXME */,
856 .mipmapPrecisionBits
= 4 /* FIXME */,
857 .maxDrawIndexedIndexValue
= UINT32_MAX
,
858 .maxDrawIndirectCount
= UINT32_MAX
,
859 .maxSamplerLodBias
= 16,
860 .maxSamplerAnisotropy
= 16,
861 .maxViewports
= MAX_VIEWPORTS
,
862 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
863 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
864 .viewportSubPixelBits
= 13, /* We take a float? */
865 .minMemoryMapAlignment
= 4096, /* A page */
866 .minTexelBufferOffsetAlignment
= 1,
867 .minUniformBufferOffsetAlignment
= 4,
868 .minStorageBufferOffsetAlignment
= 4,
869 .minTexelOffset
= -32,
870 .maxTexelOffset
= 31,
871 .minTexelGatherOffset
= -32,
872 .maxTexelGatherOffset
= 31,
873 .minInterpolationOffset
= -2,
874 .maxInterpolationOffset
= 2,
875 .subPixelInterpolationOffsetBits
= 8,
876 .maxFramebufferWidth
= (1 << 14),
877 .maxFramebufferHeight
= (1 << 14),
878 .maxFramebufferLayers
= (1 << 10),
879 .framebufferColorSampleCounts
= sample_counts
,
880 .framebufferDepthSampleCounts
= sample_counts
,
881 .framebufferStencilSampleCounts
= sample_counts
,
882 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
883 .maxColorAttachments
= MAX_RTS
,
884 .sampledImageColorSampleCounts
= sample_counts
,
885 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
886 .sampledImageDepthSampleCounts
= sample_counts
,
887 .sampledImageStencilSampleCounts
= sample_counts
,
888 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
889 .maxSampleMaskWords
= 1,
890 .timestampComputeAndGraphics
= true,
891 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
892 .maxClipDistances
= 8,
893 .maxCullDistances
= 8,
894 .maxCombinedClipAndCullDistances
= 8,
895 .discreteQueuePriorities
= 1,
896 .pointSizeRange
= { 0.125, 255.875 },
897 .lineWidthRange
= { 0.0, 7.9921875 },
898 .pointSizeGranularity
= (1.0 / 8.0),
899 .lineWidthGranularity
= (1.0 / 128.0),
900 .strictLines
= false, /* FINISHME */
901 .standardSampleLocations
= true,
902 .optimalBufferCopyOffsetAlignment
= 128,
903 .optimalBufferCopyRowPitchAlignment
= 128,
904 .nonCoherentAtomSize
= 64,
907 *pProperties
= (VkPhysicalDeviceProperties
) {
908 .apiVersion
= radv_physical_device_api_version(pdevice
),
909 .driverVersion
= vk_get_driver_version(),
910 .vendorID
= ATI_VENDOR_ID
,
911 .deviceID
= pdevice
->rad_info
.pci_id
,
912 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
914 .sparseProperties
= {0},
917 strcpy(pProperties
->deviceName
, pdevice
->name
);
918 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
921 void radv_GetPhysicalDeviceProperties2(
922 VkPhysicalDevice physicalDevice
,
923 VkPhysicalDeviceProperties2KHR
*pProperties
)
925 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
926 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
928 vk_foreach_struct(ext
, pProperties
->pNext
) {
929 switch (ext
->sType
) {
930 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
931 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
932 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
933 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
936 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
937 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
938 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
939 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
940 properties
->deviceLUIDValid
= false;
943 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
944 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
945 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
946 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
949 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
950 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
951 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
952 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
955 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
956 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
957 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
958 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
961 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
962 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
963 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
964 properties
->minImportedHostPointerAlignment
= 4096;
967 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
968 VkPhysicalDeviceSubgroupProperties
*properties
=
969 (VkPhysicalDeviceSubgroupProperties
*)ext
;
970 properties
->subgroupSize
= 64;
971 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
972 properties
->supportedOperations
=
973 VK_SUBGROUP_FEATURE_BASIC_BIT
|
974 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
975 VK_SUBGROUP_FEATURE_QUAD_BIT
|
976 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
977 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
978 VK_SUBGROUP_FEATURE_VOTE_BIT
;
979 properties
->quadOperationsInAllStages
= true;
982 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
983 VkPhysicalDeviceMaintenance3Properties
*properties
=
984 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
985 /* Make sure everything is addressable by a signed 32-bit int, and
986 * our largest descriptors are 96 bytes. */
987 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
988 /* Our buffer size fields allow only this much */
989 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
992 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
993 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
994 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
995 /* GFX6-8 only support single channel min/max filter. */
996 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
997 properties
->filterMinmaxSingleComponentFormats
= true;
1000 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1001 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1002 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1004 /* Shader engines. */
1005 properties
->shaderEngineCount
=
1006 pdevice
->rad_info
.max_se
;
1007 properties
->shaderArraysPerEngineCount
=
1008 pdevice
->rad_info
.max_sh_per_se
;
1009 properties
->computeUnitsPerShaderArray
=
1010 pdevice
->rad_info
.num_good_compute_units
/
1011 (pdevice
->rad_info
.max_se
*
1012 pdevice
->rad_info
.max_sh_per_se
);
1013 properties
->simdPerComputeUnit
= 4;
1014 properties
->wavefrontsPerSimd
=
1015 pdevice
->rad_info
.family
== CHIP_TONGA
||
1016 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1017 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1018 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1019 pdevice
->rad_info
.family
== CHIP_POLARIS12
? 8 : 10;
1020 properties
->wavefrontSize
= 64;
1023 properties
->sgprsPerSimd
=
1024 radv_get_num_physical_sgprs(pdevice
);
1025 properties
->minSgprAllocation
=
1026 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1027 properties
->maxSgprAllocation
=
1028 pdevice
->rad_info
.family
== CHIP_TONGA
||
1029 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1030 properties
->sgprAllocationGranularity
=
1031 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1034 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1035 properties
->minVgprAllocation
= 4;
1036 properties
->maxVgprAllocation
= 256;
1037 properties
->vgprAllocationGranularity
= 4;
1040 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1041 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1042 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1043 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1046 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1047 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1048 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1049 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1050 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1051 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1052 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1053 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1054 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1055 properties
->robustBufferAccessUpdateAfterBind
= false;
1056 properties
->quadDivergentImplicitLod
= false;
1058 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1059 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1060 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1061 32 /* sampler, largest when combined with image */ +
1062 64 /* sampled image */ +
1063 64 /* storage image */);
1064 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1065 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1066 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1067 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1068 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1069 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1070 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1071 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1072 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1073 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1074 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1075 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1076 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1077 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1078 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1087 static void radv_get_physical_device_queue_family_properties(
1088 struct radv_physical_device
* pdevice
,
1090 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1092 int num_queue_families
= 1;
1094 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1095 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1096 num_queue_families
++;
1098 if (pQueueFamilyProperties
== NULL
) {
1099 *pCount
= num_queue_families
;
1108 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1109 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1110 VK_QUEUE_COMPUTE_BIT
|
1111 VK_QUEUE_TRANSFER_BIT
|
1112 VK_QUEUE_SPARSE_BINDING_BIT
,
1114 .timestampValidBits
= 64,
1115 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1120 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1121 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1122 if (*pCount
> idx
) {
1123 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1124 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1125 VK_QUEUE_TRANSFER_BIT
|
1126 VK_QUEUE_SPARSE_BINDING_BIT
,
1127 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1128 .timestampValidBits
= 64,
1129 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1137 void radv_GetPhysicalDeviceQueueFamilyProperties(
1138 VkPhysicalDevice physicalDevice
,
1140 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1142 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1143 if (!pQueueFamilyProperties
) {
1144 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1147 VkQueueFamilyProperties
*properties
[] = {
1148 pQueueFamilyProperties
+ 0,
1149 pQueueFamilyProperties
+ 1,
1150 pQueueFamilyProperties
+ 2,
1152 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1153 assert(*pCount
<= 3);
1156 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1157 VkPhysicalDevice physicalDevice
,
1159 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1161 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1162 if (!pQueueFamilyProperties
) {
1163 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1166 VkQueueFamilyProperties
*properties
[] = {
1167 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1168 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1169 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1171 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1172 assert(*pCount
<= 3);
1175 void radv_GetPhysicalDeviceMemoryProperties(
1176 VkPhysicalDevice physicalDevice
,
1177 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1179 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1181 *pMemoryProperties
= physical_device
->memory_properties
;
1184 void radv_GetPhysicalDeviceMemoryProperties2(
1185 VkPhysicalDevice physicalDevice
,
1186 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1188 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1189 &pMemoryProperties
->memoryProperties
);
1192 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1194 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1195 const void *pHostPointer
,
1196 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1198 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1202 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1203 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1204 uint32_t memoryTypeBits
= 0;
1205 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1206 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1207 memoryTypeBits
= (1 << i
);
1211 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1215 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1219 static enum radeon_ctx_priority
1220 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1222 /* Default to MEDIUM when a specific global priority isn't requested */
1224 return RADEON_CTX_PRIORITY_MEDIUM
;
1226 switch(pObj
->globalPriority
) {
1227 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1228 return RADEON_CTX_PRIORITY_REALTIME
;
1229 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1230 return RADEON_CTX_PRIORITY_HIGH
;
1231 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1232 return RADEON_CTX_PRIORITY_MEDIUM
;
1233 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1234 return RADEON_CTX_PRIORITY_LOW
;
1236 unreachable("Illegal global priority value");
1237 return RADEON_CTX_PRIORITY_INVALID
;
1242 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1243 uint32_t queue_family_index
, int idx
,
1244 VkDeviceQueueCreateFlags flags
,
1245 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1247 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1248 queue
->device
= device
;
1249 queue
->queue_family_index
= queue_family_index
;
1250 queue
->queue_idx
= idx
;
1251 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1252 queue
->flags
= flags
;
1254 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1256 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1262 radv_queue_finish(struct radv_queue
*queue
)
1265 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1267 if (queue
->initial_full_flush_preamble_cs
)
1268 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1269 if (queue
->initial_preamble_cs
)
1270 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1271 if (queue
->continue_preamble_cs
)
1272 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1273 if (queue
->descriptor_bo
)
1274 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1275 if (queue
->scratch_bo
)
1276 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1277 if (queue
->esgs_ring_bo
)
1278 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1279 if (queue
->gsvs_ring_bo
)
1280 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1281 if (queue
->tess_rings_bo
)
1282 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1283 if (queue
->compute_scratch_bo
)
1284 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1288 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1290 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1291 bo_list
->list
.count
= bo_list
->capacity
= 0;
1292 bo_list
->list
.bos
= NULL
;
1296 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1298 free(bo_list
->list
.bos
);
1299 pthread_mutex_destroy(&bo_list
->mutex
);
1302 static VkResult
radv_bo_list_add(struct radv_bo_list
*bo_list
, struct radeon_winsys_bo
*bo
)
1304 pthread_mutex_lock(&bo_list
->mutex
);
1305 if (bo_list
->list
.count
== bo_list
->capacity
) {
1306 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1307 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1310 pthread_mutex_unlock(&bo_list
->mutex
);
1311 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1314 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1315 bo_list
->capacity
= capacity
;
1318 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1319 pthread_mutex_unlock(&bo_list
->mutex
);
1323 static void radv_bo_list_remove(struct radv_bo_list
*bo_list
, struct radeon_winsys_bo
*bo
)
1325 pthread_mutex_lock(&bo_list
->mutex
);
1326 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1327 if (bo_list
->list
.bos
[i
] == bo
) {
1328 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1329 --bo_list
->list
.count
;
1333 pthread_mutex_unlock(&bo_list
->mutex
);
1337 radv_device_init_gs_info(struct radv_device
*device
)
1339 switch (device
->physical_device
->rad_info
.family
) {
1348 device
->gs_table_depth
= 16;
1357 case CHIP_POLARIS10
:
1358 case CHIP_POLARIS11
:
1359 case CHIP_POLARIS12
:
1363 device
->gs_table_depth
= 32;
1366 unreachable("unknown GPU");
1370 static int radv_get_device_extension_index(const char *name
)
1372 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1373 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1379 VkResult
radv_CreateDevice(
1380 VkPhysicalDevice physicalDevice
,
1381 const VkDeviceCreateInfo
* pCreateInfo
,
1382 const VkAllocationCallbacks
* pAllocator
,
1385 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1387 struct radv_device
*device
;
1389 bool keep_shader_info
= false;
1391 /* Check enabled features */
1392 if (pCreateInfo
->pEnabledFeatures
) {
1393 VkPhysicalDeviceFeatures supported_features
;
1394 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1395 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1396 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1397 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1398 for (uint32_t i
= 0; i
< num_features
; i
++) {
1399 if (enabled_feature
[i
] && !supported_feature
[i
])
1400 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1404 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1406 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1408 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1410 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1411 device
->instance
= physical_device
->instance
;
1412 device
->physical_device
= physical_device
;
1414 device
->ws
= physical_device
->ws
;
1416 device
->alloc
= *pAllocator
;
1418 device
->alloc
= physical_device
->instance
->alloc
;
1420 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1421 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1422 int index
= radv_get_device_extension_index(ext_name
);
1423 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1424 vk_free(&device
->alloc
, device
);
1425 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1428 device
->enabled_extensions
.extensions
[index
] = true;
1431 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1433 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1434 list_inithead(&device
->shader_slabs
);
1436 radv_bo_list_init(&device
->bo_list
);
1438 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1439 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1440 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1441 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1442 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1444 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1446 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1447 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1448 if (!device
->queues
[qfi
]) {
1449 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1453 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1455 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1457 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1458 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1459 qfi
, q
, queue_create
->flags
,
1461 if (result
!= VK_SUCCESS
)
1466 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1467 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1469 /* Disabled and not implemented for now. */
1470 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1473 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1476 device
->llvm_supports_spill
= true;
1478 /* The maximum number of scratch waves. Scratch space isn't divided
1479 * evenly between CUs. The number is only a function of the number of CUs.
1480 * We can decrease the constant to decrease the scratch buffer size.
1482 * sctx->scratch_waves must be >= the maximum posible size of
1483 * 1 threadgroup, so that the hw doesn't hang from being unable
1486 * The recommended value is 4 per CU at most. Higher numbers don't
1487 * bring much benefit, but they still occupy chip resources (think
1488 * async compute). I've seen ~2% performance difference between 4 and 32.
1490 uint32_t max_threads_per_block
= 2048;
1491 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1492 max_threads_per_block
/ 64);
1494 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1496 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1497 /* If the KMD allows it (there is a KMD hw register for it),
1498 * allow launching waves out-of-order.
1500 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1503 radv_device_init_gs_info(device
);
1505 device
->tess_offchip_block_dw_size
=
1506 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1507 device
->has_distributed_tess
=
1508 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1509 device
->physical_device
->rad_info
.max_se
>= 2;
1511 if (getenv("RADV_TRACE_FILE")) {
1512 const char *filename
= getenv("RADV_TRACE_FILE");
1514 keep_shader_info
= true;
1516 if (!radv_init_trace(device
))
1519 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1520 radv_dump_enabled_options(device
, stderr
);
1523 device
->keep_shader_info
= keep_shader_info
;
1525 result
= radv_device_init_meta(device
);
1526 if (result
!= VK_SUCCESS
)
1529 radv_device_init_msaa(device
);
1531 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1532 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1534 case RADV_QUEUE_GENERAL
:
1535 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1536 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1537 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1539 case RADV_QUEUE_COMPUTE
:
1540 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1541 radeon_emit(device
->empty_cs
[family
], 0);
1544 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1547 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1548 cik_create_gfx_config(device
);
1550 VkPipelineCacheCreateInfo ci
;
1551 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1554 ci
.pInitialData
= NULL
;
1555 ci
.initialDataSize
= 0;
1557 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1559 if (result
!= VK_SUCCESS
)
1562 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1564 *pDevice
= radv_device_to_handle(device
);
1568 radv_device_finish_meta(device
);
1570 radv_bo_list_finish(&device
->bo_list
);
1572 if (device
->trace_bo
)
1573 device
->ws
->buffer_destroy(device
->trace_bo
);
1575 if (device
->gfx_init
)
1576 device
->ws
->buffer_destroy(device
->gfx_init
);
1578 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1579 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1580 radv_queue_finish(&device
->queues
[i
][q
]);
1581 if (device
->queue_count
[i
])
1582 vk_free(&device
->alloc
, device
->queues
[i
]);
1585 vk_free(&device
->alloc
, device
);
1589 void radv_DestroyDevice(
1591 const VkAllocationCallbacks
* pAllocator
)
1593 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1598 if (device
->trace_bo
)
1599 device
->ws
->buffer_destroy(device
->trace_bo
);
1601 if (device
->gfx_init
)
1602 device
->ws
->buffer_destroy(device
->gfx_init
);
1604 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1605 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1606 radv_queue_finish(&device
->queues
[i
][q
]);
1607 if (device
->queue_count
[i
])
1608 vk_free(&device
->alloc
, device
->queues
[i
]);
1609 if (device
->empty_cs
[i
])
1610 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1612 radv_device_finish_meta(device
);
1614 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1615 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1617 radv_destroy_shader_slabs(device
);
1619 radv_bo_list_finish(&device
->bo_list
);
1620 vk_free(&device
->alloc
, device
);
1623 VkResult
radv_EnumerateInstanceLayerProperties(
1624 uint32_t* pPropertyCount
,
1625 VkLayerProperties
* pProperties
)
1627 if (pProperties
== NULL
) {
1628 *pPropertyCount
= 0;
1632 /* None supported at this time */
1633 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1636 VkResult
radv_EnumerateDeviceLayerProperties(
1637 VkPhysicalDevice physicalDevice
,
1638 uint32_t* pPropertyCount
,
1639 VkLayerProperties
* pProperties
)
1641 if (pProperties
== NULL
) {
1642 *pPropertyCount
= 0;
1646 /* None supported at this time */
1647 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1650 void radv_GetDeviceQueue2(
1652 const VkDeviceQueueInfo2
* pQueueInfo
,
1655 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1656 struct radv_queue
*queue
;
1658 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1659 if (pQueueInfo
->flags
!= queue
->flags
) {
1660 /* From the Vulkan 1.1.70 spec:
1662 * "The queue returned by vkGetDeviceQueue2 must have the same
1663 * flags value from this structure as that used at device
1664 * creation time in a VkDeviceQueueCreateInfo instance. If no
1665 * matching flags were specified at device creation time then
1666 * pQueue will return VK_NULL_HANDLE."
1668 *pQueue
= VK_NULL_HANDLE
;
1672 *pQueue
= radv_queue_to_handle(queue
);
1675 void radv_GetDeviceQueue(
1677 uint32_t queueFamilyIndex
,
1678 uint32_t queueIndex
,
1681 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1682 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1683 .queueFamilyIndex
= queueFamilyIndex
,
1684 .queueIndex
= queueIndex
1687 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1691 fill_geom_tess_rings(struct radv_queue
*queue
,
1693 bool add_sample_positions
,
1694 uint32_t esgs_ring_size
,
1695 struct radeon_winsys_bo
*esgs_ring_bo
,
1696 uint32_t gsvs_ring_size
,
1697 struct radeon_winsys_bo
*gsvs_ring_bo
,
1698 uint32_t tess_factor_ring_size
,
1699 uint32_t tess_offchip_ring_offset
,
1700 uint32_t tess_offchip_ring_size
,
1701 struct radeon_winsys_bo
*tess_rings_bo
)
1703 uint64_t esgs_va
= 0, gsvs_va
= 0;
1704 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1705 uint32_t *desc
= &map
[4];
1708 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1710 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1711 if (tess_rings_bo
) {
1712 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1713 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1716 /* stride 0, num records - size, add tid, swizzle, elsize4,
1719 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1720 S_008F04_STRIDE(0) |
1721 S_008F04_SWIZZLE_ENABLE(true);
1722 desc
[2] = esgs_ring_size
;
1723 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1724 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1725 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1726 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1727 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1728 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1729 S_008F0C_ELEMENT_SIZE(1) |
1730 S_008F0C_INDEX_STRIDE(3) |
1731 S_008F0C_ADD_TID_ENABLE(true);
1734 /* GS entry for ES->GS ring */
1735 /* stride 0, num records - size, elsize0,
1738 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1739 S_008F04_STRIDE(0) |
1740 S_008F04_SWIZZLE_ENABLE(false);
1741 desc
[2] = esgs_ring_size
;
1742 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1743 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1744 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1745 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1746 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1747 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1748 S_008F0C_ELEMENT_SIZE(0) |
1749 S_008F0C_INDEX_STRIDE(0) |
1750 S_008F0C_ADD_TID_ENABLE(false);
1753 /* VS entry for GS->VS ring */
1754 /* stride 0, num records - size, elsize0,
1757 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1758 S_008F04_STRIDE(0) |
1759 S_008F04_SWIZZLE_ENABLE(false);
1760 desc
[2] = gsvs_ring_size
;
1761 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1762 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1763 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1764 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1765 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1766 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1767 S_008F0C_ELEMENT_SIZE(0) |
1768 S_008F0C_INDEX_STRIDE(0) |
1769 S_008F0C_ADD_TID_ENABLE(false);
1772 /* stride gsvs_itemsize, num records 64
1773 elsize 4, index stride 16 */
1774 /* shader will patch stride and desc[2] */
1776 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1777 S_008F04_STRIDE(0) |
1778 S_008F04_SWIZZLE_ENABLE(true);
1780 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1781 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1782 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1783 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1784 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1785 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1786 S_008F0C_ELEMENT_SIZE(1) |
1787 S_008F0C_INDEX_STRIDE(1) |
1788 S_008F0C_ADD_TID_ENABLE(true);
1792 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1793 S_008F04_STRIDE(0) |
1794 S_008F04_SWIZZLE_ENABLE(false);
1795 desc
[2] = tess_factor_ring_size
;
1796 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1797 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1798 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1799 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1800 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1801 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1802 S_008F0C_ELEMENT_SIZE(0) |
1803 S_008F0C_INDEX_STRIDE(0) |
1804 S_008F0C_ADD_TID_ENABLE(false);
1807 desc
[0] = tess_offchip_va
;
1808 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1809 S_008F04_STRIDE(0) |
1810 S_008F04_SWIZZLE_ENABLE(false);
1811 desc
[2] = tess_offchip_ring_size
;
1812 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1813 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1814 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1815 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1816 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1817 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1818 S_008F0C_ELEMENT_SIZE(0) |
1819 S_008F0C_INDEX_STRIDE(0) |
1820 S_008F0C_ADD_TID_ENABLE(false);
1823 /* add sample positions after all rings */
1824 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1826 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1828 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1830 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1832 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1836 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1838 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1839 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1840 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1841 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1842 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1843 device
->physical_device
->rad_info
.max_se
;
1844 unsigned offchip_granularity
;
1845 unsigned hs_offchip_param
;
1846 switch (device
->tess_offchip_block_dw_size
) {
1851 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1854 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1858 switch (device
->physical_device
->rad_info
.chip_class
) {
1860 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1866 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1870 *max_offchip_buffers_p
= max_offchip_buffers
;
1871 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1872 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1873 --max_offchip_buffers
;
1875 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1876 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1879 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1881 return hs_offchip_param
;
1885 radv_get_preamble_cs(struct radv_queue
*queue
,
1886 uint32_t scratch_size
,
1887 uint32_t compute_scratch_size
,
1888 uint32_t esgs_ring_size
,
1889 uint32_t gsvs_ring_size
,
1890 bool needs_tess_rings
,
1891 bool needs_sample_positions
,
1892 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1893 struct radeon_winsys_cs
**initial_preamble_cs
,
1894 struct radeon_winsys_cs
**continue_preamble_cs
)
1896 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1897 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1898 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1899 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1900 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1901 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1902 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1903 bool add_tess_rings
= false, add_sample_positions
= false;
1904 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1905 unsigned max_offchip_buffers
;
1906 unsigned hs_offchip_param
= 0;
1907 unsigned tess_offchip_ring_offset
;
1908 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1909 if (!queue
->has_tess_rings
) {
1910 if (needs_tess_rings
)
1911 add_tess_rings
= true;
1913 if (!queue
->has_sample_positions
) {
1914 if (needs_sample_positions
)
1915 add_sample_positions
= true;
1917 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1918 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1919 &max_offchip_buffers
);
1920 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1921 tess_offchip_ring_size
= max_offchip_buffers
*
1922 queue
->device
->tess_offchip_block_dw_size
* 4;
1924 if (scratch_size
<= queue
->scratch_size
&&
1925 compute_scratch_size
<= queue
->compute_scratch_size
&&
1926 esgs_ring_size
<= queue
->esgs_ring_size
&&
1927 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1928 !add_tess_rings
&& !add_sample_positions
&&
1929 queue
->initial_preamble_cs
) {
1930 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1931 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1932 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1933 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1934 *continue_preamble_cs
= NULL
;
1938 if (scratch_size
> queue
->scratch_size
) {
1939 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1947 scratch_bo
= queue
->scratch_bo
;
1949 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1950 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1951 compute_scratch_size
,
1955 if (!compute_scratch_bo
)
1959 compute_scratch_bo
= queue
->compute_scratch_bo
;
1961 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1962 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1970 esgs_ring_bo
= queue
->esgs_ring_bo
;
1971 esgs_ring_size
= queue
->esgs_ring_size
;
1974 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1975 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1983 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1984 gsvs_ring_size
= queue
->gsvs_ring_size
;
1987 if (add_tess_rings
) {
1988 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1989 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
1996 tess_rings_bo
= queue
->tess_rings_bo
;
1999 if (scratch_bo
!= queue
->scratch_bo
||
2000 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2001 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2002 tess_rings_bo
!= queue
->tess_rings_bo
||
2003 add_sample_positions
) {
2005 if (gsvs_ring_bo
|| esgs_ring_bo
||
2006 tess_rings_bo
|| add_sample_positions
) {
2007 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2008 if (add_sample_positions
)
2009 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2011 else if (scratch_bo
)
2012 size
= 8; /* 2 dword */
2014 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2018 RADEON_FLAG_CPU_ACCESS
|
2019 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2020 RADEON_FLAG_READ_ONLY
);
2024 descriptor_bo
= queue
->descriptor_bo
;
2026 for(int i
= 0; i
< 3; ++i
) {
2027 struct radeon_winsys_cs
*cs
= NULL
;
2028 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2029 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2036 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2039 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
2042 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
2045 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
2048 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
2050 if (descriptor_bo
!= queue
->descriptor_bo
) {
2051 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2054 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2055 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2056 S_008F04_SWIZZLE_ENABLE(1);
2057 map
[0] = scratch_va
;
2061 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2062 add_sample_positions
)
2063 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2064 esgs_ring_size
, esgs_ring_bo
,
2065 gsvs_ring_size
, gsvs_ring_bo
,
2066 tess_factor_ring_size
,
2067 tess_offchip_ring_offset
,
2068 tess_offchip_ring_size
,
2071 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2074 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2075 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2076 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2077 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2078 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2081 if (esgs_ring_bo
|| gsvs_ring_bo
) {
2082 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2083 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2084 radeon_emit(cs
, esgs_ring_size
>> 8);
2085 radeon_emit(cs
, gsvs_ring_size
>> 8);
2087 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2088 radeon_emit(cs
, esgs_ring_size
>> 8);
2089 radeon_emit(cs
, gsvs_ring_size
>> 8);
2093 if (tess_rings_bo
) {
2094 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
2095 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2096 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2097 S_030938_SIZE(tess_factor_ring_size
/ 4));
2098 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2100 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2101 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2102 S_030944_BASE_HI(tf_va
>> 40));
2104 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
2106 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2107 S_008988_SIZE(tess_factor_ring_size
/ 4));
2108 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2110 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2115 if (descriptor_bo
) {
2116 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
2117 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2118 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2119 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2120 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2121 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2123 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2124 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2125 radeon_emit(cs
, va
);
2126 radeon_emit(cs
, va
>> 32);
2129 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2130 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2131 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2132 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2133 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2134 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2136 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2137 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2138 radeon_emit(cs
, va
);
2139 radeon_emit(cs
, va
>> 32);
2144 if (compute_scratch_bo
) {
2145 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2146 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2147 S_008F04_SWIZZLE_ENABLE(1);
2149 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2151 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2152 radeon_emit(cs
, scratch_va
);
2153 radeon_emit(cs
, rsrc1
);
2157 si_cs_emit_cache_flush(cs
,
2158 queue
->device
->physical_device
->rad_info
.chip_class
,
2160 queue
->queue_family_index
== RING_COMPUTE
&&
2161 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2162 (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
)) |
2163 RADV_CMD_FLAG_INV_ICACHE
|
2164 RADV_CMD_FLAG_INV_SMEM_L1
|
2165 RADV_CMD_FLAG_INV_VMEM_L1
|
2166 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2167 } else if (i
== 1) {
2168 si_cs_emit_cache_flush(cs
,
2169 queue
->device
->physical_device
->rad_info
.chip_class
,
2171 queue
->queue_family_index
== RING_COMPUTE
&&
2172 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2173 RADV_CMD_FLAG_INV_ICACHE
|
2174 RADV_CMD_FLAG_INV_SMEM_L1
|
2175 RADV_CMD_FLAG_INV_VMEM_L1
|
2176 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2179 if (!queue
->device
->ws
->cs_finalize(cs
))
2183 if (queue
->initial_full_flush_preamble_cs
)
2184 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2186 if (queue
->initial_preamble_cs
)
2187 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2189 if (queue
->continue_preamble_cs
)
2190 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2192 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2193 queue
->initial_preamble_cs
= dest_cs
[1];
2194 queue
->continue_preamble_cs
= dest_cs
[2];
2196 if (scratch_bo
!= queue
->scratch_bo
) {
2197 if (queue
->scratch_bo
)
2198 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2199 queue
->scratch_bo
= scratch_bo
;
2200 queue
->scratch_size
= scratch_size
;
2203 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2204 if (queue
->compute_scratch_bo
)
2205 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2206 queue
->compute_scratch_bo
= compute_scratch_bo
;
2207 queue
->compute_scratch_size
= compute_scratch_size
;
2210 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2211 if (queue
->esgs_ring_bo
)
2212 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2213 queue
->esgs_ring_bo
= esgs_ring_bo
;
2214 queue
->esgs_ring_size
= esgs_ring_size
;
2217 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2218 if (queue
->gsvs_ring_bo
)
2219 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2220 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2221 queue
->gsvs_ring_size
= gsvs_ring_size
;
2224 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2225 queue
->tess_rings_bo
= tess_rings_bo
;
2226 queue
->has_tess_rings
= true;
2229 if (descriptor_bo
!= queue
->descriptor_bo
) {
2230 if (queue
->descriptor_bo
)
2231 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2233 queue
->descriptor_bo
= descriptor_bo
;
2236 if (add_sample_positions
)
2237 queue
->has_sample_positions
= true;
2239 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2240 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2241 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2242 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2243 *continue_preamble_cs
= NULL
;
2246 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2248 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2249 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2250 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2251 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2252 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2253 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2254 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2255 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2256 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2257 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2258 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2259 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2260 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2261 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2264 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2266 const VkSemaphore
*sems
,
2270 int syncobj_idx
= 0, sem_idx
= 0;
2272 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2275 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2276 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2278 if (sem
->temp_syncobj
|| sem
->syncobj
)
2279 counts
->syncobj_count
++;
2281 counts
->sem_count
++;
2284 if (_fence
!= VK_NULL_HANDLE
) {
2285 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2286 if (fence
->temp_syncobj
|| fence
->syncobj
)
2287 counts
->syncobj_count
++;
2290 if (counts
->syncobj_count
) {
2291 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2292 if (!counts
->syncobj
)
2293 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2296 if (counts
->sem_count
) {
2297 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2299 free(counts
->syncobj
);
2300 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2304 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2305 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2307 if (sem
->temp_syncobj
) {
2308 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2310 else if (sem
->syncobj
)
2311 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2314 counts
->sem
[sem_idx
++] = sem
->sem
;
2318 if (_fence
!= VK_NULL_HANDLE
) {
2319 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2320 if (fence
->temp_syncobj
)
2321 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2322 else if (fence
->syncobj
)
2323 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2329 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2331 free(sem_info
->wait
.syncobj
);
2332 free(sem_info
->wait
.sem
);
2333 free(sem_info
->signal
.syncobj
);
2334 free(sem_info
->signal
.sem
);
2338 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2340 const VkSemaphore
*sems
)
2342 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2343 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2345 if (sem
->temp_syncobj
) {
2346 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2347 sem
->temp_syncobj
= 0;
2352 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2354 const VkSemaphore
*wait_sems
,
2355 int num_signal_sems
,
2356 const VkSemaphore
*signal_sems
,
2360 memset(sem_info
, 0, sizeof(*sem_info
));
2362 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2365 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2367 radv_free_sem_info(sem_info
);
2369 /* caller can override these */
2370 sem_info
->cs_emit_wait
= true;
2371 sem_info
->cs_emit_signal
= true;
2375 /* Signals fence as soon as all the work currently put on queue is done. */
2376 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2377 struct radv_fence
*fence
)
2381 struct radv_winsys_sem_info sem_info
;
2383 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2384 radv_fence_to_handle(fence
));
2385 if (result
!= VK_SUCCESS
)
2388 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2389 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2390 1, NULL
, NULL
, &sem_info
, NULL
,
2391 false, fence
->fence
);
2392 radv_free_sem_info(&sem_info
);
2394 /* TODO: find a better error */
2396 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2401 VkResult
radv_QueueSubmit(
2403 uint32_t submitCount
,
2404 const VkSubmitInfo
* pSubmits
,
2407 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2408 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2409 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2410 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2412 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2413 uint32_t scratch_size
= 0;
2414 uint32_t compute_scratch_size
= 0;
2415 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2416 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2418 bool fence_emitted
= false;
2419 bool tess_rings_needed
= false;
2420 bool sample_positions_needed
= false;
2422 /* Do this first so failing to allocate scratch buffers can't result in
2423 * partially executed submissions. */
2424 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2425 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2426 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2427 pSubmits
[i
].pCommandBuffers
[j
]);
2429 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2430 compute_scratch_size
= MAX2(compute_scratch_size
,
2431 cmd_buffer
->compute_scratch_size_needed
);
2432 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2433 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2434 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2435 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2439 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2440 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2441 sample_positions_needed
, &initial_flush_preamble_cs
,
2442 &initial_preamble_cs
, &continue_preamble_cs
);
2443 if (result
!= VK_SUCCESS
)
2446 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2447 struct radeon_winsys_cs
**cs_array
;
2448 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2449 bool can_patch
= true;
2451 struct radv_winsys_sem_info sem_info
;
2453 result
= radv_alloc_sem_info(&sem_info
,
2454 pSubmits
[i
].waitSemaphoreCount
,
2455 pSubmits
[i
].pWaitSemaphores
,
2456 pSubmits
[i
].signalSemaphoreCount
,
2457 pSubmits
[i
].pSignalSemaphores
,
2459 if (result
!= VK_SUCCESS
)
2462 if (!pSubmits
[i
].commandBufferCount
) {
2463 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2464 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2465 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2470 radv_loge("failed to submit CS %d\n", i
);
2473 fence_emitted
= true;
2475 radv_free_sem_info(&sem_info
);
2479 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2480 (pSubmits
[i
].commandBufferCount
));
2482 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2483 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2484 pSubmits
[i
].pCommandBuffers
[j
]);
2485 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2487 cs_array
[j
] = cmd_buffer
->cs
;
2488 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2491 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2494 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2495 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2496 advance
= MIN2(max_cs_submission
,
2497 pSubmits
[i
].commandBufferCount
- j
);
2499 if (queue
->device
->trace_bo
)
2500 *queue
->device
->trace_id_ptr
= 0;
2502 sem_info
.cs_emit_wait
= j
== 0;
2503 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2505 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2507 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2508 advance
, initial_preamble
, continue_preamble_cs
,
2509 &sem_info
, &queue
->device
->bo_list
.list
,
2510 can_patch
, base_fence
);
2512 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2515 radv_loge("failed to submit CS %d\n", i
);
2518 fence_emitted
= true;
2519 if (queue
->device
->trace_bo
) {
2520 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2524 radv_free_temp_syncobjs(queue
->device
,
2525 pSubmits
[i
].waitSemaphoreCount
,
2526 pSubmits
[i
].pWaitSemaphores
);
2527 radv_free_sem_info(&sem_info
);
2532 if (!fence_emitted
) {
2533 radv_signal_fence(queue
, fence
);
2535 fence
->submitted
= true;
2541 VkResult
radv_QueueWaitIdle(
2544 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2546 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2547 radv_queue_family_to_ring(queue
->queue_family_index
),
2552 VkResult
radv_DeviceWaitIdle(
2555 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2557 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2558 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2559 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2565 VkResult
radv_EnumerateInstanceExtensionProperties(
2566 const char* pLayerName
,
2567 uint32_t* pPropertyCount
,
2568 VkExtensionProperties
* pProperties
)
2570 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2572 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2573 if (radv_supported_instance_extensions
.extensions
[i
]) {
2574 vk_outarray_append(&out
, prop
) {
2575 *prop
= radv_instance_extensions
[i
];
2580 return vk_outarray_status(&out
);
2583 VkResult
radv_EnumerateDeviceExtensionProperties(
2584 VkPhysicalDevice physicalDevice
,
2585 const char* pLayerName
,
2586 uint32_t* pPropertyCount
,
2587 VkExtensionProperties
* pProperties
)
2589 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2590 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2592 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2593 if (device
->supported_extensions
.extensions
[i
]) {
2594 vk_outarray_append(&out
, prop
) {
2595 *prop
= radv_device_extensions
[i
];
2600 return vk_outarray_status(&out
);
2603 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2604 VkInstance _instance
,
2607 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2609 return radv_lookup_entrypoint_checked(pName
,
2610 instance
? instance
->apiVersion
: 0,
2611 instance
? &instance
->enabled_extensions
: NULL
,
2615 /* The loader wants us to expose a second GetInstanceProcAddr function
2616 * to work around certain LD_PRELOAD issues seen in apps.
2619 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2620 VkInstance instance
,
2624 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2625 VkInstance instance
,
2628 return radv_GetInstanceProcAddr(instance
, pName
);
2631 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2635 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2637 return radv_lookup_entrypoint_checked(pName
,
2638 device
->instance
->apiVersion
,
2639 &device
->instance
->enabled_extensions
,
2640 &device
->enabled_extensions
);
2643 bool radv_get_memory_fd(struct radv_device
*device
,
2644 struct radv_device_memory
*memory
,
2647 struct radeon_bo_metadata metadata
;
2649 if (memory
->image
) {
2650 radv_init_metadata(device
, memory
->image
, &metadata
);
2651 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2654 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2658 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2659 const VkMemoryAllocateInfo
* pAllocateInfo
,
2660 const VkAllocationCallbacks
* pAllocator
,
2661 VkDeviceMemory
* pMem
)
2663 struct radv_device_memory
*mem
;
2665 enum radeon_bo_domain domain
;
2667 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2669 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2671 if (pAllocateInfo
->allocationSize
== 0) {
2672 /* Apparently, this is allowed */
2673 *pMem
= VK_NULL_HANDLE
;
2677 const VkImportMemoryFdInfoKHR
*import_info
=
2678 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2679 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2680 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2681 const VkExportMemoryAllocateInfoKHR
*export_info
=
2682 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2683 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2684 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2686 const struct wsi_memory_allocate_info
*wsi_info
=
2687 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2689 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2690 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2692 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2694 if (wsi_info
&& wsi_info
->implicit_sync
)
2695 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2697 if (dedicate_info
) {
2698 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2699 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2705 mem
->user_ptr
= NULL
;
2708 assert(import_info
->handleType
==
2709 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2710 import_info
->handleType
==
2711 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2712 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2715 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2718 close(import_info
->fd
);
2720 } else if (host_ptr_info
) {
2721 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2722 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2723 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2724 pAllocateInfo
->allocationSize
);
2726 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2729 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2732 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2733 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2734 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2735 domain
= RADEON_DOMAIN_GTT
;
2737 domain
= RADEON_DOMAIN_VRAM
;
2739 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2740 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2742 flags
|= RADEON_FLAG_CPU_ACCESS
;
2744 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2745 flags
|= RADEON_FLAG_GTT_WC
;
2747 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2748 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2750 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2754 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2757 mem
->type_index
= mem_type_index
;
2760 result
= radv_bo_list_add(&device
->bo_list
, mem
->bo
);
2761 if (result
!= VK_SUCCESS
)
2764 *pMem
= radv_device_memory_to_handle(mem
);
2769 device
->ws
->buffer_destroy(mem
->bo
);
2771 vk_free2(&device
->alloc
, pAllocator
, mem
);
2776 VkResult
radv_AllocateMemory(
2778 const VkMemoryAllocateInfo
* pAllocateInfo
,
2779 const VkAllocationCallbacks
* pAllocator
,
2780 VkDeviceMemory
* pMem
)
2782 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2783 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2786 void radv_FreeMemory(
2788 VkDeviceMemory _mem
,
2789 const VkAllocationCallbacks
* pAllocator
)
2791 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2792 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2797 radv_bo_list_remove(&device
->bo_list
, mem
->bo
);
2798 device
->ws
->buffer_destroy(mem
->bo
);
2801 vk_free2(&device
->alloc
, pAllocator
, mem
);
2804 VkResult
radv_MapMemory(
2806 VkDeviceMemory _memory
,
2807 VkDeviceSize offset
,
2809 VkMemoryMapFlags flags
,
2812 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2813 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2821 *ppData
= mem
->user_ptr
;
2823 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2830 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2833 void radv_UnmapMemory(
2835 VkDeviceMemory _memory
)
2837 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2838 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2843 if (mem
->user_ptr
== NULL
)
2844 device
->ws
->buffer_unmap(mem
->bo
);
2847 VkResult
radv_FlushMappedMemoryRanges(
2849 uint32_t memoryRangeCount
,
2850 const VkMappedMemoryRange
* pMemoryRanges
)
2855 VkResult
radv_InvalidateMappedMemoryRanges(
2857 uint32_t memoryRangeCount
,
2858 const VkMappedMemoryRange
* pMemoryRanges
)
2863 void radv_GetBufferMemoryRequirements(
2866 VkMemoryRequirements
* pMemoryRequirements
)
2868 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2869 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2871 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2873 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2874 pMemoryRequirements
->alignment
= 4096;
2876 pMemoryRequirements
->alignment
= 16;
2878 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2881 void radv_GetBufferMemoryRequirements2(
2883 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2884 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2886 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2887 &pMemoryRequirements
->memoryRequirements
);
2888 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2889 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2890 switch (ext
->sType
) {
2891 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2892 VkMemoryDedicatedRequirementsKHR
*req
=
2893 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2894 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2895 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2904 void radv_GetImageMemoryRequirements(
2907 VkMemoryRequirements
* pMemoryRequirements
)
2909 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2910 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2912 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2914 pMemoryRequirements
->size
= image
->size
;
2915 pMemoryRequirements
->alignment
= image
->alignment
;
2918 void radv_GetImageMemoryRequirements2(
2920 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2921 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2923 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2924 &pMemoryRequirements
->memoryRequirements
);
2926 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2928 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2929 switch (ext
->sType
) {
2930 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2931 VkMemoryDedicatedRequirementsKHR
*req
=
2932 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2933 req
->requiresDedicatedAllocation
= image
->shareable
;
2934 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2943 void radv_GetImageSparseMemoryRequirements(
2946 uint32_t* pSparseMemoryRequirementCount
,
2947 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2952 void radv_GetImageSparseMemoryRequirements2(
2954 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2955 uint32_t* pSparseMemoryRequirementCount
,
2956 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2961 void radv_GetDeviceMemoryCommitment(
2963 VkDeviceMemory memory
,
2964 VkDeviceSize
* pCommittedMemoryInBytes
)
2966 *pCommittedMemoryInBytes
= 0;
2969 VkResult
radv_BindBufferMemory2(VkDevice device
,
2970 uint32_t bindInfoCount
,
2971 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2973 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2974 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2975 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2978 buffer
->bo
= mem
->bo
;
2979 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2987 VkResult
radv_BindBufferMemory(
2990 VkDeviceMemory memory
,
2991 VkDeviceSize memoryOffset
)
2993 const VkBindBufferMemoryInfoKHR info
= {
2994 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2997 .memoryOffset
= memoryOffset
3000 return radv_BindBufferMemory2(device
, 1, &info
);
3003 VkResult
radv_BindImageMemory2(VkDevice device
,
3004 uint32_t bindInfoCount
,
3005 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3007 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3008 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3009 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3012 image
->bo
= mem
->bo
;
3013 image
->offset
= pBindInfos
[i
].memoryOffset
;
3023 VkResult
radv_BindImageMemory(
3026 VkDeviceMemory memory
,
3027 VkDeviceSize memoryOffset
)
3029 const VkBindImageMemoryInfoKHR info
= {
3030 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3033 .memoryOffset
= memoryOffset
3036 return radv_BindImageMemory2(device
, 1, &info
);
3041 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3042 const VkSparseBufferMemoryBindInfo
*bind
)
3044 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3046 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3047 struct radv_device_memory
*mem
= NULL
;
3049 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3050 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3052 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3053 bind
->pBinds
[i
].resourceOffset
,
3054 bind
->pBinds
[i
].size
,
3055 mem
? mem
->bo
: NULL
,
3056 bind
->pBinds
[i
].memoryOffset
);
3061 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3062 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3064 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3066 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3067 struct radv_device_memory
*mem
= NULL
;
3069 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3070 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3072 device
->ws
->buffer_virtual_bind(image
->bo
,
3073 bind
->pBinds
[i
].resourceOffset
,
3074 bind
->pBinds
[i
].size
,
3075 mem
? mem
->bo
: NULL
,
3076 bind
->pBinds
[i
].memoryOffset
);
3080 VkResult
radv_QueueBindSparse(
3082 uint32_t bindInfoCount
,
3083 const VkBindSparseInfo
* pBindInfo
,
3086 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3087 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3088 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3089 bool fence_emitted
= false;
3091 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3092 struct radv_winsys_sem_info sem_info
;
3093 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3094 radv_sparse_buffer_bind_memory(queue
->device
,
3095 pBindInfo
[i
].pBufferBinds
+ j
);
3098 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3099 radv_sparse_image_opaque_bind_memory(queue
->device
,
3100 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3104 result
= radv_alloc_sem_info(&sem_info
,
3105 pBindInfo
[i
].waitSemaphoreCount
,
3106 pBindInfo
[i
].pWaitSemaphores
,
3107 pBindInfo
[i
].signalSemaphoreCount
,
3108 pBindInfo
[i
].pSignalSemaphores
,
3110 if (result
!= VK_SUCCESS
)
3113 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3114 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3115 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3119 fence_emitted
= true;
3121 fence
->submitted
= true;
3124 radv_free_sem_info(&sem_info
);
3129 if (!fence_emitted
) {
3130 radv_signal_fence(queue
, fence
);
3132 fence
->submitted
= true;
3138 VkResult
radv_CreateFence(
3140 const VkFenceCreateInfo
* pCreateInfo
,
3141 const VkAllocationCallbacks
* pAllocator
,
3144 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3145 const VkExportFenceCreateInfoKHR
*export
=
3146 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3147 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3148 export
? export
->handleTypes
: 0;
3150 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3152 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3155 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3157 fence
->submitted
= false;
3158 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3159 fence
->temp_syncobj
= 0;
3160 if (device
->always_use_syncobj
|| handleTypes
) {
3161 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3163 vk_free2(&device
->alloc
, pAllocator
, fence
);
3164 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3166 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3167 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3169 fence
->fence
= NULL
;
3171 fence
->fence
= device
->ws
->create_fence();
3172 if (!fence
->fence
) {
3173 vk_free2(&device
->alloc
, pAllocator
, fence
);
3174 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3179 *pFence
= radv_fence_to_handle(fence
);
3184 void radv_DestroyFence(
3187 const VkAllocationCallbacks
* pAllocator
)
3189 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3190 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3195 if (fence
->temp_syncobj
)
3196 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3198 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3200 device
->ws
->destroy_fence(fence
->fence
);
3201 vk_free2(&device
->alloc
, pAllocator
, fence
);
3205 static uint64_t radv_get_current_time()
3208 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3209 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3212 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3214 uint64_t current_time
= radv_get_current_time();
3216 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3218 return current_time
+ timeout
;
3222 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3224 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3225 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3226 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3232 VkResult
radv_WaitForFences(
3234 uint32_t fenceCount
,
3235 const VkFence
* pFences
,
3239 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3240 timeout
= radv_get_absolute_timeout(timeout
);
3242 if (device
->always_use_syncobj
) {
3243 uint32_t *handles
= malloc(sizeof(uint32_t) * 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
]);
3249 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3252 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3255 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3258 if (!waitAll
&& fenceCount
> 1) {
3259 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3260 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3261 uint32_t wait_count
= 0;
3262 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3264 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3266 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3267 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3269 if (fence
->signalled
) {
3274 fences
[wait_count
++] = fence
->fence
;
3277 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3278 waitAll
, timeout
- radv_get_current_time());
3281 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3284 while(radv_get_current_time() <= timeout
) {
3285 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3286 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3293 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3294 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3295 bool expired
= false;
3297 if (fence
->temp_syncobj
) {
3298 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3303 if (fence
->syncobj
) {
3304 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3309 if (fence
->signalled
)
3312 if (!fence
->submitted
) {
3313 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3316 if (!fence
->submitted
)
3319 /* Recheck as it may have been set by submitting operations. */
3320 if (fence
->signalled
)
3324 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3328 fence
->signalled
= true;
3334 VkResult
radv_ResetFences(VkDevice _device
,
3335 uint32_t fenceCount
,
3336 const VkFence
*pFences
)
3338 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3340 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3341 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3342 fence
->submitted
= fence
->signalled
= false;
3344 /* Per spec, we first restore the permanent payload, and then reset, so
3345 * having a temp syncobj should not skip resetting the permanent syncobj. */
3346 if (fence
->temp_syncobj
) {
3347 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3348 fence
->temp_syncobj
= 0;
3351 if (fence
->syncobj
) {
3352 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3359 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3361 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3362 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3364 if (fence
->temp_syncobj
) {
3365 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3366 return success
? VK_SUCCESS
: VK_NOT_READY
;
3369 if (fence
->syncobj
) {
3370 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3371 return success
? VK_SUCCESS
: VK_NOT_READY
;
3374 if (fence
->signalled
)
3376 if (!fence
->submitted
)
3377 return VK_NOT_READY
;
3378 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3379 return VK_NOT_READY
;
3385 // Queue semaphore functions
3387 VkResult
radv_CreateSemaphore(
3389 const VkSemaphoreCreateInfo
* pCreateInfo
,
3390 const VkAllocationCallbacks
* pAllocator
,
3391 VkSemaphore
* pSemaphore
)
3393 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3394 const VkExportSemaphoreCreateInfoKHR
*export
=
3395 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3396 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3397 export
? export
->handleTypes
: 0;
3399 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3401 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3403 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3405 sem
->temp_syncobj
= 0;
3406 /* create a syncobject if we are going to export this semaphore */
3407 if (device
->always_use_syncobj
|| handleTypes
) {
3408 assert (device
->physical_device
->rad_info
.has_syncobj
);
3409 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3411 vk_free2(&device
->alloc
, pAllocator
, sem
);
3412 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3416 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3418 vk_free2(&device
->alloc
, pAllocator
, sem
);
3419 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3424 *pSemaphore
= radv_semaphore_to_handle(sem
);
3428 void radv_DestroySemaphore(
3430 VkSemaphore _semaphore
,
3431 const VkAllocationCallbacks
* pAllocator
)
3433 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3434 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3439 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3441 device
->ws
->destroy_sem(sem
->sem
);
3442 vk_free2(&device
->alloc
, pAllocator
, sem
);
3445 VkResult
radv_CreateEvent(
3447 const VkEventCreateInfo
* pCreateInfo
,
3448 const VkAllocationCallbacks
* pAllocator
,
3451 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3452 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3454 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3457 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3459 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3461 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3463 vk_free2(&device
->alloc
, pAllocator
, event
);
3464 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3467 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3469 *pEvent
= radv_event_to_handle(event
);
3474 void radv_DestroyEvent(
3477 const VkAllocationCallbacks
* pAllocator
)
3479 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3480 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3484 device
->ws
->buffer_destroy(event
->bo
);
3485 vk_free2(&device
->alloc
, pAllocator
, event
);
3488 VkResult
radv_GetEventStatus(
3492 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3494 if (*event
->map
== 1)
3495 return VK_EVENT_SET
;
3496 return VK_EVENT_RESET
;
3499 VkResult
radv_SetEvent(
3503 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3509 VkResult
radv_ResetEvent(
3513 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3519 VkResult
radv_CreateBuffer(
3521 const VkBufferCreateInfo
* pCreateInfo
,
3522 const VkAllocationCallbacks
* pAllocator
,
3525 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3526 struct radv_buffer
*buffer
;
3528 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3530 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3531 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3533 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3535 buffer
->size
= pCreateInfo
->size
;
3536 buffer
->usage
= pCreateInfo
->usage
;
3539 buffer
->flags
= pCreateInfo
->flags
;
3541 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3542 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3544 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3545 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3546 align64(buffer
->size
, 4096),
3547 4096, 0, RADEON_FLAG_VIRTUAL
);
3549 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3550 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3554 *pBuffer
= radv_buffer_to_handle(buffer
);
3559 void radv_DestroyBuffer(
3562 const VkAllocationCallbacks
* pAllocator
)
3564 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3565 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3570 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3571 device
->ws
->buffer_destroy(buffer
->bo
);
3573 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3576 static inline unsigned
3577 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3580 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3582 return image
->surface
.u
.legacy
.tiling_index
[level
];
3585 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3587 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3591 radv_init_dcc_control_reg(struct radv_device
*device
,
3592 struct radv_image_view
*iview
)
3594 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3595 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3596 unsigned max_compressed_block_size
;
3597 unsigned independent_64b_blocks
;
3599 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3602 if (iview
->image
->info
.samples
> 1) {
3603 if (iview
->image
->surface
.bpe
== 1)
3604 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3605 else if (iview
->image
->surface
.bpe
== 2)
3606 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3609 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3610 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3611 * dGPU and 64 for APU because all of our APUs to date use
3612 * DIMMs which have a request granularity size of 64B while all
3613 * other chips have a 32B request size.
3615 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3618 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3619 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3620 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3621 /* If this DCC image is potentially going to be used in texture
3622 * fetches, we need some special settings.
3624 independent_64b_blocks
= 1;
3625 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3627 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3628 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3629 * big as possible for better compression state.
3631 independent_64b_blocks
= 0;
3632 max_compressed_block_size
= max_uncompressed_block_size
;
3635 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3636 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3637 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3638 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3642 radv_initialise_color_surface(struct radv_device
*device
,
3643 struct radv_color_buffer_info
*cb
,
3644 struct radv_image_view
*iview
)
3646 const struct vk_format_description
*desc
;
3647 unsigned ntype
, format
, swap
, endian
;
3648 unsigned blend_clamp
= 0, blend_bypass
= 0;
3650 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3652 desc
= vk_format_description(iview
->vk_format
);
3654 memset(cb
, 0, sizeof(*cb
));
3656 /* Intensity is implemented as Red, so treat it that way. */
3657 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3659 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3661 cb
->cb_color_base
= va
>> 8;
3663 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3664 struct gfx9_surf_meta_flags meta
;
3665 if (iview
->image
->dcc_offset
)
3666 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3668 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3670 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3671 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3672 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3673 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3675 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3676 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3678 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3679 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3681 cb
->cb_color_base
+= level_info
->offset
>> 8;
3682 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3683 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3685 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3686 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3687 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3689 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3690 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3691 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3693 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3695 if (radv_image_has_fmask(iview
->image
)) {
3696 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3697 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3698 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3699 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3701 /* This must be set for fast clear to work without FMASK. */
3702 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3703 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3704 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3705 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3709 /* CMASK variables */
3710 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3711 va
+= iview
->image
->cmask
.offset
;
3712 cb
->cb_color_cmask
= va
>> 8;
3714 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3715 va
+= iview
->image
->dcc_offset
;
3716 cb
->cb_dcc_base
= va
>> 8;
3717 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3719 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3720 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3721 S_028C6C_SLICE_MAX(max_slice
);
3723 if (iview
->image
->info
.samples
> 1) {
3724 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3726 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3727 S_028C74_NUM_FRAGMENTS(log_samples
);
3730 if (radv_image_has_fmask(iview
->image
)) {
3731 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3732 cb
->cb_color_fmask
= va
>> 8;
3733 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3735 cb
->cb_color_fmask
= cb
->cb_color_base
;
3738 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3740 vk_format_get_first_non_void_channel(iview
->vk_format
));
3741 format
= radv_translate_colorformat(iview
->vk_format
);
3742 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3743 radv_finishme("Illegal color\n");
3744 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3745 endian
= radv_colorformat_endian_swap(format
);
3747 /* blend clamp should be set for all NORM/SRGB types */
3748 if (ntype
== V_028C70_NUMBER_UNORM
||
3749 ntype
== V_028C70_NUMBER_SNORM
||
3750 ntype
== V_028C70_NUMBER_SRGB
)
3753 /* set blend bypass according to docs if SINT/UINT or
3754 8/24 COLOR variants */
3755 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3756 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3757 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3762 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3763 (format
== V_028C70_COLOR_8
||
3764 format
== V_028C70_COLOR_8_8
||
3765 format
== V_028C70_COLOR_8_8_8_8
))
3766 ->color_is_int8
= true;
3768 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3769 S_028C70_COMP_SWAP(swap
) |
3770 S_028C70_BLEND_CLAMP(blend_clamp
) |
3771 S_028C70_BLEND_BYPASS(blend_bypass
) |
3772 S_028C70_SIMPLE_FLOAT(1) |
3773 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3774 ntype
!= V_028C70_NUMBER_SNORM
&&
3775 ntype
!= V_028C70_NUMBER_SRGB
&&
3776 format
!= V_028C70_COLOR_8_24
&&
3777 format
!= V_028C70_COLOR_24_8
) |
3778 S_028C70_NUMBER_TYPE(ntype
) |
3779 S_028C70_ENDIAN(endian
);
3780 if (radv_image_has_fmask(iview
->image
)) {
3781 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3782 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3783 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3784 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3788 if (radv_image_has_cmask(iview
->image
) &&
3789 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3790 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3792 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3793 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3795 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3797 /* This must be set for fast clear to work without FMASK. */
3798 if (!radv_image_has_fmask(iview
->image
) &&
3799 device
->physical_device
->rad_info
.chip_class
== SI
) {
3800 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3801 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3804 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3805 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3806 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3808 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3809 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3810 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3811 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3812 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3813 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3818 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3819 struct radv_image_view
*iview
)
3821 unsigned max_zplanes
= 0;
3823 assert(radv_image_is_tc_compat_htile(iview
->image
));
3825 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3826 /* Default value for 32-bit depth surfaces. */
3829 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3830 iview
->image
->info
.samples
> 1)
3833 max_zplanes
= max_zplanes
+ 1;
3835 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3836 /* Do not enable Z plane compression for 16-bit depth
3837 * surfaces because isn't supported on GFX8. Only
3838 * 32-bit depth surfaces are supported by the hardware.
3839 * This allows to maintain shader compatibility and to
3840 * reduce the number of depth decompressions.
3844 if (iview
->image
->info
.samples
<= 1)
3846 else if (iview
->image
->info
.samples
<= 4)
3857 radv_initialise_ds_surface(struct radv_device
*device
,
3858 struct radv_ds_buffer_info
*ds
,
3859 struct radv_image_view
*iview
)
3861 unsigned level
= iview
->base_mip
;
3862 unsigned format
, stencil_format
;
3863 uint64_t va
, s_offs
, z_offs
;
3864 bool stencil_only
= false;
3865 memset(ds
, 0, sizeof(*ds
));
3866 switch (iview
->image
->vk_format
) {
3867 case VK_FORMAT_D24_UNORM_S8_UINT
:
3868 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3869 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3870 ds
->offset_scale
= 2.0f
;
3872 case VK_FORMAT_D16_UNORM
:
3873 case VK_FORMAT_D16_UNORM_S8_UINT
:
3874 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3875 ds
->offset_scale
= 4.0f
;
3877 case VK_FORMAT_D32_SFLOAT
:
3878 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3879 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3880 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3881 ds
->offset_scale
= 1.0f
;
3883 case VK_FORMAT_S8_UINT
:
3884 stencil_only
= true;
3890 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3891 stencil_format
= iview
->image
->surface
.has_stencil
?
3892 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3894 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3895 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3896 S_028008_SLICE_MAX(max_slice
);
3898 ds
->db_htile_data_base
= 0;
3899 ds
->db_htile_surface
= 0;
3901 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3902 s_offs
= z_offs
= va
;
3904 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3905 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3906 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3908 ds
->db_z_info
= S_028038_FORMAT(format
) |
3909 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3910 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3911 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3912 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3913 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3915 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3916 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3917 ds
->db_depth_view
|= S_028008_MIPID(level
);
3919 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3920 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3922 if (radv_htile_enabled(iview
->image
, level
)) {
3923 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3925 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3926 unsigned max_zplanes
=
3927 radv_calc_decompress_on_z_planes(device
, iview
);
3929 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3930 S_028038_ITERATE_FLUSH(1);
3931 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3934 if (!iview
->image
->surface
.has_stencil
)
3935 /* Use all of the htile_buffer for depth if there's no stencil. */
3936 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3937 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3938 iview
->image
->htile_offset
;
3939 ds
->db_htile_data_base
= va
>> 8;
3940 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3941 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3942 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3945 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3948 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3950 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3951 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3953 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3954 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3955 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3957 if (iview
->image
->info
.samples
> 1)
3958 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3960 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3961 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3962 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3963 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3964 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3965 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3966 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3967 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3970 tile_mode
= stencil_tile_mode
;
3972 ds
->db_depth_info
|=
3973 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3974 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3975 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3976 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3977 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3978 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3979 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3980 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3982 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3983 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3984 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3985 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3987 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3990 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3991 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3992 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3994 if (radv_htile_enabled(iview
->image
, level
)) {
3995 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3997 if (!iview
->image
->surface
.has_stencil
&&
3998 !radv_image_is_tc_compat_htile(iview
->image
))
3999 /* Use all of the htile_buffer for depth if there's no stencil. */
4000 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4002 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4003 iview
->image
->htile_offset
;
4004 ds
->db_htile_data_base
= va
>> 8;
4005 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4007 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4008 unsigned max_zplanes
=
4009 radv_calc_decompress_on_z_planes(device
, iview
);
4011 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4012 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4017 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4018 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4021 VkResult
radv_CreateFramebuffer(
4023 const VkFramebufferCreateInfo
* pCreateInfo
,
4024 const VkAllocationCallbacks
* pAllocator
,
4025 VkFramebuffer
* pFramebuffer
)
4027 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4028 struct radv_framebuffer
*framebuffer
;
4030 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4032 size_t size
= sizeof(*framebuffer
) +
4033 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4034 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4035 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4036 if (framebuffer
== NULL
)
4037 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4039 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4040 framebuffer
->width
= pCreateInfo
->width
;
4041 framebuffer
->height
= pCreateInfo
->height
;
4042 framebuffer
->layers
= pCreateInfo
->layers
;
4043 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4044 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4045 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4046 framebuffer
->attachments
[i
].attachment
= iview
;
4047 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4048 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4049 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4050 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4052 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4053 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4054 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4057 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4061 void radv_DestroyFramebuffer(
4064 const VkAllocationCallbacks
* pAllocator
)
4066 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4067 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4071 vk_free2(&device
->alloc
, pAllocator
, fb
);
4074 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4076 switch (address_mode
) {
4077 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4078 return V_008F30_SQ_TEX_WRAP
;
4079 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4080 return V_008F30_SQ_TEX_MIRROR
;
4081 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4082 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4083 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4084 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4085 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4086 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4088 unreachable("illegal tex wrap mode");
4094 radv_tex_compare(VkCompareOp op
)
4097 case VK_COMPARE_OP_NEVER
:
4098 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4099 case VK_COMPARE_OP_LESS
:
4100 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4101 case VK_COMPARE_OP_EQUAL
:
4102 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4103 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4104 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4105 case VK_COMPARE_OP_GREATER
:
4106 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4107 case VK_COMPARE_OP_NOT_EQUAL
:
4108 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4109 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4110 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4111 case VK_COMPARE_OP_ALWAYS
:
4112 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4114 unreachable("illegal compare mode");
4120 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4123 case VK_FILTER_NEAREST
:
4124 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4125 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4126 case VK_FILTER_LINEAR
:
4127 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4128 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4129 case VK_FILTER_CUBIC_IMG
:
4131 fprintf(stderr
, "illegal texture filter");
4137 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4140 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4141 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4142 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4143 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4145 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4150 radv_tex_bordercolor(VkBorderColor bcolor
)
4153 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4154 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4155 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4156 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4157 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4158 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4159 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4160 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4161 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4169 radv_tex_aniso_filter(unsigned filter
)
4183 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4186 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4187 return SQ_IMG_FILTER_MODE_BLEND
;
4188 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4189 return SQ_IMG_FILTER_MODE_MIN
;
4190 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4191 return SQ_IMG_FILTER_MODE_MAX
;
4199 radv_init_sampler(struct radv_device
*device
,
4200 struct radv_sampler
*sampler
,
4201 const VkSamplerCreateInfo
*pCreateInfo
)
4203 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4204 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4205 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4206 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4207 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4209 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4210 vk_find_struct_const(pCreateInfo
->pNext
,
4211 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4212 if (sampler_reduction
)
4213 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4215 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4216 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4217 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4218 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4219 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4220 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4221 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4222 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4223 S_008F30_DISABLE_CUBE_WRAP(0) |
4224 S_008F30_COMPAT_MODE(is_vi
) |
4225 S_008F30_FILTER_MODE(filter_mode
));
4226 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4227 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4228 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4229 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4230 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4231 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4232 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4233 S_008F38_MIP_POINT_PRECLAMP(0) |
4234 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4235 S_008F38_FILTER_PREC_FIX(1) |
4236 S_008F38_ANISO_OVERRIDE(is_vi
));
4237 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4238 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4241 VkResult
radv_CreateSampler(
4243 const VkSamplerCreateInfo
* pCreateInfo
,
4244 const VkAllocationCallbacks
* pAllocator
,
4245 VkSampler
* pSampler
)
4247 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4248 struct radv_sampler
*sampler
;
4250 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4252 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4253 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4255 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4257 radv_init_sampler(device
, sampler
, pCreateInfo
);
4258 *pSampler
= radv_sampler_to_handle(sampler
);
4263 void radv_DestroySampler(
4266 const VkAllocationCallbacks
* pAllocator
)
4268 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4269 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4273 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4276 /* vk_icd.h does not declare this function, so we declare it here to
4277 * suppress Wmissing-prototypes.
4279 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4280 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4282 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4283 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4285 /* For the full details on loader interface versioning, see
4286 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4287 * What follows is a condensed summary, to help you navigate the large and
4288 * confusing official doc.
4290 * - Loader interface v0 is incompatible with later versions. We don't
4293 * - In loader interface v1:
4294 * - The first ICD entrypoint called by the loader is
4295 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4297 * - The ICD must statically expose no other Vulkan symbol unless it is
4298 * linked with -Bsymbolic.
4299 * - Each dispatchable Vulkan handle created by the ICD must be
4300 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4301 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4302 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4303 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4304 * such loader-managed surfaces.
4306 * - Loader interface v2 differs from v1 in:
4307 * - The first ICD entrypoint called by the loader is
4308 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4309 * statically expose this entrypoint.
4311 * - Loader interface v3 differs from v2 in:
4312 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4313 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4314 * because the loader no longer does so.
4316 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4320 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4321 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4324 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4325 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4327 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4329 /* At the moment, we support only the below handle types. */
4330 assert(pGetFdInfo
->handleType
==
4331 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4332 pGetFdInfo
->handleType
==
4333 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4335 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4337 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4341 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4342 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4344 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4346 switch (handleType
) {
4347 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4348 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4352 /* The valid usage section for this function says:
4354 * "handleType must not be one of the handle types defined as
4357 * So opaque handle types fall into the default "unsupported" case.
4359 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4363 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4367 uint32_t syncobj_handle
= 0;
4368 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4370 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4373 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4375 *syncobj
= syncobj_handle
;
4381 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4385 /* If we create a syncobj we do it locally so that if we have an error, we don't
4386 * leave a syncobj in an undetermined state in the fence. */
4387 uint32_t syncobj_handle
= *syncobj
;
4388 if (!syncobj_handle
) {
4389 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4391 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4396 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4398 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4400 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4403 *syncobj
= syncobj_handle
;
4410 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4411 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4413 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4414 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4415 uint32_t *syncobj_dst
= NULL
;
4417 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4418 syncobj_dst
= &sem
->temp_syncobj
;
4420 syncobj_dst
= &sem
->syncobj
;
4423 switch(pImportSemaphoreFdInfo
->handleType
) {
4424 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4425 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4426 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4427 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4429 unreachable("Unhandled semaphore handle type");
4433 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4434 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4437 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4438 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4440 uint32_t syncobj_handle
;
4442 if (sem
->temp_syncobj
)
4443 syncobj_handle
= sem
->temp_syncobj
;
4445 syncobj_handle
= sem
->syncobj
;
4447 switch(pGetFdInfo
->handleType
) {
4448 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4449 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4451 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4452 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4454 if (sem
->temp_syncobj
) {
4455 close (sem
->temp_syncobj
);
4456 sem
->temp_syncobj
= 0;
4458 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4463 unreachable("Unhandled semaphore handle type");
4467 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4471 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4472 VkPhysicalDevice physicalDevice
,
4473 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4474 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4476 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4478 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4479 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4480 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4481 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4482 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4483 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4484 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4485 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4486 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4487 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4488 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4489 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4490 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4492 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4493 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4494 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4498 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4499 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4501 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4502 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4503 uint32_t *syncobj_dst
= NULL
;
4506 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4507 syncobj_dst
= &fence
->temp_syncobj
;
4509 syncobj_dst
= &fence
->syncobj
;
4512 switch(pImportFenceFdInfo
->handleType
) {
4513 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4514 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4515 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4516 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4518 unreachable("Unhandled fence handle type");
4522 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4523 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4526 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4527 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4529 uint32_t syncobj_handle
;
4531 if (fence
->temp_syncobj
)
4532 syncobj_handle
= fence
->temp_syncobj
;
4534 syncobj_handle
= fence
->syncobj
;
4536 switch(pGetFdInfo
->handleType
) {
4537 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4538 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4540 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4541 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4543 if (fence
->temp_syncobj
) {
4544 close (fence
->temp_syncobj
);
4545 fence
->temp_syncobj
= 0;
4547 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4552 unreachable("Unhandled fence handle type");
4556 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4560 void radv_GetPhysicalDeviceExternalFenceProperties(
4561 VkPhysicalDevice physicalDevice
,
4562 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4563 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4565 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4567 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4568 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4569 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4570 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4571 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4572 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4573 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4575 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4576 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4577 pExternalFenceProperties
->externalFenceFeatures
= 0;
4582 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4583 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4584 const VkAllocationCallbacks
* pAllocator
,
4585 VkDebugReportCallbackEXT
* pCallback
)
4587 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4588 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4589 pCreateInfo
, pAllocator
, &instance
->alloc
,
4594 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4595 VkDebugReportCallbackEXT _callback
,
4596 const VkAllocationCallbacks
* pAllocator
)
4598 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4599 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4600 _callback
, pAllocator
, &instance
->alloc
);
4604 radv_DebugReportMessageEXT(VkInstance _instance
,
4605 VkDebugReportFlagsEXT flags
,
4606 VkDebugReportObjectTypeEXT objectType
,
4609 int32_t messageCode
,
4610 const char* pLayerPrefix
,
4611 const char* pMessage
)
4613 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4614 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4615 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4619 radv_GetDeviceGroupPeerMemoryFeatures(
4622 uint32_t localDeviceIndex
,
4623 uint32_t remoteDeviceIndex
,
4624 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4626 assert(localDeviceIndex
== remoteDeviceIndex
);
4628 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4629 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4630 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4631 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;