2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "util/build_id.h"
48 #include "util/debug.h"
49 #include "util/mesa-sha1.h"
50 #include "compiler/glsl_types.h"
51 #include "util/xmlpool.h"
54 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
57 unsigned char sha1
[20];
58 unsigned ptr_size
= sizeof(void*);
60 memset(uuid
, 0, VK_UUID_SIZE
);
61 _mesa_sha1_init(&ctx
);
63 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
64 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
67 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
68 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
69 _mesa_sha1_final(&ctx
, sha1
);
71 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
76 radv_get_driver_uuid(void *uuid
)
78 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
82 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
84 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
88 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
90 const char *chip_string
;
93 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
94 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
95 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
96 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
97 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
98 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
99 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
100 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
101 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; 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_VEGA20
: chip_string
= "AMD RADV VEGA20"; break;
114 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
115 case CHIP_RAVEN2
: chip_string
= "AMD RADV RAVEN2"; break;
116 case CHIP_NAVI10
: chip_string
= "AMD RADV NAVI10"; break;
117 case CHIP_NAVI12
: chip_string
= "AMD RADV NAVI12"; break;
118 case CHIP_NAVI14
: chip_string
= "AMD RADV NAVI14"; break;
119 default: chip_string
= "AMD RADV unknown"; break;
122 snprintf(name
, name_len
, "%s (LLVM " MESA_LLVM_VERSION_STRING
")", chip_string
);
126 radv_get_visible_vram_size(struct radv_physical_device
*device
)
128 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
132 radv_get_vram_size(struct radv_physical_device
*device
)
134 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
138 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
140 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
141 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
142 uint64_t vram_size
= radv_get_vram_size(device
);
143 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
144 device
->memory_properties
.memoryHeapCount
= 0;
146 vram_index
= device
->memory_properties
.memoryHeapCount
++;
147 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
149 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
152 if (visible_vram_size
) {
153 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
154 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
155 .size
= visible_vram_size
,
156 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
159 if (device
->rad_info
.gart_size
> 0) {
160 gart_index
= device
->memory_properties
.memoryHeapCount
++;
161 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
162 .size
= device
->rad_info
.gart_size
,
163 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
167 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
168 unsigned type_count
= 0;
169 if (vram_index
>= 0) {
170 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
171 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
172 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
173 .heapIndex
= vram_index
,
176 if (gart_index
>= 0) {
177 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
178 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
179 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
181 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
182 .heapIndex
= gart_index
,
185 if (visible_vram_index
>= 0) {
186 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
187 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
188 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
189 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
190 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
191 .heapIndex
= visible_vram_index
,
194 if (gart_index
>= 0) {
195 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
196 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
197 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
198 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
199 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
200 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
201 .heapIndex
= gart_index
,
204 device
->memory_properties
.memoryTypeCount
= type_count
;
208 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
210 const char *family
= getenv("RADV_FORCE_FAMILY");
216 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
217 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
218 /* Override family and chip_class. */
219 device
->rad_info
.family
= i
;
221 if (i
>= CHIP_NAVI10
)
222 device
->rad_info
.chip_class
= GFX10
;
223 else if (i
>= CHIP_VEGA10
)
224 device
->rad_info
.chip_class
= GFX9
;
225 else if (i
>= CHIP_TONGA
)
226 device
->rad_info
.chip_class
= GFX8
;
227 else if (i
>= CHIP_BONAIRE
)
228 device
->rad_info
.chip_class
= GFX7
;
230 device
->rad_info
.chip_class
= GFX6
;
236 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
241 radv_physical_device_init(struct radv_physical_device
*device
,
242 struct radv_instance
*instance
,
243 drmDevicePtr drm_device
)
245 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
247 drmVersionPtr version
;
251 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
253 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
254 radv_logi("Could not open device '%s'", path
);
256 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
259 version
= drmGetVersion(fd
);
263 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
264 radv_logi("Could not get the kernel driver version for device '%s'", path
);
266 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
267 "failed to get version %s: %m", path
);
270 if (strcmp(version
->name
, "amdgpu")) {
271 drmFreeVersion(version
);
274 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
275 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
277 return VK_ERROR_INCOMPATIBLE_DRIVER
;
279 drmFreeVersion(version
);
281 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
282 radv_logi("Found compatible device '%s'.", path
);
284 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
285 device
->instance
= instance
;
287 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
288 instance
->perftest_flags
);
290 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
294 if (instance
->enabled_extensions
.KHR_display
) {
295 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
296 if (master_fd
>= 0) {
297 uint32_t accel_working
= 0;
298 struct drm_amdgpu_info request
= {
299 .return_pointer
= (uintptr_t)&accel_working
,
300 .return_size
= sizeof(accel_working
),
301 .query
= AMDGPU_INFO_ACCEL_WORKING
304 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
311 device
->master_fd
= master_fd
;
312 device
->local_fd
= fd
;
313 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
315 radv_handle_env_var_force_family(device
);
317 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
319 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
320 device
->ws
->destroy(device
->ws
);
321 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
322 "cannot generate UUID");
326 /* These flags affect shader compilation. */
327 uint64_t shader_env_flags
=
328 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
329 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
331 /* The gpu id is already embedded in the uuid so we just pass "radv"
332 * when creating the cache.
334 char buf
[VK_UUID_SIZE
* 2 + 1];
335 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
336 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
338 if (device
->rad_info
.chip_class
< GFX8
||
339 device
->rad_info
.chip_class
> GFX9
)
340 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
342 radv_get_driver_uuid(&device
->driver_uuid
);
343 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
345 if (device
->rad_info
.family
== CHIP_STONEY
||
346 device
->rad_info
.chip_class
>= GFX9
) {
347 device
->has_rbplus
= true;
348 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
349 device
->rad_info
.family
== CHIP_VEGA12
||
350 device
->rad_info
.family
== CHIP_RAVEN
||
351 device
->rad_info
.family
== CHIP_RAVEN2
;
354 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
357 device
->has_clear_state
= device
->rad_info
.chip_class
>= GFX7
;
359 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= GFX8
;
361 /* Vega10/Raven need a special workaround for a hardware bug. */
362 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
363 device
->rad_info
.family
== CHIP_RAVEN
;
365 device
->has_tc_compat_zrange_bug
= device
->rad_info
.chip_class
< GFX10
;
367 /* Out-of-order primitive rasterization. */
368 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= GFX8
&&
369 device
->rad_info
.max_se
>= 2;
370 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
371 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
373 device
->dcc_msaa_allowed
=
374 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
376 /* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
377 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
378 (device
->rad_info
.chip_class
>= GFX8
&&
379 device
->rad_info
.me_fw_feature
>= 41);
381 device
->has_dcc_constant_encode
= device
->rad_info
.family
== CHIP_RAVEN2
||
382 device
->rad_info
.chip_class
>= GFX10
;
384 device
->use_shader_ballot
= device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
;
386 /* Determine the number of threads per wave for all stages. */
387 device
->cs_wave_size
= 64;
388 device
->ps_wave_size
= 64;
389 device
->ge_wave_size
= 64;
391 if (device
->rad_info
.chip_class
>= GFX10
) {
392 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
393 device
->cs_wave_size
= 32;
395 /* For pixel shaders, wave64 is recommanded. */
396 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
397 device
->ps_wave_size
= 32;
399 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
400 device
->ge_wave_size
= 32;
403 radv_physical_device_init_mem_types(device
);
404 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
406 device
->bus_info
= *drm_device
->businfo
.pci
;
408 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
409 ac_print_gpu_info(&device
->rad_info
);
411 /* The WSI is structured as a layer on top of the driver, so this has
412 * to be the last part of initialization (at least until we get other
415 result
= radv_init_wsi(device
);
416 if (result
!= VK_SUCCESS
) {
417 device
->ws
->destroy(device
->ws
);
418 vk_error(instance
, result
);
432 radv_physical_device_finish(struct radv_physical_device
*device
)
434 radv_finish_wsi(device
);
435 device
->ws
->destroy(device
->ws
);
436 disk_cache_destroy(device
->disk_cache
);
437 close(device
->local_fd
);
438 if (device
->master_fd
!= -1)
439 close(device
->master_fd
);
443 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
444 VkSystemAllocationScope allocationScope
)
450 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
451 size_t align
, VkSystemAllocationScope allocationScope
)
453 return realloc(pOriginal
, size
);
457 default_free_func(void *pUserData
, void *pMemory
)
462 static const VkAllocationCallbacks default_alloc
= {
464 .pfnAllocation
= default_alloc_func
,
465 .pfnReallocation
= default_realloc_func
,
466 .pfnFree
= default_free_func
,
469 static const struct debug_control radv_debug_options
[] = {
470 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
471 {"nodcc", RADV_DEBUG_NO_DCC
},
472 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
473 {"nocache", RADV_DEBUG_NO_CACHE
},
474 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
475 {"nohiz", RADV_DEBUG_NO_HIZ
},
476 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
477 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
478 {"allbos", RADV_DEBUG_ALL_BOS
},
479 {"noibs", RADV_DEBUG_NO_IBS
},
480 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
481 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
482 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
483 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
484 {"nosisched", RADV_DEBUG_NO_SISCHED
},
485 {"preoptir", RADV_DEBUG_PREOPTIR
},
486 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
487 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
488 {"info", RADV_DEBUG_INFO
},
489 {"errors", RADV_DEBUG_ERRORS
},
490 {"startup", RADV_DEBUG_STARTUP
},
491 {"checkir", RADV_DEBUG_CHECKIR
},
492 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
493 {"nobinning", RADV_DEBUG_NOBINNING
},
494 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
495 {"nongg", RADV_DEBUG_NO_NGG
},
500 radv_get_debug_option_name(int id
)
502 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
503 return radv_debug_options
[id
].string
;
506 static const struct debug_control radv_perftest_options
[] = {
507 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
508 {"sisched", RADV_PERFTEST_SISCHED
},
509 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
510 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
511 {"bolist", RADV_PERFTEST_BO_LIST
},
512 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
513 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
514 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
515 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
516 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
521 radv_get_perftest_option_name(int id
)
523 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
524 return radv_perftest_options
[id
].string
;
528 radv_handle_per_app_options(struct radv_instance
*instance
,
529 const VkApplicationInfo
*info
)
531 const char *name
= info
? info
->pApplicationName
: NULL
;
536 if (!strcmp(name
, "Talos - Linux - 32bit") ||
537 !strcmp(name
, "Talos - Linux - 64bit")) {
538 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
539 /* Force enable LLVM sisched for Talos because it looks
540 * safe and it gives few more FPS.
542 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
544 } else if (!strcmp(name
, "DOOM_VFR")) {
545 /* Work around a Doom VFR game bug */
546 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
547 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
548 /* Workaround for a WaW hazard when LLVM moves/merges
549 * load/store memory operations.
550 * See https://reviews.llvm.org/D61313
552 if (HAVE_LLVM
< 0x900)
553 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
557 static int radv_get_instance_extension_index(const char *name
)
559 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
560 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
566 static const char radv_dri_options_xml
[] =
568 DRI_CONF_SECTION_QUALITY
569 DRI_CONF_ADAPTIVE_SYNC("true")
573 static void radv_init_dri_options(struct radv_instance
*instance
)
575 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
576 driParseConfigFiles(&instance
->dri_options
,
577 &instance
->available_dri_options
,
581 VkResult
radv_CreateInstance(
582 const VkInstanceCreateInfo
* pCreateInfo
,
583 const VkAllocationCallbacks
* pAllocator
,
584 VkInstance
* pInstance
)
586 struct radv_instance
*instance
;
589 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
591 uint32_t client_version
;
592 if (pCreateInfo
->pApplicationInfo
&&
593 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
594 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
596 client_version
= VK_API_VERSION_1_0
;
599 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
600 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
602 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
604 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
607 instance
->alloc
= *pAllocator
;
609 instance
->alloc
= default_alloc
;
611 instance
->apiVersion
= client_version
;
612 instance
->physicalDeviceCount
= -1;
614 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
617 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
618 radv_perftest_options
);
621 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
622 radv_logi("Created an instance");
624 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
625 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
626 int index
= radv_get_instance_extension_index(ext_name
);
628 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
629 vk_free2(&default_alloc
, pAllocator
, instance
);
630 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
633 instance
->enabled_extensions
.extensions
[index
] = true;
636 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
637 if (result
!= VK_SUCCESS
) {
638 vk_free2(&default_alloc
, pAllocator
, instance
);
639 return vk_error(instance
, result
);
643 glsl_type_singleton_init_or_ref();
645 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
647 radv_init_dri_options(instance
);
648 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
650 *pInstance
= radv_instance_to_handle(instance
);
655 void radv_DestroyInstance(
656 VkInstance _instance
,
657 const VkAllocationCallbacks
* pAllocator
)
659 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
664 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
665 radv_physical_device_finish(instance
->physicalDevices
+ i
);
668 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
670 glsl_type_singleton_decref();
673 driDestroyOptionCache(&instance
->dri_options
);
674 driDestroyOptionInfo(&instance
->available_dri_options
);
676 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
678 vk_free(&instance
->alloc
, instance
);
682 radv_enumerate_devices(struct radv_instance
*instance
)
684 /* TODO: Check for more devices ? */
685 drmDevicePtr devices
[8];
686 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
689 instance
->physicalDeviceCount
= 0;
691 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
693 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
694 radv_logi("Found %d drm nodes", max_devices
);
697 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
699 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
700 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
701 devices
[i
]->bustype
== DRM_BUS_PCI
&&
702 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
704 result
= radv_physical_device_init(instance
->physicalDevices
+
705 instance
->physicalDeviceCount
,
708 if (result
== VK_SUCCESS
)
709 ++instance
->physicalDeviceCount
;
710 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
714 drmFreeDevices(devices
, max_devices
);
719 VkResult
radv_EnumeratePhysicalDevices(
720 VkInstance _instance
,
721 uint32_t* pPhysicalDeviceCount
,
722 VkPhysicalDevice
* pPhysicalDevices
)
724 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
727 if (instance
->physicalDeviceCount
< 0) {
728 result
= radv_enumerate_devices(instance
);
729 if (result
!= VK_SUCCESS
&&
730 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
734 if (!pPhysicalDevices
) {
735 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
737 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
738 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
739 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
742 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
746 VkResult
radv_EnumeratePhysicalDeviceGroups(
747 VkInstance _instance
,
748 uint32_t* pPhysicalDeviceGroupCount
,
749 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
751 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
754 if (instance
->physicalDeviceCount
< 0) {
755 result
= radv_enumerate_devices(instance
);
756 if (result
!= VK_SUCCESS
&&
757 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
761 if (!pPhysicalDeviceGroupProperties
) {
762 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
764 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
765 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
766 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
767 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
768 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
771 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
775 void radv_GetPhysicalDeviceFeatures(
776 VkPhysicalDevice physicalDevice
,
777 VkPhysicalDeviceFeatures
* pFeatures
)
779 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
780 memset(pFeatures
, 0, sizeof(*pFeatures
));
782 *pFeatures
= (VkPhysicalDeviceFeatures
) {
783 .robustBufferAccess
= true,
784 .fullDrawIndexUint32
= true,
785 .imageCubeArray
= true,
786 .independentBlend
= true,
787 .geometryShader
= true,
788 .tessellationShader
= true,
789 .sampleRateShading
= true,
790 .dualSrcBlend
= true,
792 .multiDrawIndirect
= true,
793 .drawIndirectFirstInstance
= true,
795 .depthBiasClamp
= true,
796 .fillModeNonSolid
= true,
801 .multiViewport
= true,
802 .samplerAnisotropy
= true,
803 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
804 .textureCompressionASTC_LDR
= false,
805 .textureCompressionBC
= true,
806 .occlusionQueryPrecise
= true,
807 .pipelineStatisticsQuery
= true,
808 .vertexPipelineStoresAndAtomics
= true,
809 .fragmentStoresAndAtomics
= true,
810 .shaderTessellationAndGeometryPointSize
= true,
811 .shaderImageGatherExtended
= true,
812 .shaderStorageImageExtendedFormats
= true,
813 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
814 .shaderUniformBufferArrayDynamicIndexing
= true,
815 .shaderSampledImageArrayDynamicIndexing
= true,
816 .shaderStorageBufferArrayDynamicIndexing
= true,
817 .shaderStorageImageArrayDynamicIndexing
= true,
818 .shaderStorageImageReadWithoutFormat
= true,
819 .shaderStorageImageWriteWithoutFormat
= true,
820 .shaderClipDistance
= true,
821 .shaderCullDistance
= true,
822 .shaderFloat64
= true,
824 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
825 .sparseBinding
= true,
826 .variableMultisampleRate
= true,
827 .inheritedQueries
= true,
831 void radv_GetPhysicalDeviceFeatures2(
832 VkPhysicalDevice physicalDevice
,
833 VkPhysicalDeviceFeatures2
*pFeatures
)
835 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
836 vk_foreach_struct(ext
, pFeatures
->pNext
) {
837 switch (ext
->sType
) {
838 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
839 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
840 features
->variablePointersStorageBuffer
= true;
841 features
->variablePointers
= true;
844 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
845 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
846 features
->multiview
= true;
847 features
->multiviewGeometryShader
= true;
848 features
->multiviewTessellationShader
= true;
851 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
852 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
853 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
854 features
->shaderDrawParameters
= true;
857 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
858 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
859 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
860 features
->protectedMemory
= false;
863 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
864 VkPhysicalDevice16BitStorageFeatures
*features
=
865 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
866 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
867 features
->storageBuffer16BitAccess
= enabled
;
868 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
869 features
->storagePushConstant16
= enabled
;
870 features
->storageInputOutput16
= enabled
&& HAVE_LLVM
>= 0x900;
873 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
874 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
875 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
876 features
->samplerYcbcrConversion
= true;
879 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
880 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
881 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
882 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
883 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
884 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
885 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
886 features
->shaderSampledImageArrayNonUniformIndexing
= true;
887 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
888 features
->shaderStorageImageArrayNonUniformIndexing
= true;
889 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
890 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
891 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
892 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
893 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
894 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
895 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
896 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
897 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
898 features
->descriptorBindingUpdateUnusedWhilePending
= true;
899 features
->descriptorBindingPartiallyBound
= true;
900 features
->descriptorBindingVariableDescriptorCount
= true;
901 features
->runtimeDescriptorArray
= true;
904 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
905 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
906 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
907 features
->conditionalRendering
= true;
908 features
->inheritedConditionalRendering
= false;
911 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
912 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
913 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
914 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
915 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
918 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
919 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
920 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
921 features
->transformFeedback
= true;
922 features
->geometryStreams
= true;
925 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
926 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
927 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
928 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
932 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
933 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
934 features
->memoryPriority
= VK_TRUE
;
937 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
938 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
939 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
940 features
->bufferDeviceAddress
= true;
941 features
->bufferDeviceAddressCaptureReplay
= false;
942 features
->bufferDeviceAddressMultiDevice
= false;
945 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
946 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
947 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
948 features
->depthClipEnable
= true;
951 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
952 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
953 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
954 features
->hostQueryReset
= true;
957 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
958 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
959 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
960 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
961 features
->storageBuffer8BitAccess
= enabled
;
962 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
963 features
->storagePushConstant8
= enabled
;
966 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
967 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
968 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
969 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& HAVE_LLVM
>= 0x0800;
970 features
->shaderInt8
= true;
973 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
974 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
975 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
976 features
->shaderBufferInt64Atomics
= HAVE_LLVM
>= 0x0900;
977 features
->shaderSharedInt64Atomics
= HAVE_LLVM
>= 0x0900;
980 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
981 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
982 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
984 features
->inlineUniformBlock
= true;
985 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
988 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
989 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
990 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
991 features
->computeDerivativeGroupQuads
= false;
992 features
->computeDerivativeGroupLinear
= true;
995 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
996 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
997 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
998 features
->ycbcrImageArrays
= true;
1001 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1002 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1003 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1004 features
->uniformBufferStandardLayout
= true;
1007 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1008 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1009 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1010 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1017 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1020 void radv_GetPhysicalDeviceProperties(
1021 VkPhysicalDevice physicalDevice
,
1022 VkPhysicalDeviceProperties
* pProperties
)
1024 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1025 VkSampleCountFlags sample_counts
= 0xf;
1027 /* make sure that the entire descriptor set is addressable with a signed
1028 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1029 * be at most 2 GiB. the combined image & samples object count as one of
1030 * both. This limit is for the pipeline layout, not for the set layout, but
1031 * there is no set limit, so we just set a pipeline limit. I don't think
1032 * any app is going to hit this soon. */
1033 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1034 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1035 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1036 32 /* sampler, largest when combined with image */ +
1037 64 /* sampled image */ +
1038 64 /* storage image */);
1040 VkPhysicalDeviceLimits limits
= {
1041 .maxImageDimension1D
= (1 << 14),
1042 .maxImageDimension2D
= (1 << 14),
1043 .maxImageDimension3D
= (1 << 11),
1044 .maxImageDimensionCube
= (1 << 14),
1045 .maxImageArrayLayers
= (1 << 11),
1046 .maxTexelBufferElements
= 128 * 1024 * 1024,
1047 .maxUniformBufferRange
= UINT32_MAX
,
1048 .maxStorageBufferRange
= UINT32_MAX
,
1049 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1050 .maxMemoryAllocationCount
= UINT32_MAX
,
1051 .maxSamplerAllocationCount
= 64 * 1024,
1052 .bufferImageGranularity
= 64, /* A cache line */
1053 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1054 .maxBoundDescriptorSets
= MAX_SETS
,
1055 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1056 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1057 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1058 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1059 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1060 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1061 .maxPerStageResources
= max_descriptor_set_size
,
1062 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1063 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1064 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1065 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1066 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1067 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1068 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1069 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1070 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1071 .maxVertexInputBindings
= MAX_VBS
,
1072 .maxVertexInputAttributeOffset
= 2047,
1073 .maxVertexInputBindingStride
= 2048,
1074 .maxVertexOutputComponents
= 128,
1075 .maxTessellationGenerationLevel
= 64,
1076 .maxTessellationPatchSize
= 32,
1077 .maxTessellationControlPerVertexInputComponents
= 128,
1078 .maxTessellationControlPerVertexOutputComponents
= 128,
1079 .maxTessellationControlPerPatchOutputComponents
= 120,
1080 .maxTessellationControlTotalOutputComponents
= 4096,
1081 .maxTessellationEvaluationInputComponents
= 128,
1082 .maxTessellationEvaluationOutputComponents
= 128,
1083 .maxGeometryShaderInvocations
= 127,
1084 .maxGeometryInputComponents
= 64,
1085 .maxGeometryOutputComponents
= 128,
1086 .maxGeometryOutputVertices
= 256,
1087 .maxGeometryTotalOutputComponents
= 1024,
1088 .maxFragmentInputComponents
= 128,
1089 .maxFragmentOutputAttachments
= 8,
1090 .maxFragmentDualSrcAttachments
= 1,
1091 .maxFragmentCombinedOutputResources
= 8,
1092 .maxComputeSharedMemorySize
= 32768,
1093 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1094 .maxComputeWorkGroupInvocations
= 2048,
1095 .maxComputeWorkGroupSize
= {
1100 .subPixelPrecisionBits
= 8,
1101 .subTexelPrecisionBits
= 8,
1102 .mipmapPrecisionBits
= 8,
1103 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1104 .maxDrawIndirectCount
= UINT32_MAX
,
1105 .maxSamplerLodBias
= 16,
1106 .maxSamplerAnisotropy
= 16,
1107 .maxViewports
= MAX_VIEWPORTS
,
1108 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1109 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1110 .viewportSubPixelBits
= 8,
1111 .minMemoryMapAlignment
= 4096, /* A page */
1112 .minTexelBufferOffsetAlignment
= 1,
1113 .minUniformBufferOffsetAlignment
= 4,
1114 .minStorageBufferOffsetAlignment
= 4,
1115 .minTexelOffset
= -32,
1116 .maxTexelOffset
= 31,
1117 .minTexelGatherOffset
= -32,
1118 .maxTexelGatherOffset
= 31,
1119 .minInterpolationOffset
= -2,
1120 .maxInterpolationOffset
= 2,
1121 .subPixelInterpolationOffsetBits
= 8,
1122 .maxFramebufferWidth
= (1 << 14),
1123 .maxFramebufferHeight
= (1 << 14),
1124 .maxFramebufferLayers
= (1 << 10),
1125 .framebufferColorSampleCounts
= sample_counts
,
1126 .framebufferDepthSampleCounts
= sample_counts
,
1127 .framebufferStencilSampleCounts
= sample_counts
,
1128 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1129 .maxColorAttachments
= MAX_RTS
,
1130 .sampledImageColorSampleCounts
= sample_counts
,
1131 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1132 .sampledImageDepthSampleCounts
= sample_counts
,
1133 .sampledImageStencilSampleCounts
= sample_counts
,
1134 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1135 .maxSampleMaskWords
= 1,
1136 .timestampComputeAndGraphics
= true,
1137 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1138 .maxClipDistances
= 8,
1139 .maxCullDistances
= 8,
1140 .maxCombinedClipAndCullDistances
= 8,
1141 .discreteQueuePriorities
= 2,
1142 .pointSizeRange
= { 0.0, 8192.0 },
1143 .lineWidthRange
= { 0.0, 7.9921875 },
1144 .pointSizeGranularity
= (1.0 / 8.0),
1145 .lineWidthGranularity
= (1.0 / 128.0),
1146 .strictLines
= false, /* FINISHME */
1147 .standardSampleLocations
= true,
1148 .optimalBufferCopyOffsetAlignment
= 128,
1149 .optimalBufferCopyRowPitchAlignment
= 128,
1150 .nonCoherentAtomSize
= 64,
1153 *pProperties
= (VkPhysicalDeviceProperties
) {
1154 .apiVersion
= radv_physical_device_api_version(pdevice
),
1155 .driverVersion
= vk_get_driver_version(),
1156 .vendorID
= ATI_VENDOR_ID
,
1157 .deviceID
= pdevice
->rad_info
.pci_id
,
1158 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1160 .sparseProperties
= {0},
1163 strcpy(pProperties
->deviceName
, pdevice
->name
);
1164 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1167 void radv_GetPhysicalDeviceProperties2(
1168 VkPhysicalDevice physicalDevice
,
1169 VkPhysicalDeviceProperties2
*pProperties
)
1171 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1172 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1174 vk_foreach_struct(ext
, pProperties
->pNext
) {
1175 switch (ext
->sType
) {
1176 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1177 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1178 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1179 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1182 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1183 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1184 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1185 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1186 properties
->deviceLUIDValid
= false;
1189 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1190 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1191 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1192 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1195 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1196 VkPhysicalDevicePointClippingProperties
*properties
=
1197 (VkPhysicalDevicePointClippingProperties
*)ext
;
1198 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1201 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1202 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1203 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1204 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1207 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1208 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1209 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1210 properties
->minImportedHostPointerAlignment
= 4096;
1213 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1214 VkPhysicalDeviceSubgroupProperties
*properties
=
1215 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1216 properties
->subgroupSize
= 64;
1217 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1218 properties
->supportedOperations
=
1219 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1220 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1221 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1222 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1223 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1224 properties
->supportedOperations
|=
1225 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1226 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1227 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1229 properties
->quadOperationsInAllStages
= true;
1232 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1233 VkPhysicalDeviceMaintenance3Properties
*properties
=
1234 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1235 /* Make sure everything is addressable by a signed 32-bit int, and
1236 * our largest descriptors are 96 bytes. */
1237 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1238 /* Our buffer size fields allow only this much */
1239 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1242 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1243 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1244 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1245 /* GFX6-8 only support single channel min/max filter. */
1246 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1247 properties
->filterMinmaxSingleComponentFormats
= true;
1250 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1251 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1252 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1254 /* Shader engines. */
1255 properties
->shaderEngineCount
=
1256 pdevice
->rad_info
.max_se
;
1257 properties
->shaderArraysPerEngineCount
=
1258 pdevice
->rad_info
.max_sh_per_se
;
1259 properties
->computeUnitsPerShaderArray
=
1260 pdevice
->rad_info
.num_good_cu_per_sh
;
1261 properties
->simdPerComputeUnit
= 4;
1262 properties
->wavefrontsPerSimd
=
1263 pdevice
->rad_info
.family
== CHIP_TONGA
||
1264 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1265 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1266 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1267 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1268 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1269 properties
->wavefrontSize
= 64;
1272 properties
->sgprsPerSimd
=
1273 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1274 properties
->minSgprAllocation
=
1275 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1276 properties
->maxSgprAllocation
=
1277 pdevice
->rad_info
.family
== CHIP_TONGA
||
1278 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1279 properties
->sgprAllocationGranularity
=
1280 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1283 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1284 properties
->minVgprAllocation
= 4;
1285 properties
->maxVgprAllocation
= 256;
1286 properties
->vgprAllocationGranularity
= 4;
1289 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1290 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1291 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1292 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1295 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1296 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1297 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1298 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1299 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1300 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1301 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1302 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1303 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1304 properties
->robustBufferAccessUpdateAfterBind
= false;
1305 properties
->quadDivergentImplicitLod
= false;
1307 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1308 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1309 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1310 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1311 32 /* sampler, largest when combined with image */ +
1312 64 /* sampled image */ +
1313 64 /* storage image */);
1314 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1315 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1316 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1317 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1318 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1319 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1320 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1321 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1322 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1323 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1324 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1325 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1326 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1327 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1328 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1331 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1332 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1333 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1334 properties
->protectedNoFault
= false;
1337 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1338 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1339 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1340 properties
->primitiveOverestimationSize
= 0;
1341 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1342 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1343 properties
->primitiveUnderestimation
= VK_FALSE
;
1344 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1345 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1346 properties
->degenerateLinesRasterized
= VK_FALSE
;
1347 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1348 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1351 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1352 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1353 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1354 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1355 properties
->pciBus
= pdevice
->bus_info
.bus
;
1356 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1357 properties
->pciFunction
= pdevice
->bus_info
.func
;
1360 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1361 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1362 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1364 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1365 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
, "radv");
1366 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1367 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1368 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1370 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1378 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1379 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1380 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1381 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1382 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1383 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1384 properties
->maxTransformFeedbackStreamDataSize
= 512;
1385 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1386 properties
->maxTransformFeedbackBufferDataStride
= 512;
1387 properties
->transformFeedbackQueries
= true;
1388 properties
->transformFeedbackStreamsLinesTriangles
= true;
1389 properties
->transformFeedbackRasterizationStreamSelect
= false;
1390 properties
->transformFeedbackDraw
= true;
1393 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1394 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1395 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1397 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1398 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1399 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1400 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1401 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1404 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1405 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1406 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1407 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1408 VK_SAMPLE_COUNT_4_BIT
|
1409 VK_SAMPLE_COUNT_8_BIT
;
1410 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1411 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1412 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1413 properties
->sampleLocationSubPixelBits
= 4;
1414 properties
->variableSampleLocations
= VK_FALSE
;
1417 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1418 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1419 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1421 /* We support all of the depth resolve modes */
1422 properties
->supportedDepthResolveModes
=
1423 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1424 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1425 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1426 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1428 /* Average doesn't make sense for stencil so we don't support that */
1429 properties
->supportedStencilResolveModes
=
1430 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1431 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1432 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1434 properties
->independentResolveNone
= VK_TRUE
;
1435 properties
->independentResolve
= VK_TRUE
;
1444 static void radv_get_physical_device_queue_family_properties(
1445 struct radv_physical_device
* pdevice
,
1447 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1449 int num_queue_families
= 1;
1451 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1452 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1453 num_queue_families
++;
1455 if (pQueueFamilyProperties
== NULL
) {
1456 *pCount
= num_queue_families
;
1465 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1466 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1467 VK_QUEUE_COMPUTE_BIT
|
1468 VK_QUEUE_TRANSFER_BIT
|
1469 VK_QUEUE_SPARSE_BINDING_BIT
,
1471 .timestampValidBits
= 64,
1472 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1477 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1478 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1479 if (*pCount
> idx
) {
1480 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1481 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1482 VK_QUEUE_TRANSFER_BIT
|
1483 VK_QUEUE_SPARSE_BINDING_BIT
,
1484 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1485 .timestampValidBits
= 64,
1486 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1494 void radv_GetPhysicalDeviceQueueFamilyProperties(
1495 VkPhysicalDevice physicalDevice
,
1497 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1499 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1500 if (!pQueueFamilyProperties
) {
1501 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1504 VkQueueFamilyProperties
*properties
[] = {
1505 pQueueFamilyProperties
+ 0,
1506 pQueueFamilyProperties
+ 1,
1507 pQueueFamilyProperties
+ 2,
1509 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1510 assert(*pCount
<= 3);
1513 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1514 VkPhysicalDevice physicalDevice
,
1516 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1518 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1519 if (!pQueueFamilyProperties
) {
1520 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1523 VkQueueFamilyProperties
*properties
[] = {
1524 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1525 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1526 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1528 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1529 assert(*pCount
<= 3);
1532 void radv_GetPhysicalDeviceMemoryProperties(
1533 VkPhysicalDevice physicalDevice
,
1534 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1536 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1538 *pMemoryProperties
= physical_device
->memory_properties
;
1542 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1543 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1545 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1546 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1547 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1548 uint64_t vram_size
= radv_get_vram_size(device
);
1549 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1550 uint64_t heap_budget
, heap_usage
;
1552 /* For all memory heaps, the computation of budget is as follow:
1553 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1555 * The Vulkan spec 1.1.97 says that the budget should include any
1556 * currently allocated device memory.
1558 * Note that the application heap usages are not really accurate (eg.
1559 * in presence of shared buffers).
1561 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1562 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1564 switch (device
->mem_type_indices
[i
]) {
1565 case RADV_MEM_TYPE_VRAM
:
1566 heap_usage
= device
->ws
->query_value(device
->ws
,
1567 RADEON_ALLOCATED_VRAM
);
1569 heap_budget
= vram_size
-
1570 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1573 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1574 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1576 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1577 heap_usage
= device
->ws
->query_value(device
->ws
,
1578 RADEON_ALLOCATED_VRAM_VIS
);
1580 heap_budget
= visible_vram_size
-
1581 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1584 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1585 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1587 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1588 heap_usage
= device
->ws
->query_value(device
->ws
,
1589 RADEON_ALLOCATED_GTT
);
1591 heap_budget
= gtt_size
-
1592 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1595 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1596 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1603 /* The heapBudget and heapUsage values must be zero for array elements
1604 * greater than or equal to
1605 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1607 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1608 memoryBudget
->heapBudget
[i
] = 0;
1609 memoryBudget
->heapUsage
[i
] = 0;
1613 void radv_GetPhysicalDeviceMemoryProperties2(
1614 VkPhysicalDevice physicalDevice
,
1615 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1617 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1618 &pMemoryProperties
->memoryProperties
);
1620 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1621 vk_find_struct(pMemoryProperties
->pNext
,
1622 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1624 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1627 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1629 VkExternalMemoryHandleTypeFlagBits handleType
,
1630 const void *pHostPointer
,
1631 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1633 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1637 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1638 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1639 uint32_t memoryTypeBits
= 0;
1640 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1641 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1642 memoryTypeBits
= (1 << i
);
1646 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1650 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1654 static enum radeon_ctx_priority
1655 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1657 /* Default to MEDIUM when a specific global priority isn't requested */
1659 return RADEON_CTX_PRIORITY_MEDIUM
;
1661 switch(pObj
->globalPriority
) {
1662 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1663 return RADEON_CTX_PRIORITY_REALTIME
;
1664 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1665 return RADEON_CTX_PRIORITY_HIGH
;
1666 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1667 return RADEON_CTX_PRIORITY_MEDIUM
;
1668 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1669 return RADEON_CTX_PRIORITY_LOW
;
1671 unreachable("Illegal global priority value");
1672 return RADEON_CTX_PRIORITY_INVALID
;
1677 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1678 uint32_t queue_family_index
, int idx
,
1679 VkDeviceQueueCreateFlags flags
,
1680 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1682 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1683 queue
->device
= device
;
1684 queue
->queue_family_index
= queue_family_index
;
1685 queue
->queue_idx
= idx
;
1686 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1687 queue
->flags
= flags
;
1689 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1691 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1697 radv_queue_finish(struct radv_queue
*queue
)
1700 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1702 if (queue
->initial_full_flush_preamble_cs
)
1703 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1704 if (queue
->initial_preamble_cs
)
1705 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1706 if (queue
->continue_preamble_cs
)
1707 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1708 if (queue
->descriptor_bo
)
1709 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1710 if (queue
->scratch_bo
)
1711 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1712 if (queue
->esgs_ring_bo
)
1713 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1714 if (queue
->gsvs_ring_bo
)
1715 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1716 if (queue
->tess_rings_bo
)
1717 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1718 if (queue
->compute_scratch_bo
)
1719 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1723 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1725 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1726 bo_list
->list
.count
= bo_list
->capacity
= 0;
1727 bo_list
->list
.bos
= NULL
;
1731 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1733 free(bo_list
->list
.bos
);
1734 pthread_mutex_destroy(&bo_list
->mutex
);
1737 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1738 struct radeon_winsys_bo
*bo
)
1740 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1745 if (unlikely(!device
->use_global_bo_list
))
1748 pthread_mutex_lock(&bo_list
->mutex
);
1749 if (bo_list
->list
.count
== bo_list
->capacity
) {
1750 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1751 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1754 pthread_mutex_unlock(&bo_list
->mutex
);
1755 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1758 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1759 bo_list
->capacity
= capacity
;
1762 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1763 pthread_mutex_unlock(&bo_list
->mutex
);
1767 static void radv_bo_list_remove(struct radv_device
*device
,
1768 struct radeon_winsys_bo
*bo
)
1770 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1775 if (unlikely(!device
->use_global_bo_list
))
1778 pthread_mutex_lock(&bo_list
->mutex
);
1779 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1780 if (bo_list
->list
.bos
[i
] == bo
) {
1781 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1782 --bo_list
->list
.count
;
1786 pthread_mutex_unlock(&bo_list
->mutex
);
1790 radv_device_init_gs_info(struct radv_device
*device
)
1792 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1793 device
->physical_device
->rad_info
.family
);
1796 static int radv_get_device_extension_index(const char *name
)
1798 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1799 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1806 radv_get_int_debug_option(const char *name
, int default_value
)
1813 result
= default_value
;
1817 result
= strtol(str
, &endptr
, 0);
1818 if (str
== endptr
) {
1819 /* No digits founs. */
1820 result
= default_value
;
1827 VkResult
radv_CreateDevice(
1828 VkPhysicalDevice physicalDevice
,
1829 const VkDeviceCreateInfo
* pCreateInfo
,
1830 const VkAllocationCallbacks
* pAllocator
,
1833 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1835 struct radv_device
*device
;
1837 bool keep_shader_info
= false;
1839 /* Check enabled features */
1840 if (pCreateInfo
->pEnabledFeatures
) {
1841 VkPhysicalDeviceFeatures supported_features
;
1842 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1843 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1844 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1845 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1846 for (uint32_t i
= 0; i
< num_features
; i
++) {
1847 if (enabled_feature
[i
] && !supported_feature
[i
])
1848 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1852 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1854 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1856 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1858 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1859 device
->instance
= physical_device
->instance
;
1860 device
->physical_device
= physical_device
;
1862 device
->ws
= physical_device
->ws
;
1864 device
->alloc
= *pAllocator
;
1866 device
->alloc
= physical_device
->instance
->alloc
;
1868 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1869 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1870 int index
= radv_get_device_extension_index(ext_name
);
1871 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1872 vk_free(&device
->alloc
, device
);
1873 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1876 device
->enabled_extensions
.extensions
[index
] = true;
1879 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1881 /* With update after bind we can't attach bo's to the command buffer
1882 * from the descriptor set anymore, so we have to use a global BO list.
1884 device
->use_global_bo_list
=
1885 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1886 device
->enabled_extensions
.EXT_descriptor_indexing
||
1887 device
->enabled_extensions
.EXT_buffer_device_address
;
1889 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1890 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1892 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1893 list_inithead(&device
->shader_slabs
);
1895 radv_bo_list_init(&device
->bo_list
);
1897 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1898 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1899 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1900 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1901 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1903 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1905 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1906 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1907 if (!device
->queues
[qfi
]) {
1908 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1912 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1914 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1916 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1917 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1918 qfi
, q
, queue_create
->flags
,
1920 if (result
!= VK_SUCCESS
)
1925 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1926 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1928 /* Disabled and not implemented for now. */
1929 device
->dfsm_allowed
= device
->pbb_allowed
&&
1930 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1931 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
);
1934 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1937 /* The maximum number of scratch waves. Scratch space isn't divided
1938 * evenly between CUs. The number is only a function of the number of CUs.
1939 * We can decrease the constant to decrease the scratch buffer size.
1941 * sctx->scratch_waves must be >= the maximum possible size of
1942 * 1 threadgroup, so that the hw doesn't hang from being unable
1945 * The recommended value is 4 per CU at most. Higher numbers don't
1946 * bring much benefit, but they still occupy chip resources (think
1947 * async compute). I've seen ~2% performance difference between 4 and 32.
1949 uint32_t max_threads_per_block
= 2048;
1950 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1951 max_threads_per_block
/ 64);
1953 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
1954 S_00B800_CS_W32_EN(device
->physical_device
->cs_wave_size
== 32);
1956 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
1957 /* If the KMD allows it (there is a KMD hw register for it),
1958 * allow launching waves out-of-order.
1960 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1963 radv_device_init_gs_info(device
);
1965 device
->tess_offchip_block_dw_size
=
1966 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1967 device
->has_distributed_tess
=
1968 device
->physical_device
->rad_info
.chip_class
>= GFX8
&&
1969 device
->physical_device
->rad_info
.max_se
>= 2;
1971 if (getenv("RADV_TRACE_FILE")) {
1972 const char *filename
= getenv("RADV_TRACE_FILE");
1974 keep_shader_info
= true;
1976 if (!radv_init_trace(device
))
1979 fprintf(stderr
, "*****************************************************************************\n");
1980 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1981 fprintf(stderr
, "*****************************************************************************\n");
1983 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1984 radv_dump_enabled_options(device
, stderr
);
1987 device
->keep_shader_info
= keep_shader_info
;
1989 result
= radv_device_init_meta(device
);
1990 if (result
!= VK_SUCCESS
)
1993 radv_device_init_msaa(device
);
1995 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1996 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1998 case RADV_QUEUE_GENERAL
:
1999 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2000 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
2001 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
2003 case RADV_QUEUE_COMPUTE
:
2004 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
2005 radeon_emit(device
->empty_cs
[family
], 0);
2008 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
2011 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
2012 cik_create_gfx_config(device
);
2014 VkPipelineCacheCreateInfo ci
;
2015 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
2018 ci
.pInitialData
= NULL
;
2019 ci
.initialDataSize
= 0;
2021 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
2023 if (result
!= VK_SUCCESS
)
2026 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
2028 device
->force_aniso
=
2029 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
2030 if (device
->force_aniso
>= 0) {
2031 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2032 1 << util_logbase2(device
->force_aniso
));
2035 *pDevice
= radv_device_to_handle(device
);
2039 radv_device_finish_meta(device
);
2041 radv_bo_list_finish(&device
->bo_list
);
2043 if (device
->trace_bo
)
2044 device
->ws
->buffer_destroy(device
->trace_bo
);
2046 if (device
->gfx_init
)
2047 device
->ws
->buffer_destroy(device
->gfx_init
);
2049 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2050 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2051 radv_queue_finish(&device
->queues
[i
][q
]);
2052 if (device
->queue_count
[i
])
2053 vk_free(&device
->alloc
, device
->queues
[i
]);
2056 vk_free(&device
->alloc
, device
);
2060 void radv_DestroyDevice(
2062 const VkAllocationCallbacks
* pAllocator
)
2064 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2069 if (device
->trace_bo
)
2070 device
->ws
->buffer_destroy(device
->trace_bo
);
2072 if (device
->gfx_init
)
2073 device
->ws
->buffer_destroy(device
->gfx_init
);
2075 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2076 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2077 radv_queue_finish(&device
->queues
[i
][q
]);
2078 if (device
->queue_count
[i
])
2079 vk_free(&device
->alloc
, device
->queues
[i
]);
2080 if (device
->empty_cs
[i
])
2081 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2083 radv_device_finish_meta(device
);
2085 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2086 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2088 radv_destroy_shader_slabs(device
);
2090 radv_bo_list_finish(&device
->bo_list
);
2091 vk_free(&device
->alloc
, device
);
2094 VkResult
radv_EnumerateInstanceLayerProperties(
2095 uint32_t* pPropertyCount
,
2096 VkLayerProperties
* pProperties
)
2098 if (pProperties
== NULL
) {
2099 *pPropertyCount
= 0;
2103 /* None supported at this time */
2104 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2107 VkResult
radv_EnumerateDeviceLayerProperties(
2108 VkPhysicalDevice physicalDevice
,
2109 uint32_t* pPropertyCount
,
2110 VkLayerProperties
* pProperties
)
2112 if (pProperties
== NULL
) {
2113 *pPropertyCount
= 0;
2117 /* None supported at this time */
2118 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2121 void radv_GetDeviceQueue2(
2123 const VkDeviceQueueInfo2
* pQueueInfo
,
2126 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2127 struct radv_queue
*queue
;
2129 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2130 if (pQueueInfo
->flags
!= queue
->flags
) {
2131 /* From the Vulkan 1.1.70 spec:
2133 * "The queue returned by vkGetDeviceQueue2 must have the same
2134 * flags value from this structure as that used at device
2135 * creation time in a VkDeviceQueueCreateInfo instance. If no
2136 * matching flags were specified at device creation time then
2137 * pQueue will return VK_NULL_HANDLE."
2139 *pQueue
= VK_NULL_HANDLE
;
2143 *pQueue
= radv_queue_to_handle(queue
);
2146 void radv_GetDeviceQueue(
2148 uint32_t queueFamilyIndex
,
2149 uint32_t queueIndex
,
2152 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2153 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2154 .queueFamilyIndex
= queueFamilyIndex
,
2155 .queueIndex
= queueIndex
2158 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2162 fill_geom_tess_rings(struct radv_queue
*queue
,
2164 bool add_sample_positions
,
2165 uint32_t esgs_ring_size
,
2166 struct radeon_winsys_bo
*esgs_ring_bo
,
2167 uint32_t gsvs_ring_size
,
2168 struct radeon_winsys_bo
*gsvs_ring_bo
,
2169 uint32_t tess_factor_ring_size
,
2170 uint32_t tess_offchip_ring_offset
,
2171 uint32_t tess_offchip_ring_size
,
2172 struct radeon_winsys_bo
*tess_rings_bo
)
2174 uint32_t *desc
= &map
[4];
2177 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2179 /* stride 0, num records - size, add tid, swizzle, elsize4,
2182 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2183 S_008F04_SWIZZLE_ENABLE(true);
2184 desc
[2] = esgs_ring_size
;
2185 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2186 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2187 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2188 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2189 S_008F0C_INDEX_STRIDE(3) |
2190 S_008F0C_ADD_TID_ENABLE(1);
2192 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2193 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2194 S_008F0C_OOB_SELECT(2) |
2195 S_008F0C_RESOURCE_LEVEL(1);
2197 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2198 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2199 S_008F0C_ELEMENT_SIZE(1);
2202 /* GS entry for ES->GS ring */
2203 /* stride 0, num records - size, elsize0,
2206 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
2207 desc
[6] = esgs_ring_size
;
2208 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2209 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2210 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2211 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2213 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2214 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2215 S_008F0C_OOB_SELECT(2) |
2216 S_008F0C_RESOURCE_LEVEL(1);
2218 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2219 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2226 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2228 /* VS entry for GS->VS ring */
2229 /* stride 0, num records - size, elsize0,
2232 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
2233 desc
[2] = gsvs_ring_size
;
2234 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2235 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2236 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2237 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2239 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2240 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2241 S_008F0C_OOB_SELECT(2) |
2242 S_008F0C_RESOURCE_LEVEL(1);
2244 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2245 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2248 /* stride gsvs_itemsize, num records 64
2249 elsize 4, index stride 16 */
2250 /* shader will patch stride and desc[2] */
2252 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
2253 S_008F04_SWIZZLE_ENABLE(1);
2255 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2256 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2257 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2258 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2259 S_008F0C_INDEX_STRIDE(1) |
2260 S_008F0C_ADD_TID_ENABLE(true);
2262 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2263 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2264 S_008F0C_OOB_SELECT(2) |
2265 S_008F0C_RESOURCE_LEVEL(1);
2267 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2268 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2269 S_008F0C_ELEMENT_SIZE(1);
2276 if (tess_rings_bo
) {
2277 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2278 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2281 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
2282 desc
[2] = tess_factor_ring_size
;
2283 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2284 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2285 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2286 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2288 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2289 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2290 S_008F0C_OOB_SELECT(3) |
2291 S_008F0C_RESOURCE_LEVEL(1);
2293 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2294 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2297 desc
[4] = tess_offchip_va
;
2298 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
2299 desc
[6] = tess_offchip_ring_size
;
2300 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2301 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2302 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2303 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2305 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2306 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2307 S_008F0C_OOB_SELECT(3) |
2308 S_008F0C_RESOURCE_LEVEL(1);
2310 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2311 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2317 if (add_sample_positions
) {
2318 /* add sample positions after all rings */
2319 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2321 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2323 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2325 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2330 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2332 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2333 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2334 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2335 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2336 unsigned max_offchip_buffers
;
2337 unsigned offchip_granularity
;
2338 unsigned hs_offchip_param
;
2342 * This must be one less than the maximum number due to a hw limitation.
2343 * Various hardware bugs need thGFX7
2346 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2347 * Gfx7 should limit max_offchip_buffers to 508
2348 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2350 * Follow AMDVLK here.
2352 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2353 max_offchip_buffers_per_se
= 256;
2354 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2355 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2356 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2357 --max_offchip_buffers_per_se
;
2359 max_offchip_buffers
= max_offchip_buffers_per_se
*
2360 device
->physical_device
->rad_info
.max_se
;
2362 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2363 * around by setting 4K granularity.
2365 if (device
->tess_offchip_block_dw_size
== 4096) {
2366 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2367 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2369 assert(device
->tess_offchip_block_dw_size
== 8192);
2370 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2373 switch (device
->physical_device
->rad_info
.chip_class
) {
2375 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2380 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2388 *max_offchip_buffers_p
= max_offchip_buffers
;
2389 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2390 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2391 --max_offchip_buffers
;
2393 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2394 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2397 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2399 return hs_offchip_param
;
2403 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2404 struct radeon_winsys_bo
*esgs_ring_bo
,
2405 uint32_t esgs_ring_size
,
2406 struct radeon_winsys_bo
*gsvs_ring_bo
,
2407 uint32_t gsvs_ring_size
)
2409 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2413 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2416 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2418 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2419 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2420 radeon_emit(cs
, esgs_ring_size
>> 8);
2421 radeon_emit(cs
, gsvs_ring_size
>> 8);
2423 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2424 radeon_emit(cs
, esgs_ring_size
>> 8);
2425 radeon_emit(cs
, gsvs_ring_size
>> 8);
2430 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2431 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2432 struct radeon_winsys_bo
*tess_rings_bo
)
2439 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2441 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2443 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2444 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2445 S_030938_SIZE(tf_ring_size
/ 4));
2446 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2449 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2450 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2451 S_030984_BASE_HI(tf_va
>> 40));
2452 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2453 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2454 S_030944_BASE_HI(tf_va
>> 40));
2456 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2459 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2460 S_008988_SIZE(tf_ring_size
/ 4));
2461 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2463 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2469 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2470 struct radeon_winsys_bo
*compute_scratch_bo
)
2472 uint64_t scratch_va
;
2474 if (!compute_scratch_bo
)
2477 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2479 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2481 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2482 radeon_emit(cs
, scratch_va
);
2483 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2484 S_008F04_SWIZZLE_ENABLE(1));
2488 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2489 struct radeon_cmdbuf
*cs
,
2490 struct radeon_winsys_bo
*descriptor_bo
)
2497 va
= radv_buffer_get_va(descriptor_bo
);
2499 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2501 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2502 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2503 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2504 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2505 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2507 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2508 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2511 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2512 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2513 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2514 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2515 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2517 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2518 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2522 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2523 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2524 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2525 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2526 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2527 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2529 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2530 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2537 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2539 struct radv_device
*device
= queue
->device
;
2541 if (device
->gfx_init
) {
2542 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2544 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2545 radeon_emit(cs
, va
);
2546 radeon_emit(cs
, va
>> 32);
2547 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2549 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2551 struct radv_physical_device
*physical_device
= device
->physical_device
;
2552 si_emit_graphics(physical_device
, cs
);
2557 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2559 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2560 si_emit_compute(physical_device
, cs
);
2564 radv_get_preamble_cs(struct radv_queue
*queue
,
2565 uint32_t scratch_size
,
2566 uint32_t compute_scratch_size
,
2567 uint32_t esgs_ring_size
,
2568 uint32_t gsvs_ring_size
,
2569 bool needs_tess_rings
,
2570 bool needs_sample_positions
,
2571 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2572 struct radeon_cmdbuf
**initial_preamble_cs
,
2573 struct radeon_cmdbuf
**continue_preamble_cs
)
2575 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2576 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2577 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2578 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2579 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2580 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2581 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2582 bool add_tess_rings
= false, add_sample_positions
= false;
2583 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2584 unsigned max_offchip_buffers
;
2585 unsigned hs_offchip_param
= 0;
2586 unsigned tess_offchip_ring_offset
;
2587 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2588 if (!queue
->has_tess_rings
) {
2589 if (needs_tess_rings
)
2590 add_tess_rings
= true;
2592 if (!queue
->has_sample_positions
) {
2593 if (needs_sample_positions
)
2594 add_sample_positions
= true;
2596 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2597 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2598 &max_offchip_buffers
);
2599 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2600 tess_offchip_ring_size
= max_offchip_buffers
*
2601 queue
->device
->tess_offchip_block_dw_size
* 4;
2603 if (scratch_size
<= queue
->scratch_size
&&
2604 compute_scratch_size
<= queue
->compute_scratch_size
&&
2605 esgs_ring_size
<= queue
->esgs_ring_size
&&
2606 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2607 !add_tess_rings
&& !add_sample_positions
&&
2608 queue
->initial_preamble_cs
) {
2609 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2610 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2611 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2612 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2613 *continue_preamble_cs
= NULL
;
2617 if (scratch_size
> queue
->scratch_size
) {
2618 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2623 RADV_BO_PRIORITY_SCRATCH
);
2627 scratch_bo
= queue
->scratch_bo
;
2629 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2630 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2631 compute_scratch_size
,
2635 RADV_BO_PRIORITY_SCRATCH
);
2636 if (!compute_scratch_bo
)
2640 compute_scratch_bo
= queue
->compute_scratch_bo
;
2642 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2643 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2648 RADV_BO_PRIORITY_SCRATCH
);
2652 esgs_ring_bo
= queue
->esgs_ring_bo
;
2653 esgs_ring_size
= queue
->esgs_ring_size
;
2656 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2657 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2662 RADV_BO_PRIORITY_SCRATCH
);
2666 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2667 gsvs_ring_size
= queue
->gsvs_ring_size
;
2670 if (add_tess_rings
) {
2671 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2672 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2676 RADV_BO_PRIORITY_SCRATCH
);
2680 tess_rings_bo
= queue
->tess_rings_bo
;
2683 if (scratch_bo
!= queue
->scratch_bo
||
2684 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2685 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2686 tess_rings_bo
!= queue
->tess_rings_bo
||
2687 add_sample_positions
) {
2689 if (gsvs_ring_bo
|| esgs_ring_bo
||
2690 tess_rings_bo
|| add_sample_positions
) {
2691 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2692 if (add_sample_positions
)
2693 size
+= 128; /* 64+32+16+8 = 120 bytes */
2695 else if (scratch_bo
)
2696 size
= 8; /* 2 dword */
2698 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2702 RADEON_FLAG_CPU_ACCESS
|
2703 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2704 RADEON_FLAG_READ_ONLY
,
2705 RADV_BO_PRIORITY_DESCRIPTOR
);
2709 descriptor_bo
= queue
->descriptor_bo
;
2711 if (descriptor_bo
!= queue
->descriptor_bo
) {
2712 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2715 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2716 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2717 S_008F04_SWIZZLE_ENABLE(1);
2718 map
[0] = scratch_va
;
2722 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2723 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2724 esgs_ring_size
, esgs_ring_bo
,
2725 gsvs_ring_size
, gsvs_ring_bo
,
2726 tess_factor_ring_size
,
2727 tess_offchip_ring_offset
,
2728 tess_offchip_ring_size
,
2731 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2734 for(int i
= 0; i
< 3; ++i
) {
2735 struct radeon_cmdbuf
*cs
= NULL
;
2736 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2737 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2744 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2746 /* Emit initial configuration. */
2747 switch (queue
->queue_family_index
) {
2748 case RADV_QUEUE_GENERAL
:
2749 radv_init_graphics_state(cs
, queue
);
2751 case RADV_QUEUE_COMPUTE
:
2752 radv_init_compute_state(cs
, queue
);
2754 case RADV_QUEUE_TRANSFER
:
2758 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2759 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2760 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2762 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2763 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2766 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2767 gsvs_ring_bo
, gsvs_ring_size
);
2768 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2769 tess_factor_ring_size
, tess_rings_bo
);
2770 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2771 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2774 si_cs_emit_cache_flush(cs
,
2775 queue
->device
->physical_device
->rad_info
.chip_class
,
2777 queue
->queue_family_index
== RING_COMPUTE
&&
2778 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2779 (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
)) |
2780 RADV_CMD_FLAG_INV_ICACHE
|
2781 RADV_CMD_FLAG_INV_SCACHE
|
2782 RADV_CMD_FLAG_INV_VCACHE
|
2783 RADV_CMD_FLAG_INV_L2
|
2784 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2785 } else if (i
== 1) {
2786 si_cs_emit_cache_flush(cs
,
2787 queue
->device
->physical_device
->rad_info
.chip_class
,
2789 queue
->queue_family_index
== RING_COMPUTE
&&
2790 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2791 RADV_CMD_FLAG_INV_ICACHE
|
2792 RADV_CMD_FLAG_INV_SCACHE
|
2793 RADV_CMD_FLAG_INV_VCACHE
|
2794 RADV_CMD_FLAG_INV_L2
|
2795 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2798 if (!queue
->device
->ws
->cs_finalize(cs
))
2802 if (queue
->initial_full_flush_preamble_cs
)
2803 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2805 if (queue
->initial_preamble_cs
)
2806 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2808 if (queue
->continue_preamble_cs
)
2809 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2811 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2812 queue
->initial_preamble_cs
= dest_cs
[1];
2813 queue
->continue_preamble_cs
= dest_cs
[2];
2815 if (scratch_bo
!= queue
->scratch_bo
) {
2816 if (queue
->scratch_bo
)
2817 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2818 queue
->scratch_bo
= scratch_bo
;
2819 queue
->scratch_size
= scratch_size
;
2822 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2823 if (queue
->compute_scratch_bo
)
2824 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2825 queue
->compute_scratch_bo
= compute_scratch_bo
;
2826 queue
->compute_scratch_size
= compute_scratch_size
;
2829 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2830 if (queue
->esgs_ring_bo
)
2831 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2832 queue
->esgs_ring_bo
= esgs_ring_bo
;
2833 queue
->esgs_ring_size
= esgs_ring_size
;
2836 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2837 if (queue
->gsvs_ring_bo
)
2838 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2839 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2840 queue
->gsvs_ring_size
= gsvs_ring_size
;
2843 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2844 queue
->tess_rings_bo
= tess_rings_bo
;
2845 queue
->has_tess_rings
= true;
2848 if (descriptor_bo
!= queue
->descriptor_bo
) {
2849 if (queue
->descriptor_bo
)
2850 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2852 queue
->descriptor_bo
= descriptor_bo
;
2855 if (add_sample_positions
)
2856 queue
->has_sample_positions
= true;
2858 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2859 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2860 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2861 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2862 *continue_preamble_cs
= NULL
;
2865 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2867 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2868 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2869 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2870 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2871 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2872 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2873 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2874 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2875 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2876 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2877 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2878 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2879 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2880 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2883 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2884 struct radv_winsys_sem_counts
*counts
,
2886 const VkSemaphore
*sems
,
2890 int syncobj_idx
= 0, sem_idx
= 0;
2892 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2895 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2896 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2898 if (sem
->temp_syncobj
|| sem
->syncobj
)
2899 counts
->syncobj_count
++;
2901 counts
->sem_count
++;
2904 if (_fence
!= VK_NULL_HANDLE
) {
2905 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2906 if (fence
->temp_syncobj
|| fence
->syncobj
)
2907 counts
->syncobj_count
++;
2910 if (counts
->syncobj_count
) {
2911 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2912 if (!counts
->syncobj
)
2913 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2916 if (counts
->sem_count
) {
2917 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2919 free(counts
->syncobj
);
2920 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2924 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2925 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2927 if (sem
->temp_syncobj
) {
2928 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2930 else if (sem
->syncobj
)
2931 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2934 counts
->sem
[sem_idx
++] = sem
->sem
;
2938 if (_fence
!= VK_NULL_HANDLE
) {
2939 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2940 if (fence
->temp_syncobj
)
2941 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2942 else if (fence
->syncobj
)
2943 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2950 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2952 free(sem_info
->wait
.syncobj
);
2953 free(sem_info
->wait
.sem
);
2954 free(sem_info
->signal
.syncobj
);
2955 free(sem_info
->signal
.sem
);
2959 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2961 const VkSemaphore
*sems
)
2963 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2964 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2966 if (sem
->temp_syncobj
) {
2967 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2968 sem
->temp_syncobj
= 0;
2974 radv_alloc_sem_info(struct radv_instance
*instance
,
2975 struct radv_winsys_sem_info
*sem_info
,
2977 const VkSemaphore
*wait_sems
,
2978 int num_signal_sems
,
2979 const VkSemaphore
*signal_sems
,
2983 memset(sem_info
, 0, sizeof(*sem_info
));
2985 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2988 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2990 radv_free_sem_info(sem_info
);
2992 /* caller can override these */
2993 sem_info
->cs_emit_wait
= true;
2994 sem_info
->cs_emit_signal
= true;
2998 /* Signals fence as soon as all the work currently put on queue is done. */
2999 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
3000 struct radv_fence
*fence
)
3004 struct radv_winsys_sem_info sem_info
;
3006 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
3007 radv_fence_to_handle(fence
));
3008 if (result
!= VK_SUCCESS
)
3011 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3012 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3013 1, NULL
, NULL
, &sem_info
, NULL
,
3014 false, fence
->fence
);
3015 radv_free_sem_info(&sem_info
);
3018 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
3023 VkResult
radv_QueueSubmit(
3025 uint32_t submitCount
,
3026 const VkSubmitInfo
* pSubmits
,
3029 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3030 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3031 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3032 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
3034 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
3035 uint32_t scratch_size
= 0;
3036 uint32_t compute_scratch_size
= 0;
3037 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
3038 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
3040 bool fence_emitted
= false;
3041 bool tess_rings_needed
= false;
3042 bool sample_positions_needed
= false;
3044 /* Do this first so failing to allocate scratch buffers can't result in
3045 * partially executed submissions. */
3046 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3047 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3048 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3049 pSubmits
[i
].pCommandBuffers
[j
]);
3051 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
3052 compute_scratch_size
= MAX2(compute_scratch_size
,
3053 cmd_buffer
->compute_scratch_size_needed
);
3054 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
3055 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
3056 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
3057 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3061 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3062 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3063 sample_positions_needed
, &initial_flush_preamble_cs
,
3064 &initial_preamble_cs
, &continue_preamble_cs
);
3065 if (result
!= VK_SUCCESS
)
3068 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3069 struct radeon_cmdbuf
**cs_array
;
3070 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
3071 bool can_patch
= true;
3073 struct radv_winsys_sem_info sem_info
;
3075 result
= radv_alloc_sem_info(queue
->device
->instance
,
3077 pSubmits
[i
].waitSemaphoreCount
,
3078 pSubmits
[i
].pWaitSemaphores
,
3079 pSubmits
[i
].signalSemaphoreCount
,
3080 pSubmits
[i
].pSignalSemaphores
,
3082 if (result
!= VK_SUCCESS
)
3085 if (!pSubmits
[i
].commandBufferCount
) {
3086 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
3087 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3088 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3093 radv_loge("failed to submit CS %d\n", i
);
3096 fence_emitted
= true;
3098 radv_free_sem_info(&sem_info
);
3102 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3103 (pSubmits
[i
].commandBufferCount
));
3105 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3106 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3107 pSubmits
[i
].pCommandBuffers
[j
]);
3108 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3110 cs_array
[j
] = cmd_buffer
->cs
;
3111 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3114 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3117 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3118 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3119 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3121 advance
= MIN2(max_cs_submission
,
3122 pSubmits
[i
].commandBufferCount
- j
);
3124 if (queue
->device
->trace_bo
)
3125 *queue
->device
->trace_id_ptr
= 0;
3127 sem_info
.cs_emit_wait
= j
== 0;
3128 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3130 if (unlikely(queue
->device
->use_global_bo_list
)) {
3131 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3132 bo_list
= &queue
->device
->bo_list
.list
;
3135 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3136 advance
, initial_preamble
, continue_preamble_cs
,
3138 can_patch
, base_fence
);
3140 if (unlikely(queue
->device
->use_global_bo_list
))
3141 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3144 radv_loge("failed to submit CS %d\n", i
);
3147 fence_emitted
= true;
3148 if (queue
->device
->trace_bo
) {
3149 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3153 radv_free_temp_syncobjs(queue
->device
,
3154 pSubmits
[i
].waitSemaphoreCount
,
3155 pSubmits
[i
].pWaitSemaphores
);
3156 radv_free_sem_info(&sem_info
);
3161 if (!fence_emitted
) {
3162 result
= radv_signal_fence(queue
, fence
);
3163 if (result
!= VK_SUCCESS
)
3171 VkResult
radv_QueueWaitIdle(
3174 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3176 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3177 radv_queue_family_to_ring(queue
->queue_family_index
),
3182 VkResult
radv_DeviceWaitIdle(
3185 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3187 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3188 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3189 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3195 VkResult
radv_EnumerateInstanceExtensionProperties(
3196 const char* pLayerName
,
3197 uint32_t* pPropertyCount
,
3198 VkExtensionProperties
* pProperties
)
3200 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3202 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3203 if (radv_supported_instance_extensions
.extensions
[i
]) {
3204 vk_outarray_append(&out
, prop
) {
3205 *prop
= radv_instance_extensions
[i
];
3210 return vk_outarray_status(&out
);
3213 VkResult
radv_EnumerateDeviceExtensionProperties(
3214 VkPhysicalDevice physicalDevice
,
3215 const char* pLayerName
,
3216 uint32_t* pPropertyCount
,
3217 VkExtensionProperties
* pProperties
)
3219 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3220 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3222 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3223 if (device
->supported_extensions
.extensions
[i
]) {
3224 vk_outarray_append(&out
, prop
) {
3225 *prop
= radv_device_extensions
[i
];
3230 return vk_outarray_status(&out
);
3233 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3234 VkInstance _instance
,
3237 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3239 return radv_lookup_entrypoint_checked(pName
,
3240 instance
? instance
->apiVersion
: 0,
3241 instance
? &instance
->enabled_extensions
: NULL
,
3245 /* The loader wants us to expose a second GetInstanceProcAddr function
3246 * to work around certain LD_PRELOAD issues seen in apps.
3249 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3250 VkInstance instance
,
3254 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3255 VkInstance instance
,
3258 return radv_GetInstanceProcAddr(instance
, pName
);
3262 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3263 VkInstance _instance
,
3267 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3268 VkInstance _instance
,
3271 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3273 return radv_lookup_physical_device_entrypoint_checked(pName
,
3274 instance
? instance
->apiVersion
: 0,
3275 instance
? &instance
->enabled_extensions
: NULL
);
3278 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3282 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3284 return radv_lookup_entrypoint_checked(pName
,
3285 device
->instance
->apiVersion
,
3286 &device
->instance
->enabled_extensions
,
3287 &device
->enabled_extensions
);
3290 bool radv_get_memory_fd(struct radv_device
*device
,
3291 struct radv_device_memory
*memory
,
3294 struct radeon_bo_metadata metadata
;
3296 if (memory
->image
) {
3297 radv_init_metadata(device
, memory
->image
, &metadata
);
3298 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3301 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3305 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3306 const VkMemoryAllocateInfo
* pAllocateInfo
,
3307 const VkAllocationCallbacks
* pAllocator
,
3308 VkDeviceMemory
* pMem
)
3310 struct radv_device_memory
*mem
;
3312 enum radeon_bo_domain domain
;
3314 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3316 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3318 if (pAllocateInfo
->allocationSize
== 0) {
3319 /* Apparently, this is allowed */
3320 *pMem
= VK_NULL_HANDLE
;
3324 const VkImportMemoryFdInfoKHR
*import_info
=
3325 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3326 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3327 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3328 const VkExportMemoryAllocateInfo
*export_info
=
3329 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3330 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3331 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3333 const struct wsi_memory_allocate_info
*wsi_info
=
3334 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3336 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3337 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3339 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3341 if (wsi_info
&& wsi_info
->implicit_sync
)
3342 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3344 if (dedicate_info
) {
3345 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3346 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3352 float priority_float
= 0.5;
3353 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3354 vk_find_struct_const(pAllocateInfo
->pNext
,
3355 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3357 priority_float
= priority_ext
->priority
;
3359 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3360 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3362 mem
->user_ptr
= NULL
;
3365 assert(import_info
->handleType
==
3366 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3367 import_info
->handleType
==
3368 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3369 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3370 priority
, NULL
, NULL
);
3372 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3375 close(import_info
->fd
);
3377 } else if (host_ptr_info
) {
3378 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3379 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3380 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3381 pAllocateInfo
->allocationSize
,
3384 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3387 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3390 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3391 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3392 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3393 domain
= RADEON_DOMAIN_GTT
;
3395 domain
= RADEON_DOMAIN_VRAM
;
3397 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3398 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3400 flags
|= RADEON_FLAG_CPU_ACCESS
;
3402 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3403 flags
|= RADEON_FLAG_GTT_WC
;
3405 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3406 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3407 if (device
->use_global_bo_list
) {
3408 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3412 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3413 domain
, flags
, priority
);
3416 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3419 mem
->type_index
= mem_type_index
;
3422 result
= radv_bo_list_add(device
, mem
->bo
);
3423 if (result
!= VK_SUCCESS
)
3426 *pMem
= radv_device_memory_to_handle(mem
);
3431 device
->ws
->buffer_destroy(mem
->bo
);
3433 vk_free2(&device
->alloc
, pAllocator
, mem
);
3438 VkResult
radv_AllocateMemory(
3440 const VkMemoryAllocateInfo
* pAllocateInfo
,
3441 const VkAllocationCallbacks
* pAllocator
,
3442 VkDeviceMemory
* pMem
)
3444 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3445 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3448 void radv_FreeMemory(
3450 VkDeviceMemory _mem
,
3451 const VkAllocationCallbacks
* pAllocator
)
3453 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3454 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3459 radv_bo_list_remove(device
, mem
->bo
);
3460 device
->ws
->buffer_destroy(mem
->bo
);
3463 vk_free2(&device
->alloc
, pAllocator
, mem
);
3466 VkResult
radv_MapMemory(
3468 VkDeviceMemory _memory
,
3469 VkDeviceSize offset
,
3471 VkMemoryMapFlags flags
,
3474 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3475 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3483 *ppData
= mem
->user_ptr
;
3485 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3492 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3495 void radv_UnmapMemory(
3497 VkDeviceMemory _memory
)
3499 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3500 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3505 if (mem
->user_ptr
== NULL
)
3506 device
->ws
->buffer_unmap(mem
->bo
);
3509 VkResult
radv_FlushMappedMemoryRanges(
3511 uint32_t memoryRangeCount
,
3512 const VkMappedMemoryRange
* pMemoryRanges
)
3517 VkResult
radv_InvalidateMappedMemoryRanges(
3519 uint32_t memoryRangeCount
,
3520 const VkMappedMemoryRange
* pMemoryRanges
)
3525 void radv_GetBufferMemoryRequirements(
3528 VkMemoryRequirements
* pMemoryRequirements
)
3530 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3531 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3533 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3535 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3536 pMemoryRequirements
->alignment
= 4096;
3538 pMemoryRequirements
->alignment
= 16;
3540 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3543 void radv_GetBufferMemoryRequirements2(
3545 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3546 VkMemoryRequirements2
*pMemoryRequirements
)
3548 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3549 &pMemoryRequirements
->memoryRequirements
);
3550 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3551 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3552 switch (ext
->sType
) {
3553 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3554 VkMemoryDedicatedRequirements
*req
=
3555 (VkMemoryDedicatedRequirements
*) ext
;
3556 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3557 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3566 void radv_GetImageMemoryRequirements(
3569 VkMemoryRequirements
* pMemoryRequirements
)
3571 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3572 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3574 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3576 pMemoryRequirements
->size
= image
->size
;
3577 pMemoryRequirements
->alignment
= image
->alignment
;
3580 void radv_GetImageMemoryRequirements2(
3582 const VkImageMemoryRequirementsInfo2
*pInfo
,
3583 VkMemoryRequirements2
*pMemoryRequirements
)
3585 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3586 &pMemoryRequirements
->memoryRequirements
);
3588 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3590 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3591 switch (ext
->sType
) {
3592 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3593 VkMemoryDedicatedRequirements
*req
=
3594 (VkMemoryDedicatedRequirements
*) ext
;
3595 req
->requiresDedicatedAllocation
= image
->shareable
;
3596 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3605 void radv_GetImageSparseMemoryRequirements(
3608 uint32_t* pSparseMemoryRequirementCount
,
3609 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3614 void radv_GetImageSparseMemoryRequirements2(
3616 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3617 uint32_t* pSparseMemoryRequirementCount
,
3618 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3623 void radv_GetDeviceMemoryCommitment(
3625 VkDeviceMemory memory
,
3626 VkDeviceSize
* pCommittedMemoryInBytes
)
3628 *pCommittedMemoryInBytes
= 0;
3631 VkResult
radv_BindBufferMemory2(VkDevice device
,
3632 uint32_t bindInfoCount
,
3633 const VkBindBufferMemoryInfo
*pBindInfos
)
3635 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3636 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3637 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3640 buffer
->bo
= mem
->bo
;
3641 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3649 VkResult
radv_BindBufferMemory(
3652 VkDeviceMemory memory
,
3653 VkDeviceSize memoryOffset
)
3655 const VkBindBufferMemoryInfo info
= {
3656 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3659 .memoryOffset
= memoryOffset
3662 return radv_BindBufferMemory2(device
, 1, &info
);
3665 VkResult
radv_BindImageMemory2(VkDevice device
,
3666 uint32_t bindInfoCount
,
3667 const VkBindImageMemoryInfo
*pBindInfos
)
3669 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3670 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3671 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3674 image
->bo
= mem
->bo
;
3675 image
->offset
= pBindInfos
[i
].memoryOffset
;
3685 VkResult
radv_BindImageMemory(
3688 VkDeviceMemory memory
,
3689 VkDeviceSize memoryOffset
)
3691 const VkBindImageMemoryInfo info
= {
3692 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3695 .memoryOffset
= memoryOffset
3698 return radv_BindImageMemory2(device
, 1, &info
);
3703 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3704 const VkSparseBufferMemoryBindInfo
*bind
)
3706 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3708 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3709 struct radv_device_memory
*mem
= NULL
;
3711 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3712 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3714 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3715 bind
->pBinds
[i
].resourceOffset
,
3716 bind
->pBinds
[i
].size
,
3717 mem
? mem
->bo
: NULL
,
3718 bind
->pBinds
[i
].memoryOffset
);
3723 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3724 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3726 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3728 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3729 struct radv_device_memory
*mem
= NULL
;
3731 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3732 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3734 device
->ws
->buffer_virtual_bind(image
->bo
,
3735 bind
->pBinds
[i
].resourceOffset
,
3736 bind
->pBinds
[i
].size
,
3737 mem
? mem
->bo
: NULL
,
3738 bind
->pBinds
[i
].memoryOffset
);
3742 VkResult
radv_QueueBindSparse(
3744 uint32_t bindInfoCount
,
3745 const VkBindSparseInfo
* pBindInfo
,
3748 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3749 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3750 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3751 bool fence_emitted
= false;
3755 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3756 struct radv_winsys_sem_info sem_info
;
3757 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3758 radv_sparse_buffer_bind_memory(queue
->device
,
3759 pBindInfo
[i
].pBufferBinds
+ j
);
3762 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3763 radv_sparse_image_opaque_bind_memory(queue
->device
,
3764 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3768 result
= radv_alloc_sem_info(queue
->device
->instance
,
3770 pBindInfo
[i
].waitSemaphoreCount
,
3771 pBindInfo
[i
].pWaitSemaphores
,
3772 pBindInfo
[i
].signalSemaphoreCount
,
3773 pBindInfo
[i
].pSignalSemaphores
,
3775 if (result
!= VK_SUCCESS
)
3778 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3779 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3780 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3785 radv_loge("failed to submit CS %d\n", i
);
3789 fence_emitted
= true;
3792 radv_free_sem_info(&sem_info
);
3797 if (!fence_emitted
) {
3798 result
= radv_signal_fence(queue
, fence
);
3799 if (result
!= VK_SUCCESS
)
3807 VkResult
radv_CreateFence(
3809 const VkFenceCreateInfo
* pCreateInfo
,
3810 const VkAllocationCallbacks
* pAllocator
,
3813 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3814 const VkExportFenceCreateInfo
*export
=
3815 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3816 VkExternalFenceHandleTypeFlags handleTypes
=
3817 export
? export
->handleTypes
: 0;
3819 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3821 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3824 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3826 fence
->fence_wsi
= NULL
;
3827 fence
->temp_syncobj
= 0;
3828 if (device
->always_use_syncobj
|| handleTypes
) {
3829 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3831 vk_free2(&device
->alloc
, pAllocator
, fence
);
3832 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3834 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3835 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3837 fence
->fence
= NULL
;
3839 fence
->fence
= device
->ws
->create_fence();
3840 if (!fence
->fence
) {
3841 vk_free2(&device
->alloc
, pAllocator
, fence
);
3842 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3845 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3846 device
->ws
->signal_fence(fence
->fence
);
3849 *pFence
= radv_fence_to_handle(fence
);
3854 void radv_DestroyFence(
3857 const VkAllocationCallbacks
* pAllocator
)
3859 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3860 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3865 if (fence
->temp_syncobj
)
3866 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3868 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3870 device
->ws
->destroy_fence(fence
->fence
);
3871 if (fence
->fence_wsi
)
3872 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3873 vk_free2(&device
->alloc
, pAllocator
, fence
);
3877 uint64_t radv_get_current_time(void)
3880 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3881 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3884 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3886 uint64_t current_time
= radv_get_current_time();
3888 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3890 return current_time
+ timeout
;
3894 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
3895 uint32_t fenceCount
, const VkFence
*pFences
)
3897 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3898 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3899 if (fence
->fence
== NULL
|| fence
->syncobj
||
3900 fence
->temp_syncobj
|| fence
->fence_wsi
||
3901 (!device
->ws
->is_fence_waitable(fence
->fence
)))
3907 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3909 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3910 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3911 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3917 VkResult
radv_WaitForFences(
3919 uint32_t fenceCount
,
3920 const VkFence
* pFences
,
3924 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3925 timeout
= radv_get_absolute_timeout(timeout
);
3927 if (device
->always_use_syncobj
&&
3928 radv_all_fences_syncobj(fenceCount
, pFences
))
3930 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3932 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3934 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3935 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3936 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3939 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3942 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3945 if (!waitAll
&& fenceCount
> 1) {
3946 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3947 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
3948 uint32_t wait_count
= 0;
3949 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3951 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3953 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3954 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3956 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
3961 fences
[wait_count
++] = fence
->fence
;
3964 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3965 waitAll
, timeout
- radv_get_current_time());
3968 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3971 while(radv_get_current_time() <= timeout
) {
3972 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3973 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3980 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3981 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3982 bool expired
= false;
3984 if (fence
->temp_syncobj
) {
3985 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3990 if (fence
->syncobj
) {
3991 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3997 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
3998 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
3999 radv_get_current_time() <= timeout
)
4003 expired
= device
->ws
->fence_wait(device
->ws
,
4010 if (fence
->fence_wsi
) {
4011 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
4012 if (result
!= VK_SUCCESS
)
4020 VkResult
radv_ResetFences(VkDevice _device
,
4021 uint32_t fenceCount
,
4022 const VkFence
*pFences
)
4024 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4026 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
4027 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4029 device
->ws
->reset_fence(fence
->fence
);
4031 /* Per spec, we first restore the permanent payload, and then reset, so
4032 * having a temp syncobj should not skip resetting the permanent syncobj. */
4033 if (fence
->temp_syncobj
) {
4034 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4035 fence
->temp_syncobj
= 0;
4038 if (fence
->syncobj
) {
4039 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
4046 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
4048 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4049 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4051 if (fence
->temp_syncobj
) {
4052 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
4053 return success
? VK_SUCCESS
: VK_NOT_READY
;
4056 if (fence
->syncobj
) {
4057 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
4058 return success
? VK_SUCCESS
: VK_NOT_READY
;
4062 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
4063 return VK_NOT_READY
;
4065 if (fence
->fence_wsi
) {
4066 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
4068 if (result
!= VK_SUCCESS
) {
4069 if (result
== VK_TIMEOUT
)
4070 return VK_NOT_READY
;
4078 // Queue semaphore functions
4080 VkResult
radv_CreateSemaphore(
4082 const VkSemaphoreCreateInfo
* pCreateInfo
,
4083 const VkAllocationCallbacks
* pAllocator
,
4084 VkSemaphore
* pSemaphore
)
4086 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4087 const VkExportSemaphoreCreateInfo
*export
=
4088 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
4089 VkExternalSemaphoreHandleTypeFlags handleTypes
=
4090 export
? export
->handleTypes
: 0;
4092 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
4094 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4096 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4098 sem
->temp_syncobj
= 0;
4099 /* create a syncobject if we are going to export this semaphore */
4100 if (device
->always_use_syncobj
|| handleTypes
) {
4101 assert (device
->physical_device
->rad_info
.has_syncobj
);
4102 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4104 vk_free2(&device
->alloc
, pAllocator
, sem
);
4105 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4109 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4111 vk_free2(&device
->alloc
, pAllocator
, sem
);
4112 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4117 *pSemaphore
= radv_semaphore_to_handle(sem
);
4121 void radv_DestroySemaphore(
4123 VkSemaphore _semaphore
,
4124 const VkAllocationCallbacks
* pAllocator
)
4126 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4127 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4132 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4134 device
->ws
->destroy_sem(sem
->sem
);
4135 vk_free2(&device
->alloc
, pAllocator
, sem
);
4138 VkResult
radv_CreateEvent(
4140 const VkEventCreateInfo
* pCreateInfo
,
4141 const VkAllocationCallbacks
* pAllocator
,
4144 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4145 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4147 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4150 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4152 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4154 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4155 RADV_BO_PRIORITY_FENCE
);
4157 vk_free2(&device
->alloc
, pAllocator
, event
);
4158 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4161 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4163 *pEvent
= radv_event_to_handle(event
);
4168 void radv_DestroyEvent(
4171 const VkAllocationCallbacks
* pAllocator
)
4173 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4174 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4178 device
->ws
->buffer_destroy(event
->bo
);
4179 vk_free2(&device
->alloc
, pAllocator
, event
);
4182 VkResult
radv_GetEventStatus(
4186 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4188 if (*event
->map
== 1)
4189 return VK_EVENT_SET
;
4190 return VK_EVENT_RESET
;
4193 VkResult
radv_SetEvent(
4197 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4203 VkResult
radv_ResetEvent(
4207 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4213 VkResult
radv_CreateBuffer(
4215 const VkBufferCreateInfo
* pCreateInfo
,
4216 const VkAllocationCallbacks
* pAllocator
,
4219 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4220 struct radv_buffer
*buffer
;
4222 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4224 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4225 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4227 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4229 buffer
->size
= pCreateInfo
->size
;
4230 buffer
->usage
= pCreateInfo
->usage
;
4233 buffer
->flags
= pCreateInfo
->flags
;
4235 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4236 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4238 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4239 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4240 align64(buffer
->size
, 4096),
4241 4096, 0, RADEON_FLAG_VIRTUAL
,
4242 RADV_BO_PRIORITY_VIRTUAL
);
4244 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4245 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4249 *pBuffer
= radv_buffer_to_handle(buffer
);
4254 void radv_DestroyBuffer(
4257 const VkAllocationCallbacks
* pAllocator
)
4259 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4260 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4265 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4266 device
->ws
->buffer_destroy(buffer
->bo
);
4268 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4271 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4273 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4275 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4276 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4280 static inline unsigned
4281 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4284 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4286 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4289 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4291 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4295 radv_init_dcc_control_reg(struct radv_device
*device
,
4296 struct radv_image_view
*iview
)
4298 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4299 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4300 unsigned max_compressed_block_size
;
4301 unsigned independent_128b_blocks
;
4302 unsigned independent_64b_blocks
;
4304 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4307 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4308 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4309 * dGPU and 64 for APU because all of our APUs to date use
4310 * DIMMs which have a request granularity size of 64B while all
4311 * other chips have a 32B request size.
4313 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4316 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4317 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4318 independent_64b_blocks
= 0;
4319 independent_128b_blocks
= 1;
4321 independent_128b_blocks
= 0;
4323 if (iview
->image
->info
.samples
> 1) {
4324 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4325 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4326 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4327 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4330 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4331 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4332 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4333 /* If this DCC image is potentially going to be used in texture
4334 * fetches, we need some special settings.
4336 independent_64b_blocks
= 1;
4337 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4339 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4340 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4341 * big as possible for better compression state.
4343 independent_64b_blocks
= 0;
4344 max_compressed_block_size
= max_uncompressed_block_size
;
4348 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4349 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4350 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4351 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
4352 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
4356 radv_initialise_color_surface(struct radv_device
*device
,
4357 struct radv_color_buffer_info
*cb
,
4358 struct radv_image_view
*iview
)
4360 const struct vk_format_description
*desc
;
4361 unsigned ntype
, format
, swap
, endian
;
4362 unsigned blend_clamp
= 0, blend_bypass
= 0;
4364 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4365 const struct radeon_surf
*surf
= &plane
->surface
;
4367 desc
= vk_format_description(iview
->vk_format
);
4369 memset(cb
, 0, sizeof(*cb
));
4371 /* Intensity is implemented as Red, so treat it that way. */
4372 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4374 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4376 cb
->cb_color_base
= va
>> 8;
4378 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4379 struct gfx9_surf_meta_flags meta
;
4380 if (iview
->image
->dcc_offset
)
4381 meta
= surf
->u
.gfx9
.dcc
;
4383 meta
= surf
->u
.gfx9
.cmask
;
4385 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4386 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4387 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4388 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
4389 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
4391 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4392 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4393 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4394 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4395 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4398 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4399 cb
->cb_color_base
|= surf
->tile_swizzle
;
4401 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4402 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4404 cb
->cb_color_base
+= level_info
->offset
>> 8;
4405 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4406 cb
->cb_color_base
|= surf
->tile_swizzle
;
4408 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4409 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4410 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4412 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4413 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4414 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
4416 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4418 if (radv_image_has_fmask(iview
->image
)) {
4419 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4420 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
4421 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
4422 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
4424 /* This must be set for fast clear to work without FMASK. */
4425 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4426 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4427 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4428 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4432 /* CMASK variables */
4433 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4434 va
+= iview
->image
->cmask_offset
;
4435 cb
->cb_color_cmask
= va
>> 8;
4437 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4438 va
+= iview
->image
->dcc_offset
;
4440 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
4441 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
4442 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
4444 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
4445 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
4447 cb
->cb_dcc_base
= va
>> 8;
4448 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
4450 /* GFX10 field has the same base shift as the GFX6 field. */
4451 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4452 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4453 S_028C6C_SLICE_MAX_GFX10(max_slice
);
4455 if (iview
->image
->info
.samples
> 1) {
4456 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4458 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4459 S_028C74_NUM_FRAGMENTS(log_samples
);
4462 if (radv_image_has_fmask(iview
->image
)) {
4463 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
4464 cb
->cb_color_fmask
= va
>> 8;
4465 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
4467 cb
->cb_color_fmask
= cb
->cb_color_base
;
4470 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4472 vk_format_get_first_non_void_channel(iview
->vk_format
));
4473 format
= radv_translate_colorformat(iview
->vk_format
);
4474 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4475 radv_finishme("Illegal color\n");
4476 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4477 endian
= radv_colorformat_endian_swap(format
);
4479 /* blend clamp should be set for all NORM/SRGB types */
4480 if (ntype
== V_028C70_NUMBER_UNORM
||
4481 ntype
== V_028C70_NUMBER_SNORM
||
4482 ntype
== V_028C70_NUMBER_SRGB
)
4485 /* set blend bypass according to docs if SINT/UINT or
4486 8/24 COLOR variants */
4487 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4488 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4489 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4494 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4495 (format
== V_028C70_COLOR_8
||
4496 format
== V_028C70_COLOR_8_8
||
4497 format
== V_028C70_COLOR_8_8_8_8
))
4498 ->color_is_int8
= true;
4500 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4501 S_028C70_COMP_SWAP(swap
) |
4502 S_028C70_BLEND_CLAMP(blend_clamp
) |
4503 S_028C70_BLEND_BYPASS(blend_bypass
) |
4504 S_028C70_SIMPLE_FLOAT(1) |
4505 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4506 ntype
!= V_028C70_NUMBER_SNORM
&&
4507 ntype
!= V_028C70_NUMBER_SRGB
&&
4508 format
!= V_028C70_COLOR_8_24
&&
4509 format
!= V_028C70_COLOR_24_8
) |
4510 S_028C70_NUMBER_TYPE(ntype
) |
4511 S_028C70_ENDIAN(endian
);
4512 if (radv_image_has_fmask(iview
->image
)) {
4513 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4514 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4515 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
4516 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4519 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
4520 /* Allow the texture block to read FMASK directly
4521 * without decompressing it. This bit must be cleared
4522 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
4523 * otherwise the operation doesn't happen.
4525 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
4527 /* Set CMASK into a tiling format that allows the
4528 * texture block to read it.
4530 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
4534 if (radv_image_has_cmask(iview
->image
) &&
4535 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4536 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4538 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4539 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4541 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4543 /* This must be set for fast clear to work without FMASK. */
4544 if (!radv_image_has_fmask(iview
->image
) &&
4545 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4546 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4547 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4550 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4551 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4553 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4554 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4555 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4556 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4558 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4559 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
4561 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
4562 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
4563 S_028EE0_RESOURCE_LEVEL(1);
4565 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
4566 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4567 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4570 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4571 S_028C68_MIP0_HEIGHT(height
- 1) |
4572 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4577 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4578 struct radv_image_view
*iview
)
4580 unsigned max_zplanes
= 0;
4582 assert(radv_image_is_tc_compat_htile(iview
->image
));
4584 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4585 /* Default value for 32-bit depth surfaces. */
4588 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4589 iview
->image
->info
.samples
> 1)
4592 max_zplanes
= max_zplanes
+ 1;
4594 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4595 /* Do not enable Z plane compression for 16-bit depth
4596 * surfaces because isn't supported on GFX8. Only
4597 * 32-bit depth surfaces are supported by the hardware.
4598 * This allows to maintain shader compatibility and to
4599 * reduce the number of depth decompressions.
4603 if (iview
->image
->info
.samples
<= 1)
4605 else if (iview
->image
->info
.samples
<= 4)
4616 radv_initialise_ds_surface(struct radv_device
*device
,
4617 struct radv_ds_buffer_info
*ds
,
4618 struct radv_image_view
*iview
)
4620 unsigned level
= iview
->base_mip
;
4621 unsigned format
, stencil_format
;
4622 uint64_t va
, s_offs
, z_offs
;
4623 bool stencil_only
= false;
4624 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4625 const struct radeon_surf
*surf
= &plane
->surface
;
4627 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4629 memset(ds
, 0, sizeof(*ds
));
4630 switch (iview
->image
->vk_format
) {
4631 case VK_FORMAT_D24_UNORM_S8_UINT
:
4632 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4633 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4634 ds
->offset_scale
= 2.0f
;
4636 case VK_FORMAT_D16_UNORM
:
4637 case VK_FORMAT_D16_UNORM_S8_UINT
:
4638 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4639 ds
->offset_scale
= 4.0f
;
4641 case VK_FORMAT_D32_SFLOAT
:
4642 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4643 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4644 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4645 ds
->offset_scale
= 1.0f
;
4647 case VK_FORMAT_S8_UINT
:
4648 stencil_only
= true;
4654 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4655 stencil_format
= surf
->has_stencil
?
4656 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4658 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4659 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4660 S_028008_SLICE_MAX(max_slice
);
4661 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4662 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
4663 S_028008_SLICE_MAX_HI(max_slice
>> 11);
4666 ds
->db_htile_data_base
= 0;
4667 ds
->db_htile_surface
= 0;
4669 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4670 s_offs
= z_offs
= va
;
4672 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4673 assert(surf
->u
.gfx9
.surf_offset
== 0);
4674 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4676 ds
->db_z_info
= S_028038_FORMAT(format
) |
4677 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4678 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4679 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4680 S_028038_ZRANGE_PRECISION(1);
4681 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4682 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4684 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4685 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4686 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4689 ds
->db_depth_view
|= S_028008_MIPID(level
);
4690 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4691 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4693 if (radv_htile_enabled(iview
->image
, level
)) {
4694 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4696 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4697 unsigned max_zplanes
=
4698 radv_calc_decompress_on_z_planes(device
, iview
);
4700 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4702 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4703 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
4704 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
4706 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
4707 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4711 if (!surf
->has_stencil
)
4712 /* Use all of the htile_buffer for depth if there's no stencil. */
4713 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4714 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4715 iview
->image
->htile_offset
;
4716 ds
->db_htile_data_base
= va
>> 8;
4717 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4718 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
4720 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4721 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4725 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4728 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4730 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4731 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4733 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4734 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4735 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4737 if (iview
->image
->info
.samples
> 1)
4738 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4740 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4741 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4742 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4743 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4744 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4745 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4746 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4747 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4750 tile_mode
= stencil_tile_mode
;
4752 ds
->db_depth_info
|=
4753 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4754 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4755 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4756 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4757 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4758 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4759 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4760 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4762 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4763 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4764 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4765 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4767 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4770 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4771 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4772 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4774 if (radv_htile_enabled(iview
->image
, level
)) {
4775 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4777 if (!surf
->has_stencil
&&
4778 !radv_image_is_tc_compat_htile(iview
->image
))
4779 /* Use all of the htile_buffer for depth if there's no stencil. */
4780 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4782 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4783 iview
->image
->htile_offset
;
4784 ds
->db_htile_data_base
= va
>> 8;
4785 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4787 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4788 unsigned max_zplanes
=
4789 radv_calc_decompress_on_z_planes(device
, iview
);
4791 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4792 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4797 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4798 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4801 VkResult
radv_CreateFramebuffer(
4803 const VkFramebufferCreateInfo
* pCreateInfo
,
4804 const VkAllocationCallbacks
* pAllocator
,
4805 VkFramebuffer
* pFramebuffer
)
4807 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4808 struct radv_framebuffer
*framebuffer
;
4810 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4812 size_t size
= sizeof(*framebuffer
) +
4813 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4814 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4815 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4816 if (framebuffer
== NULL
)
4817 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4819 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4820 framebuffer
->width
= pCreateInfo
->width
;
4821 framebuffer
->height
= pCreateInfo
->height
;
4822 framebuffer
->layers
= pCreateInfo
->layers
;
4823 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4824 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4825 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4826 framebuffer
->attachments
[i
].attachment
= iview
;
4827 if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4828 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4830 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4832 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4833 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4834 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4837 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4841 void radv_DestroyFramebuffer(
4844 const VkAllocationCallbacks
* pAllocator
)
4846 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4847 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4851 vk_free2(&device
->alloc
, pAllocator
, fb
);
4854 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4856 switch (address_mode
) {
4857 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4858 return V_008F30_SQ_TEX_WRAP
;
4859 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4860 return V_008F30_SQ_TEX_MIRROR
;
4861 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4862 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4863 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4864 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4865 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4866 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4868 unreachable("illegal tex wrap mode");
4874 radv_tex_compare(VkCompareOp op
)
4877 case VK_COMPARE_OP_NEVER
:
4878 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4879 case VK_COMPARE_OP_LESS
:
4880 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4881 case VK_COMPARE_OP_EQUAL
:
4882 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4883 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4884 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4885 case VK_COMPARE_OP_GREATER
:
4886 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4887 case VK_COMPARE_OP_NOT_EQUAL
:
4888 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4889 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4890 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4891 case VK_COMPARE_OP_ALWAYS
:
4892 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4894 unreachable("illegal compare mode");
4900 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4903 case VK_FILTER_NEAREST
:
4904 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4905 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4906 case VK_FILTER_LINEAR
:
4907 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4908 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4909 case VK_FILTER_CUBIC_IMG
:
4911 fprintf(stderr
, "illegal texture filter");
4917 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4920 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4921 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4922 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4923 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4925 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4930 radv_tex_bordercolor(VkBorderColor bcolor
)
4933 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4934 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4935 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4936 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4937 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4938 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4939 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4940 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4941 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4949 radv_tex_aniso_filter(unsigned filter
)
4963 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4966 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4967 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4968 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4969 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
4970 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4971 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
4979 radv_get_max_anisotropy(struct radv_device
*device
,
4980 const VkSamplerCreateInfo
*pCreateInfo
)
4982 if (device
->force_aniso
>= 0)
4983 return device
->force_aniso
;
4985 if (pCreateInfo
->anisotropyEnable
&&
4986 pCreateInfo
->maxAnisotropy
> 1.0f
)
4987 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4993 radv_init_sampler(struct radv_device
*device
,
4994 struct radv_sampler
*sampler
,
4995 const VkSamplerCreateInfo
*pCreateInfo
)
4997 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4998 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4999 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
5000 device
->physical_device
->rad_info
.chip_class
== GFX9
;
5001 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5003 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
5004 vk_find_struct_const(pCreateInfo
->pNext
,
5005 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
5006 if (sampler_reduction
)
5007 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
5009 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
5010 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
5011 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
5012 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
5013 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
5014 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
5015 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
5016 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
5017 S_008F30_DISABLE_CUBE_WRAP(0) |
5018 S_008F30_COMPAT_MODE(compat_mode
) |
5019 S_008F30_FILTER_MODE(filter_mode
));
5020 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
5021 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
5022 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
5023 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
5024 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
5025 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
5026 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
5027 S_008F38_MIP_POINT_PRECLAMP(0));
5028 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
5029 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
5031 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5032 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
5034 sampler
->state
[2] |=
5035 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
5036 S_008F38_FILTER_PREC_FIX(1) |
5037 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
5041 VkResult
radv_CreateSampler(
5043 const VkSamplerCreateInfo
* pCreateInfo
,
5044 const VkAllocationCallbacks
* pAllocator
,
5045 VkSampler
* pSampler
)
5047 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5048 struct radv_sampler
*sampler
;
5050 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
5051 vk_find_struct_const(pCreateInfo
->pNext
,
5052 SAMPLER_YCBCR_CONVERSION_INFO
);
5054 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
5056 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
5057 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5059 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5061 radv_init_sampler(device
, sampler
, pCreateInfo
);
5063 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
5064 *pSampler
= radv_sampler_to_handle(sampler
);
5069 void radv_DestroySampler(
5072 const VkAllocationCallbacks
* pAllocator
)
5074 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5075 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
5079 vk_free2(&device
->alloc
, pAllocator
, sampler
);
5082 /* vk_icd.h does not declare this function, so we declare it here to
5083 * suppress Wmissing-prototypes.
5085 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5086 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
5088 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5089 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
5091 /* For the full details on loader interface versioning, see
5092 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
5093 * What follows is a condensed summary, to help you navigate the large and
5094 * confusing official doc.
5096 * - Loader interface v0 is incompatible with later versions. We don't
5099 * - In loader interface v1:
5100 * - The first ICD entrypoint called by the loader is
5101 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
5103 * - The ICD must statically expose no other Vulkan symbol unless it is
5104 * linked with -Bsymbolic.
5105 * - Each dispatchable Vulkan handle created by the ICD must be
5106 * a pointer to a struct whose first member is VK_LOADER_DATA. The
5107 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
5108 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
5109 * vkDestroySurfaceKHR(). The ICD must be capable of working with
5110 * such loader-managed surfaces.
5112 * - Loader interface v2 differs from v1 in:
5113 * - The first ICD entrypoint called by the loader is
5114 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
5115 * statically expose this entrypoint.
5117 * - Loader interface v3 differs from v2 in:
5118 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
5119 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
5120 * because the loader no longer does so.
5122 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
5126 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
5127 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
5130 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5131 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
5133 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
5135 /* At the moment, we support only the below handle types. */
5136 assert(pGetFdInfo
->handleType
==
5137 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5138 pGetFdInfo
->handleType
==
5139 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5141 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
5143 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5147 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
5148 VkExternalMemoryHandleTypeFlagBits handleType
,
5150 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
5152 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5154 switch (handleType
) {
5155 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
5156 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
5160 /* The valid usage section for this function says:
5162 * "handleType must not be one of the handle types defined as
5165 * So opaque handle types fall into the default "unsupported" case.
5167 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5171 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5175 uint32_t syncobj_handle
= 0;
5176 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5178 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5181 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5183 *syncobj
= syncobj_handle
;
5189 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5193 /* If we create a syncobj we do it locally so that if we have an error, we don't
5194 * leave a syncobj in an undetermined state in the fence. */
5195 uint32_t syncobj_handle
= *syncobj
;
5196 if (!syncobj_handle
) {
5197 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5199 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5204 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5206 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5208 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5211 *syncobj
= syncobj_handle
;
5218 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5219 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5221 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5222 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5223 uint32_t *syncobj_dst
= NULL
;
5225 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5226 syncobj_dst
= &sem
->temp_syncobj
;
5228 syncobj_dst
= &sem
->syncobj
;
5231 switch(pImportSemaphoreFdInfo
->handleType
) {
5232 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5233 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5234 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5235 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5237 unreachable("Unhandled semaphore handle type");
5241 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5242 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5245 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5246 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5248 uint32_t syncobj_handle
;
5250 if (sem
->temp_syncobj
)
5251 syncobj_handle
= sem
->temp_syncobj
;
5253 syncobj_handle
= sem
->syncobj
;
5255 switch(pGetFdInfo
->handleType
) {
5256 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5257 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5259 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5260 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5262 if (sem
->temp_syncobj
) {
5263 close (sem
->temp_syncobj
);
5264 sem
->temp_syncobj
= 0;
5266 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5271 unreachable("Unhandled semaphore handle type");
5275 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5279 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5280 VkPhysicalDevice physicalDevice
,
5281 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5282 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5284 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5286 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5287 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5288 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5289 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5290 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5291 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5292 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5293 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5294 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5295 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5296 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5297 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5298 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5300 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5301 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5302 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5306 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5307 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5309 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5310 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5311 uint32_t *syncobj_dst
= NULL
;
5314 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5315 syncobj_dst
= &fence
->temp_syncobj
;
5317 syncobj_dst
= &fence
->syncobj
;
5320 switch(pImportFenceFdInfo
->handleType
) {
5321 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5322 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5323 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5324 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5326 unreachable("Unhandled fence handle type");
5330 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5331 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5334 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5335 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5337 uint32_t syncobj_handle
;
5339 if (fence
->temp_syncobj
)
5340 syncobj_handle
= fence
->temp_syncobj
;
5342 syncobj_handle
= fence
->syncobj
;
5344 switch(pGetFdInfo
->handleType
) {
5345 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5346 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5348 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5349 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5351 if (fence
->temp_syncobj
) {
5352 close (fence
->temp_syncobj
);
5353 fence
->temp_syncobj
= 0;
5355 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5360 unreachable("Unhandled fence handle type");
5364 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5368 void radv_GetPhysicalDeviceExternalFenceProperties(
5369 VkPhysicalDevice physicalDevice
,
5370 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5371 VkExternalFenceProperties
*pExternalFenceProperties
)
5373 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5375 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5376 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5377 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5378 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5379 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5380 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5381 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5383 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5384 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5385 pExternalFenceProperties
->externalFenceFeatures
= 0;
5390 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5391 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5392 const VkAllocationCallbacks
* pAllocator
,
5393 VkDebugReportCallbackEXT
* pCallback
)
5395 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5396 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5397 pCreateInfo
, pAllocator
, &instance
->alloc
,
5402 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5403 VkDebugReportCallbackEXT _callback
,
5404 const VkAllocationCallbacks
* pAllocator
)
5406 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5407 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5408 _callback
, pAllocator
, &instance
->alloc
);
5412 radv_DebugReportMessageEXT(VkInstance _instance
,
5413 VkDebugReportFlagsEXT flags
,
5414 VkDebugReportObjectTypeEXT objectType
,
5417 int32_t messageCode
,
5418 const char* pLayerPrefix
,
5419 const char* pMessage
)
5421 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5422 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5423 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5427 radv_GetDeviceGroupPeerMemoryFeatures(
5430 uint32_t localDeviceIndex
,
5431 uint32_t remoteDeviceIndex
,
5432 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5434 assert(localDeviceIndex
== remoteDeviceIndex
);
5436 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5437 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5438 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5439 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5442 static const VkTimeDomainEXT radv_time_domains
[] = {
5443 VK_TIME_DOMAIN_DEVICE_EXT
,
5444 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5445 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5448 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5449 VkPhysicalDevice physicalDevice
,
5450 uint32_t *pTimeDomainCount
,
5451 VkTimeDomainEXT
*pTimeDomains
)
5454 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5456 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5457 vk_outarray_append(&out
, i
) {
5458 *i
= radv_time_domains
[d
];
5462 return vk_outarray_status(&out
);
5466 radv_clock_gettime(clockid_t clock_id
)
5468 struct timespec current
;
5471 ret
= clock_gettime(clock_id
, ¤t
);
5472 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5473 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5477 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5480 VkResult
radv_GetCalibratedTimestampsEXT(
5482 uint32_t timestampCount
,
5483 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5484 uint64_t *pTimestamps
,
5485 uint64_t *pMaxDeviation
)
5487 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5488 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5490 uint64_t begin
, end
;
5491 uint64_t max_clock_period
= 0;
5493 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5495 for (d
= 0; d
< timestampCount
; d
++) {
5496 switch (pTimestampInfos
[d
].timeDomain
) {
5497 case VK_TIME_DOMAIN_DEVICE_EXT
:
5498 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5500 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5501 max_clock_period
= MAX2(max_clock_period
, device_period
);
5503 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5504 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5505 max_clock_period
= MAX2(max_clock_period
, 1);
5508 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5509 pTimestamps
[d
] = begin
;
5517 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5520 * The maximum deviation is the sum of the interval over which we
5521 * perform the sampling and the maximum period of any sampled
5522 * clock. That's because the maximum skew between any two sampled
5523 * clock edges is when the sampled clock with the largest period is
5524 * sampled at the end of that period but right at the beginning of the
5525 * sampling interval and some other clock is sampled right at the
5526 * begining of its sampling period and right at the end of the
5527 * sampling interval. Let's assume the GPU has the longest clock
5528 * period and that the application is sampling GPU and monotonic:
5531 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5532 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5536 * GPU -----_____-----_____-----_____-----_____
5539 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5540 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5542 * Interval <----------------->
5543 * Deviation <-------------------------->
5547 * m = read(monotonic) 2
5550 * We round the sample interval up by one tick to cover sampling error
5551 * in the interval clock
5554 uint64_t sample_interval
= end
- begin
+ 1;
5556 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5561 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5562 VkPhysicalDevice physicalDevice
,
5563 VkSampleCountFlagBits samples
,
5564 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5566 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5567 VK_SAMPLE_COUNT_4_BIT
|
5568 VK_SAMPLE_COUNT_8_BIT
)) {
5569 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5571 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };