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"
48 #include "util/build_id.h"
49 #include "util/debug.h"
50 #include "util/mesa-sha1.h"
53 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
56 unsigned char sha1
[20];
57 unsigned ptr_size
= sizeof(void*);
59 memset(uuid
, 0, VK_UUID_SIZE
);
60 _mesa_sha1_init(&ctx
);
62 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
63 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
66 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
67 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
68 _mesa_sha1_final(&ctx
, sha1
);
70 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
75 radv_get_driver_uuid(void *uuid
)
77 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
81 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
83 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
87 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
89 const char *chip_string
;
92 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
93 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
94 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
95 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
96 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
97 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
98 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
99 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
100 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
101 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
102 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
103 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
104 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
105 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
106 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
107 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
108 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
109 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
110 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
111 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
112 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
113 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
114 case CHIP_RAVEN2
: chip_string
= "AMD RADV RAVEN2"; break;
115 default: chip_string
= "AMD RADV unknown"; break;
118 snprintf(name
, name_len
, "%s (LLVM " MESA_LLVM_VERSION_STRING
")", chip_string
);
122 radv_get_visible_vram_size(struct radv_physical_device
*device
)
124 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
128 radv_get_vram_size(struct radv_physical_device
*device
)
130 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
134 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
136 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
137 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
138 uint64_t vram_size
= radv_get_vram_size(device
);
139 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
140 device
->memory_properties
.memoryHeapCount
= 0;
142 vram_index
= device
->memory_properties
.memoryHeapCount
++;
143 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
145 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
148 if (visible_vram_size
) {
149 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
150 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
151 .size
= visible_vram_size
,
152 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
155 if (device
->rad_info
.gart_size
> 0) {
156 gart_index
= device
->memory_properties
.memoryHeapCount
++;
157 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
158 .size
= device
->rad_info
.gart_size
,
159 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
163 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
164 unsigned type_count
= 0;
165 if (vram_index
>= 0) {
166 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
167 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
168 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
169 .heapIndex
= vram_index
,
172 if (gart_index
>= 0) {
173 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
174 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
175 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
176 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
177 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
178 .heapIndex
= gart_index
,
181 if (visible_vram_index
>= 0) {
182 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
183 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
184 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
185 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
186 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
187 .heapIndex
= visible_vram_index
,
190 if (gart_index
>= 0) {
191 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
192 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
193 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
194 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
195 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
196 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
197 .heapIndex
= gart_index
,
200 device
->memory_properties
.memoryTypeCount
= type_count
;
204 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
206 const char *family
= getenv("RADV_FORCE_FAMILY");
212 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
213 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
214 /* Override family and chip_class. */
215 device
->rad_info
.family
= i
;
217 if (i
>= CHIP_VEGA10
)
218 device
->rad_info
.chip_class
= GFX9
;
219 else if (i
>= CHIP_TONGA
)
220 device
->rad_info
.chip_class
= VI
;
221 else if (i
>= CHIP_BONAIRE
)
222 device
->rad_info
.chip_class
= CIK
;
224 device
->rad_info
.chip_class
= SI
;
230 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
235 radv_physical_device_init(struct radv_physical_device
*device
,
236 struct radv_instance
*instance
,
237 drmDevicePtr drm_device
)
239 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
241 drmVersionPtr version
;
245 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
247 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
248 radv_logi("Could not open device '%s'", path
);
250 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
253 version
= drmGetVersion(fd
);
257 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
258 radv_logi("Could not get the kernel driver version for device '%s'", path
);
260 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
261 "failed to get version %s: %m", path
);
264 if (strcmp(version
->name
, "amdgpu")) {
265 drmFreeVersion(version
);
268 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
269 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
271 return VK_ERROR_INCOMPATIBLE_DRIVER
;
273 drmFreeVersion(version
);
275 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
276 radv_logi("Found compatible device '%s'.", path
);
278 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
279 device
->instance
= instance
;
281 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
282 instance
->perftest_flags
);
284 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
288 if (instance
->enabled_extensions
.KHR_display
) {
289 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
290 if (master_fd
>= 0) {
291 uint32_t accel_working
= 0;
292 struct drm_amdgpu_info request
= {
293 .return_pointer
= (uintptr_t)&accel_working
,
294 .return_size
= sizeof(accel_working
),
295 .query
= AMDGPU_INFO_ACCEL_WORKING
298 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
305 device
->master_fd
= master_fd
;
306 device
->local_fd
= fd
;
307 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
309 radv_handle_env_var_force_family(device
);
311 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
313 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
314 device
->ws
->destroy(device
->ws
);
315 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
316 "cannot generate UUID");
320 /* These flags affect shader compilation. */
321 uint64_t shader_env_flags
=
322 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
323 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
325 /* The gpu id is already embedded in the uuid so we just pass "radv"
326 * when creating the cache.
328 char buf
[VK_UUID_SIZE
* 2 + 1];
329 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
330 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
332 if (device
->rad_info
.chip_class
< VI
||
333 device
->rad_info
.chip_class
> GFX9
)
334 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
336 radv_get_driver_uuid(&device
->driver_uuid
);
337 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
339 if (device
->rad_info
.family
== CHIP_STONEY
||
340 device
->rad_info
.chip_class
>= GFX9
) {
341 device
->has_rbplus
= true;
342 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
343 device
->rad_info
.family
== CHIP_VEGA12
||
344 device
->rad_info
.family
== CHIP_RAVEN
||
345 device
->rad_info
.family
== CHIP_RAVEN2
;
348 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
351 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
353 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
355 /* Vega10/Raven need a special workaround for a hardware bug. */
356 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
357 device
->rad_info
.family
== CHIP_RAVEN
;
359 /* Out-of-order primitive rasterization. */
360 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
361 device
->rad_info
.max_se
>= 2;
362 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
363 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
365 device
->dcc_msaa_allowed
=
366 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
368 /* TODO: Figure out how to use LOAD_CONTEXT_REG on SI/CIK. */
369 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
370 (device
->rad_info
.chip_class
>= VI
&&
371 device
->rad_info
.me_fw_feature
>= 41);
373 radv_physical_device_init_mem_types(device
);
374 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
376 device
->bus_info
= *drm_device
->businfo
.pci
;
378 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
379 ac_print_gpu_info(&device
->rad_info
);
381 /* The WSI is structured as a layer on top of the driver, so this has
382 * to be the last part of initialization (at least until we get other
385 result
= radv_init_wsi(device
);
386 if (result
!= VK_SUCCESS
) {
387 device
->ws
->destroy(device
->ws
);
388 vk_error(instance
, result
);
402 radv_physical_device_finish(struct radv_physical_device
*device
)
404 radv_finish_wsi(device
);
405 device
->ws
->destroy(device
->ws
);
406 disk_cache_destroy(device
->disk_cache
);
407 close(device
->local_fd
);
408 if (device
->master_fd
!= -1)
409 close(device
->master_fd
);
413 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
414 VkSystemAllocationScope allocationScope
)
420 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
421 size_t align
, VkSystemAllocationScope allocationScope
)
423 return realloc(pOriginal
, size
);
427 default_free_func(void *pUserData
, void *pMemory
)
432 static const VkAllocationCallbacks default_alloc
= {
434 .pfnAllocation
= default_alloc_func
,
435 .pfnReallocation
= default_realloc_func
,
436 .pfnFree
= default_free_func
,
439 static const struct debug_control radv_debug_options
[] = {
440 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
441 {"nodcc", RADV_DEBUG_NO_DCC
},
442 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
443 {"nocache", RADV_DEBUG_NO_CACHE
},
444 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
445 {"nohiz", RADV_DEBUG_NO_HIZ
},
446 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
447 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
448 {"allbos", RADV_DEBUG_ALL_BOS
},
449 {"noibs", RADV_DEBUG_NO_IBS
},
450 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
451 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
452 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
453 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
454 {"nosisched", RADV_DEBUG_NO_SISCHED
},
455 {"preoptir", RADV_DEBUG_PREOPTIR
},
456 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
457 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
458 {"info", RADV_DEBUG_INFO
},
459 {"errors", RADV_DEBUG_ERRORS
},
460 {"startup", RADV_DEBUG_STARTUP
},
461 {"checkir", RADV_DEBUG_CHECKIR
},
462 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
463 {"nobinning", RADV_DEBUG_NOBINNING
},
468 radv_get_debug_option_name(int id
)
470 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
471 return radv_debug_options
[id
].string
;
474 static const struct debug_control radv_perftest_options
[] = {
475 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
476 {"sisched", RADV_PERFTEST_SISCHED
},
477 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
478 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
483 radv_get_perftest_option_name(int id
)
485 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
486 return radv_perftest_options
[id
].string
;
490 radv_handle_per_app_options(struct radv_instance
*instance
,
491 const VkApplicationInfo
*info
)
493 const char *name
= info
? info
->pApplicationName
: NULL
;
498 if (!strcmp(name
, "Talos - Linux - 32bit") ||
499 !strcmp(name
, "Talos - Linux - 64bit")) {
500 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
501 /* Force enable LLVM sisched for Talos because it looks
502 * safe and it gives few more FPS.
504 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
506 } else if (!strcmp(name
, "DOOM_VFR")) {
507 /* Work around a Doom VFR game bug */
508 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
512 static int radv_get_instance_extension_index(const char *name
)
514 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
515 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
522 VkResult
radv_CreateInstance(
523 const VkInstanceCreateInfo
* pCreateInfo
,
524 const VkAllocationCallbacks
* pAllocator
,
525 VkInstance
* pInstance
)
527 struct radv_instance
*instance
;
530 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
532 uint32_t client_version
;
533 if (pCreateInfo
->pApplicationInfo
&&
534 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
535 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
537 client_version
= VK_API_VERSION_1_0
;
540 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
541 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
543 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
545 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
548 instance
->alloc
= *pAllocator
;
550 instance
->alloc
= default_alloc
;
552 instance
->apiVersion
= client_version
;
553 instance
->physicalDeviceCount
= -1;
555 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
558 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
559 radv_perftest_options
);
562 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
563 radv_logi("Created an instance");
565 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
566 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
567 int index
= radv_get_instance_extension_index(ext_name
);
569 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
570 vk_free2(&default_alloc
, pAllocator
, instance
);
571 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
574 instance
->enabled_extensions
.extensions
[index
] = true;
577 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
578 if (result
!= VK_SUCCESS
) {
579 vk_free2(&default_alloc
, pAllocator
, instance
);
580 return vk_error(instance
, result
);
585 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
587 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
589 *pInstance
= radv_instance_to_handle(instance
);
594 void radv_DestroyInstance(
595 VkInstance _instance
,
596 const VkAllocationCallbacks
* pAllocator
)
598 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
603 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
604 radv_physical_device_finish(instance
->physicalDevices
+ i
);
607 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
611 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
613 vk_free(&instance
->alloc
, instance
);
617 radv_enumerate_devices(struct radv_instance
*instance
)
619 /* TODO: Check for more devices ? */
620 drmDevicePtr devices
[8];
621 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
624 instance
->physicalDeviceCount
= 0;
626 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
628 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
629 radv_logi("Found %d drm nodes", max_devices
);
632 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
634 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
635 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
636 devices
[i
]->bustype
== DRM_BUS_PCI
&&
637 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
639 result
= radv_physical_device_init(instance
->physicalDevices
+
640 instance
->physicalDeviceCount
,
643 if (result
== VK_SUCCESS
)
644 ++instance
->physicalDeviceCount
;
645 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
649 drmFreeDevices(devices
, max_devices
);
654 VkResult
radv_EnumeratePhysicalDevices(
655 VkInstance _instance
,
656 uint32_t* pPhysicalDeviceCount
,
657 VkPhysicalDevice
* pPhysicalDevices
)
659 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
662 if (instance
->physicalDeviceCount
< 0) {
663 result
= radv_enumerate_devices(instance
);
664 if (result
!= VK_SUCCESS
&&
665 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
669 if (!pPhysicalDevices
) {
670 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
672 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
673 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
674 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
677 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
681 VkResult
radv_EnumeratePhysicalDeviceGroups(
682 VkInstance _instance
,
683 uint32_t* pPhysicalDeviceGroupCount
,
684 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
686 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
689 if (instance
->physicalDeviceCount
< 0) {
690 result
= radv_enumerate_devices(instance
);
691 if (result
!= VK_SUCCESS
&&
692 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
696 if (!pPhysicalDeviceGroupProperties
) {
697 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
699 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
700 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
701 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
702 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
703 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
706 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
710 void radv_GetPhysicalDeviceFeatures(
711 VkPhysicalDevice physicalDevice
,
712 VkPhysicalDeviceFeatures
* pFeatures
)
714 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
715 memset(pFeatures
, 0, sizeof(*pFeatures
));
717 *pFeatures
= (VkPhysicalDeviceFeatures
) {
718 .robustBufferAccess
= true,
719 .fullDrawIndexUint32
= true,
720 .imageCubeArray
= true,
721 .independentBlend
= true,
722 .geometryShader
= true,
723 .tessellationShader
= true,
724 .sampleRateShading
= true,
725 .dualSrcBlend
= true,
727 .multiDrawIndirect
= true,
728 .drawIndirectFirstInstance
= true,
730 .depthBiasClamp
= true,
731 .fillModeNonSolid
= true,
736 .multiViewport
= true,
737 .samplerAnisotropy
= true,
738 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
739 .textureCompressionASTC_LDR
= false,
740 .textureCompressionBC
= true,
741 .occlusionQueryPrecise
= true,
742 .pipelineStatisticsQuery
= true,
743 .vertexPipelineStoresAndAtomics
= true,
744 .fragmentStoresAndAtomics
= true,
745 .shaderTessellationAndGeometryPointSize
= true,
746 .shaderImageGatherExtended
= true,
747 .shaderStorageImageExtendedFormats
= true,
748 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= VI
,
749 .shaderUniformBufferArrayDynamicIndexing
= true,
750 .shaderSampledImageArrayDynamicIndexing
= true,
751 .shaderStorageBufferArrayDynamicIndexing
= true,
752 .shaderStorageImageArrayDynamicIndexing
= true,
753 .shaderStorageImageReadWithoutFormat
= true,
754 .shaderStorageImageWriteWithoutFormat
= true,
755 .shaderClipDistance
= true,
756 .shaderCullDistance
= true,
757 .shaderFloat64
= true,
759 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
760 .sparseBinding
= true,
761 .variableMultisampleRate
= true,
762 .inheritedQueries
= true,
766 void radv_GetPhysicalDeviceFeatures2(
767 VkPhysicalDevice physicalDevice
,
768 VkPhysicalDeviceFeatures2
*pFeatures
)
770 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
771 vk_foreach_struct(ext
, pFeatures
->pNext
) {
772 switch (ext
->sType
) {
773 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES
: {
774 VkPhysicalDeviceVariablePointerFeatures
*features
= (void *)ext
;
775 features
->variablePointersStorageBuffer
= true;
776 features
->variablePointers
= true;
779 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
780 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
781 features
->multiview
= true;
782 features
->multiviewGeometryShader
= true;
783 features
->multiviewTessellationShader
= true;
786 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
787 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
788 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
789 features
->shaderDrawParameters
= true;
792 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
793 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
794 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
795 features
->protectedMemory
= false;
798 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
799 VkPhysicalDevice16BitStorageFeatures
*features
=
800 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
801 bool enabled
= pdevice
->rad_info
.chip_class
>= VI
;
802 features
->storageBuffer16BitAccess
= enabled
;
803 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
804 features
->storagePushConstant16
= enabled
;
805 features
->storageInputOutput16
= enabled
&& HAVE_LLVM
>= 0x900;
808 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
809 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
810 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
811 features
->samplerYcbcrConversion
= false;
814 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
815 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
816 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
817 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
818 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
819 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
820 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
821 features
->shaderSampledImageArrayNonUniformIndexing
= true;
822 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
823 features
->shaderStorageImageArrayNonUniformIndexing
= true;
824 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
825 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
826 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
827 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
828 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
829 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
830 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
831 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
832 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
833 features
->descriptorBindingUpdateUnusedWhilePending
= true;
834 features
->descriptorBindingPartiallyBound
= true;
835 features
->descriptorBindingVariableDescriptorCount
= true;
836 features
->runtimeDescriptorArray
= true;
839 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
840 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
841 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
842 features
->conditionalRendering
= true;
843 features
->inheritedConditionalRendering
= false;
846 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
847 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
848 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
849 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
850 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
853 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
854 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
855 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
856 features
->transformFeedback
= true;
857 features
->geometryStreams
= true;
860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
861 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
862 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
863 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= CIK
;
866 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
867 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
868 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
869 features
->memoryPriority
= VK_TRUE
;
872 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_ADDRESS_FEATURES_EXT
: {
873 VkPhysicalDeviceBufferAddressFeaturesEXT
*features
=
874 (VkPhysicalDeviceBufferAddressFeaturesEXT
*)ext
;
875 features
->bufferDeviceAddress
= true;
876 features
->bufferDeviceAddressCaptureReplay
= false;
877 features
->bufferDeviceAddressMultiDevice
= false;
880 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
881 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
882 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
883 features
->depthClipEnable
= true;
886 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
887 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
888 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
889 features
->hostQueryReset
= true;
892 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
893 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
894 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
895 bool enabled
= pdevice
->rad_info
.chip_class
>= VI
;
896 features
->storageBuffer8BitAccess
= enabled
;
897 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
898 features
->storagePushConstant8
= enabled
;
901 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
902 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
903 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
904 bool enabled
= pdevice
->rad_info
.chip_class
>= VI
;
905 features
->shaderFloat16
= VK_FALSE
;
906 features
->shaderInt8
= enabled
;
913 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
916 void radv_GetPhysicalDeviceProperties(
917 VkPhysicalDevice physicalDevice
,
918 VkPhysicalDeviceProperties
* pProperties
)
920 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
921 VkSampleCountFlags sample_counts
= 0xf;
923 /* make sure that the entire descriptor set is addressable with a signed
924 * 32-bit int. So the sum of all limits scaled by descriptor size has to
925 * be at most 2 GiB. the combined image & samples object count as one of
926 * both. This limit is for the pipeline layout, not for the set layout, but
927 * there is no set limit, so we just set a pipeline limit. I don't think
928 * any app is going to hit this soon. */
929 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
930 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
931 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
932 32 /* sampler, largest when combined with image */ +
933 64 /* sampled image */ +
934 64 /* storage image */);
936 VkPhysicalDeviceLimits limits
= {
937 .maxImageDimension1D
= (1 << 14),
938 .maxImageDimension2D
= (1 << 14),
939 .maxImageDimension3D
= (1 << 11),
940 .maxImageDimensionCube
= (1 << 14),
941 .maxImageArrayLayers
= (1 << 11),
942 .maxTexelBufferElements
= 128 * 1024 * 1024,
943 .maxUniformBufferRange
= UINT32_MAX
,
944 .maxStorageBufferRange
= UINT32_MAX
,
945 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
946 .maxMemoryAllocationCount
= UINT32_MAX
,
947 .maxSamplerAllocationCount
= 64 * 1024,
948 .bufferImageGranularity
= 64, /* A cache line */
949 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
950 .maxBoundDescriptorSets
= MAX_SETS
,
951 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
952 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
953 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
954 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
955 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
956 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
957 .maxPerStageResources
= max_descriptor_set_size
,
958 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
959 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
960 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
961 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
962 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
963 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
964 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
965 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
966 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
967 .maxVertexInputBindings
= MAX_VBS
,
968 .maxVertexInputAttributeOffset
= 2047,
969 .maxVertexInputBindingStride
= 2048,
970 .maxVertexOutputComponents
= 128,
971 .maxTessellationGenerationLevel
= 64,
972 .maxTessellationPatchSize
= 32,
973 .maxTessellationControlPerVertexInputComponents
= 128,
974 .maxTessellationControlPerVertexOutputComponents
= 128,
975 .maxTessellationControlPerPatchOutputComponents
= 120,
976 .maxTessellationControlTotalOutputComponents
= 4096,
977 .maxTessellationEvaluationInputComponents
= 128,
978 .maxTessellationEvaluationOutputComponents
= 128,
979 .maxGeometryShaderInvocations
= 127,
980 .maxGeometryInputComponents
= 64,
981 .maxGeometryOutputComponents
= 128,
982 .maxGeometryOutputVertices
= 256,
983 .maxGeometryTotalOutputComponents
= 1024,
984 .maxFragmentInputComponents
= 128,
985 .maxFragmentOutputAttachments
= 8,
986 .maxFragmentDualSrcAttachments
= 1,
987 .maxFragmentCombinedOutputResources
= 8,
988 .maxComputeSharedMemorySize
= 32768,
989 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
990 .maxComputeWorkGroupInvocations
= 2048,
991 .maxComputeWorkGroupSize
= {
996 .subPixelPrecisionBits
= 8,
997 .subTexelPrecisionBits
= 8,
998 .mipmapPrecisionBits
= 8,
999 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1000 .maxDrawIndirectCount
= UINT32_MAX
,
1001 .maxSamplerLodBias
= 16,
1002 .maxSamplerAnisotropy
= 16,
1003 .maxViewports
= MAX_VIEWPORTS
,
1004 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1005 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1006 .viewportSubPixelBits
= 8,
1007 .minMemoryMapAlignment
= 4096, /* A page */
1008 .minTexelBufferOffsetAlignment
= 1,
1009 .minUniformBufferOffsetAlignment
= 4,
1010 .minStorageBufferOffsetAlignment
= 4,
1011 .minTexelOffset
= -32,
1012 .maxTexelOffset
= 31,
1013 .minTexelGatherOffset
= -32,
1014 .maxTexelGatherOffset
= 31,
1015 .minInterpolationOffset
= -2,
1016 .maxInterpolationOffset
= 2,
1017 .subPixelInterpolationOffsetBits
= 8,
1018 .maxFramebufferWidth
= (1 << 14),
1019 .maxFramebufferHeight
= (1 << 14),
1020 .maxFramebufferLayers
= (1 << 10),
1021 .framebufferColorSampleCounts
= sample_counts
,
1022 .framebufferDepthSampleCounts
= sample_counts
,
1023 .framebufferStencilSampleCounts
= sample_counts
,
1024 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1025 .maxColorAttachments
= MAX_RTS
,
1026 .sampledImageColorSampleCounts
= sample_counts
,
1027 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1028 .sampledImageDepthSampleCounts
= sample_counts
,
1029 .sampledImageStencilSampleCounts
= sample_counts
,
1030 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= VI
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1031 .maxSampleMaskWords
= 1,
1032 .timestampComputeAndGraphics
= true,
1033 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1034 .maxClipDistances
= 8,
1035 .maxCullDistances
= 8,
1036 .maxCombinedClipAndCullDistances
= 8,
1037 .discreteQueuePriorities
= 2,
1038 .pointSizeRange
= { 0.0, 8192.0 },
1039 .lineWidthRange
= { 0.0, 7.9921875 },
1040 .pointSizeGranularity
= (1.0 / 8.0),
1041 .lineWidthGranularity
= (1.0 / 128.0),
1042 .strictLines
= false, /* FINISHME */
1043 .standardSampleLocations
= true,
1044 .optimalBufferCopyOffsetAlignment
= 128,
1045 .optimalBufferCopyRowPitchAlignment
= 128,
1046 .nonCoherentAtomSize
= 64,
1049 *pProperties
= (VkPhysicalDeviceProperties
) {
1050 .apiVersion
= radv_physical_device_api_version(pdevice
),
1051 .driverVersion
= vk_get_driver_version(),
1052 .vendorID
= ATI_VENDOR_ID
,
1053 .deviceID
= pdevice
->rad_info
.pci_id
,
1054 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1056 .sparseProperties
= {0},
1059 strcpy(pProperties
->deviceName
, pdevice
->name
);
1060 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1063 void radv_GetPhysicalDeviceProperties2(
1064 VkPhysicalDevice physicalDevice
,
1065 VkPhysicalDeviceProperties2
*pProperties
)
1067 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1068 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1070 vk_foreach_struct(ext
, pProperties
->pNext
) {
1071 switch (ext
->sType
) {
1072 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1073 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1074 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1075 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1078 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1079 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1080 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1081 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1082 properties
->deviceLUIDValid
= false;
1085 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1086 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1087 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1088 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1091 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1092 VkPhysicalDevicePointClippingProperties
*properties
=
1093 (VkPhysicalDevicePointClippingProperties
*)ext
;
1094 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1097 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1098 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1099 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1100 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1103 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1104 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1105 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1106 properties
->minImportedHostPointerAlignment
= 4096;
1109 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1110 VkPhysicalDeviceSubgroupProperties
*properties
=
1111 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1112 properties
->subgroupSize
= 64;
1113 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1114 properties
->supportedOperations
=
1115 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1116 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1117 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1118 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1119 if (pdevice
->rad_info
.chip_class
>= VI
) {
1120 properties
->supportedOperations
|=
1121 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1122 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1123 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1125 properties
->quadOperationsInAllStages
= true;
1128 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1129 VkPhysicalDeviceMaintenance3Properties
*properties
=
1130 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1131 /* Make sure everything is addressable by a signed 32-bit int, and
1132 * our largest descriptors are 96 bytes. */
1133 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1134 /* Our buffer size fields allow only this much */
1135 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1138 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1139 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1140 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1141 /* GFX6-8 only support single channel min/max filter. */
1142 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1143 properties
->filterMinmaxSingleComponentFormats
= true;
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1147 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1148 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1150 /* Shader engines. */
1151 properties
->shaderEngineCount
=
1152 pdevice
->rad_info
.max_se
;
1153 properties
->shaderArraysPerEngineCount
=
1154 pdevice
->rad_info
.max_sh_per_se
;
1155 properties
->computeUnitsPerShaderArray
=
1156 pdevice
->rad_info
.num_good_cu_per_sh
;
1157 properties
->simdPerComputeUnit
= 4;
1158 properties
->wavefrontsPerSimd
=
1159 pdevice
->rad_info
.family
== CHIP_TONGA
||
1160 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1161 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1162 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1163 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1164 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1165 properties
->wavefrontSize
= 64;
1168 properties
->sgprsPerSimd
=
1169 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1170 properties
->minSgprAllocation
=
1171 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1172 properties
->maxSgprAllocation
=
1173 pdevice
->rad_info
.family
== CHIP_TONGA
||
1174 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1175 properties
->sgprAllocationGranularity
=
1176 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1179 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1180 properties
->minVgprAllocation
= 4;
1181 properties
->maxVgprAllocation
= 256;
1182 properties
->vgprAllocationGranularity
= 4;
1185 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1186 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1187 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1188 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1191 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1192 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1193 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1194 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1195 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1196 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1197 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1198 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1199 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1200 properties
->robustBufferAccessUpdateAfterBind
= false;
1201 properties
->quadDivergentImplicitLod
= false;
1203 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1204 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1205 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1206 32 /* sampler, largest when combined with image */ +
1207 64 /* sampled image */ +
1208 64 /* storage image */);
1209 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1210 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1211 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1212 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1213 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1214 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1215 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1216 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1217 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1218 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1219 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1220 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1221 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1222 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1223 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1226 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1227 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1228 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1229 properties
->protectedNoFault
= false;
1232 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1233 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1234 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1235 properties
->primitiveOverestimationSize
= 0;
1236 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1237 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1238 properties
->primitiveUnderestimation
= VK_FALSE
;
1239 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1240 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1241 properties
->degenerateLinesRasterized
= VK_FALSE
;
1242 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1243 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1246 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1247 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1248 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1249 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1250 properties
->pciBus
= pdevice
->bus_info
.bus
;
1251 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1252 properties
->pciFunction
= pdevice
->bus_info
.func
;
1255 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1256 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1257 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1259 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1260 memset(driver_props
->driverName
, 0, VK_MAX_DRIVER_NAME_SIZE_KHR
);
1261 strcpy(driver_props
->driverName
, "radv");
1263 memset(driver_props
->driverInfo
, 0, VK_MAX_DRIVER_INFO_SIZE_KHR
);
1264 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1265 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1266 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1268 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1276 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1277 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1278 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1279 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1280 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1281 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1282 properties
->maxTransformFeedbackStreamDataSize
= 512;
1283 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1284 properties
->maxTransformFeedbackBufferDataStride
= 512;
1285 properties
->transformFeedbackQueries
= true;
1286 properties
->transformFeedbackStreamsLinesTriangles
= false;
1287 properties
->transformFeedbackRasterizationStreamSelect
= false;
1288 properties
->transformFeedbackDraw
= true;
1297 static void radv_get_physical_device_queue_family_properties(
1298 struct radv_physical_device
* pdevice
,
1300 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1302 int num_queue_families
= 1;
1304 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1305 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1306 num_queue_families
++;
1308 if (pQueueFamilyProperties
== NULL
) {
1309 *pCount
= num_queue_families
;
1318 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1319 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1320 VK_QUEUE_COMPUTE_BIT
|
1321 VK_QUEUE_TRANSFER_BIT
|
1322 VK_QUEUE_SPARSE_BINDING_BIT
,
1324 .timestampValidBits
= 64,
1325 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1330 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1331 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1332 if (*pCount
> idx
) {
1333 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1334 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1335 VK_QUEUE_TRANSFER_BIT
|
1336 VK_QUEUE_SPARSE_BINDING_BIT
,
1337 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1338 .timestampValidBits
= 64,
1339 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1347 void radv_GetPhysicalDeviceQueueFamilyProperties(
1348 VkPhysicalDevice physicalDevice
,
1350 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1352 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1353 if (!pQueueFamilyProperties
) {
1354 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1357 VkQueueFamilyProperties
*properties
[] = {
1358 pQueueFamilyProperties
+ 0,
1359 pQueueFamilyProperties
+ 1,
1360 pQueueFamilyProperties
+ 2,
1362 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1363 assert(*pCount
<= 3);
1366 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1367 VkPhysicalDevice physicalDevice
,
1369 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1371 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1372 if (!pQueueFamilyProperties
) {
1373 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1376 VkQueueFamilyProperties
*properties
[] = {
1377 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1378 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1379 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1381 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1382 assert(*pCount
<= 3);
1385 void radv_GetPhysicalDeviceMemoryProperties(
1386 VkPhysicalDevice physicalDevice
,
1387 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1389 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1391 *pMemoryProperties
= physical_device
->memory_properties
;
1395 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1396 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1398 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1399 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1400 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1401 uint64_t vram_size
= radv_get_vram_size(device
);
1402 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1403 uint64_t heap_budget
, heap_usage
;
1405 /* For all memory heaps, the computation of budget is as follow:
1406 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1408 * The Vulkan spec 1.1.97 says that the budget should include any
1409 * currently allocated device memory.
1411 * Note that the application heap usages are not really accurate (eg.
1412 * in presence of shared buffers).
1415 heap_usage
= device
->ws
->query_value(device
->ws
,
1416 RADEON_ALLOCATED_VRAM
);
1418 heap_budget
= vram_size
-
1419 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1422 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM
] = heap_budget
;
1423 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM
] = heap_usage
;
1426 if (visible_vram_size
) {
1427 heap_usage
= device
->ws
->query_value(device
->ws
,
1428 RADEON_ALLOCATED_VRAM_VIS
);
1430 heap_budget
= visible_vram_size
-
1431 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1434 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_budget
;
1435 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_usage
;
1439 heap_usage
= device
->ws
->query_value(device
->ws
,
1440 RADEON_ALLOCATED_GTT
);
1442 heap_budget
= gtt_size
-
1443 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1446 memoryBudget
->heapBudget
[RADV_MEM_HEAP_GTT
] = heap_budget
;
1447 memoryBudget
->heapUsage
[RADV_MEM_HEAP_GTT
] = heap_usage
;
1450 /* The heapBudget and heapUsage values must be zero for array elements
1451 * greater than or equal to
1452 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1454 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1455 memoryBudget
->heapBudget
[i
] = 0;
1456 memoryBudget
->heapUsage
[i
] = 0;
1460 void radv_GetPhysicalDeviceMemoryProperties2(
1461 VkPhysicalDevice physicalDevice
,
1462 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1464 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1465 &pMemoryProperties
->memoryProperties
);
1467 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1468 vk_find_struct(pMemoryProperties
->pNext
,
1469 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1471 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1474 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1476 VkExternalMemoryHandleTypeFlagBits handleType
,
1477 const void *pHostPointer
,
1478 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1480 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1484 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1485 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1486 uint32_t memoryTypeBits
= 0;
1487 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1488 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1489 memoryTypeBits
= (1 << i
);
1493 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1497 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1501 static enum radeon_ctx_priority
1502 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1504 /* Default to MEDIUM when a specific global priority isn't requested */
1506 return RADEON_CTX_PRIORITY_MEDIUM
;
1508 switch(pObj
->globalPriority
) {
1509 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1510 return RADEON_CTX_PRIORITY_REALTIME
;
1511 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1512 return RADEON_CTX_PRIORITY_HIGH
;
1513 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1514 return RADEON_CTX_PRIORITY_MEDIUM
;
1515 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1516 return RADEON_CTX_PRIORITY_LOW
;
1518 unreachable("Illegal global priority value");
1519 return RADEON_CTX_PRIORITY_INVALID
;
1524 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1525 uint32_t queue_family_index
, int idx
,
1526 VkDeviceQueueCreateFlags flags
,
1527 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1529 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1530 queue
->device
= device
;
1531 queue
->queue_family_index
= queue_family_index
;
1532 queue
->queue_idx
= idx
;
1533 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1534 queue
->flags
= flags
;
1536 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1538 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1544 radv_queue_finish(struct radv_queue
*queue
)
1547 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1549 if (queue
->initial_full_flush_preamble_cs
)
1550 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1551 if (queue
->initial_preamble_cs
)
1552 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1553 if (queue
->continue_preamble_cs
)
1554 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1555 if (queue
->descriptor_bo
)
1556 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1557 if (queue
->scratch_bo
)
1558 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1559 if (queue
->esgs_ring_bo
)
1560 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1561 if (queue
->gsvs_ring_bo
)
1562 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1563 if (queue
->tess_rings_bo
)
1564 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1565 if (queue
->compute_scratch_bo
)
1566 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1570 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1572 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1573 bo_list
->list
.count
= bo_list
->capacity
= 0;
1574 bo_list
->list
.bos
= NULL
;
1578 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1580 free(bo_list
->list
.bos
);
1581 pthread_mutex_destroy(&bo_list
->mutex
);
1584 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1585 struct radeon_winsys_bo
*bo
)
1587 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1592 if (unlikely(!device
->use_global_bo_list
))
1595 pthread_mutex_lock(&bo_list
->mutex
);
1596 if (bo_list
->list
.count
== bo_list
->capacity
) {
1597 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1598 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1601 pthread_mutex_unlock(&bo_list
->mutex
);
1602 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1605 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1606 bo_list
->capacity
= capacity
;
1609 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1610 pthread_mutex_unlock(&bo_list
->mutex
);
1614 static void radv_bo_list_remove(struct radv_device
*device
,
1615 struct radeon_winsys_bo
*bo
)
1617 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1622 if (unlikely(!device
->use_global_bo_list
))
1625 pthread_mutex_lock(&bo_list
->mutex
);
1626 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1627 if (bo_list
->list
.bos
[i
] == bo
) {
1628 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1629 --bo_list
->list
.count
;
1633 pthread_mutex_unlock(&bo_list
->mutex
);
1637 radv_device_init_gs_info(struct radv_device
*device
)
1639 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1640 device
->physical_device
->rad_info
.family
);
1643 static int radv_get_device_extension_index(const char *name
)
1645 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1646 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1653 radv_get_int_debug_option(const char *name
, int default_value
)
1660 result
= default_value
;
1664 result
= strtol(str
, &endptr
, 0);
1665 if (str
== endptr
) {
1666 /* No digits founs. */
1667 result
= default_value
;
1674 VkResult
radv_CreateDevice(
1675 VkPhysicalDevice physicalDevice
,
1676 const VkDeviceCreateInfo
* pCreateInfo
,
1677 const VkAllocationCallbacks
* pAllocator
,
1680 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1682 struct radv_device
*device
;
1684 bool keep_shader_info
= false;
1686 /* Check enabled features */
1687 if (pCreateInfo
->pEnabledFeatures
) {
1688 VkPhysicalDeviceFeatures supported_features
;
1689 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1690 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1691 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1692 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1693 for (uint32_t i
= 0; i
< num_features
; i
++) {
1694 if (enabled_feature
[i
] && !supported_feature
[i
])
1695 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1699 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1701 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1703 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1705 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1706 device
->instance
= physical_device
->instance
;
1707 device
->physical_device
= physical_device
;
1709 device
->ws
= physical_device
->ws
;
1711 device
->alloc
= *pAllocator
;
1713 device
->alloc
= physical_device
->instance
->alloc
;
1715 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1716 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1717 int index
= radv_get_device_extension_index(ext_name
);
1718 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1719 vk_free(&device
->alloc
, device
);
1720 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1723 device
->enabled_extensions
.extensions
[index
] = true;
1726 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1728 /* With update after bind we can't attach bo's to the command buffer
1729 * from the descriptor set anymore, so we have to use a global BO list.
1731 device
->use_global_bo_list
=
1732 device
->enabled_extensions
.EXT_descriptor_indexing
||
1733 device
->enabled_extensions
.EXT_buffer_device_address
;
1735 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1736 list_inithead(&device
->shader_slabs
);
1738 radv_bo_list_init(&device
->bo_list
);
1740 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1741 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1742 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1743 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1744 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1746 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1748 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1749 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1750 if (!device
->queues
[qfi
]) {
1751 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1755 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1757 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1759 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1760 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1761 qfi
, q
, queue_create
->flags
,
1763 if (result
!= VK_SUCCESS
)
1768 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1769 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1771 /* Disabled and not implemented for now. */
1772 device
->dfsm_allowed
= device
->pbb_allowed
&&
1773 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1774 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
);
1777 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1780 /* The maximum number of scratch waves. Scratch space isn't divided
1781 * evenly between CUs. The number is only a function of the number of CUs.
1782 * We can decrease the constant to decrease the scratch buffer size.
1784 * sctx->scratch_waves must be >= the maximum possible size of
1785 * 1 threadgroup, so that the hw doesn't hang from being unable
1788 * The recommended value is 4 per CU at most. Higher numbers don't
1789 * bring much benefit, but they still occupy chip resources (think
1790 * async compute). I've seen ~2% performance difference between 4 and 32.
1792 uint32_t max_threads_per_block
= 2048;
1793 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1794 max_threads_per_block
/ 64);
1796 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1798 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1799 /* If the KMD allows it (there is a KMD hw register for it),
1800 * allow launching waves out-of-order.
1802 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1805 radv_device_init_gs_info(device
);
1807 device
->tess_offchip_block_dw_size
=
1808 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1809 device
->has_distributed_tess
=
1810 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1811 device
->physical_device
->rad_info
.max_se
>= 2;
1813 if (getenv("RADV_TRACE_FILE")) {
1814 const char *filename
= getenv("RADV_TRACE_FILE");
1816 keep_shader_info
= true;
1818 if (!radv_init_trace(device
))
1821 fprintf(stderr
, "*****************************************************************************\n");
1822 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1823 fprintf(stderr
, "*****************************************************************************\n");
1825 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1826 radv_dump_enabled_options(device
, stderr
);
1829 device
->keep_shader_info
= keep_shader_info
;
1831 result
= radv_device_init_meta(device
);
1832 if (result
!= VK_SUCCESS
)
1835 radv_device_init_msaa(device
);
1837 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1838 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1840 case RADV_QUEUE_GENERAL
:
1841 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1842 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1843 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1845 case RADV_QUEUE_COMPUTE
:
1846 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1847 radeon_emit(device
->empty_cs
[family
], 0);
1850 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1853 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1854 cik_create_gfx_config(device
);
1856 VkPipelineCacheCreateInfo ci
;
1857 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1860 ci
.pInitialData
= NULL
;
1861 ci
.initialDataSize
= 0;
1863 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1865 if (result
!= VK_SUCCESS
)
1868 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1870 device
->force_aniso
=
1871 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1872 if (device
->force_aniso
>= 0) {
1873 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
1874 1 << util_logbase2(device
->force_aniso
));
1877 *pDevice
= radv_device_to_handle(device
);
1881 radv_device_finish_meta(device
);
1883 radv_bo_list_finish(&device
->bo_list
);
1885 if (device
->trace_bo
)
1886 device
->ws
->buffer_destroy(device
->trace_bo
);
1888 if (device
->gfx_init
)
1889 device
->ws
->buffer_destroy(device
->gfx_init
);
1891 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1892 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1893 radv_queue_finish(&device
->queues
[i
][q
]);
1894 if (device
->queue_count
[i
])
1895 vk_free(&device
->alloc
, device
->queues
[i
]);
1898 vk_free(&device
->alloc
, device
);
1902 void radv_DestroyDevice(
1904 const VkAllocationCallbacks
* pAllocator
)
1906 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1911 if (device
->trace_bo
)
1912 device
->ws
->buffer_destroy(device
->trace_bo
);
1914 if (device
->gfx_init
)
1915 device
->ws
->buffer_destroy(device
->gfx_init
);
1917 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1918 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1919 radv_queue_finish(&device
->queues
[i
][q
]);
1920 if (device
->queue_count
[i
])
1921 vk_free(&device
->alloc
, device
->queues
[i
]);
1922 if (device
->empty_cs
[i
])
1923 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1925 radv_device_finish_meta(device
);
1927 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1928 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1930 radv_destroy_shader_slabs(device
);
1932 radv_bo_list_finish(&device
->bo_list
);
1933 vk_free(&device
->alloc
, device
);
1936 VkResult
radv_EnumerateInstanceLayerProperties(
1937 uint32_t* pPropertyCount
,
1938 VkLayerProperties
* pProperties
)
1940 if (pProperties
== NULL
) {
1941 *pPropertyCount
= 0;
1945 /* None supported at this time */
1946 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1949 VkResult
radv_EnumerateDeviceLayerProperties(
1950 VkPhysicalDevice physicalDevice
,
1951 uint32_t* pPropertyCount
,
1952 VkLayerProperties
* pProperties
)
1954 if (pProperties
== NULL
) {
1955 *pPropertyCount
= 0;
1959 /* None supported at this time */
1960 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1963 void radv_GetDeviceQueue2(
1965 const VkDeviceQueueInfo2
* pQueueInfo
,
1968 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1969 struct radv_queue
*queue
;
1971 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1972 if (pQueueInfo
->flags
!= queue
->flags
) {
1973 /* From the Vulkan 1.1.70 spec:
1975 * "The queue returned by vkGetDeviceQueue2 must have the same
1976 * flags value from this structure as that used at device
1977 * creation time in a VkDeviceQueueCreateInfo instance. If no
1978 * matching flags were specified at device creation time then
1979 * pQueue will return VK_NULL_HANDLE."
1981 *pQueue
= VK_NULL_HANDLE
;
1985 *pQueue
= radv_queue_to_handle(queue
);
1988 void radv_GetDeviceQueue(
1990 uint32_t queueFamilyIndex
,
1991 uint32_t queueIndex
,
1994 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1995 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1996 .queueFamilyIndex
= queueFamilyIndex
,
1997 .queueIndex
= queueIndex
2000 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2004 fill_geom_tess_rings(struct radv_queue
*queue
,
2006 bool add_sample_positions
,
2007 uint32_t esgs_ring_size
,
2008 struct radeon_winsys_bo
*esgs_ring_bo
,
2009 uint32_t gsvs_ring_size
,
2010 struct radeon_winsys_bo
*gsvs_ring_bo
,
2011 uint32_t tess_factor_ring_size
,
2012 uint32_t tess_offchip_ring_offset
,
2013 uint32_t tess_offchip_ring_size
,
2014 struct radeon_winsys_bo
*tess_rings_bo
)
2016 uint32_t *desc
= &map
[4];
2019 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2021 /* stride 0, num records - size, add tid, swizzle, elsize4,
2024 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2025 S_008F04_STRIDE(0) |
2026 S_008F04_SWIZZLE_ENABLE(true);
2027 desc
[2] = esgs_ring_size
;
2028 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2029 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2030 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2031 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2032 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2033 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2034 S_008F0C_ELEMENT_SIZE(1) |
2035 S_008F0C_INDEX_STRIDE(3) |
2036 S_008F0C_ADD_TID_ENABLE(true);
2038 /* GS entry for ES->GS ring */
2039 /* stride 0, num records - size, elsize0,
2042 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
2043 S_008F04_STRIDE(0) |
2044 S_008F04_SWIZZLE_ENABLE(false);
2045 desc
[6] = esgs_ring_size
;
2046 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2047 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2048 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2049 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2050 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2051 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2052 S_008F0C_ELEMENT_SIZE(0) |
2053 S_008F0C_INDEX_STRIDE(0) |
2054 S_008F0C_ADD_TID_ENABLE(false);
2060 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2062 /* VS entry for GS->VS ring */
2063 /* stride 0, num records - size, elsize0,
2066 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2067 S_008F04_STRIDE(0) |
2068 S_008F04_SWIZZLE_ENABLE(false);
2069 desc
[2] = gsvs_ring_size
;
2070 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2071 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2072 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2073 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2074 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2075 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2076 S_008F0C_ELEMENT_SIZE(0) |
2077 S_008F0C_INDEX_STRIDE(0) |
2078 S_008F0C_ADD_TID_ENABLE(false);
2080 /* stride gsvs_itemsize, num records 64
2081 elsize 4, index stride 16 */
2082 /* shader will patch stride and desc[2] */
2084 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2085 S_008F04_STRIDE(0) |
2086 S_008F04_SWIZZLE_ENABLE(true);
2088 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2089 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2090 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2091 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2092 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2093 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2094 S_008F0C_ELEMENT_SIZE(1) |
2095 S_008F0C_INDEX_STRIDE(1) |
2096 S_008F0C_ADD_TID_ENABLE(true);
2101 if (tess_rings_bo
) {
2102 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2103 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2106 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
2107 S_008F04_STRIDE(0) |
2108 S_008F04_SWIZZLE_ENABLE(false);
2109 desc
[2] = tess_factor_ring_size
;
2110 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2111 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2112 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2113 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2114 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2115 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2116 S_008F0C_ELEMENT_SIZE(0) |
2117 S_008F0C_INDEX_STRIDE(0) |
2118 S_008F0C_ADD_TID_ENABLE(false);
2120 desc
[4] = tess_offchip_va
;
2121 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
2122 S_008F04_STRIDE(0) |
2123 S_008F04_SWIZZLE_ENABLE(false);
2124 desc
[6] = tess_offchip_ring_size
;
2125 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2126 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2127 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2128 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2129 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2130 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2131 S_008F0C_ELEMENT_SIZE(0) |
2132 S_008F0C_INDEX_STRIDE(0) |
2133 S_008F0C_ADD_TID_ENABLE(false);
2138 if (add_sample_positions
) {
2139 /* add sample positions after all rings */
2140 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2142 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2144 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2146 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2151 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2153 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
2154 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2155 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2156 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2157 unsigned max_offchip_buffers
;
2158 unsigned offchip_granularity
;
2159 unsigned hs_offchip_param
;
2163 * This must be one less than the maximum number due to a hw limitation.
2164 * Various hardware bugs in SI, CIK, and GFX9 need this.
2167 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2168 * Gfx7 should limit max_offchip_buffers to 508
2169 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2171 * Follow AMDVLK here.
2173 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2174 device
->physical_device
->rad_info
.chip_class
== CIK
||
2175 device
->physical_device
->rad_info
.chip_class
== SI
)
2176 --max_offchip_buffers_per_se
;
2178 max_offchip_buffers
= max_offchip_buffers_per_se
*
2179 device
->physical_device
->rad_info
.max_se
;
2181 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2182 * around by setting 4K granularity.
2184 if (device
->tess_offchip_block_dw_size
== 4096) {
2185 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2186 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2188 assert(device
->tess_offchip_block_dw_size
== 8192);
2189 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2192 switch (device
->physical_device
->rad_info
.chip_class
) {
2194 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2200 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2204 *max_offchip_buffers_p
= max_offchip_buffers
;
2205 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2206 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
2207 --max_offchip_buffers
;
2209 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2210 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2213 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2215 return hs_offchip_param
;
2219 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2220 struct radeon_winsys_bo
*esgs_ring_bo
,
2221 uint32_t esgs_ring_size
,
2222 struct radeon_winsys_bo
*gsvs_ring_bo
,
2223 uint32_t gsvs_ring_size
)
2225 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2229 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2232 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2234 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2235 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2236 radeon_emit(cs
, esgs_ring_size
>> 8);
2237 radeon_emit(cs
, gsvs_ring_size
>> 8);
2239 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2240 radeon_emit(cs
, esgs_ring_size
>> 8);
2241 radeon_emit(cs
, gsvs_ring_size
>> 8);
2246 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2247 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2248 struct radeon_winsys_bo
*tess_rings_bo
)
2255 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2257 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2259 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2260 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2261 S_030938_SIZE(tf_ring_size
/ 4));
2262 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2264 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2265 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2266 S_030944_BASE_HI(tf_va
>> 40));
2268 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2271 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2272 S_008988_SIZE(tf_ring_size
/ 4));
2273 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2275 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2281 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2282 struct radeon_winsys_bo
*compute_scratch_bo
)
2284 uint64_t scratch_va
;
2286 if (!compute_scratch_bo
)
2289 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2291 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2293 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2294 radeon_emit(cs
, scratch_va
);
2295 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2296 S_008F04_SWIZZLE_ENABLE(1));
2300 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2301 struct radeon_cmdbuf
*cs
,
2302 struct radeon_winsys_bo
*descriptor_bo
)
2309 va
= radv_buffer_get_va(descriptor_bo
);
2311 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2313 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2314 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2315 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2316 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2317 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2319 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2320 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2324 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2325 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2326 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2327 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2328 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2329 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2331 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2332 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2339 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2341 struct radv_device
*device
= queue
->device
;
2343 if (device
->gfx_init
) {
2344 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2346 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2347 radeon_emit(cs
, va
);
2348 radeon_emit(cs
, va
>> 32);
2349 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2351 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2353 struct radv_physical_device
*physical_device
= device
->physical_device
;
2354 si_emit_graphics(physical_device
, cs
);
2359 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2361 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2362 si_emit_compute(physical_device
, cs
);
2366 radv_get_preamble_cs(struct radv_queue
*queue
,
2367 uint32_t scratch_size
,
2368 uint32_t compute_scratch_size
,
2369 uint32_t esgs_ring_size
,
2370 uint32_t gsvs_ring_size
,
2371 bool needs_tess_rings
,
2372 bool needs_sample_positions
,
2373 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2374 struct radeon_cmdbuf
**initial_preamble_cs
,
2375 struct radeon_cmdbuf
**continue_preamble_cs
)
2377 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2378 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2379 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2380 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2381 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2382 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2383 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2384 bool add_tess_rings
= false, add_sample_positions
= false;
2385 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2386 unsigned max_offchip_buffers
;
2387 unsigned hs_offchip_param
= 0;
2388 unsigned tess_offchip_ring_offset
;
2389 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2390 if (!queue
->has_tess_rings
) {
2391 if (needs_tess_rings
)
2392 add_tess_rings
= true;
2394 if (!queue
->has_sample_positions
) {
2395 if (needs_sample_positions
)
2396 add_sample_positions
= true;
2398 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2399 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2400 &max_offchip_buffers
);
2401 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2402 tess_offchip_ring_size
= max_offchip_buffers
*
2403 queue
->device
->tess_offchip_block_dw_size
* 4;
2405 if (scratch_size
<= queue
->scratch_size
&&
2406 compute_scratch_size
<= queue
->compute_scratch_size
&&
2407 esgs_ring_size
<= queue
->esgs_ring_size
&&
2408 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2409 !add_tess_rings
&& !add_sample_positions
&&
2410 queue
->initial_preamble_cs
) {
2411 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2412 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2413 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2414 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2415 *continue_preamble_cs
= NULL
;
2419 if (scratch_size
> queue
->scratch_size
) {
2420 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2425 RADV_BO_PRIORITY_SCRATCH
);
2429 scratch_bo
= queue
->scratch_bo
;
2431 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2432 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2433 compute_scratch_size
,
2437 RADV_BO_PRIORITY_SCRATCH
);
2438 if (!compute_scratch_bo
)
2442 compute_scratch_bo
= queue
->compute_scratch_bo
;
2444 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2445 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2450 RADV_BO_PRIORITY_SCRATCH
);
2454 esgs_ring_bo
= queue
->esgs_ring_bo
;
2455 esgs_ring_size
= queue
->esgs_ring_size
;
2458 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2459 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2464 RADV_BO_PRIORITY_SCRATCH
);
2468 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2469 gsvs_ring_size
= queue
->gsvs_ring_size
;
2472 if (add_tess_rings
) {
2473 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2474 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2478 RADV_BO_PRIORITY_SCRATCH
);
2482 tess_rings_bo
= queue
->tess_rings_bo
;
2485 if (scratch_bo
!= queue
->scratch_bo
||
2486 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2487 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2488 tess_rings_bo
!= queue
->tess_rings_bo
||
2489 add_sample_positions
) {
2491 if (gsvs_ring_bo
|| esgs_ring_bo
||
2492 tess_rings_bo
|| add_sample_positions
) {
2493 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2494 if (add_sample_positions
)
2495 size
+= 128; /* 64+32+16+8 = 120 bytes */
2497 else if (scratch_bo
)
2498 size
= 8; /* 2 dword */
2500 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2504 RADEON_FLAG_CPU_ACCESS
|
2505 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2506 RADEON_FLAG_READ_ONLY
,
2507 RADV_BO_PRIORITY_DESCRIPTOR
);
2511 descriptor_bo
= queue
->descriptor_bo
;
2513 if (descriptor_bo
!= queue
->descriptor_bo
) {
2514 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2517 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2518 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2519 S_008F04_SWIZZLE_ENABLE(1);
2520 map
[0] = scratch_va
;
2524 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2525 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2526 esgs_ring_size
, esgs_ring_bo
,
2527 gsvs_ring_size
, gsvs_ring_bo
,
2528 tess_factor_ring_size
,
2529 tess_offchip_ring_offset
,
2530 tess_offchip_ring_size
,
2533 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2536 for(int i
= 0; i
< 3; ++i
) {
2537 struct radeon_cmdbuf
*cs
= NULL
;
2538 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2539 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2546 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2548 /* Emit initial configuration. */
2549 switch (queue
->queue_family_index
) {
2550 case RADV_QUEUE_GENERAL
:
2551 radv_init_graphics_state(cs
, queue
);
2553 case RADV_QUEUE_COMPUTE
:
2554 radv_init_compute_state(cs
, queue
);
2556 case RADV_QUEUE_TRANSFER
:
2560 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2561 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2562 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2563 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2564 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2567 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2568 gsvs_ring_bo
, gsvs_ring_size
);
2569 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2570 tess_factor_ring_size
, tess_rings_bo
);
2571 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2572 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2575 si_cs_emit_cache_flush(cs
,
2576 queue
->device
->physical_device
->rad_info
.chip_class
,
2578 queue
->queue_family_index
== RING_COMPUTE
&&
2579 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2580 (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
)) |
2581 RADV_CMD_FLAG_INV_ICACHE
|
2582 RADV_CMD_FLAG_INV_SMEM_L1
|
2583 RADV_CMD_FLAG_INV_VMEM_L1
|
2584 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2585 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2586 } else if (i
== 1) {
2587 si_cs_emit_cache_flush(cs
,
2588 queue
->device
->physical_device
->rad_info
.chip_class
,
2590 queue
->queue_family_index
== RING_COMPUTE
&&
2591 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2592 RADV_CMD_FLAG_INV_ICACHE
|
2593 RADV_CMD_FLAG_INV_SMEM_L1
|
2594 RADV_CMD_FLAG_INV_VMEM_L1
|
2595 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2596 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2599 if (!queue
->device
->ws
->cs_finalize(cs
))
2603 if (queue
->initial_full_flush_preamble_cs
)
2604 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2606 if (queue
->initial_preamble_cs
)
2607 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2609 if (queue
->continue_preamble_cs
)
2610 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2612 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2613 queue
->initial_preamble_cs
= dest_cs
[1];
2614 queue
->continue_preamble_cs
= dest_cs
[2];
2616 if (scratch_bo
!= queue
->scratch_bo
) {
2617 if (queue
->scratch_bo
)
2618 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2619 queue
->scratch_bo
= scratch_bo
;
2620 queue
->scratch_size
= scratch_size
;
2623 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2624 if (queue
->compute_scratch_bo
)
2625 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2626 queue
->compute_scratch_bo
= compute_scratch_bo
;
2627 queue
->compute_scratch_size
= compute_scratch_size
;
2630 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2631 if (queue
->esgs_ring_bo
)
2632 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2633 queue
->esgs_ring_bo
= esgs_ring_bo
;
2634 queue
->esgs_ring_size
= esgs_ring_size
;
2637 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2638 if (queue
->gsvs_ring_bo
)
2639 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2640 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2641 queue
->gsvs_ring_size
= gsvs_ring_size
;
2644 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2645 queue
->tess_rings_bo
= tess_rings_bo
;
2646 queue
->has_tess_rings
= true;
2649 if (descriptor_bo
!= queue
->descriptor_bo
) {
2650 if (queue
->descriptor_bo
)
2651 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2653 queue
->descriptor_bo
= descriptor_bo
;
2656 if (add_sample_positions
)
2657 queue
->has_sample_positions
= true;
2659 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2660 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2661 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2662 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2663 *continue_preamble_cs
= NULL
;
2666 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2668 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2669 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2670 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2671 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2672 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2673 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2674 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2675 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2676 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2677 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2678 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2679 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2680 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2681 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2684 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2685 struct radv_winsys_sem_counts
*counts
,
2687 const VkSemaphore
*sems
,
2691 int syncobj_idx
= 0, sem_idx
= 0;
2693 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2696 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2697 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2699 if (sem
->temp_syncobj
|| sem
->syncobj
)
2700 counts
->syncobj_count
++;
2702 counts
->sem_count
++;
2705 if (_fence
!= VK_NULL_HANDLE
) {
2706 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2707 if (fence
->temp_syncobj
|| fence
->syncobj
)
2708 counts
->syncobj_count
++;
2711 if (counts
->syncobj_count
) {
2712 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2713 if (!counts
->syncobj
)
2714 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2717 if (counts
->sem_count
) {
2718 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2720 free(counts
->syncobj
);
2721 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2725 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2726 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2728 if (sem
->temp_syncobj
) {
2729 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2731 else if (sem
->syncobj
)
2732 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2735 counts
->sem
[sem_idx
++] = sem
->sem
;
2739 if (_fence
!= VK_NULL_HANDLE
) {
2740 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2741 if (fence
->temp_syncobj
)
2742 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2743 else if (fence
->syncobj
)
2744 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2751 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2753 free(sem_info
->wait
.syncobj
);
2754 free(sem_info
->wait
.sem
);
2755 free(sem_info
->signal
.syncobj
);
2756 free(sem_info
->signal
.sem
);
2760 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2762 const VkSemaphore
*sems
)
2764 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2765 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2767 if (sem
->temp_syncobj
) {
2768 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2769 sem
->temp_syncobj
= 0;
2775 radv_alloc_sem_info(struct radv_instance
*instance
,
2776 struct radv_winsys_sem_info
*sem_info
,
2778 const VkSemaphore
*wait_sems
,
2779 int num_signal_sems
,
2780 const VkSemaphore
*signal_sems
,
2784 memset(sem_info
, 0, sizeof(*sem_info
));
2786 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2789 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2791 radv_free_sem_info(sem_info
);
2793 /* caller can override these */
2794 sem_info
->cs_emit_wait
= true;
2795 sem_info
->cs_emit_signal
= true;
2799 /* Signals fence as soon as all the work currently put on queue is done. */
2800 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2801 struct radv_fence
*fence
)
2805 struct radv_winsys_sem_info sem_info
;
2807 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2808 radv_fence_to_handle(fence
));
2809 if (result
!= VK_SUCCESS
)
2812 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2813 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2814 1, NULL
, NULL
, &sem_info
, NULL
,
2815 false, fence
->fence
);
2816 radv_free_sem_info(&sem_info
);
2819 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2824 VkResult
radv_QueueSubmit(
2826 uint32_t submitCount
,
2827 const VkSubmitInfo
* pSubmits
,
2830 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2831 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2832 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2833 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2835 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
2836 uint32_t scratch_size
= 0;
2837 uint32_t compute_scratch_size
= 0;
2838 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2839 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2841 bool fence_emitted
= false;
2842 bool tess_rings_needed
= false;
2843 bool sample_positions_needed
= false;
2845 /* Do this first so failing to allocate scratch buffers can't result in
2846 * partially executed submissions. */
2847 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2848 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2849 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2850 pSubmits
[i
].pCommandBuffers
[j
]);
2852 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2853 compute_scratch_size
= MAX2(compute_scratch_size
,
2854 cmd_buffer
->compute_scratch_size_needed
);
2855 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2856 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2857 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2858 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2862 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2863 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2864 sample_positions_needed
, &initial_flush_preamble_cs
,
2865 &initial_preamble_cs
, &continue_preamble_cs
);
2866 if (result
!= VK_SUCCESS
)
2869 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2870 struct radeon_cmdbuf
**cs_array
;
2871 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2872 bool can_patch
= true;
2874 struct radv_winsys_sem_info sem_info
;
2876 result
= radv_alloc_sem_info(queue
->device
->instance
,
2878 pSubmits
[i
].waitSemaphoreCount
,
2879 pSubmits
[i
].pWaitSemaphores
,
2880 pSubmits
[i
].signalSemaphoreCount
,
2881 pSubmits
[i
].pSignalSemaphores
,
2883 if (result
!= VK_SUCCESS
)
2886 if (!pSubmits
[i
].commandBufferCount
) {
2887 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2888 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2889 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2894 radv_loge("failed to submit CS %d\n", i
);
2897 fence_emitted
= true;
2899 radv_free_sem_info(&sem_info
);
2903 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2904 (pSubmits
[i
].commandBufferCount
));
2906 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2907 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2908 pSubmits
[i
].pCommandBuffers
[j
]);
2909 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2911 cs_array
[j
] = cmd_buffer
->cs
;
2912 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2915 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2918 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2919 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2920 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2922 advance
= MIN2(max_cs_submission
,
2923 pSubmits
[i
].commandBufferCount
- j
);
2925 if (queue
->device
->trace_bo
)
2926 *queue
->device
->trace_id_ptr
= 0;
2928 sem_info
.cs_emit_wait
= j
== 0;
2929 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2931 if (unlikely(queue
->device
->use_global_bo_list
)) {
2932 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2933 bo_list
= &queue
->device
->bo_list
.list
;
2936 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2937 advance
, initial_preamble
, continue_preamble_cs
,
2939 can_patch
, base_fence
);
2941 if (unlikely(queue
->device
->use_global_bo_list
))
2942 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2945 radv_loge("failed to submit CS %d\n", i
);
2948 fence_emitted
= true;
2949 if (queue
->device
->trace_bo
) {
2950 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2954 radv_free_temp_syncobjs(queue
->device
,
2955 pSubmits
[i
].waitSemaphoreCount
,
2956 pSubmits
[i
].pWaitSemaphores
);
2957 radv_free_sem_info(&sem_info
);
2962 if (!fence_emitted
) {
2963 result
= radv_signal_fence(queue
, fence
);
2964 if (result
!= VK_SUCCESS
)
2967 fence
->submitted
= true;
2973 VkResult
radv_QueueWaitIdle(
2976 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2978 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2979 radv_queue_family_to_ring(queue
->queue_family_index
),
2984 VkResult
radv_DeviceWaitIdle(
2987 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2989 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2990 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2991 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2997 VkResult
radv_EnumerateInstanceExtensionProperties(
2998 const char* pLayerName
,
2999 uint32_t* pPropertyCount
,
3000 VkExtensionProperties
* pProperties
)
3002 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3004 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3005 if (radv_supported_instance_extensions
.extensions
[i
]) {
3006 vk_outarray_append(&out
, prop
) {
3007 *prop
= radv_instance_extensions
[i
];
3012 return vk_outarray_status(&out
);
3015 VkResult
radv_EnumerateDeviceExtensionProperties(
3016 VkPhysicalDevice physicalDevice
,
3017 const char* pLayerName
,
3018 uint32_t* pPropertyCount
,
3019 VkExtensionProperties
* pProperties
)
3021 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3022 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3024 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3025 if (device
->supported_extensions
.extensions
[i
]) {
3026 vk_outarray_append(&out
, prop
) {
3027 *prop
= radv_device_extensions
[i
];
3032 return vk_outarray_status(&out
);
3035 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3036 VkInstance _instance
,
3039 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3041 return radv_lookup_entrypoint_checked(pName
,
3042 instance
? instance
->apiVersion
: 0,
3043 instance
? &instance
->enabled_extensions
: NULL
,
3047 /* The loader wants us to expose a second GetInstanceProcAddr function
3048 * to work around certain LD_PRELOAD issues seen in apps.
3051 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3052 VkInstance instance
,
3056 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3057 VkInstance instance
,
3060 return radv_GetInstanceProcAddr(instance
, pName
);
3063 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3067 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3069 return radv_lookup_entrypoint_checked(pName
,
3070 device
->instance
->apiVersion
,
3071 &device
->instance
->enabled_extensions
,
3072 &device
->enabled_extensions
);
3075 bool radv_get_memory_fd(struct radv_device
*device
,
3076 struct radv_device_memory
*memory
,
3079 struct radeon_bo_metadata metadata
;
3081 if (memory
->image
) {
3082 radv_init_metadata(device
, memory
->image
, &metadata
);
3083 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3086 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3090 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3091 const VkMemoryAllocateInfo
* pAllocateInfo
,
3092 const VkAllocationCallbacks
* pAllocator
,
3093 VkDeviceMemory
* pMem
)
3095 struct radv_device_memory
*mem
;
3097 enum radeon_bo_domain domain
;
3099 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3101 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3103 if (pAllocateInfo
->allocationSize
== 0) {
3104 /* Apparently, this is allowed */
3105 *pMem
= VK_NULL_HANDLE
;
3109 const VkImportMemoryFdInfoKHR
*import_info
=
3110 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3111 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3112 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3113 const VkExportMemoryAllocateInfo
*export_info
=
3114 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3115 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3116 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3118 const struct wsi_memory_allocate_info
*wsi_info
=
3119 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3121 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3122 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3124 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3126 if (wsi_info
&& wsi_info
->implicit_sync
)
3127 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3129 if (dedicate_info
) {
3130 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3131 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3137 float priority_float
= 0.5;
3138 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3139 vk_find_struct_const(pAllocateInfo
->pNext
,
3140 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3142 priority_float
= priority_ext
->priority
;
3144 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3145 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3147 mem
->user_ptr
= NULL
;
3150 assert(import_info
->handleType
==
3151 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3152 import_info
->handleType
==
3153 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3154 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3155 priority
, NULL
, NULL
);
3157 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3160 close(import_info
->fd
);
3162 } else if (host_ptr_info
) {
3163 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3164 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3165 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3166 pAllocateInfo
->allocationSize
,
3169 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3172 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3175 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3176 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3177 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3178 domain
= RADEON_DOMAIN_GTT
;
3180 domain
= RADEON_DOMAIN_VRAM
;
3182 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3183 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3185 flags
|= RADEON_FLAG_CPU_ACCESS
;
3187 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3188 flags
|= RADEON_FLAG_GTT_WC
;
3190 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
3191 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3193 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3194 domain
, flags
, priority
);
3197 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3200 mem
->type_index
= mem_type_index
;
3203 result
= radv_bo_list_add(device
, mem
->bo
);
3204 if (result
!= VK_SUCCESS
)
3207 *pMem
= radv_device_memory_to_handle(mem
);
3212 device
->ws
->buffer_destroy(mem
->bo
);
3214 vk_free2(&device
->alloc
, pAllocator
, mem
);
3219 VkResult
radv_AllocateMemory(
3221 const VkMemoryAllocateInfo
* pAllocateInfo
,
3222 const VkAllocationCallbacks
* pAllocator
,
3223 VkDeviceMemory
* pMem
)
3225 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3226 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3229 void radv_FreeMemory(
3231 VkDeviceMemory _mem
,
3232 const VkAllocationCallbacks
* pAllocator
)
3234 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3235 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3240 radv_bo_list_remove(device
, mem
->bo
);
3241 device
->ws
->buffer_destroy(mem
->bo
);
3244 vk_free2(&device
->alloc
, pAllocator
, mem
);
3247 VkResult
radv_MapMemory(
3249 VkDeviceMemory _memory
,
3250 VkDeviceSize offset
,
3252 VkMemoryMapFlags flags
,
3255 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3256 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3264 *ppData
= mem
->user_ptr
;
3266 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3273 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3276 void radv_UnmapMemory(
3278 VkDeviceMemory _memory
)
3280 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3281 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3286 if (mem
->user_ptr
== NULL
)
3287 device
->ws
->buffer_unmap(mem
->bo
);
3290 VkResult
radv_FlushMappedMemoryRanges(
3292 uint32_t memoryRangeCount
,
3293 const VkMappedMemoryRange
* pMemoryRanges
)
3298 VkResult
radv_InvalidateMappedMemoryRanges(
3300 uint32_t memoryRangeCount
,
3301 const VkMappedMemoryRange
* pMemoryRanges
)
3306 void radv_GetBufferMemoryRequirements(
3309 VkMemoryRequirements
* pMemoryRequirements
)
3311 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3312 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3314 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3316 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3317 pMemoryRequirements
->alignment
= 4096;
3319 pMemoryRequirements
->alignment
= 16;
3321 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3324 void radv_GetBufferMemoryRequirements2(
3326 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3327 VkMemoryRequirements2
*pMemoryRequirements
)
3329 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3330 &pMemoryRequirements
->memoryRequirements
);
3331 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3332 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3333 switch (ext
->sType
) {
3334 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3335 VkMemoryDedicatedRequirements
*req
=
3336 (VkMemoryDedicatedRequirements
*) ext
;
3337 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3338 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3347 void radv_GetImageMemoryRequirements(
3350 VkMemoryRequirements
* pMemoryRequirements
)
3352 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3353 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3355 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3357 pMemoryRequirements
->size
= image
->size
;
3358 pMemoryRequirements
->alignment
= image
->alignment
;
3361 void radv_GetImageMemoryRequirements2(
3363 const VkImageMemoryRequirementsInfo2
*pInfo
,
3364 VkMemoryRequirements2
*pMemoryRequirements
)
3366 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3367 &pMemoryRequirements
->memoryRequirements
);
3369 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3371 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3372 switch (ext
->sType
) {
3373 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3374 VkMemoryDedicatedRequirements
*req
=
3375 (VkMemoryDedicatedRequirements
*) ext
;
3376 req
->requiresDedicatedAllocation
= image
->shareable
;
3377 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3386 void radv_GetImageSparseMemoryRequirements(
3389 uint32_t* pSparseMemoryRequirementCount
,
3390 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3395 void radv_GetImageSparseMemoryRequirements2(
3397 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3398 uint32_t* pSparseMemoryRequirementCount
,
3399 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3404 void radv_GetDeviceMemoryCommitment(
3406 VkDeviceMemory memory
,
3407 VkDeviceSize
* pCommittedMemoryInBytes
)
3409 *pCommittedMemoryInBytes
= 0;
3412 VkResult
radv_BindBufferMemory2(VkDevice device
,
3413 uint32_t bindInfoCount
,
3414 const VkBindBufferMemoryInfo
*pBindInfos
)
3416 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3417 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3418 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3421 buffer
->bo
= mem
->bo
;
3422 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3430 VkResult
radv_BindBufferMemory(
3433 VkDeviceMemory memory
,
3434 VkDeviceSize memoryOffset
)
3436 const VkBindBufferMemoryInfo info
= {
3437 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3440 .memoryOffset
= memoryOffset
3443 return radv_BindBufferMemory2(device
, 1, &info
);
3446 VkResult
radv_BindImageMemory2(VkDevice device
,
3447 uint32_t bindInfoCount
,
3448 const VkBindImageMemoryInfo
*pBindInfos
)
3450 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3451 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3452 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3455 image
->bo
= mem
->bo
;
3456 image
->offset
= pBindInfos
[i
].memoryOffset
;
3466 VkResult
radv_BindImageMemory(
3469 VkDeviceMemory memory
,
3470 VkDeviceSize memoryOffset
)
3472 const VkBindImageMemoryInfo info
= {
3473 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3476 .memoryOffset
= memoryOffset
3479 return radv_BindImageMemory2(device
, 1, &info
);
3484 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3485 const VkSparseBufferMemoryBindInfo
*bind
)
3487 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3489 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3490 struct radv_device_memory
*mem
= NULL
;
3492 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3493 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3495 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3496 bind
->pBinds
[i
].resourceOffset
,
3497 bind
->pBinds
[i
].size
,
3498 mem
? mem
->bo
: NULL
,
3499 bind
->pBinds
[i
].memoryOffset
);
3504 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3505 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3507 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3509 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3510 struct radv_device_memory
*mem
= NULL
;
3512 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3513 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3515 device
->ws
->buffer_virtual_bind(image
->bo
,
3516 bind
->pBinds
[i
].resourceOffset
,
3517 bind
->pBinds
[i
].size
,
3518 mem
? mem
->bo
: NULL
,
3519 bind
->pBinds
[i
].memoryOffset
);
3523 VkResult
radv_QueueBindSparse(
3525 uint32_t bindInfoCount
,
3526 const VkBindSparseInfo
* pBindInfo
,
3529 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3530 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3531 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3532 bool fence_emitted
= false;
3536 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3537 struct radv_winsys_sem_info sem_info
;
3538 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3539 radv_sparse_buffer_bind_memory(queue
->device
,
3540 pBindInfo
[i
].pBufferBinds
+ j
);
3543 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3544 radv_sparse_image_opaque_bind_memory(queue
->device
,
3545 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3549 result
= radv_alloc_sem_info(queue
->device
->instance
,
3551 pBindInfo
[i
].waitSemaphoreCount
,
3552 pBindInfo
[i
].pWaitSemaphores
,
3553 pBindInfo
[i
].signalSemaphoreCount
,
3554 pBindInfo
[i
].pSignalSemaphores
,
3556 if (result
!= VK_SUCCESS
)
3559 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3560 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3561 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3566 radv_loge("failed to submit CS %d\n", i
);
3570 fence_emitted
= true;
3572 fence
->submitted
= true;
3575 radv_free_sem_info(&sem_info
);
3580 if (!fence_emitted
) {
3581 result
= radv_signal_fence(queue
, fence
);
3582 if (result
!= VK_SUCCESS
)
3585 fence
->submitted
= true;
3591 VkResult
radv_CreateFence(
3593 const VkFenceCreateInfo
* pCreateInfo
,
3594 const VkAllocationCallbacks
* pAllocator
,
3597 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3598 const VkExportFenceCreateInfo
*export
=
3599 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3600 VkExternalFenceHandleTypeFlags handleTypes
=
3601 export
? export
->handleTypes
: 0;
3603 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3605 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3608 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3610 fence
->fence_wsi
= NULL
;
3611 fence
->submitted
= false;
3612 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3613 fence
->temp_syncobj
= 0;
3614 if (device
->always_use_syncobj
|| handleTypes
) {
3615 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3617 vk_free2(&device
->alloc
, pAllocator
, fence
);
3618 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3620 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3621 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3623 fence
->fence
= NULL
;
3625 fence
->fence
= device
->ws
->create_fence();
3626 if (!fence
->fence
) {
3627 vk_free2(&device
->alloc
, pAllocator
, fence
);
3628 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3633 *pFence
= radv_fence_to_handle(fence
);
3638 void radv_DestroyFence(
3641 const VkAllocationCallbacks
* pAllocator
)
3643 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3644 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3649 if (fence
->temp_syncobj
)
3650 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3652 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3654 device
->ws
->destroy_fence(fence
->fence
);
3655 if (fence
->fence_wsi
)
3656 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3657 vk_free2(&device
->alloc
, pAllocator
, fence
);
3661 uint64_t radv_get_current_time(void)
3664 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3665 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3668 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3670 uint64_t current_time
= radv_get_current_time();
3672 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3674 return current_time
+ timeout
;
3678 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3680 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3681 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3682 if (fence
->fence
== NULL
|| fence
->syncobj
||
3683 fence
->temp_syncobj
||
3684 (!fence
->signalled
&& !fence
->submitted
))
3690 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3692 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3693 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3694 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3700 VkResult
radv_WaitForFences(
3702 uint32_t fenceCount
,
3703 const VkFence
* pFences
,
3707 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3708 timeout
= radv_get_absolute_timeout(timeout
);
3710 if (device
->always_use_syncobj
&&
3711 radv_all_fences_syncobj(fenceCount
, pFences
))
3713 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3715 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3717 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3718 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3719 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3722 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3725 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3728 if (!waitAll
&& fenceCount
> 1) {
3729 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3730 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3731 uint32_t wait_count
= 0;
3732 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3734 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3736 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3737 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3739 if (fence
->signalled
) {
3744 fences
[wait_count
++] = fence
->fence
;
3747 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3748 waitAll
, timeout
- radv_get_current_time());
3751 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3754 while(radv_get_current_time() <= timeout
) {
3755 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3756 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3763 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3764 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3765 bool expired
= false;
3767 if (fence
->temp_syncobj
) {
3768 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3773 if (fence
->syncobj
) {
3774 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3779 if (fence
->signalled
)
3783 if (!fence
->submitted
) {
3784 while(radv_get_current_time() <= timeout
&&
3788 if (!fence
->submitted
)
3791 /* Recheck as it may have been set by
3792 * submitting operations. */
3794 if (fence
->signalled
)
3798 expired
= device
->ws
->fence_wait(device
->ws
,
3805 if (fence
->fence_wsi
) {
3806 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3807 if (result
!= VK_SUCCESS
)
3811 fence
->signalled
= true;
3817 VkResult
radv_ResetFences(VkDevice _device
,
3818 uint32_t fenceCount
,
3819 const VkFence
*pFences
)
3821 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3823 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3824 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3825 fence
->submitted
= fence
->signalled
= false;
3827 /* Per spec, we first restore the permanent payload, and then reset, so
3828 * having a temp syncobj should not skip resetting the permanent syncobj. */
3829 if (fence
->temp_syncobj
) {
3830 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3831 fence
->temp_syncobj
= 0;
3834 if (fence
->syncobj
) {
3835 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3842 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3844 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3845 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3847 if (fence
->temp_syncobj
) {
3848 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3849 return success
? VK_SUCCESS
: VK_NOT_READY
;
3852 if (fence
->syncobj
) {
3853 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3854 return success
? VK_SUCCESS
: VK_NOT_READY
;
3857 if (fence
->signalled
)
3859 if (!fence
->submitted
)
3860 return VK_NOT_READY
;
3862 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3863 return VK_NOT_READY
;
3865 if (fence
->fence_wsi
) {
3866 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
3868 if (result
!= VK_SUCCESS
) {
3869 if (result
== VK_TIMEOUT
)
3870 return VK_NOT_READY
;
3878 // Queue semaphore functions
3880 VkResult
radv_CreateSemaphore(
3882 const VkSemaphoreCreateInfo
* pCreateInfo
,
3883 const VkAllocationCallbacks
* pAllocator
,
3884 VkSemaphore
* pSemaphore
)
3886 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3887 const VkExportSemaphoreCreateInfo
*export
=
3888 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
3889 VkExternalSemaphoreHandleTypeFlags handleTypes
=
3890 export
? export
->handleTypes
: 0;
3892 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3894 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3896 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3898 sem
->temp_syncobj
= 0;
3899 /* create a syncobject if we are going to export this semaphore */
3900 if (device
->always_use_syncobj
|| handleTypes
) {
3901 assert (device
->physical_device
->rad_info
.has_syncobj
);
3902 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3904 vk_free2(&device
->alloc
, pAllocator
, sem
);
3905 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3909 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3911 vk_free2(&device
->alloc
, pAllocator
, sem
);
3912 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3917 *pSemaphore
= radv_semaphore_to_handle(sem
);
3921 void radv_DestroySemaphore(
3923 VkSemaphore _semaphore
,
3924 const VkAllocationCallbacks
* pAllocator
)
3926 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3927 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3932 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3934 device
->ws
->destroy_sem(sem
->sem
);
3935 vk_free2(&device
->alloc
, pAllocator
, sem
);
3938 VkResult
radv_CreateEvent(
3940 const VkEventCreateInfo
* pCreateInfo
,
3941 const VkAllocationCallbacks
* pAllocator
,
3944 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3945 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3947 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3950 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3952 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3954 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
3955 RADV_BO_PRIORITY_FENCE
);
3957 vk_free2(&device
->alloc
, pAllocator
, event
);
3958 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3961 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3963 *pEvent
= radv_event_to_handle(event
);
3968 void radv_DestroyEvent(
3971 const VkAllocationCallbacks
* pAllocator
)
3973 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3974 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3978 device
->ws
->buffer_destroy(event
->bo
);
3979 vk_free2(&device
->alloc
, pAllocator
, event
);
3982 VkResult
radv_GetEventStatus(
3986 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3988 if (*event
->map
== 1)
3989 return VK_EVENT_SET
;
3990 return VK_EVENT_RESET
;
3993 VkResult
radv_SetEvent(
3997 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4003 VkResult
radv_ResetEvent(
4007 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4013 VkResult
radv_CreateBuffer(
4015 const VkBufferCreateInfo
* pCreateInfo
,
4016 const VkAllocationCallbacks
* pAllocator
,
4019 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4020 struct radv_buffer
*buffer
;
4022 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4024 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4025 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4027 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4029 buffer
->size
= pCreateInfo
->size
;
4030 buffer
->usage
= pCreateInfo
->usage
;
4033 buffer
->flags
= pCreateInfo
->flags
;
4035 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4036 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4038 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4039 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4040 align64(buffer
->size
, 4096),
4041 4096, 0, RADEON_FLAG_VIRTUAL
,
4042 RADV_BO_PRIORITY_VIRTUAL
);
4044 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4045 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4049 *pBuffer
= radv_buffer_to_handle(buffer
);
4054 void radv_DestroyBuffer(
4057 const VkAllocationCallbacks
* pAllocator
)
4059 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4060 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4065 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4066 device
->ws
->buffer_destroy(buffer
->bo
);
4068 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4071 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4073 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4075 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4076 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4080 static inline unsigned
4081 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
4084 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4086 return image
->surface
.u
.legacy
.tiling_index
[level
];
4089 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4091 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4095 radv_init_dcc_control_reg(struct radv_device
*device
,
4096 struct radv_image_view
*iview
)
4098 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4099 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4100 unsigned max_compressed_block_size
;
4101 unsigned independent_64b_blocks
;
4103 if (!radv_image_has_dcc(iview
->image
))
4106 if (iview
->image
->info
.samples
> 1) {
4107 if (iview
->image
->surface
.bpe
== 1)
4108 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4109 else if (iview
->image
->surface
.bpe
== 2)
4110 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4113 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4114 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4115 * dGPU and 64 for APU because all of our APUs to date use
4116 * DIMMs which have a request granularity size of 64B while all
4117 * other chips have a 32B request size.
4119 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4122 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4123 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4124 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4125 /* If this DCC image is potentially going to be used in texture
4126 * fetches, we need some special settings.
4128 independent_64b_blocks
= 1;
4129 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4131 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4132 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4133 * big as possible for better compression state.
4135 independent_64b_blocks
= 0;
4136 max_compressed_block_size
= max_uncompressed_block_size
;
4139 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4140 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4141 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4142 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
4146 radv_initialise_color_surface(struct radv_device
*device
,
4147 struct radv_color_buffer_info
*cb
,
4148 struct radv_image_view
*iview
)
4150 const struct vk_format_description
*desc
;
4151 unsigned ntype
, format
, swap
, endian
;
4152 unsigned blend_clamp
= 0, blend_bypass
= 0;
4154 const struct radeon_surf
*surf
= &iview
->image
->surface
;
4156 desc
= vk_format_description(iview
->vk_format
);
4158 memset(cb
, 0, sizeof(*cb
));
4160 /* Intensity is implemented as Red, so treat it that way. */
4161 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4163 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4165 cb
->cb_color_base
= va
>> 8;
4167 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4168 struct gfx9_surf_meta_flags meta
;
4169 if (iview
->image
->dcc_offset
)
4170 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
4172 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
4174 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
4175 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
4176 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4177 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4179 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
4180 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
4182 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4183 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4185 cb
->cb_color_base
+= level_info
->offset
>> 8;
4186 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4187 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
4189 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4190 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4191 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
4193 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4194 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4195 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
4197 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4199 if (radv_image_has_fmask(iview
->image
)) {
4200 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4201 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
4202 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4203 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4205 /* This must be set for fast clear to work without FMASK. */
4206 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4207 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4208 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4209 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4213 /* CMASK variables */
4214 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4215 va
+= iview
->image
->cmask
.offset
;
4216 cb
->cb_color_cmask
= va
>> 8;
4218 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4219 va
+= iview
->image
->dcc_offset
;
4220 cb
->cb_dcc_base
= va
>> 8;
4221 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
4223 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4224 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4225 S_028C6C_SLICE_MAX(max_slice
);
4227 if (iview
->image
->info
.samples
> 1) {
4228 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4230 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4231 S_028C74_NUM_FRAGMENTS(log_samples
);
4234 if (radv_image_has_fmask(iview
->image
)) {
4235 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4236 cb
->cb_color_fmask
= va
>> 8;
4237 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4239 cb
->cb_color_fmask
= cb
->cb_color_base
;
4242 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4244 vk_format_get_first_non_void_channel(iview
->vk_format
));
4245 format
= radv_translate_colorformat(iview
->vk_format
);
4246 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4247 radv_finishme("Illegal color\n");
4248 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4249 endian
= radv_colorformat_endian_swap(format
);
4251 /* blend clamp should be set for all NORM/SRGB types */
4252 if (ntype
== V_028C70_NUMBER_UNORM
||
4253 ntype
== V_028C70_NUMBER_SNORM
||
4254 ntype
== V_028C70_NUMBER_SRGB
)
4257 /* set blend bypass according to docs if SINT/UINT or
4258 8/24 COLOR variants */
4259 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4260 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4261 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4266 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4267 (format
== V_028C70_COLOR_8
||
4268 format
== V_028C70_COLOR_8_8
||
4269 format
== V_028C70_COLOR_8_8_8_8
))
4270 ->color_is_int8
= true;
4272 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4273 S_028C70_COMP_SWAP(swap
) |
4274 S_028C70_BLEND_CLAMP(blend_clamp
) |
4275 S_028C70_BLEND_BYPASS(blend_bypass
) |
4276 S_028C70_SIMPLE_FLOAT(1) |
4277 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4278 ntype
!= V_028C70_NUMBER_SNORM
&&
4279 ntype
!= V_028C70_NUMBER_SRGB
&&
4280 format
!= V_028C70_COLOR_8_24
&&
4281 format
!= V_028C70_COLOR_24_8
) |
4282 S_028C70_NUMBER_TYPE(ntype
) |
4283 S_028C70_ENDIAN(endian
);
4284 if (radv_image_has_fmask(iview
->image
)) {
4285 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4286 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
4287 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4288 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4292 if (radv_image_has_cmask(iview
->image
) &&
4293 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4294 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4296 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4297 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4299 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4301 /* This must be set for fast clear to work without FMASK. */
4302 if (!radv_image_has_fmask(iview
->image
) &&
4303 device
->physical_device
->rad_info
.chip_class
== SI
) {
4304 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
4305 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4308 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4309 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4310 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4312 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
4313 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4314 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
4315 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
4316 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
4317 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4322 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4323 struct radv_image_view
*iview
)
4325 unsigned max_zplanes
= 0;
4327 assert(radv_image_is_tc_compat_htile(iview
->image
));
4329 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4330 /* Default value for 32-bit depth surfaces. */
4333 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4334 iview
->image
->info
.samples
> 1)
4337 max_zplanes
= max_zplanes
+ 1;
4339 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4340 /* Do not enable Z plane compression for 16-bit depth
4341 * surfaces because isn't supported on GFX8. Only
4342 * 32-bit depth surfaces are supported by the hardware.
4343 * This allows to maintain shader compatibility and to
4344 * reduce the number of depth decompressions.
4348 if (iview
->image
->info
.samples
<= 1)
4350 else if (iview
->image
->info
.samples
<= 4)
4361 radv_initialise_ds_surface(struct radv_device
*device
,
4362 struct radv_ds_buffer_info
*ds
,
4363 struct radv_image_view
*iview
)
4365 unsigned level
= iview
->base_mip
;
4366 unsigned format
, stencil_format
;
4367 uint64_t va
, s_offs
, z_offs
;
4368 bool stencil_only
= false;
4369 memset(ds
, 0, sizeof(*ds
));
4370 switch (iview
->image
->vk_format
) {
4371 case VK_FORMAT_D24_UNORM_S8_UINT
:
4372 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4373 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4374 ds
->offset_scale
= 2.0f
;
4376 case VK_FORMAT_D16_UNORM
:
4377 case VK_FORMAT_D16_UNORM_S8_UINT
:
4378 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4379 ds
->offset_scale
= 4.0f
;
4381 case VK_FORMAT_D32_SFLOAT
:
4382 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4383 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4384 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4385 ds
->offset_scale
= 1.0f
;
4387 case VK_FORMAT_S8_UINT
:
4388 stencil_only
= true;
4394 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4395 stencil_format
= iview
->image
->surface
.has_stencil
?
4396 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4398 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4399 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4400 S_028008_SLICE_MAX(max_slice
);
4402 ds
->db_htile_data_base
= 0;
4403 ds
->db_htile_surface
= 0;
4405 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4406 s_offs
= z_offs
= va
;
4408 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4409 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
4410 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
4412 ds
->db_z_info
= S_028038_FORMAT(format
) |
4413 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4414 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
4415 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4416 S_028038_ZRANGE_PRECISION(1);
4417 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4418 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
4420 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
4421 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
4422 ds
->db_depth_view
|= S_028008_MIPID(level
);
4424 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4425 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4427 if (radv_htile_enabled(iview
->image
, level
)) {
4428 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4430 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4431 unsigned max_zplanes
=
4432 radv_calc_decompress_on_z_planes(device
, iview
);
4434 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4435 S_028038_ITERATE_FLUSH(1);
4436 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4439 if (!iview
->image
->surface
.has_stencil
)
4440 /* Use all of the htile_buffer for depth if there's no stencil. */
4441 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4442 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4443 iview
->image
->htile_offset
;
4444 ds
->db_htile_data_base
= va
>> 8;
4445 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4446 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4447 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4450 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4453 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4455 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4456 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4458 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4459 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4460 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4462 if (iview
->image
->info
.samples
> 1)
4463 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4465 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4466 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4467 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4468 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4469 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4470 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4471 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4472 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4475 tile_mode
= stencil_tile_mode
;
4477 ds
->db_depth_info
|=
4478 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4479 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4480 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4481 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4482 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4483 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4484 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4485 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4487 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4488 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4489 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4490 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4492 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4495 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4496 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4497 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4499 if (radv_htile_enabled(iview
->image
, level
)) {
4500 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4502 if (!iview
->image
->surface
.has_stencil
&&
4503 !radv_image_is_tc_compat_htile(iview
->image
))
4504 /* Use all of the htile_buffer for depth if there's no stencil. */
4505 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4507 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4508 iview
->image
->htile_offset
;
4509 ds
->db_htile_data_base
= va
>> 8;
4510 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4512 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4513 unsigned max_zplanes
=
4514 radv_calc_decompress_on_z_planes(device
, iview
);
4516 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4517 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4522 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4523 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4526 VkResult
radv_CreateFramebuffer(
4528 const VkFramebufferCreateInfo
* pCreateInfo
,
4529 const VkAllocationCallbacks
* pAllocator
,
4530 VkFramebuffer
* pFramebuffer
)
4532 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4533 struct radv_framebuffer
*framebuffer
;
4535 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4537 size_t size
= sizeof(*framebuffer
) +
4538 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4539 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4540 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4541 if (framebuffer
== NULL
)
4542 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4544 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4545 framebuffer
->width
= pCreateInfo
->width
;
4546 framebuffer
->height
= pCreateInfo
->height
;
4547 framebuffer
->layers
= pCreateInfo
->layers
;
4548 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4549 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4550 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4551 framebuffer
->attachments
[i
].attachment
= iview
;
4552 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4553 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4554 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4555 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4557 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4558 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4559 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4562 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4566 void radv_DestroyFramebuffer(
4569 const VkAllocationCallbacks
* pAllocator
)
4571 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4572 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4576 vk_free2(&device
->alloc
, pAllocator
, fb
);
4579 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4581 switch (address_mode
) {
4582 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4583 return V_008F30_SQ_TEX_WRAP
;
4584 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4585 return V_008F30_SQ_TEX_MIRROR
;
4586 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4587 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4588 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4589 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4590 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4591 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4593 unreachable("illegal tex wrap mode");
4599 radv_tex_compare(VkCompareOp op
)
4602 case VK_COMPARE_OP_NEVER
:
4603 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4604 case VK_COMPARE_OP_LESS
:
4605 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4606 case VK_COMPARE_OP_EQUAL
:
4607 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4608 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4609 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4610 case VK_COMPARE_OP_GREATER
:
4611 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4612 case VK_COMPARE_OP_NOT_EQUAL
:
4613 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4614 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4615 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4616 case VK_COMPARE_OP_ALWAYS
:
4617 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4619 unreachable("illegal compare mode");
4625 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4628 case VK_FILTER_NEAREST
:
4629 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4630 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4631 case VK_FILTER_LINEAR
:
4632 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4633 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4634 case VK_FILTER_CUBIC_IMG
:
4636 fprintf(stderr
, "illegal texture filter");
4642 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4645 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4646 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4647 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4648 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4650 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4655 radv_tex_bordercolor(VkBorderColor bcolor
)
4658 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4659 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4660 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4661 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4662 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4663 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4664 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4665 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4666 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4674 radv_tex_aniso_filter(unsigned filter
)
4688 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4691 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4692 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4693 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4694 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
4695 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4696 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
4704 radv_get_max_anisotropy(struct radv_device
*device
,
4705 const VkSamplerCreateInfo
*pCreateInfo
)
4707 if (device
->force_aniso
>= 0)
4708 return device
->force_aniso
;
4710 if (pCreateInfo
->anisotropyEnable
&&
4711 pCreateInfo
->maxAnisotropy
> 1.0f
)
4712 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4718 radv_init_sampler(struct radv_device
*device
,
4719 struct radv_sampler
*sampler
,
4720 const VkSamplerCreateInfo
*pCreateInfo
)
4722 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4723 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4724 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4725 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4727 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4728 vk_find_struct_const(pCreateInfo
->pNext
,
4729 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4730 if (sampler_reduction
)
4731 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4733 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4734 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4735 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4736 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4737 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4738 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4739 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4740 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4741 S_008F30_DISABLE_CUBE_WRAP(0) |
4742 S_008F30_COMPAT_MODE(is_vi
) |
4743 S_008F30_FILTER_MODE(filter_mode
));
4744 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4745 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4746 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4747 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4748 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4749 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4750 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4751 S_008F38_MIP_POINT_PRECLAMP(0) |
4752 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4753 S_008F38_FILTER_PREC_FIX(1) |
4754 S_008F38_ANISO_OVERRIDE(is_vi
));
4755 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4756 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4759 VkResult
radv_CreateSampler(
4761 const VkSamplerCreateInfo
* pCreateInfo
,
4762 const VkAllocationCallbacks
* pAllocator
,
4763 VkSampler
* pSampler
)
4765 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4766 struct radv_sampler
*sampler
;
4768 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4770 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4771 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4773 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4775 radv_init_sampler(device
, sampler
, pCreateInfo
);
4776 *pSampler
= radv_sampler_to_handle(sampler
);
4781 void radv_DestroySampler(
4784 const VkAllocationCallbacks
* pAllocator
)
4786 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4787 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4791 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4794 /* vk_icd.h does not declare this function, so we declare it here to
4795 * suppress Wmissing-prototypes.
4797 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4798 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4800 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4801 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4803 /* For the full details on loader interface versioning, see
4804 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4805 * What follows is a condensed summary, to help you navigate the large and
4806 * confusing official doc.
4808 * - Loader interface v0 is incompatible with later versions. We don't
4811 * - In loader interface v1:
4812 * - The first ICD entrypoint called by the loader is
4813 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4815 * - The ICD must statically expose no other Vulkan symbol unless it is
4816 * linked with -Bsymbolic.
4817 * - Each dispatchable Vulkan handle created by the ICD must be
4818 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4819 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4820 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4821 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4822 * such loader-managed surfaces.
4824 * - Loader interface v2 differs from v1 in:
4825 * - The first ICD entrypoint called by the loader is
4826 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4827 * statically expose this entrypoint.
4829 * - Loader interface v3 differs from v2 in:
4830 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4831 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4832 * because the loader no longer does so.
4834 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4838 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4839 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4842 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4843 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4845 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4847 /* At the moment, we support only the below handle types. */
4848 assert(pGetFdInfo
->handleType
==
4849 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
4850 pGetFdInfo
->handleType
==
4851 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4853 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4855 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4859 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4860 VkExternalMemoryHandleTypeFlagBits handleType
,
4862 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4864 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4866 switch (handleType
) {
4867 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4868 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4872 /* The valid usage section for this function says:
4874 * "handleType must not be one of the handle types defined as
4877 * So opaque handle types fall into the default "unsupported" case.
4879 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4883 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4887 uint32_t syncobj_handle
= 0;
4888 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4890 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4893 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4895 *syncobj
= syncobj_handle
;
4901 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4905 /* If we create a syncobj we do it locally so that if we have an error, we don't
4906 * leave a syncobj in an undetermined state in the fence. */
4907 uint32_t syncobj_handle
= *syncobj
;
4908 if (!syncobj_handle
) {
4909 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4911 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4916 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4918 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4920 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4923 *syncobj
= syncobj_handle
;
4930 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4931 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4933 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4934 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4935 uint32_t *syncobj_dst
= NULL
;
4937 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
4938 syncobj_dst
= &sem
->temp_syncobj
;
4940 syncobj_dst
= &sem
->syncobj
;
4943 switch(pImportSemaphoreFdInfo
->handleType
) {
4944 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
4945 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4946 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
4947 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4949 unreachable("Unhandled semaphore handle type");
4953 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4954 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4957 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4958 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4960 uint32_t syncobj_handle
;
4962 if (sem
->temp_syncobj
)
4963 syncobj_handle
= sem
->temp_syncobj
;
4965 syncobj_handle
= sem
->syncobj
;
4967 switch(pGetFdInfo
->handleType
) {
4968 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
4969 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4971 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
4972 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4974 if (sem
->temp_syncobj
) {
4975 close (sem
->temp_syncobj
);
4976 sem
->temp_syncobj
= 0;
4978 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4983 unreachable("Unhandled semaphore handle type");
4987 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4991 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4992 VkPhysicalDevice physicalDevice
,
4993 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
4994 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
4996 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4998 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4999 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5000 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5001 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5002 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5003 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5004 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5005 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5006 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5007 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5008 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5009 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5010 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5012 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5013 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5014 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5018 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5019 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5021 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5022 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5023 uint32_t *syncobj_dst
= NULL
;
5026 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5027 syncobj_dst
= &fence
->temp_syncobj
;
5029 syncobj_dst
= &fence
->syncobj
;
5032 switch(pImportFenceFdInfo
->handleType
) {
5033 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5034 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5035 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5036 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5038 unreachable("Unhandled fence handle type");
5042 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5043 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5046 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5047 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5049 uint32_t syncobj_handle
;
5051 if (fence
->temp_syncobj
)
5052 syncobj_handle
= fence
->temp_syncobj
;
5054 syncobj_handle
= fence
->syncobj
;
5056 switch(pGetFdInfo
->handleType
) {
5057 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5058 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5060 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5061 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5063 if (fence
->temp_syncobj
) {
5064 close (fence
->temp_syncobj
);
5065 fence
->temp_syncobj
= 0;
5067 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5072 unreachable("Unhandled fence handle type");
5076 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5080 void radv_GetPhysicalDeviceExternalFenceProperties(
5081 VkPhysicalDevice physicalDevice
,
5082 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5083 VkExternalFenceProperties
*pExternalFenceProperties
)
5085 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5087 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5088 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5089 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5090 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5091 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5092 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5093 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5095 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5096 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5097 pExternalFenceProperties
->externalFenceFeatures
= 0;
5102 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5103 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5104 const VkAllocationCallbacks
* pAllocator
,
5105 VkDebugReportCallbackEXT
* pCallback
)
5107 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5108 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5109 pCreateInfo
, pAllocator
, &instance
->alloc
,
5114 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5115 VkDebugReportCallbackEXT _callback
,
5116 const VkAllocationCallbacks
* pAllocator
)
5118 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5119 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5120 _callback
, pAllocator
, &instance
->alloc
);
5124 radv_DebugReportMessageEXT(VkInstance _instance
,
5125 VkDebugReportFlagsEXT flags
,
5126 VkDebugReportObjectTypeEXT objectType
,
5129 int32_t messageCode
,
5130 const char* pLayerPrefix
,
5131 const char* pMessage
)
5133 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5134 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5135 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5139 radv_GetDeviceGroupPeerMemoryFeatures(
5142 uint32_t localDeviceIndex
,
5143 uint32_t remoteDeviceIndex
,
5144 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5146 assert(localDeviceIndex
== remoteDeviceIndex
);
5148 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5149 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5150 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5151 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5154 static const VkTimeDomainEXT radv_time_domains
[] = {
5155 VK_TIME_DOMAIN_DEVICE_EXT
,
5156 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5157 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5160 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5161 VkPhysicalDevice physicalDevice
,
5162 uint32_t *pTimeDomainCount
,
5163 VkTimeDomainEXT
*pTimeDomains
)
5166 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5168 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5169 vk_outarray_append(&out
, i
) {
5170 *i
= radv_time_domains
[d
];
5174 return vk_outarray_status(&out
);
5178 radv_clock_gettime(clockid_t clock_id
)
5180 struct timespec current
;
5183 ret
= clock_gettime(clock_id
, ¤t
);
5184 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5185 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5189 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5192 VkResult
radv_GetCalibratedTimestampsEXT(
5194 uint32_t timestampCount
,
5195 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5196 uint64_t *pTimestamps
,
5197 uint64_t *pMaxDeviation
)
5199 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5200 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5202 uint64_t begin
, end
;
5203 uint64_t max_clock_period
= 0;
5205 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5207 for (d
= 0; d
< timestampCount
; d
++) {
5208 switch (pTimestampInfos
[d
].timeDomain
) {
5209 case VK_TIME_DOMAIN_DEVICE_EXT
:
5210 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5212 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5213 max_clock_period
= MAX2(max_clock_period
, device_period
);
5215 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5216 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5217 max_clock_period
= MAX2(max_clock_period
, 1);
5220 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5221 pTimestamps
[d
] = begin
;
5229 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5232 * The maximum deviation is the sum of the interval over which we
5233 * perform the sampling and the maximum period of any sampled
5234 * clock. That's because the maximum skew between any two sampled
5235 * clock edges is when the sampled clock with the largest period is
5236 * sampled at the end of that period but right at the beginning of the
5237 * sampling interval and some other clock is sampled right at the
5238 * begining of its sampling period and right at the end of the
5239 * sampling interval. Let's assume the GPU has the longest clock
5240 * period and that the application is sampling GPU and monotonic:
5243 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5244 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5248 * GPU -----_____-----_____-----_____-----_____
5251 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5252 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5254 * Interval <----------------->
5255 * Deviation <-------------------------->
5259 * m = read(monotonic) 2
5262 * We round the sample interval up by one tick to cover sampling error
5263 * in the interval clock
5266 uint64_t sample_interval
= end
- begin
+ 1;
5268 *pMaxDeviation
= sample_interval
+ max_clock_period
;