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
||
352 device
->rad_info
.family
== CHIP_RENOIR
;
355 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
358 device
->has_clear_state
= device
->rad_info
.chip_class
>= GFX7
;
360 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= GFX8
;
362 /* Vega10/Raven need a special workaround for a hardware bug. */
363 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
364 device
->rad_info
.family
== CHIP_RAVEN
;
366 device
->has_tc_compat_zrange_bug
= device
->rad_info
.chip_class
< GFX10
;
368 /* Out-of-order primitive rasterization. */
369 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= GFX8
&&
370 device
->rad_info
.max_se
>= 2;
371 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
372 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
374 device
->dcc_msaa_allowed
=
375 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
377 /* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
378 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
379 (device
->rad_info
.chip_class
>= GFX8
&&
380 device
->rad_info
.me_fw_feature
>= 41);
382 device
->has_dcc_constant_encode
= device
->rad_info
.family
== CHIP_RAVEN2
||
383 device
->rad_info
.family
== CHIP_RENOIR
||
384 device
->rad_info
.chip_class
>= GFX10
;
386 device
->use_shader_ballot
= device
->rad_info
.chip_class
>= GFX8
&&
387 device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
;
389 /* Determine the number of threads per wave for all stages. */
390 device
->cs_wave_size
= 64;
391 device
->ps_wave_size
= 64;
392 device
->ge_wave_size
= 64;
394 if (device
->rad_info
.chip_class
>= GFX10
) {
395 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
396 device
->cs_wave_size
= 32;
398 /* For pixel shaders, wave64 is recommanded. */
399 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
400 device
->ps_wave_size
= 32;
402 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
403 device
->ge_wave_size
= 32;
406 radv_physical_device_init_mem_types(device
);
407 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
409 device
->bus_info
= *drm_device
->businfo
.pci
;
411 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
412 ac_print_gpu_info(&device
->rad_info
);
414 /* The WSI is structured as a layer on top of the driver, so this has
415 * to be the last part of initialization (at least until we get other
418 result
= radv_init_wsi(device
);
419 if (result
!= VK_SUCCESS
) {
420 device
->ws
->destroy(device
->ws
);
421 vk_error(instance
, result
);
435 radv_physical_device_finish(struct radv_physical_device
*device
)
437 radv_finish_wsi(device
);
438 device
->ws
->destroy(device
->ws
);
439 disk_cache_destroy(device
->disk_cache
);
440 close(device
->local_fd
);
441 if (device
->master_fd
!= -1)
442 close(device
->master_fd
);
446 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
447 VkSystemAllocationScope allocationScope
)
453 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
454 size_t align
, VkSystemAllocationScope allocationScope
)
456 return realloc(pOriginal
, size
);
460 default_free_func(void *pUserData
, void *pMemory
)
465 static const VkAllocationCallbacks default_alloc
= {
467 .pfnAllocation
= default_alloc_func
,
468 .pfnReallocation
= default_realloc_func
,
469 .pfnFree
= default_free_func
,
472 static const struct debug_control radv_debug_options
[] = {
473 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
474 {"nodcc", RADV_DEBUG_NO_DCC
},
475 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
476 {"nocache", RADV_DEBUG_NO_CACHE
},
477 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
478 {"nohiz", RADV_DEBUG_NO_HIZ
},
479 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
480 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
481 {"allbos", RADV_DEBUG_ALL_BOS
},
482 {"noibs", RADV_DEBUG_NO_IBS
},
483 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
484 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
485 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
486 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
487 {"nosisched", RADV_DEBUG_NO_SISCHED
},
488 {"preoptir", RADV_DEBUG_PREOPTIR
},
489 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
490 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
491 {"info", RADV_DEBUG_INFO
},
492 {"errors", RADV_DEBUG_ERRORS
},
493 {"startup", RADV_DEBUG_STARTUP
},
494 {"checkir", RADV_DEBUG_CHECKIR
},
495 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
496 {"nobinning", RADV_DEBUG_NOBINNING
},
497 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
498 {"nongg", RADV_DEBUG_NO_NGG
},
499 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
504 radv_get_debug_option_name(int id
)
506 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
507 return radv_debug_options
[id
].string
;
510 static const struct debug_control radv_perftest_options
[] = {
511 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
512 {"sisched", RADV_PERFTEST_SISCHED
},
513 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
514 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
515 {"bolist", RADV_PERFTEST_BO_LIST
},
516 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
517 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
518 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
519 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
520 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
525 radv_get_perftest_option_name(int id
)
527 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
528 return radv_perftest_options
[id
].string
;
532 radv_handle_per_app_options(struct radv_instance
*instance
,
533 const VkApplicationInfo
*info
)
535 const char *name
= info
? info
->pApplicationName
: NULL
;
540 if (!strcmp(name
, "Talos - Linux - 32bit") ||
541 !strcmp(name
, "Talos - Linux - 64bit")) {
542 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
543 /* Force enable LLVM sisched for Talos because it looks
544 * safe and it gives few more FPS.
546 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
548 } else if (!strcmp(name
, "DOOM_VFR")) {
549 /* Work around a Doom VFR game bug */
550 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
551 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
552 /* Workaround for a WaW hazard when LLVM moves/merges
553 * load/store memory operations.
554 * See https://reviews.llvm.org/D61313
556 if (HAVE_LLVM
< 0x900)
557 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
558 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
559 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
)) {
560 /* Force enable VK_AMD_shader_ballot because it looks
561 * safe and it gives a nice boost (+20% on Vega 56 at
564 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
569 static int radv_get_instance_extension_index(const char *name
)
571 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
572 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
578 static const char radv_dri_options_xml
[] =
580 DRI_CONF_SECTION_QUALITY
581 DRI_CONF_ADAPTIVE_SYNC("true")
585 static void radv_init_dri_options(struct radv_instance
*instance
)
587 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
588 driParseConfigFiles(&instance
->dri_options
,
589 &instance
->available_dri_options
,
593 VkResult
radv_CreateInstance(
594 const VkInstanceCreateInfo
* pCreateInfo
,
595 const VkAllocationCallbacks
* pAllocator
,
596 VkInstance
* pInstance
)
598 struct radv_instance
*instance
;
601 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
603 uint32_t client_version
;
604 if (pCreateInfo
->pApplicationInfo
&&
605 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
606 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
608 client_version
= VK_API_VERSION_1_0
;
611 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
612 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
614 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
616 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
619 instance
->alloc
= *pAllocator
;
621 instance
->alloc
= default_alloc
;
623 instance
->apiVersion
= client_version
;
624 instance
->physicalDeviceCount
= -1;
626 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
629 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
630 radv_perftest_options
);
633 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
634 radv_logi("Created an instance");
636 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
637 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
638 int index
= radv_get_instance_extension_index(ext_name
);
640 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
641 vk_free2(&default_alloc
, pAllocator
, instance
);
642 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
645 instance
->enabled_extensions
.extensions
[index
] = true;
648 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
649 if (result
!= VK_SUCCESS
) {
650 vk_free2(&default_alloc
, pAllocator
, instance
);
651 return vk_error(instance
, result
);
655 glsl_type_singleton_init_or_ref();
657 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
659 radv_init_dri_options(instance
);
660 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
662 *pInstance
= radv_instance_to_handle(instance
);
667 void radv_DestroyInstance(
668 VkInstance _instance
,
669 const VkAllocationCallbacks
* pAllocator
)
671 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
676 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
677 radv_physical_device_finish(instance
->physicalDevices
+ i
);
680 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
682 glsl_type_singleton_decref();
685 driDestroyOptionCache(&instance
->dri_options
);
686 driDestroyOptionInfo(&instance
->available_dri_options
);
688 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
690 vk_free(&instance
->alloc
, instance
);
694 radv_enumerate_devices(struct radv_instance
*instance
)
696 /* TODO: Check for more devices ? */
697 drmDevicePtr devices
[8];
698 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
701 instance
->physicalDeviceCount
= 0;
703 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
705 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
706 radv_logi("Found %d drm nodes", max_devices
);
709 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
711 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
712 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
713 devices
[i
]->bustype
== DRM_BUS_PCI
&&
714 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
716 result
= radv_physical_device_init(instance
->physicalDevices
+
717 instance
->physicalDeviceCount
,
720 if (result
== VK_SUCCESS
)
721 ++instance
->physicalDeviceCount
;
722 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
726 drmFreeDevices(devices
, max_devices
);
731 VkResult
radv_EnumeratePhysicalDevices(
732 VkInstance _instance
,
733 uint32_t* pPhysicalDeviceCount
,
734 VkPhysicalDevice
* pPhysicalDevices
)
736 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
739 if (instance
->physicalDeviceCount
< 0) {
740 result
= radv_enumerate_devices(instance
);
741 if (result
!= VK_SUCCESS
&&
742 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
746 if (!pPhysicalDevices
) {
747 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
749 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
750 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
751 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
754 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
758 VkResult
radv_EnumeratePhysicalDeviceGroups(
759 VkInstance _instance
,
760 uint32_t* pPhysicalDeviceGroupCount
,
761 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
763 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
766 if (instance
->physicalDeviceCount
< 0) {
767 result
= radv_enumerate_devices(instance
);
768 if (result
!= VK_SUCCESS
&&
769 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
773 if (!pPhysicalDeviceGroupProperties
) {
774 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
776 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
777 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
778 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
779 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
780 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
783 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
787 void radv_GetPhysicalDeviceFeatures(
788 VkPhysicalDevice physicalDevice
,
789 VkPhysicalDeviceFeatures
* pFeatures
)
791 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
792 memset(pFeatures
, 0, sizeof(*pFeatures
));
794 *pFeatures
= (VkPhysicalDeviceFeatures
) {
795 .robustBufferAccess
= true,
796 .fullDrawIndexUint32
= true,
797 .imageCubeArray
= true,
798 .independentBlend
= true,
799 .geometryShader
= true,
800 .tessellationShader
= true,
801 .sampleRateShading
= true,
802 .dualSrcBlend
= true,
804 .multiDrawIndirect
= true,
805 .drawIndirectFirstInstance
= true,
807 .depthBiasClamp
= true,
808 .fillModeNonSolid
= true,
813 .multiViewport
= true,
814 .samplerAnisotropy
= true,
815 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
816 .textureCompressionASTC_LDR
= false,
817 .textureCompressionBC
= true,
818 .occlusionQueryPrecise
= true,
819 .pipelineStatisticsQuery
= true,
820 .vertexPipelineStoresAndAtomics
= true,
821 .fragmentStoresAndAtomics
= true,
822 .shaderTessellationAndGeometryPointSize
= true,
823 .shaderImageGatherExtended
= true,
824 .shaderStorageImageExtendedFormats
= true,
825 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
826 .shaderUniformBufferArrayDynamicIndexing
= true,
827 .shaderSampledImageArrayDynamicIndexing
= true,
828 .shaderStorageBufferArrayDynamicIndexing
= true,
829 .shaderStorageImageArrayDynamicIndexing
= true,
830 .shaderStorageImageReadWithoutFormat
= true,
831 .shaderStorageImageWriteWithoutFormat
= true,
832 .shaderClipDistance
= true,
833 .shaderCullDistance
= true,
834 .shaderFloat64
= true,
836 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
837 .sparseBinding
= true,
838 .variableMultisampleRate
= true,
839 .inheritedQueries
= true,
843 void radv_GetPhysicalDeviceFeatures2(
844 VkPhysicalDevice physicalDevice
,
845 VkPhysicalDeviceFeatures2
*pFeatures
)
847 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
848 vk_foreach_struct(ext
, pFeatures
->pNext
) {
849 switch (ext
->sType
) {
850 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
851 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
852 features
->variablePointersStorageBuffer
= true;
853 features
->variablePointers
= true;
856 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
857 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
858 features
->multiview
= true;
859 features
->multiviewGeometryShader
= true;
860 features
->multiviewTessellationShader
= true;
863 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
864 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
865 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
866 features
->shaderDrawParameters
= true;
869 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
870 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
871 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
872 features
->protectedMemory
= false;
875 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
876 VkPhysicalDevice16BitStorageFeatures
*features
=
877 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
878 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
879 features
->storageBuffer16BitAccess
= enabled
;
880 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
881 features
->storagePushConstant16
= enabled
;
882 features
->storageInputOutput16
= enabled
&& HAVE_LLVM
>= 0x900;
885 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
886 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
887 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
888 features
->samplerYcbcrConversion
= true;
891 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
892 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
893 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
894 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
895 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
896 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
897 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
898 features
->shaderSampledImageArrayNonUniformIndexing
= true;
899 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
900 features
->shaderStorageImageArrayNonUniformIndexing
= true;
901 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
902 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
903 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
904 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
905 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
906 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
907 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
908 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
909 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
910 features
->descriptorBindingUpdateUnusedWhilePending
= true;
911 features
->descriptorBindingPartiallyBound
= true;
912 features
->descriptorBindingVariableDescriptorCount
= true;
913 features
->runtimeDescriptorArray
= true;
916 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
917 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
918 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
919 features
->conditionalRendering
= true;
920 features
->inheritedConditionalRendering
= false;
923 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
924 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
925 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
926 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
927 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
930 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
931 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
932 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
933 features
->transformFeedback
= true;
934 features
->geometryStreams
= true;
937 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
938 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
939 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
940 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
943 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
944 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
945 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
946 features
->memoryPriority
= VK_TRUE
;
949 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
950 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
951 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
952 features
->bufferDeviceAddress
= true;
953 features
->bufferDeviceAddressCaptureReplay
= false;
954 features
->bufferDeviceAddressMultiDevice
= false;
957 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
958 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
959 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
960 features
->depthClipEnable
= true;
963 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
964 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
965 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
966 features
->hostQueryReset
= true;
969 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
970 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
971 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
972 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
973 features
->storageBuffer8BitAccess
= enabled
;
974 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
975 features
->storagePushConstant8
= enabled
;
978 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
979 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
980 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
981 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& HAVE_LLVM
>= 0x0800;
982 features
->shaderInt8
= true;
985 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
986 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
987 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
988 features
->shaderBufferInt64Atomics
= HAVE_LLVM
>= 0x0900;
989 features
->shaderSharedInt64Atomics
= HAVE_LLVM
>= 0x0900;
992 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
993 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
994 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
996 features
->inlineUniformBlock
= true;
997 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1000 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1001 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1002 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1003 features
->computeDerivativeGroupQuads
= false;
1004 features
->computeDerivativeGroupLinear
= true;
1007 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1008 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1009 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1010 features
->ycbcrImageArrays
= true;
1013 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1014 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1015 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1016 features
->uniformBufferStandardLayout
= true;
1019 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1020 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1021 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1022 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1025 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1026 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1027 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1028 features
->imagelessFramebuffer
= true;
1031 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1032 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1033 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1034 features
->pipelineExecutableInfo
= true;
1041 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1044 void radv_GetPhysicalDeviceProperties(
1045 VkPhysicalDevice physicalDevice
,
1046 VkPhysicalDeviceProperties
* pProperties
)
1048 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1049 VkSampleCountFlags sample_counts
= 0xf;
1051 /* make sure that the entire descriptor set is addressable with a signed
1052 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1053 * be at most 2 GiB. the combined image & samples object count as one of
1054 * both. This limit is for the pipeline layout, not for the set layout, but
1055 * there is no set limit, so we just set a pipeline limit. I don't think
1056 * any app is going to hit this soon. */
1057 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1058 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1059 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1060 32 /* sampler, largest when combined with image */ +
1061 64 /* sampled image */ +
1062 64 /* storage image */);
1064 VkPhysicalDeviceLimits limits
= {
1065 .maxImageDimension1D
= (1 << 14),
1066 .maxImageDimension2D
= (1 << 14),
1067 .maxImageDimension3D
= (1 << 11),
1068 .maxImageDimensionCube
= (1 << 14),
1069 .maxImageArrayLayers
= (1 << 11),
1070 .maxTexelBufferElements
= 128 * 1024 * 1024,
1071 .maxUniformBufferRange
= UINT32_MAX
,
1072 .maxStorageBufferRange
= UINT32_MAX
,
1073 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1074 .maxMemoryAllocationCount
= UINT32_MAX
,
1075 .maxSamplerAllocationCount
= 64 * 1024,
1076 .bufferImageGranularity
= 64, /* A cache line */
1077 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1078 .maxBoundDescriptorSets
= MAX_SETS
,
1079 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1080 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1081 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1082 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1083 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1084 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1085 .maxPerStageResources
= max_descriptor_set_size
,
1086 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1087 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1088 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1089 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1090 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1091 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1092 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1093 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1094 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1095 .maxVertexInputBindings
= MAX_VBS
,
1096 .maxVertexInputAttributeOffset
= 2047,
1097 .maxVertexInputBindingStride
= 2048,
1098 .maxVertexOutputComponents
= 128,
1099 .maxTessellationGenerationLevel
= 64,
1100 .maxTessellationPatchSize
= 32,
1101 .maxTessellationControlPerVertexInputComponents
= 128,
1102 .maxTessellationControlPerVertexOutputComponents
= 128,
1103 .maxTessellationControlPerPatchOutputComponents
= 120,
1104 .maxTessellationControlTotalOutputComponents
= 4096,
1105 .maxTessellationEvaluationInputComponents
= 128,
1106 .maxTessellationEvaluationOutputComponents
= 128,
1107 .maxGeometryShaderInvocations
= 127,
1108 .maxGeometryInputComponents
= 64,
1109 .maxGeometryOutputComponents
= 128,
1110 .maxGeometryOutputVertices
= 256,
1111 .maxGeometryTotalOutputComponents
= 1024,
1112 .maxFragmentInputComponents
= 128,
1113 .maxFragmentOutputAttachments
= 8,
1114 .maxFragmentDualSrcAttachments
= 1,
1115 .maxFragmentCombinedOutputResources
= 8,
1116 .maxComputeSharedMemorySize
= 32768,
1117 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1118 .maxComputeWorkGroupInvocations
= 2048,
1119 .maxComputeWorkGroupSize
= {
1124 .subPixelPrecisionBits
= 8,
1125 .subTexelPrecisionBits
= 8,
1126 .mipmapPrecisionBits
= 8,
1127 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1128 .maxDrawIndirectCount
= UINT32_MAX
,
1129 .maxSamplerLodBias
= 16,
1130 .maxSamplerAnisotropy
= 16,
1131 .maxViewports
= MAX_VIEWPORTS
,
1132 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1133 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1134 .viewportSubPixelBits
= 8,
1135 .minMemoryMapAlignment
= 4096, /* A page */
1136 .minTexelBufferOffsetAlignment
= 1,
1137 .minUniformBufferOffsetAlignment
= 4,
1138 .minStorageBufferOffsetAlignment
= 4,
1139 .minTexelOffset
= -32,
1140 .maxTexelOffset
= 31,
1141 .minTexelGatherOffset
= -32,
1142 .maxTexelGatherOffset
= 31,
1143 .minInterpolationOffset
= -2,
1144 .maxInterpolationOffset
= 2,
1145 .subPixelInterpolationOffsetBits
= 8,
1146 .maxFramebufferWidth
= (1 << 14),
1147 .maxFramebufferHeight
= (1 << 14),
1148 .maxFramebufferLayers
= (1 << 10),
1149 .framebufferColorSampleCounts
= sample_counts
,
1150 .framebufferDepthSampleCounts
= sample_counts
,
1151 .framebufferStencilSampleCounts
= sample_counts
,
1152 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1153 .maxColorAttachments
= MAX_RTS
,
1154 .sampledImageColorSampleCounts
= sample_counts
,
1155 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1156 .sampledImageDepthSampleCounts
= sample_counts
,
1157 .sampledImageStencilSampleCounts
= sample_counts
,
1158 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1159 .maxSampleMaskWords
= 1,
1160 .timestampComputeAndGraphics
= true,
1161 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1162 .maxClipDistances
= 8,
1163 .maxCullDistances
= 8,
1164 .maxCombinedClipAndCullDistances
= 8,
1165 .discreteQueuePriorities
= 2,
1166 .pointSizeRange
= { 0.0, 8192.0 },
1167 .lineWidthRange
= { 0.0, 7.9921875 },
1168 .pointSizeGranularity
= (1.0 / 8.0),
1169 .lineWidthGranularity
= (1.0 / 128.0),
1170 .strictLines
= false, /* FINISHME */
1171 .standardSampleLocations
= true,
1172 .optimalBufferCopyOffsetAlignment
= 128,
1173 .optimalBufferCopyRowPitchAlignment
= 128,
1174 .nonCoherentAtomSize
= 64,
1177 *pProperties
= (VkPhysicalDeviceProperties
) {
1178 .apiVersion
= radv_physical_device_api_version(pdevice
),
1179 .driverVersion
= vk_get_driver_version(),
1180 .vendorID
= ATI_VENDOR_ID
,
1181 .deviceID
= pdevice
->rad_info
.pci_id
,
1182 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1184 .sparseProperties
= {0},
1187 strcpy(pProperties
->deviceName
, pdevice
->name
);
1188 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1191 void radv_GetPhysicalDeviceProperties2(
1192 VkPhysicalDevice physicalDevice
,
1193 VkPhysicalDeviceProperties2
*pProperties
)
1195 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1196 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1198 vk_foreach_struct(ext
, pProperties
->pNext
) {
1199 switch (ext
->sType
) {
1200 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1201 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1202 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1203 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1206 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1207 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1208 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1209 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1210 properties
->deviceLUIDValid
= false;
1213 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1214 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1215 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1216 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1219 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1220 VkPhysicalDevicePointClippingProperties
*properties
=
1221 (VkPhysicalDevicePointClippingProperties
*)ext
;
1222 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1225 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1226 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1227 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1228 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1231 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1232 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1233 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1234 properties
->minImportedHostPointerAlignment
= 4096;
1237 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1238 VkPhysicalDeviceSubgroupProperties
*properties
=
1239 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1240 properties
->subgroupSize
= 64;
1241 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1242 properties
->supportedOperations
=
1243 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1244 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1245 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1246 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1247 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1248 properties
->supportedOperations
|=
1249 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1250 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1251 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1253 properties
->quadOperationsInAllStages
= true;
1256 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1257 VkPhysicalDeviceMaintenance3Properties
*properties
=
1258 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1259 /* Make sure everything is addressable by a signed 32-bit int, and
1260 * our largest descriptors are 96 bytes. */
1261 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1262 /* Our buffer size fields allow only this much */
1263 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1266 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1267 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1268 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1269 /* GFX6-8 only support single channel min/max filter. */
1270 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1271 properties
->filterMinmaxSingleComponentFormats
= true;
1274 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1275 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1276 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1278 /* Shader engines. */
1279 properties
->shaderEngineCount
=
1280 pdevice
->rad_info
.max_se
;
1281 properties
->shaderArraysPerEngineCount
=
1282 pdevice
->rad_info
.max_sh_per_se
;
1283 properties
->computeUnitsPerShaderArray
=
1284 pdevice
->rad_info
.num_good_cu_per_sh
;
1285 properties
->simdPerComputeUnit
= 4;
1286 properties
->wavefrontsPerSimd
=
1287 pdevice
->rad_info
.family
== CHIP_TONGA
||
1288 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1289 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1290 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1291 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1292 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1293 properties
->wavefrontSize
= 64;
1296 properties
->sgprsPerSimd
=
1297 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1298 properties
->minSgprAllocation
=
1299 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1300 properties
->maxSgprAllocation
=
1301 pdevice
->rad_info
.family
== CHIP_TONGA
||
1302 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1303 properties
->sgprAllocationGranularity
=
1304 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1307 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1308 properties
->minVgprAllocation
= 4;
1309 properties
->maxVgprAllocation
= 256;
1310 properties
->vgprAllocationGranularity
= 4;
1313 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1314 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1315 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1316 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1319 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1320 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1321 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1322 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1323 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1324 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1325 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1326 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1327 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1328 properties
->robustBufferAccessUpdateAfterBind
= false;
1329 properties
->quadDivergentImplicitLod
= false;
1331 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1332 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1333 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1334 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1335 32 /* sampler, largest when combined with image */ +
1336 64 /* sampled image */ +
1337 64 /* storage image */);
1338 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1339 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1340 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1341 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1342 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1343 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1344 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1345 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1346 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1347 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1348 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1349 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1350 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1351 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1352 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1355 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1356 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1357 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1358 properties
->protectedNoFault
= false;
1361 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1362 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1363 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1364 properties
->primitiveOverestimationSize
= 0;
1365 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1366 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1367 properties
->primitiveUnderestimation
= VK_FALSE
;
1368 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1369 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1370 properties
->degenerateLinesRasterized
= VK_FALSE
;
1371 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1372 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1375 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1376 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1377 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1378 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1379 properties
->pciBus
= pdevice
->bus_info
.bus
;
1380 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1381 properties
->pciFunction
= pdevice
->bus_info
.func
;
1384 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1385 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1386 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1388 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1389 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
, "radv");
1390 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1391 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1392 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1394 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1402 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1403 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1404 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1405 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1406 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1407 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1408 properties
->maxTransformFeedbackStreamDataSize
= 512;
1409 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1410 properties
->maxTransformFeedbackBufferDataStride
= 512;
1411 properties
->transformFeedbackQueries
= true;
1412 properties
->transformFeedbackStreamsLinesTriangles
= true;
1413 properties
->transformFeedbackRasterizationStreamSelect
= false;
1414 properties
->transformFeedbackDraw
= true;
1417 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1418 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1419 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1421 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1422 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1423 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1424 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1425 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1428 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1429 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1430 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1431 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1432 VK_SAMPLE_COUNT_4_BIT
|
1433 VK_SAMPLE_COUNT_8_BIT
;
1434 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1435 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1436 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1437 properties
->sampleLocationSubPixelBits
= 4;
1438 properties
->variableSampleLocations
= VK_FALSE
;
1441 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1442 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1443 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1445 /* We support all of the depth resolve modes */
1446 properties
->supportedDepthResolveModes
=
1447 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1448 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1449 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1450 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1452 /* Average doesn't make sense for stencil so we don't support that */
1453 properties
->supportedStencilResolveModes
=
1454 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1455 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1456 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1458 properties
->independentResolveNone
= VK_TRUE
;
1459 properties
->independentResolve
= VK_TRUE
;
1468 static void radv_get_physical_device_queue_family_properties(
1469 struct radv_physical_device
* pdevice
,
1471 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1473 int num_queue_families
= 1;
1475 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1476 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1477 num_queue_families
++;
1479 if (pQueueFamilyProperties
== NULL
) {
1480 *pCount
= num_queue_families
;
1489 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1490 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1491 VK_QUEUE_COMPUTE_BIT
|
1492 VK_QUEUE_TRANSFER_BIT
|
1493 VK_QUEUE_SPARSE_BINDING_BIT
,
1495 .timestampValidBits
= 64,
1496 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1501 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1502 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1503 if (*pCount
> idx
) {
1504 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1505 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1506 VK_QUEUE_TRANSFER_BIT
|
1507 VK_QUEUE_SPARSE_BINDING_BIT
,
1508 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1509 .timestampValidBits
= 64,
1510 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1518 void radv_GetPhysicalDeviceQueueFamilyProperties(
1519 VkPhysicalDevice physicalDevice
,
1521 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1523 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1524 if (!pQueueFamilyProperties
) {
1525 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1528 VkQueueFamilyProperties
*properties
[] = {
1529 pQueueFamilyProperties
+ 0,
1530 pQueueFamilyProperties
+ 1,
1531 pQueueFamilyProperties
+ 2,
1533 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1534 assert(*pCount
<= 3);
1537 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1538 VkPhysicalDevice physicalDevice
,
1540 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1542 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1543 if (!pQueueFamilyProperties
) {
1544 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1547 VkQueueFamilyProperties
*properties
[] = {
1548 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1549 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1550 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1552 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1553 assert(*pCount
<= 3);
1556 void radv_GetPhysicalDeviceMemoryProperties(
1557 VkPhysicalDevice physicalDevice
,
1558 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1560 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1562 *pMemoryProperties
= physical_device
->memory_properties
;
1566 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1567 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1569 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1570 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1571 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1572 uint64_t vram_size
= radv_get_vram_size(device
);
1573 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1574 uint64_t heap_budget
, heap_usage
;
1576 /* For all memory heaps, the computation of budget is as follow:
1577 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1579 * The Vulkan spec 1.1.97 says that the budget should include any
1580 * currently allocated device memory.
1582 * Note that the application heap usages are not really accurate (eg.
1583 * in presence of shared buffers).
1585 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1586 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1588 switch (device
->mem_type_indices
[i
]) {
1589 case RADV_MEM_TYPE_VRAM
:
1590 heap_usage
= device
->ws
->query_value(device
->ws
,
1591 RADEON_ALLOCATED_VRAM
);
1593 heap_budget
= vram_size
-
1594 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1597 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1598 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1600 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1601 heap_usage
= device
->ws
->query_value(device
->ws
,
1602 RADEON_ALLOCATED_VRAM_VIS
);
1604 heap_budget
= visible_vram_size
-
1605 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1608 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1609 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1611 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1612 heap_usage
= device
->ws
->query_value(device
->ws
,
1613 RADEON_ALLOCATED_GTT
);
1615 heap_budget
= gtt_size
-
1616 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1619 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1620 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1627 /* The heapBudget and heapUsage values must be zero for array elements
1628 * greater than or equal to
1629 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1631 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1632 memoryBudget
->heapBudget
[i
] = 0;
1633 memoryBudget
->heapUsage
[i
] = 0;
1637 void radv_GetPhysicalDeviceMemoryProperties2(
1638 VkPhysicalDevice physicalDevice
,
1639 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1641 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1642 &pMemoryProperties
->memoryProperties
);
1644 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1645 vk_find_struct(pMemoryProperties
->pNext
,
1646 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1648 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1651 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1653 VkExternalMemoryHandleTypeFlagBits handleType
,
1654 const void *pHostPointer
,
1655 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1657 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1661 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1662 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1663 uint32_t memoryTypeBits
= 0;
1664 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1665 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1666 memoryTypeBits
= (1 << i
);
1670 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1674 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1678 static enum radeon_ctx_priority
1679 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1681 /* Default to MEDIUM when a specific global priority isn't requested */
1683 return RADEON_CTX_PRIORITY_MEDIUM
;
1685 switch(pObj
->globalPriority
) {
1686 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1687 return RADEON_CTX_PRIORITY_REALTIME
;
1688 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1689 return RADEON_CTX_PRIORITY_HIGH
;
1690 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1691 return RADEON_CTX_PRIORITY_MEDIUM
;
1692 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1693 return RADEON_CTX_PRIORITY_LOW
;
1695 unreachable("Illegal global priority value");
1696 return RADEON_CTX_PRIORITY_INVALID
;
1701 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1702 uint32_t queue_family_index
, int idx
,
1703 VkDeviceQueueCreateFlags flags
,
1704 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1706 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1707 queue
->device
= device
;
1708 queue
->queue_family_index
= queue_family_index
;
1709 queue
->queue_idx
= idx
;
1710 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1711 queue
->flags
= flags
;
1713 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1715 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1721 radv_queue_finish(struct radv_queue
*queue
)
1724 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1726 if (queue
->initial_full_flush_preamble_cs
)
1727 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1728 if (queue
->initial_preamble_cs
)
1729 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1730 if (queue
->continue_preamble_cs
)
1731 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1732 if (queue
->descriptor_bo
)
1733 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1734 if (queue
->scratch_bo
)
1735 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1736 if (queue
->esgs_ring_bo
)
1737 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1738 if (queue
->gsvs_ring_bo
)
1739 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1740 if (queue
->tess_rings_bo
)
1741 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1742 if (queue
->compute_scratch_bo
)
1743 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1747 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1749 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1750 bo_list
->list
.count
= bo_list
->capacity
= 0;
1751 bo_list
->list
.bos
= NULL
;
1755 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1757 free(bo_list
->list
.bos
);
1758 pthread_mutex_destroy(&bo_list
->mutex
);
1761 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1762 struct radeon_winsys_bo
*bo
)
1764 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1769 if (unlikely(!device
->use_global_bo_list
))
1772 pthread_mutex_lock(&bo_list
->mutex
);
1773 if (bo_list
->list
.count
== bo_list
->capacity
) {
1774 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1775 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1778 pthread_mutex_unlock(&bo_list
->mutex
);
1779 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1782 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1783 bo_list
->capacity
= capacity
;
1786 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1787 pthread_mutex_unlock(&bo_list
->mutex
);
1791 static void radv_bo_list_remove(struct radv_device
*device
,
1792 struct radeon_winsys_bo
*bo
)
1794 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1799 if (unlikely(!device
->use_global_bo_list
))
1802 pthread_mutex_lock(&bo_list
->mutex
);
1803 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1804 if (bo_list
->list
.bos
[i
] == bo
) {
1805 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1806 --bo_list
->list
.count
;
1810 pthread_mutex_unlock(&bo_list
->mutex
);
1814 radv_device_init_gs_info(struct radv_device
*device
)
1816 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1817 device
->physical_device
->rad_info
.family
);
1820 static int radv_get_device_extension_index(const char *name
)
1822 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1823 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1830 radv_get_int_debug_option(const char *name
, int default_value
)
1837 result
= default_value
;
1841 result
= strtol(str
, &endptr
, 0);
1842 if (str
== endptr
) {
1843 /* No digits founs. */
1844 result
= default_value
;
1851 VkResult
radv_CreateDevice(
1852 VkPhysicalDevice physicalDevice
,
1853 const VkDeviceCreateInfo
* pCreateInfo
,
1854 const VkAllocationCallbacks
* pAllocator
,
1857 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1859 struct radv_device
*device
;
1861 bool keep_shader_info
= false;
1863 /* Check enabled features */
1864 if (pCreateInfo
->pEnabledFeatures
) {
1865 VkPhysicalDeviceFeatures supported_features
;
1866 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1867 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1868 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1869 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1870 for (uint32_t i
= 0; i
< num_features
; i
++) {
1871 if (enabled_feature
[i
] && !supported_feature
[i
])
1872 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1876 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1878 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1880 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1882 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1883 device
->instance
= physical_device
->instance
;
1884 device
->physical_device
= physical_device
;
1886 device
->ws
= physical_device
->ws
;
1888 device
->alloc
= *pAllocator
;
1890 device
->alloc
= physical_device
->instance
->alloc
;
1892 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1893 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1894 int index
= radv_get_device_extension_index(ext_name
);
1895 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1896 vk_free(&device
->alloc
, device
);
1897 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1900 device
->enabled_extensions
.extensions
[index
] = true;
1903 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1905 /* With update after bind we can't attach bo's to the command buffer
1906 * from the descriptor set anymore, so we have to use a global BO list.
1908 device
->use_global_bo_list
=
1909 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1910 device
->enabled_extensions
.EXT_descriptor_indexing
||
1911 device
->enabled_extensions
.EXT_buffer_device_address
;
1913 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1914 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1916 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1917 list_inithead(&device
->shader_slabs
);
1919 radv_bo_list_init(&device
->bo_list
);
1921 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1922 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1923 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1924 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1925 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1927 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1929 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1930 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1931 if (!device
->queues
[qfi
]) {
1932 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1936 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1938 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1940 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1941 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1942 qfi
, q
, queue_create
->flags
,
1944 if (result
!= VK_SUCCESS
)
1949 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1950 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1952 device
->dfsm_allowed
= device
->pbb_allowed
&&
1953 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1954 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
||
1955 device
->physical_device
->rad_info
.family
== CHIP_RENOIR
);
1958 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1961 /* The maximum number of scratch waves. Scratch space isn't divided
1962 * evenly between CUs. The number is only a function of the number of CUs.
1963 * We can decrease the constant to decrease the scratch buffer size.
1965 * sctx->scratch_waves must be >= the maximum possible size of
1966 * 1 threadgroup, so that the hw doesn't hang from being unable
1969 * The recommended value is 4 per CU at most. Higher numbers don't
1970 * bring much benefit, but they still occupy chip resources (think
1971 * async compute). I've seen ~2% performance difference between 4 and 32.
1973 uint32_t max_threads_per_block
= 2048;
1974 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1975 max_threads_per_block
/ 64);
1977 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
1978 S_00B800_CS_W32_EN(device
->physical_device
->cs_wave_size
== 32);
1980 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
1981 /* If the KMD allows it (there is a KMD hw register for it),
1982 * allow launching waves out-of-order.
1984 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1987 radv_device_init_gs_info(device
);
1989 device
->tess_offchip_block_dw_size
=
1990 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1991 device
->has_distributed_tess
=
1992 device
->physical_device
->rad_info
.chip_class
>= GFX8
&&
1993 device
->physical_device
->rad_info
.max_se
>= 2;
1995 if (getenv("RADV_TRACE_FILE")) {
1996 const char *filename
= getenv("RADV_TRACE_FILE");
1998 keep_shader_info
= true;
2000 if (!radv_init_trace(device
))
2003 fprintf(stderr
, "*****************************************************************************\n");
2004 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
2005 fprintf(stderr
, "*****************************************************************************\n");
2007 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
2008 radv_dump_enabled_options(device
, stderr
);
2011 device
->keep_shader_info
= keep_shader_info
;
2013 result
= radv_device_init_meta(device
);
2014 if (result
!= VK_SUCCESS
)
2017 radv_device_init_msaa(device
);
2019 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
2020 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
2022 case RADV_QUEUE_GENERAL
:
2023 /* Since amdgpu version 3.6.0, CONTEXT_CONTROL is emitted by the kernel */
2024 if (device
->physical_device
->rad_info
.drm_minor
< 6) {
2025 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2026 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
2027 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
2030 case RADV_QUEUE_COMPUTE
:
2031 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
2032 radeon_emit(device
->empty_cs
[family
], 0);
2035 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
2038 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
2039 cik_create_gfx_config(device
);
2041 VkPipelineCacheCreateInfo ci
;
2042 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
2045 ci
.pInitialData
= NULL
;
2046 ci
.initialDataSize
= 0;
2048 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
2050 if (result
!= VK_SUCCESS
)
2053 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
2055 device
->force_aniso
=
2056 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
2057 if (device
->force_aniso
>= 0) {
2058 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2059 1 << util_logbase2(device
->force_aniso
));
2062 *pDevice
= radv_device_to_handle(device
);
2066 radv_device_finish_meta(device
);
2068 radv_bo_list_finish(&device
->bo_list
);
2070 if (device
->trace_bo
)
2071 device
->ws
->buffer_destroy(device
->trace_bo
);
2073 if (device
->gfx_init
)
2074 device
->ws
->buffer_destroy(device
->gfx_init
);
2076 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2077 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2078 radv_queue_finish(&device
->queues
[i
][q
]);
2079 if (device
->queue_count
[i
])
2080 vk_free(&device
->alloc
, device
->queues
[i
]);
2083 vk_free(&device
->alloc
, device
);
2087 void radv_DestroyDevice(
2089 const VkAllocationCallbacks
* pAllocator
)
2091 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2096 if (device
->trace_bo
)
2097 device
->ws
->buffer_destroy(device
->trace_bo
);
2099 if (device
->gfx_init
)
2100 device
->ws
->buffer_destroy(device
->gfx_init
);
2102 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2103 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2104 radv_queue_finish(&device
->queues
[i
][q
]);
2105 if (device
->queue_count
[i
])
2106 vk_free(&device
->alloc
, device
->queues
[i
]);
2107 if (device
->empty_cs
[i
])
2108 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2110 radv_device_finish_meta(device
);
2112 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2113 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2115 radv_destroy_shader_slabs(device
);
2117 radv_bo_list_finish(&device
->bo_list
);
2118 vk_free(&device
->alloc
, device
);
2121 VkResult
radv_EnumerateInstanceLayerProperties(
2122 uint32_t* pPropertyCount
,
2123 VkLayerProperties
* pProperties
)
2125 if (pProperties
== NULL
) {
2126 *pPropertyCount
= 0;
2130 /* None supported at this time */
2131 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2134 VkResult
radv_EnumerateDeviceLayerProperties(
2135 VkPhysicalDevice physicalDevice
,
2136 uint32_t* pPropertyCount
,
2137 VkLayerProperties
* pProperties
)
2139 if (pProperties
== NULL
) {
2140 *pPropertyCount
= 0;
2144 /* None supported at this time */
2145 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2148 void radv_GetDeviceQueue2(
2150 const VkDeviceQueueInfo2
* pQueueInfo
,
2153 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2154 struct radv_queue
*queue
;
2156 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2157 if (pQueueInfo
->flags
!= queue
->flags
) {
2158 /* From the Vulkan 1.1.70 spec:
2160 * "The queue returned by vkGetDeviceQueue2 must have the same
2161 * flags value from this structure as that used at device
2162 * creation time in a VkDeviceQueueCreateInfo instance. If no
2163 * matching flags were specified at device creation time then
2164 * pQueue will return VK_NULL_HANDLE."
2166 *pQueue
= VK_NULL_HANDLE
;
2170 *pQueue
= radv_queue_to_handle(queue
);
2173 void radv_GetDeviceQueue(
2175 uint32_t queueFamilyIndex
,
2176 uint32_t queueIndex
,
2179 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2180 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2181 .queueFamilyIndex
= queueFamilyIndex
,
2182 .queueIndex
= queueIndex
2185 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2189 fill_geom_tess_rings(struct radv_queue
*queue
,
2191 bool add_sample_positions
,
2192 uint32_t esgs_ring_size
,
2193 struct radeon_winsys_bo
*esgs_ring_bo
,
2194 uint32_t gsvs_ring_size
,
2195 struct radeon_winsys_bo
*gsvs_ring_bo
,
2196 uint32_t tess_factor_ring_size
,
2197 uint32_t tess_offchip_ring_offset
,
2198 uint32_t tess_offchip_ring_size
,
2199 struct radeon_winsys_bo
*tess_rings_bo
)
2201 uint32_t *desc
= &map
[4];
2204 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2206 /* stride 0, num records - size, add tid, swizzle, elsize4,
2209 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2210 S_008F04_SWIZZLE_ENABLE(true);
2211 desc
[2] = esgs_ring_size
;
2212 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2213 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2214 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2215 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2216 S_008F0C_INDEX_STRIDE(3) |
2217 S_008F0C_ADD_TID_ENABLE(1);
2219 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2220 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2221 S_008F0C_OOB_SELECT(2) |
2222 S_008F0C_RESOURCE_LEVEL(1);
2224 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2225 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2226 S_008F0C_ELEMENT_SIZE(1);
2229 /* GS entry for ES->GS ring */
2230 /* stride 0, num records - size, elsize0,
2233 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
2234 desc
[6] = esgs_ring_size
;
2235 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2236 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2237 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2238 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2240 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2241 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2242 S_008F0C_OOB_SELECT(2) |
2243 S_008F0C_RESOURCE_LEVEL(1);
2245 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2246 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2253 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2255 /* VS entry for GS->VS ring */
2256 /* stride 0, num records - size, elsize0,
2259 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
2260 desc
[2] = gsvs_ring_size
;
2261 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2262 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2263 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2264 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2266 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2267 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2268 S_008F0C_OOB_SELECT(2) |
2269 S_008F0C_RESOURCE_LEVEL(1);
2271 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2272 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2275 /* stride gsvs_itemsize, num records 64
2276 elsize 4, index stride 16 */
2277 /* shader will patch stride and desc[2] */
2279 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
2280 S_008F04_SWIZZLE_ENABLE(1);
2282 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2283 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2284 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2285 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2286 S_008F0C_INDEX_STRIDE(1) |
2287 S_008F0C_ADD_TID_ENABLE(true);
2289 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2290 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2291 S_008F0C_OOB_SELECT(2) |
2292 S_008F0C_RESOURCE_LEVEL(1);
2294 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2295 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2296 S_008F0C_ELEMENT_SIZE(1);
2303 if (tess_rings_bo
) {
2304 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2305 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2308 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
2309 desc
[2] = tess_factor_ring_size
;
2310 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2311 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2312 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2313 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2315 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2316 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2317 S_008F0C_OOB_SELECT(3) |
2318 S_008F0C_RESOURCE_LEVEL(1);
2320 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2321 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2324 desc
[4] = tess_offchip_va
;
2325 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
2326 desc
[6] = tess_offchip_ring_size
;
2327 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2328 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2329 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2330 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2332 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2333 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2334 S_008F0C_OOB_SELECT(3) |
2335 S_008F0C_RESOURCE_LEVEL(1);
2337 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2338 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2344 if (add_sample_positions
) {
2345 /* add sample positions after all rings */
2346 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2348 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2350 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2352 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2357 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2359 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2360 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2361 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2362 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2363 unsigned max_offchip_buffers
;
2364 unsigned offchip_granularity
;
2365 unsigned hs_offchip_param
;
2369 * This must be one less than the maximum number due to a hw limitation.
2370 * Various hardware bugs need thGFX7
2373 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2374 * Gfx7 should limit max_offchip_buffers to 508
2375 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2377 * Follow AMDVLK here.
2379 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2380 max_offchip_buffers_per_se
= 256;
2381 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2382 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2383 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2384 --max_offchip_buffers_per_se
;
2386 max_offchip_buffers
= max_offchip_buffers_per_se
*
2387 device
->physical_device
->rad_info
.max_se
;
2389 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2390 * around by setting 4K granularity.
2392 if (device
->tess_offchip_block_dw_size
== 4096) {
2393 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2394 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2396 assert(device
->tess_offchip_block_dw_size
== 8192);
2397 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2400 switch (device
->physical_device
->rad_info
.chip_class
) {
2402 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2407 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2415 *max_offchip_buffers_p
= max_offchip_buffers
;
2416 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2417 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2418 --max_offchip_buffers
;
2420 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2421 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2424 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2426 return hs_offchip_param
;
2430 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2431 struct radeon_winsys_bo
*esgs_ring_bo
,
2432 uint32_t esgs_ring_size
,
2433 struct radeon_winsys_bo
*gsvs_ring_bo
,
2434 uint32_t gsvs_ring_size
)
2436 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2440 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2443 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2445 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2446 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2447 radeon_emit(cs
, esgs_ring_size
>> 8);
2448 radeon_emit(cs
, gsvs_ring_size
>> 8);
2450 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2451 radeon_emit(cs
, esgs_ring_size
>> 8);
2452 radeon_emit(cs
, gsvs_ring_size
>> 8);
2457 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2458 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2459 struct radeon_winsys_bo
*tess_rings_bo
)
2466 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2468 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2470 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2471 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2472 S_030938_SIZE(tf_ring_size
/ 4));
2473 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2476 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2477 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2478 S_030984_BASE_HI(tf_va
>> 40));
2479 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2480 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2481 S_030944_BASE_HI(tf_va
>> 40));
2483 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2486 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2487 S_008988_SIZE(tf_ring_size
/ 4));
2488 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2490 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2496 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2497 struct radeon_winsys_bo
*compute_scratch_bo
)
2499 uint64_t scratch_va
;
2501 if (!compute_scratch_bo
)
2504 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2506 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2508 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2509 radeon_emit(cs
, scratch_va
);
2510 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2511 S_008F04_SWIZZLE_ENABLE(1));
2515 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2516 struct radeon_cmdbuf
*cs
,
2517 struct radeon_winsys_bo
*descriptor_bo
)
2524 va
= radv_buffer_get_va(descriptor_bo
);
2526 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2528 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2529 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2530 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2531 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2532 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2534 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2535 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2538 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2539 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2540 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2541 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2542 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2544 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2545 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2549 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2550 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2551 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2552 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2553 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2554 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2556 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2557 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2564 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2566 struct radv_device
*device
= queue
->device
;
2568 if (device
->gfx_init
) {
2569 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2571 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2572 radeon_emit(cs
, va
);
2573 radeon_emit(cs
, va
>> 32);
2574 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2576 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2578 struct radv_physical_device
*physical_device
= device
->physical_device
;
2579 si_emit_graphics(physical_device
, cs
);
2584 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2586 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2587 si_emit_compute(physical_device
, cs
);
2591 radv_get_preamble_cs(struct radv_queue
*queue
,
2592 uint32_t scratch_size
,
2593 uint32_t compute_scratch_size
,
2594 uint32_t esgs_ring_size
,
2595 uint32_t gsvs_ring_size
,
2596 bool needs_tess_rings
,
2597 bool needs_sample_positions
,
2598 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2599 struct radeon_cmdbuf
**initial_preamble_cs
,
2600 struct radeon_cmdbuf
**continue_preamble_cs
)
2602 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2603 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2604 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2605 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2606 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2607 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2608 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2609 bool add_tess_rings
= false, add_sample_positions
= false;
2610 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2611 unsigned max_offchip_buffers
;
2612 unsigned hs_offchip_param
= 0;
2613 unsigned tess_offchip_ring_offset
;
2614 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2615 if (!queue
->has_tess_rings
) {
2616 if (needs_tess_rings
)
2617 add_tess_rings
= true;
2619 if (!queue
->has_sample_positions
) {
2620 if (needs_sample_positions
)
2621 add_sample_positions
= true;
2623 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2624 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2625 &max_offchip_buffers
);
2626 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2627 tess_offchip_ring_size
= max_offchip_buffers
*
2628 queue
->device
->tess_offchip_block_dw_size
* 4;
2630 if (scratch_size
<= queue
->scratch_size
&&
2631 compute_scratch_size
<= queue
->compute_scratch_size
&&
2632 esgs_ring_size
<= queue
->esgs_ring_size
&&
2633 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2634 !add_tess_rings
&& !add_sample_positions
&&
2635 queue
->initial_preamble_cs
) {
2636 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2637 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2638 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2639 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2640 *continue_preamble_cs
= NULL
;
2644 if (scratch_size
> queue
->scratch_size
) {
2645 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2650 RADV_BO_PRIORITY_SCRATCH
);
2654 scratch_bo
= queue
->scratch_bo
;
2656 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2657 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2658 compute_scratch_size
,
2662 RADV_BO_PRIORITY_SCRATCH
);
2663 if (!compute_scratch_bo
)
2667 compute_scratch_bo
= queue
->compute_scratch_bo
;
2669 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2670 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2675 RADV_BO_PRIORITY_SCRATCH
);
2679 esgs_ring_bo
= queue
->esgs_ring_bo
;
2680 esgs_ring_size
= queue
->esgs_ring_size
;
2683 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2684 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2689 RADV_BO_PRIORITY_SCRATCH
);
2693 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2694 gsvs_ring_size
= queue
->gsvs_ring_size
;
2697 if (add_tess_rings
) {
2698 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2699 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2703 RADV_BO_PRIORITY_SCRATCH
);
2707 tess_rings_bo
= queue
->tess_rings_bo
;
2710 if (scratch_bo
!= queue
->scratch_bo
||
2711 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2712 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2713 tess_rings_bo
!= queue
->tess_rings_bo
||
2714 add_sample_positions
) {
2716 if (gsvs_ring_bo
|| esgs_ring_bo
||
2717 tess_rings_bo
|| add_sample_positions
) {
2718 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2719 if (add_sample_positions
)
2720 size
+= 128; /* 64+32+16+8 = 120 bytes */
2722 else if (scratch_bo
)
2723 size
= 8; /* 2 dword */
2725 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2729 RADEON_FLAG_CPU_ACCESS
|
2730 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2731 RADEON_FLAG_READ_ONLY
,
2732 RADV_BO_PRIORITY_DESCRIPTOR
);
2736 descriptor_bo
= queue
->descriptor_bo
;
2738 if (descriptor_bo
!= queue
->descriptor_bo
) {
2739 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2742 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2743 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2744 S_008F04_SWIZZLE_ENABLE(1);
2745 map
[0] = scratch_va
;
2749 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2750 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2751 esgs_ring_size
, esgs_ring_bo
,
2752 gsvs_ring_size
, gsvs_ring_bo
,
2753 tess_factor_ring_size
,
2754 tess_offchip_ring_offset
,
2755 tess_offchip_ring_size
,
2758 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2761 for(int i
= 0; i
< 3; ++i
) {
2762 struct radeon_cmdbuf
*cs
= NULL
;
2763 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2764 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2771 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2773 /* Emit initial configuration. */
2774 switch (queue
->queue_family_index
) {
2775 case RADV_QUEUE_GENERAL
:
2776 radv_init_graphics_state(cs
, queue
);
2778 case RADV_QUEUE_COMPUTE
:
2779 radv_init_compute_state(cs
, queue
);
2781 case RADV_QUEUE_TRANSFER
:
2785 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2786 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2787 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2789 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2790 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2793 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2794 gsvs_ring_bo
, gsvs_ring_size
);
2795 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2796 tess_factor_ring_size
, tess_rings_bo
);
2797 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2798 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2801 si_cs_emit_cache_flush(cs
,
2802 queue
->device
->physical_device
->rad_info
.chip_class
,
2804 queue
->queue_family_index
== RING_COMPUTE
&&
2805 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2806 (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
)) |
2807 RADV_CMD_FLAG_INV_ICACHE
|
2808 RADV_CMD_FLAG_INV_SCACHE
|
2809 RADV_CMD_FLAG_INV_VCACHE
|
2810 RADV_CMD_FLAG_INV_L2
|
2811 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2812 } else if (i
== 1) {
2813 si_cs_emit_cache_flush(cs
,
2814 queue
->device
->physical_device
->rad_info
.chip_class
,
2816 queue
->queue_family_index
== RING_COMPUTE
&&
2817 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2818 RADV_CMD_FLAG_INV_ICACHE
|
2819 RADV_CMD_FLAG_INV_SCACHE
|
2820 RADV_CMD_FLAG_INV_VCACHE
|
2821 RADV_CMD_FLAG_INV_L2
|
2822 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2825 if (!queue
->device
->ws
->cs_finalize(cs
))
2829 if (queue
->initial_full_flush_preamble_cs
)
2830 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2832 if (queue
->initial_preamble_cs
)
2833 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2835 if (queue
->continue_preamble_cs
)
2836 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2838 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2839 queue
->initial_preamble_cs
= dest_cs
[1];
2840 queue
->continue_preamble_cs
= dest_cs
[2];
2842 if (scratch_bo
!= queue
->scratch_bo
) {
2843 if (queue
->scratch_bo
)
2844 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2845 queue
->scratch_bo
= scratch_bo
;
2846 queue
->scratch_size
= scratch_size
;
2849 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2850 if (queue
->compute_scratch_bo
)
2851 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2852 queue
->compute_scratch_bo
= compute_scratch_bo
;
2853 queue
->compute_scratch_size
= compute_scratch_size
;
2856 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2857 if (queue
->esgs_ring_bo
)
2858 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2859 queue
->esgs_ring_bo
= esgs_ring_bo
;
2860 queue
->esgs_ring_size
= esgs_ring_size
;
2863 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2864 if (queue
->gsvs_ring_bo
)
2865 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2866 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2867 queue
->gsvs_ring_size
= gsvs_ring_size
;
2870 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2871 queue
->tess_rings_bo
= tess_rings_bo
;
2872 queue
->has_tess_rings
= true;
2875 if (descriptor_bo
!= queue
->descriptor_bo
) {
2876 if (queue
->descriptor_bo
)
2877 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2879 queue
->descriptor_bo
= descriptor_bo
;
2882 if (add_sample_positions
)
2883 queue
->has_sample_positions
= true;
2885 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2886 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2887 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2888 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2889 *continue_preamble_cs
= NULL
;
2892 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2894 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2895 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2896 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2897 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2898 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2899 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2900 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2901 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2902 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2903 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2904 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2905 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2906 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2907 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2910 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2911 struct radv_winsys_sem_counts
*counts
,
2913 const VkSemaphore
*sems
,
2917 int syncobj_idx
= 0, sem_idx
= 0;
2919 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2922 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2923 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2925 if (sem
->temp_syncobj
|| sem
->syncobj
)
2926 counts
->syncobj_count
++;
2928 counts
->sem_count
++;
2931 if (_fence
!= VK_NULL_HANDLE
) {
2932 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2933 if (fence
->temp_syncobj
|| fence
->syncobj
)
2934 counts
->syncobj_count
++;
2937 if (counts
->syncobj_count
) {
2938 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2939 if (!counts
->syncobj
)
2940 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2943 if (counts
->sem_count
) {
2944 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2946 free(counts
->syncobj
);
2947 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2951 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2952 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2954 if (sem
->temp_syncobj
) {
2955 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2957 else if (sem
->syncobj
)
2958 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2961 counts
->sem
[sem_idx
++] = sem
->sem
;
2965 if (_fence
!= VK_NULL_HANDLE
) {
2966 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2967 if (fence
->temp_syncobj
)
2968 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2969 else if (fence
->syncobj
)
2970 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2977 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2979 free(sem_info
->wait
.syncobj
);
2980 free(sem_info
->wait
.sem
);
2981 free(sem_info
->signal
.syncobj
);
2982 free(sem_info
->signal
.sem
);
2986 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2988 const VkSemaphore
*sems
)
2990 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2991 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2993 if (sem
->temp_syncobj
) {
2994 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2995 sem
->temp_syncobj
= 0;
3001 radv_alloc_sem_info(struct radv_instance
*instance
,
3002 struct radv_winsys_sem_info
*sem_info
,
3004 const VkSemaphore
*wait_sems
,
3005 int num_signal_sems
,
3006 const VkSemaphore
*signal_sems
,
3010 memset(sem_info
, 0, sizeof(*sem_info
));
3012 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
3015 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
3017 radv_free_sem_info(sem_info
);
3019 /* caller can override these */
3020 sem_info
->cs_emit_wait
= true;
3021 sem_info
->cs_emit_signal
= true;
3025 /* Signals fence as soon as all the work currently put on queue is done. */
3026 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
3027 struct radv_fence
*fence
)
3031 struct radv_winsys_sem_info sem_info
;
3033 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
3034 radv_fence_to_handle(fence
));
3035 if (result
!= VK_SUCCESS
)
3038 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3039 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3040 1, NULL
, NULL
, &sem_info
, NULL
,
3041 false, fence
->fence
);
3042 radv_free_sem_info(&sem_info
);
3045 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
3050 VkResult
radv_QueueSubmit(
3052 uint32_t submitCount
,
3053 const VkSubmitInfo
* pSubmits
,
3056 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3057 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3058 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3059 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
3061 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
3062 uint32_t scratch_size
= 0;
3063 uint32_t compute_scratch_size
= 0;
3064 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
3065 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
3067 bool fence_emitted
= false;
3068 bool tess_rings_needed
= false;
3069 bool sample_positions_needed
= false;
3071 /* Do this first so failing to allocate scratch buffers can't result in
3072 * partially executed submissions. */
3073 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3074 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3075 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3076 pSubmits
[i
].pCommandBuffers
[j
]);
3078 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
3079 compute_scratch_size
= MAX2(compute_scratch_size
,
3080 cmd_buffer
->compute_scratch_size_needed
);
3081 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
3082 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
3083 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
3084 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3088 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3089 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3090 sample_positions_needed
, &initial_flush_preamble_cs
,
3091 &initial_preamble_cs
, &continue_preamble_cs
);
3092 if (result
!= VK_SUCCESS
)
3095 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3096 struct radeon_cmdbuf
**cs_array
;
3097 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
3098 bool can_patch
= true;
3100 struct radv_winsys_sem_info sem_info
;
3102 result
= radv_alloc_sem_info(queue
->device
->instance
,
3104 pSubmits
[i
].waitSemaphoreCount
,
3105 pSubmits
[i
].pWaitSemaphores
,
3106 pSubmits
[i
].signalSemaphoreCount
,
3107 pSubmits
[i
].pSignalSemaphores
,
3109 if (result
!= VK_SUCCESS
)
3112 if (!pSubmits
[i
].commandBufferCount
) {
3113 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
3114 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3115 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3120 radv_loge("failed to submit CS %d\n", i
);
3123 fence_emitted
= true;
3125 radv_free_sem_info(&sem_info
);
3129 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3130 (pSubmits
[i
].commandBufferCount
));
3132 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3133 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3134 pSubmits
[i
].pCommandBuffers
[j
]);
3135 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3137 cs_array
[j
] = cmd_buffer
->cs
;
3138 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3141 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3144 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3145 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3146 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3148 advance
= MIN2(max_cs_submission
,
3149 pSubmits
[i
].commandBufferCount
- j
);
3151 if (queue
->device
->trace_bo
)
3152 *queue
->device
->trace_id_ptr
= 0;
3154 sem_info
.cs_emit_wait
= j
== 0;
3155 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3157 if (unlikely(queue
->device
->use_global_bo_list
)) {
3158 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3159 bo_list
= &queue
->device
->bo_list
.list
;
3162 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3163 advance
, initial_preamble
, continue_preamble_cs
,
3165 can_patch
, base_fence
);
3167 if (unlikely(queue
->device
->use_global_bo_list
))
3168 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3171 radv_loge("failed to submit CS %d\n", i
);
3174 fence_emitted
= true;
3175 if (queue
->device
->trace_bo
) {
3176 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3180 radv_free_temp_syncobjs(queue
->device
,
3181 pSubmits
[i
].waitSemaphoreCount
,
3182 pSubmits
[i
].pWaitSemaphores
);
3183 radv_free_sem_info(&sem_info
);
3188 if (!fence_emitted
) {
3189 result
= radv_signal_fence(queue
, fence
);
3190 if (result
!= VK_SUCCESS
)
3198 VkResult
radv_QueueWaitIdle(
3201 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3203 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3204 radv_queue_family_to_ring(queue
->queue_family_index
),
3209 VkResult
radv_DeviceWaitIdle(
3212 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3214 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3215 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3216 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3222 VkResult
radv_EnumerateInstanceExtensionProperties(
3223 const char* pLayerName
,
3224 uint32_t* pPropertyCount
,
3225 VkExtensionProperties
* pProperties
)
3227 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3229 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3230 if (radv_supported_instance_extensions
.extensions
[i
]) {
3231 vk_outarray_append(&out
, prop
) {
3232 *prop
= radv_instance_extensions
[i
];
3237 return vk_outarray_status(&out
);
3240 VkResult
radv_EnumerateDeviceExtensionProperties(
3241 VkPhysicalDevice physicalDevice
,
3242 const char* pLayerName
,
3243 uint32_t* pPropertyCount
,
3244 VkExtensionProperties
* pProperties
)
3246 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3247 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3249 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3250 if (device
->supported_extensions
.extensions
[i
]) {
3251 vk_outarray_append(&out
, prop
) {
3252 *prop
= radv_device_extensions
[i
];
3257 return vk_outarray_status(&out
);
3260 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3261 VkInstance _instance
,
3264 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3266 return radv_lookup_entrypoint_checked(pName
,
3267 instance
? instance
->apiVersion
: 0,
3268 instance
? &instance
->enabled_extensions
: NULL
,
3272 /* The loader wants us to expose a second GetInstanceProcAddr function
3273 * to work around certain LD_PRELOAD issues seen in apps.
3276 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3277 VkInstance instance
,
3281 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3282 VkInstance instance
,
3285 return radv_GetInstanceProcAddr(instance
, pName
);
3289 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3290 VkInstance _instance
,
3294 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3295 VkInstance _instance
,
3298 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3300 return radv_lookup_physical_device_entrypoint_checked(pName
,
3301 instance
? instance
->apiVersion
: 0,
3302 instance
? &instance
->enabled_extensions
: NULL
);
3305 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3309 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3311 return radv_lookup_entrypoint_checked(pName
,
3312 device
->instance
->apiVersion
,
3313 &device
->instance
->enabled_extensions
,
3314 &device
->enabled_extensions
);
3317 bool radv_get_memory_fd(struct radv_device
*device
,
3318 struct radv_device_memory
*memory
,
3321 struct radeon_bo_metadata metadata
;
3323 if (memory
->image
) {
3324 radv_init_metadata(device
, memory
->image
, &metadata
);
3325 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3328 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3332 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3333 const VkMemoryAllocateInfo
* pAllocateInfo
,
3334 const VkAllocationCallbacks
* pAllocator
,
3335 VkDeviceMemory
* pMem
)
3337 struct radv_device_memory
*mem
;
3339 enum radeon_bo_domain domain
;
3341 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3343 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3345 if (pAllocateInfo
->allocationSize
== 0) {
3346 /* Apparently, this is allowed */
3347 *pMem
= VK_NULL_HANDLE
;
3351 const VkImportMemoryFdInfoKHR
*import_info
=
3352 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3353 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3354 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3355 const VkExportMemoryAllocateInfo
*export_info
=
3356 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3357 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3358 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3360 const struct wsi_memory_allocate_info
*wsi_info
=
3361 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3363 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3364 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3366 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3368 if (wsi_info
&& wsi_info
->implicit_sync
)
3369 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3371 if (dedicate_info
) {
3372 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3373 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3379 float priority_float
= 0.5;
3380 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3381 vk_find_struct_const(pAllocateInfo
->pNext
,
3382 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3384 priority_float
= priority_ext
->priority
;
3386 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3387 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3389 mem
->user_ptr
= NULL
;
3392 assert(import_info
->handleType
==
3393 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3394 import_info
->handleType
==
3395 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3396 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3397 priority
, NULL
, NULL
);
3399 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3402 close(import_info
->fd
);
3404 } else if (host_ptr_info
) {
3405 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3406 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3407 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3408 pAllocateInfo
->allocationSize
,
3411 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3414 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3417 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3418 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3419 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3420 domain
= RADEON_DOMAIN_GTT
;
3422 domain
= RADEON_DOMAIN_VRAM
;
3424 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3425 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3427 flags
|= RADEON_FLAG_CPU_ACCESS
;
3429 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3430 flags
|= RADEON_FLAG_GTT_WC
;
3432 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3433 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3434 if (device
->use_global_bo_list
) {
3435 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3439 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3440 domain
, flags
, priority
);
3443 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3446 mem
->type_index
= mem_type_index
;
3449 result
= radv_bo_list_add(device
, mem
->bo
);
3450 if (result
!= VK_SUCCESS
)
3453 *pMem
= radv_device_memory_to_handle(mem
);
3458 device
->ws
->buffer_destroy(mem
->bo
);
3460 vk_free2(&device
->alloc
, pAllocator
, mem
);
3465 VkResult
radv_AllocateMemory(
3467 const VkMemoryAllocateInfo
* pAllocateInfo
,
3468 const VkAllocationCallbacks
* pAllocator
,
3469 VkDeviceMemory
* pMem
)
3471 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3472 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3475 void radv_FreeMemory(
3477 VkDeviceMemory _mem
,
3478 const VkAllocationCallbacks
* pAllocator
)
3480 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3481 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3486 radv_bo_list_remove(device
, mem
->bo
);
3487 device
->ws
->buffer_destroy(mem
->bo
);
3490 vk_free2(&device
->alloc
, pAllocator
, mem
);
3493 VkResult
radv_MapMemory(
3495 VkDeviceMemory _memory
,
3496 VkDeviceSize offset
,
3498 VkMemoryMapFlags flags
,
3501 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3502 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3510 *ppData
= mem
->user_ptr
;
3512 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3519 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3522 void radv_UnmapMemory(
3524 VkDeviceMemory _memory
)
3526 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3527 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3532 if (mem
->user_ptr
== NULL
)
3533 device
->ws
->buffer_unmap(mem
->bo
);
3536 VkResult
radv_FlushMappedMemoryRanges(
3538 uint32_t memoryRangeCount
,
3539 const VkMappedMemoryRange
* pMemoryRanges
)
3544 VkResult
radv_InvalidateMappedMemoryRanges(
3546 uint32_t memoryRangeCount
,
3547 const VkMappedMemoryRange
* pMemoryRanges
)
3552 void radv_GetBufferMemoryRequirements(
3555 VkMemoryRequirements
* pMemoryRequirements
)
3557 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3558 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3560 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3562 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3563 pMemoryRequirements
->alignment
= 4096;
3565 pMemoryRequirements
->alignment
= 16;
3567 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3570 void radv_GetBufferMemoryRequirements2(
3572 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3573 VkMemoryRequirements2
*pMemoryRequirements
)
3575 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3576 &pMemoryRequirements
->memoryRequirements
);
3577 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3578 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3579 switch (ext
->sType
) {
3580 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3581 VkMemoryDedicatedRequirements
*req
=
3582 (VkMemoryDedicatedRequirements
*) ext
;
3583 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3584 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3593 void radv_GetImageMemoryRequirements(
3596 VkMemoryRequirements
* pMemoryRequirements
)
3598 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3599 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3601 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3603 pMemoryRequirements
->size
= image
->size
;
3604 pMemoryRequirements
->alignment
= image
->alignment
;
3607 void radv_GetImageMemoryRequirements2(
3609 const VkImageMemoryRequirementsInfo2
*pInfo
,
3610 VkMemoryRequirements2
*pMemoryRequirements
)
3612 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3613 &pMemoryRequirements
->memoryRequirements
);
3615 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3617 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3618 switch (ext
->sType
) {
3619 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3620 VkMemoryDedicatedRequirements
*req
=
3621 (VkMemoryDedicatedRequirements
*) ext
;
3622 req
->requiresDedicatedAllocation
= image
->shareable
;
3623 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3632 void radv_GetImageSparseMemoryRequirements(
3635 uint32_t* pSparseMemoryRequirementCount
,
3636 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3641 void radv_GetImageSparseMemoryRequirements2(
3643 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3644 uint32_t* pSparseMemoryRequirementCount
,
3645 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3650 void radv_GetDeviceMemoryCommitment(
3652 VkDeviceMemory memory
,
3653 VkDeviceSize
* pCommittedMemoryInBytes
)
3655 *pCommittedMemoryInBytes
= 0;
3658 VkResult
radv_BindBufferMemory2(VkDevice device
,
3659 uint32_t bindInfoCount
,
3660 const VkBindBufferMemoryInfo
*pBindInfos
)
3662 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3663 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3664 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3667 buffer
->bo
= mem
->bo
;
3668 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3676 VkResult
radv_BindBufferMemory(
3679 VkDeviceMemory memory
,
3680 VkDeviceSize memoryOffset
)
3682 const VkBindBufferMemoryInfo info
= {
3683 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3686 .memoryOffset
= memoryOffset
3689 return radv_BindBufferMemory2(device
, 1, &info
);
3692 VkResult
radv_BindImageMemory2(VkDevice device
,
3693 uint32_t bindInfoCount
,
3694 const VkBindImageMemoryInfo
*pBindInfos
)
3696 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3697 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3698 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3701 image
->bo
= mem
->bo
;
3702 image
->offset
= pBindInfos
[i
].memoryOffset
;
3712 VkResult
radv_BindImageMemory(
3715 VkDeviceMemory memory
,
3716 VkDeviceSize memoryOffset
)
3718 const VkBindImageMemoryInfo info
= {
3719 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3722 .memoryOffset
= memoryOffset
3725 return radv_BindImageMemory2(device
, 1, &info
);
3730 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3731 const VkSparseBufferMemoryBindInfo
*bind
)
3733 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3735 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3736 struct radv_device_memory
*mem
= NULL
;
3738 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3739 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3741 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3742 bind
->pBinds
[i
].resourceOffset
,
3743 bind
->pBinds
[i
].size
,
3744 mem
? mem
->bo
: NULL
,
3745 bind
->pBinds
[i
].memoryOffset
);
3750 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3751 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3753 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3755 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3756 struct radv_device_memory
*mem
= NULL
;
3758 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3759 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3761 device
->ws
->buffer_virtual_bind(image
->bo
,
3762 bind
->pBinds
[i
].resourceOffset
,
3763 bind
->pBinds
[i
].size
,
3764 mem
? mem
->bo
: NULL
,
3765 bind
->pBinds
[i
].memoryOffset
);
3769 VkResult
radv_QueueBindSparse(
3771 uint32_t bindInfoCount
,
3772 const VkBindSparseInfo
* pBindInfo
,
3775 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3776 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3777 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3778 bool fence_emitted
= false;
3782 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3783 struct radv_winsys_sem_info sem_info
;
3784 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3785 radv_sparse_buffer_bind_memory(queue
->device
,
3786 pBindInfo
[i
].pBufferBinds
+ j
);
3789 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3790 radv_sparse_image_opaque_bind_memory(queue
->device
,
3791 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3795 result
= radv_alloc_sem_info(queue
->device
->instance
,
3797 pBindInfo
[i
].waitSemaphoreCount
,
3798 pBindInfo
[i
].pWaitSemaphores
,
3799 pBindInfo
[i
].signalSemaphoreCount
,
3800 pBindInfo
[i
].pSignalSemaphores
,
3802 if (result
!= VK_SUCCESS
)
3805 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3806 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3807 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3812 radv_loge("failed to submit CS %d\n", i
);
3816 fence_emitted
= true;
3819 radv_free_sem_info(&sem_info
);
3824 if (!fence_emitted
) {
3825 result
= radv_signal_fence(queue
, fence
);
3826 if (result
!= VK_SUCCESS
)
3834 VkResult
radv_CreateFence(
3836 const VkFenceCreateInfo
* pCreateInfo
,
3837 const VkAllocationCallbacks
* pAllocator
,
3840 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3841 const VkExportFenceCreateInfo
*export
=
3842 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3843 VkExternalFenceHandleTypeFlags handleTypes
=
3844 export
? export
->handleTypes
: 0;
3846 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3848 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3851 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3853 fence
->fence_wsi
= NULL
;
3854 fence
->temp_syncobj
= 0;
3855 if (device
->always_use_syncobj
|| handleTypes
) {
3856 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3858 vk_free2(&device
->alloc
, pAllocator
, fence
);
3859 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3861 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3862 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3864 fence
->fence
= NULL
;
3866 fence
->fence
= device
->ws
->create_fence();
3867 if (!fence
->fence
) {
3868 vk_free2(&device
->alloc
, pAllocator
, fence
);
3869 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3872 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3873 device
->ws
->signal_fence(fence
->fence
);
3876 *pFence
= radv_fence_to_handle(fence
);
3881 void radv_DestroyFence(
3884 const VkAllocationCallbacks
* pAllocator
)
3886 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3887 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3892 if (fence
->temp_syncobj
)
3893 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3895 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3897 device
->ws
->destroy_fence(fence
->fence
);
3898 if (fence
->fence_wsi
)
3899 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3900 vk_free2(&device
->alloc
, pAllocator
, fence
);
3904 uint64_t radv_get_current_time(void)
3907 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3908 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3911 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3913 uint64_t current_time
= radv_get_current_time();
3915 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3917 return current_time
+ timeout
;
3921 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
3922 uint32_t fenceCount
, const VkFence
*pFences
)
3924 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3925 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3926 if (fence
->fence
== NULL
|| fence
->syncobj
||
3927 fence
->temp_syncobj
|| fence
->fence_wsi
||
3928 (!device
->ws
->is_fence_waitable(fence
->fence
)))
3934 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3936 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3937 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3938 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3944 VkResult
radv_WaitForFences(
3946 uint32_t fenceCount
,
3947 const VkFence
* pFences
,
3951 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3952 timeout
= radv_get_absolute_timeout(timeout
);
3954 if (device
->always_use_syncobj
&&
3955 radv_all_fences_syncobj(fenceCount
, pFences
))
3957 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3959 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3961 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3962 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3963 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3966 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3969 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3972 if (!waitAll
&& fenceCount
> 1) {
3973 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3974 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
3975 uint32_t wait_count
= 0;
3976 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3978 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3980 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3981 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3983 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
3988 fences
[wait_count
++] = fence
->fence
;
3991 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3992 waitAll
, timeout
- radv_get_current_time());
3995 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3998 while(radv_get_current_time() <= timeout
) {
3999 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4000 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
4007 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4008 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4009 bool expired
= false;
4011 if (fence
->temp_syncobj
) {
4012 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
4017 if (fence
->syncobj
) {
4018 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
4024 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
4025 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
4026 radv_get_current_time() <= timeout
)
4030 expired
= device
->ws
->fence_wait(device
->ws
,
4037 if (fence
->fence_wsi
) {
4038 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
4039 if (result
!= VK_SUCCESS
)
4047 VkResult
radv_ResetFences(VkDevice _device
,
4048 uint32_t fenceCount
,
4049 const VkFence
*pFences
)
4051 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4053 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
4054 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4056 device
->ws
->reset_fence(fence
->fence
);
4058 /* Per spec, we first restore the permanent payload, and then reset, so
4059 * having a temp syncobj should not skip resetting the permanent syncobj. */
4060 if (fence
->temp_syncobj
) {
4061 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4062 fence
->temp_syncobj
= 0;
4065 if (fence
->syncobj
) {
4066 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
4073 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
4075 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4076 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4078 if (fence
->temp_syncobj
) {
4079 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
4080 return success
? VK_SUCCESS
: VK_NOT_READY
;
4083 if (fence
->syncobj
) {
4084 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
4085 return success
? VK_SUCCESS
: VK_NOT_READY
;
4089 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
4090 return VK_NOT_READY
;
4092 if (fence
->fence_wsi
) {
4093 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
4095 if (result
!= VK_SUCCESS
) {
4096 if (result
== VK_TIMEOUT
)
4097 return VK_NOT_READY
;
4105 // Queue semaphore functions
4107 VkResult
radv_CreateSemaphore(
4109 const VkSemaphoreCreateInfo
* pCreateInfo
,
4110 const VkAllocationCallbacks
* pAllocator
,
4111 VkSemaphore
* pSemaphore
)
4113 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4114 const VkExportSemaphoreCreateInfo
*export
=
4115 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
4116 VkExternalSemaphoreHandleTypeFlags handleTypes
=
4117 export
? export
->handleTypes
: 0;
4119 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
4121 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4123 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4125 sem
->temp_syncobj
= 0;
4126 /* create a syncobject if we are going to export this semaphore */
4127 if (device
->always_use_syncobj
|| handleTypes
) {
4128 assert (device
->physical_device
->rad_info
.has_syncobj
);
4129 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4131 vk_free2(&device
->alloc
, pAllocator
, sem
);
4132 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4136 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4138 vk_free2(&device
->alloc
, pAllocator
, sem
);
4139 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4144 *pSemaphore
= radv_semaphore_to_handle(sem
);
4148 void radv_DestroySemaphore(
4150 VkSemaphore _semaphore
,
4151 const VkAllocationCallbacks
* pAllocator
)
4153 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4154 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4159 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4161 device
->ws
->destroy_sem(sem
->sem
);
4162 vk_free2(&device
->alloc
, pAllocator
, sem
);
4165 VkResult
radv_CreateEvent(
4167 const VkEventCreateInfo
* pCreateInfo
,
4168 const VkAllocationCallbacks
* pAllocator
,
4171 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4172 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4174 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4177 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4179 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4181 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4182 RADV_BO_PRIORITY_FENCE
);
4184 vk_free2(&device
->alloc
, pAllocator
, event
);
4185 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4188 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4190 *pEvent
= radv_event_to_handle(event
);
4195 void radv_DestroyEvent(
4198 const VkAllocationCallbacks
* pAllocator
)
4200 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4201 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4205 device
->ws
->buffer_destroy(event
->bo
);
4206 vk_free2(&device
->alloc
, pAllocator
, event
);
4209 VkResult
radv_GetEventStatus(
4213 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4215 if (*event
->map
== 1)
4216 return VK_EVENT_SET
;
4217 return VK_EVENT_RESET
;
4220 VkResult
radv_SetEvent(
4224 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4230 VkResult
radv_ResetEvent(
4234 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4240 VkResult
radv_CreateBuffer(
4242 const VkBufferCreateInfo
* pCreateInfo
,
4243 const VkAllocationCallbacks
* pAllocator
,
4246 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4247 struct radv_buffer
*buffer
;
4249 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4251 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4252 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4254 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4256 buffer
->size
= pCreateInfo
->size
;
4257 buffer
->usage
= pCreateInfo
->usage
;
4260 buffer
->flags
= pCreateInfo
->flags
;
4262 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4263 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4265 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4266 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4267 align64(buffer
->size
, 4096),
4268 4096, 0, RADEON_FLAG_VIRTUAL
,
4269 RADV_BO_PRIORITY_VIRTUAL
);
4271 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4272 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4276 *pBuffer
= radv_buffer_to_handle(buffer
);
4281 void radv_DestroyBuffer(
4284 const VkAllocationCallbacks
* pAllocator
)
4286 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4287 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4292 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4293 device
->ws
->buffer_destroy(buffer
->bo
);
4295 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4298 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4300 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4302 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4303 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4307 static inline unsigned
4308 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4311 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4313 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4316 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4318 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4322 radv_init_dcc_control_reg(struct radv_device
*device
,
4323 struct radv_image_view
*iview
)
4325 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4326 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4327 unsigned max_compressed_block_size
;
4328 unsigned independent_128b_blocks
;
4329 unsigned independent_64b_blocks
;
4331 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4334 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4335 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4336 * dGPU and 64 for APU because all of our APUs to date use
4337 * DIMMs which have a request granularity size of 64B while all
4338 * other chips have a 32B request size.
4340 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4343 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4344 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4345 independent_64b_blocks
= 0;
4346 independent_128b_blocks
= 1;
4348 independent_128b_blocks
= 0;
4350 if (iview
->image
->info
.samples
> 1) {
4351 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4352 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4353 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4354 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4357 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4358 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4359 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4360 /* If this DCC image is potentially going to be used in texture
4361 * fetches, we need some special settings.
4363 independent_64b_blocks
= 1;
4364 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4366 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4367 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4368 * big as possible for better compression state.
4370 independent_64b_blocks
= 0;
4371 max_compressed_block_size
= max_uncompressed_block_size
;
4375 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4376 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4377 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4378 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
4379 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
4383 radv_initialise_color_surface(struct radv_device
*device
,
4384 struct radv_color_buffer_info
*cb
,
4385 struct radv_image_view
*iview
)
4387 const struct vk_format_description
*desc
;
4388 unsigned ntype
, format
, swap
, endian
;
4389 unsigned blend_clamp
= 0, blend_bypass
= 0;
4391 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4392 const struct radeon_surf
*surf
= &plane
->surface
;
4394 desc
= vk_format_description(iview
->vk_format
);
4396 memset(cb
, 0, sizeof(*cb
));
4398 /* Intensity is implemented as Red, so treat it that way. */
4399 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4401 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4403 cb
->cb_color_base
= va
>> 8;
4405 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4406 struct gfx9_surf_meta_flags meta
;
4407 if (iview
->image
->dcc_offset
)
4408 meta
= surf
->u
.gfx9
.dcc
;
4410 meta
= surf
->u
.gfx9
.cmask
;
4412 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4413 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4414 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4415 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
4416 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
4418 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4419 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4420 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4421 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4422 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4425 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4426 cb
->cb_color_base
|= surf
->tile_swizzle
;
4428 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4429 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4431 cb
->cb_color_base
+= level_info
->offset
>> 8;
4432 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4433 cb
->cb_color_base
|= surf
->tile_swizzle
;
4435 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4436 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4437 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4439 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4440 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4441 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
4443 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4445 if (radv_image_has_fmask(iview
->image
)) {
4446 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4447 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
4448 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
4449 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
4451 /* This must be set for fast clear to work without FMASK. */
4452 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4453 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4454 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4455 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4459 /* CMASK variables */
4460 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4461 va
+= iview
->image
->cmask_offset
;
4462 cb
->cb_color_cmask
= va
>> 8;
4464 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4465 va
+= iview
->image
->dcc_offset
;
4467 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
4468 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
4469 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
4471 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
4472 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
4474 cb
->cb_dcc_base
= va
>> 8;
4475 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
4477 /* GFX10 field has the same base shift as the GFX6 field. */
4478 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4479 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4480 S_028C6C_SLICE_MAX_GFX10(max_slice
);
4482 if (iview
->image
->info
.samples
> 1) {
4483 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4485 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4486 S_028C74_NUM_FRAGMENTS(log_samples
);
4489 if (radv_image_has_fmask(iview
->image
)) {
4490 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
4491 cb
->cb_color_fmask
= va
>> 8;
4492 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
4494 cb
->cb_color_fmask
= cb
->cb_color_base
;
4497 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4499 vk_format_get_first_non_void_channel(iview
->vk_format
));
4500 format
= radv_translate_colorformat(iview
->vk_format
);
4501 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4502 radv_finishme("Illegal color\n");
4503 swap
= radv_translate_colorswap(iview
->vk_format
, false);
4504 endian
= radv_colorformat_endian_swap(format
);
4506 /* blend clamp should be set for all NORM/SRGB types */
4507 if (ntype
== V_028C70_NUMBER_UNORM
||
4508 ntype
== V_028C70_NUMBER_SNORM
||
4509 ntype
== V_028C70_NUMBER_SRGB
)
4512 /* set blend bypass according to docs if SINT/UINT or
4513 8/24 COLOR variants */
4514 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4515 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4516 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4521 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4522 (format
== V_028C70_COLOR_8
||
4523 format
== V_028C70_COLOR_8_8
||
4524 format
== V_028C70_COLOR_8_8_8_8
))
4525 ->color_is_int8
= true;
4527 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4528 S_028C70_COMP_SWAP(swap
) |
4529 S_028C70_BLEND_CLAMP(blend_clamp
) |
4530 S_028C70_BLEND_BYPASS(blend_bypass
) |
4531 S_028C70_SIMPLE_FLOAT(1) |
4532 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4533 ntype
!= V_028C70_NUMBER_SNORM
&&
4534 ntype
!= V_028C70_NUMBER_SRGB
&&
4535 format
!= V_028C70_COLOR_8_24
&&
4536 format
!= V_028C70_COLOR_24_8
) |
4537 S_028C70_NUMBER_TYPE(ntype
) |
4538 S_028C70_ENDIAN(endian
);
4539 if (radv_image_has_fmask(iview
->image
)) {
4540 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4541 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4542 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
4543 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4546 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
4547 /* Allow the texture block to read FMASK directly
4548 * without decompressing it. This bit must be cleared
4549 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
4550 * otherwise the operation doesn't happen.
4552 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
4554 /* Set CMASK into a tiling format that allows the
4555 * texture block to read it.
4557 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
4561 if (radv_image_has_cmask(iview
->image
) &&
4562 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4563 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4565 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4566 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4568 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4570 /* This must be set for fast clear to work without FMASK. */
4571 if (!radv_image_has_fmask(iview
->image
) &&
4572 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4573 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4574 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4577 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4578 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4580 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4581 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4582 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4583 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4585 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4586 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
4588 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
4589 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
4590 S_028EE0_RESOURCE_LEVEL(1);
4592 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
4593 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4594 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4597 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4598 S_028C68_MIP0_HEIGHT(height
- 1) |
4599 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4604 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4605 struct radv_image_view
*iview
)
4607 unsigned max_zplanes
= 0;
4609 assert(radv_image_is_tc_compat_htile(iview
->image
));
4611 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4612 /* Default value for 32-bit depth surfaces. */
4615 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4616 iview
->image
->info
.samples
> 1)
4619 max_zplanes
= max_zplanes
+ 1;
4621 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4622 /* Do not enable Z plane compression for 16-bit depth
4623 * surfaces because isn't supported on GFX8. Only
4624 * 32-bit depth surfaces are supported by the hardware.
4625 * This allows to maintain shader compatibility and to
4626 * reduce the number of depth decompressions.
4630 if (iview
->image
->info
.samples
<= 1)
4632 else if (iview
->image
->info
.samples
<= 4)
4643 radv_initialise_ds_surface(struct radv_device
*device
,
4644 struct radv_ds_buffer_info
*ds
,
4645 struct radv_image_view
*iview
)
4647 unsigned level
= iview
->base_mip
;
4648 unsigned format
, stencil_format
;
4649 uint64_t va
, s_offs
, z_offs
;
4650 bool stencil_only
= false;
4651 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4652 const struct radeon_surf
*surf
= &plane
->surface
;
4654 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4656 memset(ds
, 0, sizeof(*ds
));
4657 switch (iview
->image
->vk_format
) {
4658 case VK_FORMAT_D24_UNORM_S8_UINT
:
4659 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4660 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4661 ds
->offset_scale
= 2.0f
;
4663 case VK_FORMAT_D16_UNORM
:
4664 case VK_FORMAT_D16_UNORM_S8_UINT
:
4665 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4666 ds
->offset_scale
= 4.0f
;
4668 case VK_FORMAT_D32_SFLOAT
:
4669 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4670 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4671 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4672 ds
->offset_scale
= 1.0f
;
4674 case VK_FORMAT_S8_UINT
:
4675 stencil_only
= true;
4681 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4682 stencil_format
= surf
->has_stencil
?
4683 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4685 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4686 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4687 S_028008_SLICE_MAX(max_slice
);
4688 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4689 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
4690 S_028008_SLICE_MAX_HI(max_slice
>> 11);
4693 ds
->db_htile_data_base
= 0;
4694 ds
->db_htile_surface
= 0;
4696 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4697 s_offs
= z_offs
= va
;
4699 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4700 assert(surf
->u
.gfx9
.surf_offset
== 0);
4701 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4703 ds
->db_z_info
= S_028038_FORMAT(format
) |
4704 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4705 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4706 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4707 S_028038_ZRANGE_PRECISION(1);
4708 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4709 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4711 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4712 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4713 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4716 ds
->db_depth_view
|= S_028008_MIPID(level
);
4717 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4718 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4720 if (radv_htile_enabled(iview
->image
, level
)) {
4721 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4723 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4724 unsigned max_zplanes
=
4725 radv_calc_decompress_on_z_planes(device
, iview
);
4727 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4729 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4730 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
4731 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
4733 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
4734 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4738 if (!surf
->has_stencil
)
4739 /* Use all of the htile_buffer for depth if there's no stencil. */
4740 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4741 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4742 iview
->image
->htile_offset
;
4743 ds
->db_htile_data_base
= va
>> 8;
4744 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4745 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
4747 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4748 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4752 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4755 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4757 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4758 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4760 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4761 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4762 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4764 if (iview
->image
->info
.samples
> 1)
4765 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4767 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4768 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4769 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4770 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4771 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4772 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4773 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4774 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4777 tile_mode
= stencil_tile_mode
;
4779 ds
->db_depth_info
|=
4780 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4781 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4782 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4783 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4784 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4785 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4786 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4787 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4789 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4790 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4791 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4792 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4794 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4797 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4798 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4799 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4801 if (radv_htile_enabled(iview
->image
, level
)) {
4802 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4804 if (!surf
->has_stencil
&&
4805 !radv_image_is_tc_compat_htile(iview
->image
))
4806 /* Use all of the htile_buffer for depth if there's no stencil. */
4807 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4809 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4810 iview
->image
->htile_offset
;
4811 ds
->db_htile_data_base
= va
>> 8;
4812 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4814 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4815 unsigned max_zplanes
=
4816 radv_calc_decompress_on_z_planes(device
, iview
);
4818 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4819 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4824 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4825 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4828 VkResult
radv_CreateFramebuffer(
4830 const VkFramebufferCreateInfo
* pCreateInfo
,
4831 const VkAllocationCallbacks
* pAllocator
,
4832 VkFramebuffer
* pFramebuffer
)
4834 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4835 struct radv_framebuffer
*framebuffer
;
4836 const VkFramebufferAttachmentsCreateInfoKHR
*imageless_create_info
=
4837 vk_find_struct_const(pCreateInfo
->pNext
,
4838 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR
);
4840 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4842 size_t size
= sizeof(*framebuffer
);
4843 if (!imageless_create_info
)
4844 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
4845 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4846 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4847 if (framebuffer
== NULL
)
4848 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4850 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4851 framebuffer
->width
= pCreateInfo
->width
;
4852 framebuffer
->height
= pCreateInfo
->height
;
4853 framebuffer
->layers
= pCreateInfo
->layers
;
4854 if (imageless_create_info
) {
4855 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
4856 const VkFramebufferAttachmentImageInfoKHR
*attachment
=
4857 imageless_create_info
->pAttachmentImageInfos
+ i
;
4858 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
4859 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
4860 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
4863 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4864 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4865 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4866 framebuffer
->attachments
[i
] = iview
;
4867 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4868 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4869 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4873 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4877 void radv_DestroyFramebuffer(
4880 const VkAllocationCallbacks
* pAllocator
)
4882 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4883 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4887 vk_free2(&device
->alloc
, pAllocator
, fb
);
4890 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4892 switch (address_mode
) {
4893 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4894 return V_008F30_SQ_TEX_WRAP
;
4895 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4896 return V_008F30_SQ_TEX_MIRROR
;
4897 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4898 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4899 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4900 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4901 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4902 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4904 unreachable("illegal tex wrap mode");
4910 radv_tex_compare(VkCompareOp op
)
4913 case VK_COMPARE_OP_NEVER
:
4914 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4915 case VK_COMPARE_OP_LESS
:
4916 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4917 case VK_COMPARE_OP_EQUAL
:
4918 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4919 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4920 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4921 case VK_COMPARE_OP_GREATER
:
4922 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4923 case VK_COMPARE_OP_NOT_EQUAL
:
4924 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4925 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4926 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4927 case VK_COMPARE_OP_ALWAYS
:
4928 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4930 unreachable("illegal compare mode");
4936 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4939 case VK_FILTER_NEAREST
:
4940 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4941 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4942 case VK_FILTER_LINEAR
:
4943 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4944 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4945 case VK_FILTER_CUBIC_IMG
:
4947 fprintf(stderr
, "illegal texture filter");
4953 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4956 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4957 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4958 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4959 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4961 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4966 radv_tex_bordercolor(VkBorderColor bcolor
)
4969 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4970 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4971 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4972 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4973 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4974 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4975 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4976 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4977 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4985 radv_tex_aniso_filter(unsigned filter
)
4999 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
5002 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
5003 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5004 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
5005 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
5006 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
5007 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
5015 radv_get_max_anisotropy(struct radv_device
*device
,
5016 const VkSamplerCreateInfo
*pCreateInfo
)
5018 if (device
->force_aniso
>= 0)
5019 return device
->force_aniso
;
5021 if (pCreateInfo
->anisotropyEnable
&&
5022 pCreateInfo
->maxAnisotropy
> 1.0f
)
5023 return (uint32_t)pCreateInfo
->maxAnisotropy
;
5029 radv_init_sampler(struct radv_device
*device
,
5030 struct radv_sampler
*sampler
,
5031 const VkSamplerCreateInfo
*pCreateInfo
)
5033 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
5034 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
5035 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
5036 device
->physical_device
->rad_info
.chip_class
== GFX9
;
5037 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5039 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
5040 vk_find_struct_const(pCreateInfo
->pNext
,
5041 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
5042 if (sampler_reduction
)
5043 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
5045 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
5046 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
5047 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
5048 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
5049 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
5050 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
5051 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
5052 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
5053 S_008F30_DISABLE_CUBE_WRAP(0) |
5054 S_008F30_COMPAT_MODE(compat_mode
) |
5055 S_008F30_FILTER_MODE(filter_mode
));
5056 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
5057 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
5058 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
5059 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
5060 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
5061 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
5062 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
5063 S_008F38_MIP_POINT_PRECLAMP(0));
5064 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
5065 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
5067 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5068 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
5070 sampler
->state
[2] |=
5071 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
5072 S_008F38_FILTER_PREC_FIX(1) |
5073 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
5077 VkResult
radv_CreateSampler(
5079 const VkSamplerCreateInfo
* pCreateInfo
,
5080 const VkAllocationCallbacks
* pAllocator
,
5081 VkSampler
* pSampler
)
5083 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5084 struct radv_sampler
*sampler
;
5086 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
5087 vk_find_struct_const(pCreateInfo
->pNext
,
5088 SAMPLER_YCBCR_CONVERSION_INFO
);
5090 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
5092 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
5093 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5095 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5097 radv_init_sampler(device
, sampler
, pCreateInfo
);
5099 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
5100 *pSampler
= radv_sampler_to_handle(sampler
);
5105 void radv_DestroySampler(
5108 const VkAllocationCallbacks
* pAllocator
)
5110 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5111 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
5115 vk_free2(&device
->alloc
, pAllocator
, sampler
);
5118 /* vk_icd.h does not declare this function, so we declare it here to
5119 * suppress Wmissing-prototypes.
5121 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5122 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
5124 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5125 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
5127 /* For the full details on loader interface versioning, see
5128 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
5129 * What follows is a condensed summary, to help you navigate the large and
5130 * confusing official doc.
5132 * - Loader interface v0 is incompatible with later versions. We don't
5135 * - In loader interface v1:
5136 * - The first ICD entrypoint called by the loader is
5137 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
5139 * - The ICD must statically expose no other Vulkan symbol unless it is
5140 * linked with -Bsymbolic.
5141 * - Each dispatchable Vulkan handle created by the ICD must be
5142 * a pointer to a struct whose first member is VK_LOADER_DATA. The
5143 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
5144 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
5145 * vkDestroySurfaceKHR(). The ICD must be capable of working with
5146 * such loader-managed surfaces.
5148 * - Loader interface v2 differs from v1 in:
5149 * - The first ICD entrypoint called by the loader is
5150 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
5151 * statically expose this entrypoint.
5153 * - Loader interface v3 differs from v2 in:
5154 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
5155 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
5156 * because the loader no longer does so.
5158 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
5162 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
5163 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
5166 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5167 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
5169 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
5171 /* At the moment, we support only the below handle types. */
5172 assert(pGetFdInfo
->handleType
==
5173 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5174 pGetFdInfo
->handleType
==
5175 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5177 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
5179 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5183 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
5184 VkExternalMemoryHandleTypeFlagBits handleType
,
5186 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
5188 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5190 switch (handleType
) {
5191 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
5192 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
5196 /* The valid usage section for this function says:
5198 * "handleType must not be one of the handle types defined as
5201 * So opaque handle types fall into the default "unsupported" case.
5203 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5207 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5211 uint32_t syncobj_handle
= 0;
5212 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5214 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5217 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5219 *syncobj
= syncobj_handle
;
5225 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5229 /* If we create a syncobj we do it locally so that if we have an error, we don't
5230 * leave a syncobj in an undetermined state in the fence. */
5231 uint32_t syncobj_handle
= *syncobj
;
5232 if (!syncobj_handle
) {
5233 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5235 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5240 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5242 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5244 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5247 *syncobj
= syncobj_handle
;
5254 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5255 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5257 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5258 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5259 uint32_t *syncobj_dst
= NULL
;
5261 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5262 syncobj_dst
= &sem
->temp_syncobj
;
5264 syncobj_dst
= &sem
->syncobj
;
5267 switch(pImportSemaphoreFdInfo
->handleType
) {
5268 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5269 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5270 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5271 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5273 unreachable("Unhandled semaphore handle type");
5277 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5278 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5281 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5282 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5284 uint32_t syncobj_handle
;
5286 if (sem
->temp_syncobj
)
5287 syncobj_handle
= sem
->temp_syncobj
;
5289 syncobj_handle
= sem
->syncobj
;
5291 switch(pGetFdInfo
->handleType
) {
5292 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5293 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5295 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5296 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5298 if (sem
->temp_syncobj
) {
5299 close (sem
->temp_syncobj
);
5300 sem
->temp_syncobj
= 0;
5302 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5307 unreachable("Unhandled semaphore handle type");
5311 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5315 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5316 VkPhysicalDevice physicalDevice
,
5317 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5318 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5320 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5322 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5323 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5324 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5325 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5326 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5327 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5328 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5329 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5330 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5331 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5332 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5333 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5334 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5336 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5337 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5338 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5342 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5343 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5345 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5346 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5347 uint32_t *syncobj_dst
= NULL
;
5350 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5351 syncobj_dst
= &fence
->temp_syncobj
;
5353 syncobj_dst
= &fence
->syncobj
;
5356 switch(pImportFenceFdInfo
->handleType
) {
5357 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5358 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5359 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5360 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5362 unreachable("Unhandled fence handle type");
5366 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5367 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5370 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5371 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5373 uint32_t syncobj_handle
;
5375 if (fence
->temp_syncobj
)
5376 syncobj_handle
= fence
->temp_syncobj
;
5378 syncobj_handle
= fence
->syncobj
;
5380 switch(pGetFdInfo
->handleType
) {
5381 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5382 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5384 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5385 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5387 if (fence
->temp_syncobj
) {
5388 close (fence
->temp_syncobj
);
5389 fence
->temp_syncobj
= 0;
5391 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5396 unreachable("Unhandled fence handle type");
5400 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5404 void radv_GetPhysicalDeviceExternalFenceProperties(
5405 VkPhysicalDevice physicalDevice
,
5406 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5407 VkExternalFenceProperties
*pExternalFenceProperties
)
5409 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5411 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5412 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5413 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5414 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5415 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5416 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5417 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5419 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5420 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5421 pExternalFenceProperties
->externalFenceFeatures
= 0;
5426 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5427 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5428 const VkAllocationCallbacks
* pAllocator
,
5429 VkDebugReportCallbackEXT
* pCallback
)
5431 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5432 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5433 pCreateInfo
, pAllocator
, &instance
->alloc
,
5438 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5439 VkDebugReportCallbackEXT _callback
,
5440 const VkAllocationCallbacks
* pAllocator
)
5442 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5443 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5444 _callback
, pAllocator
, &instance
->alloc
);
5448 radv_DebugReportMessageEXT(VkInstance _instance
,
5449 VkDebugReportFlagsEXT flags
,
5450 VkDebugReportObjectTypeEXT objectType
,
5453 int32_t messageCode
,
5454 const char* pLayerPrefix
,
5455 const char* pMessage
)
5457 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5458 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5459 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5463 radv_GetDeviceGroupPeerMemoryFeatures(
5466 uint32_t localDeviceIndex
,
5467 uint32_t remoteDeviceIndex
,
5468 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5470 assert(localDeviceIndex
== remoteDeviceIndex
);
5472 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5473 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5474 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5475 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5478 static const VkTimeDomainEXT radv_time_domains
[] = {
5479 VK_TIME_DOMAIN_DEVICE_EXT
,
5480 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5481 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5484 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5485 VkPhysicalDevice physicalDevice
,
5486 uint32_t *pTimeDomainCount
,
5487 VkTimeDomainEXT
*pTimeDomains
)
5490 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5492 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5493 vk_outarray_append(&out
, i
) {
5494 *i
= radv_time_domains
[d
];
5498 return vk_outarray_status(&out
);
5502 radv_clock_gettime(clockid_t clock_id
)
5504 struct timespec current
;
5507 ret
= clock_gettime(clock_id
, ¤t
);
5508 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5509 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5513 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5516 VkResult
radv_GetCalibratedTimestampsEXT(
5518 uint32_t timestampCount
,
5519 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5520 uint64_t *pTimestamps
,
5521 uint64_t *pMaxDeviation
)
5523 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5524 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5526 uint64_t begin
, end
;
5527 uint64_t max_clock_period
= 0;
5529 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5531 for (d
= 0; d
< timestampCount
; d
++) {
5532 switch (pTimestampInfos
[d
].timeDomain
) {
5533 case VK_TIME_DOMAIN_DEVICE_EXT
:
5534 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5536 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5537 max_clock_period
= MAX2(max_clock_period
, device_period
);
5539 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5540 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5541 max_clock_period
= MAX2(max_clock_period
, 1);
5544 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5545 pTimestamps
[d
] = begin
;
5553 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5556 * The maximum deviation is the sum of the interval over which we
5557 * perform the sampling and the maximum period of any sampled
5558 * clock. That's because the maximum skew between any two sampled
5559 * clock edges is when the sampled clock with the largest period is
5560 * sampled at the end of that period but right at the beginning of the
5561 * sampling interval and some other clock is sampled right at the
5562 * begining of its sampling period and right at the end of the
5563 * sampling interval. Let's assume the GPU has the longest clock
5564 * period and that the application is sampling GPU and monotonic:
5567 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5568 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5572 * GPU -----_____-----_____-----_____-----_____
5575 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5576 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5578 * Interval <----------------->
5579 * Deviation <-------------------------->
5583 * m = read(monotonic) 2
5586 * We round the sample interval up by one tick to cover sampling error
5587 * in the interval clock
5590 uint64_t sample_interval
= end
- begin
+ 1;
5592 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5597 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5598 VkPhysicalDevice physicalDevice
,
5599 VkSampleCountFlagBits samples
,
5600 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5602 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5603 VK_SAMPLE_COUNT_4_BIT
|
5604 VK_SAMPLE_COUNT_8_BIT
)) {
5605 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5607 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };