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_device_name(enum radeon_family family
, char *name
, size_t name_len
)
91 const char *chip_string
;
94 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
95 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
96 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
97 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
98 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
99 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
100 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
101 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
102 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
103 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
104 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
105 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
106 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
107 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
108 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
109 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
110 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
111 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
112 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
113 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
114 case CHIP_VEGA20
: chip_string
= "AMD RADV VEGA20"; break;
115 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
116 case CHIP_RAVEN2
: chip_string
= "AMD RADV RAVEN2"; break;
117 case CHIP_NAVI10
: chip_string
= "AMD RADV NAVI10"; break;
118 case CHIP_NAVI12
: chip_string
= "AMD RADV NAVI12"; break;
119 case CHIP_NAVI14
: chip_string
= "AMD RADV NAVI14"; break;
120 default: chip_string
= "AMD RADV unknown"; break;
123 snprintf(name
, name_len
, "%s (LLVM " MESA_LLVM_VERSION_STRING
")", chip_string
);
127 radv_get_visible_vram_size(struct radv_physical_device
*device
)
129 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
133 radv_get_vram_size(struct radv_physical_device
*device
)
135 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
139 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
141 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
142 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
143 uint64_t vram_size
= radv_get_vram_size(device
);
144 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
145 device
->memory_properties
.memoryHeapCount
= 0;
147 vram_index
= device
->memory_properties
.memoryHeapCount
++;
148 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
150 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
153 if (visible_vram_size
) {
154 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
155 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
156 .size
= visible_vram_size
,
157 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
160 if (device
->rad_info
.gart_size
> 0) {
161 gart_index
= device
->memory_properties
.memoryHeapCount
++;
162 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
163 .size
= device
->rad_info
.gart_size
,
164 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
168 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
169 unsigned type_count
= 0;
170 if (vram_index
>= 0) {
171 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
172 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
173 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
174 .heapIndex
= vram_index
,
177 if (gart_index
>= 0 && device
->rad_info
.has_dedicated_vram
) {
178 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
179 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
180 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
181 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
182 .heapIndex
= gart_index
,
185 if (visible_vram_index
>= 0) {
186 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
187 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
188 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
189 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
190 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
191 .heapIndex
= visible_vram_index
,
194 if (gart_index
>= 0 && !device
->rad_info
.has_dedicated_vram
) {
195 /* Put GTT after visible VRAM for GPUs without dedicated VRAM
196 * as they have identical property flags, and according to the
197 * spec, for types with identical flags, the one with greater
198 * performance must be given a lower index. */
199 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
200 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
201 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
202 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
203 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
204 .heapIndex
= gart_index
,
207 if (gart_index
>= 0) {
208 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
209 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
210 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
211 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
212 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
213 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
214 .heapIndex
= gart_index
,
217 device
->memory_properties
.memoryTypeCount
= type_count
;
221 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
223 const char *family
= getenv("RADV_FORCE_FAMILY");
229 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
230 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
231 /* Override family and chip_class. */
232 device
->rad_info
.family
= i
;
234 if (i
>= CHIP_NAVI10
)
235 device
->rad_info
.chip_class
= GFX10
;
236 else if (i
>= CHIP_VEGA10
)
237 device
->rad_info
.chip_class
= GFX9
;
238 else if (i
>= CHIP_TONGA
)
239 device
->rad_info
.chip_class
= GFX8
;
240 else if (i
>= CHIP_BONAIRE
)
241 device
->rad_info
.chip_class
= GFX7
;
243 device
->rad_info
.chip_class
= GFX6
;
249 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
254 radv_physical_device_init(struct radv_physical_device
*device
,
255 struct radv_instance
*instance
,
256 drmDevicePtr drm_device
)
258 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
260 drmVersionPtr version
;
264 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
266 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
267 radv_logi("Could not open device '%s'", path
);
269 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
272 version
= drmGetVersion(fd
);
276 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
277 radv_logi("Could not get the kernel driver version for device '%s'", path
);
279 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
280 "failed to get version %s: %m", path
);
283 if (strcmp(version
->name
, "amdgpu")) {
284 drmFreeVersion(version
);
287 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
288 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
290 return VK_ERROR_INCOMPATIBLE_DRIVER
;
292 drmFreeVersion(version
);
294 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
295 radv_logi("Found compatible device '%s'.", path
);
297 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
298 device
->instance
= instance
;
300 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
301 instance
->perftest_flags
);
303 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
307 if (instance
->enabled_extensions
.KHR_display
) {
308 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
309 if (master_fd
>= 0) {
310 uint32_t accel_working
= 0;
311 struct drm_amdgpu_info request
= {
312 .return_pointer
= (uintptr_t)&accel_working
,
313 .return_size
= sizeof(accel_working
),
314 .query
= AMDGPU_INFO_ACCEL_WORKING
317 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
324 device
->master_fd
= master_fd
;
325 device
->local_fd
= fd
;
326 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
328 radv_handle_env_var_force_family(device
);
330 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
332 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
333 device
->ws
->destroy(device
->ws
);
334 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
335 "cannot generate UUID");
339 /* These flags affect shader compilation. */
340 uint64_t shader_env_flags
=
341 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
342 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
344 /* The gpu id is already embedded in the uuid so we just pass "radv"
345 * when creating the cache.
347 char buf
[VK_UUID_SIZE
* 2 + 1];
348 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
349 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
351 if (device
->rad_info
.chip_class
< GFX8
||
352 device
->rad_info
.chip_class
> GFX9
)
353 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
355 radv_get_driver_uuid(&device
->driver_uuid
);
356 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
358 device
->out_of_order_rast_allowed
= device
->rad_info
.has_out_of_order_rast
&&
359 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
361 device
->dcc_msaa_allowed
=
362 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
364 device
->use_shader_ballot
= device
->rad_info
.chip_class
>= GFX8
&&
365 device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
;
367 device
->use_ngg_streamout
= false;
369 /* Determine the number of threads per wave for all stages. */
370 device
->cs_wave_size
= 64;
371 device
->ps_wave_size
= 64;
372 device
->ge_wave_size
= 64;
374 if (device
->rad_info
.chip_class
>= GFX10
) {
375 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
376 device
->cs_wave_size
= 32;
378 /* For pixel shaders, wave64 is recommanded. */
379 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
380 device
->ps_wave_size
= 32;
382 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
383 device
->ge_wave_size
= 32;
386 radv_physical_device_init_mem_types(device
);
387 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
389 device
->bus_info
= *drm_device
->businfo
.pci
;
391 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
392 ac_print_gpu_info(&device
->rad_info
);
394 /* The WSI is structured as a layer on top of the driver, so this has
395 * to be the last part of initialization (at least until we get other
398 result
= radv_init_wsi(device
);
399 if (result
!= VK_SUCCESS
) {
400 device
->ws
->destroy(device
->ws
);
401 vk_error(instance
, result
);
415 radv_physical_device_finish(struct radv_physical_device
*device
)
417 radv_finish_wsi(device
);
418 device
->ws
->destroy(device
->ws
);
419 disk_cache_destroy(device
->disk_cache
);
420 close(device
->local_fd
);
421 if (device
->master_fd
!= -1)
422 close(device
->master_fd
);
426 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
427 VkSystemAllocationScope allocationScope
)
433 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
434 size_t align
, VkSystemAllocationScope allocationScope
)
436 return realloc(pOriginal
, size
);
440 default_free_func(void *pUserData
, void *pMemory
)
445 static const VkAllocationCallbacks default_alloc
= {
447 .pfnAllocation
= default_alloc_func
,
448 .pfnReallocation
= default_realloc_func
,
449 .pfnFree
= default_free_func
,
452 static const struct debug_control radv_debug_options
[] = {
453 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
454 {"nodcc", RADV_DEBUG_NO_DCC
},
455 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
456 {"nocache", RADV_DEBUG_NO_CACHE
},
457 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
458 {"nohiz", RADV_DEBUG_NO_HIZ
},
459 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
460 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
461 {"allbos", RADV_DEBUG_ALL_BOS
},
462 {"noibs", RADV_DEBUG_NO_IBS
},
463 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
464 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
465 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
466 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
467 {"nosisched", RADV_DEBUG_NO_SISCHED
},
468 {"preoptir", RADV_DEBUG_PREOPTIR
},
469 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
470 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
471 {"info", RADV_DEBUG_INFO
},
472 {"errors", RADV_DEBUG_ERRORS
},
473 {"startup", RADV_DEBUG_STARTUP
},
474 {"checkir", RADV_DEBUG_CHECKIR
},
475 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
476 {"nobinning", RADV_DEBUG_NOBINNING
},
477 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
478 {"nongg", RADV_DEBUG_NO_NGG
},
479 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
480 {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS
},
485 radv_get_debug_option_name(int id
)
487 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
488 return radv_debug_options
[id
].string
;
491 static const struct debug_control radv_perftest_options
[] = {
492 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
493 {"sisched", RADV_PERFTEST_SISCHED
},
494 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
495 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
496 {"bolist", RADV_PERFTEST_BO_LIST
},
497 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
498 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
499 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
500 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
501 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
502 {"dfsm", RADV_PERFTEST_DFSM
},
507 radv_get_perftest_option_name(int id
)
509 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
510 return radv_perftest_options
[id
].string
;
514 radv_handle_per_app_options(struct radv_instance
*instance
,
515 const VkApplicationInfo
*info
)
517 const char *name
= info
? info
->pApplicationName
: NULL
;
522 if (!strcmp(name
, "Talos - Linux - 32bit") ||
523 !strcmp(name
, "Talos - Linux - 64bit")) {
524 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
525 /* Force enable LLVM sisched for Talos because it looks
526 * safe and it gives few more FPS.
528 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
530 } else if (!strcmp(name
, "DOOM_VFR")) {
531 /* Work around a Doom VFR game bug */
532 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
533 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
534 /* Workaround for a WaW hazard when LLVM moves/merges
535 * load/store memory operations.
536 * See https://reviews.llvm.org/D61313
538 if (LLVM_VERSION_MAJOR
< 9)
539 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
540 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
541 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
)) {
542 /* Force enable VK_AMD_shader_ballot because it looks
543 * safe and it gives a nice boost (+20% on Vega 56 at
546 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
551 static int radv_get_instance_extension_index(const char *name
)
553 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
554 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
560 static const char radv_dri_options_xml
[] =
562 DRI_CONF_SECTION_PERFORMANCE
563 DRI_CONF_ADAPTIVE_SYNC("true")
564 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
565 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
569 static void radv_init_dri_options(struct radv_instance
*instance
)
571 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
572 driParseConfigFiles(&instance
->dri_options
,
573 &instance
->available_dri_options
,
575 instance
->engineName
,
576 instance
->engineVersion
);
579 VkResult
radv_CreateInstance(
580 const VkInstanceCreateInfo
* pCreateInfo
,
581 const VkAllocationCallbacks
* pAllocator
,
582 VkInstance
* pInstance
)
584 struct radv_instance
*instance
;
587 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
589 uint32_t client_version
;
590 if (pCreateInfo
->pApplicationInfo
&&
591 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
592 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
594 client_version
= VK_API_VERSION_1_0
;
597 const char *engine_name
= NULL
;
598 uint32_t engine_version
= 0;
599 if (pCreateInfo
->pApplicationInfo
) {
600 engine_name
= pCreateInfo
->pApplicationInfo
->pEngineName
;
601 engine_version
= pCreateInfo
->pApplicationInfo
->engineVersion
;
604 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
605 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
607 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
609 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
612 instance
->alloc
= *pAllocator
;
614 instance
->alloc
= default_alloc
;
616 instance
->apiVersion
= client_version
;
617 instance
->physicalDeviceCount
= -1;
619 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
622 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
623 radv_perftest_options
);
626 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
627 radv_logi("Created an instance");
629 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
630 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
631 int index
= radv_get_instance_extension_index(ext_name
);
633 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
634 vk_free2(&default_alloc
, pAllocator
, instance
);
635 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
638 instance
->enabled_extensions
.extensions
[index
] = true;
641 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
642 if (result
!= VK_SUCCESS
) {
643 vk_free2(&default_alloc
, pAllocator
, instance
);
644 return vk_error(instance
, result
);
647 instance
->engineName
= vk_strdup(&instance
->alloc
, engine_name
,
648 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
649 instance
->engineVersion
= engine_version
;
652 glsl_type_singleton_init_or_ref();
654 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
656 radv_init_dri_options(instance
);
657 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
659 *pInstance
= radv_instance_to_handle(instance
);
664 void radv_DestroyInstance(
665 VkInstance _instance
,
666 const VkAllocationCallbacks
* pAllocator
)
668 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
673 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
674 radv_physical_device_finish(instance
->physicalDevices
+ i
);
677 vk_free(&instance
->alloc
, instance
->engineName
);
679 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
681 glsl_type_singleton_decref();
684 driDestroyOptionCache(&instance
->dri_options
);
685 driDestroyOptionInfo(&instance
->available_dri_options
);
687 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
689 vk_free(&instance
->alloc
, instance
);
693 radv_enumerate_devices(struct radv_instance
*instance
)
695 /* TODO: Check for more devices ? */
696 drmDevicePtr devices
[8];
697 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
700 instance
->physicalDeviceCount
= 0;
702 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
704 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
705 radv_logi("Found %d drm nodes", max_devices
);
708 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
710 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
711 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
712 devices
[i
]->bustype
== DRM_BUS_PCI
&&
713 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
715 result
= radv_physical_device_init(instance
->physicalDevices
+
716 instance
->physicalDeviceCount
,
719 if (result
== VK_SUCCESS
)
720 ++instance
->physicalDeviceCount
;
721 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
725 drmFreeDevices(devices
, max_devices
);
730 VkResult
radv_EnumeratePhysicalDevices(
731 VkInstance _instance
,
732 uint32_t* pPhysicalDeviceCount
,
733 VkPhysicalDevice
* pPhysicalDevices
)
735 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
738 if (instance
->physicalDeviceCount
< 0) {
739 result
= radv_enumerate_devices(instance
);
740 if (result
!= VK_SUCCESS
&&
741 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
745 if (!pPhysicalDevices
) {
746 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
748 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
749 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
750 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
753 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
757 VkResult
radv_EnumeratePhysicalDeviceGroups(
758 VkInstance _instance
,
759 uint32_t* pPhysicalDeviceGroupCount
,
760 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
762 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
765 if (instance
->physicalDeviceCount
< 0) {
766 result
= radv_enumerate_devices(instance
);
767 if (result
!= VK_SUCCESS
&&
768 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
772 if (!pPhysicalDeviceGroupProperties
) {
773 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
775 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
776 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
777 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
778 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
779 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
782 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
786 void radv_GetPhysicalDeviceFeatures(
787 VkPhysicalDevice physicalDevice
,
788 VkPhysicalDeviceFeatures
* pFeatures
)
790 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
791 memset(pFeatures
, 0, sizeof(*pFeatures
));
793 *pFeatures
= (VkPhysicalDeviceFeatures
) {
794 .robustBufferAccess
= true,
795 .fullDrawIndexUint32
= true,
796 .imageCubeArray
= true,
797 .independentBlend
= true,
798 .geometryShader
= true,
799 .tessellationShader
= true,
800 .sampleRateShading
= true,
801 .dualSrcBlend
= true,
803 .multiDrawIndirect
= true,
804 .drawIndirectFirstInstance
= true,
806 .depthBiasClamp
= true,
807 .fillModeNonSolid
= true,
812 .multiViewport
= true,
813 .samplerAnisotropy
= true,
814 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
815 .textureCompressionASTC_LDR
= false,
816 .textureCompressionBC
= true,
817 .occlusionQueryPrecise
= true,
818 .pipelineStatisticsQuery
= true,
819 .vertexPipelineStoresAndAtomics
= true,
820 .fragmentStoresAndAtomics
= true,
821 .shaderTessellationAndGeometryPointSize
= true,
822 .shaderImageGatherExtended
= true,
823 .shaderStorageImageExtendedFormats
= true,
824 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
825 .shaderUniformBufferArrayDynamicIndexing
= true,
826 .shaderSampledImageArrayDynamicIndexing
= true,
827 .shaderStorageBufferArrayDynamicIndexing
= true,
828 .shaderStorageImageArrayDynamicIndexing
= true,
829 .shaderStorageImageReadWithoutFormat
= true,
830 .shaderStorageImageWriteWithoutFormat
= true,
831 .shaderClipDistance
= true,
832 .shaderCullDistance
= true,
833 .shaderFloat64
= true,
835 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
836 .sparseBinding
= true,
837 .variableMultisampleRate
= true,
838 .inheritedQueries
= true,
842 void radv_GetPhysicalDeviceFeatures2(
843 VkPhysicalDevice physicalDevice
,
844 VkPhysicalDeviceFeatures2
*pFeatures
)
846 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
847 vk_foreach_struct(ext
, pFeatures
->pNext
) {
848 switch (ext
->sType
) {
849 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
850 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
851 features
->variablePointersStorageBuffer
= true;
852 features
->variablePointers
= true;
855 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
856 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
857 features
->multiview
= true;
858 features
->multiviewGeometryShader
= true;
859 features
->multiviewTessellationShader
= true;
862 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
863 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
864 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
865 features
->shaderDrawParameters
= true;
868 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
869 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
870 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
871 features
->protectedMemory
= false;
874 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
875 VkPhysicalDevice16BitStorageFeatures
*features
=
876 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
877 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
878 features
->storageBuffer16BitAccess
= enabled
;
879 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
880 features
->storagePushConstant16
= enabled
;
881 features
->storageInputOutput16
= enabled
&& LLVM_VERSION_MAJOR
>= 9;
884 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
885 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
886 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
887 features
->samplerYcbcrConversion
= true;
890 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
891 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
892 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
893 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
894 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
895 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
896 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
897 features
->shaderSampledImageArrayNonUniformIndexing
= true;
898 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
899 features
->shaderStorageImageArrayNonUniformIndexing
= true;
900 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
901 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
902 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
903 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
904 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
905 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
906 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
907 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
908 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
909 features
->descriptorBindingUpdateUnusedWhilePending
= true;
910 features
->descriptorBindingPartiallyBound
= true;
911 features
->descriptorBindingVariableDescriptorCount
= true;
912 features
->runtimeDescriptorArray
= true;
915 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
916 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
917 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
918 features
->conditionalRendering
= true;
919 features
->inheritedConditionalRendering
= false;
922 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
923 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
924 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
925 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
926 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
929 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
930 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
931 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
932 features
->transformFeedback
= true;
933 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
936 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
937 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
938 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
939 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
942 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
943 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
944 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
945 features
->memoryPriority
= VK_TRUE
;
948 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
949 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
950 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
951 features
->bufferDeviceAddress
= true;
952 features
->bufferDeviceAddressCaptureReplay
= false;
953 features
->bufferDeviceAddressMultiDevice
= false;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
957 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
958 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
959 features
->depthClipEnable
= true;
962 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
963 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
964 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
965 features
->hostQueryReset
= true;
968 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
969 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
970 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
971 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
972 features
->storageBuffer8BitAccess
= enabled
;
973 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
974 features
->storagePushConstant8
= enabled
;
977 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
978 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
979 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
980 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
981 features
->shaderInt8
= true;
984 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
985 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
986 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
987 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
988 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
991 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
992 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
993 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
995 features
->inlineUniformBlock
= true;
996 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
999 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1000 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1001 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1002 features
->computeDerivativeGroupQuads
= false;
1003 features
->computeDerivativeGroupLinear
= true;
1006 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1007 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1008 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1009 features
->ycbcrImageArrays
= true;
1012 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1013 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1014 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1015 features
->uniformBufferStandardLayout
= true;
1018 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1019 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1020 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1021 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1024 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1025 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1026 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1027 features
->imagelessFramebuffer
= true;
1030 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1031 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1032 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1033 features
->pipelineExecutableInfo
= true;
1040 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1043 void radv_GetPhysicalDeviceProperties(
1044 VkPhysicalDevice physicalDevice
,
1045 VkPhysicalDeviceProperties
* pProperties
)
1047 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1048 VkSampleCountFlags sample_counts
= 0xf;
1050 /* make sure that the entire descriptor set is addressable with a signed
1051 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1052 * be at most 2 GiB. the combined image & samples object count as one of
1053 * both. This limit is for the pipeline layout, not for the set layout, but
1054 * there is no set limit, so we just set a pipeline limit. I don't think
1055 * any app is going to hit this soon. */
1056 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1057 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1058 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1059 32 /* sampler, largest when combined with image */ +
1060 64 /* sampled image */ +
1061 64 /* storage image */);
1063 VkPhysicalDeviceLimits limits
= {
1064 .maxImageDimension1D
= (1 << 14),
1065 .maxImageDimension2D
= (1 << 14),
1066 .maxImageDimension3D
= (1 << 11),
1067 .maxImageDimensionCube
= (1 << 14),
1068 .maxImageArrayLayers
= (1 << 11),
1069 .maxTexelBufferElements
= 128 * 1024 * 1024,
1070 .maxUniformBufferRange
= UINT32_MAX
,
1071 .maxStorageBufferRange
= UINT32_MAX
,
1072 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1073 .maxMemoryAllocationCount
= UINT32_MAX
,
1074 .maxSamplerAllocationCount
= 64 * 1024,
1075 .bufferImageGranularity
= 64, /* A cache line */
1076 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1077 .maxBoundDescriptorSets
= MAX_SETS
,
1078 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1079 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1080 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1081 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1082 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1083 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1084 .maxPerStageResources
= max_descriptor_set_size
,
1085 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1086 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1087 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1088 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1089 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1090 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1091 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1092 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1093 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1094 .maxVertexInputBindings
= MAX_VBS
,
1095 .maxVertexInputAttributeOffset
= 2047,
1096 .maxVertexInputBindingStride
= 2048,
1097 .maxVertexOutputComponents
= 128,
1098 .maxTessellationGenerationLevel
= 64,
1099 .maxTessellationPatchSize
= 32,
1100 .maxTessellationControlPerVertexInputComponents
= 128,
1101 .maxTessellationControlPerVertexOutputComponents
= 128,
1102 .maxTessellationControlPerPatchOutputComponents
= 120,
1103 .maxTessellationControlTotalOutputComponents
= 4096,
1104 .maxTessellationEvaluationInputComponents
= 128,
1105 .maxTessellationEvaluationOutputComponents
= 128,
1106 .maxGeometryShaderInvocations
= 127,
1107 .maxGeometryInputComponents
= 64,
1108 .maxGeometryOutputComponents
= 128,
1109 .maxGeometryOutputVertices
= 256,
1110 .maxGeometryTotalOutputComponents
= 1024,
1111 .maxFragmentInputComponents
= 128,
1112 .maxFragmentOutputAttachments
= 8,
1113 .maxFragmentDualSrcAttachments
= 1,
1114 .maxFragmentCombinedOutputResources
= 8,
1115 .maxComputeSharedMemorySize
= 32768,
1116 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1117 .maxComputeWorkGroupInvocations
= 2048,
1118 .maxComputeWorkGroupSize
= {
1123 .subPixelPrecisionBits
= 8,
1124 .subTexelPrecisionBits
= 8,
1125 .mipmapPrecisionBits
= 8,
1126 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1127 .maxDrawIndirectCount
= UINT32_MAX
,
1128 .maxSamplerLodBias
= 16,
1129 .maxSamplerAnisotropy
= 16,
1130 .maxViewports
= MAX_VIEWPORTS
,
1131 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1132 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1133 .viewportSubPixelBits
= 8,
1134 .minMemoryMapAlignment
= 4096, /* A page */
1135 .minTexelBufferOffsetAlignment
= 1,
1136 .minUniformBufferOffsetAlignment
= 4,
1137 .minStorageBufferOffsetAlignment
= 4,
1138 .minTexelOffset
= -32,
1139 .maxTexelOffset
= 31,
1140 .minTexelGatherOffset
= -32,
1141 .maxTexelGatherOffset
= 31,
1142 .minInterpolationOffset
= -2,
1143 .maxInterpolationOffset
= 2,
1144 .subPixelInterpolationOffsetBits
= 8,
1145 .maxFramebufferWidth
= (1 << 14),
1146 .maxFramebufferHeight
= (1 << 14),
1147 .maxFramebufferLayers
= (1 << 10),
1148 .framebufferColorSampleCounts
= sample_counts
,
1149 .framebufferDepthSampleCounts
= sample_counts
,
1150 .framebufferStencilSampleCounts
= sample_counts
,
1151 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1152 .maxColorAttachments
= MAX_RTS
,
1153 .sampledImageColorSampleCounts
= sample_counts
,
1154 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1155 .sampledImageDepthSampleCounts
= sample_counts
,
1156 .sampledImageStencilSampleCounts
= sample_counts
,
1157 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1158 .maxSampleMaskWords
= 1,
1159 .timestampComputeAndGraphics
= true,
1160 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1161 .maxClipDistances
= 8,
1162 .maxCullDistances
= 8,
1163 .maxCombinedClipAndCullDistances
= 8,
1164 .discreteQueuePriorities
= 2,
1165 .pointSizeRange
= { 0.0, 8192.0 },
1166 .lineWidthRange
= { 0.0, 7.9921875 },
1167 .pointSizeGranularity
= (1.0 / 8.0),
1168 .lineWidthGranularity
= (1.0 / 128.0),
1169 .strictLines
= false, /* FINISHME */
1170 .standardSampleLocations
= true,
1171 .optimalBufferCopyOffsetAlignment
= 128,
1172 .optimalBufferCopyRowPitchAlignment
= 128,
1173 .nonCoherentAtomSize
= 64,
1176 *pProperties
= (VkPhysicalDeviceProperties
) {
1177 .apiVersion
= radv_physical_device_api_version(pdevice
),
1178 .driverVersion
= vk_get_driver_version(),
1179 .vendorID
= ATI_VENDOR_ID
,
1180 .deviceID
= pdevice
->rad_info
.pci_id
,
1181 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1183 .sparseProperties
= {0},
1186 strcpy(pProperties
->deviceName
, pdevice
->name
);
1187 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1190 void radv_GetPhysicalDeviceProperties2(
1191 VkPhysicalDevice physicalDevice
,
1192 VkPhysicalDeviceProperties2
*pProperties
)
1194 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1195 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1197 vk_foreach_struct(ext
, pProperties
->pNext
) {
1198 switch (ext
->sType
) {
1199 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1200 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1201 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1202 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1205 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1206 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1207 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1208 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1209 properties
->deviceLUIDValid
= false;
1212 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1213 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1214 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1215 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1218 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1219 VkPhysicalDevicePointClippingProperties
*properties
=
1220 (VkPhysicalDevicePointClippingProperties
*)ext
;
1221 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1224 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1225 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1226 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1227 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1230 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1231 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1232 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1233 properties
->minImportedHostPointerAlignment
= 4096;
1236 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1237 VkPhysicalDeviceSubgroupProperties
*properties
=
1238 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1239 properties
->subgroupSize
= 64;
1240 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1241 properties
->supportedOperations
=
1242 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1243 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1244 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1245 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1246 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1247 properties
->supportedOperations
|=
1248 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1249 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1250 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1252 properties
->quadOperationsInAllStages
= true;
1255 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1256 VkPhysicalDeviceMaintenance3Properties
*properties
=
1257 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1258 /* Make sure everything is addressable by a signed 32-bit int, and
1259 * our largest descriptors are 96 bytes. */
1260 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1261 /* Our buffer size fields allow only this much */
1262 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1265 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1266 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1267 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1268 /* GFX6-8 only support single channel min/max filter. */
1269 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1270 properties
->filterMinmaxSingleComponentFormats
= true;
1273 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1274 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1275 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1277 /* Shader engines. */
1278 properties
->shaderEngineCount
=
1279 pdevice
->rad_info
.max_se
;
1280 properties
->shaderArraysPerEngineCount
=
1281 pdevice
->rad_info
.max_sh_per_se
;
1282 properties
->computeUnitsPerShaderArray
=
1283 pdevice
->rad_info
.num_good_cu_per_sh
;
1284 properties
->simdPerComputeUnit
= 4;
1285 properties
->wavefrontsPerSimd
=
1286 pdevice
->rad_info
.family
== CHIP_TONGA
||
1287 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1288 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1289 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1290 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1291 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1292 properties
->wavefrontSize
= 64;
1295 properties
->sgprsPerSimd
=
1296 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1297 properties
->minSgprAllocation
=
1298 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1299 properties
->maxSgprAllocation
=
1300 pdevice
->rad_info
.family
== CHIP_TONGA
||
1301 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1302 properties
->sgprAllocationGranularity
=
1303 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1306 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1307 properties
->minVgprAllocation
= 4;
1308 properties
->maxVgprAllocation
= 256;
1309 properties
->vgprAllocationGranularity
= 4;
1312 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1313 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1314 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1316 properties
->shaderCoreFeatures
= 0;
1317 properties
->activeComputeUnitCount
=
1318 pdevice
->rad_info
.num_good_compute_units
;
1321 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1322 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1323 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1324 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1327 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1328 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1329 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1330 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1331 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1332 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1333 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1334 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1335 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1336 properties
->robustBufferAccessUpdateAfterBind
= false;
1337 properties
->quadDivergentImplicitLod
= false;
1339 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1340 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1341 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1342 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1343 32 /* sampler, largest when combined with image */ +
1344 64 /* sampled image */ +
1345 64 /* storage image */);
1346 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1347 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1348 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1349 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1350 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1351 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1352 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1353 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1354 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1355 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1356 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1357 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1358 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1359 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1360 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1363 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1364 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1365 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1366 properties
->protectedNoFault
= false;
1369 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1370 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1371 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1372 properties
->primitiveOverestimationSize
= 0;
1373 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1374 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1375 properties
->primitiveUnderestimation
= VK_FALSE
;
1376 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1377 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1378 properties
->degenerateLinesRasterized
= VK_FALSE
;
1379 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1380 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1383 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1384 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1385 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1386 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1387 properties
->pciBus
= pdevice
->bus_info
.bus
;
1388 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1389 properties
->pciFunction
= pdevice
->bus_info
.func
;
1392 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1393 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1394 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1396 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1397 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
, "radv");
1398 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1399 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1400 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1402 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1410 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1411 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1412 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1413 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1414 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1415 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1416 properties
->maxTransformFeedbackStreamDataSize
= 512;
1417 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1418 properties
->maxTransformFeedbackBufferDataStride
= 512;
1419 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1420 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1421 properties
->transformFeedbackRasterizationStreamSelect
= false;
1422 properties
->transformFeedbackDraw
= true;
1425 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1426 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1427 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1429 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1430 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1431 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1432 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1433 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1436 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1437 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1438 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1439 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1440 VK_SAMPLE_COUNT_4_BIT
|
1441 VK_SAMPLE_COUNT_8_BIT
;
1442 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1443 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1444 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1445 properties
->sampleLocationSubPixelBits
= 4;
1446 properties
->variableSampleLocations
= VK_FALSE
;
1449 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1450 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1451 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1453 /* We support all of the depth resolve modes */
1454 properties
->supportedDepthResolveModes
=
1455 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1456 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1457 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1458 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1460 /* Average doesn't make sense for stencil so we don't support that */
1461 properties
->supportedStencilResolveModes
=
1462 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1463 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1464 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1466 properties
->independentResolveNone
= VK_TRUE
;
1467 properties
->independentResolve
= VK_TRUE
;
1476 static void radv_get_physical_device_queue_family_properties(
1477 struct radv_physical_device
* pdevice
,
1479 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1481 int num_queue_families
= 1;
1483 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1484 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1485 num_queue_families
++;
1487 if (pQueueFamilyProperties
== NULL
) {
1488 *pCount
= num_queue_families
;
1497 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1498 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1499 VK_QUEUE_COMPUTE_BIT
|
1500 VK_QUEUE_TRANSFER_BIT
|
1501 VK_QUEUE_SPARSE_BINDING_BIT
,
1503 .timestampValidBits
= 64,
1504 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1509 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1510 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1511 if (*pCount
> idx
) {
1512 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1513 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1514 VK_QUEUE_TRANSFER_BIT
|
1515 VK_QUEUE_SPARSE_BINDING_BIT
,
1516 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1517 .timestampValidBits
= 64,
1518 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1526 void radv_GetPhysicalDeviceQueueFamilyProperties(
1527 VkPhysicalDevice physicalDevice
,
1529 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1531 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1532 if (!pQueueFamilyProperties
) {
1533 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1536 VkQueueFamilyProperties
*properties
[] = {
1537 pQueueFamilyProperties
+ 0,
1538 pQueueFamilyProperties
+ 1,
1539 pQueueFamilyProperties
+ 2,
1541 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1542 assert(*pCount
<= 3);
1545 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1546 VkPhysicalDevice physicalDevice
,
1548 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1550 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1551 if (!pQueueFamilyProperties
) {
1552 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1555 VkQueueFamilyProperties
*properties
[] = {
1556 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1557 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1558 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1560 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1561 assert(*pCount
<= 3);
1564 void radv_GetPhysicalDeviceMemoryProperties(
1565 VkPhysicalDevice physicalDevice
,
1566 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1568 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1570 *pMemoryProperties
= physical_device
->memory_properties
;
1574 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1575 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1577 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1578 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1579 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1580 uint64_t vram_size
= radv_get_vram_size(device
);
1581 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1582 uint64_t heap_budget
, heap_usage
;
1584 /* For all memory heaps, the computation of budget is as follow:
1585 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1587 * The Vulkan spec 1.1.97 says that the budget should include any
1588 * currently allocated device memory.
1590 * Note that the application heap usages are not really accurate (eg.
1591 * in presence of shared buffers).
1593 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1594 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1596 switch (device
->mem_type_indices
[i
]) {
1597 case RADV_MEM_TYPE_VRAM
:
1598 heap_usage
= device
->ws
->query_value(device
->ws
,
1599 RADEON_ALLOCATED_VRAM
);
1601 heap_budget
= vram_size
-
1602 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1605 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1606 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1608 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1609 heap_usage
= device
->ws
->query_value(device
->ws
,
1610 RADEON_ALLOCATED_VRAM_VIS
);
1612 heap_budget
= visible_vram_size
-
1613 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1616 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1617 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1619 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1620 heap_usage
= device
->ws
->query_value(device
->ws
,
1621 RADEON_ALLOCATED_GTT
);
1623 heap_budget
= gtt_size
-
1624 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1627 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1628 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1635 /* The heapBudget and heapUsage values must be zero for array elements
1636 * greater than or equal to
1637 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1639 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1640 memoryBudget
->heapBudget
[i
] = 0;
1641 memoryBudget
->heapUsage
[i
] = 0;
1645 void radv_GetPhysicalDeviceMemoryProperties2(
1646 VkPhysicalDevice physicalDevice
,
1647 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1649 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1650 &pMemoryProperties
->memoryProperties
);
1652 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1653 vk_find_struct(pMemoryProperties
->pNext
,
1654 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1656 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1659 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1661 VkExternalMemoryHandleTypeFlagBits handleType
,
1662 const void *pHostPointer
,
1663 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1665 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1669 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1670 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1671 uint32_t memoryTypeBits
= 0;
1672 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1673 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1674 memoryTypeBits
= (1 << i
);
1678 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1682 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1686 static enum radeon_ctx_priority
1687 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1689 /* Default to MEDIUM when a specific global priority isn't requested */
1691 return RADEON_CTX_PRIORITY_MEDIUM
;
1693 switch(pObj
->globalPriority
) {
1694 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1695 return RADEON_CTX_PRIORITY_REALTIME
;
1696 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1697 return RADEON_CTX_PRIORITY_HIGH
;
1698 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1699 return RADEON_CTX_PRIORITY_MEDIUM
;
1700 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1701 return RADEON_CTX_PRIORITY_LOW
;
1703 unreachable("Illegal global priority value");
1704 return RADEON_CTX_PRIORITY_INVALID
;
1709 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1710 uint32_t queue_family_index
, int idx
,
1711 VkDeviceQueueCreateFlags flags
,
1712 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1714 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1715 queue
->device
= device
;
1716 queue
->queue_family_index
= queue_family_index
;
1717 queue
->queue_idx
= idx
;
1718 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1719 queue
->flags
= flags
;
1721 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1723 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1729 radv_queue_finish(struct radv_queue
*queue
)
1732 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1734 if (queue
->initial_full_flush_preamble_cs
)
1735 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1736 if (queue
->initial_preamble_cs
)
1737 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1738 if (queue
->continue_preamble_cs
)
1739 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1740 if (queue
->descriptor_bo
)
1741 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1742 if (queue
->scratch_bo
)
1743 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1744 if (queue
->esgs_ring_bo
)
1745 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1746 if (queue
->gsvs_ring_bo
)
1747 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1748 if (queue
->tess_rings_bo
)
1749 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1751 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
1752 if (queue
->gds_oa_bo
)
1753 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
1754 if (queue
->compute_scratch_bo
)
1755 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1759 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1761 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1762 bo_list
->list
.count
= bo_list
->capacity
= 0;
1763 bo_list
->list
.bos
= NULL
;
1767 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1769 free(bo_list
->list
.bos
);
1770 pthread_mutex_destroy(&bo_list
->mutex
);
1773 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1774 struct radeon_winsys_bo
*bo
)
1776 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1781 if (unlikely(!device
->use_global_bo_list
))
1784 pthread_mutex_lock(&bo_list
->mutex
);
1785 if (bo_list
->list
.count
== bo_list
->capacity
) {
1786 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1787 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1790 pthread_mutex_unlock(&bo_list
->mutex
);
1791 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1794 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1795 bo_list
->capacity
= capacity
;
1798 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1799 pthread_mutex_unlock(&bo_list
->mutex
);
1803 static void radv_bo_list_remove(struct radv_device
*device
,
1804 struct radeon_winsys_bo
*bo
)
1806 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1811 if (unlikely(!device
->use_global_bo_list
))
1814 pthread_mutex_lock(&bo_list
->mutex
);
1815 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1816 if (bo_list
->list
.bos
[i
] == bo
) {
1817 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1818 --bo_list
->list
.count
;
1822 pthread_mutex_unlock(&bo_list
->mutex
);
1826 radv_device_init_gs_info(struct radv_device
*device
)
1828 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1829 device
->physical_device
->rad_info
.family
);
1832 static int radv_get_device_extension_index(const char *name
)
1834 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1835 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1842 radv_get_int_debug_option(const char *name
, int default_value
)
1849 result
= default_value
;
1853 result
= strtol(str
, &endptr
, 0);
1854 if (str
== endptr
) {
1855 /* No digits founs. */
1856 result
= default_value
;
1863 VkResult
radv_CreateDevice(
1864 VkPhysicalDevice physicalDevice
,
1865 const VkDeviceCreateInfo
* pCreateInfo
,
1866 const VkAllocationCallbacks
* pAllocator
,
1869 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1871 struct radv_device
*device
;
1873 bool keep_shader_info
= false;
1875 /* Check enabled features */
1876 if (pCreateInfo
->pEnabledFeatures
) {
1877 VkPhysicalDeviceFeatures supported_features
;
1878 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1879 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1880 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1881 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1882 for (uint32_t i
= 0; i
< num_features
; i
++) {
1883 if (enabled_feature
[i
] && !supported_feature
[i
])
1884 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1888 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1890 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1892 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1894 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1895 device
->instance
= physical_device
->instance
;
1896 device
->physical_device
= physical_device
;
1898 device
->ws
= physical_device
->ws
;
1900 device
->alloc
= *pAllocator
;
1902 device
->alloc
= physical_device
->instance
->alloc
;
1904 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1905 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1906 int index
= radv_get_device_extension_index(ext_name
);
1907 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1908 vk_free(&device
->alloc
, device
);
1909 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1912 device
->enabled_extensions
.extensions
[index
] = true;
1915 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1917 /* With update after bind we can't attach bo's to the command buffer
1918 * from the descriptor set anymore, so we have to use a global BO list.
1920 device
->use_global_bo_list
=
1921 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1922 device
->enabled_extensions
.EXT_descriptor_indexing
||
1923 device
->enabled_extensions
.EXT_buffer_device_address
;
1925 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
1926 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
1928 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1929 list_inithead(&device
->shader_slabs
);
1931 radv_bo_list_init(&device
->bo_list
);
1933 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1934 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1935 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1936 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1937 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1939 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1941 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1942 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1943 if (!device
->queues
[qfi
]) {
1944 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1948 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1950 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1952 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1953 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1954 qfi
, q
, queue_create
->flags
,
1956 if (result
!= VK_SUCCESS
)
1961 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1962 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1964 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
1965 device
->dfsm_allowed
= device
->pbb_allowed
&&
1966 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
1969 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1972 /* The maximum number of scratch waves. Scratch space isn't divided
1973 * evenly between CUs. The number is only a function of the number of CUs.
1974 * We can decrease the constant to decrease the scratch buffer size.
1976 * sctx->scratch_waves must be >= the maximum possible size of
1977 * 1 threadgroup, so that the hw doesn't hang from being unable
1980 * The recommended value is 4 per CU at most. Higher numbers don't
1981 * bring much benefit, but they still occupy chip resources (think
1982 * async compute). I've seen ~2% performance difference between 4 and 32.
1984 uint32_t max_threads_per_block
= 2048;
1985 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1986 max_threads_per_block
/ 64);
1988 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
1989 S_00B800_CS_W32_EN(device
->physical_device
->cs_wave_size
== 32);
1991 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
1992 /* If the KMD allows it (there is a KMD hw register for it),
1993 * allow launching waves out-of-order.
1995 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1998 radv_device_init_gs_info(device
);
2000 device
->tess_offchip_block_dw_size
=
2001 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
2003 if (getenv("RADV_TRACE_FILE")) {
2004 const char *filename
= getenv("RADV_TRACE_FILE");
2006 keep_shader_info
= true;
2008 if (!radv_init_trace(device
))
2011 fprintf(stderr
, "*****************************************************************************\n");
2012 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
2013 fprintf(stderr
, "*****************************************************************************\n");
2015 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
2016 radv_dump_enabled_options(device
, stderr
);
2019 device
->keep_shader_info
= keep_shader_info
;
2021 result
= radv_device_init_meta(device
);
2022 if (result
!= VK_SUCCESS
)
2025 radv_device_init_msaa(device
);
2027 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
2028 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
2030 case RADV_QUEUE_GENERAL
:
2031 /* Since amdgpu version 3.6.0, CONTEXT_CONTROL is emitted by the kernel */
2032 if (device
->physical_device
->rad_info
.drm_minor
< 6) {
2033 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2034 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
2035 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
2038 case RADV_QUEUE_COMPUTE
:
2039 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
2040 radeon_emit(device
->empty_cs
[family
], 0);
2043 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
2046 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
2047 cik_create_gfx_config(device
);
2049 VkPipelineCacheCreateInfo ci
;
2050 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
2053 ci
.pInitialData
= NULL
;
2054 ci
.initialDataSize
= 0;
2056 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
2058 if (result
!= VK_SUCCESS
)
2061 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
2063 device
->force_aniso
=
2064 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
2065 if (device
->force_aniso
>= 0) {
2066 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2067 1 << util_logbase2(device
->force_aniso
));
2070 *pDevice
= radv_device_to_handle(device
);
2074 radv_device_finish_meta(device
);
2076 radv_bo_list_finish(&device
->bo_list
);
2078 if (device
->trace_bo
)
2079 device
->ws
->buffer_destroy(device
->trace_bo
);
2081 if (device
->gfx_init
)
2082 device
->ws
->buffer_destroy(device
->gfx_init
);
2084 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2085 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2086 radv_queue_finish(&device
->queues
[i
][q
]);
2087 if (device
->queue_count
[i
])
2088 vk_free(&device
->alloc
, device
->queues
[i
]);
2091 vk_free(&device
->alloc
, device
);
2095 void radv_DestroyDevice(
2097 const VkAllocationCallbacks
* pAllocator
)
2099 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2104 if (device
->trace_bo
)
2105 device
->ws
->buffer_destroy(device
->trace_bo
);
2107 if (device
->gfx_init
)
2108 device
->ws
->buffer_destroy(device
->gfx_init
);
2110 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2111 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2112 radv_queue_finish(&device
->queues
[i
][q
]);
2113 if (device
->queue_count
[i
])
2114 vk_free(&device
->alloc
, device
->queues
[i
]);
2115 if (device
->empty_cs
[i
])
2116 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2118 radv_device_finish_meta(device
);
2120 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2121 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2123 radv_destroy_shader_slabs(device
);
2125 radv_bo_list_finish(&device
->bo_list
);
2126 vk_free(&device
->alloc
, device
);
2129 VkResult
radv_EnumerateInstanceLayerProperties(
2130 uint32_t* pPropertyCount
,
2131 VkLayerProperties
* pProperties
)
2133 if (pProperties
== NULL
) {
2134 *pPropertyCount
= 0;
2138 /* None supported at this time */
2139 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2142 VkResult
radv_EnumerateDeviceLayerProperties(
2143 VkPhysicalDevice physicalDevice
,
2144 uint32_t* pPropertyCount
,
2145 VkLayerProperties
* pProperties
)
2147 if (pProperties
== NULL
) {
2148 *pPropertyCount
= 0;
2152 /* None supported at this time */
2153 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2156 void radv_GetDeviceQueue2(
2158 const VkDeviceQueueInfo2
* pQueueInfo
,
2161 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2162 struct radv_queue
*queue
;
2164 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2165 if (pQueueInfo
->flags
!= queue
->flags
) {
2166 /* From the Vulkan 1.1.70 spec:
2168 * "The queue returned by vkGetDeviceQueue2 must have the same
2169 * flags value from this structure as that used at device
2170 * creation time in a VkDeviceQueueCreateInfo instance. If no
2171 * matching flags were specified at device creation time then
2172 * pQueue will return VK_NULL_HANDLE."
2174 *pQueue
= VK_NULL_HANDLE
;
2178 *pQueue
= radv_queue_to_handle(queue
);
2181 void radv_GetDeviceQueue(
2183 uint32_t queueFamilyIndex
,
2184 uint32_t queueIndex
,
2187 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2188 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2189 .queueFamilyIndex
= queueFamilyIndex
,
2190 .queueIndex
= queueIndex
2193 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2197 fill_geom_tess_rings(struct radv_queue
*queue
,
2199 bool add_sample_positions
,
2200 uint32_t esgs_ring_size
,
2201 struct radeon_winsys_bo
*esgs_ring_bo
,
2202 uint32_t gsvs_ring_size
,
2203 struct radeon_winsys_bo
*gsvs_ring_bo
,
2204 uint32_t tess_factor_ring_size
,
2205 uint32_t tess_offchip_ring_offset
,
2206 uint32_t tess_offchip_ring_size
,
2207 struct radeon_winsys_bo
*tess_rings_bo
)
2209 uint32_t *desc
= &map
[4];
2212 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2214 /* stride 0, num records - size, add tid, swizzle, elsize4,
2217 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2218 S_008F04_SWIZZLE_ENABLE(true);
2219 desc
[2] = esgs_ring_size
;
2220 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2221 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2222 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2223 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2224 S_008F0C_INDEX_STRIDE(3) |
2225 S_008F0C_ADD_TID_ENABLE(1);
2227 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2228 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2229 S_008F0C_OOB_SELECT(2) |
2230 S_008F0C_RESOURCE_LEVEL(1);
2232 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2233 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2234 S_008F0C_ELEMENT_SIZE(1);
2237 /* GS entry for ES->GS ring */
2238 /* stride 0, num records - size, elsize0,
2241 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
2242 desc
[6] = esgs_ring_size
;
2243 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2244 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2245 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2246 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2248 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2249 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2250 S_008F0C_OOB_SELECT(2) |
2251 S_008F0C_RESOURCE_LEVEL(1);
2253 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2254 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2261 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2263 /* VS entry for GS->VS ring */
2264 /* stride 0, num records - size, elsize0,
2267 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
2268 desc
[2] = gsvs_ring_size
;
2269 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2270 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2271 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2272 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2274 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2275 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2276 S_008F0C_OOB_SELECT(2) |
2277 S_008F0C_RESOURCE_LEVEL(1);
2279 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2280 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2283 /* stride gsvs_itemsize, num records 64
2284 elsize 4, index stride 16 */
2285 /* shader will patch stride and desc[2] */
2287 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
2288 S_008F04_SWIZZLE_ENABLE(1);
2290 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2291 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2292 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2293 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2294 S_008F0C_INDEX_STRIDE(1) |
2295 S_008F0C_ADD_TID_ENABLE(true);
2297 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2298 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2299 S_008F0C_OOB_SELECT(2) |
2300 S_008F0C_RESOURCE_LEVEL(1);
2302 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2303 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2304 S_008F0C_ELEMENT_SIZE(1);
2311 if (tess_rings_bo
) {
2312 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2313 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2316 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
2317 desc
[2] = tess_factor_ring_size
;
2318 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2319 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2320 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2321 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2323 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2324 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2325 S_008F0C_OOB_SELECT(3) |
2326 S_008F0C_RESOURCE_LEVEL(1);
2328 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2329 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2332 desc
[4] = tess_offchip_va
;
2333 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
2334 desc
[6] = tess_offchip_ring_size
;
2335 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2336 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2337 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2338 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2340 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2341 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2342 S_008F0C_OOB_SELECT(3) |
2343 S_008F0C_RESOURCE_LEVEL(1);
2345 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2346 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2352 if (add_sample_positions
) {
2353 /* add sample positions after all rings */
2354 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2356 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2358 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2360 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2365 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2367 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2368 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2369 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2370 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2371 unsigned max_offchip_buffers
;
2372 unsigned offchip_granularity
;
2373 unsigned hs_offchip_param
;
2377 * This must be one less than the maximum number due to a hw limitation.
2378 * Various hardware bugs need thGFX7
2381 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2382 * Gfx7 should limit max_offchip_buffers to 508
2383 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2385 * Follow AMDVLK here.
2387 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2388 max_offchip_buffers_per_se
= 256;
2389 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2390 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2391 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2392 --max_offchip_buffers_per_se
;
2394 max_offchip_buffers
= max_offchip_buffers_per_se
*
2395 device
->physical_device
->rad_info
.max_se
;
2397 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2398 * around by setting 4K granularity.
2400 if (device
->tess_offchip_block_dw_size
== 4096) {
2401 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2402 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2404 assert(device
->tess_offchip_block_dw_size
== 8192);
2405 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2408 switch (device
->physical_device
->rad_info
.chip_class
) {
2410 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2415 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2423 *max_offchip_buffers_p
= max_offchip_buffers
;
2424 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2425 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2426 --max_offchip_buffers
;
2428 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2429 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2432 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2434 return hs_offchip_param
;
2438 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2439 struct radeon_winsys_bo
*esgs_ring_bo
,
2440 uint32_t esgs_ring_size
,
2441 struct radeon_winsys_bo
*gsvs_ring_bo
,
2442 uint32_t gsvs_ring_size
)
2444 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2448 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2451 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2453 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2454 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2455 radeon_emit(cs
, esgs_ring_size
>> 8);
2456 radeon_emit(cs
, gsvs_ring_size
>> 8);
2458 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2459 radeon_emit(cs
, esgs_ring_size
>> 8);
2460 radeon_emit(cs
, gsvs_ring_size
>> 8);
2465 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2466 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2467 struct radeon_winsys_bo
*tess_rings_bo
)
2474 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2476 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2478 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2479 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2480 S_030938_SIZE(tf_ring_size
/ 4));
2481 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2484 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2485 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2486 S_030984_BASE_HI(tf_va
>> 40));
2487 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2488 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2489 S_030944_BASE_HI(tf_va
>> 40));
2491 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2494 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2495 S_008988_SIZE(tf_ring_size
/ 4));
2496 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2498 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2504 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2505 struct radeon_winsys_bo
*compute_scratch_bo
)
2507 uint64_t scratch_va
;
2509 if (!compute_scratch_bo
)
2512 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2514 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2516 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2517 radeon_emit(cs
, scratch_va
);
2518 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2519 S_008F04_SWIZZLE_ENABLE(1));
2523 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2524 struct radeon_cmdbuf
*cs
,
2525 struct radeon_winsys_bo
*descriptor_bo
)
2532 va
= radv_buffer_get_va(descriptor_bo
);
2534 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2536 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2537 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2538 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2539 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2540 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2542 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2543 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2546 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2547 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2548 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2549 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2550 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2552 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2553 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2557 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2558 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2559 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2560 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2561 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2562 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2564 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2565 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2572 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2574 struct radv_device
*device
= queue
->device
;
2576 if (device
->gfx_init
) {
2577 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2579 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2580 radeon_emit(cs
, va
);
2581 radeon_emit(cs
, va
>> 32);
2582 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2584 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2586 struct radv_physical_device
*physical_device
= device
->physical_device
;
2587 si_emit_graphics(physical_device
, cs
);
2592 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2594 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2595 si_emit_compute(physical_device
, cs
);
2599 radv_get_preamble_cs(struct radv_queue
*queue
,
2600 uint32_t scratch_size
,
2601 uint32_t compute_scratch_size
,
2602 uint32_t esgs_ring_size
,
2603 uint32_t gsvs_ring_size
,
2604 bool needs_tess_rings
,
2606 bool needs_sample_positions
,
2607 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2608 struct radeon_cmdbuf
**initial_preamble_cs
,
2609 struct radeon_cmdbuf
**continue_preamble_cs
)
2611 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2612 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2613 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2614 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2615 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2616 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2617 struct radeon_winsys_bo
*gds_bo
= NULL
;
2618 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
2619 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2620 bool add_tess_rings
= false, add_gds
= false, add_sample_positions
= false;
2621 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2622 unsigned max_offchip_buffers
;
2623 unsigned hs_offchip_param
= 0;
2624 unsigned tess_offchip_ring_offset
;
2625 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2626 if (!queue
->has_tess_rings
) {
2627 if (needs_tess_rings
)
2628 add_tess_rings
= true;
2630 if (!queue
->has_gds
) {
2634 if (!queue
->has_sample_positions
) {
2635 if (needs_sample_positions
)
2636 add_sample_positions
= true;
2638 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2639 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2640 &max_offchip_buffers
);
2641 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2642 tess_offchip_ring_size
= max_offchip_buffers
*
2643 queue
->device
->tess_offchip_block_dw_size
* 4;
2645 if (scratch_size
<= queue
->scratch_size
&&
2646 compute_scratch_size
<= queue
->compute_scratch_size
&&
2647 esgs_ring_size
<= queue
->esgs_ring_size
&&
2648 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2649 !add_tess_rings
&& !add_gds
&& !add_sample_positions
&&
2650 queue
->initial_preamble_cs
) {
2651 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2652 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2653 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2654 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2655 *continue_preamble_cs
= NULL
;
2659 if (scratch_size
> queue
->scratch_size
) {
2660 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2665 RADV_BO_PRIORITY_SCRATCH
);
2669 scratch_bo
= queue
->scratch_bo
;
2671 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2672 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2673 compute_scratch_size
,
2677 RADV_BO_PRIORITY_SCRATCH
);
2678 if (!compute_scratch_bo
)
2682 compute_scratch_bo
= queue
->compute_scratch_bo
;
2684 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2685 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2690 RADV_BO_PRIORITY_SCRATCH
);
2694 esgs_ring_bo
= queue
->esgs_ring_bo
;
2695 esgs_ring_size
= queue
->esgs_ring_size
;
2698 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2699 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2704 RADV_BO_PRIORITY_SCRATCH
);
2708 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2709 gsvs_ring_size
= queue
->gsvs_ring_size
;
2712 if (add_tess_rings
) {
2713 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2714 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2718 RADV_BO_PRIORITY_SCRATCH
);
2722 tess_rings_bo
= queue
->tess_rings_bo
;
2726 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
2728 /* 4 streamout GDS counters.
2729 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
2731 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2735 RADV_BO_PRIORITY_SCRATCH
);
2739 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2743 RADV_BO_PRIORITY_SCRATCH
);
2747 gds_bo
= queue
->gds_bo
;
2748 gds_oa_bo
= queue
->gds_oa_bo
;
2751 if (scratch_bo
!= queue
->scratch_bo
||
2752 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2753 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2754 tess_rings_bo
!= queue
->tess_rings_bo
||
2755 add_sample_positions
) {
2757 if (gsvs_ring_bo
|| esgs_ring_bo
||
2758 tess_rings_bo
|| add_sample_positions
) {
2759 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2760 if (add_sample_positions
)
2761 size
+= 128; /* 64+32+16+8 = 120 bytes */
2763 else if (scratch_bo
)
2764 size
= 8; /* 2 dword */
2766 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2770 RADEON_FLAG_CPU_ACCESS
|
2771 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2772 RADEON_FLAG_READ_ONLY
,
2773 RADV_BO_PRIORITY_DESCRIPTOR
);
2777 descriptor_bo
= queue
->descriptor_bo
;
2779 if (descriptor_bo
!= queue
->descriptor_bo
) {
2780 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2783 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2784 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2785 S_008F04_SWIZZLE_ENABLE(1);
2786 map
[0] = scratch_va
;
2790 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2791 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2792 esgs_ring_size
, esgs_ring_bo
,
2793 gsvs_ring_size
, gsvs_ring_bo
,
2794 tess_factor_ring_size
,
2795 tess_offchip_ring_offset
,
2796 tess_offchip_ring_size
,
2799 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2802 for(int i
= 0; i
< 3; ++i
) {
2803 struct radeon_cmdbuf
*cs
= NULL
;
2804 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2805 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2812 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2814 /* Emit initial configuration. */
2815 switch (queue
->queue_family_index
) {
2816 case RADV_QUEUE_GENERAL
:
2817 radv_init_graphics_state(cs
, queue
);
2819 case RADV_QUEUE_COMPUTE
:
2820 radv_init_compute_state(cs
, queue
);
2822 case RADV_QUEUE_TRANSFER
:
2826 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2827 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2828 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2830 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2831 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2834 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2835 gsvs_ring_bo
, gsvs_ring_size
);
2836 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2837 tess_factor_ring_size
, tess_rings_bo
);
2838 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2839 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2842 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
2844 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
2847 si_cs_emit_cache_flush(cs
,
2848 queue
->device
->physical_device
->rad_info
.chip_class
,
2850 queue
->queue_family_index
== RING_COMPUTE
&&
2851 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2852 (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
)) |
2853 RADV_CMD_FLAG_INV_ICACHE
|
2854 RADV_CMD_FLAG_INV_SCACHE
|
2855 RADV_CMD_FLAG_INV_VCACHE
|
2856 RADV_CMD_FLAG_INV_L2
|
2857 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2858 } else if (i
== 1) {
2859 si_cs_emit_cache_flush(cs
,
2860 queue
->device
->physical_device
->rad_info
.chip_class
,
2862 queue
->queue_family_index
== RING_COMPUTE
&&
2863 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2864 RADV_CMD_FLAG_INV_ICACHE
|
2865 RADV_CMD_FLAG_INV_SCACHE
|
2866 RADV_CMD_FLAG_INV_VCACHE
|
2867 RADV_CMD_FLAG_INV_L2
|
2868 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2871 if (!queue
->device
->ws
->cs_finalize(cs
))
2875 if (queue
->initial_full_flush_preamble_cs
)
2876 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2878 if (queue
->initial_preamble_cs
)
2879 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2881 if (queue
->continue_preamble_cs
)
2882 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2884 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2885 queue
->initial_preamble_cs
= dest_cs
[1];
2886 queue
->continue_preamble_cs
= dest_cs
[2];
2888 if (scratch_bo
!= queue
->scratch_bo
) {
2889 if (queue
->scratch_bo
)
2890 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2891 queue
->scratch_bo
= scratch_bo
;
2892 queue
->scratch_size
= scratch_size
;
2895 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2896 if (queue
->compute_scratch_bo
)
2897 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2898 queue
->compute_scratch_bo
= compute_scratch_bo
;
2899 queue
->compute_scratch_size
= compute_scratch_size
;
2902 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2903 if (queue
->esgs_ring_bo
)
2904 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2905 queue
->esgs_ring_bo
= esgs_ring_bo
;
2906 queue
->esgs_ring_size
= esgs_ring_size
;
2909 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2910 if (queue
->gsvs_ring_bo
)
2911 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2912 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2913 queue
->gsvs_ring_size
= gsvs_ring_size
;
2916 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2917 queue
->tess_rings_bo
= tess_rings_bo
;
2918 queue
->has_tess_rings
= true;
2921 if (gds_bo
!= queue
->gds_bo
) {
2922 queue
->gds_bo
= gds_bo
;
2923 queue
->has_gds
= true;
2926 if (gds_oa_bo
!= queue
->gds_oa_bo
)
2927 queue
->gds_oa_bo
= gds_oa_bo
;
2929 if (descriptor_bo
!= queue
->descriptor_bo
) {
2930 if (queue
->descriptor_bo
)
2931 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2933 queue
->descriptor_bo
= descriptor_bo
;
2936 if (add_sample_positions
)
2937 queue
->has_sample_positions
= true;
2939 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2940 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2941 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2942 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2943 *continue_preamble_cs
= NULL
;
2946 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2948 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2949 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2950 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2951 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2952 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2953 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2954 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2955 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2956 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2957 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2958 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2959 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2960 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2961 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
2962 queue
->device
->ws
->buffer_destroy(gds_bo
);
2963 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
2964 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
2966 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2969 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2970 struct radv_winsys_sem_counts
*counts
,
2972 const VkSemaphore
*sems
,
2976 int syncobj_idx
= 0, sem_idx
= 0;
2978 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2981 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2982 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2984 if (sem
->temp_syncobj
|| sem
->syncobj
)
2985 counts
->syncobj_count
++;
2987 counts
->sem_count
++;
2990 if (_fence
!= VK_NULL_HANDLE
) {
2991 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2992 if (fence
->temp_syncobj
|| fence
->syncobj
)
2993 counts
->syncobj_count
++;
2996 if (counts
->syncobj_count
) {
2997 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2998 if (!counts
->syncobj
)
2999 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3002 if (counts
->sem_count
) {
3003 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
3005 free(counts
->syncobj
);
3006 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3010 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3011 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3013 if (sem
->temp_syncobj
) {
3014 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
3016 else if (sem
->syncobj
)
3017 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
3020 counts
->sem
[sem_idx
++] = sem
->sem
;
3024 if (_fence
!= VK_NULL_HANDLE
) {
3025 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3026 if (fence
->temp_syncobj
)
3027 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
3028 else if (fence
->syncobj
)
3029 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
3036 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
3038 free(sem_info
->wait
.syncobj
);
3039 free(sem_info
->wait
.sem
);
3040 free(sem_info
->signal
.syncobj
);
3041 free(sem_info
->signal
.sem
);
3045 static void radv_free_temp_syncobjs(struct radv_device
*device
,
3047 const VkSemaphore
*sems
)
3049 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3050 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
3052 if (sem
->temp_syncobj
) {
3053 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
3054 sem
->temp_syncobj
= 0;
3060 radv_alloc_sem_info(struct radv_instance
*instance
,
3061 struct radv_winsys_sem_info
*sem_info
,
3063 const VkSemaphore
*wait_sems
,
3064 int num_signal_sems
,
3065 const VkSemaphore
*signal_sems
,
3069 memset(sem_info
, 0, sizeof(*sem_info
));
3071 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
3074 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
3076 radv_free_sem_info(sem_info
);
3078 /* caller can override these */
3079 sem_info
->cs_emit_wait
= true;
3080 sem_info
->cs_emit_signal
= true;
3084 /* Signals fence as soon as all the work currently put on queue is done. */
3085 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
3086 struct radv_fence
*fence
)
3090 struct radv_winsys_sem_info sem_info
;
3092 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
3093 radv_fence_to_handle(fence
));
3094 if (result
!= VK_SUCCESS
)
3097 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3098 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3099 1, NULL
, NULL
, &sem_info
, NULL
,
3100 false, fence
->fence
);
3101 radv_free_sem_info(&sem_info
);
3104 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
3109 VkResult
radv_QueueSubmit(
3111 uint32_t submitCount
,
3112 const VkSubmitInfo
* pSubmits
,
3115 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3116 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3117 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3118 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
3120 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
3121 uint32_t scratch_size
= 0;
3122 uint32_t compute_scratch_size
= 0;
3123 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
3124 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
3126 bool fence_emitted
= false;
3127 bool tess_rings_needed
= false;
3128 bool gds_needed
= false;
3129 bool sample_positions_needed
= false;
3131 /* Do this first so failing to allocate scratch buffers can't result in
3132 * partially executed submissions. */
3133 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3134 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3135 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3136 pSubmits
[i
].pCommandBuffers
[j
]);
3138 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
3139 compute_scratch_size
= MAX2(compute_scratch_size
,
3140 cmd_buffer
->compute_scratch_size_needed
);
3141 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
3142 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
3143 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
3144 gds_needed
|= cmd_buffer
->gds_needed
;
3145 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3149 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3150 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3151 gds_needed
, sample_positions_needed
,
3152 &initial_flush_preamble_cs
,
3153 &initial_preamble_cs
, &continue_preamble_cs
);
3154 if (result
!= VK_SUCCESS
)
3157 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3158 struct radeon_cmdbuf
**cs_array
;
3159 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
3160 bool can_patch
= true;
3162 struct radv_winsys_sem_info sem_info
;
3164 result
= radv_alloc_sem_info(queue
->device
->instance
,
3166 pSubmits
[i
].waitSemaphoreCount
,
3167 pSubmits
[i
].pWaitSemaphores
,
3168 pSubmits
[i
].signalSemaphoreCount
,
3169 pSubmits
[i
].pSignalSemaphores
,
3171 if (result
!= VK_SUCCESS
)
3174 if (!pSubmits
[i
].commandBufferCount
) {
3175 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
3176 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3177 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3182 radv_loge("failed to submit CS %d\n", i
);
3185 fence_emitted
= true;
3187 radv_free_sem_info(&sem_info
);
3191 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3192 (pSubmits
[i
].commandBufferCount
));
3194 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3195 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3196 pSubmits
[i
].pCommandBuffers
[j
]);
3197 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3199 cs_array
[j
] = cmd_buffer
->cs
;
3200 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3203 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3206 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3207 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3208 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3210 advance
= MIN2(max_cs_submission
,
3211 pSubmits
[i
].commandBufferCount
- j
);
3213 if (queue
->device
->trace_bo
)
3214 *queue
->device
->trace_id_ptr
= 0;
3216 sem_info
.cs_emit_wait
= j
== 0;
3217 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3219 if (unlikely(queue
->device
->use_global_bo_list
)) {
3220 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3221 bo_list
= &queue
->device
->bo_list
.list
;
3224 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3225 advance
, initial_preamble
, continue_preamble_cs
,
3227 can_patch
, base_fence
);
3229 if (unlikely(queue
->device
->use_global_bo_list
))
3230 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3233 radv_loge("failed to submit CS %d\n", i
);
3236 fence_emitted
= true;
3237 if (queue
->device
->trace_bo
) {
3238 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3242 radv_free_temp_syncobjs(queue
->device
,
3243 pSubmits
[i
].waitSemaphoreCount
,
3244 pSubmits
[i
].pWaitSemaphores
);
3245 radv_free_sem_info(&sem_info
);
3250 if (!fence_emitted
) {
3251 result
= radv_signal_fence(queue
, fence
);
3252 if (result
!= VK_SUCCESS
)
3260 VkResult
radv_QueueWaitIdle(
3263 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3265 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3266 radv_queue_family_to_ring(queue
->queue_family_index
),
3271 VkResult
radv_DeviceWaitIdle(
3274 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3276 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3277 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3278 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3284 VkResult
radv_EnumerateInstanceExtensionProperties(
3285 const char* pLayerName
,
3286 uint32_t* pPropertyCount
,
3287 VkExtensionProperties
* pProperties
)
3289 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3291 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3292 if (radv_supported_instance_extensions
.extensions
[i
]) {
3293 vk_outarray_append(&out
, prop
) {
3294 *prop
= radv_instance_extensions
[i
];
3299 return vk_outarray_status(&out
);
3302 VkResult
radv_EnumerateDeviceExtensionProperties(
3303 VkPhysicalDevice physicalDevice
,
3304 const char* pLayerName
,
3305 uint32_t* pPropertyCount
,
3306 VkExtensionProperties
* pProperties
)
3308 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3309 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3311 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3312 if (device
->supported_extensions
.extensions
[i
]) {
3313 vk_outarray_append(&out
, prop
) {
3314 *prop
= radv_device_extensions
[i
];
3319 return vk_outarray_status(&out
);
3322 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3323 VkInstance _instance
,
3326 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3327 bool unchecked
= instance
? instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
3330 return radv_lookup_entrypoint_unchecked(pName
);
3332 return radv_lookup_entrypoint_checked(pName
,
3333 instance
? instance
->apiVersion
: 0,
3334 instance
? &instance
->enabled_extensions
: NULL
,
3339 /* The loader wants us to expose a second GetInstanceProcAddr function
3340 * to work around certain LD_PRELOAD issues seen in apps.
3343 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3344 VkInstance instance
,
3348 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3349 VkInstance instance
,
3352 return radv_GetInstanceProcAddr(instance
, pName
);
3356 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3357 VkInstance _instance
,
3361 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3362 VkInstance _instance
,
3365 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3367 return radv_lookup_physical_device_entrypoint_checked(pName
,
3368 instance
? instance
->apiVersion
: 0,
3369 instance
? &instance
->enabled_extensions
: NULL
);
3372 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3376 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3377 bool unchecked
= device
? device
->instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
3380 return radv_lookup_entrypoint_unchecked(pName
);
3382 return radv_lookup_entrypoint_checked(pName
,
3383 device
->instance
->apiVersion
,
3384 &device
->instance
->enabled_extensions
,
3385 &device
->enabled_extensions
);
3389 bool radv_get_memory_fd(struct radv_device
*device
,
3390 struct radv_device_memory
*memory
,
3393 struct radeon_bo_metadata metadata
;
3395 if (memory
->image
) {
3396 radv_init_metadata(device
, memory
->image
, &metadata
);
3397 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3400 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3404 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3405 const VkMemoryAllocateInfo
* pAllocateInfo
,
3406 const VkAllocationCallbacks
* pAllocator
,
3407 VkDeviceMemory
* pMem
)
3409 struct radv_device_memory
*mem
;
3411 enum radeon_bo_domain domain
;
3413 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3415 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3417 if (pAllocateInfo
->allocationSize
== 0) {
3418 /* Apparently, this is allowed */
3419 *pMem
= VK_NULL_HANDLE
;
3423 const VkImportMemoryFdInfoKHR
*import_info
=
3424 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3425 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3426 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3427 const VkExportMemoryAllocateInfo
*export_info
=
3428 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3429 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3430 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3432 const struct wsi_memory_allocate_info
*wsi_info
=
3433 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3435 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3436 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3438 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3440 if (wsi_info
&& wsi_info
->implicit_sync
)
3441 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3443 if (dedicate_info
) {
3444 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3445 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3451 float priority_float
= 0.5;
3452 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3453 vk_find_struct_const(pAllocateInfo
->pNext
,
3454 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3456 priority_float
= priority_ext
->priority
;
3458 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3459 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3461 mem
->user_ptr
= NULL
;
3464 assert(import_info
->handleType
==
3465 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3466 import_info
->handleType
==
3467 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3468 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3469 priority
, NULL
, NULL
);
3471 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3474 close(import_info
->fd
);
3476 } else if (host_ptr_info
) {
3477 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3478 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3479 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3480 pAllocateInfo
->allocationSize
,
3483 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3486 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3489 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3490 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3491 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3492 domain
= RADEON_DOMAIN_GTT
;
3494 domain
= RADEON_DOMAIN_VRAM
;
3496 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3497 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3499 flags
|= RADEON_FLAG_CPU_ACCESS
;
3501 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3502 flags
|= RADEON_FLAG_GTT_WC
;
3504 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3505 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3506 if (device
->use_global_bo_list
) {
3507 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3511 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3512 domain
, flags
, priority
);
3515 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3518 mem
->type_index
= mem_type_index
;
3521 result
= radv_bo_list_add(device
, mem
->bo
);
3522 if (result
!= VK_SUCCESS
)
3525 *pMem
= radv_device_memory_to_handle(mem
);
3530 device
->ws
->buffer_destroy(mem
->bo
);
3532 vk_free2(&device
->alloc
, pAllocator
, mem
);
3537 VkResult
radv_AllocateMemory(
3539 const VkMemoryAllocateInfo
* pAllocateInfo
,
3540 const VkAllocationCallbacks
* pAllocator
,
3541 VkDeviceMemory
* pMem
)
3543 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3544 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3547 void radv_FreeMemory(
3549 VkDeviceMemory _mem
,
3550 const VkAllocationCallbacks
* pAllocator
)
3552 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3553 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3558 radv_bo_list_remove(device
, mem
->bo
);
3559 device
->ws
->buffer_destroy(mem
->bo
);
3562 vk_free2(&device
->alloc
, pAllocator
, mem
);
3565 VkResult
radv_MapMemory(
3567 VkDeviceMemory _memory
,
3568 VkDeviceSize offset
,
3570 VkMemoryMapFlags flags
,
3573 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3574 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3582 *ppData
= mem
->user_ptr
;
3584 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3591 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3594 void radv_UnmapMemory(
3596 VkDeviceMemory _memory
)
3598 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3599 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3604 if (mem
->user_ptr
== NULL
)
3605 device
->ws
->buffer_unmap(mem
->bo
);
3608 VkResult
radv_FlushMappedMemoryRanges(
3610 uint32_t memoryRangeCount
,
3611 const VkMappedMemoryRange
* pMemoryRanges
)
3616 VkResult
radv_InvalidateMappedMemoryRanges(
3618 uint32_t memoryRangeCount
,
3619 const VkMappedMemoryRange
* pMemoryRanges
)
3624 void radv_GetBufferMemoryRequirements(
3627 VkMemoryRequirements
* pMemoryRequirements
)
3629 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3630 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3632 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3634 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3635 pMemoryRequirements
->alignment
= 4096;
3637 pMemoryRequirements
->alignment
= 16;
3639 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3642 void radv_GetBufferMemoryRequirements2(
3644 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3645 VkMemoryRequirements2
*pMemoryRequirements
)
3647 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3648 &pMemoryRequirements
->memoryRequirements
);
3649 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3650 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3651 switch (ext
->sType
) {
3652 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3653 VkMemoryDedicatedRequirements
*req
=
3654 (VkMemoryDedicatedRequirements
*) ext
;
3655 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3656 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3665 void radv_GetImageMemoryRequirements(
3668 VkMemoryRequirements
* pMemoryRequirements
)
3670 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3671 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3673 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3675 pMemoryRequirements
->size
= image
->size
;
3676 pMemoryRequirements
->alignment
= image
->alignment
;
3679 void radv_GetImageMemoryRequirements2(
3681 const VkImageMemoryRequirementsInfo2
*pInfo
,
3682 VkMemoryRequirements2
*pMemoryRequirements
)
3684 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3685 &pMemoryRequirements
->memoryRequirements
);
3687 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3689 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3690 switch (ext
->sType
) {
3691 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3692 VkMemoryDedicatedRequirements
*req
=
3693 (VkMemoryDedicatedRequirements
*) ext
;
3694 req
->requiresDedicatedAllocation
= image
->shareable
;
3695 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3704 void radv_GetImageSparseMemoryRequirements(
3707 uint32_t* pSparseMemoryRequirementCount
,
3708 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3713 void radv_GetImageSparseMemoryRequirements2(
3715 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3716 uint32_t* pSparseMemoryRequirementCount
,
3717 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3722 void radv_GetDeviceMemoryCommitment(
3724 VkDeviceMemory memory
,
3725 VkDeviceSize
* pCommittedMemoryInBytes
)
3727 *pCommittedMemoryInBytes
= 0;
3730 VkResult
radv_BindBufferMemory2(VkDevice device
,
3731 uint32_t bindInfoCount
,
3732 const VkBindBufferMemoryInfo
*pBindInfos
)
3734 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3735 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3736 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3739 buffer
->bo
= mem
->bo
;
3740 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3748 VkResult
radv_BindBufferMemory(
3751 VkDeviceMemory memory
,
3752 VkDeviceSize memoryOffset
)
3754 const VkBindBufferMemoryInfo info
= {
3755 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3758 .memoryOffset
= memoryOffset
3761 return radv_BindBufferMemory2(device
, 1, &info
);
3764 VkResult
radv_BindImageMemory2(VkDevice device
,
3765 uint32_t bindInfoCount
,
3766 const VkBindImageMemoryInfo
*pBindInfos
)
3768 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3769 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3770 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3773 image
->bo
= mem
->bo
;
3774 image
->offset
= pBindInfos
[i
].memoryOffset
;
3784 VkResult
radv_BindImageMemory(
3787 VkDeviceMemory memory
,
3788 VkDeviceSize memoryOffset
)
3790 const VkBindImageMemoryInfo info
= {
3791 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3794 .memoryOffset
= memoryOffset
3797 return radv_BindImageMemory2(device
, 1, &info
);
3802 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3803 const VkSparseBufferMemoryBindInfo
*bind
)
3805 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3807 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3808 struct radv_device_memory
*mem
= NULL
;
3810 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3811 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3813 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3814 bind
->pBinds
[i
].resourceOffset
,
3815 bind
->pBinds
[i
].size
,
3816 mem
? mem
->bo
: NULL
,
3817 bind
->pBinds
[i
].memoryOffset
);
3822 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3823 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3825 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3827 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3828 struct radv_device_memory
*mem
= NULL
;
3830 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3831 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3833 device
->ws
->buffer_virtual_bind(image
->bo
,
3834 bind
->pBinds
[i
].resourceOffset
,
3835 bind
->pBinds
[i
].size
,
3836 mem
? mem
->bo
: NULL
,
3837 bind
->pBinds
[i
].memoryOffset
);
3841 VkResult
radv_QueueBindSparse(
3843 uint32_t bindInfoCount
,
3844 const VkBindSparseInfo
* pBindInfo
,
3847 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3848 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3849 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3850 bool fence_emitted
= false;
3854 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3855 struct radv_winsys_sem_info sem_info
;
3856 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3857 radv_sparse_buffer_bind_memory(queue
->device
,
3858 pBindInfo
[i
].pBufferBinds
+ j
);
3861 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3862 radv_sparse_image_opaque_bind_memory(queue
->device
,
3863 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3867 result
= radv_alloc_sem_info(queue
->device
->instance
,
3869 pBindInfo
[i
].waitSemaphoreCount
,
3870 pBindInfo
[i
].pWaitSemaphores
,
3871 pBindInfo
[i
].signalSemaphoreCount
,
3872 pBindInfo
[i
].pSignalSemaphores
,
3874 if (result
!= VK_SUCCESS
)
3877 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3878 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3879 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3884 radv_loge("failed to submit CS %d\n", i
);
3888 fence_emitted
= true;
3891 radv_free_sem_info(&sem_info
);
3896 if (!fence_emitted
) {
3897 result
= radv_signal_fence(queue
, fence
);
3898 if (result
!= VK_SUCCESS
)
3906 VkResult
radv_CreateFence(
3908 const VkFenceCreateInfo
* pCreateInfo
,
3909 const VkAllocationCallbacks
* pAllocator
,
3912 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3913 const VkExportFenceCreateInfo
*export
=
3914 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3915 VkExternalFenceHandleTypeFlags handleTypes
=
3916 export
? export
->handleTypes
: 0;
3918 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3920 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3923 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3925 fence
->fence_wsi
= NULL
;
3926 fence
->temp_syncobj
= 0;
3927 if (device
->always_use_syncobj
|| handleTypes
) {
3928 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3930 vk_free2(&device
->alloc
, pAllocator
, fence
);
3931 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3933 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3934 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3936 fence
->fence
= NULL
;
3938 fence
->fence
= device
->ws
->create_fence();
3939 if (!fence
->fence
) {
3940 vk_free2(&device
->alloc
, pAllocator
, fence
);
3941 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3944 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3945 device
->ws
->signal_fence(fence
->fence
);
3948 *pFence
= radv_fence_to_handle(fence
);
3953 void radv_DestroyFence(
3956 const VkAllocationCallbacks
* pAllocator
)
3958 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3959 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3964 if (fence
->temp_syncobj
)
3965 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3967 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3969 device
->ws
->destroy_fence(fence
->fence
);
3970 if (fence
->fence_wsi
)
3971 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3972 vk_free2(&device
->alloc
, pAllocator
, fence
);
3976 uint64_t radv_get_current_time(void)
3979 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3980 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3983 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3985 uint64_t current_time
= radv_get_current_time();
3987 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3989 return current_time
+ timeout
;
3993 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
3994 uint32_t fenceCount
, const VkFence
*pFences
)
3996 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3997 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3998 if (fence
->fence
== NULL
|| fence
->syncobj
||
3999 fence
->temp_syncobj
|| fence
->fence_wsi
||
4000 (!device
->ws
->is_fence_waitable(fence
->fence
)))
4006 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
4008 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4009 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4010 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
4016 VkResult
radv_WaitForFences(
4018 uint32_t fenceCount
,
4019 const VkFence
* pFences
,
4023 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4024 timeout
= radv_get_absolute_timeout(timeout
);
4026 if (device
->always_use_syncobj
&&
4027 radv_all_fences_syncobj(fenceCount
, pFences
))
4029 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
4031 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4033 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4034 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4035 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
4038 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
4041 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4044 if (!waitAll
&& fenceCount
> 1) {
4045 /* Not doing this by default for waitAll, due to needing to allocate twice. */
4046 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
4047 uint32_t wait_count
= 0;
4048 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
4050 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4052 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4053 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4055 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
4060 fences
[wait_count
++] = fence
->fence
;
4063 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
4064 waitAll
, timeout
- radv_get_current_time());
4067 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4070 while(radv_get_current_time() <= timeout
) {
4071 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4072 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
4079 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4080 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4081 bool expired
= false;
4083 if (fence
->temp_syncobj
) {
4084 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
4089 if (fence
->syncobj
) {
4090 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
4096 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
4097 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
4098 radv_get_current_time() <= timeout
)
4102 expired
= device
->ws
->fence_wait(device
->ws
,
4109 if (fence
->fence_wsi
) {
4110 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
4111 if (result
!= VK_SUCCESS
)
4119 VkResult
radv_ResetFences(VkDevice _device
,
4120 uint32_t fenceCount
,
4121 const VkFence
*pFences
)
4123 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4125 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
4126 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4128 device
->ws
->reset_fence(fence
->fence
);
4130 /* Per spec, we first restore the permanent payload, and then reset, so
4131 * having a temp syncobj should not skip resetting the permanent syncobj. */
4132 if (fence
->temp_syncobj
) {
4133 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4134 fence
->temp_syncobj
= 0;
4137 if (fence
->syncobj
) {
4138 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
4145 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
4147 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4148 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4150 if (fence
->temp_syncobj
) {
4151 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
4152 return success
? VK_SUCCESS
: VK_NOT_READY
;
4155 if (fence
->syncobj
) {
4156 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
4157 return success
? VK_SUCCESS
: VK_NOT_READY
;
4161 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
4162 return VK_NOT_READY
;
4164 if (fence
->fence_wsi
) {
4165 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
4167 if (result
!= VK_SUCCESS
) {
4168 if (result
== VK_TIMEOUT
)
4169 return VK_NOT_READY
;
4177 // Queue semaphore functions
4179 VkResult
radv_CreateSemaphore(
4181 const VkSemaphoreCreateInfo
* pCreateInfo
,
4182 const VkAllocationCallbacks
* pAllocator
,
4183 VkSemaphore
* pSemaphore
)
4185 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4186 const VkExportSemaphoreCreateInfo
*export
=
4187 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
4188 VkExternalSemaphoreHandleTypeFlags handleTypes
=
4189 export
? export
->handleTypes
: 0;
4191 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
4193 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4195 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4197 sem
->temp_syncobj
= 0;
4198 /* create a syncobject if we are going to export this semaphore */
4199 if (device
->always_use_syncobj
|| handleTypes
) {
4200 assert (device
->physical_device
->rad_info
.has_syncobj
);
4201 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4203 vk_free2(&device
->alloc
, pAllocator
, sem
);
4204 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4208 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4210 vk_free2(&device
->alloc
, pAllocator
, sem
);
4211 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4216 *pSemaphore
= radv_semaphore_to_handle(sem
);
4220 void radv_DestroySemaphore(
4222 VkSemaphore _semaphore
,
4223 const VkAllocationCallbacks
* pAllocator
)
4225 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4226 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4231 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4233 device
->ws
->destroy_sem(sem
->sem
);
4234 vk_free2(&device
->alloc
, pAllocator
, sem
);
4237 VkResult
radv_CreateEvent(
4239 const VkEventCreateInfo
* pCreateInfo
,
4240 const VkAllocationCallbacks
* pAllocator
,
4243 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4244 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4246 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4249 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4251 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4253 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4254 RADV_BO_PRIORITY_FENCE
);
4256 vk_free2(&device
->alloc
, pAllocator
, event
);
4257 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4260 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4262 *pEvent
= radv_event_to_handle(event
);
4267 void radv_DestroyEvent(
4270 const VkAllocationCallbacks
* pAllocator
)
4272 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4273 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4277 device
->ws
->buffer_destroy(event
->bo
);
4278 vk_free2(&device
->alloc
, pAllocator
, event
);
4281 VkResult
radv_GetEventStatus(
4285 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4287 if (*event
->map
== 1)
4288 return VK_EVENT_SET
;
4289 return VK_EVENT_RESET
;
4292 VkResult
radv_SetEvent(
4296 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4302 VkResult
radv_ResetEvent(
4306 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4312 VkResult
radv_CreateBuffer(
4314 const VkBufferCreateInfo
* pCreateInfo
,
4315 const VkAllocationCallbacks
* pAllocator
,
4318 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4319 struct radv_buffer
*buffer
;
4321 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4323 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4324 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4326 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4328 buffer
->size
= pCreateInfo
->size
;
4329 buffer
->usage
= pCreateInfo
->usage
;
4332 buffer
->flags
= pCreateInfo
->flags
;
4334 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4335 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4337 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4338 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4339 align64(buffer
->size
, 4096),
4340 4096, 0, RADEON_FLAG_VIRTUAL
,
4341 RADV_BO_PRIORITY_VIRTUAL
);
4343 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4344 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4348 *pBuffer
= radv_buffer_to_handle(buffer
);
4353 void radv_DestroyBuffer(
4356 const VkAllocationCallbacks
* pAllocator
)
4358 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4359 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4364 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4365 device
->ws
->buffer_destroy(buffer
->bo
);
4367 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4370 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4372 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4374 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4375 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4379 static inline unsigned
4380 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4383 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4385 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4388 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4390 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4394 radv_init_dcc_control_reg(struct radv_device
*device
,
4395 struct radv_image_view
*iview
)
4397 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4398 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4399 unsigned max_compressed_block_size
;
4400 unsigned independent_128b_blocks
;
4401 unsigned independent_64b_blocks
;
4403 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4406 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4407 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4408 * dGPU and 64 for APU because all of our APUs to date use
4409 * DIMMs which have a request granularity size of 64B while all
4410 * other chips have a 32B request size.
4412 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4415 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4416 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4417 independent_64b_blocks
= 0;
4418 independent_128b_blocks
= 1;
4420 independent_128b_blocks
= 0;
4422 if (iview
->image
->info
.samples
> 1) {
4423 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4424 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4425 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4426 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4429 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4430 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4431 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4432 /* If this DCC image is potentially going to be used in texture
4433 * fetches, we need some special settings.
4435 independent_64b_blocks
= 1;
4436 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4438 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4439 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4440 * big as possible for better compression state.
4442 independent_64b_blocks
= 0;
4443 max_compressed_block_size
= max_uncompressed_block_size
;
4447 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4448 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4449 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4450 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
4451 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
4455 radv_initialise_color_surface(struct radv_device
*device
,
4456 struct radv_color_buffer_info
*cb
,
4457 struct radv_image_view
*iview
)
4459 const struct vk_format_description
*desc
;
4460 unsigned ntype
, format
, swap
, endian
;
4461 unsigned blend_clamp
= 0, blend_bypass
= 0;
4463 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4464 const struct radeon_surf
*surf
= &plane
->surface
;
4466 desc
= vk_format_description(iview
->vk_format
);
4468 memset(cb
, 0, sizeof(*cb
));
4470 /* Intensity is implemented as Red, so treat it that way. */
4471 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4473 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4475 cb
->cb_color_base
= va
>> 8;
4477 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4478 struct gfx9_surf_meta_flags meta
;
4479 if (iview
->image
->dcc_offset
)
4480 meta
= surf
->u
.gfx9
.dcc
;
4482 meta
= surf
->u
.gfx9
.cmask
;
4484 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4485 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4486 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4487 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
4488 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
4490 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4491 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4492 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4493 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4494 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4497 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4498 cb
->cb_color_base
|= surf
->tile_swizzle
;
4500 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4501 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4503 cb
->cb_color_base
+= level_info
->offset
>> 8;
4504 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4505 cb
->cb_color_base
|= surf
->tile_swizzle
;
4507 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4508 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4509 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4511 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4512 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4513 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
4515 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4517 if (radv_image_has_fmask(iview
->image
)) {
4518 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4519 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
4520 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
4521 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
4523 /* This must be set for fast clear to work without FMASK. */
4524 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4525 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4526 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4527 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4531 /* CMASK variables */
4532 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4533 va
+= iview
->image
->cmask_offset
;
4534 cb
->cb_color_cmask
= va
>> 8;
4536 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4537 va
+= iview
->image
->dcc_offset
;
4539 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
4540 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
4541 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
4543 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
4544 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
4546 cb
->cb_dcc_base
= va
>> 8;
4547 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
4549 /* GFX10 field has the same base shift as the GFX6 field. */
4550 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4551 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4552 S_028C6C_SLICE_MAX_GFX10(max_slice
);
4554 if (iview
->image
->info
.samples
> 1) {
4555 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4557 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4558 S_028C74_NUM_FRAGMENTS(log_samples
);
4561 if (radv_image_has_fmask(iview
->image
)) {
4562 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
4563 cb
->cb_color_fmask
= va
>> 8;
4564 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
4566 cb
->cb_color_fmask
= cb
->cb_color_base
;
4569 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4571 vk_format_get_first_non_void_channel(iview
->vk_format
));
4572 format
= radv_translate_colorformat(iview
->vk_format
);
4573 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4574 radv_finishme("Illegal color\n");
4575 swap
= radv_translate_colorswap(iview
->vk_format
, false);
4576 endian
= radv_colorformat_endian_swap(format
);
4578 /* blend clamp should be set for all NORM/SRGB types */
4579 if (ntype
== V_028C70_NUMBER_UNORM
||
4580 ntype
== V_028C70_NUMBER_SNORM
||
4581 ntype
== V_028C70_NUMBER_SRGB
)
4584 /* set blend bypass according to docs if SINT/UINT or
4585 8/24 COLOR variants */
4586 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4587 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4588 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4593 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4594 (format
== V_028C70_COLOR_8
||
4595 format
== V_028C70_COLOR_8_8
||
4596 format
== V_028C70_COLOR_8_8_8_8
))
4597 ->color_is_int8
= true;
4599 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4600 S_028C70_COMP_SWAP(swap
) |
4601 S_028C70_BLEND_CLAMP(blend_clamp
) |
4602 S_028C70_BLEND_BYPASS(blend_bypass
) |
4603 S_028C70_SIMPLE_FLOAT(1) |
4604 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4605 ntype
!= V_028C70_NUMBER_SNORM
&&
4606 ntype
!= V_028C70_NUMBER_SRGB
&&
4607 format
!= V_028C70_COLOR_8_24
&&
4608 format
!= V_028C70_COLOR_24_8
) |
4609 S_028C70_NUMBER_TYPE(ntype
) |
4610 S_028C70_ENDIAN(endian
);
4611 if (radv_image_has_fmask(iview
->image
)) {
4612 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4613 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4614 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
4615 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4618 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
4619 /* Allow the texture block to read FMASK directly
4620 * without decompressing it. This bit must be cleared
4621 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
4622 * otherwise the operation doesn't happen.
4624 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
4626 /* Set CMASK into a tiling format that allows the
4627 * texture block to read it.
4629 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
4633 if (radv_image_has_cmask(iview
->image
) &&
4634 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4635 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4637 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4638 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4640 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4642 /* This must be set for fast clear to work without FMASK. */
4643 if (!radv_image_has_fmask(iview
->image
) &&
4644 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4645 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4646 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4649 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4650 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4652 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4653 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4654 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4655 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4657 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4658 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
4660 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
4661 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
4662 S_028EE0_RESOURCE_LEVEL(1);
4664 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
4665 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4666 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4669 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4670 S_028C68_MIP0_HEIGHT(height
- 1) |
4671 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4676 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4677 struct radv_image_view
*iview
)
4679 unsigned max_zplanes
= 0;
4681 assert(radv_image_is_tc_compat_htile(iview
->image
));
4683 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4684 /* Default value for 32-bit depth surfaces. */
4687 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4688 iview
->image
->info
.samples
> 1)
4691 max_zplanes
= max_zplanes
+ 1;
4693 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4694 /* Do not enable Z plane compression for 16-bit depth
4695 * surfaces because isn't supported on GFX8. Only
4696 * 32-bit depth surfaces are supported by the hardware.
4697 * This allows to maintain shader compatibility and to
4698 * reduce the number of depth decompressions.
4702 if (iview
->image
->info
.samples
<= 1)
4704 else if (iview
->image
->info
.samples
<= 4)
4715 radv_initialise_ds_surface(struct radv_device
*device
,
4716 struct radv_ds_buffer_info
*ds
,
4717 struct radv_image_view
*iview
)
4719 unsigned level
= iview
->base_mip
;
4720 unsigned format
, stencil_format
;
4721 uint64_t va
, s_offs
, z_offs
;
4722 bool stencil_only
= false;
4723 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4724 const struct radeon_surf
*surf
= &plane
->surface
;
4726 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4728 memset(ds
, 0, sizeof(*ds
));
4729 switch (iview
->image
->vk_format
) {
4730 case VK_FORMAT_D24_UNORM_S8_UINT
:
4731 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4732 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4733 ds
->offset_scale
= 2.0f
;
4735 case VK_FORMAT_D16_UNORM
:
4736 case VK_FORMAT_D16_UNORM_S8_UINT
:
4737 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4738 ds
->offset_scale
= 4.0f
;
4740 case VK_FORMAT_D32_SFLOAT
:
4741 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4742 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4743 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4744 ds
->offset_scale
= 1.0f
;
4746 case VK_FORMAT_S8_UINT
:
4747 stencil_only
= true;
4753 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4754 stencil_format
= surf
->has_stencil
?
4755 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4757 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4758 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4759 S_028008_SLICE_MAX(max_slice
);
4760 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4761 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
4762 S_028008_SLICE_MAX_HI(max_slice
>> 11);
4765 ds
->db_htile_data_base
= 0;
4766 ds
->db_htile_surface
= 0;
4768 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4769 s_offs
= z_offs
= va
;
4771 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4772 assert(surf
->u
.gfx9
.surf_offset
== 0);
4773 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4775 ds
->db_z_info
= S_028038_FORMAT(format
) |
4776 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4777 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4778 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4779 S_028038_ZRANGE_PRECISION(1);
4780 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4781 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4783 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4784 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4785 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4788 ds
->db_depth_view
|= S_028008_MIPID(level
);
4789 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4790 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4792 if (radv_htile_enabled(iview
->image
, level
)) {
4793 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4795 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4796 unsigned max_zplanes
=
4797 radv_calc_decompress_on_z_planes(device
, iview
);
4799 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4801 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4802 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
4803 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
4805 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
4806 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4810 if (!surf
->has_stencil
)
4811 /* Use all of the htile_buffer for depth if there's no stencil. */
4812 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4813 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4814 iview
->image
->htile_offset
;
4815 ds
->db_htile_data_base
= va
>> 8;
4816 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4817 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
4819 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4820 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4824 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4827 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4829 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4830 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4832 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4833 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4834 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4836 if (iview
->image
->info
.samples
> 1)
4837 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4839 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4840 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4841 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4842 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4843 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4844 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4845 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4846 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4849 tile_mode
= stencil_tile_mode
;
4851 ds
->db_depth_info
|=
4852 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4853 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4854 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4855 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4856 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4857 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4858 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4859 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4861 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4862 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4863 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4864 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4866 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4869 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4870 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4871 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4873 if (radv_htile_enabled(iview
->image
, level
)) {
4874 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4876 if (!surf
->has_stencil
&&
4877 !radv_image_is_tc_compat_htile(iview
->image
))
4878 /* Use all of the htile_buffer for depth if there's no stencil. */
4879 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4881 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4882 iview
->image
->htile_offset
;
4883 ds
->db_htile_data_base
= va
>> 8;
4884 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4886 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4887 unsigned max_zplanes
=
4888 radv_calc_decompress_on_z_planes(device
, iview
);
4890 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4891 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4896 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4897 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4900 VkResult
radv_CreateFramebuffer(
4902 const VkFramebufferCreateInfo
* pCreateInfo
,
4903 const VkAllocationCallbacks
* pAllocator
,
4904 VkFramebuffer
* pFramebuffer
)
4906 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4907 struct radv_framebuffer
*framebuffer
;
4908 const VkFramebufferAttachmentsCreateInfoKHR
*imageless_create_info
=
4909 vk_find_struct_const(pCreateInfo
->pNext
,
4910 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR
);
4912 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4914 size_t size
= sizeof(*framebuffer
);
4915 if (!imageless_create_info
)
4916 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
4917 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4918 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4919 if (framebuffer
== NULL
)
4920 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4922 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4923 framebuffer
->width
= pCreateInfo
->width
;
4924 framebuffer
->height
= pCreateInfo
->height
;
4925 framebuffer
->layers
= pCreateInfo
->layers
;
4926 if (imageless_create_info
) {
4927 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
4928 const VkFramebufferAttachmentImageInfoKHR
*attachment
=
4929 imageless_create_info
->pAttachmentImageInfos
+ i
;
4930 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
4931 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
4932 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
4935 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4936 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4937 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4938 framebuffer
->attachments
[i
] = iview
;
4939 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4940 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4941 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4945 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4949 void radv_DestroyFramebuffer(
4952 const VkAllocationCallbacks
* pAllocator
)
4954 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4955 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4959 vk_free2(&device
->alloc
, pAllocator
, fb
);
4962 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4964 switch (address_mode
) {
4965 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4966 return V_008F30_SQ_TEX_WRAP
;
4967 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4968 return V_008F30_SQ_TEX_MIRROR
;
4969 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4970 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4971 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4972 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4973 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4974 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4976 unreachable("illegal tex wrap mode");
4982 radv_tex_compare(VkCompareOp op
)
4985 case VK_COMPARE_OP_NEVER
:
4986 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4987 case VK_COMPARE_OP_LESS
:
4988 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4989 case VK_COMPARE_OP_EQUAL
:
4990 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4991 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4992 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4993 case VK_COMPARE_OP_GREATER
:
4994 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4995 case VK_COMPARE_OP_NOT_EQUAL
:
4996 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4997 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4998 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4999 case VK_COMPARE_OP_ALWAYS
:
5000 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
5002 unreachable("illegal compare mode");
5008 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
5011 case VK_FILTER_NEAREST
:
5012 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
5013 V_008F38_SQ_TEX_XY_FILTER_POINT
);
5014 case VK_FILTER_LINEAR
:
5015 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
5016 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
5017 case VK_FILTER_CUBIC_IMG
:
5019 fprintf(stderr
, "illegal texture filter");
5025 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
5028 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
5029 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
5030 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
5031 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
5033 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
5038 radv_tex_bordercolor(VkBorderColor bcolor
)
5041 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
5042 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
5043 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
5044 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
5045 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
5046 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
5047 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
5048 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
5049 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
5057 radv_tex_aniso_filter(unsigned filter
)
5071 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
5074 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
5075 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5076 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
5077 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
5078 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
5079 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
5087 radv_get_max_anisotropy(struct radv_device
*device
,
5088 const VkSamplerCreateInfo
*pCreateInfo
)
5090 if (device
->force_aniso
>= 0)
5091 return device
->force_aniso
;
5093 if (pCreateInfo
->anisotropyEnable
&&
5094 pCreateInfo
->maxAnisotropy
> 1.0f
)
5095 return (uint32_t)pCreateInfo
->maxAnisotropy
;
5101 radv_init_sampler(struct radv_device
*device
,
5102 struct radv_sampler
*sampler
,
5103 const VkSamplerCreateInfo
*pCreateInfo
)
5105 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
5106 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
5107 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
5108 device
->physical_device
->rad_info
.chip_class
== GFX9
;
5109 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
5111 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
5112 vk_find_struct_const(pCreateInfo
->pNext
,
5113 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
5114 if (sampler_reduction
)
5115 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
5117 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
5118 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
5119 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
5120 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
5121 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
5122 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
5123 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
5124 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
5125 S_008F30_DISABLE_CUBE_WRAP(0) |
5126 S_008F30_COMPAT_MODE(compat_mode
) |
5127 S_008F30_FILTER_MODE(filter_mode
));
5128 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
5129 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
5130 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
5131 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
5132 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
5133 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
5134 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
5135 S_008F38_MIP_POINT_PRECLAMP(0));
5136 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
5137 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
5139 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5140 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
5142 sampler
->state
[2] |=
5143 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
5144 S_008F38_FILTER_PREC_FIX(1) |
5145 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
5149 VkResult
radv_CreateSampler(
5151 const VkSamplerCreateInfo
* pCreateInfo
,
5152 const VkAllocationCallbacks
* pAllocator
,
5153 VkSampler
* pSampler
)
5155 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5156 struct radv_sampler
*sampler
;
5158 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
5159 vk_find_struct_const(pCreateInfo
->pNext
,
5160 SAMPLER_YCBCR_CONVERSION_INFO
);
5162 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
5164 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
5165 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5167 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5169 radv_init_sampler(device
, sampler
, pCreateInfo
);
5171 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
5172 *pSampler
= radv_sampler_to_handle(sampler
);
5177 void radv_DestroySampler(
5180 const VkAllocationCallbacks
* pAllocator
)
5182 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5183 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
5187 vk_free2(&device
->alloc
, pAllocator
, sampler
);
5190 /* vk_icd.h does not declare this function, so we declare it here to
5191 * suppress Wmissing-prototypes.
5193 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5194 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
5196 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5197 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
5199 /* For the full details on loader interface versioning, see
5200 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
5201 * What follows is a condensed summary, to help you navigate the large and
5202 * confusing official doc.
5204 * - Loader interface v0 is incompatible with later versions. We don't
5207 * - In loader interface v1:
5208 * - The first ICD entrypoint called by the loader is
5209 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
5211 * - The ICD must statically expose no other Vulkan symbol unless it is
5212 * linked with -Bsymbolic.
5213 * - Each dispatchable Vulkan handle created by the ICD must be
5214 * a pointer to a struct whose first member is VK_LOADER_DATA. The
5215 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
5216 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
5217 * vkDestroySurfaceKHR(). The ICD must be capable of working with
5218 * such loader-managed surfaces.
5220 * - Loader interface v2 differs from v1 in:
5221 * - The first ICD entrypoint called by the loader is
5222 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
5223 * statically expose this entrypoint.
5225 * - Loader interface v3 differs from v2 in:
5226 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
5227 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
5228 * because the loader no longer does so.
5230 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
5234 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
5235 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
5238 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5239 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
5241 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
5243 /* At the moment, we support only the below handle types. */
5244 assert(pGetFdInfo
->handleType
==
5245 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5246 pGetFdInfo
->handleType
==
5247 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5249 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
5251 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5255 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
5256 VkExternalMemoryHandleTypeFlagBits handleType
,
5258 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
5260 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5262 switch (handleType
) {
5263 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
5264 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
5268 /* The valid usage section for this function says:
5270 * "handleType must not be one of the handle types defined as
5273 * So opaque handle types fall into the default "unsupported" case.
5275 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5279 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5283 uint32_t syncobj_handle
= 0;
5284 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5286 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5289 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5291 *syncobj
= syncobj_handle
;
5297 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5301 /* If we create a syncobj we do it locally so that if we have an error, we don't
5302 * leave a syncobj in an undetermined state in the fence. */
5303 uint32_t syncobj_handle
= *syncobj
;
5304 if (!syncobj_handle
) {
5305 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5307 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5312 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5314 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5316 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5319 *syncobj
= syncobj_handle
;
5326 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5327 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5329 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5330 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5331 uint32_t *syncobj_dst
= NULL
;
5333 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5334 syncobj_dst
= &sem
->temp_syncobj
;
5336 syncobj_dst
= &sem
->syncobj
;
5339 switch(pImportSemaphoreFdInfo
->handleType
) {
5340 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5341 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5342 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5343 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5345 unreachable("Unhandled semaphore handle type");
5349 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5350 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5353 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5354 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5356 uint32_t syncobj_handle
;
5358 if (sem
->temp_syncobj
)
5359 syncobj_handle
= sem
->temp_syncobj
;
5361 syncobj_handle
= sem
->syncobj
;
5363 switch(pGetFdInfo
->handleType
) {
5364 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5365 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5367 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5368 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5370 if (sem
->temp_syncobj
) {
5371 close (sem
->temp_syncobj
);
5372 sem
->temp_syncobj
= 0;
5374 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5379 unreachable("Unhandled semaphore handle type");
5383 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5387 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5388 VkPhysicalDevice physicalDevice
,
5389 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5390 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5392 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5394 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5395 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5396 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5397 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5398 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5399 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5400 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5401 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5402 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5403 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5404 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5405 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5406 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5408 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5409 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5410 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5414 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5415 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5417 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5418 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5419 uint32_t *syncobj_dst
= NULL
;
5422 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5423 syncobj_dst
= &fence
->temp_syncobj
;
5425 syncobj_dst
= &fence
->syncobj
;
5428 switch(pImportFenceFdInfo
->handleType
) {
5429 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5430 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5431 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5432 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5434 unreachable("Unhandled fence handle type");
5438 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5439 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5442 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5443 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5445 uint32_t syncobj_handle
;
5447 if (fence
->temp_syncobj
)
5448 syncobj_handle
= fence
->temp_syncobj
;
5450 syncobj_handle
= fence
->syncobj
;
5452 switch(pGetFdInfo
->handleType
) {
5453 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5454 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5456 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5457 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5459 if (fence
->temp_syncobj
) {
5460 close (fence
->temp_syncobj
);
5461 fence
->temp_syncobj
= 0;
5463 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5468 unreachable("Unhandled fence handle type");
5472 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5476 void radv_GetPhysicalDeviceExternalFenceProperties(
5477 VkPhysicalDevice physicalDevice
,
5478 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5479 VkExternalFenceProperties
*pExternalFenceProperties
)
5481 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5483 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5484 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5485 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5486 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5487 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5488 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5489 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5491 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5492 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5493 pExternalFenceProperties
->externalFenceFeatures
= 0;
5498 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5499 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5500 const VkAllocationCallbacks
* pAllocator
,
5501 VkDebugReportCallbackEXT
* pCallback
)
5503 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5504 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5505 pCreateInfo
, pAllocator
, &instance
->alloc
,
5510 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5511 VkDebugReportCallbackEXT _callback
,
5512 const VkAllocationCallbacks
* pAllocator
)
5514 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5515 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5516 _callback
, pAllocator
, &instance
->alloc
);
5520 radv_DebugReportMessageEXT(VkInstance _instance
,
5521 VkDebugReportFlagsEXT flags
,
5522 VkDebugReportObjectTypeEXT objectType
,
5525 int32_t messageCode
,
5526 const char* pLayerPrefix
,
5527 const char* pMessage
)
5529 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5530 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5531 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5535 radv_GetDeviceGroupPeerMemoryFeatures(
5538 uint32_t localDeviceIndex
,
5539 uint32_t remoteDeviceIndex
,
5540 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5542 assert(localDeviceIndex
== remoteDeviceIndex
);
5544 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5545 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5546 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5547 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5550 static const VkTimeDomainEXT radv_time_domains
[] = {
5551 VK_TIME_DOMAIN_DEVICE_EXT
,
5552 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5553 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5556 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5557 VkPhysicalDevice physicalDevice
,
5558 uint32_t *pTimeDomainCount
,
5559 VkTimeDomainEXT
*pTimeDomains
)
5562 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5564 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5565 vk_outarray_append(&out
, i
) {
5566 *i
= radv_time_domains
[d
];
5570 return vk_outarray_status(&out
);
5574 radv_clock_gettime(clockid_t clock_id
)
5576 struct timespec current
;
5579 ret
= clock_gettime(clock_id
, ¤t
);
5580 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5581 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5585 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5588 VkResult
radv_GetCalibratedTimestampsEXT(
5590 uint32_t timestampCount
,
5591 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5592 uint64_t *pTimestamps
,
5593 uint64_t *pMaxDeviation
)
5595 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5596 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5598 uint64_t begin
, end
;
5599 uint64_t max_clock_period
= 0;
5601 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5603 for (d
= 0; d
< timestampCount
; d
++) {
5604 switch (pTimestampInfos
[d
].timeDomain
) {
5605 case VK_TIME_DOMAIN_DEVICE_EXT
:
5606 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5608 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5609 max_clock_period
= MAX2(max_clock_period
, device_period
);
5611 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5612 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5613 max_clock_period
= MAX2(max_clock_period
, 1);
5616 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5617 pTimestamps
[d
] = begin
;
5625 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5628 * The maximum deviation is the sum of the interval over which we
5629 * perform the sampling and the maximum period of any sampled
5630 * clock. That's because the maximum skew between any two sampled
5631 * clock edges is when the sampled clock with the largest period is
5632 * sampled at the end of that period but right at the beginning of the
5633 * sampling interval and some other clock is sampled right at the
5634 * begining of its sampling period and right at the end of the
5635 * sampling interval. Let's assume the GPU has the longest clock
5636 * period and that the application is sampling GPU and monotonic:
5639 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5640 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5644 * GPU -----_____-----_____-----_____-----_____
5647 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5648 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5650 * Interval <----------------->
5651 * Deviation <-------------------------->
5655 * m = read(monotonic) 2
5658 * We round the sample interval up by one tick to cover sampling error
5659 * in the interval clock
5662 uint64_t sample_interval
= end
- begin
+ 1;
5664 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5669 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5670 VkPhysicalDevice physicalDevice
,
5671 VkSampleCountFlagBits samples
,
5672 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5674 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5675 VK_SAMPLE_COUNT_4_BIT
|
5676 VK_SAMPLE_COUNT_8_BIT
)) {
5677 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5679 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };