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
);
342 if (device
->use_aco
&& device
->use_ngg
) {
343 fprintf(stderr
, "WARNING: disabling NGG because ACO is used.\n");
344 device
->use_ngg
= false;
347 device
->use_ngg_streamout
= false;
349 /* Determine the number of threads per wave for all stages. */
350 device
->cs_wave_size
= 64;
351 device
->ps_wave_size
= 64;
352 device
->ge_wave_size
= 64;
354 if (device
->rad_info
.chip_class
>= GFX10
) {
355 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
356 device
->cs_wave_size
= 32;
358 /* For pixel shaders, wave64 is recommanded. */
359 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
360 device
->ps_wave_size
= 32;
362 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
363 device
->ge_wave_size
= 32;
366 radv_physical_device_init_mem_types(device
);
367 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
369 device
->bus_info
= *drm_device
->businfo
.pci
;
371 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
372 ac_print_gpu_info(&device
->rad_info
);
374 /* The WSI is structured as a layer on top of the driver, so this has
375 * to be the last part of initialization (at least until we get other
378 result
= radv_init_wsi(device
);
379 if (result
!= VK_SUCCESS
) {
380 device
->ws
->destroy(device
->ws
);
381 vk_error(instance
, result
);
395 radv_physical_device_finish(struct radv_physical_device
*device
)
397 radv_finish_wsi(device
);
398 device
->ws
->destroy(device
->ws
);
399 disk_cache_destroy(device
->disk_cache
);
400 close(device
->local_fd
);
401 if (device
->master_fd
!= -1)
402 close(device
->master_fd
);
406 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
407 VkSystemAllocationScope allocationScope
)
413 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
414 size_t align
, VkSystemAllocationScope allocationScope
)
416 return realloc(pOriginal
, size
);
420 default_free_func(void *pUserData
, void *pMemory
)
425 static const VkAllocationCallbacks default_alloc
= {
427 .pfnAllocation
= default_alloc_func
,
428 .pfnReallocation
= default_realloc_func
,
429 .pfnFree
= default_free_func
,
432 static const struct debug_control radv_debug_options
[] = {
433 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
434 {"nodcc", RADV_DEBUG_NO_DCC
},
435 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
436 {"nocache", RADV_DEBUG_NO_CACHE
},
437 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
438 {"nohiz", RADV_DEBUG_NO_HIZ
},
439 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
440 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
441 {"allbos", RADV_DEBUG_ALL_BOS
},
442 {"noibs", RADV_DEBUG_NO_IBS
},
443 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
444 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
445 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
446 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
447 {"nosisched", RADV_DEBUG_NO_SISCHED
},
448 {"preoptir", RADV_DEBUG_PREOPTIR
},
449 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
450 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
451 {"info", RADV_DEBUG_INFO
},
452 {"errors", RADV_DEBUG_ERRORS
},
453 {"startup", RADV_DEBUG_STARTUP
},
454 {"checkir", RADV_DEBUG_CHECKIR
},
455 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
456 {"nobinning", RADV_DEBUG_NOBINNING
},
457 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
458 {"nongg", RADV_DEBUG_NO_NGG
},
459 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
460 {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS
},
461 {"metashaders", RADV_DEBUG_DUMP_META_SHADERS
},
466 radv_get_debug_option_name(int id
)
468 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
469 return radv_debug_options
[id
].string
;
472 static const struct debug_control radv_perftest_options
[] = {
473 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
474 {"sisched", RADV_PERFTEST_SISCHED
},
475 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
476 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
477 {"bolist", RADV_PERFTEST_BO_LIST
},
478 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
479 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
480 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
481 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
482 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
483 {"dfsm", RADV_PERFTEST_DFSM
},
484 {"aco", RADV_PERFTEST_ACO
},
489 radv_get_perftest_option_name(int id
)
491 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
492 return radv_perftest_options
[id
].string
;
496 radv_handle_per_app_options(struct radv_instance
*instance
,
497 const VkApplicationInfo
*info
)
499 const char *name
= info
? info
->pApplicationName
: NULL
;
504 if (!strcmp(name
, "Talos - Linux - 32bit") ||
505 !strcmp(name
, "Talos - Linux - 64bit")) {
506 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
507 /* Force enable LLVM sisched for Talos because it looks
508 * safe and it gives few more FPS.
510 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
512 } else if (!strcmp(name
, "DOOM_VFR")) {
513 /* Work around a Doom VFR game bug */
514 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
515 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
516 /* Workaround for a WaW hazard when LLVM moves/merges
517 * load/store memory operations.
518 * See https://reviews.llvm.org/D61313
520 if (LLVM_VERSION_MAJOR
< 9)
521 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
522 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
523 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
)) {
524 /* Force enable VK_AMD_shader_ballot because it looks
525 * safe and it gives a nice boost (+20% on Vega 56 at
528 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
530 } else if (!strcmp(name
, "Fledge")) {
532 * Zero VRAM for "The Surge 2"
534 * This avoid a hang when when rendering any level. Likely
535 * uninitialized data in an indirect draw.
537 instance
->debug_flags
|= RADV_DEBUG_ZERO_VRAM
;
541 static int radv_get_instance_extension_index(const char *name
)
543 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
544 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
550 static const char radv_dri_options_xml
[] =
552 DRI_CONF_SECTION_PERFORMANCE
553 DRI_CONF_ADAPTIVE_SYNC("true")
554 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
555 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
559 static void radv_init_dri_options(struct radv_instance
*instance
)
561 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
562 driParseConfigFiles(&instance
->dri_options
,
563 &instance
->available_dri_options
,
565 instance
->engineName
,
566 instance
->engineVersion
);
569 VkResult
radv_CreateInstance(
570 const VkInstanceCreateInfo
* pCreateInfo
,
571 const VkAllocationCallbacks
* pAllocator
,
572 VkInstance
* pInstance
)
574 struct radv_instance
*instance
;
577 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
579 uint32_t client_version
;
580 if (pCreateInfo
->pApplicationInfo
&&
581 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
582 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
584 client_version
= VK_API_VERSION_1_0
;
587 const char *engine_name
= NULL
;
588 uint32_t engine_version
= 0;
589 if (pCreateInfo
->pApplicationInfo
) {
590 engine_name
= pCreateInfo
->pApplicationInfo
->pEngineName
;
591 engine_version
= pCreateInfo
->pApplicationInfo
->engineVersion
;
594 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
595 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
597 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
599 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
602 instance
->alloc
= *pAllocator
;
604 instance
->alloc
= default_alloc
;
606 instance
->apiVersion
= client_version
;
607 instance
->physicalDeviceCount
= -1;
609 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
612 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
613 radv_perftest_options
);
615 if (instance
->perftest_flags
& RADV_PERFTEST_ACO
)
616 fprintf(stderr
, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
618 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
619 radv_logi("Created an instance");
621 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
622 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
623 int index
= radv_get_instance_extension_index(ext_name
);
625 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
626 vk_free2(&default_alloc
, pAllocator
, instance
);
627 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
630 instance
->enabled_extensions
.extensions
[index
] = true;
633 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
634 if (result
!= VK_SUCCESS
) {
635 vk_free2(&default_alloc
, pAllocator
, instance
);
636 return vk_error(instance
, result
);
639 instance
->engineName
= vk_strdup(&instance
->alloc
, engine_name
,
640 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
641 instance
->engineVersion
= engine_version
;
644 glsl_type_singleton_init_or_ref();
646 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
648 radv_init_dri_options(instance
);
649 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
651 *pInstance
= radv_instance_to_handle(instance
);
656 void radv_DestroyInstance(
657 VkInstance _instance
,
658 const VkAllocationCallbacks
* pAllocator
)
660 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
665 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
666 radv_physical_device_finish(instance
->physicalDevices
+ i
);
669 vk_free(&instance
->alloc
, instance
->engineName
);
671 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
673 glsl_type_singleton_decref();
676 driDestroyOptionCache(&instance
->dri_options
);
677 driDestroyOptionInfo(&instance
->available_dri_options
);
679 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
681 vk_free(&instance
->alloc
, instance
);
685 radv_enumerate_devices(struct radv_instance
*instance
)
687 /* TODO: Check for more devices ? */
688 drmDevicePtr devices
[8];
689 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
692 instance
->physicalDeviceCount
= 0;
694 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
696 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
697 radv_logi("Found %d drm nodes", max_devices
);
700 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
702 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
703 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
704 devices
[i
]->bustype
== DRM_BUS_PCI
&&
705 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
707 result
= radv_physical_device_init(instance
->physicalDevices
+
708 instance
->physicalDeviceCount
,
711 if (result
== VK_SUCCESS
)
712 ++instance
->physicalDeviceCount
;
713 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
717 drmFreeDevices(devices
, max_devices
);
722 VkResult
radv_EnumeratePhysicalDevices(
723 VkInstance _instance
,
724 uint32_t* pPhysicalDeviceCount
,
725 VkPhysicalDevice
* pPhysicalDevices
)
727 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
730 if (instance
->physicalDeviceCount
< 0) {
731 result
= radv_enumerate_devices(instance
);
732 if (result
!= VK_SUCCESS
&&
733 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
737 if (!pPhysicalDevices
) {
738 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
740 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
741 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
742 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
745 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
749 VkResult
radv_EnumeratePhysicalDeviceGroups(
750 VkInstance _instance
,
751 uint32_t* pPhysicalDeviceGroupCount
,
752 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
754 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
757 if (instance
->physicalDeviceCount
< 0) {
758 result
= radv_enumerate_devices(instance
);
759 if (result
!= VK_SUCCESS
&&
760 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
764 if (!pPhysicalDeviceGroupProperties
) {
765 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
767 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
768 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
769 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
770 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
771 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
774 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
778 void radv_GetPhysicalDeviceFeatures(
779 VkPhysicalDevice physicalDevice
,
780 VkPhysicalDeviceFeatures
* pFeatures
)
782 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
783 memset(pFeatures
, 0, sizeof(*pFeatures
));
785 *pFeatures
= (VkPhysicalDeviceFeatures
) {
786 .robustBufferAccess
= true,
787 .fullDrawIndexUint32
= true,
788 .imageCubeArray
= true,
789 .independentBlend
= true,
790 .geometryShader
= true,
791 .tessellationShader
= true,
792 .sampleRateShading
= true,
793 .dualSrcBlend
= true,
795 .multiDrawIndirect
= true,
796 .drawIndirectFirstInstance
= true,
798 .depthBiasClamp
= true,
799 .fillModeNonSolid
= true,
804 .multiViewport
= true,
805 .samplerAnisotropy
= true,
806 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
807 .textureCompressionASTC_LDR
= false,
808 .textureCompressionBC
= true,
809 .occlusionQueryPrecise
= true,
810 .pipelineStatisticsQuery
= true,
811 .vertexPipelineStoresAndAtomics
= true,
812 .fragmentStoresAndAtomics
= true,
813 .shaderTessellationAndGeometryPointSize
= true,
814 .shaderImageGatherExtended
= true,
815 .shaderStorageImageExtendedFormats
= true,
816 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
817 .shaderUniformBufferArrayDynamicIndexing
= true,
818 .shaderSampledImageArrayDynamicIndexing
= true,
819 .shaderStorageBufferArrayDynamicIndexing
= true,
820 .shaderStorageImageArrayDynamicIndexing
= true,
821 .shaderStorageImageReadWithoutFormat
= true,
822 .shaderStorageImageWriteWithoutFormat
= true,
823 .shaderClipDistance
= true,
824 .shaderCullDistance
= true,
825 .shaderFloat64
= true,
827 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
&& !pdevice
->use_aco
,
828 .sparseBinding
= true,
829 .variableMultisampleRate
= true,
830 .inheritedQueries
= true,
834 void radv_GetPhysicalDeviceFeatures2(
835 VkPhysicalDevice physicalDevice
,
836 VkPhysicalDeviceFeatures2
*pFeatures
)
838 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
839 vk_foreach_struct(ext
, pFeatures
->pNext
) {
840 switch (ext
->sType
) {
841 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
842 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
843 features
->variablePointersStorageBuffer
= true;
844 features
->variablePointers
= true;
847 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
848 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
849 features
->multiview
= true;
850 features
->multiviewGeometryShader
= true;
851 features
->multiviewTessellationShader
= true;
854 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
855 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
856 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
857 features
->shaderDrawParameters
= true;
860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
861 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
862 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
863 features
->protectedMemory
= false;
866 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
867 VkPhysicalDevice16BitStorageFeatures
*features
=
868 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
869 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
870 features
->storageBuffer16BitAccess
= enabled
;
871 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
872 features
->storagePushConstant16
= enabled
;
873 features
->storageInputOutput16
= enabled
&& LLVM_VERSION_MAJOR
>= 9;
876 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
877 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
878 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
879 features
->samplerYcbcrConversion
= true;
882 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
883 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
884 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
885 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
886 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
887 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
888 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
889 features
->shaderSampledImageArrayNonUniformIndexing
= true;
890 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
891 features
->shaderStorageImageArrayNonUniformIndexing
= true;
892 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
893 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
894 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
895 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
896 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
897 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
898 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
899 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
900 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
901 features
->descriptorBindingUpdateUnusedWhilePending
= true;
902 features
->descriptorBindingPartiallyBound
= true;
903 features
->descriptorBindingVariableDescriptorCount
= true;
904 features
->runtimeDescriptorArray
= true;
907 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
908 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
909 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
910 features
->conditionalRendering
= true;
911 features
->inheritedConditionalRendering
= false;
914 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
915 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
916 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
917 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
918 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
921 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
922 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
923 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
924 features
->transformFeedback
= true;
925 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
928 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
929 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
930 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
931 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
934 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
935 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
936 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
937 features
->memoryPriority
= VK_TRUE
;
940 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
941 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
942 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
943 features
->bufferDeviceAddress
= true;
944 features
->bufferDeviceAddressCaptureReplay
= false;
945 features
->bufferDeviceAddressMultiDevice
= false;
948 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
949 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
950 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
951 features
->depthClipEnable
= true;
954 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
955 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
956 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
957 features
->hostQueryReset
= true;
960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
961 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
962 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
963 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
964 features
->storageBuffer8BitAccess
= enabled
;
965 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
966 features
->storagePushConstant8
= enabled
;
969 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR
: {
970 VkPhysicalDeviceShaderFloat16Int8FeaturesKHR
*features
=
971 (VkPhysicalDeviceShaderFloat16Int8FeaturesKHR
*)ext
;
972 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
973 features
->shaderInt8
= !pdevice
->use_aco
;
976 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
977 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
978 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
979 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
980 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
983 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
984 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
=
985 (VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*)ext
;
986 features
->shaderDemoteToHelperInvocation
= pdevice
->use_aco
;
989 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
990 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
991 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
993 features
->inlineUniformBlock
= true;
994 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
997 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
998 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
999 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1000 features
->computeDerivativeGroupQuads
= false;
1001 features
->computeDerivativeGroupLinear
= true;
1004 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1005 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1006 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1007 features
->ycbcrImageArrays
= true;
1010 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1011 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1012 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1013 features
->uniformBufferStandardLayout
= true;
1016 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1017 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1018 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1019 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1022 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1023 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1024 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1025 features
->imagelessFramebuffer
= true;
1028 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1029 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1030 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1031 features
->pipelineExecutableInfo
= true;
1034 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1035 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1036 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1037 features
->shaderSubgroupClock
= true;
1038 features
->shaderDeviceClock
= false;
1041 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1042 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1043 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1044 features
->texelBufferAlignment
= true;
1051 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1054 void radv_GetPhysicalDeviceProperties(
1055 VkPhysicalDevice physicalDevice
,
1056 VkPhysicalDeviceProperties
* pProperties
)
1058 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1059 VkSampleCountFlags sample_counts
= 0xf;
1061 /* make sure that the entire descriptor set is addressable with a signed
1062 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1063 * be at most 2 GiB. the combined image & samples object count as one of
1064 * both. This limit is for the pipeline layout, not for the set layout, but
1065 * there is no set limit, so we just set a pipeline limit. I don't think
1066 * any app is going to hit this soon. */
1067 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1068 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1069 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1070 32 /* sampler, largest when combined with image */ +
1071 64 /* sampled image */ +
1072 64 /* storage image */);
1074 VkPhysicalDeviceLimits limits
= {
1075 .maxImageDimension1D
= (1 << 14),
1076 .maxImageDimension2D
= (1 << 14),
1077 .maxImageDimension3D
= (1 << 11),
1078 .maxImageDimensionCube
= (1 << 14),
1079 .maxImageArrayLayers
= (1 << 11),
1080 .maxTexelBufferElements
= 128 * 1024 * 1024,
1081 .maxUniformBufferRange
= UINT32_MAX
,
1082 .maxStorageBufferRange
= UINT32_MAX
,
1083 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1084 .maxMemoryAllocationCount
= UINT32_MAX
,
1085 .maxSamplerAllocationCount
= 64 * 1024,
1086 .bufferImageGranularity
= 64, /* A cache line */
1087 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1088 .maxBoundDescriptorSets
= MAX_SETS
,
1089 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1090 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1091 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1092 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1093 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1094 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1095 .maxPerStageResources
= max_descriptor_set_size
,
1096 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1097 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1098 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1099 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1100 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1101 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1102 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1103 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1104 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1105 .maxVertexInputBindings
= MAX_VBS
,
1106 .maxVertexInputAttributeOffset
= 2047,
1107 .maxVertexInputBindingStride
= 2048,
1108 .maxVertexOutputComponents
= 128,
1109 .maxTessellationGenerationLevel
= 64,
1110 .maxTessellationPatchSize
= 32,
1111 .maxTessellationControlPerVertexInputComponents
= 128,
1112 .maxTessellationControlPerVertexOutputComponents
= 128,
1113 .maxTessellationControlPerPatchOutputComponents
= 120,
1114 .maxTessellationControlTotalOutputComponents
= 4096,
1115 .maxTessellationEvaluationInputComponents
= 128,
1116 .maxTessellationEvaluationOutputComponents
= 128,
1117 .maxGeometryShaderInvocations
= 127,
1118 .maxGeometryInputComponents
= 64,
1119 .maxGeometryOutputComponents
= 128,
1120 .maxGeometryOutputVertices
= 256,
1121 .maxGeometryTotalOutputComponents
= 1024,
1122 .maxFragmentInputComponents
= 128,
1123 .maxFragmentOutputAttachments
= 8,
1124 .maxFragmentDualSrcAttachments
= 1,
1125 .maxFragmentCombinedOutputResources
= 8,
1126 .maxComputeSharedMemorySize
= 32768,
1127 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1128 .maxComputeWorkGroupInvocations
= 2048,
1129 .maxComputeWorkGroupSize
= {
1134 .subPixelPrecisionBits
= 8,
1135 .subTexelPrecisionBits
= 8,
1136 .mipmapPrecisionBits
= 8,
1137 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1138 .maxDrawIndirectCount
= UINT32_MAX
,
1139 .maxSamplerLodBias
= 16,
1140 .maxSamplerAnisotropy
= 16,
1141 .maxViewports
= MAX_VIEWPORTS
,
1142 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1143 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1144 .viewportSubPixelBits
= 8,
1145 .minMemoryMapAlignment
= 4096, /* A page */
1146 .minTexelBufferOffsetAlignment
= 4,
1147 .minUniformBufferOffsetAlignment
= 4,
1148 .minStorageBufferOffsetAlignment
= 4,
1149 .minTexelOffset
= -32,
1150 .maxTexelOffset
= 31,
1151 .minTexelGatherOffset
= -32,
1152 .maxTexelGatherOffset
= 31,
1153 .minInterpolationOffset
= -2,
1154 .maxInterpolationOffset
= 2,
1155 .subPixelInterpolationOffsetBits
= 8,
1156 .maxFramebufferWidth
= (1 << 14),
1157 .maxFramebufferHeight
= (1 << 14),
1158 .maxFramebufferLayers
= (1 << 10),
1159 .framebufferColorSampleCounts
= sample_counts
,
1160 .framebufferDepthSampleCounts
= sample_counts
,
1161 .framebufferStencilSampleCounts
= sample_counts
,
1162 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1163 .maxColorAttachments
= MAX_RTS
,
1164 .sampledImageColorSampleCounts
= sample_counts
,
1165 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1166 .sampledImageDepthSampleCounts
= sample_counts
,
1167 .sampledImageStencilSampleCounts
= sample_counts
,
1168 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1169 .maxSampleMaskWords
= 1,
1170 .timestampComputeAndGraphics
= true,
1171 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1172 .maxClipDistances
= 8,
1173 .maxCullDistances
= 8,
1174 .maxCombinedClipAndCullDistances
= 8,
1175 .discreteQueuePriorities
= 2,
1176 .pointSizeRange
= { 0.0, 8192.0 },
1177 .lineWidthRange
= { 0.0, 7.9921875 },
1178 .pointSizeGranularity
= (1.0 / 8.0),
1179 .lineWidthGranularity
= (1.0 / 128.0),
1180 .strictLines
= false, /* FINISHME */
1181 .standardSampleLocations
= true,
1182 .optimalBufferCopyOffsetAlignment
= 128,
1183 .optimalBufferCopyRowPitchAlignment
= 128,
1184 .nonCoherentAtomSize
= 64,
1187 *pProperties
= (VkPhysicalDeviceProperties
) {
1188 .apiVersion
= radv_physical_device_api_version(pdevice
),
1189 .driverVersion
= vk_get_driver_version(),
1190 .vendorID
= ATI_VENDOR_ID
,
1191 .deviceID
= pdevice
->rad_info
.pci_id
,
1192 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1194 .sparseProperties
= {0},
1197 strcpy(pProperties
->deviceName
, pdevice
->name
);
1198 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1201 void radv_GetPhysicalDeviceProperties2(
1202 VkPhysicalDevice physicalDevice
,
1203 VkPhysicalDeviceProperties2
*pProperties
)
1205 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1206 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1208 vk_foreach_struct(ext
, pProperties
->pNext
) {
1209 switch (ext
->sType
) {
1210 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1211 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1212 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1213 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1216 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1217 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1218 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1219 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1220 properties
->deviceLUIDValid
= false;
1223 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1224 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1225 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1226 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1229 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1230 VkPhysicalDevicePointClippingProperties
*properties
=
1231 (VkPhysicalDevicePointClippingProperties
*)ext
;
1232 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1235 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1236 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1237 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1238 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1241 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1242 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1243 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1244 properties
->minImportedHostPointerAlignment
= 4096;
1247 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1248 VkPhysicalDeviceSubgroupProperties
*properties
=
1249 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1250 properties
->subgroupSize
= 64;
1251 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1252 properties
->supportedOperations
=
1253 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1254 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1255 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1256 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1257 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1258 properties
->supportedOperations
|=
1259 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1260 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1261 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1262 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1264 properties
->quadOperationsInAllStages
= true;
1267 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1268 VkPhysicalDeviceMaintenance3Properties
*properties
=
1269 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1270 /* Make sure everything is addressable by a signed 32-bit int, and
1271 * our largest descriptors are 96 bytes. */
1272 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1273 /* Our buffer size fields allow only this much */
1274 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1277 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1278 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1279 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1280 /* GFX6-8 only support single channel min/max filter. */
1281 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1282 properties
->filterMinmaxSingleComponentFormats
= true;
1285 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1286 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1287 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1289 /* Shader engines. */
1290 properties
->shaderEngineCount
=
1291 pdevice
->rad_info
.max_se
;
1292 properties
->shaderArraysPerEngineCount
=
1293 pdevice
->rad_info
.max_sh_per_se
;
1294 properties
->computeUnitsPerShaderArray
=
1295 pdevice
->rad_info
.num_good_cu_per_sh
;
1296 properties
->simdPerComputeUnit
= 4;
1297 properties
->wavefrontsPerSimd
=
1298 pdevice
->rad_info
.family
== CHIP_TONGA
||
1299 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1300 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1301 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1302 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1303 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1304 properties
->wavefrontSize
= 64;
1307 properties
->sgprsPerSimd
=
1308 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1309 properties
->minSgprAllocation
=
1310 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1311 properties
->maxSgprAllocation
=
1312 pdevice
->rad_info
.family
== CHIP_TONGA
||
1313 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1314 properties
->sgprAllocationGranularity
=
1315 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1318 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1319 properties
->minVgprAllocation
= 4;
1320 properties
->maxVgprAllocation
= 256;
1321 properties
->vgprAllocationGranularity
= 4;
1324 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1325 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1326 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1328 properties
->shaderCoreFeatures
= 0;
1329 properties
->activeComputeUnitCount
=
1330 pdevice
->rad_info
.num_good_compute_units
;
1333 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1334 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1335 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1336 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1339 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1340 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1341 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1342 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1343 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1344 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1345 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1346 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1347 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1348 properties
->robustBufferAccessUpdateAfterBind
= false;
1349 properties
->quadDivergentImplicitLod
= false;
1351 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1352 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1353 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1354 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1355 32 /* sampler, largest when combined with image */ +
1356 64 /* sampled image */ +
1357 64 /* storage image */);
1358 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1359 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1360 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1361 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1362 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1363 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1364 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1365 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1366 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1367 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1368 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1369 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1370 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1371 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1372 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1375 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1376 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1377 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1378 properties
->protectedNoFault
= false;
1381 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1382 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1383 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1384 properties
->primitiveOverestimationSize
= 0;
1385 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1386 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1387 properties
->primitiveUnderestimation
= VK_FALSE
;
1388 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1389 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1390 properties
->degenerateLinesRasterized
= VK_FALSE
;
1391 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1392 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1395 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1396 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1397 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1398 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1399 properties
->pciBus
= pdevice
->bus_info
.bus
;
1400 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1401 properties
->pciFunction
= pdevice
->bus_info
.func
;
1404 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1405 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1406 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1408 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1409 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
, "radv");
1410 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1411 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1412 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1414 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1422 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1423 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1424 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1425 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1426 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1427 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1428 properties
->maxTransformFeedbackStreamDataSize
= 512;
1429 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1430 properties
->maxTransformFeedbackBufferDataStride
= 512;
1431 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1432 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1433 properties
->transformFeedbackRasterizationStreamSelect
= false;
1434 properties
->transformFeedbackDraw
= true;
1437 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1438 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1439 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1441 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1442 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1443 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1444 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1445 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1448 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1449 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1450 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1451 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1452 VK_SAMPLE_COUNT_4_BIT
|
1453 VK_SAMPLE_COUNT_8_BIT
;
1454 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1455 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1456 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1457 properties
->sampleLocationSubPixelBits
= 4;
1458 properties
->variableSampleLocations
= VK_FALSE
;
1461 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1462 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1463 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1465 /* We support all of the depth resolve modes */
1466 properties
->supportedDepthResolveModes
=
1467 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1468 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1469 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1470 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1472 /* Average doesn't make sense for stencil so we don't support that */
1473 properties
->supportedStencilResolveModes
=
1474 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1475 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1476 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1478 properties
->independentResolveNone
= VK_TRUE
;
1479 properties
->independentResolve
= VK_TRUE
;
1482 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1483 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*properties
=
1484 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1485 properties
->storageTexelBufferOffsetAlignmentBytes
= 4;
1486 properties
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1487 properties
->uniformTexelBufferOffsetAlignmentBytes
= 4;
1488 properties
->uniformTexelBufferOffsetSingleTexelAlignment
= true;
1491 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR
: {
1492 VkPhysicalDeviceFloatControlsPropertiesKHR
*properties
=
1493 (VkPhysicalDeviceFloatControlsPropertiesKHR
*)ext
;
1495 /* On AMD hardware, denormals and rounding modes for
1496 * fp16/fp64 are controlled by the same config
1499 properties
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1500 properties
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1502 /* Do not allow both preserving and flushing denorms
1503 * because different shaders in the same pipeline can
1504 * have different settings and this won't work for
1505 * merged shaders. To make it work, this requires LLVM
1506 * support for changing the register. The same logic
1507 * applies for the rounding modes because they are
1508 * configured with the same config register.
1510 properties
->shaderDenormFlushToZeroFloat32
= true;
1511 properties
->shaderDenormPreserveFloat32
= false;
1512 properties
->shaderRoundingModeRTEFloat32
= true;
1513 properties
->shaderRoundingModeRTZFloat32
= false;
1514 properties
->shaderSignedZeroInfNanPreserveFloat32
= true;
1516 properties
->shaderDenormFlushToZeroFloat16
= false;
1517 properties
->shaderDenormPreserveFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
1518 properties
->shaderRoundingModeRTEFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
1519 properties
->shaderRoundingModeRTZFloat16
= false;
1520 properties
->shaderSignedZeroInfNanPreserveFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
1522 properties
->shaderDenormFlushToZeroFloat64
= false;
1523 properties
->shaderDenormPreserveFloat64
= true;
1524 properties
->shaderRoundingModeRTEFloat64
= true;
1525 properties
->shaderRoundingModeRTZFloat64
= false;
1526 properties
->shaderSignedZeroInfNanPreserveFloat64
= true;
1535 static void radv_get_physical_device_queue_family_properties(
1536 struct radv_physical_device
* pdevice
,
1538 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1540 int num_queue_families
= 1;
1542 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1543 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1544 num_queue_families
++;
1546 if (pQueueFamilyProperties
== NULL
) {
1547 *pCount
= num_queue_families
;
1556 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1557 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1558 VK_QUEUE_COMPUTE_BIT
|
1559 VK_QUEUE_TRANSFER_BIT
|
1560 VK_QUEUE_SPARSE_BINDING_BIT
,
1562 .timestampValidBits
= 64,
1563 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1568 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1569 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1570 if (*pCount
> idx
) {
1571 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1572 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1573 VK_QUEUE_TRANSFER_BIT
|
1574 VK_QUEUE_SPARSE_BINDING_BIT
,
1575 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1576 .timestampValidBits
= 64,
1577 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1585 void radv_GetPhysicalDeviceQueueFamilyProperties(
1586 VkPhysicalDevice physicalDevice
,
1588 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1590 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1591 if (!pQueueFamilyProperties
) {
1592 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1595 VkQueueFamilyProperties
*properties
[] = {
1596 pQueueFamilyProperties
+ 0,
1597 pQueueFamilyProperties
+ 1,
1598 pQueueFamilyProperties
+ 2,
1600 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1601 assert(*pCount
<= 3);
1604 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1605 VkPhysicalDevice physicalDevice
,
1607 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1609 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1610 if (!pQueueFamilyProperties
) {
1611 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1614 VkQueueFamilyProperties
*properties
[] = {
1615 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1616 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1617 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1619 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1620 assert(*pCount
<= 3);
1623 void radv_GetPhysicalDeviceMemoryProperties(
1624 VkPhysicalDevice physicalDevice
,
1625 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1627 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1629 *pMemoryProperties
= physical_device
->memory_properties
;
1633 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1634 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1636 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1637 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1638 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1639 uint64_t vram_size
= radv_get_vram_size(device
);
1640 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1641 uint64_t heap_budget
, heap_usage
;
1643 /* For all memory heaps, the computation of budget is as follow:
1644 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1646 * The Vulkan spec 1.1.97 says that the budget should include any
1647 * currently allocated device memory.
1649 * Note that the application heap usages are not really accurate (eg.
1650 * in presence of shared buffers).
1652 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1653 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1655 switch (device
->mem_type_indices
[i
]) {
1656 case RADV_MEM_TYPE_VRAM
:
1657 heap_usage
= device
->ws
->query_value(device
->ws
,
1658 RADEON_ALLOCATED_VRAM
);
1660 heap_budget
= vram_size
-
1661 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1664 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1665 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1667 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1668 heap_usage
= device
->ws
->query_value(device
->ws
,
1669 RADEON_ALLOCATED_VRAM_VIS
);
1671 heap_budget
= visible_vram_size
-
1672 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1675 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1676 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1678 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1679 heap_usage
= device
->ws
->query_value(device
->ws
,
1680 RADEON_ALLOCATED_GTT
);
1682 heap_budget
= gtt_size
-
1683 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1686 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1687 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1694 /* The heapBudget and heapUsage values must be zero for array elements
1695 * greater than or equal to
1696 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1698 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1699 memoryBudget
->heapBudget
[i
] = 0;
1700 memoryBudget
->heapUsage
[i
] = 0;
1704 void radv_GetPhysicalDeviceMemoryProperties2(
1705 VkPhysicalDevice physicalDevice
,
1706 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1708 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1709 &pMemoryProperties
->memoryProperties
);
1711 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1712 vk_find_struct(pMemoryProperties
->pNext
,
1713 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1715 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1718 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1720 VkExternalMemoryHandleTypeFlagBits handleType
,
1721 const void *pHostPointer
,
1722 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1724 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1728 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1729 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1730 uint32_t memoryTypeBits
= 0;
1731 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1732 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1733 memoryTypeBits
= (1 << i
);
1737 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1741 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1745 static enum radeon_ctx_priority
1746 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1748 /* Default to MEDIUM when a specific global priority isn't requested */
1750 return RADEON_CTX_PRIORITY_MEDIUM
;
1752 switch(pObj
->globalPriority
) {
1753 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1754 return RADEON_CTX_PRIORITY_REALTIME
;
1755 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1756 return RADEON_CTX_PRIORITY_HIGH
;
1757 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1758 return RADEON_CTX_PRIORITY_MEDIUM
;
1759 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1760 return RADEON_CTX_PRIORITY_LOW
;
1762 unreachable("Illegal global priority value");
1763 return RADEON_CTX_PRIORITY_INVALID
;
1768 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1769 uint32_t queue_family_index
, int idx
,
1770 VkDeviceQueueCreateFlags flags
,
1771 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1773 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1774 queue
->device
= device
;
1775 queue
->queue_family_index
= queue_family_index
;
1776 queue
->queue_idx
= idx
;
1777 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1778 queue
->flags
= flags
;
1780 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1782 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1788 radv_queue_finish(struct radv_queue
*queue
)
1791 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1793 if (queue
->initial_full_flush_preamble_cs
)
1794 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1795 if (queue
->initial_preamble_cs
)
1796 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1797 if (queue
->continue_preamble_cs
)
1798 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1799 if (queue
->descriptor_bo
)
1800 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1801 if (queue
->scratch_bo
)
1802 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1803 if (queue
->esgs_ring_bo
)
1804 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1805 if (queue
->gsvs_ring_bo
)
1806 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1807 if (queue
->tess_rings_bo
)
1808 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1810 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
1811 if (queue
->gds_oa_bo
)
1812 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
1813 if (queue
->compute_scratch_bo
)
1814 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1818 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1820 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1821 bo_list
->list
.count
= bo_list
->capacity
= 0;
1822 bo_list
->list
.bos
= NULL
;
1826 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1828 free(bo_list
->list
.bos
);
1829 pthread_mutex_destroy(&bo_list
->mutex
);
1832 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1833 struct radeon_winsys_bo
*bo
)
1835 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1840 if (unlikely(!device
->use_global_bo_list
))
1843 pthread_mutex_lock(&bo_list
->mutex
);
1844 if (bo_list
->list
.count
== bo_list
->capacity
) {
1845 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1846 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1849 pthread_mutex_unlock(&bo_list
->mutex
);
1850 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1853 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1854 bo_list
->capacity
= capacity
;
1857 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1858 pthread_mutex_unlock(&bo_list
->mutex
);
1862 static void radv_bo_list_remove(struct radv_device
*device
,
1863 struct radeon_winsys_bo
*bo
)
1865 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1870 if (unlikely(!device
->use_global_bo_list
))
1873 pthread_mutex_lock(&bo_list
->mutex
);
1874 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1875 if (bo_list
->list
.bos
[i
] == bo
) {
1876 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1877 --bo_list
->list
.count
;
1881 pthread_mutex_unlock(&bo_list
->mutex
);
1885 radv_device_init_gs_info(struct radv_device
*device
)
1887 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1888 device
->physical_device
->rad_info
.family
);
1891 static int radv_get_device_extension_index(const char *name
)
1893 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1894 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1901 radv_get_int_debug_option(const char *name
, int default_value
)
1908 result
= default_value
;
1912 result
= strtol(str
, &endptr
, 0);
1913 if (str
== endptr
) {
1914 /* No digits founs. */
1915 result
= default_value
;
1922 VkResult
radv_CreateDevice(
1923 VkPhysicalDevice physicalDevice
,
1924 const VkDeviceCreateInfo
* pCreateInfo
,
1925 const VkAllocationCallbacks
* pAllocator
,
1928 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1930 struct radv_device
*device
;
1932 bool keep_shader_info
= false;
1934 /* Check enabled features */
1935 if (pCreateInfo
->pEnabledFeatures
) {
1936 VkPhysicalDeviceFeatures supported_features
;
1937 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1938 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1939 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1940 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1941 for (uint32_t i
= 0; i
< num_features
; i
++) {
1942 if (enabled_feature
[i
] && !supported_feature
[i
])
1943 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1947 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1949 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1951 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1953 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1954 device
->instance
= physical_device
->instance
;
1955 device
->physical_device
= physical_device
;
1957 device
->ws
= physical_device
->ws
;
1959 device
->alloc
= *pAllocator
;
1961 device
->alloc
= physical_device
->instance
->alloc
;
1963 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1964 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1965 int index
= radv_get_device_extension_index(ext_name
);
1966 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1967 vk_free(&device
->alloc
, device
);
1968 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1971 device
->enabled_extensions
.extensions
[index
] = true;
1974 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1976 /* With update after bind we can't attach bo's to the command buffer
1977 * from the descriptor set anymore, so we have to use a global BO list.
1979 device
->use_global_bo_list
=
1980 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1981 device
->enabled_extensions
.EXT_descriptor_indexing
||
1982 device
->enabled_extensions
.EXT_buffer_device_address
;
1984 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1985 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1987 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1988 list_inithead(&device
->shader_slabs
);
1990 radv_bo_list_init(&device
->bo_list
);
1992 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1993 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1994 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1995 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1996 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1998 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
2000 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
2001 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2002 if (!device
->queues
[qfi
]) {
2003 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
2007 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
2009 device
->queue_count
[qfi
] = queue_create
->queueCount
;
2011 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
2012 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
2013 qfi
, q
, queue_create
->flags
,
2015 if (result
!= VK_SUCCESS
)
2020 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
2021 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
2023 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
2024 device
->dfsm_allowed
= device
->pbb_allowed
&&
2025 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
2028 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
2031 /* The maximum number of scratch waves. Scratch space isn't divided
2032 * evenly between CUs. The number is only a function of the number of CUs.
2033 * We can decrease the constant to decrease the scratch buffer size.
2035 * sctx->scratch_waves must be >= the maximum possible size of
2036 * 1 threadgroup, so that the hw doesn't hang from being unable
2039 * The recommended value is 4 per CU at most. Higher numbers don't
2040 * bring much benefit, but they still occupy chip resources (think
2041 * async compute). I've seen ~2% performance difference between 4 and 32.
2043 uint32_t max_threads_per_block
= 2048;
2044 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
2045 max_threads_per_block
/ 64);
2047 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
2048 S_00B800_CS_W32_EN(device
->physical_device
->cs_wave_size
== 32);
2050 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2051 /* If the KMD allows it (there is a KMD hw register for it),
2052 * allow launching waves out-of-order.
2054 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
2057 radv_device_init_gs_info(device
);
2059 device
->tess_offchip_block_dw_size
=
2060 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
2062 if (getenv("RADV_TRACE_FILE")) {
2063 const char *filename
= getenv("RADV_TRACE_FILE");
2065 keep_shader_info
= true;
2067 if (!radv_init_trace(device
))
2070 fprintf(stderr
, "*****************************************************************************\n");
2071 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
2072 fprintf(stderr
, "*****************************************************************************\n");
2074 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
2075 radv_dump_enabled_options(device
, stderr
);
2078 device
->keep_shader_info
= keep_shader_info
;
2080 result
= radv_device_init_meta(device
);
2081 if (result
!= VK_SUCCESS
)
2084 radv_device_init_msaa(device
);
2086 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
2087 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
2089 case RADV_QUEUE_GENERAL
:
2090 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2091 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
2092 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
2094 case RADV_QUEUE_COMPUTE
:
2095 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
2096 radeon_emit(device
->empty_cs
[family
], 0);
2099 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
2102 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
2103 cik_create_gfx_config(device
);
2105 VkPipelineCacheCreateInfo ci
;
2106 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
2109 ci
.pInitialData
= NULL
;
2110 ci
.initialDataSize
= 0;
2112 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
2114 if (result
!= VK_SUCCESS
)
2117 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
2119 device
->force_aniso
=
2120 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
2121 if (device
->force_aniso
>= 0) {
2122 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2123 1 << util_logbase2(device
->force_aniso
));
2126 *pDevice
= radv_device_to_handle(device
);
2130 radv_device_finish_meta(device
);
2132 radv_bo_list_finish(&device
->bo_list
);
2134 if (device
->trace_bo
)
2135 device
->ws
->buffer_destroy(device
->trace_bo
);
2137 if (device
->gfx_init
)
2138 device
->ws
->buffer_destroy(device
->gfx_init
);
2140 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2141 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2142 radv_queue_finish(&device
->queues
[i
][q
]);
2143 if (device
->queue_count
[i
])
2144 vk_free(&device
->alloc
, device
->queues
[i
]);
2147 vk_free(&device
->alloc
, device
);
2151 void radv_DestroyDevice(
2153 const VkAllocationCallbacks
* pAllocator
)
2155 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2160 if (device
->trace_bo
)
2161 device
->ws
->buffer_destroy(device
->trace_bo
);
2163 if (device
->gfx_init
)
2164 device
->ws
->buffer_destroy(device
->gfx_init
);
2166 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2167 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2168 radv_queue_finish(&device
->queues
[i
][q
]);
2169 if (device
->queue_count
[i
])
2170 vk_free(&device
->alloc
, device
->queues
[i
]);
2171 if (device
->empty_cs
[i
])
2172 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2174 radv_device_finish_meta(device
);
2176 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2177 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2179 radv_destroy_shader_slabs(device
);
2181 radv_bo_list_finish(&device
->bo_list
);
2182 vk_free(&device
->alloc
, device
);
2185 VkResult
radv_EnumerateInstanceLayerProperties(
2186 uint32_t* pPropertyCount
,
2187 VkLayerProperties
* pProperties
)
2189 if (pProperties
== NULL
) {
2190 *pPropertyCount
= 0;
2194 /* None supported at this time */
2195 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2198 VkResult
radv_EnumerateDeviceLayerProperties(
2199 VkPhysicalDevice physicalDevice
,
2200 uint32_t* pPropertyCount
,
2201 VkLayerProperties
* pProperties
)
2203 if (pProperties
== NULL
) {
2204 *pPropertyCount
= 0;
2208 /* None supported at this time */
2209 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2212 void radv_GetDeviceQueue2(
2214 const VkDeviceQueueInfo2
* pQueueInfo
,
2217 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2218 struct radv_queue
*queue
;
2220 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2221 if (pQueueInfo
->flags
!= queue
->flags
) {
2222 /* From the Vulkan 1.1.70 spec:
2224 * "The queue returned by vkGetDeviceQueue2 must have the same
2225 * flags value from this structure as that used at device
2226 * creation time in a VkDeviceQueueCreateInfo instance. If no
2227 * matching flags were specified at device creation time then
2228 * pQueue will return VK_NULL_HANDLE."
2230 *pQueue
= VK_NULL_HANDLE
;
2234 *pQueue
= radv_queue_to_handle(queue
);
2237 void radv_GetDeviceQueue(
2239 uint32_t queueFamilyIndex
,
2240 uint32_t queueIndex
,
2243 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2244 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2245 .queueFamilyIndex
= queueFamilyIndex
,
2246 .queueIndex
= queueIndex
2249 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2253 fill_geom_tess_rings(struct radv_queue
*queue
,
2255 bool add_sample_positions
,
2256 uint32_t esgs_ring_size
,
2257 struct radeon_winsys_bo
*esgs_ring_bo
,
2258 uint32_t gsvs_ring_size
,
2259 struct radeon_winsys_bo
*gsvs_ring_bo
,
2260 uint32_t tess_factor_ring_size
,
2261 uint32_t tess_offchip_ring_offset
,
2262 uint32_t tess_offchip_ring_size
,
2263 struct radeon_winsys_bo
*tess_rings_bo
)
2265 uint32_t *desc
= &map
[4];
2268 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2270 /* stride 0, num records - size, add tid, swizzle, elsize4,
2273 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2274 S_008F04_SWIZZLE_ENABLE(true);
2275 desc
[2] = esgs_ring_size
;
2276 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2277 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2278 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2279 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2280 S_008F0C_INDEX_STRIDE(3) |
2281 S_008F0C_ADD_TID_ENABLE(1);
2283 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2284 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2285 S_008F0C_OOB_SELECT(2) |
2286 S_008F0C_RESOURCE_LEVEL(1);
2288 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2289 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2290 S_008F0C_ELEMENT_SIZE(1);
2293 /* GS entry for ES->GS ring */
2294 /* stride 0, num records - size, elsize0,
2297 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
2298 desc
[6] = esgs_ring_size
;
2299 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2300 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2301 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2302 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2304 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2305 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2306 S_008F0C_OOB_SELECT(2) |
2307 S_008F0C_RESOURCE_LEVEL(1);
2309 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2310 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2317 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2319 /* VS entry for GS->VS ring */
2320 /* stride 0, num records - size, elsize0,
2323 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
2324 desc
[2] = gsvs_ring_size
;
2325 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2326 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2327 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2328 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2330 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2331 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2332 S_008F0C_OOB_SELECT(2) |
2333 S_008F0C_RESOURCE_LEVEL(1);
2335 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2336 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2339 /* stride gsvs_itemsize, num records 64
2340 elsize 4, index stride 16 */
2341 /* shader will patch stride and desc[2] */
2343 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
2344 S_008F04_SWIZZLE_ENABLE(1);
2346 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2347 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2348 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2349 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2350 S_008F0C_INDEX_STRIDE(1) |
2351 S_008F0C_ADD_TID_ENABLE(true);
2353 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2354 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2355 S_008F0C_OOB_SELECT(2) |
2356 S_008F0C_RESOURCE_LEVEL(1);
2358 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2359 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2360 S_008F0C_ELEMENT_SIZE(1);
2367 if (tess_rings_bo
) {
2368 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2369 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2372 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
2373 desc
[2] = tess_factor_ring_size
;
2374 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2375 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2376 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2377 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2379 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2380 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2381 S_008F0C_OOB_SELECT(3) |
2382 S_008F0C_RESOURCE_LEVEL(1);
2384 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2385 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2388 desc
[4] = tess_offchip_va
;
2389 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
2390 desc
[6] = tess_offchip_ring_size
;
2391 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2392 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2393 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2394 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2396 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2397 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2398 S_008F0C_OOB_SELECT(3) |
2399 S_008F0C_RESOURCE_LEVEL(1);
2401 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2402 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2408 if (add_sample_positions
) {
2409 /* add sample positions after all rings */
2410 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2412 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2414 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2416 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2421 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2423 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2424 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2425 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2426 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2427 unsigned max_offchip_buffers
;
2428 unsigned offchip_granularity
;
2429 unsigned hs_offchip_param
;
2433 * This must be one less than the maximum number due to a hw limitation.
2434 * Various hardware bugs need thGFX7
2437 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2438 * Gfx7 should limit max_offchip_buffers to 508
2439 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2441 * Follow AMDVLK here.
2443 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2444 max_offchip_buffers_per_se
= 256;
2445 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2446 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2447 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2448 --max_offchip_buffers_per_se
;
2450 max_offchip_buffers
= max_offchip_buffers_per_se
*
2451 device
->physical_device
->rad_info
.max_se
;
2453 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2454 * around by setting 4K granularity.
2456 if (device
->tess_offchip_block_dw_size
== 4096) {
2457 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2458 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2460 assert(device
->tess_offchip_block_dw_size
== 8192);
2461 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2464 switch (device
->physical_device
->rad_info
.chip_class
) {
2466 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2471 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2479 *max_offchip_buffers_p
= max_offchip_buffers
;
2480 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2481 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2482 --max_offchip_buffers
;
2484 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2485 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2488 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2490 return hs_offchip_param
;
2494 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2495 struct radeon_winsys_bo
*esgs_ring_bo
,
2496 uint32_t esgs_ring_size
,
2497 struct radeon_winsys_bo
*gsvs_ring_bo
,
2498 uint32_t gsvs_ring_size
)
2500 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2504 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2507 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2509 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2510 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2511 radeon_emit(cs
, esgs_ring_size
>> 8);
2512 radeon_emit(cs
, gsvs_ring_size
>> 8);
2514 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2515 radeon_emit(cs
, esgs_ring_size
>> 8);
2516 radeon_emit(cs
, gsvs_ring_size
>> 8);
2521 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2522 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2523 struct radeon_winsys_bo
*tess_rings_bo
)
2530 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2532 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2534 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2535 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2536 S_030938_SIZE(tf_ring_size
/ 4));
2537 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2540 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2541 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2542 S_030984_BASE_HI(tf_va
>> 40));
2543 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2544 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2545 S_030944_BASE_HI(tf_va
>> 40));
2547 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2550 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2551 S_008988_SIZE(tf_ring_size
/ 4));
2552 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2554 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2560 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2561 struct radeon_winsys_bo
*compute_scratch_bo
)
2563 uint64_t scratch_va
;
2565 if (!compute_scratch_bo
)
2568 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2570 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2572 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2573 radeon_emit(cs
, scratch_va
);
2574 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2575 S_008F04_SWIZZLE_ENABLE(1));
2579 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2580 struct radeon_cmdbuf
*cs
,
2581 struct radeon_winsys_bo
*descriptor_bo
)
2588 va
= radv_buffer_get_va(descriptor_bo
);
2590 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2592 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2593 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2594 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2595 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2596 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2598 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2599 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2602 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2603 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2604 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2605 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2606 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2608 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2609 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2613 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2614 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2615 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2616 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2617 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2618 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2620 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2621 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2628 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2630 struct radv_device
*device
= queue
->device
;
2632 if (device
->gfx_init
) {
2633 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2635 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2636 radeon_emit(cs
, va
);
2637 radeon_emit(cs
, va
>> 32);
2638 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2640 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2642 struct radv_physical_device
*physical_device
= device
->physical_device
;
2643 si_emit_graphics(physical_device
, cs
);
2648 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2650 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2651 si_emit_compute(physical_device
, cs
);
2655 radv_get_preamble_cs(struct radv_queue
*queue
,
2656 uint32_t scratch_size
,
2657 uint32_t compute_scratch_size
,
2658 uint32_t esgs_ring_size
,
2659 uint32_t gsvs_ring_size
,
2660 bool needs_tess_rings
,
2662 bool needs_sample_positions
,
2663 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2664 struct radeon_cmdbuf
**initial_preamble_cs
,
2665 struct radeon_cmdbuf
**continue_preamble_cs
)
2667 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2668 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2669 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2670 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2671 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2672 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2673 struct radeon_winsys_bo
*gds_bo
= NULL
;
2674 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
2675 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2676 bool add_tess_rings
= false, add_gds
= false, add_sample_positions
= false;
2677 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2678 unsigned max_offchip_buffers
;
2679 unsigned hs_offchip_param
= 0;
2680 unsigned tess_offchip_ring_offset
;
2681 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2682 if (!queue
->has_tess_rings
) {
2683 if (needs_tess_rings
)
2684 add_tess_rings
= true;
2686 if (!queue
->has_gds
) {
2690 if (!queue
->has_sample_positions
) {
2691 if (needs_sample_positions
)
2692 add_sample_positions
= true;
2694 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2695 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2696 &max_offchip_buffers
);
2697 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2698 tess_offchip_ring_size
= max_offchip_buffers
*
2699 queue
->device
->tess_offchip_block_dw_size
* 4;
2701 if (scratch_size
<= queue
->scratch_size
&&
2702 compute_scratch_size
<= queue
->compute_scratch_size
&&
2703 esgs_ring_size
<= queue
->esgs_ring_size
&&
2704 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2705 !add_tess_rings
&& !add_gds
&& !add_sample_positions
&&
2706 queue
->initial_preamble_cs
) {
2707 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2708 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2709 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2710 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
&&
2711 !needs_tess_rings
&& !needs_gds
&& !needs_sample_positions
)
2712 *continue_preamble_cs
= NULL
;
2716 if (scratch_size
> queue
->scratch_size
) {
2717 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2722 RADV_BO_PRIORITY_SCRATCH
);
2726 scratch_bo
= queue
->scratch_bo
;
2728 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2729 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2730 compute_scratch_size
,
2734 RADV_BO_PRIORITY_SCRATCH
);
2735 if (!compute_scratch_bo
)
2739 compute_scratch_bo
= queue
->compute_scratch_bo
;
2741 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2742 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2747 RADV_BO_PRIORITY_SCRATCH
);
2751 esgs_ring_bo
= queue
->esgs_ring_bo
;
2752 esgs_ring_size
= queue
->esgs_ring_size
;
2755 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2756 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2761 RADV_BO_PRIORITY_SCRATCH
);
2765 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2766 gsvs_ring_size
= queue
->gsvs_ring_size
;
2769 if (add_tess_rings
) {
2770 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2771 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2775 RADV_BO_PRIORITY_SCRATCH
);
2779 tess_rings_bo
= queue
->tess_rings_bo
;
2783 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
2785 /* 4 streamout GDS counters.
2786 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
2788 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2792 RADV_BO_PRIORITY_SCRATCH
);
2796 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2800 RADV_BO_PRIORITY_SCRATCH
);
2804 gds_bo
= queue
->gds_bo
;
2805 gds_oa_bo
= queue
->gds_oa_bo
;
2808 if (scratch_bo
!= queue
->scratch_bo
||
2809 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2810 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2811 tess_rings_bo
!= queue
->tess_rings_bo
||
2812 add_sample_positions
) {
2814 if (gsvs_ring_bo
|| esgs_ring_bo
||
2815 tess_rings_bo
|| add_sample_positions
) {
2816 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2817 if (add_sample_positions
)
2818 size
+= 128; /* 64+32+16+8 = 120 bytes */
2820 else if (scratch_bo
)
2821 size
= 8; /* 2 dword */
2823 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2827 RADEON_FLAG_CPU_ACCESS
|
2828 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2829 RADEON_FLAG_READ_ONLY
,
2830 RADV_BO_PRIORITY_DESCRIPTOR
);
2834 descriptor_bo
= queue
->descriptor_bo
;
2836 if (descriptor_bo
!= queue
->descriptor_bo
) {
2837 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2840 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2841 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2842 S_008F04_SWIZZLE_ENABLE(1);
2843 map
[0] = scratch_va
;
2847 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2848 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2849 esgs_ring_size
, esgs_ring_bo
,
2850 gsvs_ring_size
, gsvs_ring_bo
,
2851 tess_factor_ring_size
,
2852 tess_offchip_ring_offset
,
2853 tess_offchip_ring_size
,
2856 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2859 for(int i
= 0; i
< 3; ++i
) {
2860 struct radeon_cmdbuf
*cs
= NULL
;
2861 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2862 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2869 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2871 /* Emit initial configuration. */
2872 switch (queue
->queue_family_index
) {
2873 case RADV_QUEUE_GENERAL
:
2874 radv_init_graphics_state(cs
, queue
);
2876 case RADV_QUEUE_COMPUTE
:
2877 radv_init_compute_state(cs
, queue
);
2879 case RADV_QUEUE_TRANSFER
:
2883 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2884 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2885 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2887 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2888 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2891 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2892 gsvs_ring_bo
, gsvs_ring_size
);
2893 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2894 tess_factor_ring_size
, tess_rings_bo
);
2895 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2896 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2899 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
2901 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
2904 si_cs_emit_cache_flush(cs
,
2905 queue
->device
->physical_device
->rad_info
.chip_class
,
2907 queue
->queue_family_index
== RING_COMPUTE
&&
2908 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2909 (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
)) |
2910 RADV_CMD_FLAG_INV_ICACHE
|
2911 RADV_CMD_FLAG_INV_SCACHE
|
2912 RADV_CMD_FLAG_INV_VCACHE
|
2913 RADV_CMD_FLAG_INV_L2
|
2914 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2915 } else if (i
== 1) {
2916 si_cs_emit_cache_flush(cs
,
2917 queue
->device
->physical_device
->rad_info
.chip_class
,
2919 queue
->queue_family_index
== RING_COMPUTE
&&
2920 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2921 RADV_CMD_FLAG_INV_ICACHE
|
2922 RADV_CMD_FLAG_INV_SCACHE
|
2923 RADV_CMD_FLAG_INV_VCACHE
|
2924 RADV_CMD_FLAG_INV_L2
|
2925 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2928 if (!queue
->device
->ws
->cs_finalize(cs
))
2932 if (queue
->initial_full_flush_preamble_cs
)
2933 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2935 if (queue
->initial_preamble_cs
)
2936 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2938 if (queue
->continue_preamble_cs
)
2939 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2941 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2942 queue
->initial_preamble_cs
= dest_cs
[1];
2943 queue
->continue_preamble_cs
= dest_cs
[2];
2945 if (scratch_bo
!= queue
->scratch_bo
) {
2946 if (queue
->scratch_bo
)
2947 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2948 queue
->scratch_bo
= scratch_bo
;
2949 queue
->scratch_size
= scratch_size
;
2952 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2953 if (queue
->compute_scratch_bo
)
2954 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2955 queue
->compute_scratch_bo
= compute_scratch_bo
;
2956 queue
->compute_scratch_size
= compute_scratch_size
;
2959 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2960 if (queue
->esgs_ring_bo
)
2961 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2962 queue
->esgs_ring_bo
= esgs_ring_bo
;
2963 queue
->esgs_ring_size
= esgs_ring_size
;
2966 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2967 if (queue
->gsvs_ring_bo
)
2968 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2969 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2970 queue
->gsvs_ring_size
= gsvs_ring_size
;
2973 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2974 queue
->tess_rings_bo
= tess_rings_bo
;
2975 queue
->has_tess_rings
= true;
2978 if (gds_bo
!= queue
->gds_bo
) {
2979 queue
->gds_bo
= gds_bo
;
2980 queue
->has_gds
= true;
2983 if (gds_oa_bo
!= queue
->gds_oa_bo
)
2984 queue
->gds_oa_bo
= gds_oa_bo
;
2986 if (descriptor_bo
!= queue
->descriptor_bo
) {
2987 if (queue
->descriptor_bo
)
2988 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2990 queue
->descriptor_bo
= descriptor_bo
;
2993 if (add_sample_positions
)
2994 queue
->has_sample_positions
= true;
2996 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2997 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2998 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2999 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
3000 *continue_preamble_cs
= NULL
;
3003 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
3005 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
3006 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
3007 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
3008 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
3009 queue
->device
->ws
->buffer_destroy(scratch_bo
);
3010 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
3011 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
3012 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
3013 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
3014 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
3015 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
3016 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
3017 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
3018 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
3019 queue
->device
->ws
->buffer_destroy(gds_bo
);
3020 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
3021 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
3023 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3026 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
3027 struct radv_winsys_sem_counts
*counts
,
3029 const VkSemaphore
*sems
,
3033 int syncobj_idx
= 0, sem_idx
= 0;
3035 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
3038 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3039 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3041 if (sem
->temp_syncobj
|| sem
->syncobj
)
3042 counts
->syncobj_count
++;
3044 counts
->sem_count
++;
3047 if (_fence
!= VK_NULL_HANDLE
) {
3048 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3049 if (fence
->temp_syncobj
|| fence
->syncobj
)
3050 counts
->syncobj_count
++;
3053 if (counts
->syncobj_count
) {
3054 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
3055 if (!counts
->syncobj
)
3056 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3059 if (counts
->sem_count
) {
3060 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
3062 free(counts
->syncobj
);
3063 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
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 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
3073 else if (sem
->syncobj
)
3074 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
3077 counts
->sem
[sem_idx
++] = sem
->sem
;
3081 if (_fence
!= VK_NULL_HANDLE
) {
3082 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3083 if (fence
->temp_syncobj
)
3084 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
3085 else if (fence
->syncobj
)
3086 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
3093 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
3095 free(sem_info
->wait
.syncobj
);
3096 free(sem_info
->wait
.sem
);
3097 free(sem_info
->signal
.syncobj
);
3098 free(sem_info
->signal
.sem
);
3102 static void radv_free_temp_syncobjs(struct radv_device
*device
,
3104 const VkSemaphore
*sems
)
3106 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3107 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3109 if (sem
->temp_syncobj
) {
3110 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
3111 sem
->temp_syncobj
= 0;
3117 radv_alloc_sem_info(struct radv_instance
*instance
,
3118 struct radv_winsys_sem_info
*sem_info
,
3120 const VkSemaphore
*wait_sems
,
3121 int num_signal_sems
,
3122 const VkSemaphore
*signal_sems
,
3126 memset(sem_info
, 0, sizeof(*sem_info
));
3128 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
3131 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
3133 radv_free_sem_info(sem_info
);
3135 /* caller can override these */
3136 sem_info
->cs_emit_wait
= true;
3137 sem_info
->cs_emit_signal
= true;
3141 /* Signals fence as soon as all the work currently put on queue is done. */
3142 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
3143 struct radv_fence
*fence
)
3147 struct radv_winsys_sem_info sem_info
;
3149 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
3150 radv_fence_to_handle(fence
));
3151 if (result
!= VK_SUCCESS
)
3154 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3155 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3156 1, NULL
, NULL
, &sem_info
, NULL
,
3157 false, fence
->fence
);
3158 radv_free_sem_info(&sem_info
);
3161 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
3166 VkResult
radv_QueueSubmit(
3168 uint32_t submitCount
,
3169 const VkSubmitInfo
* pSubmits
,
3172 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3173 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3174 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3175 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
3177 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
3178 uint32_t scratch_size
= 0;
3179 uint32_t compute_scratch_size
= 0;
3180 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
3181 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
3183 bool fence_emitted
= false;
3184 bool tess_rings_needed
= false;
3185 bool gds_needed
= false;
3186 bool sample_positions_needed
= false;
3188 /* Do this first so failing to allocate scratch buffers can't result in
3189 * partially executed submissions. */
3190 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3191 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3192 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3193 pSubmits
[i
].pCommandBuffers
[j
]);
3195 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
3196 compute_scratch_size
= MAX2(compute_scratch_size
,
3197 cmd_buffer
->compute_scratch_size_needed
);
3198 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
3199 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
3200 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
3201 gds_needed
|= cmd_buffer
->gds_needed
;
3202 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3206 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3207 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3208 gds_needed
, sample_positions_needed
,
3209 &initial_flush_preamble_cs
,
3210 &initial_preamble_cs
, &continue_preamble_cs
);
3211 if (result
!= VK_SUCCESS
)
3214 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3215 struct radeon_cmdbuf
**cs_array
;
3216 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
3217 bool can_patch
= true;
3219 struct radv_winsys_sem_info sem_info
;
3221 result
= radv_alloc_sem_info(queue
->device
->instance
,
3223 pSubmits
[i
].waitSemaphoreCount
,
3224 pSubmits
[i
].pWaitSemaphores
,
3225 pSubmits
[i
].signalSemaphoreCount
,
3226 pSubmits
[i
].pSignalSemaphores
,
3228 if (result
!= VK_SUCCESS
)
3231 if (!pSubmits
[i
].commandBufferCount
) {
3232 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
3233 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3234 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3239 radv_loge("failed to submit CS %d\n", i
);
3242 fence_emitted
= true;
3244 radv_free_sem_info(&sem_info
);
3248 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3249 (pSubmits
[i
].commandBufferCount
));
3251 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3252 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3253 pSubmits
[i
].pCommandBuffers
[j
]);
3254 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3256 cs_array
[j
] = cmd_buffer
->cs
;
3257 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3260 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3263 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3264 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3265 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3267 advance
= MIN2(max_cs_submission
,
3268 pSubmits
[i
].commandBufferCount
- j
);
3270 if (queue
->device
->trace_bo
)
3271 *queue
->device
->trace_id_ptr
= 0;
3273 sem_info
.cs_emit_wait
= j
== 0;
3274 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3276 if (unlikely(queue
->device
->use_global_bo_list
)) {
3277 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3278 bo_list
= &queue
->device
->bo_list
.list
;
3281 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3282 advance
, initial_preamble
, continue_preamble_cs
,
3284 can_patch
, base_fence
);
3286 if (unlikely(queue
->device
->use_global_bo_list
))
3287 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3290 radv_loge("failed to submit CS %d\n", i
);
3293 fence_emitted
= true;
3294 if (queue
->device
->trace_bo
) {
3295 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3299 radv_free_temp_syncobjs(queue
->device
,
3300 pSubmits
[i
].waitSemaphoreCount
,
3301 pSubmits
[i
].pWaitSemaphores
);
3302 radv_free_sem_info(&sem_info
);
3307 if (!fence_emitted
) {
3308 result
= radv_signal_fence(queue
, fence
);
3309 if (result
!= VK_SUCCESS
)
3317 VkResult
radv_QueueWaitIdle(
3320 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3322 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3323 radv_queue_family_to_ring(queue
->queue_family_index
),
3328 VkResult
radv_DeviceWaitIdle(
3331 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3333 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3334 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3335 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3341 VkResult
radv_EnumerateInstanceExtensionProperties(
3342 const char* pLayerName
,
3343 uint32_t* pPropertyCount
,
3344 VkExtensionProperties
* pProperties
)
3346 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3348 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3349 if (radv_supported_instance_extensions
.extensions
[i
]) {
3350 vk_outarray_append(&out
, prop
) {
3351 *prop
= radv_instance_extensions
[i
];
3356 return vk_outarray_status(&out
);
3359 VkResult
radv_EnumerateDeviceExtensionProperties(
3360 VkPhysicalDevice physicalDevice
,
3361 const char* pLayerName
,
3362 uint32_t* pPropertyCount
,
3363 VkExtensionProperties
* pProperties
)
3365 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3366 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3368 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3369 if (device
->supported_extensions
.extensions
[i
]) {
3370 vk_outarray_append(&out
, prop
) {
3371 *prop
= radv_device_extensions
[i
];
3376 return vk_outarray_status(&out
);
3379 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3380 VkInstance _instance
,
3383 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3384 bool unchecked
= instance
? instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
3387 return radv_lookup_entrypoint_unchecked(pName
);
3389 return radv_lookup_entrypoint_checked(pName
,
3390 instance
? instance
->apiVersion
: 0,
3391 instance
? &instance
->enabled_extensions
: NULL
,
3396 /* The loader wants us to expose a second GetInstanceProcAddr function
3397 * to work around certain LD_PRELOAD issues seen in apps.
3400 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3401 VkInstance instance
,
3405 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3406 VkInstance instance
,
3409 return radv_GetInstanceProcAddr(instance
, pName
);
3413 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3414 VkInstance _instance
,
3418 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3419 VkInstance _instance
,
3422 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3424 return radv_lookup_physical_device_entrypoint_checked(pName
,
3425 instance
? instance
->apiVersion
: 0,
3426 instance
? &instance
->enabled_extensions
: NULL
);
3429 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3433 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3434 bool unchecked
= device
? device
->instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
3437 return radv_lookup_entrypoint_unchecked(pName
);
3439 return radv_lookup_entrypoint_checked(pName
,
3440 device
->instance
->apiVersion
,
3441 &device
->instance
->enabled_extensions
,
3442 &device
->enabled_extensions
);
3446 bool radv_get_memory_fd(struct radv_device
*device
,
3447 struct radv_device_memory
*memory
,
3450 struct radeon_bo_metadata metadata
;
3452 if (memory
->image
) {
3453 radv_init_metadata(device
, memory
->image
, &metadata
);
3454 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3457 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3462 static void radv_free_memory(struct radv_device
*device
,
3463 const VkAllocationCallbacks
* pAllocator
,
3464 struct radv_device_memory
*mem
)
3469 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
3470 if (mem
->android_hardware_buffer
)
3471 AHardwareBuffer_release(mem
->android_hardware_buffer
);
3475 radv_bo_list_remove(device
, mem
->bo
);
3476 device
->ws
->buffer_destroy(mem
->bo
);
3480 vk_free2(&device
->alloc
, pAllocator
, mem
);
3483 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3484 const VkMemoryAllocateInfo
* pAllocateInfo
,
3485 const VkAllocationCallbacks
* pAllocator
,
3486 VkDeviceMemory
* pMem
)
3488 struct radv_device_memory
*mem
;
3490 enum radeon_bo_domain domain
;
3492 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3494 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3496 const VkImportMemoryFdInfoKHR
*import_info
=
3497 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3498 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3499 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3500 const VkExportMemoryAllocateInfo
*export_info
=
3501 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3502 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahb_import_info
=
3503 vk_find_struct_const(pAllocateInfo
->pNext
,
3504 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
3505 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3506 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3508 const struct wsi_memory_allocate_info
*wsi_info
=
3509 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3511 if (pAllocateInfo
->allocationSize
== 0 && !ahb_import_info
&&
3512 !(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
))) {
3513 /* Apparently, this is allowed */
3514 *pMem
= VK_NULL_HANDLE
;
3518 mem
= vk_zalloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3519 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3521 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3523 if (wsi_info
&& wsi_info
->implicit_sync
)
3524 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3526 if (dedicate_info
) {
3527 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3528 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3534 float priority_float
= 0.5;
3535 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3536 vk_find_struct_const(pAllocateInfo
->pNext
,
3537 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3539 priority_float
= priority_ext
->priority
;
3541 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3542 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3544 mem
->user_ptr
= NULL
;
3547 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
3548 mem
->android_hardware_buffer
= NULL
;
3551 if (ahb_import_info
) {
3552 result
= radv_import_ahb_memory(device
, mem
, priority
, ahb_import_info
);
3553 if (result
!= VK_SUCCESS
)
3555 } else if(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)) {
3556 result
= radv_create_ahb_memory(device
, mem
, priority
, pAllocateInfo
);
3557 if (result
!= VK_SUCCESS
)
3559 } else if (import_info
) {
3560 assert(import_info
->handleType
==
3561 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3562 import_info
->handleType
==
3563 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3564 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3567 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3570 close(import_info
->fd
);
3572 } else if (host_ptr_info
) {
3573 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3574 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3575 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3576 pAllocateInfo
->allocationSize
,
3579 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3582 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3585 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3586 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3587 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3588 domain
= RADEON_DOMAIN_GTT
;
3590 domain
= RADEON_DOMAIN_VRAM
;
3592 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3593 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3595 flags
|= RADEON_FLAG_CPU_ACCESS
;
3597 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3598 flags
|= RADEON_FLAG_GTT_WC
;
3600 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3601 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3602 if (device
->use_global_bo_list
) {
3603 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3607 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3608 domain
, flags
, priority
);
3611 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3614 mem
->type_index
= mem_type_index
;
3617 result
= radv_bo_list_add(device
, mem
->bo
);
3618 if (result
!= VK_SUCCESS
)
3621 *pMem
= radv_device_memory_to_handle(mem
);
3626 radv_free_memory(device
, pAllocator
,mem
);
3627 vk_free2(&device
->alloc
, pAllocator
, mem
);
3632 VkResult
radv_AllocateMemory(
3634 const VkMemoryAllocateInfo
* pAllocateInfo
,
3635 const VkAllocationCallbacks
* pAllocator
,
3636 VkDeviceMemory
* pMem
)
3638 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3639 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3642 void radv_FreeMemory(
3644 VkDeviceMemory _mem
,
3645 const VkAllocationCallbacks
* pAllocator
)
3647 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3648 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3650 radv_free_memory(device
, pAllocator
, mem
);
3653 VkResult
radv_MapMemory(
3655 VkDeviceMemory _memory
,
3656 VkDeviceSize offset
,
3658 VkMemoryMapFlags flags
,
3661 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3662 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3670 *ppData
= mem
->user_ptr
;
3672 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3679 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3682 void radv_UnmapMemory(
3684 VkDeviceMemory _memory
)
3686 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3687 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3692 if (mem
->user_ptr
== NULL
)
3693 device
->ws
->buffer_unmap(mem
->bo
);
3696 VkResult
radv_FlushMappedMemoryRanges(
3698 uint32_t memoryRangeCount
,
3699 const VkMappedMemoryRange
* pMemoryRanges
)
3704 VkResult
radv_InvalidateMappedMemoryRanges(
3706 uint32_t memoryRangeCount
,
3707 const VkMappedMemoryRange
* pMemoryRanges
)
3712 void radv_GetBufferMemoryRequirements(
3715 VkMemoryRequirements
* pMemoryRequirements
)
3717 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3718 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3720 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3722 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3723 pMemoryRequirements
->alignment
= 4096;
3725 pMemoryRequirements
->alignment
= 16;
3727 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3730 void radv_GetBufferMemoryRequirements2(
3732 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3733 VkMemoryRequirements2
*pMemoryRequirements
)
3735 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3736 &pMemoryRequirements
->memoryRequirements
);
3737 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3738 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3739 switch (ext
->sType
) {
3740 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3741 VkMemoryDedicatedRequirements
*req
=
3742 (VkMemoryDedicatedRequirements
*) ext
;
3743 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3744 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3753 void radv_GetImageMemoryRequirements(
3756 VkMemoryRequirements
* pMemoryRequirements
)
3758 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3759 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3761 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3763 pMemoryRequirements
->size
= image
->size
;
3764 pMemoryRequirements
->alignment
= image
->alignment
;
3767 void radv_GetImageMemoryRequirements2(
3769 const VkImageMemoryRequirementsInfo2
*pInfo
,
3770 VkMemoryRequirements2
*pMemoryRequirements
)
3772 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3773 &pMemoryRequirements
->memoryRequirements
);
3775 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3777 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3778 switch (ext
->sType
) {
3779 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3780 VkMemoryDedicatedRequirements
*req
=
3781 (VkMemoryDedicatedRequirements
*) ext
;
3782 req
->requiresDedicatedAllocation
= image
->shareable
;
3783 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3792 void radv_GetImageSparseMemoryRequirements(
3795 uint32_t* pSparseMemoryRequirementCount
,
3796 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3801 void radv_GetImageSparseMemoryRequirements2(
3803 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3804 uint32_t* pSparseMemoryRequirementCount
,
3805 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3810 void radv_GetDeviceMemoryCommitment(
3812 VkDeviceMemory memory
,
3813 VkDeviceSize
* pCommittedMemoryInBytes
)
3815 *pCommittedMemoryInBytes
= 0;
3818 VkResult
radv_BindBufferMemory2(VkDevice device
,
3819 uint32_t bindInfoCount
,
3820 const VkBindBufferMemoryInfo
*pBindInfos
)
3822 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3823 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3824 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3827 buffer
->bo
= mem
->bo
;
3828 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3836 VkResult
radv_BindBufferMemory(
3839 VkDeviceMemory memory
,
3840 VkDeviceSize memoryOffset
)
3842 const VkBindBufferMemoryInfo info
= {
3843 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3846 .memoryOffset
= memoryOffset
3849 return radv_BindBufferMemory2(device
, 1, &info
);
3852 VkResult
radv_BindImageMemory2(VkDevice device
,
3853 uint32_t bindInfoCount
,
3854 const VkBindImageMemoryInfo
*pBindInfos
)
3856 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3857 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3858 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3861 image
->bo
= mem
->bo
;
3862 image
->offset
= pBindInfos
[i
].memoryOffset
;
3872 VkResult
radv_BindImageMemory(
3875 VkDeviceMemory memory
,
3876 VkDeviceSize memoryOffset
)
3878 const VkBindImageMemoryInfo info
= {
3879 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3882 .memoryOffset
= memoryOffset
3885 return radv_BindImageMemory2(device
, 1, &info
);
3890 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3891 const VkSparseBufferMemoryBindInfo
*bind
)
3893 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3895 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3896 struct radv_device_memory
*mem
= NULL
;
3898 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3899 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3901 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3902 bind
->pBinds
[i
].resourceOffset
,
3903 bind
->pBinds
[i
].size
,
3904 mem
? mem
->bo
: NULL
,
3905 bind
->pBinds
[i
].memoryOffset
);
3910 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3911 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3913 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3915 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3916 struct radv_device_memory
*mem
= NULL
;
3918 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3919 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3921 device
->ws
->buffer_virtual_bind(image
->bo
,
3922 bind
->pBinds
[i
].resourceOffset
,
3923 bind
->pBinds
[i
].size
,
3924 mem
? mem
->bo
: NULL
,
3925 bind
->pBinds
[i
].memoryOffset
);
3929 VkResult
radv_QueueBindSparse(
3931 uint32_t bindInfoCount
,
3932 const VkBindSparseInfo
* pBindInfo
,
3935 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3936 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3937 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3938 bool fence_emitted
= false;
3942 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3943 struct radv_winsys_sem_info sem_info
;
3944 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3945 radv_sparse_buffer_bind_memory(queue
->device
,
3946 pBindInfo
[i
].pBufferBinds
+ j
);
3949 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3950 radv_sparse_image_opaque_bind_memory(queue
->device
,
3951 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3955 result
= radv_alloc_sem_info(queue
->device
->instance
,
3957 pBindInfo
[i
].waitSemaphoreCount
,
3958 pBindInfo
[i
].pWaitSemaphores
,
3959 pBindInfo
[i
].signalSemaphoreCount
,
3960 pBindInfo
[i
].pSignalSemaphores
,
3962 if (result
!= VK_SUCCESS
)
3965 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3966 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3967 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3972 radv_loge("failed to submit CS %d\n", i
);
3976 fence_emitted
= true;
3979 radv_free_sem_info(&sem_info
);
3984 if (!fence_emitted
) {
3985 result
= radv_signal_fence(queue
, fence
);
3986 if (result
!= VK_SUCCESS
)
3994 VkResult
radv_CreateFence(
3996 const VkFenceCreateInfo
* pCreateInfo
,
3997 const VkAllocationCallbacks
* pAllocator
,
4000 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4001 const VkExportFenceCreateInfo
*export
=
4002 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
4003 VkExternalFenceHandleTypeFlags handleTypes
=
4004 export
? export
->handleTypes
: 0;
4006 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
4008 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4011 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4013 fence
->fence_wsi
= NULL
;
4014 fence
->temp_syncobj
= 0;
4015 if (device
->always_use_syncobj
|| handleTypes
) {
4016 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
4018 vk_free2(&device
->alloc
, pAllocator
, fence
);
4019 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4021 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
4022 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
4024 fence
->fence
= NULL
;
4026 fence
->fence
= device
->ws
->create_fence();
4027 if (!fence
->fence
) {
4028 vk_free2(&device
->alloc
, pAllocator
, fence
);
4029 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4032 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
4033 device
->ws
->signal_fence(fence
->fence
);
4036 *pFence
= radv_fence_to_handle(fence
);
4041 void radv_DestroyFence(
4044 const VkAllocationCallbacks
* pAllocator
)
4046 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4047 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4052 if (fence
->temp_syncobj
)
4053 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4055 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
4057 device
->ws
->destroy_fence(fence
->fence
);
4058 if (fence
->fence_wsi
)
4059 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
4060 vk_free2(&device
->alloc
, pAllocator
, fence
);
4064 uint64_t radv_get_current_time(void)
4067 clock_gettime(CLOCK_MONOTONIC
, &tv
);
4068 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
4071 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
4073 uint64_t current_time
= radv_get_current_time();
4075 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
4077 return current_time
+ timeout
;
4081 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
4082 uint32_t fenceCount
, const VkFence
*pFences
)
4084 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4085 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4086 if (fence
->fence
== NULL
|| fence
->syncobj
||
4087 fence
->temp_syncobj
|| fence
->fence_wsi
||
4088 (!device
->ws
->is_fence_waitable(fence
->fence
)))
4094 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
4096 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4097 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4098 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
4104 VkResult
radv_WaitForFences(
4106 uint32_t fenceCount
,
4107 const VkFence
* pFences
,
4111 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4112 timeout
= radv_get_absolute_timeout(timeout
);
4114 if (device
->always_use_syncobj
&&
4115 radv_all_fences_syncobj(fenceCount
, pFences
))
4117 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
4119 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4121 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4122 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4123 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
4126 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
4129 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4132 if (!waitAll
&& fenceCount
> 1) {
4133 /* Not doing this by default for waitAll, due to needing to allocate twice. */
4134 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
4135 uint32_t wait_count
= 0;
4136 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
4138 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4140 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4141 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4143 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
4148 fences
[wait_count
++] = fence
->fence
;
4151 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
4152 waitAll
, timeout
- radv_get_current_time());
4155 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4158 while(radv_get_current_time() <= timeout
) {
4159 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4160 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
4167 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4168 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4169 bool expired
= false;
4171 if (fence
->temp_syncobj
) {
4172 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
4177 if (fence
->syncobj
) {
4178 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
4184 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
4185 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
4186 radv_get_current_time() <= timeout
)
4190 expired
= device
->ws
->fence_wait(device
->ws
,
4197 if (fence
->fence_wsi
) {
4198 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
4199 if (result
!= VK_SUCCESS
)
4207 VkResult
radv_ResetFences(VkDevice _device
,
4208 uint32_t fenceCount
,
4209 const VkFence
*pFences
)
4211 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4213 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
4214 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4216 device
->ws
->reset_fence(fence
->fence
);
4218 /* Per spec, we first restore the permanent payload, and then reset, so
4219 * having a temp syncobj should not skip resetting the permanent syncobj. */
4220 if (fence
->temp_syncobj
) {
4221 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4222 fence
->temp_syncobj
= 0;
4225 if (fence
->syncobj
) {
4226 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
4233 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
4235 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4236 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4238 if (fence
->temp_syncobj
) {
4239 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
4240 return success
? VK_SUCCESS
: VK_NOT_READY
;
4243 if (fence
->syncobj
) {
4244 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
4245 return success
? VK_SUCCESS
: VK_NOT_READY
;
4249 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
4250 return VK_NOT_READY
;
4252 if (fence
->fence_wsi
) {
4253 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
4255 if (result
!= VK_SUCCESS
) {
4256 if (result
== VK_TIMEOUT
)
4257 return VK_NOT_READY
;
4265 // Queue semaphore functions
4267 VkResult
radv_CreateSemaphore(
4269 const VkSemaphoreCreateInfo
* pCreateInfo
,
4270 const VkAllocationCallbacks
* pAllocator
,
4271 VkSemaphore
* pSemaphore
)
4273 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4274 const VkExportSemaphoreCreateInfo
*export
=
4275 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
4276 VkExternalSemaphoreHandleTypeFlags handleTypes
=
4277 export
? export
->handleTypes
: 0;
4279 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
4281 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4283 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4285 sem
->temp_syncobj
= 0;
4286 /* create a syncobject if we are going to export this semaphore */
4287 if (device
->always_use_syncobj
|| handleTypes
) {
4288 assert (device
->physical_device
->rad_info
.has_syncobj
);
4289 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4291 vk_free2(&device
->alloc
, pAllocator
, sem
);
4292 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4296 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4298 vk_free2(&device
->alloc
, pAllocator
, sem
);
4299 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4304 *pSemaphore
= radv_semaphore_to_handle(sem
);
4308 void radv_DestroySemaphore(
4310 VkSemaphore _semaphore
,
4311 const VkAllocationCallbacks
* pAllocator
)
4313 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4314 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4319 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4321 device
->ws
->destroy_sem(sem
->sem
);
4322 vk_free2(&device
->alloc
, pAllocator
, sem
);
4325 VkResult
radv_CreateEvent(
4327 const VkEventCreateInfo
* pCreateInfo
,
4328 const VkAllocationCallbacks
* pAllocator
,
4331 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4332 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4334 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4337 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4339 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4341 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4342 RADV_BO_PRIORITY_FENCE
);
4344 vk_free2(&device
->alloc
, pAllocator
, event
);
4345 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4348 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4350 *pEvent
= radv_event_to_handle(event
);
4355 void radv_DestroyEvent(
4358 const VkAllocationCallbacks
* pAllocator
)
4360 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4361 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4365 device
->ws
->buffer_destroy(event
->bo
);
4366 vk_free2(&device
->alloc
, pAllocator
, event
);
4369 VkResult
radv_GetEventStatus(
4373 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4375 if (*event
->map
== 1)
4376 return VK_EVENT_SET
;
4377 return VK_EVENT_RESET
;
4380 VkResult
radv_SetEvent(
4384 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4390 VkResult
radv_ResetEvent(
4394 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4400 VkResult
radv_CreateBuffer(
4402 const VkBufferCreateInfo
* pCreateInfo
,
4403 const VkAllocationCallbacks
* pAllocator
,
4406 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4407 struct radv_buffer
*buffer
;
4409 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4411 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4412 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4414 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4416 buffer
->size
= pCreateInfo
->size
;
4417 buffer
->usage
= pCreateInfo
->usage
;
4420 buffer
->flags
= pCreateInfo
->flags
;
4422 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4423 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4425 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4426 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4427 align64(buffer
->size
, 4096),
4428 4096, 0, RADEON_FLAG_VIRTUAL
,
4429 RADV_BO_PRIORITY_VIRTUAL
);
4431 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4432 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4436 *pBuffer
= radv_buffer_to_handle(buffer
);
4441 void radv_DestroyBuffer(
4444 const VkAllocationCallbacks
* pAllocator
)
4446 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4447 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4452 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4453 device
->ws
->buffer_destroy(buffer
->bo
);
4455 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4458 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4460 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4462 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4463 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4467 static inline unsigned
4468 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4471 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4473 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4476 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4478 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4482 radv_init_dcc_control_reg(struct radv_device
*device
,
4483 struct radv_image_view
*iview
)
4485 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4486 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4487 unsigned max_compressed_block_size
;
4488 unsigned independent_128b_blocks
;
4489 unsigned independent_64b_blocks
;
4491 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4494 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4495 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4496 * dGPU and 64 for APU because all of our APUs to date use
4497 * DIMMs which have a request granularity size of 64B while all
4498 * other chips have a 32B request size.
4500 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4503 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4504 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4505 independent_64b_blocks
= 0;
4506 independent_128b_blocks
= 1;
4508 independent_128b_blocks
= 0;
4510 if (iview
->image
->info
.samples
> 1) {
4511 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4512 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4513 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4514 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4517 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4518 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4519 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4520 /* If this DCC image is potentially going to be used in texture
4521 * fetches, we need some special settings.
4523 independent_64b_blocks
= 1;
4524 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4526 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4527 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4528 * big as possible for better compression state.
4530 independent_64b_blocks
= 0;
4531 max_compressed_block_size
= max_uncompressed_block_size
;
4535 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4536 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4537 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4538 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
4539 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
4543 radv_initialise_color_surface(struct radv_device
*device
,
4544 struct radv_color_buffer_info
*cb
,
4545 struct radv_image_view
*iview
)
4547 const struct vk_format_description
*desc
;
4548 unsigned ntype
, format
, swap
, endian
;
4549 unsigned blend_clamp
= 0, blend_bypass
= 0;
4551 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4552 const struct radeon_surf
*surf
= &plane
->surface
;
4554 desc
= vk_format_description(iview
->vk_format
);
4556 memset(cb
, 0, sizeof(*cb
));
4558 /* Intensity is implemented as Red, so treat it that way. */
4559 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4561 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4563 cb
->cb_color_base
= va
>> 8;
4565 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4566 struct gfx9_surf_meta_flags meta
;
4567 if (iview
->image
->dcc_offset
)
4568 meta
= surf
->u
.gfx9
.dcc
;
4570 meta
= surf
->u
.gfx9
.cmask
;
4572 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4573 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4574 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4575 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
4576 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
4578 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4579 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4580 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4581 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4582 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4585 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4586 cb
->cb_color_base
|= surf
->tile_swizzle
;
4588 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4589 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4591 cb
->cb_color_base
+= level_info
->offset
>> 8;
4592 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4593 cb
->cb_color_base
|= surf
->tile_swizzle
;
4595 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4596 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4597 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4599 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4600 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4601 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
4603 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4605 if (radv_image_has_fmask(iview
->image
)) {
4606 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4607 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
4608 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
4609 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
4611 /* This must be set for fast clear to work without FMASK. */
4612 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4613 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4614 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4615 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4619 /* CMASK variables */
4620 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4621 va
+= iview
->image
->cmask_offset
;
4622 cb
->cb_color_cmask
= va
>> 8;
4624 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4625 va
+= iview
->image
->dcc_offset
;
4627 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
4628 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
4629 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
4631 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
4632 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
4634 cb
->cb_dcc_base
= va
>> 8;
4635 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
4637 /* GFX10 field has the same base shift as the GFX6 field. */
4638 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4639 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4640 S_028C6C_SLICE_MAX_GFX10(max_slice
);
4642 if (iview
->image
->info
.samples
> 1) {
4643 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4645 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4646 S_028C74_NUM_FRAGMENTS(log_samples
);
4649 if (radv_image_has_fmask(iview
->image
)) {
4650 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
4651 cb
->cb_color_fmask
= va
>> 8;
4652 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
4654 cb
->cb_color_fmask
= cb
->cb_color_base
;
4657 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4659 vk_format_get_first_non_void_channel(iview
->vk_format
));
4660 format
= radv_translate_colorformat(iview
->vk_format
);
4661 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4662 radv_finishme("Illegal color\n");
4663 swap
= radv_translate_colorswap(iview
->vk_format
, false);
4664 endian
= radv_colorformat_endian_swap(format
);
4666 /* blend clamp should be set for all NORM/SRGB types */
4667 if (ntype
== V_028C70_NUMBER_UNORM
||
4668 ntype
== V_028C70_NUMBER_SNORM
||
4669 ntype
== V_028C70_NUMBER_SRGB
)
4672 /* set blend bypass according to docs if SINT/UINT or
4673 8/24 COLOR variants */
4674 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4675 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4676 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4681 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4682 (format
== V_028C70_COLOR_8
||
4683 format
== V_028C70_COLOR_8_8
||
4684 format
== V_028C70_COLOR_8_8_8_8
))
4685 ->color_is_int8
= true;
4687 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4688 S_028C70_COMP_SWAP(swap
) |
4689 S_028C70_BLEND_CLAMP(blend_clamp
) |
4690 S_028C70_BLEND_BYPASS(blend_bypass
) |
4691 S_028C70_SIMPLE_FLOAT(1) |
4692 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4693 ntype
!= V_028C70_NUMBER_SNORM
&&
4694 ntype
!= V_028C70_NUMBER_SRGB
&&
4695 format
!= V_028C70_COLOR_8_24
&&
4696 format
!= V_028C70_COLOR_24_8
) |
4697 S_028C70_NUMBER_TYPE(ntype
) |
4698 S_028C70_ENDIAN(endian
);
4699 if (radv_image_has_fmask(iview
->image
)) {
4700 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4701 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4702 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
4703 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4706 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
4707 /* Allow the texture block to read FMASK directly
4708 * without decompressing it. This bit must be cleared
4709 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
4710 * otherwise the operation doesn't happen.
4712 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
4714 /* Set CMASK into a tiling format that allows the
4715 * texture block to read it.
4717 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
4721 if (radv_image_has_cmask(iview
->image
) &&
4722 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4723 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4725 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4726 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4728 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4730 /* This must be set for fast clear to work without FMASK. */
4731 if (!radv_image_has_fmask(iview
->image
) &&
4732 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4733 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4734 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4737 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4738 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4740 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4741 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4742 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4743 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4745 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4746 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
4748 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
4749 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
4750 S_028EE0_RESOURCE_LEVEL(1);
4752 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
4753 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4754 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4757 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4758 S_028C68_MIP0_HEIGHT(height
- 1) |
4759 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4764 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4765 struct radv_image_view
*iview
)
4767 unsigned max_zplanes
= 0;
4769 assert(radv_image_is_tc_compat_htile(iview
->image
));
4771 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4772 /* Default value for 32-bit depth surfaces. */
4775 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4776 iview
->image
->info
.samples
> 1)
4779 max_zplanes
= max_zplanes
+ 1;
4781 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4782 /* Do not enable Z plane compression for 16-bit depth
4783 * surfaces because isn't supported on GFX8. Only
4784 * 32-bit depth surfaces are supported by the hardware.
4785 * This allows to maintain shader compatibility and to
4786 * reduce the number of depth decompressions.
4790 if (iview
->image
->info
.samples
<= 1)
4792 else if (iview
->image
->info
.samples
<= 4)
4803 radv_initialise_ds_surface(struct radv_device
*device
,
4804 struct radv_ds_buffer_info
*ds
,
4805 struct radv_image_view
*iview
)
4807 unsigned level
= iview
->base_mip
;
4808 unsigned format
, stencil_format
;
4809 uint64_t va
, s_offs
, z_offs
;
4810 bool stencil_only
= false;
4811 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4812 const struct radeon_surf
*surf
= &plane
->surface
;
4814 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4816 memset(ds
, 0, sizeof(*ds
));
4817 switch (iview
->image
->vk_format
) {
4818 case VK_FORMAT_D24_UNORM_S8_UINT
:
4819 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4820 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4821 ds
->offset_scale
= 2.0f
;
4823 case VK_FORMAT_D16_UNORM
:
4824 case VK_FORMAT_D16_UNORM_S8_UINT
:
4825 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4826 ds
->offset_scale
= 4.0f
;
4828 case VK_FORMAT_D32_SFLOAT
:
4829 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4830 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4831 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4832 ds
->offset_scale
= 1.0f
;
4834 case VK_FORMAT_S8_UINT
:
4835 stencil_only
= true;
4841 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4842 stencil_format
= surf
->has_stencil
?
4843 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4845 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4846 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4847 S_028008_SLICE_MAX(max_slice
);
4848 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4849 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
4850 S_028008_SLICE_MAX_HI(max_slice
>> 11);
4853 ds
->db_htile_data_base
= 0;
4854 ds
->db_htile_surface
= 0;
4856 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4857 s_offs
= z_offs
= va
;
4859 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4860 assert(surf
->u
.gfx9
.surf_offset
== 0);
4861 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4863 ds
->db_z_info
= S_028038_FORMAT(format
) |
4864 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4865 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4866 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4867 S_028038_ZRANGE_PRECISION(1);
4868 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4869 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4871 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4872 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4873 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4876 ds
->db_depth_view
|= S_028008_MIPID(level
);
4877 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4878 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4880 if (radv_htile_enabled(iview
->image
, level
)) {
4881 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4883 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4884 unsigned max_zplanes
=
4885 radv_calc_decompress_on_z_planes(device
, iview
);
4887 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4889 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4890 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
4891 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
4893 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
4894 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4898 if (!surf
->has_stencil
)
4899 /* Use all of the htile_buffer for depth if there's no stencil. */
4900 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4901 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4902 iview
->image
->htile_offset
;
4903 ds
->db_htile_data_base
= va
>> 8;
4904 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4905 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
4907 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4908 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4912 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4915 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4917 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4918 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4920 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4921 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4922 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4924 if (iview
->image
->info
.samples
> 1)
4925 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4927 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4928 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4929 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4930 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4931 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4932 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4933 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4934 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4937 tile_mode
= stencil_tile_mode
;
4939 ds
->db_depth_info
|=
4940 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4941 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4942 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4943 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4944 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4945 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4946 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4947 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4949 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4950 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4951 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4952 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4954 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4957 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4958 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4959 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4961 if (radv_htile_enabled(iview
->image
, level
)) {
4962 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4964 if (!surf
->has_stencil
&&
4965 !radv_image_is_tc_compat_htile(iview
->image
))
4966 /* Use all of the htile_buffer for depth if there's no stencil. */
4967 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4969 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4970 iview
->image
->htile_offset
;
4971 ds
->db_htile_data_base
= va
>> 8;
4972 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4974 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4975 unsigned max_zplanes
=
4976 radv_calc_decompress_on_z_planes(device
, iview
);
4978 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4979 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4984 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4985 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4988 VkResult
radv_CreateFramebuffer(
4990 const VkFramebufferCreateInfo
* pCreateInfo
,
4991 const VkAllocationCallbacks
* pAllocator
,
4992 VkFramebuffer
* pFramebuffer
)
4994 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4995 struct radv_framebuffer
*framebuffer
;
4996 const VkFramebufferAttachmentsCreateInfoKHR
*imageless_create_info
=
4997 vk_find_struct_const(pCreateInfo
->pNext
,
4998 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR
);
5000 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
5002 size_t size
= sizeof(*framebuffer
);
5003 if (!imageless_create_info
)
5004 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
5005 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
5006 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5007 if (framebuffer
== NULL
)
5008 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5010 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
5011 framebuffer
->width
= pCreateInfo
->width
;
5012 framebuffer
->height
= pCreateInfo
->height
;
5013 framebuffer
->layers
= pCreateInfo
->layers
;
5014 if (imageless_create_info
) {
5015 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
5016 const VkFramebufferAttachmentImageInfoKHR
*attachment
=
5017 imageless_create_info
->pAttachmentImageInfos
+ i
;
5018 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
5019 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
5020 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
5023 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
5024 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
5025 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
5026 framebuffer
->attachments
[i
] = iview
;
5027 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
5028 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
5029 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
5033 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
5037 void radv_DestroyFramebuffer(
5040 const VkAllocationCallbacks
* pAllocator
)
5042 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5043 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
5047 vk_free2(&device
->alloc
, pAllocator
, fb
);
5050 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
5052 switch (address_mode
) {
5053 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
5054 return V_008F30_SQ_TEX_WRAP
;
5055 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
5056 return V_008F30_SQ_TEX_MIRROR
;
5057 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
5058 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
5059 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
5060 return V_008F30_SQ_TEX_CLAMP_BORDER
;
5061 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
5062 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
5064 unreachable("illegal tex wrap mode");
5070 radv_tex_compare(VkCompareOp op
)
5073 case VK_COMPARE_OP_NEVER
:
5074 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
5075 case VK_COMPARE_OP_LESS
:
5076 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
5077 case VK_COMPARE_OP_EQUAL
:
5078 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
5079 case VK_COMPARE_OP_LESS_OR_EQUAL
:
5080 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
5081 case VK_COMPARE_OP_GREATER
:
5082 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
5083 case VK_COMPARE_OP_NOT_EQUAL
:
5084 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
5085 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
5086 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
5087 case VK_COMPARE_OP_ALWAYS
:
5088 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
5090 unreachable("illegal compare mode");
5096 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
5099 case VK_FILTER_NEAREST
:
5100 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
5101 V_008F38_SQ_TEX_XY_FILTER_POINT
);
5102 case VK_FILTER_LINEAR
:
5103 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
5104 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
5105 case VK_FILTER_CUBIC_IMG
:
5107 fprintf(stderr
, "illegal texture filter");
5113 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
5116 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
5117 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
5118 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
5119 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
5121 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
5126 radv_tex_bordercolor(VkBorderColor bcolor
)
5129 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
5130 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
5131 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
5132 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
5133 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
5134 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
5135 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
5136 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
5137 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
5145 radv_tex_aniso_filter(unsigned filter
)
5159 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
5162 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
5163 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5164 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
5165 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
5166 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
5167 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
5175 radv_get_max_anisotropy(struct radv_device
*device
,
5176 const VkSamplerCreateInfo
*pCreateInfo
)
5178 if (device
->force_aniso
>= 0)
5179 return device
->force_aniso
;
5181 if (pCreateInfo
->anisotropyEnable
&&
5182 pCreateInfo
->maxAnisotropy
> 1.0f
)
5183 return (uint32_t)pCreateInfo
->maxAnisotropy
;
5189 radv_init_sampler(struct radv_device
*device
,
5190 struct radv_sampler
*sampler
,
5191 const VkSamplerCreateInfo
*pCreateInfo
)
5193 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
5194 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
5195 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
5196 device
->physical_device
->rad_info
.chip_class
== GFX9
;
5197 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5199 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
5200 vk_find_struct_const(pCreateInfo
->pNext
,
5201 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
5202 if (sampler_reduction
)
5203 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
5205 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
5206 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
5207 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
5208 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
5209 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
5210 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
5211 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
5212 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
5213 S_008F30_DISABLE_CUBE_WRAP(0) |
5214 S_008F30_COMPAT_MODE(compat_mode
) |
5215 S_008F30_FILTER_MODE(filter_mode
));
5216 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
5217 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
5218 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
5219 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
5220 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
5221 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
5222 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
5223 S_008F38_MIP_POINT_PRECLAMP(0));
5224 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
5225 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
5227 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5228 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
5230 sampler
->state
[2] |=
5231 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
5232 S_008F38_FILTER_PREC_FIX(1) |
5233 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
5237 VkResult
radv_CreateSampler(
5239 const VkSamplerCreateInfo
* pCreateInfo
,
5240 const VkAllocationCallbacks
* pAllocator
,
5241 VkSampler
* pSampler
)
5243 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5244 struct radv_sampler
*sampler
;
5246 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
5247 vk_find_struct_const(pCreateInfo
->pNext
,
5248 SAMPLER_YCBCR_CONVERSION_INFO
);
5250 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
5252 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
5253 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5255 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5257 radv_init_sampler(device
, sampler
, pCreateInfo
);
5259 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
5260 *pSampler
= radv_sampler_to_handle(sampler
);
5265 void radv_DestroySampler(
5268 const VkAllocationCallbacks
* pAllocator
)
5270 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5271 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
5275 vk_free2(&device
->alloc
, pAllocator
, sampler
);
5278 /* vk_icd.h does not declare this function, so we declare it here to
5279 * suppress Wmissing-prototypes.
5281 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5282 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
5284 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5285 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
5287 /* For the full details on loader interface versioning, see
5288 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
5289 * What follows is a condensed summary, to help you navigate the large and
5290 * confusing official doc.
5292 * - Loader interface v0 is incompatible with later versions. We don't
5295 * - In loader interface v1:
5296 * - The first ICD entrypoint called by the loader is
5297 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
5299 * - The ICD must statically expose no other Vulkan symbol unless it is
5300 * linked with -Bsymbolic.
5301 * - Each dispatchable Vulkan handle created by the ICD must be
5302 * a pointer to a struct whose first member is VK_LOADER_DATA. The
5303 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
5304 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
5305 * vkDestroySurfaceKHR(). The ICD must be capable of working with
5306 * such loader-managed surfaces.
5308 * - Loader interface v2 differs from v1 in:
5309 * - The first ICD entrypoint called by the loader is
5310 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
5311 * statically expose this entrypoint.
5313 * - Loader interface v3 differs from v2 in:
5314 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
5315 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
5316 * because the loader no longer does so.
5318 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
5322 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
5323 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
5326 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5327 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
5329 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
5331 /* At the moment, we support only the below handle types. */
5332 assert(pGetFdInfo
->handleType
==
5333 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5334 pGetFdInfo
->handleType
==
5335 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5337 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
5339 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5343 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
5344 VkExternalMemoryHandleTypeFlagBits handleType
,
5346 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
5348 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5350 switch (handleType
) {
5351 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
5352 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
5356 /* The valid usage section for this function says:
5358 * "handleType must not be one of the handle types defined as
5361 * So opaque handle types fall into the default "unsupported" case.
5363 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5367 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5371 uint32_t syncobj_handle
= 0;
5372 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5374 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5377 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5379 *syncobj
= syncobj_handle
;
5385 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5389 /* If we create a syncobj we do it locally so that if we have an error, we don't
5390 * leave a syncobj in an undetermined state in the fence. */
5391 uint32_t syncobj_handle
= *syncobj
;
5392 if (!syncobj_handle
) {
5393 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5395 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5400 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5402 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5404 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5407 *syncobj
= syncobj_handle
;
5414 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5415 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5417 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5418 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5419 uint32_t *syncobj_dst
= NULL
;
5421 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5422 syncobj_dst
= &sem
->temp_syncobj
;
5424 syncobj_dst
= &sem
->syncobj
;
5427 switch(pImportSemaphoreFdInfo
->handleType
) {
5428 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5429 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5430 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5431 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5433 unreachable("Unhandled semaphore handle type");
5437 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5438 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5441 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5442 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5444 uint32_t syncobj_handle
;
5446 if (sem
->temp_syncobj
)
5447 syncobj_handle
= sem
->temp_syncobj
;
5449 syncobj_handle
= sem
->syncobj
;
5451 switch(pGetFdInfo
->handleType
) {
5452 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5453 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5455 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5456 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5458 if (sem
->temp_syncobj
) {
5459 close (sem
->temp_syncobj
);
5460 sem
->temp_syncobj
= 0;
5462 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5467 unreachable("Unhandled semaphore handle type");
5471 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5475 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5476 VkPhysicalDevice physicalDevice
,
5477 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5478 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5480 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5482 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5483 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5484 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5485 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5486 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5487 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5488 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5489 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5490 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5491 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5492 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5493 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5494 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5496 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5497 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5498 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5502 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5503 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5505 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5506 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5507 uint32_t *syncobj_dst
= NULL
;
5510 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5511 syncobj_dst
= &fence
->temp_syncobj
;
5513 syncobj_dst
= &fence
->syncobj
;
5516 switch(pImportFenceFdInfo
->handleType
) {
5517 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5518 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5519 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5520 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5522 unreachable("Unhandled fence handle type");
5526 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5527 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5530 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5531 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5533 uint32_t syncobj_handle
;
5535 if (fence
->temp_syncobj
)
5536 syncobj_handle
= fence
->temp_syncobj
;
5538 syncobj_handle
= fence
->syncobj
;
5540 switch(pGetFdInfo
->handleType
) {
5541 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5542 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5544 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5545 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5547 if (fence
->temp_syncobj
) {
5548 close (fence
->temp_syncobj
);
5549 fence
->temp_syncobj
= 0;
5551 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5556 unreachable("Unhandled fence handle type");
5560 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5564 void radv_GetPhysicalDeviceExternalFenceProperties(
5565 VkPhysicalDevice physicalDevice
,
5566 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5567 VkExternalFenceProperties
*pExternalFenceProperties
)
5569 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5571 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5572 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5573 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5574 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5575 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5576 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5577 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5579 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5580 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5581 pExternalFenceProperties
->externalFenceFeatures
= 0;
5586 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5587 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5588 const VkAllocationCallbacks
* pAllocator
,
5589 VkDebugReportCallbackEXT
* pCallback
)
5591 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5592 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5593 pCreateInfo
, pAllocator
, &instance
->alloc
,
5598 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5599 VkDebugReportCallbackEXT _callback
,
5600 const VkAllocationCallbacks
* pAllocator
)
5602 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5603 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5604 _callback
, pAllocator
, &instance
->alloc
);
5608 radv_DebugReportMessageEXT(VkInstance _instance
,
5609 VkDebugReportFlagsEXT flags
,
5610 VkDebugReportObjectTypeEXT objectType
,
5613 int32_t messageCode
,
5614 const char* pLayerPrefix
,
5615 const char* pMessage
)
5617 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5618 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5619 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5623 radv_GetDeviceGroupPeerMemoryFeatures(
5626 uint32_t localDeviceIndex
,
5627 uint32_t remoteDeviceIndex
,
5628 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5630 assert(localDeviceIndex
== remoteDeviceIndex
);
5632 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5633 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5634 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5635 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5638 static const VkTimeDomainEXT radv_time_domains
[] = {
5639 VK_TIME_DOMAIN_DEVICE_EXT
,
5640 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5641 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5644 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5645 VkPhysicalDevice physicalDevice
,
5646 uint32_t *pTimeDomainCount
,
5647 VkTimeDomainEXT
*pTimeDomains
)
5650 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5652 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5653 vk_outarray_append(&out
, i
) {
5654 *i
= radv_time_domains
[d
];
5658 return vk_outarray_status(&out
);
5662 radv_clock_gettime(clockid_t clock_id
)
5664 struct timespec current
;
5667 ret
= clock_gettime(clock_id
, ¤t
);
5668 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5669 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5673 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5676 VkResult
radv_GetCalibratedTimestampsEXT(
5678 uint32_t timestampCount
,
5679 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5680 uint64_t *pTimestamps
,
5681 uint64_t *pMaxDeviation
)
5683 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5684 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5686 uint64_t begin
, end
;
5687 uint64_t max_clock_period
= 0;
5689 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5691 for (d
= 0; d
< timestampCount
; d
++) {
5692 switch (pTimestampInfos
[d
].timeDomain
) {
5693 case VK_TIME_DOMAIN_DEVICE_EXT
:
5694 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5696 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5697 max_clock_period
= MAX2(max_clock_period
, device_period
);
5699 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5700 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5701 max_clock_period
= MAX2(max_clock_period
, 1);
5704 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5705 pTimestamps
[d
] = begin
;
5713 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5716 * The maximum deviation is the sum of the interval over which we
5717 * perform the sampling and the maximum period of any sampled
5718 * clock. That's because the maximum skew between any two sampled
5719 * clock edges is when the sampled clock with the largest period is
5720 * sampled at the end of that period but right at the beginning of the
5721 * sampling interval and some other clock is sampled right at the
5722 * begining of its sampling period and right at the end of the
5723 * sampling interval. Let's assume the GPU has the longest clock
5724 * period and that the application is sampling GPU and monotonic:
5727 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5728 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5732 * GPU -----_____-----_____-----_____-----_____
5735 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5736 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5738 * Interval <----------------->
5739 * Deviation <-------------------------->
5743 * m = read(monotonic) 2
5746 * We round the sample interval up by one tick to cover sampling error
5747 * in the interval clock
5750 uint64_t sample_interval
= end
- begin
+ 1;
5752 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5757 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5758 VkPhysicalDevice physicalDevice
,
5759 VkSampleCountFlagBits samples
,
5760 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5762 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5763 VK_SAMPLE_COUNT_4_BIT
|
5764 VK_SAMPLE_COUNT_8_BIT
)) {
5765 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5767 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };