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 <llvm/Config/llvm-config.h>
33 #include "radv_debug.h"
34 #include "radv_private.h"
35 #include "radv_shader.h"
37 #include "util/disk_cache.h"
38 #include "util/strtod.h"
42 #include <amdgpu_drm.h>
43 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
44 #include "ac_llvm_util.h"
45 #include "vk_format.h"
48 #include "util/build_id.h"
49 #include "util/debug.h"
50 #include "util/mesa-sha1.h"
51 #include "compiler/glsl_types.h"
52 #include "util/xmlpool.h"
55 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
58 unsigned char sha1
[20];
59 unsigned ptr_size
= sizeof(void*);
61 memset(uuid
, 0, VK_UUID_SIZE
);
62 _mesa_sha1_init(&ctx
);
64 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
65 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
68 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
69 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
70 _mesa_sha1_final(&ctx
, sha1
);
72 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
77 radv_get_driver_uuid(void *uuid
)
79 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
83 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
85 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
89 radv_get_visible_vram_size(struct radv_physical_device
*device
)
91 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
95 radv_get_vram_size(struct radv_physical_device
*device
)
97 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
101 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
103 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
104 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
105 uint64_t vram_size
= radv_get_vram_size(device
);
106 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
107 device
->memory_properties
.memoryHeapCount
= 0;
109 vram_index
= device
->memory_properties
.memoryHeapCount
++;
110 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
112 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
115 if (visible_vram_size
) {
116 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
117 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
118 .size
= visible_vram_size
,
119 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
122 if (device
->rad_info
.gart_size
> 0) {
123 gart_index
= device
->memory_properties
.memoryHeapCount
++;
124 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
125 .size
= device
->rad_info
.gart_size
,
126 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
130 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
131 unsigned type_count
= 0;
132 if (vram_index
>= 0) {
133 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
134 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
135 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
136 .heapIndex
= vram_index
,
139 if (gart_index
>= 0 && device
->rad_info
.has_dedicated_vram
) {
140 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
141 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
142 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
143 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
144 .heapIndex
= gart_index
,
147 if (visible_vram_index
>= 0) {
148 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
149 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
150 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
151 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
152 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
153 .heapIndex
= visible_vram_index
,
156 if (gart_index
>= 0 && !device
->rad_info
.has_dedicated_vram
) {
157 /* Put GTT after visible VRAM for GPUs without dedicated VRAM
158 * as they have identical property flags, and according to the
159 * spec, for types with identical flags, the one with greater
160 * performance must be given a lower index. */
161 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
162 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
163 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
165 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
166 .heapIndex
= gart_index
,
169 if (gart_index
>= 0) {
170 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
171 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
172 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
173 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
174 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
175 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
176 .heapIndex
= gart_index
,
179 device
->memory_properties
.memoryTypeCount
= type_count
;
183 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
185 const char *family
= getenv("RADV_FORCE_FAMILY");
191 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
192 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
193 /* Override family and chip_class. */
194 device
->rad_info
.family
= i
;
196 if (i
>= CHIP_NAVI10
)
197 device
->rad_info
.chip_class
= GFX10
;
198 else if (i
>= CHIP_VEGA10
)
199 device
->rad_info
.chip_class
= GFX9
;
200 else if (i
>= CHIP_TONGA
)
201 device
->rad_info
.chip_class
= GFX8
;
202 else if (i
>= CHIP_BONAIRE
)
203 device
->rad_info
.chip_class
= GFX7
;
205 device
->rad_info
.chip_class
= GFX6
;
211 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
216 radv_physical_device_init(struct radv_physical_device
*device
,
217 struct radv_instance
*instance
,
218 drmDevicePtr drm_device
)
220 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
222 drmVersionPtr version
;
226 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
228 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
229 radv_logi("Could not open device '%s'", path
);
231 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
234 version
= drmGetVersion(fd
);
238 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
239 radv_logi("Could not get the kernel driver version for device '%s'", path
);
241 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
242 "failed to get version %s: %m", path
);
245 if (strcmp(version
->name
, "amdgpu")) {
246 drmFreeVersion(version
);
249 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
250 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
252 return VK_ERROR_INCOMPATIBLE_DRIVER
;
254 drmFreeVersion(version
);
256 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
257 radv_logi("Found compatible device '%s'.", path
);
259 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
260 device
->instance
= instance
;
262 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
263 instance
->perftest_flags
);
265 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
269 if (instance
->enabled_extensions
.KHR_display
) {
270 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
271 if (master_fd
>= 0) {
272 uint32_t accel_working
= 0;
273 struct drm_amdgpu_info request
= {
274 .return_pointer
= (uintptr_t)&accel_working
,
275 .return_size
= sizeof(accel_working
),
276 .query
= AMDGPU_INFO_ACCEL_WORKING
279 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
286 device
->master_fd
= master_fd
;
287 device
->local_fd
= fd
;
288 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
290 radv_handle_env_var_force_family(device
);
292 device
->use_aco
= instance
->perftest_flags
& RADV_PERFTEST_ACO
;
293 if ((device
->rad_info
.chip_class
< GFX8
||
294 device
->rad_info
.chip_class
> GFX9
) && device
->use_aco
) {
295 fprintf(stderr
, "WARNING: disabling ACO on unsupported GPUs.\n");
296 device
->use_aco
= false;
299 snprintf(device
->name
, sizeof(device
->name
),
300 "AMD RADV%s %s (LLVM " MESA_LLVM_VERSION_STRING
")", device
->use_aco
? "/ACO" : "",
301 device
->rad_info
.name
);
303 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
304 device
->ws
->destroy(device
->ws
);
305 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
306 "cannot generate UUID");
310 /* These flags affect shader compilation. */
311 uint64_t shader_env_flags
=
312 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
313 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0) |
314 (device
->use_aco
? 0x4 : 0);
316 /* The gpu id is already embedded in the uuid so we just pass "radv"
317 * when creating the cache.
319 char buf
[VK_UUID_SIZE
* 2 + 1];
320 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
321 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
323 if (device
->rad_info
.chip_class
< GFX8
||
324 device
->rad_info
.chip_class
> GFX9
)
325 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
327 radv_get_driver_uuid(&device
->driver_uuid
);
328 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
330 device
->out_of_order_rast_allowed
= device
->rad_info
.has_out_of_order_rast
&&
331 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
333 device
->dcc_msaa_allowed
=
334 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
336 device
->use_shader_ballot
= device
->rad_info
.chip_class
>= GFX8
&&
337 (device
->use_aco
|| device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
);
339 device
->use_ngg
= device
->rad_info
.chip_class
>= GFX10
&&
340 device
->rad_info
.family
!= CHIP_NAVI14
&&
341 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_NGG
);
343 device
->use_ngg_streamout
= false;
345 /* Determine the number of threads per wave for all stages. */
346 device
->cs_wave_size
= 64;
347 device
->ps_wave_size
= 64;
348 device
->ge_wave_size
= 64;
350 if (device
->rad_info
.chip_class
>= GFX10
) {
351 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
352 device
->cs_wave_size
= 32;
354 /* For pixel shaders, wave64 is recommanded. */
355 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
356 device
->ps_wave_size
= 32;
358 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
359 device
->ge_wave_size
= 32;
362 radv_physical_device_init_mem_types(device
);
363 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
365 device
->bus_info
= *drm_device
->businfo
.pci
;
367 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
368 ac_print_gpu_info(&device
->rad_info
);
370 /* The WSI is structured as a layer on top of the driver, so this has
371 * to be the last part of initialization (at least until we get other
374 result
= radv_init_wsi(device
);
375 if (result
!= VK_SUCCESS
) {
376 device
->ws
->destroy(device
->ws
);
377 vk_error(instance
, result
);
391 radv_physical_device_finish(struct radv_physical_device
*device
)
393 radv_finish_wsi(device
);
394 device
->ws
->destroy(device
->ws
);
395 disk_cache_destroy(device
->disk_cache
);
396 close(device
->local_fd
);
397 if (device
->master_fd
!= -1)
398 close(device
->master_fd
);
402 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
403 VkSystemAllocationScope allocationScope
)
409 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
410 size_t align
, VkSystemAllocationScope allocationScope
)
412 return realloc(pOriginal
, size
);
416 default_free_func(void *pUserData
, void *pMemory
)
421 static const VkAllocationCallbacks default_alloc
= {
423 .pfnAllocation
= default_alloc_func
,
424 .pfnReallocation
= default_realloc_func
,
425 .pfnFree
= default_free_func
,
428 static const struct debug_control radv_debug_options
[] = {
429 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
430 {"nodcc", RADV_DEBUG_NO_DCC
},
431 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
432 {"nocache", RADV_DEBUG_NO_CACHE
},
433 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
434 {"nohiz", RADV_DEBUG_NO_HIZ
},
435 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
436 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
437 {"allbos", RADV_DEBUG_ALL_BOS
},
438 {"noibs", RADV_DEBUG_NO_IBS
},
439 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
440 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
441 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
442 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
443 {"nosisched", RADV_DEBUG_NO_SISCHED
},
444 {"preoptir", RADV_DEBUG_PREOPTIR
},
445 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
446 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
447 {"info", RADV_DEBUG_INFO
},
448 {"errors", RADV_DEBUG_ERRORS
},
449 {"startup", RADV_DEBUG_STARTUP
},
450 {"checkir", RADV_DEBUG_CHECKIR
},
451 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
452 {"nobinning", RADV_DEBUG_NOBINNING
},
453 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
454 {"nongg", RADV_DEBUG_NO_NGG
},
455 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
456 {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS
},
457 {"metashaders", RADV_DEBUG_DUMP_META_SHADERS
},
462 radv_get_debug_option_name(int id
)
464 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
465 return radv_debug_options
[id
].string
;
468 static const struct debug_control radv_perftest_options
[] = {
469 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
470 {"sisched", RADV_PERFTEST_SISCHED
},
471 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
472 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
473 {"bolist", RADV_PERFTEST_BO_LIST
},
474 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
475 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
476 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
477 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
478 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
479 {"dfsm", RADV_PERFTEST_DFSM
},
480 {"aco", RADV_PERFTEST_ACO
},
485 radv_get_perftest_option_name(int id
)
487 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
488 return radv_perftest_options
[id
].string
;
492 radv_handle_per_app_options(struct radv_instance
*instance
,
493 const VkApplicationInfo
*info
)
495 const char *name
= info
? info
->pApplicationName
: NULL
;
500 if (!strcmp(name
, "Talos - Linux - 32bit") ||
501 !strcmp(name
, "Talos - Linux - 64bit")) {
502 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
503 /* Force enable LLVM sisched for Talos because it looks
504 * safe and it gives few more FPS.
506 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
508 } else if (!strcmp(name
, "DOOM_VFR")) {
509 /* Work around a Doom VFR game bug */
510 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
511 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
512 /* Workaround for a WaW hazard when LLVM moves/merges
513 * load/store memory operations.
514 * See https://reviews.llvm.org/D61313
516 if (LLVM_VERSION_MAJOR
< 9)
517 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
518 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
519 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
)) {
520 /* Force enable VK_AMD_shader_ballot because it looks
521 * safe and it gives a nice boost (+20% on Vega 56 at
524 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
526 } else if (!strcmp(name
, "Fledge")) {
528 * Zero VRAM for "The Surge 2"
530 * This avoid a hang when when rendering any level. Likely
531 * uninitialized data in an indirect draw.
533 instance
->debug_flags
|= RADV_DEBUG_ZERO_VRAM
;
537 static int radv_get_instance_extension_index(const char *name
)
539 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
540 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
546 static const char radv_dri_options_xml
[] =
548 DRI_CONF_SECTION_PERFORMANCE
549 DRI_CONF_ADAPTIVE_SYNC("true")
550 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
551 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
555 static void radv_init_dri_options(struct radv_instance
*instance
)
557 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
558 driParseConfigFiles(&instance
->dri_options
,
559 &instance
->available_dri_options
,
561 instance
->engineName
,
562 instance
->engineVersion
);
565 VkResult
radv_CreateInstance(
566 const VkInstanceCreateInfo
* pCreateInfo
,
567 const VkAllocationCallbacks
* pAllocator
,
568 VkInstance
* pInstance
)
570 struct radv_instance
*instance
;
573 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
575 uint32_t client_version
;
576 if (pCreateInfo
->pApplicationInfo
&&
577 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
578 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
580 client_version
= VK_API_VERSION_1_0
;
583 const char *engine_name
= NULL
;
584 uint32_t engine_version
= 0;
585 if (pCreateInfo
->pApplicationInfo
) {
586 engine_name
= pCreateInfo
->pApplicationInfo
->pEngineName
;
587 engine_version
= pCreateInfo
->pApplicationInfo
->engineVersion
;
590 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
591 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
593 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
595 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
598 instance
->alloc
= *pAllocator
;
600 instance
->alloc
= default_alloc
;
602 instance
->apiVersion
= client_version
;
603 instance
->physicalDeviceCount
= -1;
605 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
608 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
609 radv_perftest_options
);
611 if (instance
->perftest_flags
& RADV_PERFTEST_ACO
)
612 fprintf(stderr
, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
614 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
615 radv_logi("Created an instance");
617 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
618 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
619 int index
= radv_get_instance_extension_index(ext_name
);
621 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
622 vk_free2(&default_alloc
, pAllocator
, instance
);
623 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
626 instance
->enabled_extensions
.extensions
[index
] = true;
629 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
630 if (result
!= VK_SUCCESS
) {
631 vk_free2(&default_alloc
, pAllocator
, instance
);
632 return vk_error(instance
, result
);
635 instance
->engineName
= vk_strdup(&instance
->alloc
, engine_name
,
636 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
637 instance
->engineVersion
= engine_version
;
640 glsl_type_singleton_init_or_ref();
642 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
644 radv_init_dri_options(instance
);
645 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
647 *pInstance
= radv_instance_to_handle(instance
);
652 void radv_DestroyInstance(
653 VkInstance _instance
,
654 const VkAllocationCallbacks
* pAllocator
)
656 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
661 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
662 radv_physical_device_finish(instance
->physicalDevices
+ i
);
665 vk_free(&instance
->alloc
, instance
->engineName
);
667 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
669 glsl_type_singleton_decref();
672 driDestroyOptionCache(&instance
->dri_options
);
673 driDestroyOptionInfo(&instance
->available_dri_options
);
675 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
677 vk_free(&instance
->alloc
, instance
);
681 radv_enumerate_devices(struct radv_instance
*instance
)
683 /* TODO: Check for more devices ? */
684 drmDevicePtr devices
[8];
685 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
688 instance
->physicalDeviceCount
= 0;
690 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
692 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
693 radv_logi("Found %d drm nodes", max_devices
);
696 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
698 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
699 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
700 devices
[i
]->bustype
== DRM_BUS_PCI
&&
701 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
703 result
= radv_physical_device_init(instance
->physicalDevices
+
704 instance
->physicalDeviceCount
,
707 if (result
== VK_SUCCESS
)
708 ++instance
->physicalDeviceCount
;
709 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
713 drmFreeDevices(devices
, max_devices
);
718 VkResult
radv_EnumeratePhysicalDevices(
719 VkInstance _instance
,
720 uint32_t* pPhysicalDeviceCount
,
721 VkPhysicalDevice
* pPhysicalDevices
)
723 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
726 if (instance
->physicalDeviceCount
< 0) {
727 result
= radv_enumerate_devices(instance
);
728 if (result
!= VK_SUCCESS
&&
729 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
733 if (!pPhysicalDevices
) {
734 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
736 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
737 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
738 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
741 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
745 VkResult
radv_EnumeratePhysicalDeviceGroups(
746 VkInstance _instance
,
747 uint32_t* pPhysicalDeviceGroupCount
,
748 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
750 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
753 if (instance
->physicalDeviceCount
< 0) {
754 result
= radv_enumerate_devices(instance
);
755 if (result
!= VK_SUCCESS
&&
756 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
760 if (!pPhysicalDeviceGroupProperties
) {
761 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
763 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
764 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
765 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
766 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
767 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
770 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
774 void radv_GetPhysicalDeviceFeatures(
775 VkPhysicalDevice physicalDevice
,
776 VkPhysicalDeviceFeatures
* pFeatures
)
778 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
779 memset(pFeatures
, 0, sizeof(*pFeatures
));
781 *pFeatures
= (VkPhysicalDeviceFeatures
) {
782 .robustBufferAccess
= true,
783 .fullDrawIndexUint32
= true,
784 .imageCubeArray
= true,
785 .independentBlend
= true,
786 .geometryShader
= true,
787 .tessellationShader
= true,
788 .sampleRateShading
= true,
789 .dualSrcBlend
= true,
791 .multiDrawIndirect
= true,
792 .drawIndirectFirstInstance
= true,
794 .depthBiasClamp
= true,
795 .fillModeNonSolid
= true,
800 .multiViewport
= true,
801 .samplerAnisotropy
= true,
802 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
803 .textureCompressionASTC_LDR
= false,
804 .textureCompressionBC
= true,
805 .occlusionQueryPrecise
= true,
806 .pipelineStatisticsQuery
= true,
807 .vertexPipelineStoresAndAtomics
= true,
808 .fragmentStoresAndAtomics
= true,
809 .shaderTessellationAndGeometryPointSize
= true,
810 .shaderImageGatherExtended
= true,
811 .shaderStorageImageExtendedFormats
= true,
812 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
813 .shaderUniformBufferArrayDynamicIndexing
= true,
814 .shaderSampledImageArrayDynamicIndexing
= true,
815 .shaderStorageBufferArrayDynamicIndexing
= true,
816 .shaderStorageImageArrayDynamicIndexing
= true,
817 .shaderStorageImageReadWithoutFormat
= true,
818 .shaderStorageImageWriteWithoutFormat
= true,
819 .shaderClipDistance
= true,
820 .shaderCullDistance
= true,
821 .shaderFloat64
= true,
823 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
&& !pdevice
->use_aco
,
824 .sparseBinding
= true,
825 .variableMultisampleRate
= true,
826 .inheritedQueries
= true,
830 void radv_GetPhysicalDeviceFeatures2(
831 VkPhysicalDevice physicalDevice
,
832 VkPhysicalDeviceFeatures2
*pFeatures
)
834 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
835 vk_foreach_struct(ext
, pFeatures
->pNext
) {
836 switch (ext
->sType
) {
837 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
838 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
839 features
->variablePointersStorageBuffer
= true;
840 features
->variablePointers
= true;
843 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
844 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
845 features
->multiview
= true;
846 features
->multiviewGeometryShader
= true;
847 features
->multiviewTessellationShader
= true;
850 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
851 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
852 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
853 features
->shaderDrawParameters
= true;
856 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
857 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
858 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
859 features
->protectedMemory
= false;
862 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
863 VkPhysicalDevice16BitStorageFeatures
*features
=
864 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
865 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
866 features
->storageBuffer16BitAccess
= enabled
;
867 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
868 features
->storagePushConstant16
= enabled
;
869 features
->storageInputOutput16
= enabled
&& LLVM_VERSION_MAJOR
>= 9;
872 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
873 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
874 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
875 features
->samplerYcbcrConversion
= true;
878 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
879 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
880 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
881 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
882 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
883 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
884 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
885 features
->shaderSampledImageArrayNonUniformIndexing
= true;
886 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
887 features
->shaderStorageImageArrayNonUniformIndexing
= true;
888 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
889 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
890 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
891 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
892 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
893 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
894 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
895 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
896 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
897 features
->descriptorBindingUpdateUnusedWhilePending
= true;
898 features
->descriptorBindingPartiallyBound
= true;
899 features
->descriptorBindingVariableDescriptorCount
= true;
900 features
->runtimeDescriptorArray
= true;
903 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
904 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
905 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
906 features
->conditionalRendering
= true;
907 features
->inheritedConditionalRendering
= false;
910 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
911 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
912 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
913 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
914 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
917 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
918 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
919 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
920 features
->transformFeedback
= true;
921 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
924 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
925 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
926 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
927 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
930 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
931 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
932 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
933 features
->memoryPriority
= VK_TRUE
;
936 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
937 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
938 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
939 features
->bufferDeviceAddress
= true;
940 features
->bufferDeviceAddressCaptureReplay
= false;
941 features
->bufferDeviceAddressMultiDevice
= false;
944 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
945 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
946 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
947 features
->depthClipEnable
= true;
950 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
951 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
952 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
953 features
->hostQueryReset
= true;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
957 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
958 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
959 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
960 features
->storageBuffer8BitAccess
= enabled
;
961 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
962 features
->storagePushConstant8
= enabled
;
965 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
966 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
967 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
968 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
969 features
->shaderInt8
= !pdevice
->use_aco
;
972 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
973 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
974 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
975 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
976 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
979 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
980 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
=
981 (VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*)ext
;
982 features
->shaderDemoteToHelperInvocation
= pdevice
->use_aco
;
985 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
986 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
987 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
989 features
->inlineUniformBlock
= true;
990 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
993 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
994 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
995 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
996 features
->computeDerivativeGroupQuads
= false;
997 features
->computeDerivativeGroupLinear
= true;
1000 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1001 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1002 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1003 features
->ycbcrImageArrays
= true;
1006 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1007 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1008 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1009 features
->uniformBufferStandardLayout
= true;
1012 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1013 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1014 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1015 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1018 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1019 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1020 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1021 features
->imagelessFramebuffer
= true;
1024 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1025 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1026 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1027 features
->pipelineExecutableInfo
= true;
1030 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1031 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1032 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1033 features
->shaderSubgroupClock
= true;
1034 features
->shaderDeviceClock
= false;
1037 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1038 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1039 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1040 features
->texelBufferAlignment
= true;
1047 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1050 void radv_GetPhysicalDeviceProperties(
1051 VkPhysicalDevice physicalDevice
,
1052 VkPhysicalDeviceProperties
* pProperties
)
1054 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1055 VkSampleCountFlags sample_counts
= 0xf;
1057 /* make sure that the entire descriptor set is addressable with a signed
1058 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1059 * be at most 2 GiB. the combined image & samples object count as one of
1060 * both. This limit is for the pipeline layout, not for the set layout, but
1061 * there is no set limit, so we just set a pipeline limit. I don't think
1062 * any app is going to hit this soon. */
1063 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1064 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1065 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1066 32 /* sampler, largest when combined with image */ +
1067 64 /* sampled image */ +
1068 64 /* storage image */);
1070 VkPhysicalDeviceLimits limits
= {
1071 .maxImageDimension1D
= (1 << 14),
1072 .maxImageDimension2D
= (1 << 14),
1073 .maxImageDimension3D
= (1 << 11),
1074 .maxImageDimensionCube
= (1 << 14),
1075 .maxImageArrayLayers
= (1 << 11),
1076 .maxTexelBufferElements
= 128 * 1024 * 1024,
1077 .maxUniformBufferRange
= UINT32_MAX
,
1078 .maxStorageBufferRange
= UINT32_MAX
,
1079 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1080 .maxMemoryAllocationCount
= UINT32_MAX
,
1081 .maxSamplerAllocationCount
= 64 * 1024,
1082 .bufferImageGranularity
= 64, /* A cache line */
1083 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1084 .maxBoundDescriptorSets
= MAX_SETS
,
1085 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1086 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1087 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1088 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1089 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1090 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1091 .maxPerStageResources
= max_descriptor_set_size
,
1092 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1093 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1094 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1095 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1096 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1097 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1098 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1099 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1100 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1101 .maxVertexInputBindings
= MAX_VBS
,
1102 .maxVertexInputAttributeOffset
= 2047,
1103 .maxVertexInputBindingStride
= 2048,
1104 .maxVertexOutputComponents
= 128,
1105 .maxTessellationGenerationLevel
= 64,
1106 .maxTessellationPatchSize
= 32,
1107 .maxTessellationControlPerVertexInputComponents
= 128,
1108 .maxTessellationControlPerVertexOutputComponents
= 128,
1109 .maxTessellationControlPerPatchOutputComponents
= 120,
1110 .maxTessellationControlTotalOutputComponents
= 4096,
1111 .maxTessellationEvaluationInputComponents
= 128,
1112 .maxTessellationEvaluationOutputComponents
= 128,
1113 .maxGeometryShaderInvocations
= 127,
1114 .maxGeometryInputComponents
= 64,
1115 .maxGeometryOutputComponents
= 128,
1116 .maxGeometryOutputVertices
= 256,
1117 .maxGeometryTotalOutputComponents
= 1024,
1118 .maxFragmentInputComponents
= 128,
1119 .maxFragmentOutputAttachments
= 8,
1120 .maxFragmentDualSrcAttachments
= 1,
1121 .maxFragmentCombinedOutputResources
= 8,
1122 .maxComputeSharedMemorySize
= 32768,
1123 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1124 .maxComputeWorkGroupInvocations
= 2048,
1125 .maxComputeWorkGroupSize
= {
1130 .subPixelPrecisionBits
= 8,
1131 .subTexelPrecisionBits
= 8,
1132 .mipmapPrecisionBits
= 8,
1133 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1134 .maxDrawIndirectCount
= UINT32_MAX
,
1135 .maxSamplerLodBias
= 16,
1136 .maxSamplerAnisotropy
= 16,
1137 .maxViewports
= MAX_VIEWPORTS
,
1138 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1139 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1140 .viewportSubPixelBits
= 8,
1141 .minMemoryMapAlignment
= 4096, /* A page */
1142 .minTexelBufferOffsetAlignment
= 4,
1143 .minUniformBufferOffsetAlignment
= 4,
1144 .minStorageBufferOffsetAlignment
= 4,
1145 .minTexelOffset
= -32,
1146 .maxTexelOffset
= 31,
1147 .minTexelGatherOffset
= -32,
1148 .maxTexelGatherOffset
= 31,
1149 .minInterpolationOffset
= -2,
1150 .maxInterpolationOffset
= 2,
1151 .subPixelInterpolationOffsetBits
= 8,
1152 .maxFramebufferWidth
= (1 << 14),
1153 .maxFramebufferHeight
= (1 << 14),
1154 .maxFramebufferLayers
= (1 << 10),
1155 .framebufferColorSampleCounts
= sample_counts
,
1156 .framebufferDepthSampleCounts
= sample_counts
,
1157 .framebufferStencilSampleCounts
= sample_counts
,
1158 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1159 .maxColorAttachments
= MAX_RTS
,
1160 .sampledImageColorSampleCounts
= sample_counts
,
1161 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1162 .sampledImageDepthSampleCounts
= sample_counts
,
1163 .sampledImageStencilSampleCounts
= sample_counts
,
1164 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1165 .maxSampleMaskWords
= 1,
1166 .timestampComputeAndGraphics
= true,
1167 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1168 .maxClipDistances
= 8,
1169 .maxCullDistances
= 8,
1170 .maxCombinedClipAndCullDistances
= 8,
1171 .discreteQueuePriorities
= 2,
1172 .pointSizeRange
= { 0.0, 8192.0 },
1173 .lineWidthRange
= { 0.0, 7.9921875 },
1174 .pointSizeGranularity
= (1.0 / 8.0),
1175 .lineWidthGranularity
= (1.0 / 128.0),
1176 .strictLines
= false, /* FINISHME */
1177 .standardSampleLocations
= true,
1178 .optimalBufferCopyOffsetAlignment
= 128,
1179 .optimalBufferCopyRowPitchAlignment
= 128,
1180 .nonCoherentAtomSize
= 64,
1183 *pProperties
= (VkPhysicalDeviceProperties
) {
1184 .apiVersion
= radv_physical_device_api_version(pdevice
),
1185 .driverVersion
= vk_get_driver_version(),
1186 .vendorID
= ATI_VENDOR_ID
,
1187 .deviceID
= pdevice
->rad_info
.pci_id
,
1188 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1190 .sparseProperties
= {0},
1193 strcpy(pProperties
->deviceName
, pdevice
->name
);
1194 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1197 void radv_GetPhysicalDeviceProperties2(
1198 VkPhysicalDevice physicalDevice
,
1199 VkPhysicalDeviceProperties2
*pProperties
)
1201 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1202 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1204 vk_foreach_struct(ext
, pProperties
->pNext
) {
1205 switch (ext
->sType
) {
1206 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1207 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1208 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1209 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1212 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1213 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1214 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1215 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1216 properties
->deviceLUIDValid
= false;
1219 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1220 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1221 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1222 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1225 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1226 VkPhysicalDevicePointClippingProperties
*properties
=
1227 (VkPhysicalDevicePointClippingProperties
*)ext
;
1228 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1231 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1232 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1233 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1234 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1237 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1238 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1239 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1240 properties
->minImportedHostPointerAlignment
= 4096;
1243 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1244 VkPhysicalDeviceSubgroupProperties
*properties
=
1245 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1246 properties
->subgroupSize
= 64;
1247 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1248 properties
->supportedOperations
=
1249 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1250 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1251 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1252 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1253 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1254 properties
->supportedOperations
|=
1255 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1256 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1257 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1258 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1260 properties
->quadOperationsInAllStages
= true;
1263 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1264 VkPhysicalDeviceMaintenance3Properties
*properties
=
1265 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1266 /* Make sure everything is addressable by a signed 32-bit int, and
1267 * our largest descriptors are 96 bytes. */
1268 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1269 /* Our buffer size fields allow only this much */
1270 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1273 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1274 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1275 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1276 /* GFX6-8 only support single channel min/max filter. */
1277 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1278 properties
->filterMinmaxSingleComponentFormats
= true;
1281 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1282 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1283 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1285 /* Shader engines. */
1286 properties
->shaderEngineCount
=
1287 pdevice
->rad_info
.max_se
;
1288 properties
->shaderArraysPerEngineCount
=
1289 pdevice
->rad_info
.max_sh_per_se
;
1290 properties
->computeUnitsPerShaderArray
=
1291 pdevice
->rad_info
.num_good_cu_per_sh
;
1292 properties
->simdPerComputeUnit
= 4;
1293 properties
->wavefrontsPerSimd
=
1294 pdevice
->rad_info
.family
== CHIP_TONGA
||
1295 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1296 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1297 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1298 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1299 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1300 properties
->wavefrontSize
= 64;
1303 properties
->sgprsPerSimd
=
1304 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1305 properties
->minSgprAllocation
=
1306 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1307 properties
->maxSgprAllocation
=
1308 pdevice
->rad_info
.family
== CHIP_TONGA
||
1309 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1310 properties
->sgprAllocationGranularity
=
1311 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1314 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1315 properties
->minVgprAllocation
= 4;
1316 properties
->maxVgprAllocation
= 256;
1317 properties
->vgprAllocationGranularity
= 4;
1320 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1321 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1322 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1324 properties
->shaderCoreFeatures
= 0;
1325 properties
->activeComputeUnitCount
=
1326 pdevice
->rad_info
.num_good_compute_units
;
1329 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1330 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1331 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1332 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1335 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1336 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1337 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1338 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1339 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1340 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1341 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1342 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1343 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1344 properties
->robustBufferAccessUpdateAfterBind
= false;
1345 properties
->quadDivergentImplicitLod
= false;
1347 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1348 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1349 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1350 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1351 32 /* sampler, largest when combined with image */ +
1352 64 /* sampled image */ +
1353 64 /* storage image */);
1354 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1355 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1356 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1357 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1358 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1359 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1360 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1361 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1362 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1363 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1364 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1365 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1366 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1367 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1368 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1371 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1372 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1373 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1374 properties
->protectedNoFault
= false;
1377 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1378 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1379 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1380 properties
->primitiveOverestimationSize
= 0;
1381 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1382 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1383 properties
->primitiveUnderestimation
= VK_FALSE
;
1384 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1385 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1386 properties
->degenerateLinesRasterized
= VK_FALSE
;
1387 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1388 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1391 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1392 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1393 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1394 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1395 properties
->pciBus
= pdevice
->bus_info
.bus
;
1396 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1397 properties
->pciFunction
= pdevice
->bus_info
.func
;
1400 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1401 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1402 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1404 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1405 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
, "radv");
1406 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1407 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1408 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1410 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1418 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1419 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1420 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1421 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1422 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1423 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1424 properties
->maxTransformFeedbackStreamDataSize
= 512;
1425 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1426 properties
->maxTransformFeedbackBufferDataStride
= 512;
1427 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1428 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1429 properties
->transformFeedbackRasterizationStreamSelect
= false;
1430 properties
->transformFeedbackDraw
= true;
1433 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1434 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1435 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1437 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1438 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1439 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1440 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1441 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1444 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1445 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1446 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1447 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1448 VK_SAMPLE_COUNT_4_BIT
|
1449 VK_SAMPLE_COUNT_8_BIT
;
1450 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1451 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1452 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1453 properties
->sampleLocationSubPixelBits
= 4;
1454 properties
->variableSampleLocations
= VK_FALSE
;
1457 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1458 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1459 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1461 /* We support all of the depth resolve modes */
1462 properties
->supportedDepthResolveModes
=
1463 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1464 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1465 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1466 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1468 /* Average doesn't make sense for stencil so we don't support that */
1469 properties
->supportedStencilResolveModes
=
1470 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1471 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1472 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1474 properties
->independentResolveNone
= VK_TRUE
;
1475 properties
->independentResolve
= VK_TRUE
;
1478 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1479 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*properties
=
1480 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1481 properties
->storageTexelBufferOffsetAlignmentBytes
= 4;
1482 properties
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1483 properties
->uniformTexelBufferOffsetAlignmentBytes
= 4;
1484 properties
->uniformTexelBufferOffsetSingleTexelAlignment
= true;
1493 static void radv_get_physical_device_queue_family_properties(
1494 struct radv_physical_device
* pdevice
,
1496 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1498 int num_queue_families
= 1;
1500 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1501 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1502 num_queue_families
++;
1504 if (pQueueFamilyProperties
== NULL
) {
1505 *pCount
= num_queue_families
;
1514 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1515 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1516 VK_QUEUE_COMPUTE_BIT
|
1517 VK_QUEUE_TRANSFER_BIT
|
1518 VK_QUEUE_SPARSE_BINDING_BIT
,
1520 .timestampValidBits
= 64,
1521 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1526 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1527 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1528 if (*pCount
> idx
) {
1529 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1530 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1531 VK_QUEUE_TRANSFER_BIT
|
1532 VK_QUEUE_SPARSE_BINDING_BIT
,
1533 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1534 .timestampValidBits
= 64,
1535 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1543 void radv_GetPhysicalDeviceQueueFamilyProperties(
1544 VkPhysicalDevice physicalDevice
,
1546 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1548 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1549 if (!pQueueFamilyProperties
) {
1550 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1553 VkQueueFamilyProperties
*properties
[] = {
1554 pQueueFamilyProperties
+ 0,
1555 pQueueFamilyProperties
+ 1,
1556 pQueueFamilyProperties
+ 2,
1558 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1559 assert(*pCount
<= 3);
1562 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1563 VkPhysicalDevice physicalDevice
,
1565 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1567 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1568 if (!pQueueFamilyProperties
) {
1569 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1572 VkQueueFamilyProperties
*properties
[] = {
1573 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1574 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1575 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1577 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1578 assert(*pCount
<= 3);
1581 void radv_GetPhysicalDeviceMemoryProperties(
1582 VkPhysicalDevice physicalDevice
,
1583 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1585 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1587 *pMemoryProperties
= physical_device
->memory_properties
;
1591 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1592 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1594 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1595 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1596 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1597 uint64_t vram_size
= radv_get_vram_size(device
);
1598 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1599 uint64_t heap_budget
, heap_usage
;
1601 /* For all memory heaps, the computation of budget is as follow:
1602 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1604 * The Vulkan spec 1.1.97 says that the budget should include any
1605 * currently allocated device memory.
1607 * Note that the application heap usages are not really accurate (eg.
1608 * in presence of shared buffers).
1610 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1611 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1613 switch (device
->mem_type_indices
[i
]) {
1614 case RADV_MEM_TYPE_VRAM
:
1615 heap_usage
= device
->ws
->query_value(device
->ws
,
1616 RADEON_ALLOCATED_VRAM
);
1618 heap_budget
= vram_size
-
1619 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1622 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1623 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1625 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1626 heap_usage
= device
->ws
->query_value(device
->ws
,
1627 RADEON_ALLOCATED_VRAM_VIS
);
1629 heap_budget
= visible_vram_size
-
1630 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1633 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1634 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1636 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1637 heap_usage
= device
->ws
->query_value(device
->ws
,
1638 RADEON_ALLOCATED_GTT
);
1640 heap_budget
= gtt_size
-
1641 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1644 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1645 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1652 /* The heapBudget and heapUsage values must be zero for array elements
1653 * greater than or equal to
1654 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1656 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1657 memoryBudget
->heapBudget
[i
] = 0;
1658 memoryBudget
->heapUsage
[i
] = 0;
1662 void radv_GetPhysicalDeviceMemoryProperties2(
1663 VkPhysicalDevice physicalDevice
,
1664 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1666 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1667 &pMemoryProperties
->memoryProperties
);
1669 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1670 vk_find_struct(pMemoryProperties
->pNext
,
1671 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1673 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1676 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1678 VkExternalMemoryHandleTypeFlagBits handleType
,
1679 const void *pHostPointer
,
1680 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1682 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1686 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1687 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1688 uint32_t memoryTypeBits
= 0;
1689 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1690 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1691 memoryTypeBits
= (1 << i
);
1695 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1699 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1703 static enum radeon_ctx_priority
1704 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1706 /* Default to MEDIUM when a specific global priority isn't requested */
1708 return RADEON_CTX_PRIORITY_MEDIUM
;
1710 switch(pObj
->globalPriority
) {
1711 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1712 return RADEON_CTX_PRIORITY_REALTIME
;
1713 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1714 return RADEON_CTX_PRIORITY_HIGH
;
1715 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1716 return RADEON_CTX_PRIORITY_MEDIUM
;
1717 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1718 return RADEON_CTX_PRIORITY_LOW
;
1720 unreachable("Illegal global priority value");
1721 return RADEON_CTX_PRIORITY_INVALID
;
1726 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1727 uint32_t queue_family_index
, int idx
,
1728 VkDeviceQueueCreateFlags flags
,
1729 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1731 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1732 queue
->device
= device
;
1733 queue
->queue_family_index
= queue_family_index
;
1734 queue
->queue_idx
= idx
;
1735 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1736 queue
->flags
= flags
;
1738 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1740 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1746 radv_queue_finish(struct radv_queue
*queue
)
1749 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1751 if (queue
->initial_full_flush_preamble_cs
)
1752 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1753 if (queue
->initial_preamble_cs
)
1754 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1755 if (queue
->continue_preamble_cs
)
1756 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1757 if (queue
->descriptor_bo
)
1758 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1759 if (queue
->scratch_bo
)
1760 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1761 if (queue
->esgs_ring_bo
)
1762 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1763 if (queue
->gsvs_ring_bo
)
1764 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1765 if (queue
->tess_rings_bo
)
1766 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1768 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
1769 if (queue
->gds_oa_bo
)
1770 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
1771 if (queue
->compute_scratch_bo
)
1772 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1776 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1778 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1779 bo_list
->list
.count
= bo_list
->capacity
= 0;
1780 bo_list
->list
.bos
= NULL
;
1784 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1786 free(bo_list
->list
.bos
);
1787 pthread_mutex_destroy(&bo_list
->mutex
);
1790 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1791 struct radeon_winsys_bo
*bo
)
1793 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1798 if (unlikely(!device
->use_global_bo_list
))
1801 pthread_mutex_lock(&bo_list
->mutex
);
1802 if (bo_list
->list
.count
== bo_list
->capacity
) {
1803 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1804 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1807 pthread_mutex_unlock(&bo_list
->mutex
);
1808 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1811 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1812 bo_list
->capacity
= capacity
;
1815 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1816 pthread_mutex_unlock(&bo_list
->mutex
);
1820 static void radv_bo_list_remove(struct radv_device
*device
,
1821 struct radeon_winsys_bo
*bo
)
1823 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1828 if (unlikely(!device
->use_global_bo_list
))
1831 pthread_mutex_lock(&bo_list
->mutex
);
1832 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1833 if (bo_list
->list
.bos
[i
] == bo
) {
1834 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1835 --bo_list
->list
.count
;
1839 pthread_mutex_unlock(&bo_list
->mutex
);
1843 radv_device_init_gs_info(struct radv_device
*device
)
1845 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1846 device
->physical_device
->rad_info
.family
);
1849 static int radv_get_device_extension_index(const char *name
)
1851 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1852 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1859 radv_get_int_debug_option(const char *name
, int default_value
)
1866 result
= default_value
;
1870 result
= strtol(str
, &endptr
, 0);
1871 if (str
== endptr
) {
1872 /* No digits founs. */
1873 result
= default_value
;
1880 VkResult
radv_CreateDevice(
1881 VkPhysicalDevice physicalDevice
,
1882 const VkDeviceCreateInfo
* pCreateInfo
,
1883 const VkAllocationCallbacks
* pAllocator
,
1886 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1888 struct radv_device
*device
;
1890 bool keep_shader_info
= false;
1892 /* Check enabled features */
1893 if (pCreateInfo
->pEnabledFeatures
) {
1894 VkPhysicalDeviceFeatures supported_features
;
1895 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1896 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1897 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1898 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1899 for (uint32_t i
= 0; i
< num_features
; i
++) {
1900 if (enabled_feature
[i
] && !supported_feature
[i
])
1901 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1905 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1907 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1909 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1911 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1912 device
->instance
= physical_device
->instance
;
1913 device
->physical_device
= physical_device
;
1915 device
->ws
= physical_device
->ws
;
1917 device
->alloc
= *pAllocator
;
1919 device
->alloc
= physical_device
->instance
->alloc
;
1921 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1922 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1923 int index
= radv_get_device_extension_index(ext_name
);
1924 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1925 vk_free(&device
->alloc
, device
);
1926 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1929 device
->enabled_extensions
.extensions
[index
] = true;
1932 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1934 /* With update after bind we can't attach bo's to the command buffer
1935 * from the descriptor set anymore, so we have to use a global BO list.
1937 device
->use_global_bo_list
=
1938 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1939 device
->enabled_extensions
.EXT_descriptor_indexing
||
1940 device
->enabled_extensions
.EXT_buffer_device_address
;
1942 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1943 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1945 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1946 list_inithead(&device
->shader_slabs
);
1948 radv_bo_list_init(&device
->bo_list
);
1950 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1951 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1952 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1953 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1954 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1956 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1958 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1959 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1960 if (!device
->queues
[qfi
]) {
1961 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1965 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1967 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1969 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1970 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1971 qfi
, q
, queue_create
->flags
,
1973 if (result
!= VK_SUCCESS
)
1978 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1979 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1981 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
1982 device
->dfsm_allowed
= device
->pbb_allowed
&&
1983 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
1986 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1989 /* The maximum number of scratch waves. Scratch space isn't divided
1990 * evenly between CUs. The number is only a function of the number of CUs.
1991 * We can decrease the constant to decrease the scratch buffer size.
1993 * sctx->scratch_waves must be >= the maximum possible size of
1994 * 1 threadgroup, so that the hw doesn't hang from being unable
1997 * The recommended value is 4 per CU at most. Higher numbers don't
1998 * bring much benefit, but they still occupy chip resources (think
1999 * async compute). I've seen ~2% performance difference between 4 and 32.
2001 uint32_t max_threads_per_block
= 2048;
2002 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
2003 max_threads_per_block
/ 64);
2005 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
2006 S_00B800_CS_W32_EN(device
->physical_device
->cs_wave_size
== 32);
2008 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2009 /* If the KMD allows it (there is a KMD hw register for it),
2010 * allow launching waves out-of-order.
2012 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
2015 radv_device_init_gs_info(device
);
2017 device
->tess_offchip_block_dw_size
=
2018 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
2020 if (getenv("RADV_TRACE_FILE")) {
2021 const char *filename
= getenv("RADV_TRACE_FILE");
2023 keep_shader_info
= true;
2025 if (!radv_init_trace(device
))
2028 fprintf(stderr
, "*****************************************************************************\n");
2029 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
2030 fprintf(stderr
, "*****************************************************************************\n");
2032 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
2033 radv_dump_enabled_options(device
, stderr
);
2036 device
->keep_shader_info
= keep_shader_info
;
2038 result
= radv_device_init_meta(device
);
2039 if (result
!= VK_SUCCESS
)
2042 radv_device_init_msaa(device
);
2044 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
2045 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
2047 case RADV_QUEUE_GENERAL
:
2048 /* Since amdgpu version 3.6.0, CONTEXT_CONTROL is emitted by the kernel */
2049 if (device
->physical_device
->rad_info
.drm_minor
< 6) {
2050 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2051 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
2052 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
2055 case RADV_QUEUE_COMPUTE
:
2056 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
2057 radeon_emit(device
->empty_cs
[family
], 0);
2060 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
2063 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
2064 cik_create_gfx_config(device
);
2066 VkPipelineCacheCreateInfo ci
;
2067 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
2070 ci
.pInitialData
= NULL
;
2071 ci
.initialDataSize
= 0;
2073 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
2075 if (result
!= VK_SUCCESS
)
2078 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
2080 device
->force_aniso
=
2081 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
2082 if (device
->force_aniso
>= 0) {
2083 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2084 1 << util_logbase2(device
->force_aniso
));
2087 *pDevice
= radv_device_to_handle(device
);
2091 radv_device_finish_meta(device
);
2093 radv_bo_list_finish(&device
->bo_list
);
2095 if (device
->trace_bo
)
2096 device
->ws
->buffer_destroy(device
->trace_bo
);
2098 if (device
->gfx_init
)
2099 device
->ws
->buffer_destroy(device
->gfx_init
);
2101 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2102 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2103 radv_queue_finish(&device
->queues
[i
][q
]);
2104 if (device
->queue_count
[i
])
2105 vk_free(&device
->alloc
, device
->queues
[i
]);
2108 vk_free(&device
->alloc
, device
);
2112 void radv_DestroyDevice(
2114 const VkAllocationCallbacks
* pAllocator
)
2116 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2121 if (device
->trace_bo
)
2122 device
->ws
->buffer_destroy(device
->trace_bo
);
2124 if (device
->gfx_init
)
2125 device
->ws
->buffer_destroy(device
->gfx_init
);
2127 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2128 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2129 radv_queue_finish(&device
->queues
[i
][q
]);
2130 if (device
->queue_count
[i
])
2131 vk_free(&device
->alloc
, device
->queues
[i
]);
2132 if (device
->empty_cs
[i
])
2133 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2135 radv_device_finish_meta(device
);
2137 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2138 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2140 radv_destroy_shader_slabs(device
);
2142 radv_bo_list_finish(&device
->bo_list
);
2143 vk_free(&device
->alloc
, device
);
2146 VkResult
radv_EnumerateInstanceLayerProperties(
2147 uint32_t* pPropertyCount
,
2148 VkLayerProperties
* pProperties
)
2150 if (pProperties
== NULL
) {
2151 *pPropertyCount
= 0;
2155 /* None supported at this time */
2156 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2159 VkResult
radv_EnumerateDeviceLayerProperties(
2160 VkPhysicalDevice physicalDevice
,
2161 uint32_t* pPropertyCount
,
2162 VkLayerProperties
* pProperties
)
2164 if (pProperties
== NULL
) {
2165 *pPropertyCount
= 0;
2169 /* None supported at this time */
2170 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2173 void radv_GetDeviceQueue2(
2175 const VkDeviceQueueInfo2
* pQueueInfo
,
2178 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2179 struct radv_queue
*queue
;
2181 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2182 if (pQueueInfo
->flags
!= queue
->flags
) {
2183 /* From the Vulkan 1.1.70 spec:
2185 * "The queue returned by vkGetDeviceQueue2 must have the same
2186 * flags value from this structure as that used at device
2187 * creation time in a VkDeviceQueueCreateInfo instance. If no
2188 * matching flags were specified at device creation time then
2189 * pQueue will return VK_NULL_HANDLE."
2191 *pQueue
= VK_NULL_HANDLE
;
2195 *pQueue
= radv_queue_to_handle(queue
);
2198 void radv_GetDeviceQueue(
2200 uint32_t queueFamilyIndex
,
2201 uint32_t queueIndex
,
2204 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2205 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2206 .queueFamilyIndex
= queueFamilyIndex
,
2207 .queueIndex
= queueIndex
2210 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2214 fill_geom_tess_rings(struct radv_queue
*queue
,
2216 bool add_sample_positions
,
2217 uint32_t esgs_ring_size
,
2218 struct radeon_winsys_bo
*esgs_ring_bo
,
2219 uint32_t gsvs_ring_size
,
2220 struct radeon_winsys_bo
*gsvs_ring_bo
,
2221 uint32_t tess_factor_ring_size
,
2222 uint32_t tess_offchip_ring_offset
,
2223 uint32_t tess_offchip_ring_size
,
2224 struct radeon_winsys_bo
*tess_rings_bo
)
2226 uint32_t *desc
= &map
[4];
2229 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2231 /* stride 0, num records - size, add tid, swizzle, elsize4,
2234 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2235 S_008F04_SWIZZLE_ENABLE(true);
2236 desc
[2] = esgs_ring_size
;
2237 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2238 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2239 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2240 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2241 S_008F0C_INDEX_STRIDE(3) |
2242 S_008F0C_ADD_TID_ENABLE(1);
2244 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2245 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2246 S_008F0C_OOB_SELECT(2) |
2247 S_008F0C_RESOURCE_LEVEL(1);
2249 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2250 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2251 S_008F0C_ELEMENT_SIZE(1);
2254 /* GS entry for ES->GS ring */
2255 /* stride 0, num records - size, elsize0,
2258 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
2259 desc
[6] = esgs_ring_size
;
2260 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2261 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2262 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2263 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2265 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2266 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2267 S_008F0C_OOB_SELECT(2) |
2268 S_008F0C_RESOURCE_LEVEL(1);
2270 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2271 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2278 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2280 /* VS entry for GS->VS ring */
2281 /* stride 0, num records - size, elsize0,
2284 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
2285 desc
[2] = gsvs_ring_size
;
2286 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2287 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2288 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2289 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2291 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2292 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2293 S_008F0C_OOB_SELECT(2) |
2294 S_008F0C_RESOURCE_LEVEL(1);
2296 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2297 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2300 /* stride gsvs_itemsize, num records 64
2301 elsize 4, index stride 16 */
2302 /* shader will patch stride and desc[2] */
2304 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
2305 S_008F04_SWIZZLE_ENABLE(1);
2307 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2308 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2309 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2310 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2311 S_008F0C_INDEX_STRIDE(1) |
2312 S_008F0C_ADD_TID_ENABLE(true);
2314 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2315 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2316 S_008F0C_OOB_SELECT(2) |
2317 S_008F0C_RESOURCE_LEVEL(1);
2319 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2320 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2321 S_008F0C_ELEMENT_SIZE(1);
2328 if (tess_rings_bo
) {
2329 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2330 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2333 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
2334 desc
[2] = tess_factor_ring_size
;
2335 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2336 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2337 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2338 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2340 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2341 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2342 S_008F0C_OOB_SELECT(3) |
2343 S_008F0C_RESOURCE_LEVEL(1);
2345 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2346 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2349 desc
[4] = tess_offchip_va
;
2350 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
2351 desc
[6] = tess_offchip_ring_size
;
2352 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2353 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2354 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2355 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2357 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2358 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2359 S_008F0C_OOB_SELECT(3) |
2360 S_008F0C_RESOURCE_LEVEL(1);
2362 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2363 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2369 if (add_sample_positions
) {
2370 /* add sample positions after all rings */
2371 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2373 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2375 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2377 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2382 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2384 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2385 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2386 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2387 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2388 unsigned max_offchip_buffers
;
2389 unsigned offchip_granularity
;
2390 unsigned hs_offchip_param
;
2394 * This must be one less than the maximum number due to a hw limitation.
2395 * Various hardware bugs need thGFX7
2398 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2399 * Gfx7 should limit max_offchip_buffers to 508
2400 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2402 * Follow AMDVLK here.
2404 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2405 max_offchip_buffers_per_se
= 256;
2406 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2407 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2408 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2409 --max_offchip_buffers_per_se
;
2411 max_offchip_buffers
= max_offchip_buffers_per_se
*
2412 device
->physical_device
->rad_info
.max_se
;
2414 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2415 * around by setting 4K granularity.
2417 if (device
->tess_offchip_block_dw_size
== 4096) {
2418 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2419 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2421 assert(device
->tess_offchip_block_dw_size
== 8192);
2422 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2425 switch (device
->physical_device
->rad_info
.chip_class
) {
2427 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2432 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2440 *max_offchip_buffers_p
= max_offchip_buffers
;
2441 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2442 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2443 --max_offchip_buffers
;
2445 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2446 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2449 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2451 return hs_offchip_param
;
2455 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2456 struct radeon_winsys_bo
*esgs_ring_bo
,
2457 uint32_t esgs_ring_size
,
2458 struct radeon_winsys_bo
*gsvs_ring_bo
,
2459 uint32_t gsvs_ring_size
)
2461 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2465 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2468 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2470 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2471 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2472 radeon_emit(cs
, esgs_ring_size
>> 8);
2473 radeon_emit(cs
, gsvs_ring_size
>> 8);
2475 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2476 radeon_emit(cs
, esgs_ring_size
>> 8);
2477 radeon_emit(cs
, gsvs_ring_size
>> 8);
2482 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2483 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2484 struct radeon_winsys_bo
*tess_rings_bo
)
2491 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2493 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2495 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2496 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2497 S_030938_SIZE(tf_ring_size
/ 4));
2498 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2501 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2502 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2503 S_030984_BASE_HI(tf_va
>> 40));
2504 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2505 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2506 S_030944_BASE_HI(tf_va
>> 40));
2508 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2511 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2512 S_008988_SIZE(tf_ring_size
/ 4));
2513 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2515 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2521 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2522 struct radeon_winsys_bo
*compute_scratch_bo
)
2524 uint64_t scratch_va
;
2526 if (!compute_scratch_bo
)
2529 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2531 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2533 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2534 radeon_emit(cs
, scratch_va
);
2535 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2536 S_008F04_SWIZZLE_ENABLE(1));
2540 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2541 struct radeon_cmdbuf
*cs
,
2542 struct radeon_winsys_bo
*descriptor_bo
)
2549 va
= radv_buffer_get_va(descriptor_bo
);
2551 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2553 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2554 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2555 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2556 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2557 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2559 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2560 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2563 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2564 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2565 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2566 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2567 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2569 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2570 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2574 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2575 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2576 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2577 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2578 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2579 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2581 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2582 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2589 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2591 struct radv_device
*device
= queue
->device
;
2593 if (device
->gfx_init
) {
2594 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2596 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2597 radeon_emit(cs
, va
);
2598 radeon_emit(cs
, va
>> 32);
2599 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2601 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2603 struct radv_physical_device
*physical_device
= device
->physical_device
;
2604 si_emit_graphics(physical_device
, cs
);
2609 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2611 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2612 si_emit_compute(physical_device
, cs
);
2616 radv_get_preamble_cs(struct radv_queue
*queue
,
2617 uint32_t scratch_size
,
2618 uint32_t compute_scratch_size
,
2619 uint32_t esgs_ring_size
,
2620 uint32_t gsvs_ring_size
,
2621 bool needs_tess_rings
,
2623 bool needs_sample_positions
,
2624 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2625 struct radeon_cmdbuf
**initial_preamble_cs
,
2626 struct radeon_cmdbuf
**continue_preamble_cs
)
2628 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2629 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2630 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2631 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2632 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2633 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2634 struct radeon_winsys_bo
*gds_bo
= NULL
;
2635 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
2636 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2637 bool add_tess_rings
= false, add_gds
= false, add_sample_positions
= false;
2638 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2639 unsigned max_offchip_buffers
;
2640 unsigned hs_offchip_param
= 0;
2641 unsigned tess_offchip_ring_offset
;
2642 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2643 if (!queue
->has_tess_rings
) {
2644 if (needs_tess_rings
)
2645 add_tess_rings
= true;
2647 if (!queue
->has_gds
) {
2651 if (!queue
->has_sample_positions
) {
2652 if (needs_sample_positions
)
2653 add_sample_positions
= true;
2655 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2656 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2657 &max_offchip_buffers
);
2658 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2659 tess_offchip_ring_size
= max_offchip_buffers
*
2660 queue
->device
->tess_offchip_block_dw_size
* 4;
2662 if (scratch_size
<= queue
->scratch_size
&&
2663 compute_scratch_size
<= queue
->compute_scratch_size
&&
2664 esgs_ring_size
<= queue
->esgs_ring_size
&&
2665 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2666 !add_tess_rings
&& !add_gds
&& !add_sample_positions
&&
2667 queue
->initial_preamble_cs
) {
2668 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2669 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2670 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2671 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
&&
2672 !needs_tess_rings
&& !needs_gds
&& !needs_sample_positions
)
2673 *continue_preamble_cs
= NULL
;
2677 if (scratch_size
> queue
->scratch_size
) {
2678 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2683 RADV_BO_PRIORITY_SCRATCH
);
2687 scratch_bo
= queue
->scratch_bo
;
2689 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2690 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2691 compute_scratch_size
,
2695 RADV_BO_PRIORITY_SCRATCH
);
2696 if (!compute_scratch_bo
)
2700 compute_scratch_bo
= queue
->compute_scratch_bo
;
2702 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2703 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2708 RADV_BO_PRIORITY_SCRATCH
);
2712 esgs_ring_bo
= queue
->esgs_ring_bo
;
2713 esgs_ring_size
= queue
->esgs_ring_size
;
2716 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2717 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2722 RADV_BO_PRIORITY_SCRATCH
);
2726 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2727 gsvs_ring_size
= queue
->gsvs_ring_size
;
2730 if (add_tess_rings
) {
2731 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2732 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2736 RADV_BO_PRIORITY_SCRATCH
);
2740 tess_rings_bo
= queue
->tess_rings_bo
;
2744 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
2746 /* 4 streamout GDS counters.
2747 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
2749 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2753 RADV_BO_PRIORITY_SCRATCH
);
2757 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2761 RADV_BO_PRIORITY_SCRATCH
);
2765 gds_bo
= queue
->gds_bo
;
2766 gds_oa_bo
= queue
->gds_oa_bo
;
2769 if (scratch_bo
!= queue
->scratch_bo
||
2770 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2771 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2772 tess_rings_bo
!= queue
->tess_rings_bo
||
2773 add_sample_positions
) {
2775 if (gsvs_ring_bo
|| esgs_ring_bo
||
2776 tess_rings_bo
|| add_sample_positions
) {
2777 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2778 if (add_sample_positions
)
2779 size
+= 128; /* 64+32+16+8 = 120 bytes */
2781 else if (scratch_bo
)
2782 size
= 8; /* 2 dword */
2784 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2788 RADEON_FLAG_CPU_ACCESS
|
2789 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2790 RADEON_FLAG_READ_ONLY
,
2791 RADV_BO_PRIORITY_DESCRIPTOR
);
2795 descriptor_bo
= queue
->descriptor_bo
;
2797 if (descriptor_bo
!= queue
->descriptor_bo
) {
2798 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2801 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2802 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2803 S_008F04_SWIZZLE_ENABLE(1);
2804 map
[0] = scratch_va
;
2808 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2809 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2810 esgs_ring_size
, esgs_ring_bo
,
2811 gsvs_ring_size
, gsvs_ring_bo
,
2812 tess_factor_ring_size
,
2813 tess_offchip_ring_offset
,
2814 tess_offchip_ring_size
,
2817 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2820 for(int i
= 0; i
< 3; ++i
) {
2821 struct radeon_cmdbuf
*cs
= NULL
;
2822 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2823 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2830 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2832 /* Emit initial configuration. */
2833 switch (queue
->queue_family_index
) {
2834 case RADV_QUEUE_GENERAL
:
2835 radv_init_graphics_state(cs
, queue
);
2837 case RADV_QUEUE_COMPUTE
:
2838 radv_init_compute_state(cs
, queue
);
2840 case RADV_QUEUE_TRANSFER
:
2844 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2845 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2846 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2848 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2849 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2852 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2853 gsvs_ring_bo
, gsvs_ring_size
);
2854 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2855 tess_factor_ring_size
, tess_rings_bo
);
2856 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2857 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2860 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
2862 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
2865 si_cs_emit_cache_flush(cs
,
2866 queue
->device
->physical_device
->rad_info
.chip_class
,
2868 queue
->queue_family_index
== RING_COMPUTE
&&
2869 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2870 (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
)) |
2871 RADV_CMD_FLAG_INV_ICACHE
|
2872 RADV_CMD_FLAG_INV_SCACHE
|
2873 RADV_CMD_FLAG_INV_VCACHE
|
2874 RADV_CMD_FLAG_INV_L2
|
2875 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2876 } else if (i
== 1) {
2877 si_cs_emit_cache_flush(cs
,
2878 queue
->device
->physical_device
->rad_info
.chip_class
,
2880 queue
->queue_family_index
== RING_COMPUTE
&&
2881 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2882 RADV_CMD_FLAG_INV_ICACHE
|
2883 RADV_CMD_FLAG_INV_SCACHE
|
2884 RADV_CMD_FLAG_INV_VCACHE
|
2885 RADV_CMD_FLAG_INV_L2
|
2886 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2889 if (!queue
->device
->ws
->cs_finalize(cs
))
2893 if (queue
->initial_full_flush_preamble_cs
)
2894 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2896 if (queue
->initial_preamble_cs
)
2897 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2899 if (queue
->continue_preamble_cs
)
2900 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2902 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2903 queue
->initial_preamble_cs
= dest_cs
[1];
2904 queue
->continue_preamble_cs
= dest_cs
[2];
2906 if (scratch_bo
!= queue
->scratch_bo
) {
2907 if (queue
->scratch_bo
)
2908 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2909 queue
->scratch_bo
= scratch_bo
;
2910 queue
->scratch_size
= scratch_size
;
2913 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2914 if (queue
->compute_scratch_bo
)
2915 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2916 queue
->compute_scratch_bo
= compute_scratch_bo
;
2917 queue
->compute_scratch_size
= compute_scratch_size
;
2920 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2921 if (queue
->esgs_ring_bo
)
2922 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2923 queue
->esgs_ring_bo
= esgs_ring_bo
;
2924 queue
->esgs_ring_size
= esgs_ring_size
;
2927 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2928 if (queue
->gsvs_ring_bo
)
2929 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2930 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2931 queue
->gsvs_ring_size
= gsvs_ring_size
;
2934 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2935 queue
->tess_rings_bo
= tess_rings_bo
;
2936 queue
->has_tess_rings
= true;
2939 if (gds_bo
!= queue
->gds_bo
) {
2940 queue
->gds_bo
= gds_bo
;
2941 queue
->has_gds
= true;
2944 if (gds_oa_bo
!= queue
->gds_oa_bo
)
2945 queue
->gds_oa_bo
= gds_oa_bo
;
2947 if (descriptor_bo
!= queue
->descriptor_bo
) {
2948 if (queue
->descriptor_bo
)
2949 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2951 queue
->descriptor_bo
= descriptor_bo
;
2954 if (add_sample_positions
)
2955 queue
->has_sample_positions
= true;
2957 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2958 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2959 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2960 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2961 *continue_preamble_cs
= NULL
;
2964 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2966 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2967 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2968 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2969 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2970 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2971 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2972 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2973 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2974 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2975 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2976 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2977 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2978 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2979 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
2980 queue
->device
->ws
->buffer_destroy(gds_bo
);
2981 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
2982 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
2984 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2987 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2988 struct radv_winsys_sem_counts
*counts
,
2990 const VkSemaphore
*sems
,
2994 int syncobj_idx
= 0, sem_idx
= 0;
2996 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2999 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3000 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3002 if (sem
->temp_syncobj
|| sem
->syncobj
)
3003 counts
->syncobj_count
++;
3005 counts
->sem_count
++;
3008 if (_fence
!= VK_NULL_HANDLE
) {
3009 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3010 if (fence
->temp_syncobj
|| fence
->syncobj
)
3011 counts
->syncobj_count
++;
3014 if (counts
->syncobj_count
) {
3015 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
3016 if (!counts
->syncobj
)
3017 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3020 if (counts
->sem_count
) {
3021 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
3023 free(counts
->syncobj
);
3024 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3028 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3029 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3031 if (sem
->temp_syncobj
) {
3032 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
3034 else if (sem
->syncobj
)
3035 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
3038 counts
->sem
[sem_idx
++] = sem
->sem
;
3042 if (_fence
!= VK_NULL_HANDLE
) {
3043 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3044 if (fence
->temp_syncobj
)
3045 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
3046 else if (fence
->syncobj
)
3047 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
3054 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
3056 free(sem_info
->wait
.syncobj
);
3057 free(sem_info
->wait
.sem
);
3058 free(sem_info
->signal
.syncobj
);
3059 free(sem_info
->signal
.sem
);
3063 static void radv_free_temp_syncobjs(struct radv_device
*device
,
3065 const VkSemaphore
*sems
)
3067 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3068 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3070 if (sem
->temp_syncobj
) {
3071 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
3072 sem
->temp_syncobj
= 0;
3078 radv_alloc_sem_info(struct radv_instance
*instance
,
3079 struct radv_winsys_sem_info
*sem_info
,
3081 const VkSemaphore
*wait_sems
,
3082 int num_signal_sems
,
3083 const VkSemaphore
*signal_sems
,
3087 memset(sem_info
, 0, sizeof(*sem_info
));
3089 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
3092 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
3094 radv_free_sem_info(sem_info
);
3096 /* caller can override these */
3097 sem_info
->cs_emit_wait
= true;
3098 sem_info
->cs_emit_signal
= true;
3102 /* Signals fence as soon as all the work currently put on queue is done. */
3103 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
3104 struct radv_fence
*fence
)
3108 struct radv_winsys_sem_info sem_info
;
3110 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
3111 radv_fence_to_handle(fence
));
3112 if (result
!= VK_SUCCESS
)
3115 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3116 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3117 1, NULL
, NULL
, &sem_info
, NULL
,
3118 false, fence
->fence
);
3119 radv_free_sem_info(&sem_info
);
3122 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
3127 VkResult
radv_QueueSubmit(
3129 uint32_t submitCount
,
3130 const VkSubmitInfo
* pSubmits
,
3133 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3134 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3135 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3136 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
3138 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
3139 uint32_t scratch_size
= 0;
3140 uint32_t compute_scratch_size
= 0;
3141 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
3142 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
3144 bool fence_emitted
= false;
3145 bool tess_rings_needed
= false;
3146 bool gds_needed
= false;
3147 bool sample_positions_needed
= false;
3149 /* Do this first so failing to allocate scratch buffers can't result in
3150 * partially executed submissions. */
3151 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3152 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3153 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3154 pSubmits
[i
].pCommandBuffers
[j
]);
3156 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
3157 compute_scratch_size
= MAX2(compute_scratch_size
,
3158 cmd_buffer
->compute_scratch_size_needed
);
3159 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
3160 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
3161 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
3162 gds_needed
|= cmd_buffer
->gds_needed
;
3163 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3167 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3168 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3169 gds_needed
, sample_positions_needed
,
3170 &initial_flush_preamble_cs
,
3171 &initial_preamble_cs
, &continue_preamble_cs
);
3172 if (result
!= VK_SUCCESS
)
3175 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3176 struct radeon_cmdbuf
**cs_array
;
3177 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
3178 bool can_patch
= true;
3180 struct radv_winsys_sem_info sem_info
;
3182 result
= radv_alloc_sem_info(queue
->device
->instance
,
3184 pSubmits
[i
].waitSemaphoreCount
,
3185 pSubmits
[i
].pWaitSemaphores
,
3186 pSubmits
[i
].signalSemaphoreCount
,
3187 pSubmits
[i
].pSignalSemaphores
,
3189 if (result
!= VK_SUCCESS
)
3192 if (!pSubmits
[i
].commandBufferCount
) {
3193 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
3194 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3195 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3200 radv_loge("failed to submit CS %d\n", i
);
3203 fence_emitted
= true;
3205 radv_free_sem_info(&sem_info
);
3209 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3210 (pSubmits
[i
].commandBufferCount
));
3212 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3213 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3214 pSubmits
[i
].pCommandBuffers
[j
]);
3215 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3217 cs_array
[j
] = cmd_buffer
->cs
;
3218 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3221 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3224 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3225 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3226 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3228 advance
= MIN2(max_cs_submission
,
3229 pSubmits
[i
].commandBufferCount
- j
);
3231 if (queue
->device
->trace_bo
)
3232 *queue
->device
->trace_id_ptr
= 0;
3234 sem_info
.cs_emit_wait
= j
== 0;
3235 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3237 if (unlikely(queue
->device
->use_global_bo_list
)) {
3238 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3239 bo_list
= &queue
->device
->bo_list
.list
;
3242 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3243 advance
, initial_preamble
, continue_preamble_cs
,
3245 can_patch
, base_fence
);
3247 if (unlikely(queue
->device
->use_global_bo_list
))
3248 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3251 radv_loge("failed to submit CS %d\n", i
);
3254 fence_emitted
= true;
3255 if (queue
->device
->trace_bo
) {
3256 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3260 radv_free_temp_syncobjs(queue
->device
,
3261 pSubmits
[i
].waitSemaphoreCount
,
3262 pSubmits
[i
].pWaitSemaphores
);
3263 radv_free_sem_info(&sem_info
);
3268 if (!fence_emitted
) {
3269 result
= radv_signal_fence(queue
, fence
);
3270 if (result
!= VK_SUCCESS
)
3278 VkResult
radv_QueueWaitIdle(
3281 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3283 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3284 radv_queue_family_to_ring(queue
->queue_family_index
),
3289 VkResult
radv_DeviceWaitIdle(
3292 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3294 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3295 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3296 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3302 VkResult
radv_EnumerateInstanceExtensionProperties(
3303 const char* pLayerName
,
3304 uint32_t* pPropertyCount
,
3305 VkExtensionProperties
* pProperties
)
3307 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3309 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3310 if (radv_supported_instance_extensions
.extensions
[i
]) {
3311 vk_outarray_append(&out
, prop
) {
3312 *prop
= radv_instance_extensions
[i
];
3317 return vk_outarray_status(&out
);
3320 VkResult
radv_EnumerateDeviceExtensionProperties(
3321 VkPhysicalDevice physicalDevice
,
3322 const char* pLayerName
,
3323 uint32_t* pPropertyCount
,
3324 VkExtensionProperties
* pProperties
)
3326 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3327 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3329 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3330 if (device
->supported_extensions
.extensions
[i
]) {
3331 vk_outarray_append(&out
, prop
) {
3332 *prop
= radv_device_extensions
[i
];
3337 return vk_outarray_status(&out
);
3340 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3341 VkInstance _instance
,
3344 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3345 bool unchecked
= instance
? instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
3348 return radv_lookup_entrypoint_unchecked(pName
);
3350 return radv_lookup_entrypoint_checked(pName
,
3351 instance
? instance
->apiVersion
: 0,
3352 instance
? &instance
->enabled_extensions
: NULL
,
3357 /* The loader wants us to expose a second GetInstanceProcAddr function
3358 * to work around certain LD_PRELOAD issues seen in apps.
3361 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3362 VkInstance instance
,
3366 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3367 VkInstance instance
,
3370 return radv_GetInstanceProcAddr(instance
, pName
);
3374 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3375 VkInstance _instance
,
3379 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3380 VkInstance _instance
,
3383 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3385 return radv_lookup_physical_device_entrypoint_checked(pName
,
3386 instance
? instance
->apiVersion
: 0,
3387 instance
? &instance
->enabled_extensions
: NULL
);
3390 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3394 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3395 bool unchecked
= device
? device
->instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
3398 return radv_lookup_entrypoint_unchecked(pName
);
3400 return radv_lookup_entrypoint_checked(pName
,
3401 device
->instance
->apiVersion
,
3402 &device
->instance
->enabled_extensions
,
3403 &device
->enabled_extensions
);
3407 bool radv_get_memory_fd(struct radv_device
*device
,
3408 struct radv_device_memory
*memory
,
3411 struct radeon_bo_metadata metadata
;
3413 if (memory
->image
) {
3414 radv_init_metadata(device
, memory
->image
, &metadata
);
3415 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3418 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3422 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3423 const VkMemoryAllocateInfo
* pAllocateInfo
,
3424 const VkAllocationCallbacks
* pAllocator
,
3425 VkDeviceMemory
* pMem
)
3427 struct radv_device_memory
*mem
;
3429 enum radeon_bo_domain domain
;
3431 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3433 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3435 if (pAllocateInfo
->allocationSize
== 0) {
3436 /* Apparently, this is allowed */
3437 *pMem
= VK_NULL_HANDLE
;
3441 const VkImportMemoryFdInfoKHR
*import_info
=
3442 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3443 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3444 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3445 const VkExportMemoryAllocateInfo
*export_info
=
3446 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3447 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3448 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3450 const struct wsi_memory_allocate_info
*wsi_info
=
3451 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3453 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3454 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3456 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3458 if (wsi_info
&& wsi_info
->implicit_sync
)
3459 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3461 if (dedicate_info
) {
3462 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3463 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3469 float priority_float
= 0.5;
3470 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3471 vk_find_struct_const(pAllocateInfo
->pNext
,
3472 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3474 priority_float
= priority_ext
->priority
;
3476 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3477 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3479 mem
->user_ptr
= NULL
;
3482 assert(import_info
->handleType
==
3483 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3484 import_info
->handleType
==
3485 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3486 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3487 priority
, NULL
, NULL
);
3489 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3492 close(import_info
->fd
);
3494 } else if (host_ptr_info
) {
3495 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3496 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3497 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3498 pAllocateInfo
->allocationSize
,
3501 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3504 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3507 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3508 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3509 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3510 domain
= RADEON_DOMAIN_GTT
;
3512 domain
= RADEON_DOMAIN_VRAM
;
3514 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3515 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3517 flags
|= RADEON_FLAG_CPU_ACCESS
;
3519 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3520 flags
|= RADEON_FLAG_GTT_WC
;
3522 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3523 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3524 if (device
->use_global_bo_list
) {
3525 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3529 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3530 domain
, flags
, priority
);
3533 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3536 mem
->type_index
= mem_type_index
;
3539 result
= radv_bo_list_add(device
, mem
->bo
);
3540 if (result
!= VK_SUCCESS
)
3543 *pMem
= radv_device_memory_to_handle(mem
);
3548 device
->ws
->buffer_destroy(mem
->bo
);
3550 vk_free2(&device
->alloc
, pAllocator
, mem
);
3555 VkResult
radv_AllocateMemory(
3557 const VkMemoryAllocateInfo
* pAllocateInfo
,
3558 const VkAllocationCallbacks
* pAllocator
,
3559 VkDeviceMemory
* pMem
)
3561 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3562 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3565 void radv_FreeMemory(
3567 VkDeviceMemory _mem
,
3568 const VkAllocationCallbacks
* pAllocator
)
3570 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3571 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3576 radv_bo_list_remove(device
, mem
->bo
);
3577 device
->ws
->buffer_destroy(mem
->bo
);
3580 vk_free2(&device
->alloc
, pAllocator
, mem
);
3583 VkResult
radv_MapMemory(
3585 VkDeviceMemory _memory
,
3586 VkDeviceSize offset
,
3588 VkMemoryMapFlags flags
,
3591 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3592 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3600 *ppData
= mem
->user_ptr
;
3602 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3609 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3612 void radv_UnmapMemory(
3614 VkDeviceMemory _memory
)
3616 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3617 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3622 if (mem
->user_ptr
== NULL
)
3623 device
->ws
->buffer_unmap(mem
->bo
);
3626 VkResult
radv_FlushMappedMemoryRanges(
3628 uint32_t memoryRangeCount
,
3629 const VkMappedMemoryRange
* pMemoryRanges
)
3634 VkResult
radv_InvalidateMappedMemoryRanges(
3636 uint32_t memoryRangeCount
,
3637 const VkMappedMemoryRange
* pMemoryRanges
)
3642 void radv_GetBufferMemoryRequirements(
3645 VkMemoryRequirements
* pMemoryRequirements
)
3647 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3648 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3650 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3652 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3653 pMemoryRequirements
->alignment
= 4096;
3655 pMemoryRequirements
->alignment
= 16;
3657 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3660 void radv_GetBufferMemoryRequirements2(
3662 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3663 VkMemoryRequirements2
*pMemoryRequirements
)
3665 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3666 &pMemoryRequirements
->memoryRequirements
);
3667 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3668 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3669 switch (ext
->sType
) {
3670 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3671 VkMemoryDedicatedRequirements
*req
=
3672 (VkMemoryDedicatedRequirements
*) ext
;
3673 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3674 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3683 void radv_GetImageMemoryRequirements(
3686 VkMemoryRequirements
* pMemoryRequirements
)
3688 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3689 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3691 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3693 pMemoryRequirements
->size
= image
->size
;
3694 pMemoryRequirements
->alignment
= image
->alignment
;
3697 void radv_GetImageMemoryRequirements2(
3699 const VkImageMemoryRequirementsInfo2
*pInfo
,
3700 VkMemoryRequirements2
*pMemoryRequirements
)
3702 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3703 &pMemoryRequirements
->memoryRequirements
);
3705 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3707 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3708 switch (ext
->sType
) {
3709 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3710 VkMemoryDedicatedRequirements
*req
=
3711 (VkMemoryDedicatedRequirements
*) ext
;
3712 req
->requiresDedicatedAllocation
= image
->shareable
;
3713 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3722 void radv_GetImageSparseMemoryRequirements(
3725 uint32_t* pSparseMemoryRequirementCount
,
3726 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3731 void radv_GetImageSparseMemoryRequirements2(
3733 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3734 uint32_t* pSparseMemoryRequirementCount
,
3735 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3740 void radv_GetDeviceMemoryCommitment(
3742 VkDeviceMemory memory
,
3743 VkDeviceSize
* pCommittedMemoryInBytes
)
3745 *pCommittedMemoryInBytes
= 0;
3748 VkResult
radv_BindBufferMemory2(VkDevice device
,
3749 uint32_t bindInfoCount
,
3750 const VkBindBufferMemoryInfo
*pBindInfos
)
3752 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3753 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3754 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3757 buffer
->bo
= mem
->bo
;
3758 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3766 VkResult
radv_BindBufferMemory(
3769 VkDeviceMemory memory
,
3770 VkDeviceSize memoryOffset
)
3772 const VkBindBufferMemoryInfo info
= {
3773 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3776 .memoryOffset
= memoryOffset
3779 return radv_BindBufferMemory2(device
, 1, &info
);
3782 VkResult
radv_BindImageMemory2(VkDevice device
,
3783 uint32_t bindInfoCount
,
3784 const VkBindImageMemoryInfo
*pBindInfos
)
3786 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3787 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3788 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3791 image
->bo
= mem
->bo
;
3792 image
->offset
= pBindInfos
[i
].memoryOffset
;
3802 VkResult
radv_BindImageMemory(
3805 VkDeviceMemory memory
,
3806 VkDeviceSize memoryOffset
)
3808 const VkBindImageMemoryInfo info
= {
3809 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3812 .memoryOffset
= memoryOffset
3815 return radv_BindImageMemory2(device
, 1, &info
);
3820 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3821 const VkSparseBufferMemoryBindInfo
*bind
)
3823 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3825 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3826 struct radv_device_memory
*mem
= NULL
;
3828 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3829 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3831 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3832 bind
->pBinds
[i
].resourceOffset
,
3833 bind
->pBinds
[i
].size
,
3834 mem
? mem
->bo
: NULL
,
3835 bind
->pBinds
[i
].memoryOffset
);
3840 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3841 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3843 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3845 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3846 struct radv_device_memory
*mem
= NULL
;
3848 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3849 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3851 device
->ws
->buffer_virtual_bind(image
->bo
,
3852 bind
->pBinds
[i
].resourceOffset
,
3853 bind
->pBinds
[i
].size
,
3854 mem
? mem
->bo
: NULL
,
3855 bind
->pBinds
[i
].memoryOffset
);
3859 VkResult
radv_QueueBindSparse(
3861 uint32_t bindInfoCount
,
3862 const VkBindSparseInfo
* pBindInfo
,
3865 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3866 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3867 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3868 bool fence_emitted
= false;
3872 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3873 struct radv_winsys_sem_info sem_info
;
3874 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3875 radv_sparse_buffer_bind_memory(queue
->device
,
3876 pBindInfo
[i
].pBufferBinds
+ j
);
3879 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3880 radv_sparse_image_opaque_bind_memory(queue
->device
,
3881 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3885 result
= radv_alloc_sem_info(queue
->device
->instance
,
3887 pBindInfo
[i
].waitSemaphoreCount
,
3888 pBindInfo
[i
].pWaitSemaphores
,
3889 pBindInfo
[i
].signalSemaphoreCount
,
3890 pBindInfo
[i
].pSignalSemaphores
,
3892 if (result
!= VK_SUCCESS
)
3895 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3896 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3897 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3902 radv_loge("failed to submit CS %d\n", i
);
3906 fence_emitted
= true;
3909 radv_free_sem_info(&sem_info
);
3914 if (!fence_emitted
) {
3915 result
= radv_signal_fence(queue
, fence
);
3916 if (result
!= VK_SUCCESS
)
3924 VkResult
radv_CreateFence(
3926 const VkFenceCreateInfo
* pCreateInfo
,
3927 const VkAllocationCallbacks
* pAllocator
,
3930 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3931 const VkExportFenceCreateInfo
*export
=
3932 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3933 VkExternalFenceHandleTypeFlags handleTypes
=
3934 export
? export
->handleTypes
: 0;
3936 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3938 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3941 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3943 fence
->fence_wsi
= NULL
;
3944 fence
->temp_syncobj
= 0;
3945 if (device
->always_use_syncobj
|| handleTypes
) {
3946 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3948 vk_free2(&device
->alloc
, pAllocator
, fence
);
3949 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3951 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3952 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3954 fence
->fence
= NULL
;
3956 fence
->fence
= device
->ws
->create_fence();
3957 if (!fence
->fence
) {
3958 vk_free2(&device
->alloc
, pAllocator
, fence
);
3959 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3962 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3963 device
->ws
->signal_fence(fence
->fence
);
3966 *pFence
= radv_fence_to_handle(fence
);
3971 void radv_DestroyFence(
3974 const VkAllocationCallbacks
* pAllocator
)
3976 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3977 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3982 if (fence
->temp_syncobj
)
3983 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3985 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3987 device
->ws
->destroy_fence(fence
->fence
);
3988 if (fence
->fence_wsi
)
3989 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3990 vk_free2(&device
->alloc
, pAllocator
, fence
);
3994 uint64_t radv_get_current_time(void)
3997 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3998 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
4001 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
4003 uint64_t current_time
= radv_get_current_time();
4005 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
4007 return current_time
+ timeout
;
4011 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
4012 uint32_t fenceCount
, const VkFence
*pFences
)
4014 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4015 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4016 if (fence
->fence
== NULL
|| fence
->syncobj
||
4017 fence
->temp_syncobj
|| fence
->fence_wsi
||
4018 (!device
->ws
->is_fence_waitable(fence
->fence
)))
4024 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
4026 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4027 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4028 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
4034 VkResult
radv_WaitForFences(
4036 uint32_t fenceCount
,
4037 const VkFence
* pFences
,
4041 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4042 timeout
= radv_get_absolute_timeout(timeout
);
4044 if (device
->always_use_syncobj
&&
4045 radv_all_fences_syncobj(fenceCount
, pFences
))
4047 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
4049 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4051 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4052 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4053 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
4056 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
4059 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4062 if (!waitAll
&& fenceCount
> 1) {
4063 /* Not doing this by default for waitAll, due to needing to allocate twice. */
4064 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
4065 uint32_t wait_count
= 0;
4066 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
4068 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4070 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4071 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4073 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
4078 fences
[wait_count
++] = fence
->fence
;
4081 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
4082 waitAll
, timeout
- radv_get_current_time());
4085 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4088 while(radv_get_current_time() <= timeout
) {
4089 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4090 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
4097 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4098 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4099 bool expired
= false;
4101 if (fence
->temp_syncobj
) {
4102 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
4107 if (fence
->syncobj
) {
4108 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
4114 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
4115 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
4116 radv_get_current_time() <= timeout
)
4120 expired
= device
->ws
->fence_wait(device
->ws
,
4127 if (fence
->fence_wsi
) {
4128 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
4129 if (result
!= VK_SUCCESS
)
4137 VkResult
radv_ResetFences(VkDevice _device
,
4138 uint32_t fenceCount
,
4139 const VkFence
*pFences
)
4141 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4143 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
4144 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4146 device
->ws
->reset_fence(fence
->fence
);
4148 /* Per spec, we first restore the permanent payload, and then reset, so
4149 * having a temp syncobj should not skip resetting the permanent syncobj. */
4150 if (fence
->temp_syncobj
) {
4151 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4152 fence
->temp_syncobj
= 0;
4155 if (fence
->syncobj
) {
4156 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
4163 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
4165 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4166 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4168 if (fence
->temp_syncobj
) {
4169 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
4170 return success
? VK_SUCCESS
: VK_NOT_READY
;
4173 if (fence
->syncobj
) {
4174 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
4175 return success
? VK_SUCCESS
: VK_NOT_READY
;
4179 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
4180 return VK_NOT_READY
;
4182 if (fence
->fence_wsi
) {
4183 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
4185 if (result
!= VK_SUCCESS
) {
4186 if (result
== VK_TIMEOUT
)
4187 return VK_NOT_READY
;
4195 // Queue semaphore functions
4197 VkResult
radv_CreateSemaphore(
4199 const VkSemaphoreCreateInfo
* pCreateInfo
,
4200 const VkAllocationCallbacks
* pAllocator
,
4201 VkSemaphore
* pSemaphore
)
4203 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4204 const VkExportSemaphoreCreateInfo
*export
=
4205 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
4206 VkExternalSemaphoreHandleTypeFlags handleTypes
=
4207 export
? export
->handleTypes
: 0;
4209 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
4211 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4213 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4215 sem
->temp_syncobj
= 0;
4216 /* create a syncobject if we are going to export this semaphore */
4217 if (device
->always_use_syncobj
|| handleTypes
) {
4218 assert (device
->physical_device
->rad_info
.has_syncobj
);
4219 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4221 vk_free2(&device
->alloc
, pAllocator
, sem
);
4222 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4226 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4228 vk_free2(&device
->alloc
, pAllocator
, sem
);
4229 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4234 *pSemaphore
= radv_semaphore_to_handle(sem
);
4238 void radv_DestroySemaphore(
4240 VkSemaphore _semaphore
,
4241 const VkAllocationCallbacks
* pAllocator
)
4243 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4244 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4249 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4251 device
->ws
->destroy_sem(sem
->sem
);
4252 vk_free2(&device
->alloc
, pAllocator
, sem
);
4255 VkResult
radv_CreateEvent(
4257 const VkEventCreateInfo
* pCreateInfo
,
4258 const VkAllocationCallbacks
* pAllocator
,
4261 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4262 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4264 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4267 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4269 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4271 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4272 RADV_BO_PRIORITY_FENCE
);
4274 vk_free2(&device
->alloc
, pAllocator
, event
);
4275 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4278 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4280 *pEvent
= radv_event_to_handle(event
);
4285 void radv_DestroyEvent(
4288 const VkAllocationCallbacks
* pAllocator
)
4290 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4291 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4295 device
->ws
->buffer_destroy(event
->bo
);
4296 vk_free2(&device
->alloc
, pAllocator
, event
);
4299 VkResult
radv_GetEventStatus(
4303 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4305 if (*event
->map
== 1)
4306 return VK_EVENT_SET
;
4307 return VK_EVENT_RESET
;
4310 VkResult
radv_SetEvent(
4314 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4320 VkResult
radv_ResetEvent(
4324 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4330 VkResult
radv_CreateBuffer(
4332 const VkBufferCreateInfo
* pCreateInfo
,
4333 const VkAllocationCallbacks
* pAllocator
,
4336 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4337 struct radv_buffer
*buffer
;
4339 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4341 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4342 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4344 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4346 buffer
->size
= pCreateInfo
->size
;
4347 buffer
->usage
= pCreateInfo
->usage
;
4350 buffer
->flags
= pCreateInfo
->flags
;
4352 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4353 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4355 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4356 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4357 align64(buffer
->size
, 4096),
4358 4096, 0, RADEON_FLAG_VIRTUAL
,
4359 RADV_BO_PRIORITY_VIRTUAL
);
4361 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4362 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4366 *pBuffer
= radv_buffer_to_handle(buffer
);
4371 void radv_DestroyBuffer(
4374 const VkAllocationCallbacks
* pAllocator
)
4376 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4377 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4382 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4383 device
->ws
->buffer_destroy(buffer
->bo
);
4385 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4388 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4390 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4392 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4393 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4397 static inline unsigned
4398 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4401 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4403 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4406 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4408 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4412 radv_init_dcc_control_reg(struct radv_device
*device
,
4413 struct radv_image_view
*iview
)
4415 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4416 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4417 unsigned max_compressed_block_size
;
4418 unsigned independent_128b_blocks
;
4419 unsigned independent_64b_blocks
;
4421 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4424 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4425 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4426 * dGPU and 64 for APU because all of our APUs to date use
4427 * DIMMs which have a request granularity size of 64B while all
4428 * other chips have a 32B request size.
4430 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4433 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4434 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4435 independent_64b_blocks
= 0;
4436 independent_128b_blocks
= 1;
4438 independent_128b_blocks
= 0;
4440 if (iview
->image
->info
.samples
> 1) {
4441 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4442 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4443 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4444 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4447 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4448 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4449 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4450 /* If this DCC image is potentially going to be used in texture
4451 * fetches, we need some special settings.
4453 independent_64b_blocks
= 1;
4454 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4456 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4457 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4458 * big as possible for better compression state.
4460 independent_64b_blocks
= 0;
4461 max_compressed_block_size
= max_uncompressed_block_size
;
4465 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4466 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4467 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4468 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
4469 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
4473 radv_initialise_color_surface(struct radv_device
*device
,
4474 struct radv_color_buffer_info
*cb
,
4475 struct radv_image_view
*iview
)
4477 const struct vk_format_description
*desc
;
4478 unsigned ntype
, format
, swap
, endian
;
4479 unsigned blend_clamp
= 0, blend_bypass
= 0;
4481 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4482 const struct radeon_surf
*surf
= &plane
->surface
;
4484 desc
= vk_format_description(iview
->vk_format
);
4486 memset(cb
, 0, sizeof(*cb
));
4488 /* Intensity is implemented as Red, so treat it that way. */
4489 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4491 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4493 cb
->cb_color_base
= va
>> 8;
4495 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4496 struct gfx9_surf_meta_flags meta
;
4497 if (iview
->image
->dcc_offset
)
4498 meta
= surf
->u
.gfx9
.dcc
;
4500 meta
= surf
->u
.gfx9
.cmask
;
4502 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4503 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4504 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4505 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
4506 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
4508 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4509 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4510 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4511 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4512 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4515 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4516 cb
->cb_color_base
|= surf
->tile_swizzle
;
4518 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4519 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4521 cb
->cb_color_base
+= level_info
->offset
>> 8;
4522 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4523 cb
->cb_color_base
|= surf
->tile_swizzle
;
4525 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4526 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4527 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4529 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4530 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4531 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
4533 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4535 if (radv_image_has_fmask(iview
->image
)) {
4536 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4537 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
4538 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
4539 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
4541 /* This must be set for fast clear to work without FMASK. */
4542 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4543 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4544 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4545 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4549 /* CMASK variables */
4550 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4551 va
+= iview
->image
->cmask_offset
;
4552 cb
->cb_color_cmask
= va
>> 8;
4554 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4555 va
+= iview
->image
->dcc_offset
;
4557 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
4558 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
4559 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
4561 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
4562 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
4564 cb
->cb_dcc_base
= va
>> 8;
4565 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
4567 /* GFX10 field has the same base shift as the GFX6 field. */
4568 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4569 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4570 S_028C6C_SLICE_MAX_GFX10(max_slice
);
4572 if (iview
->image
->info
.samples
> 1) {
4573 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4575 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4576 S_028C74_NUM_FRAGMENTS(log_samples
);
4579 if (radv_image_has_fmask(iview
->image
)) {
4580 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
4581 cb
->cb_color_fmask
= va
>> 8;
4582 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
4584 cb
->cb_color_fmask
= cb
->cb_color_base
;
4587 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4589 vk_format_get_first_non_void_channel(iview
->vk_format
));
4590 format
= radv_translate_colorformat(iview
->vk_format
);
4591 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4592 radv_finishme("Illegal color\n");
4593 swap
= radv_translate_colorswap(iview
->vk_format
, false);
4594 endian
= radv_colorformat_endian_swap(format
);
4596 /* blend clamp should be set for all NORM/SRGB types */
4597 if (ntype
== V_028C70_NUMBER_UNORM
||
4598 ntype
== V_028C70_NUMBER_SNORM
||
4599 ntype
== V_028C70_NUMBER_SRGB
)
4602 /* set blend bypass according to docs if SINT/UINT or
4603 8/24 COLOR variants */
4604 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4605 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4606 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4611 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4612 (format
== V_028C70_COLOR_8
||
4613 format
== V_028C70_COLOR_8_8
||
4614 format
== V_028C70_COLOR_8_8_8_8
))
4615 ->color_is_int8
= true;
4617 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4618 S_028C70_COMP_SWAP(swap
) |
4619 S_028C70_BLEND_CLAMP(blend_clamp
) |
4620 S_028C70_BLEND_BYPASS(blend_bypass
) |
4621 S_028C70_SIMPLE_FLOAT(1) |
4622 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4623 ntype
!= V_028C70_NUMBER_SNORM
&&
4624 ntype
!= V_028C70_NUMBER_SRGB
&&
4625 format
!= V_028C70_COLOR_8_24
&&
4626 format
!= V_028C70_COLOR_24_8
) |
4627 S_028C70_NUMBER_TYPE(ntype
) |
4628 S_028C70_ENDIAN(endian
);
4629 if (radv_image_has_fmask(iview
->image
)) {
4630 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4631 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4632 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
4633 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4636 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
4637 /* Allow the texture block to read FMASK directly
4638 * without decompressing it. This bit must be cleared
4639 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
4640 * otherwise the operation doesn't happen.
4642 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
4644 /* Set CMASK into a tiling format that allows the
4645 * texture block to read it.
4647 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
4651 if (radv_image_has_cmask(iview
->image
) &&
4652 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4653 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4655 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4656 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4658 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4660 /* This must be set for fast clear to work without FMASK. */
4661 if (!radv_image_has_fmask(iview
->image
) &&
4662 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4663 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4664 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4667 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4668 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4670 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4671 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4672 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4673 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4675 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4676 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
4678 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
4679 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
4680 S_028EE0_RESOURCE_LEVEL(1);
4682 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
4683 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4684 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4687 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4688 S_028C68_MIP0_HEIGHT(height
- 1) |
4689 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4694 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4695 struct radv_image_view
*iview
)
4697 unsigned max_zplanes
= 0;
4699 assert(radv_image_is_tc_compat_htile(iview
->image
));
4701 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4702 /* Default value for 32-bit depth surfaces. */
4705 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4706 iview
->image
->info
.samples
> 1)
4709 max_zplanes
= max_zplanes
+ 1;
4711 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4712 /* Do not enable Z plane compression for 16-bit depth
4713 * surfaces because isn't supported on GFX8. Only
4714 * 32-bit depth surfaces are supported by the hardware.
4715 * This allows to maintain shader compatibility and to
4716 * reduce the number of depth decompressions.
4720 if (iview
->image
->info
.samples
<= 1)
4722 else if (iview
->image
->info
.samples
<= 4)
4733 radv_initialise_ds_surface(struct radv_device
*device
,
4734 struct radv_ds_buffer_info
*ds
,
4735 struct radv_image_view
*iview
)
4737 unsigned level
= iview
->base_mip
;
4738 unsigned format
, stencil_format
;
4739 uint64_t va
, s_offs
, z_offs
;
4740 bool stencil_only
= false;
4741 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4742 const struct radeon_surf
*surf
= &plane
->surface
;
4744 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4746 memset(ds
, 0, sizeof(*ds
));
4747 switch (iview
->image
->vk_format
) {
4748 case VK_FORMAT_D24_UNORM_S8_UINT
:
4749 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4750 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4751 ds
->offset_scale
= 2.0f
;
4753 case VK_FORMAT_D16_UNORM
:
4754 case VK_FORMAT_D16_UNORM_S8_UINT
:
4755 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4756 ds
->offset_scale
= 4.0f
;
4758 case VK_FORMAT_D32_SFLOAT
:
4759 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4760 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4761 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4762 ds
->offset_scale
= 1.0f
;
4764 case VK_FORMAT_S8_UINT
:
4765 stencil_only
= true;
4771 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4772 stencil_format
= surf
->has_stencil
?
4773 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4775 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4776 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4777 S_028008_SLICE_MAX(max_slice
);
4778 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4779 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
4780 S_028008_SLICE_MAX_HI(max_slice
>> 11);
4783 ds
->db_htile_data_base
= 0;
4784 ds
->db_htile_surface
= 0;
4786 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4787 s_offs
= z_offs
= va
;
4789 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4790 assert(surf
->u
.gfx9
.surf_offset
== 0);
4791 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4793 ds
->db_z_info
= S_028038_FORMAT(format
) |
4794 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4795 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4796 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4797 S_028038_ZRANGE_PRECISION(1);
4798 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4799 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4801 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4802 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4803 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4806 ds
->db_depth_view
|= S_028008_MIPID(level
);
4807 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4808 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4810 if (radv_htile_enabled(iview
->image
, level
)) {
4811 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4813 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4814 unsigned max_zplanes
=
4815 radv_calc_decompress_on_z_planes(device
, iview
);
4817 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4819 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4820 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
4821 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
4823 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
4824 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4828 if (!surf
->has_stencil
)
4829 /* Use all of the htile_buffer for depth if there's no stencil. */
4830 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4831 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4832 iview
->image
->htile_offset
;
4833 ds
->db_htile_data_base
= va
>> 8;
4834 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4835 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
4837 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4838 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4842 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4845 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4847 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4848 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4850 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4851 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4852 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4854 if (iview
->image
->info
.samples
> 1)
4855 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4857 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4858 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4859 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4860 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4861 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4862 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4863 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4864 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4867 tile_mode
= stencil_tile_mode
;
4869 ds
->db_depth_info
|=
4870 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4871 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4872 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4873 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4874 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4875 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4876 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4877 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4879 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4880 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4881 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4882 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4884 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4887 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4888 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4889 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4891 if (radv_htile_enabled(iview
->image
, level
)) {
4892 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4894 if (!surf
->has_stencil
&&
4895 !radv_image_is_tc_compat_htile(iview
->image
))
4896 /* Use all of the htile_buffer for depth if there's no stencil. */
4897 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4899 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4900 iview
->image
->htile_offset
;
4901 ds
->db_htile_data_base
= va
>> 8;
4902 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4904 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4905 unsigned max_zplanes
=
4906 radv_calc_decompress_on_z_planes(device
, iview
);
4908 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4909 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4914 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4915 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4918 VkResult
radv_CreateFramebuffer(
4920 const VkFramebufferCreateInfo
* pCreateInfo
,
4921 const VkAllocationCallbacks
* pAllocator
,
4922 VkFramebuffer
* pFramebuffer
)
4924 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4925 struct radv_framebuffer
*framebuffer
;
4926 const VkFramebufferAttachmentsCreateInfoKHR
*imageless_create_info
=
4927 vk_find_struct_const(pCreateInfo
->pNext
,
4928 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR
);
4930 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4932 size_t size
= sizeof(*framebuffer
);
4933 if (!imageless_create_info
)
4934 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
4935 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4936 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4937 if (framebuffer
== NULL
)
4938 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4940 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4941 framebuffer
->width
= pCreateInfo
->width
;
4942 framebuffer
->height
= pCreateInfo
->height
;
4943 framebuffer
->layers
= pCreateInfo
->layers
;
4944 if (imageless_create_info
) {
4945 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
4946 const VkFramebufferAttachmentImageInfoKHR
*attachment
=
4947 imageless_create_info
->pAttachmentImageInfos
+ i
;
4948 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
4949 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
4950 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
4953 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4954 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4955 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4956 framebuffer
->attachments
[i
] = iview
;
4957 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4958 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4959 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4963 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4967 void radv_DestroyFramebuffer(
4970 const VkAllocationCallbacks
* pAllocator
)
4972 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4973 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4977 vk_free2(&device
->alloc
, pAllocator
, fb
);
4980 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4982 switch (address_mode
) {
4983 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4984 return V_008F30_SQ_TEX_WRAP
;
4985 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4986 return V_008F30_SQ_TEX_MIRROR
;
4987 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4988 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4989 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4990 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4991 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4992 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4994 unreachable("illegal tex wrap mode");
5000 radv_tex_compare(VkCompareOp op
)
5003 case VK_COMPARE_OP_NEVER
:
5004 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
5005 case VK_COMPARE_OP_LESS
:
5006 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
5007 case VK_COMPARE_OP_EQUAL
:
5008 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
5009 case VK_COMPARE_OP_LESS_OR_EQUAL
:
5010 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
5011 case VK_COMPARE_OP_GREATER
:
5012 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
5013 case VK_COMPARE_OP_NOT_EQUAL
:
5014 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
5015 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
5016 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
5017 case VK_COMPARE_OP_ALWAYS
:
5018 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
5020 unreachable("illegal compare mode");
5026 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
5029 case VK_FILTER_NEAREST
:
5030 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
5031 V_008F38_SQ_TEX_XY_FILTER_POINT
);
5032 case VK_FILTER_LINEAR
:
5033 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
5034 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
5035 case VK_FILTER_CUBIC_IMG
:
5037 fprintf(stderr
, "illegal texture filter");
5043 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
5046 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
5047 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
5048 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
5049 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
5051 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
5056 radv_tex_bordercolor(VkBorderColor bcolor
)
5059 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
5060 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
5061 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
5062 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
5063 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
5064 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
5065 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
5066 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
5067 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
5075 radv_tex_aniso_filter(unsigned filter
)
5089 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
5092 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
5093 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5094 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
5095 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
5096 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
5097 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
5105 radv_get_max_anisotropy(struct radv_device
*device
,
5106 const VkSamplerCreateInfo
*pCreateInfo
)
5108 if (device
->force_aniso
>= 0)
5109 return device
->force_aniso
;
5111 if (pCreateInfo
->anisotropyEnable
&&
5112 pCreateInfo
->maxAnisotropy
> 1.0f
)
5113 return (uint32_t)pCreateInfo
->maxAnisotropy
;
5119 radv_init_sampler(struct radv_device
*device
,
5120 struct radv_sampler
*sampler
,
5121 const VkSamplerCreateInfo
*pCreateInfo
)
5123 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
5124 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
5125 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
5126 device
->physical_device
->rad_info
.chip_class
== GFX9
;
5127 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5129 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
5130 vk_find_struct_const(pCreateInfo
->pNext
,
5131 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
5132 if (sampler_reduction
)
5133 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
5135 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
5136 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
5137 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
5138 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
5139 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
5140 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
5141 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
5142 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
5143 S_008F30_DISABLE_CUBE_WRAP(0) |
5144 S_008F30_COMPAT_MODE(compat_mode
) |
5145 S_008F30_FILTER_MODE(filter_mode
));
5146 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
5147 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
5148 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
5149 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
5150 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
5151 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
5152 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
5153 S_008F38_MIP_POINT_PRECLAMP(0));
5154 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
5155 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
5157 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5158 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
5160 sampler
->state
[2] |=
5161 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
5162 S_008F38_FILTER_PREC_FIX(1) |
5163 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
5167 VkResult
radv_CreateSampler(
5169 const VkSamplerCreateInfo
* pCreateInfo
,
5170 const VkAllocationCallbacks
* pAllocator
,
5171 VkSampler
* pSampler
)
5173 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5174 struct radv_sampler
*sampler
;
5176 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
5177 vk_find_struct_const(pCreateInfo
->pNext
,
5178 SAMPLER_YCBCR_CONVERSION_INFO
);
5180 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
5182 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
5183 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5185 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5187 radv_init_sampler(device
, sampler
, pCreateInfo
);
5189 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
5190 *pSampler
= radv_sampler_to_handle(sampler
);
5195 void radv_DestroySampler(
5198 const VkAllocationCallbacks
* pAllocator
)
5200 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5201 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
5205 vk_free2(&device
->alloc
, pAllocator
, sampler
);
5208 /* vk_icd.h does not declare this function, so we declare it here to
5209 * suppress Wmissing-prototypes.
5211 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5212 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
5214 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5215 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
5217 /* For the full details on loader interface versioning, see
5218 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
5219 * What follows is a condensed summary, to help you navigate the large and
5220 * confusing official doc.
5222 * - Loader interface v0 is incompatible with later versions. We don't
5225 * - In loader interface v1:
5226 * - The first ICD entrypoint called by the loader is
5227 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
5229 * - The ICD must statically expose no other Vulkan symbol unless it is
5230 * linked with -Bsymbolic.
5231 * - Each dispatchable Vulkan handle created by the ICD must be
5232 * a pointer to a struct whose first member is VK_LOADER_DATA. The
5233 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
5234 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
5235 * vkDestroySurfaceKHR(). The ICD must be capable of working with
5236 * such loader-managed surfaces.
5238 * - Loader interface v2 differs from v1 in:
5239 * - The first ICD entrypoint called by the loader is
5240 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
5241 * statically expose this entrypoint.
5243 * - Loader interface v3 differs from v2 in:
5244 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
5245 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
5246 * because the loader no longer does so.
5248 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
5252 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
5253 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
5256 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5257 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
5259 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
5261 /* At the moment, we support only the below handle types. */
5262 assert(pGetFdInfo
->handleType
==
5263 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5264 pGetFdInfo
->handleType
==
5265 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5267 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
5269 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5273 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
5274 VkExternalMemoryHandleTypeFlagBits handleType
,
5276 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
5278 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5280 switch (handleType
) {
5281 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
5282 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
5286 /* The valid usage section for this function says:
5288 * "handleType must not be one of the handle types defined as
5291 * So opaque handle types fall into the default "unsupported" case.
5293 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5297 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5301 uint32_t syncobj_handle
= 0;
5302 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5304 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5307 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5309 *syncobj
= syncobj_handle
;
5315 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5319 /* If we create a syncobj we do it locally so that if we have an error, we don't
5320 * leave a syncobj in an undetermined state in the fence. */
5321 uint32_t syncobj_handle
= *syncobj
;
5322 if (!syncobj_handle
) {
5323 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5325 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5330 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5332 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5334 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5337 *syncobj
= syncobj_handle
;
5344 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5345 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5347 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5348 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5349 uint32_t *syncobj_dst
= NULL
;
5351 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5352 syncobj_dst
= &sem
->temp_syncobj
;
5354 syncobj_dst
= &sem
->syncobj
;
5357 switch(pImportSemaphoreFdInfo
->handleType
) {
5358 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5359 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5360 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5361 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5363 unreachable("Unhandled semaphore handle type");
5367 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5368 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5371 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5372 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5374 uint32_t syncobj_handle
;
5376 if (sem
->temp_syncobj
)
5377 syncobj_handle
= sem
->temp_syncobj
;
5379 syncobj_handle
= sem
->syncobj
;
5381 switch(pGetFdInfo
->handleType
) {
5382 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5383 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5385 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5386 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5388 if (sem
->temp_syncobj
) {
5389 close (sem
->temp_syncobj
);
5390 sem
->temp_syncobj
= 0;
5392 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5397 unreachable("Unhandled semaphore handle type");
5401 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5405 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5406 VkPhysicalDevice physicalDevice
,
5407 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5408 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5410 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5412 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5413 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5414 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5415 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5416 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5417 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5418 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5419 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5420 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5421 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5422 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5423 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5424 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5426 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5427 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5428 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5432 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5433 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5435 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5436 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5437 uint32_t *syncobj_dst
= NULL
;
5440 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5441 syncobj_dst
= &fence
->temp_syncobj
;
5443 syncobj_dst
= &fence
->syncobj
;
5446 switch(pImportFenceFdInfo
->handleType
) {
5447 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5448 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5449 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5450 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5452 unreachable("Unhandled fence handle type");
5456 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5457 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5460 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5461 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5463 uint32_t syncobj_handle
;
5465 if (fence
->temp_syncobj
)
5466 syncobj_handle
= fence
->temp_syncobj
;
5468 syncobj_handle
= fence
->syncobj
;
5470 switch(pGetFdInfo
->handleType
) {
5471 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5472 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5474 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5475 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5477 if (fence
->temp_syncobj
) {
5478 close (fence
->temp_syncobj
);
5479 fence
->temp_syncobj
= 0;
5481 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5486 unreachable("Unhandled fence handle type");
5490 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5494 void radv_GetPhysicalDeviceExternalFenceProperties(
5495 VkPhysicalDevice physicalDevice
,
5496 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5497 VkExternalFenceProperties
*pExternalFenceProperties
)
5499 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5501 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5502 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5503 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5504 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5505 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5506 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5507 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5509 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5510 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5511 pExternalFenceProperties
->externalFenceFeatures
= 0;
5516 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5517 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5518 const VkAllocationCallbacks
* pAllocator
,
5519 VkDebugReportCallbackEXT
* pCallback
)
5521 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5522 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5523 pCreateInfo
, pAllocator
, &instance
->alloc
,
5528 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5529 VkDebugReportCallbackEXT _callback
,
5530 const VkAllocationCallbacks
* pAllocator
)
5532 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5533 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5534 _callback
, pAllocator
, &instance
->alloc
);
5538 radv_DebugReportMessageEXT(VkInstance _instance
,
5539 VkDebugReportFlagsEXT flags
,
5540 VkDebugReportObjectTypeEXT objectType
,
5543 int32_t messageCode
,
5544 const char* pLayerPrefix
,
5545 const char* pMessage
)
5547 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5548 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5549 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5553 radv_GetDeviceGroupPeerMemoryFeatures(
5556 uint32_t localDeviceIndex
,
5557 uint32_t remoteDeviceIndex
,
5558 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5560 assert(localDeviceIndex
== remoteDeviceIndex
);
5562 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5563 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5564 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5565 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5568 static const VkTimeDomainEXT radv_time_domains
[] = {
5569 VK_TIME_DOMAIN_DEVICE_EXT
,
5570 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5571 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5574 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5575 VkPhysicalDevice physicalDevice
,
5576 uint32_t *pTimeDomainCount
,
5577 VkTimeDomainEXT
*pTimeDomains
)
5580 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5582 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5583 vk_outarray_append(&out
, i
) {
5584 *i
= radv_time_domains
[d
];
5588 return vk_outarray_status(&out
);
5592 radv_clock_gettime(clockid_t clock_id
)
5594 struct timespec current
;
5597 ret
= clock_gettime(clock_id
, ¤t
);
5598 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5599 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5603 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5606 VkResult
radv_GetCalibratedTimestampsEXT(
5608 uint32_t timestampCount
,
5609 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5610 uint64_t *pTimestamps
,
5611 uint64_t *pMaxDeviation
)
5613 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5614 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5616 uint64_t begin
, end
;
5617 uint64_t max_clock_period
= 0;
5619 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5621 for (d
= 0; d
< timestampCount
; d
++) {
5622 switch (pTimestampInfos
[d
].timeDomain
) {
5623 case VK_TIME_DOMAIN_DEVICE_EXT
:
5624 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5626 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5627 max_clock_period
= MAX2(max_clock_period
, device_period
);
5629 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5630 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5631 max_clock_period
= MAX2(max_clock_period
, 1);
5634 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5635 pTimestamps
[d
] = begin
;
5643 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5646 * The maximum deviation is the sum of the interval over which we
5647 * perform the sampling and the maximum period of any sampled
5648 * clock. That's because the maximum skew between any two sampled
5649 * clock edges is when the sampled clock with the largest period is
5650 * sampled at the end of that period but right at the beginning of the
5651 * sampling interval and some other clock is sampled right at the
5652 * begining of its sampling period and right at the end of the
5653 * sampling interval. Let's assume the GPU has the longest clock
5654 * period and that the application is sampling GPU and monotonic:
5657 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5658 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5662 * GPU -----_____-----_____-----_____-----_____
5665 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5666 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5668 * Interval <----------------->
5669 * Deviation <-------------------------->
5673 * m = read(monotonic) 2
5676 * We round the sample interval up by one tick to cover sampling error
5677 * in the interval clock
5680 uint64_t sample_interval
= end
- begin
+ 1;
5682 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5687 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5688 VkPhysicalDevice physicalDevice
,
5689 VkSampleCountFlagBits samples
,
5690 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5692 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5693 VK_SAMPLE_COUNT_4_BIT
|
5694 VK_SAMPLE_COUNT_8_BIT
)) {
5695 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5697 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };