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
31 #include <linux/audit.h>
32 #include <linux/bpf.h>
33 #include <linux/filter.h>
34 #include <linux/seccomp.h>
35 #include <linux/unistd.h>
40 #include <sys/prctl.h>
45 #include "radv_debug.h"
46 #include "radv_private.h"
47 #include "radv_shader.h"
49 #include "util/disk_cache.h"
53 #include "drm-uapi/amdgpu_drm.h"
54 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
55 #include "winsys/null/radv_null_winsys_public.h"
56 #include "ac_llvm_util.h"
57 #include "vk_format.h"
60 #include "util/build_id.h"
61 #include "util/debug.h"
62 #include "util/mesa-sha1.h"
63 #include "util/timespec.h"
64 #include "util/u_atomic.h"
65 #include "compiler/glsl_types.h"
66 #include "util/xmlpool.h"
68 static struct radv_timeline_point
*
69 radv_timeline_find_point_at_least_locked(struct radv_device
*device
,
70 struct radv_timeline
*timeline
,
73 static struct radv_timeline_point
*
74 radv_timeline_add_point_locked(struct radv_device
*device
,
75 struct radv_timeline
*timeline
,
79 radv_timeline_trigger_waiters_locked(struct radv_timeline
*timeline
,
80 struct list_head
*processing_list
);
83 void radv_destroy_semaphore_part(struct radv_device
*device
,
84 struct radv_semaphore_part
*part
);
87 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
90 unsigned char sha1
[20];
91 unsigned ptr_size
= sizeof(void*);
93 memset(uuid
, 0, VK_UUID_SIZE
);
94 _mesa_sha1_init(&ctx
);
96 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
97 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
100 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
101 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
102 _mesa_sha1_final(&ctx
, sha1
);
104 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
109 radv_get_driver_uuid(void *uuid
)
111 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
115 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
117 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
121 radv_get_visible_vram_size(struct radv_physical_device
*device
)
123 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
127 radv_get_vram_size(struct radv_physical_device
*device
)
129 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
133 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
135 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
136 uint64_t vram_size
= radv_get_vram_size(device
);
137 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
138 device
->memory_properties
.memoryHeapCount
= 0;
140 vram_index
= device
->memory_properties
.memoryHeapCount
++;
141 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
143 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
147 if (device
->rad_info
.gart_size
> 0) {
148 gart_index
= device
->memory_properties
.memoryHeapCount
++;
149 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
150 .size
= device
->rad_info
.gart_size
,
155 if (visible_vram_size
) {
156 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
157 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
158 .size
= visible_vram_size
,
159 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
163 unsigned type_count
= 0;
165 if (device
->rad_info
.has_dedicated_vram
) {
166 if (vram_index
>= 0) {
167 device
->memory_domains
[type_count
] = RADEON_DOMAIN_VRAM
;
168 device
->memory_flags
[type_count
] = RADEON_FLAG_NO_CPU_ACCESS
;
169 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
170 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
171 .heapIndex
= vram_index
,
175 if (visible_vram_index
>= 0) {
176 device
->memory_domains
[type_count
] = RADEON_DOMAIN_VRAM
;
177 device
->memory_flags
[type_count
] = RADEON_FLAG_NO_CPU_ACCESS
;
178 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
179 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
180 .heapIndex
= visible_vram_index
,
185 if (gart_index
>= 0) {
186 device
->memory_domains
[type_count
] = RADEON_DOMAIN_GTT
;
187 device
->memory_flags
[type_count
] = RADEON_FLAG_GTT_WC
| RADEON_FLAG_CPU_ACCESS
;
188 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
189 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
190 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
191 .heapIndex
= gart_index
,
194 if (visible_vram_index
>= 0) {
195 device
->memory_domains
[type_count
] = RADEON_DOMAIN_VRAM
;
196 device
->memory_flags
[type_count
] = RADEON_FLAG_CPU_ACCESS
;
197 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
198 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
199 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
200 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
201 .heapIndex
= visible_vram_index
,
205 if (gart_index
>= 0) {
206 device
->memory_domains
[type_count
] = RADEON_DOMAIN_GTT
;
207 device
->memory_flags
[type_count
] = RADEON_FLAG_CPU_ACCESS
;
208 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
209 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
210 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
211 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
212 .heapIndex
= gart_index
,
215 device
->memory_properties
.memoryTypeCount
= type_count
;
217 if (device
->rad_info
.has_l2_uncached
) {
218 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
219 VkMemoryType mem_type
= device
->memory_properties
.memoryTypes
[i
];
221 if ((mem_type
.propertyFlags
& (VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
222 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
)) ||
223 mem_type
.propertyFlags
== VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
) {
225 VkMemoryPropertyFlags property_flags
= mem_type
.propertyFlags
|
226 VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
|
227 VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD
;
229 device
->memory_domains
[type_count
] = device
->memory_domains
[i
];
230 device
->memory_flags
[type_count
] = device
->memory_flags
[i
] | RADEON_FLAG_VA_UNCACHED
;
231 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
232 .propertyFlags
= property_flags
,
233 .heapIndex
= mem_type
.heapIndex
,
237 device
->memory_properties
.memoryTypeCount
= type_count
;
242 radv_physical_device_init(struct radv_physical_device
*device
,
243 struct radv_instance
*instance
,
244 drmDevicePtr drm_device
)
251 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
252 drmVersionPtr version
;
254 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
256 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
257 radv_logi("Could not open device '%s'", path
);
259 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
262 version
= drmGetVersion(fd
);
266 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
267 radv_logi("Could not get the kernel driver version for device '%s'", path
);
269 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
270 "failed to get version %s: %m", path
);
273 if (strcmp(version
->name
, "amdgpu")) {
274 drmFreeVersion(version
);
277 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
278 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
280 return VK_ERROR_INCOMPATIBLE_DRIVER
;
282 drmFreeVersion(version
);
284 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
285 radv_logi("Found compatible device '%s'.", path
);
288 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
289 device
->instance
= instance
;
292 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
293 instance
->perftest_flags
);
295 device
->ws
= radv_null_winsys_create();
299 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
303 if (drm_device
&& instance
->enabled_extensions
.KHR_display
) {
304 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
305 if (master_fd
>= 0) {
306 uint32_t accel_working
= 0;
307 struct drm_amdgpu_info request
= {
308 .return_pointer
= (uintptr_t)&accel_working
,
309 .return_size
= sizeof(accel_working
),
310 .query
= AMDGPU_INFO_ACCEL_WORKING
313 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
320 device
->master_fd
= master_fd
;
321 device
->local_fd
= fd
;
322 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
324 device
->use_aco
= instance
->perftest_flags
& RADV_PERFTEST_ACO
;
326 snprintf(device
->name
, sizeof(device
->name
),
327 "AMD RADV%s %s (LLVM " MESA_LLVM_VERSION_STRING
")", device
->use_aco
? "/ACO" : "",
328 device
->rad_info
.name
);
330 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
331 device
->ws
->destroy(device
->ws
);
332 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
333 "cannot generate UUID");
337 /* These flags affect shader compilation. */
338 uint64_t shader_env_flags
= (device
->use_aco
? 0x2 : 0);
340 /* The gpu id is already embedded in the uuid so we just pass "radv"
341 * when creating the cache.
343 char buf
[VK_UUID_SIZE
* 2 + 1];
344 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
345 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
347 if (device
->rad_info
.chip_class
< GFX8
)
348 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
350 radv_get_driver_uuid(&device
->driver_uuid
);
351 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
353 device
->out_of_order_rast_allowed
= device
->rad_info
.has_out_of_order_rast
&&
354 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
356 device
->dcc_msaa_allowed
=
357 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
359 device
->use_shader_ballot
= (device
->use_aco
&& device
->rad_info
.chip_class
>= GFX8
) ||
360 (device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
);
362 device
->use_ngg
= device
->rad_info
.chip_class
>= GFX10
&&
363 device
->rad_info
.family
!= CHIP_NAVI14
&&
364 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_NGG
);
366 /* TODO: Implement NGG GS with ACO. */
367 device
->use_ngg_gs
= device
->use_ngg
&& !device
->use_aco
;
368 device
->use_ngg_streamout
= false;
370 /* Determine the number of threads per wave for all stages. */
371 device
->cs_wave_size
= 64;
372 device
->ps_wave_size
= 64;
373 device
->ge_wave_size
= 64;
375 if (device
->rad_info
.chip_class
>= GFX10
) {
376 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
377 device
->cs_wave_size
= 32;
379 /* For pixel shaders, wave64 is recommanded. */
380 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
381 device
->ps_wave_size
= 32;
383 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
384 device
->ge_wave_size
= 32;
387 radv_physical_device_init_mem_types(device
);
388 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
391 device
->bus_info
= *drm_device
->businfo
.pci
;
393 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
394 ac_print_gpu_info(&device
->rad_info
);
396 /* The WSI is structured as a layer on top of the driver, so this has
397 * to be the last part of initialization (at least until we get other
400 result
= radv_init_wsi(device
);
401 if (result
!= VK_SUCCESS
) {
402 device
->ws
->destroy(device
->ws
);
403 vk_error(instance
, result
);
417 radv_physical_device_finish(struct radv_physical_device
*device
)
419 radv_finish_wsi(device
);
420 device
->ws
->destroy(device
->ws
);
421 disk_cache_destroy(device
->disk_cache
);
422 close(device
->local_fd
);
423 if (device
->master_fd
!= -1)
424 close(device
->master_fd
);
428 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
429 VkSystemAllocationScope allocationScope
)
435 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
436 size_t align
, VkSystemAllocationScope allocationScope
)
438 return realloc(pOriginal
, size
);
442 default_free_func(void *pUserData
, void *pMemory
)
447 static const VkAllocationCallbacks default_alloc
= {
449 .pfnAllocation
= default_alloc_func
,
450 .pfnReallocation
= default_realloc_func
,
451 .pfnFree
= default_free_func
,
454 static const struct debug_control radv_debug_options
[] = {
455 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
456 {"nodcc", RADV_DEBUG_NO_DCC
},
457 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
458 {"nocache", RADV_DEBUG_NO_CACHE
},
459 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
460 {"nohiz", RADV_DEBUG_NO_HIZ
},
461 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
462 {"allbos", RADV_DEBUG_ALL_BOS
},
463 {"noibs", RADV_DEBUG_NO_IBS
},
464 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
465 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
466 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
467 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
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
},
481 {"metashaders", RADV_DEBUG_DUMP_META_SHADERS
},
482 {"nomemorycache", RADV_DEBUG_NO_MEMORY_CACHE
},
487 radv_get_debug_option_name(int id
)
489 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
490 return radv_debug_options
[id
].string
;
493 static const struct debug_control radv_perftest_options
[] = {
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
},
503 {"aco", RADV_PERFTEST_ACO
},
508 radv_get_perftest_option_name(int id
)
510 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
511 return radv_perftest_options
[id
].string
;
515 radv_handle_per_app_options(struct radv_instance
*instance
,
516 const VkApplicationInfo
*info
)
518 const char *name
= info
? info
->pApplicationName
: NULL
;
523 if (!strcmp(name
, "DOOM_VFR")) {
524 /* Work around a Doom VFR game bug */
525 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
526 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
527 /* Workaround for a WaW hazard when LLVM moves/merges
528 * load/store memory operations.
529 * See https://reviews.llvm.org/D61313
531 if (LLVM_VERSION_MAJOR
< 9)
532 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
533 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
534 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
) &&
535 !(instance
->perftest_flags
& RADV_PERFTEST_ACO
)) {
536 /* Force enable VK_AMD_shader_ballot because it looks
537 * safe and it gives a nice boost (+20% on Vega 56 at
538 * this time). It also prevents corruption on LLVM.
540 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
542 } else if (!strcmp(name
, "Fledge")) {
544 * Zero VRAM for "The Surge 2"
546 * This avoid a hang when when rendering any level. Likely
547 * uninitialized data in an indirect draw.
549 instance
->debug_flags
|= RADV_DEBUG_ZERO_VRAM
;
550 } else if (!strcmp(name
, "No Man's Sky")) {
551 /* Work around a NMS game bug */
552 instance
->debug_flags
|= RADV_DEBUG_DISCARD_TO_DEMOTE
;
556 static int radv_get_instance_extension_index(const char *name
)
558 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
559 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
565 static const char radv_dri_options_xml
[] =
567 DRI_CONF_SECTION_PERFORMANCE
568 DRI_CONF_ADAPTIVE_SYNC("true")
569 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
570 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
573 DRI_CONF_SECTION_DEBUG
574 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
578 static void radv_init_dri_options(struct radv_instance
*instance
)
580 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
581 driParseConfigFiles(&instance
->dri_options
,
582 &instance
->available_dri_options
,
584 instance
->engineName
,
585 instance
->engineVersion
);
588 VkResult
radv_CreateInstance(
589 const VkInstanceCreateInfo
* pCreateInfo
,
590 const VkAllocationCallbacks
* pAllocator
,
591 VkInstance
* pInstance
)
593 struct radv_instance
*instance
;
596 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
598 uint32_t client_version
;
599 if (pCreateInfo
->pApplicationInfo
&&
600 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
601 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
603 client_version
= VK_API_VERSION_1_0
;
606 const char *engine_name
= NULL
;
607 uint32_t engine_version
= 0;
608 if (pCreateInfo
->pApplicationInfo
) {
609 engine_name
= pCreateInfo
->pApplicationInfo
->pEngineName
;
610 engine_version
= pCreateInfo
->pApplicationInfo
->engineVersion
;
613 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
614 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
616 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
618 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
621 instance
->alloc
= *pAllocator
;
623 instance
->alloc
= default_alloc
;
625 instance
->apiVersion
= client_version
;
626 instance
->physicalDeviceCount
= -1;
628 /* Get secure compile thread count. NOTE: We cap this at 32 */
629 #define MAX_SC_PROCS 32
630 char *num_sc_threads
= getenv("RADV_SECURE_COMPILE_THREADS");
632 instance
->num_sc_threads
= MIN2(strtoul(num_sc_threads
, NULL
, 10), MAX_SC_PROCS
);
634 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
637 /* Disable memory cache when secure compile is set */
638 if (radv_device_use_secure_compile(instance
))
639 instance
->debug_flags
|= RADV_DEBUG_NO_MEMORY_CACHE
;
641 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
642 radv_perftest_options
);
644 if (instance
->perftest_flags
& RADV_PERFTEST_ACO
)
645 fprintf(stderr
, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
647 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
648 radv_logi("Created an instance");
650 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
651 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
652 int index
= radv_get_instance_extension_index(ext_name
);
654 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
655 vk_free2(&default_alloc
, pAllocator
, instance
);
656 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
659 instance
->enabled_extensions
.extensions
[index
] = true;
662 bool unchecked
= instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
;
664 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
665 /* Vulkan requires that entrypoints for extensions which have
666 * not been enabled must not be advertised.
669 !radv_instance_entrypoint_is_enabled(i
, instance
->apiVersion
,
670 &instance
->enabled_extensions
)) {
671 instance
->dispatch
.entrypoints
[i
] = NULL
;
673 instance
->dispatch
.entrypoints
[i
] =
674 radv_instance_dispatch_table
.entrypoints
[i
];
678 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->physical_device_dispatch
.entrypoints
); i
++) {
679 /* Vulkan requires that entrypoints for extensions which have
680 * not been enabled must not be advertised.
683 !radv_physical_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
684 &instance
->enabled_extensions
)) {
685 instance
->physical_device_dispatch
.entrypoints
[i
] = NULL
;
687 instance
->physical_device_dispatch
.entrypoints
[i
] =
688 radv_physical_device_dispatch_table
.entrypoints
[i
];
692 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->device_dispatch
.entrypoints
); i
++) {
693 /* Vulkan requires that entrypoints for extensions which have
694 * not been enabled must not be advertised.
697 !radv_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
698 &instance
->enabled_extensions
, NULL
)) {
699 instance
->device_dispatch
.entrypoints
[i
] = NULL
;
701 instance
->device_dispatch
.entrypoints
[i
] =
702 radv_device_dispatch_table
.entrypoints
[i
];
706 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
707 if (result
!= VK_SUCCESS
) {
708 vk_free2(&default_alloc
, pAllocator
, instance
);
709 return vk_error(instance
, result
);
712 instance
->engineName
= vk_strdup(&instance
->alloc
, engine_name
,
713 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
714 instance
->engineVersion
= engine_version
;
716 glsl_type_singleton_init_or_ref();
718 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
720 radv_init_dri_options(instance
);
721 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
723 *pInstance
= radv_instance_to_handle(instance
);
728 void radv_DestroyInstance(
729 VkInstance _instance
,
730 const VkAllocationCallbacks
* pAllocator
)
732 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
737 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
738 radv_physical_device_finish(instance
->physicalDevices
+ i
);
741 vk_free(&instance
->alloc
, instance
->engineName
);
743 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
745 glsl_type_singleton_decref();
747 driDestroyOptionCache(&instance
->dri_options
);
748 driDestroyOptionInfo(&instance
->available_dri_options
);
750 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
752 vk_free(&instance
->alloc
, instance
);
756 radv_enumerate_devices(struct radv_instance
*instance
)
758 /* TODO: Check for more devices ? */
759 drmDevicePtr devices
[8];
760 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
763 instance
->physicalDeviceCount
= 0;
765 if (getenv("RADV_FORCE_FAMILY")) {
766 /* When RADV_FORCE_FAMILY is set, the driver creates a nul
767 * device that allows to test the compiler without having an
770 result
= radv_physical_device_init(instance
->physicalDevices
+
771 instance
->physicalDeviceCount
,
774 ++instance
->physicalDeviceCount
;
778 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
780 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
781 radv_logi("Found %d drm nodes", max_devices
);
784 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
786 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
787 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
788 devices
[i
]->bustype
== DRM_BUS_PCI
&&
789 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
791 result
= radv_physical_device_init(instance
->physicalDevices
+
792 instance
->physicalDeviceCount
,
795 if (result
== VK_SUCCESS
)
796 ++instance
->physicalDeviceCount
;
797 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
801 drmFreeDevices(devices
, max_devices
);
806 VkResult
radv_EnumeratePhysicalDevices(
807 VkInstance _instance
,
808 uint32_t* pPhysicalDeviceCount
,
809 VkPhysicalDevice
* pPhysicalDevices
)
811 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
814 if (instance
->physicalDeviceCount
< 0) {
815 result
= radv_enumerate_devices(instance
);
816 if (result
!= VK_SUCCESS
&&
817 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
821 if (!pPhysicalDevices
) {
822 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
824 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
825 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
826 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
829 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
833 VkResult
radv_EnumeratePhysicalDeviceGroups(
834 VkInstance _instance
,
835 uint32_t* pPhysicalDeviceGroupCount
,
836 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
838 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
841 if (instance
->physicalDeviceCount
< 0) {
842 result
= radv_enumerate_devices(instance
);
843 if (result
!= VK_SUCCESS
&&
844 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
848 if (!pPhysicalDeviceGroupProperties
) {
849 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
851 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
852 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
853 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
854 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
855 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
858 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
862 void radv_GetPhysicalDeviceFeatures(
863 VkPhysicalDevice physicalDevice
,
864 VkPhysicalDeviceFeatures
* pFeatures
)
866 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
867 memset(pFeatures
, 0, sizeof(*pFeatures
));
869 *pFeatures
= (VkPhysicalDeviceFeatures
) {
870 .robustBufferAccess
= true,
871 .fullDrawIndexUint32
= true,
872 .imageCubeArray
= true,
873 .independentBlend
= true,
874 .geometryShader
= true,
875 .tessellationShader
= true,
876 .sampleRateShading
= true,
877 .dualSrcBlend
= true,
879 .multiDrawIndirect
= true,
880 .drawIndirectFirstInstance
= true,
882 .depthBiasClamp
= true,
883 .fillModeNonSolid
= true,
888 .multiViewport
= true,
889 .samplerAnisotropy
= true,
890 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
891 .textureCompressionASTC_LDR
= false,
892 .textureCompressionBC
= true,
893 .occlusionQueryPrecise
= true,
894 .pipelineStatisticsQuery
= true,
895 .vertexPipelineStoresAndAtomics
= true,
896 .fragmentStoresAndAtomics
= true,
897 .shaderTessellationAndGeometryPointSize
= true,
898 .shaderImageGatherExtended
= true,
899 .shaderStorageImageExtendedFormats
= true,
900 .shaderStorageImageMultisample
= true,
901 .shaderUniformBufferArrayDynamicIndexing
= true,
902 .shaderSampledImageArrayDynamicIndexing
= true,
903 .shaderStorageBufferArrayDynamicIndexing
= true,
904 .shaderStorageImageArrayDynamicIndexing
= true,
905 .shaderStorageImageReadWithoutFormat
= true,
906 .shaderStorageImageWriteWithoutFormat
= true,
907 .shaderClipDistance
= true,
908 .shaderCullDistance
= true,
909 .shaderFloat64
= true,
911 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
912 .sparseBinding
= true,
913 .variableMultisampleRate
= true,
914 .inheritedQueries
= true,
918 void radv_GetPhysicalDeviceFeatures2(
919 VkPhysicalDevice physicalDevice
,
920 VkPhysicalDeviceFeatures2
*pFeatures
)
922 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
923 vk_foreach_struct(ext
, pFeatures
->pNext
) {
924 switch (ext
->sType
) {
925 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
926 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
927 features
->variablePointersStorageBuffer
= true;
928 features
->variablePointers
= true;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
932 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
933 features
->multiview
= true;
934 features
->multiviewGeometryShader
= true;
935 features
->multiviewTessellationShader
= true;
938 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
939 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
940 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
941 features
->shaderDrawParameters
= true;
944 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
945 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
946 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
947 features
->protectedMemory
= false;
950 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
951 VkPhysicalDevice16BitStorageFeatures
*features
=
952 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
953 bool enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
954 features
->storageBuffer16BitAccess
= enable
;
955 features
->uniformAndStorageBuffer16BitAccess
= enable
;
956 features
->storagePushConstant16
= enable
;
957 features
->storageInputOutput16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
&& LLVM_VERSION_MAJOR
>= 9;
960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
961 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
962 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
963 features
->samplerYcbcrConversion
= true;
966 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES
: {
967 VkPhysicalDeviceDescriptorIndexingFeatures
*features
=
968 (VkPhysicalDeviceDescriptorIndexingFeatures
*)ext
;
969 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
970 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
971 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
972 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
973 features
->shaderSampledImageArrayNonUniformIndexing
= true;
974 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
975 features
->shaderStorageImageArrayNonUniformIndexing
= true;
976 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
977 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
978 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
979 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
980 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
981 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
982 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
983 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
984 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
985 features
->descriptorBindingUpdateUnusedWhilePending
= true;
986 features
->descriptorBindingPartiallyBound
= true;
987 features
->descriptorBindingVariableDescriptorCount
= true;
988 features
->runtimeDescriptorArray
= true;
991 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
992 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
993 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
994 features
->conditionalRendering
= true;
995 features
->inheritedConditionalRendering
= false;
998 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
999 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1000 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1001 features
->vertexAttributeInstanceRateDivisor
= true;
1002 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1005 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1006 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1007 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1008 features
->transformFeedback
= true;
1009 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
1012 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES
: {
1013 VkPhysicalDeviceScalarBlockLayoutFeatures
*features
=
1014 (VkPhysicalDeviceScalarBlockLayoutFeatures
*)ext
;
1015 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
1018 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
1019 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
1020 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
1021 features
->memoryPriority
= true;
1024 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1025 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
1026 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
1027 features
->bufferDeviceAddress
= true;
1028 features
->bufferDeviceAddressCaptureReplay
= false;
1029 features
->bufferDeviceAddressMultiDevice
= false;
1032 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES
: {
1033 VkPhysicalDeviceBufferDeviceAddressFeatures
*features
=
1034 (VkPhysicalDeviceBufferDeviceAddressFeatures
*)ext
;
1035 features
->bufferDeviceAddress
= true;
1036 features
->bufferDeviceAddressCaptureReplay
= false;
1037 features
->bufferDeviceAddressMultiDevice
= false;
1040 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1041 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1042 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1043 features
->depthClipEnable
= true;
1046 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES
: {
1047 VkPhysicalDeviceHostQueryResetFeatures
*features
=
1048 (VkPhysicalDeviceHostQueryResetFeatures
*)ext
;
1049 features
->hostQueryReset
= true;
1052 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES
: {
1053 VkPhysicalDevice8BitStorageFeatures
*features
=
1054 (VkPhysicalDevice8BitStorageFeatures
*)ext
;
1055 bool enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1056 features
->storageBuffer8BitAccess
= enable
;
1057 features
->uniformAndStorageBuffer8BitAccess
= enable
;
1058 features
->storagePushConstant8
= enable
;
1061 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES
: {
1062 VkPhysicalDeviceShaderFloat16Int8Features
*features
=
1063 (VkPhysicalDeviceShaderFloat16Int8Features
*)ext
;
1064 features
->shaderFloat16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
;
1065 features
->shaderInt8
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1068 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES
: {
1069 VkPhysicalDeviceShaderAtomicInt64Features
*features
=
1070 (VkPhysicalDeviceShaderAtomicInt64Features
*)ext
;
1071 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1072 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1075 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1076 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
=
1077 (VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*)ext
;
1078 features
->shaderDemoteToHelperInvocation
= pdevice
->use_aco
;
1081 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1082 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1083 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1085 features
->inlineUniformBlock
= true;
1086 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1089 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1090 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1091 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1092 features
->computeDerivativeGroupQuads
= false;
1093 features
->computeDerivativeGroupLinear
= true;
1096 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1097 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1098 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1099 features
->ycbcrImageArrays
= true;
1102 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES
: {
1103 VkPhysicalDeviceUniformBufferStandardLayoutFeatures
*features
=
1104 (VkPhysicalDeviceUniformBufferStandardLayoutFeatures
*)ext
;
1105 features
->uniformBufferStandardLayout
= true;
1108 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1109 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1110 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1111 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1114 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES
: {
1115 VkPhysicalDeviceImagelessFramebufferFeatures
*features
=
1116 (VkPhysicalDeviceImagelessFramebufferFeatures
*)ext
;
1117 features
->imagelessFramebuffer
= true;
1120 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1121 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1122 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1123 features
->pipelineExecutableInfo
= true;
1126 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1127 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1128 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1129 features
->shaderSubgroupClock
= true;
1130 features
->shaderDeviceClock
= false;
1133 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1134 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1135 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1136 features
->texelBufferAlignment
= true;
1139 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES
: {
1140 VkPhysicalDeviceTimelineSemaphoreFeatures
*features
=
1141 (VkPhysicalDeviceTimelineSemaphoreFeatures
*) ext
;
1142 features
->timelineSemaphore
= true;
1145 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1146 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1147 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1148 features
->subgroupSizeControl
= true;
1149 features
->computeFullSubgroups
= true;
1152 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COHERENT_MEMORY_FEATURES_AMD
: {
1153 VkPhysicalDeviceCoherentMemoryFeaturesAMD
*features
=
1154 (VkPhysicalDeviceCoherentMemoryFeaturesAMD
*)ext
;
1155 features
->deviceCoherentMemory
= pdevice
->rad_info
.has_l2_uncached
;
1158 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES
: {
1159 VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
*features
=
1160 (VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
*)ext
;
1161 features
->shaderSubgroupExtendedTypes
= !pdevice
->use_aco
;
1164 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES_KHR
: {
1165 VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*features
=
1166 (VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*)ext
;
1167 features
->separateDepthStencilLayouts
= true;
1170 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
: {
1171 VkPhysicalDeviceVulkan11Features
*features
=
1172 (VkPhysicalDeviceVulkan11Features
*)ext
;
1173 bool storage16_enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1174 features
->storageBuffer16BitAccess
= storage16_enable
;
1175 features
->uniformAndStorageBuffer16BitAccess
= storage16_enable
;
1176 features
->storagePushConstant16
= storage16_enable
;
1177 features
->storageInputOutput16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
&& LLVM_VERSION_MAJOR
>= 9;
1178 features
->multiview
= true;
1179 features
->multiviewGeometryShader
= true;
1180 features
->multiviewTessellationShader
= true;
1181 features
->variablePointersStorageBuffer
= true;
1182 features
->variablePointers
= true;
1183 features
->protectedMemory
= false;
1184 features
->samplerYcbcrConversion
= true;
1185 features
->shaderDrawParameters
= true;
1188 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
: {
1189 VkPhysicalDeviceVulkan12Features
*features
=
1190 (VkPhysicalDeviceVulkan12Features
*)ext
;
1191 bool int8_enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1192 features
->samplerMirrorClampToEdge
= true;
1193 features
->drawIndirectCount
= true;
1194 features
->storageBuffer8BitAccess
= int8_enable
;
1195 features
->uniformAndStorageBuffer8BitAccess
= int8_enable
;
1196 features
->storagePushConstant8
= int8_enable
;
1197 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1198 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1199 features
->shaderFloat16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
;
1200 features
->shaderInt8
= int8_enable
;
1201 features
->descriptorIndexing
= true;
1202 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
1203 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
1204 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
1205 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
1206 features
->shaderSampledImageArrayNonUniformIndexing
= true;
1207 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
1208 features
->shaderStorageImageArrayNonUniformIndexing
= true;
1209 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
1210 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
1211 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
1212 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
1213 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
1214 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
1215 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
1216 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
1217 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
1218 features
->descriptorBindingUpdateUnusedWhilePending
= true;
1219 features
->descriptorBindingPartiallyBound
= true;
1220 features
->descriptorBindingVariableDescriptorCount
= true;
1221 features
->runtimeDescriptorArray
= true;
1222 features
->samplerFilterMinmax
= true;
1223 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
1224 features
->imagelessFramebuffer
= true;
1225 features
->uniformBufferStandardLayout
= true;
1226 features
->shaderSubgroupExtendedTypes
= !pdevice
->use_aco
;
1227 features
->separateDepthStencilLayouts
= true;
1228 features
->hostQueryReset
= true;
1229 features
->timelineSemaphore
= pdevice
->rad_info
.has_syncobj_wait_for_submit
;
1230 features
->bufferDeviceAddress
= true;
1231 features
->bufferDeviceAddressCaptureReplay
= false;
1232 features
->bufferDeviceAddressMultiDevice
= false;
1233 features
->vulkanMemoryModel
= false;
1234 features
->vulkanMemoryModelDeviceScope
= false;
1235 features
->vulkanMemoryModelAvailabilityVisibilityChains
= false;
1236 features
->shaderOutputViewportIndex
= true;
1237 features
->shaderOutputLayer
= true;
1238 features
->subgroupBroadcastDynamicId
= true;
1241 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1242 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1243 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1244 features
->rectangularLines
= false;
1245 features
->bresenhamLines
= true;
1246 features
->smoothLines
= false;
1247 features
->stippledRectangularLines
= false;
1248 features
->stippledBresenhamLines
= true;
1249 features
->stippledSmoothLines
= false;
1252 case VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD
: {
1253 VkDeviceMemoryOverallocationCreateInfoAMD
*features
=
1254 (VkDeviceMemoryOverallocationCreateInfoAMD
*)ext
;
1255 features
->overallocationBehavior
= true;
1262 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1266 radv_max_descriptor_set_size()
1268 /* make sure that the entire descriptor set is addressable with a signed
1269 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1270 * be at most 2 GiB. the combined image & samples object count as one of
1271 * both. This limit is for the pipeline layout, not for the set layout, but
1272 * there is no set limit, so we just set a pipeline limit. I don't think
1273 * any app is going to hit this soon. */
1274 return ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
1275 - MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1276 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1277 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1278 32 /* sampler, largest when combined with image */ +
1279 64 /* sampled image */ +
1280 64 /* storage image */);
1283 void radv_GetPhysicalDeviceProperties(
1284 VkPhysicalDevice physicalDevice
,
1285 VkPhysicalDeviceProperties
* pProperties
)
1287 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1288 VkSampleCountFlags sample_counts
= 0xf;
1290 size_t max_descriptor_set_size
= radv_max_descriptor_set_size();
1292 VkPhysicalDeviceLimits limits
= {
1293 .maxImageDimension1D
= (1 << 14),
1294 .maxImageDimension2D
= (1 << 14),
1295 .maxImageDimension3D
= (1 << 11),
1296 .maxImageDimensionCube
= (1 << 14),
1297 .maxImageArrayLayers
= (1 << 11),
1298 .maxTexelBufferElements
= UINT32_MAX
,
1299 .maxUniformBufferRange
= UINT32_MAX
,
1300 .maxStorageBufferRange
= UINT32_MAX
,
1301 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1302 .maxMemoryAllocationCount
= UINT32_MAX
,
1303 .maxSamplerAllocationCount
= 64 * 1024,
1304 .bufferImageGranularity
= 64, /* A cache line */
1305 .sparseAddressSpaceSize
= RADV_MAX_MEMORY_ALLOCATION_SIZE
, /* buffer max size */
1306 .maxBoundDescriptorSets
= MAX_SETS
,
1307 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1308 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1309 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1310 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1311 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1312 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1313 .maxPerStageResources
= max_descriptor_set_size
,
1314 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1315 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1316 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1317 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1318 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1319 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1320 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1321 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1322 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1323 .maxVertexInputBindings
= MAX_VBS
,
1324 .maxVertexInputAttributeOffset
= 2047,
1325 .maxVertexInputBindingStride
= 2048,
1326 .maxVertexOutputComponents
= 128,
1327 .maxTessellationGenerationLevel
= 64,
1328 .maxTessellationPatchSize
= 32,
1329 .maxTessellationControlPerVertexInputComponents
= 128,
1330 .maxTessellationControlPerVertexOutputComponents
= 128,
1331 .maxTessellationControlPerPatchOutputComponents
= 120,
1332 .maxTessellationControlTotalOutputComponents
= 4096,
1333 .maxTessellationEvaluationInputComponents
= 128,
1334 .maxTessellationEvaluationOutputComponents
= 128,
1335 .maxGeometryShaderInvocations
= 127,
1336 .maxGeometryInputComponents
= 64,
1337 .maxGeometryOutputComponents
= 128,
1338 .maxGeometryOutputVertices
= 256,
1339 .maxGeometryTotalOutputComponents
= 1024,
1340 .maxFragmentInputComponents
= 128,
1341 .maxFragmentOutputAttachments
= 8,
1342 .maxFragmentDualSrcAttachments
= 1,
1343 .maxFragmentCombinedOutputResources
= 8,
1344 .maxComputeSharedMemorySize
= 32768,
1345 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1346 .maxComputeWorkGroupInvocations
= 1024,
1347 .maxComputeWorkGroupSize
= {
1352 .subPixelPrecisionBits
= 8,
1353 .subTexelPrecisionBits
= 8,
1354 .mipmapPrecisionBits
= 8,
1355 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1356 .maxDrawIndirectCount
= UINT32_MAX
,
1357 .maxSamplerLodBias
= 16,
1358 .maxSamplerAnisotropy
= 16,
1359 .maxViewports
= MAX_VIEWPORTS
,
1360 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1361 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1362 .viewportSubPixelBits
= 8,
1363 .minMemoryMapAlignment
= 4096, /* A page */
1364 .minTexelBufferOffsetAlignment
= 4,
1365 .minUniformBufferOffsetAlignment
= 4,
1366 .minStorageBufferOffsetAlignment
= 4,
1367 .minTexelOffset
= -32,
1368 .maxTexelOffset
= 31,
1369 .minTexelGatherOffset
= -32,
1370 .maxTexelGatherOffset
= 31,
1371 .minInterpolationOffset
= -2,
1372 .maxInterpolationOffset
= 2,
1373 .subPixelInterpolationOffsetBits
= 8,
1374 .maxFramebufferWidth
= (1 << 14),
1375 .maxFramebufferHeight
= (1 << 14),
1376 .maxFramebufferLayers
= (1 << 10),
1377 .framebufferColorSampleCounts
= sample_counts
,
1378 .framebufferDepthSampleCounts
= sample_counts
,
1379 .framebufferStencilSampleCounts
= sample_counts
,
1380 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1381 .maxColorAttachments
= MAX_RTS
,
1382 .sampledImageColorSampleCounts
= sample_counts
,
1383 .sampledImageIntegerSampleCounts
= sample_counts
,
1384 .sampledImageDepthSampleCounts
= sample_counts
,
1385 .sampledImageStencilSampleCounts
= sample_counts
,
1386 .storageImageSampleCounts
= sample_counts
,
1387 .maxSampleMaskWords
= 1,
1388 .timestampComputeAndGraphics
= true,
1389 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1390 .maxClipDistances
= 8,
1391 .maxCullDistances
= 8,
1392 .maxCombinedClipAndCullDistances
= 8,
1393 .discreteQueuePriorities
= 2,
1394 .pointSizeRange
= { 0.0, 8192.0 },
1395 .lineWidthRange
= { 0.0, 8192.0 },
1396 .pointSizeGranularity
= (1.0 / 8.0),
1397 .lineWidthGranularity
= (1.0 / 8.0),
1398 .strictLines
= false, /* FINISHME */
1399 .standardSampleLocations
= true,
1400 .optimalBufferCopyOffsetAlignment
= 128,
1401 .optimalBufferCopyRowPitchAlignment
= 128,
1402 .nonCoherentAtomSize
= 64,
1405 *pProperties
= (VkPhysicalDeviceProperties
) {
1406 .apiVersion
= radv_physical_device_api_version(pdevice
),
1407 .driverVersion
= vk_get_driver_version(),
1408 .vendorID
= ATI_VENDOR_ID
,
1409 .deviceID
= pdevice
->rad_info
.pci_id
,
1410 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1412 .sparseProperties
= {0},
1415 strcpy(pProperties
->deviceName
, pdevice
->name
);
1416 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1420 radv_get_physical_device_properties_1_1(struct radv_physical_device
*pdevice
,
1421 VkPhysicalDeviceVulkan11Properties
*p
)
1423 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
);
1425 memcpy(p
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1426 memcpy(p
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1427 memset(p
->deviceLUID
, 0, VK_LUID_SIZE
);
1428 /* The LUID is for Windows. */
1429 p
->deviceLUIDValid
= false;
1430 p
->deviceNodeMask
= 0;
1432 p
->subgroupSize
= RADV_SUBGROUP_SIZE
;
1433 p
->subgroupSupportedStages
= VK_SHADER_STAGE_ALL_GRAPHICS
|
1434 VK_SHADER_STAGE_COMPUTE_BIT
;
1435 p
->subgroupSupportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1436 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1437 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1438 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1439 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1440 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1442 if (((pdevice
->rad_info
.chip_class
== GFX6
||
1443 pdevice
->rad_info
.chip_class
== GFX7
) && !pdevice
->use_aco
) ||
1444 pdevice
->rad_info
.chip_class
>= GFX8
) {
1445 p
->subgroupSupportedOperations
|= VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1446 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1448 p
->subgroupQuadOperationsInAllStages
= true;
1450 p
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1451 p
->maxMultiviewViewCount
= MAX_VIEWS
;
1452 p
->maxMultiviewInstanceIndex
= INT_MAX
;
1453 p
->protectedNoFault
= false;
1454 p
->maxPerSetDescriptors
= RADV_MAX_PER_SET_DESCRIPTORS
;
1455 p
->maxMemoryAllocationSize
= RADV_MAX_MEMORY_ALLOCATION_SIZE
;
1459 radv_get_physical_device_properties_1_2(struct radv_physical_device
*pdevice
,
1460 VkPhysicalDeviceVulkan12Properties
*p
)
1462 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
);
1464 p
->driverID
= VK_DRIVER_ID_MESA_RADV
;
1465 snprintf(p
->driverName
, VK_MAX_DRIVER_NAME_SIZE
, "radv");
1466 snprintf(p
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE
,
1467 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1468 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1469 p
->conformanceVersion
= (VkConformanceVersion
) {
1476 /* On AMD hardware, denormals and rounding modes for fp16/fp64 are
1477 * controlled by the same config register.
1479 if (pdevice
->rad_info
.has_double_rate_fp16
) {
1480 p
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1481 p
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1483 p
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1484 p
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1487 /* Do not allow both preserving and flushing denorms because different
1488 * shaders in the same pipeline can have different settings and this
1489 * won't work for merged shaders. To make it work, this requires LLVM
1490 * support for changing the register. The same logic applies for the
1491 * rounding modes because they are configured with the same config
1492 * register. TODO: we can enable a lot of these for ACO when it
1493 * supports all stages.
1495 p
->shaderDenormFlushToZeroFloat32
= true;
1496 p
->shaderDenormPreserveFloat32
= false;
1497 p
->shaderRoundingModeRTEFloat32
= true;
1498 p
->shaderRoundingModeRTZFloat32
= false;
1499 p
->shaderSignedZeroInfNanPreserveFloat32
= true;
1501 p
->shaderDenormFlushToZeroFloat16
= false;
1502 p
->shaderDenormPreserveFloat16
= pdevice
->rad_info
.has_double_rate_fp16
;
1503 p
->shaderRoundingModeRTEFloat16
= pdevice
->rad_info
.has_double_rate_fp16
;
1504 p
->shaderRoundingModeRTZFloat16
= false;
1505 p
->shaderSignedZeroInfNanPreserveFloat16
= pdevice
->rad_info
.has_double_rate_fp16
;
1507 p
->shaderDenormFlushToZeroFloat64
= false;
1508 p
->shaderDenormPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1509 p
->shaderRoundingModeRTEFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1510 p
->shaderRoundingModeRTZFloat64
= false;
1511 p
->shaderSignedZeroInfNanPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1513 p
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1514 p
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1515 p
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1516 p
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1517 p
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1518 p
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1519 p
->robustBufferAccessUpdateAfterBind
= false;
1520 p
->quadDivergentImplicitLod
= false;
1522 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1523 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1524 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1525 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1526 32 /* sampler, largest when combined with image */ +
1527 64 /* sampled image */ +
1528 64 /* storage image */);
1529 p
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1530 p
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1531 p
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1532 p
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1533 p
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1534 p
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1535 p
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1536 p
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1537 p
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1538 p
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1539 p
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1540 p
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1541 p
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1542 p
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1543 p
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1545 /* We support all of the depth resolve modes */
1546 p
->supportedDepthResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1547 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1548 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1549 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1551 /* Average doesn't make sense for stencil so we don't support that */
1552 p
->supportedStencilResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1553 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1554 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1556 p
->independentResolveNone
= true;
1557 p
->independentResolve
= true;
1559 /* GFX6-8 only support single channel min/max filter. */
1560 p
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1561 p
->filterMinmaxSingleComponentFormats
= true;
1563 p
->maxTimelineSemaphoreValueDifference
= UINT64_MAX
;
1565 p
->framebufferIntegerColorSampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1568 void radv_GetPhysicalDeviceProperties2(
1569 VkPhysicalDevice physicalDevice
,
1570 VkPhysicalDeviceProperties2
*pProperties
)
1572 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1573 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1575 VkPhysicalDeviceVulkan11Properties core_1_1
= {
1576 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
,
1578 radv_get_physical_device_properties_1_1(pdevice
, &core_1_1
);
1580 VkPhysicalDeviceVulkan12Properties core_1_2
= {
1581 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
,
1583 radv_get_physical_device_properties_1_2(pdevice
, &core_1_2
);
1585 #define CORE_RENAMED_PROPERTY(major, minor, ext_property, core_property) \
1586 memcpy(&properties->ext_property, &core_##major##_##minor.core_property, \
1587 sizeof(core_##major##_##minor.core_property))
1589 #define CORE_PROPERTY(major, minor, property) \
1590 CORE_RENAMED_PROPERTY(major, minor, property, property)
1592 vk_foreach_struct(ext
, pProperties
->pNext
) {
1593 switch (ext
->sType
) {
1594 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1595 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1596 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1597 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1600 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1601 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1602 CORE_PROPERTY(1, 1, deviceUUID
);
1603 CORE_PROPERTY(1, 1, driverUUID
);
1604 CORE_PROPERTY(1, 1, deviceLUID
);
1605 CORE_PROPERTY(1, 1, deviceLUIDValid
);
1608 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1609 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1610 CORE_PROPERTY(1, 1, maxMultiviewViewCount
);
1611 CORE_PROPERTY(1, 1, maxMultiviewInstanceIndex
);
1614 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1615 VkPhysicalDevicePointClippingProperties
*properties
=
1616 (VkPhysicalDevicePointClippingProperties
*)ext
;
1617 CORE_PROPERTY(1, 1, pointClippingBehavior
);
1620 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1621 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1622 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1623 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1626 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1627 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1628 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1629 properties
->minImportedHostPointerAlignment
= 4096;
1632 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1633 VkPhysicalDeviceSubgroupProperties
*properties
=
1634 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1635 CORE_PROPERTY(1, 1, subgroupSize
);
1636 CORE_RENAMED_PROPERTY(1, 1, supportedStages
,
1637 subgroupSupportedStages
);
1638 CORE_RENAMED_PROPERTY(1, 1, supportedOperations
,
1639 subgroupSupportedOperations
);
1640 CORE_RENAMED_PROPERTY(1, 1, quadOperationsInAllStages
,
1641 subgroupQuadOperationsInAllStages
);
1644 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1645 VkPhysicalDeviceMaintenance3Properties
*properties
=
1646 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1647 CORE_PROPERTY(1, 1, maxPerSetDescriptors
);
1648 CORE_PROPERTY(1, 1, maxMemoryAllocationSize
);
1651 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES
: {
1652 VkPhysicalDeviceSamplerFilterMinmaxProperties
*properties
=
1653 (VkPhysicalDeviceSamplerFilterMinmaxProperties
*)ext
;
1654 CORE_PROPERTY(1, 2, filterMinmaxImageComponentMapping
);
1655 CORE_PROPERTY(1, 2, filterMinmaxSingleComponentFormats
);
1658 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1659 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1660 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1662 /* Shader engines. */
1663 properties
->shaderEngineCount
=
1664 pdevice
->rad_info
.max_se
;
1665 properties
->shaderArraysPerEngineCount
=
1666 pdevice
->rad_info
.max_sh_per_se
;
1667 properties
->computeUnitsPerShaderArray
=
1668 pdevice
->rad_info
.num_good_cu_per_sh
;
1669 properties
->simdPerComputeUnit
=
1670 pdevice
->rad_info
.num_simd_per_compute_unit
;
1671 properties
->wavefrontsPerSimd
=
1672 pdevice
->rad_info
.max_wave64_per_simd
;
1673 properties
->wavefrontSize
= 64;
1676 properties
->sgprsPerSimd
=
1677 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1678 properties
->minSgprAllocation
=
1679 pdevice
->rad_info
.min_sgpr_alloc
;
1680 properties
->maxSgprAllocation
=
1681 pdevice
->rad_info
.max_sgpr_alloc
;
1682 properties
->sgprAllocationGranularity
=
1683 pdevice
->rad_info
.sgpr_alloc_granularity
;
1686 properties
->vgprsPerSimd
=
1687 pdevice
->rad_info
.num_physical_wave64_vgprs_per_simd
;
1688 properties
->minVgprAllocation
=
1689 pdevice
->rad_info
.min_wave64_vgpr_alloc
;
1690 properties
->maxVgprAllocation
=
1691 pdevice
->rad_info
.max_vgpr_alloc
;
1692 properties
->vgprAllocationGranularity
=
1693 pdevice
->rad_info
.wave64_vgpr_alloc_granularity
;
1696 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1697 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1698 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1700 properties
->shaderCoreFeatures
= 0;
1701 properties
->activeComputeUnitCount
=
1702 pdevice
->rad_info
.num_good_compute_units
;
1705 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1706 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1707 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1708 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1711 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES
: {
1712 VkPhysicalDeviceDescriptorIndexingProperties
*properties
=
1713 (VkPhysicalDeviceDescriptorIndexingProperties
*)ext
;
1714 CORE_PROPERTY(1, 2, maxUpdateAfterBindDescriptorsInAllPools
);
1715 CORE_PROPERTY(1, 2, shaderUniformBufferArrayNonUniformIndexingNative
);
1716 CORE_PROPERTY(1, 2, shaderSampledImageArrayNonUniformIndexingNative
);
1717 CORE_PROPERTY(1, 2, shaderStorageBufferArrayNonUniformIndexingNative
);
1718 CORE_PROPERTY(1, 2, shaderStorageImageArrayNonUniformIndexingNative
);
1719 CORE_PROPERTY(1, 2, shaderInputAttachmentArrayNonUniformIndexingNative
);
1720 CORE_PROPERTY(1, 2, robustBufferAccessUpdateAfterBind
);
1721 CORE_PROPERTY(1, 2, quadDivergentImplicitLod
);
1722 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSamplers
);
1723 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindUniformBuffers
);
1724 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageBuffers
);
1725 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSampledImages
);
1726 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageImages
);
1727 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindInputAttachments
);
1728 CORE_PROPERTY(1, 2, maxPerStageUpdateAfterBindResources
);
1729 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSamplers
);
1730 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffers
);
1731 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
);
1732 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffers
);
1733 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
);
1734 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSampledImages
);
1735 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageImages
);
1736 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindInputAttachments
);
1739 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1740 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1741 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1742 CORE_PROPERTY(1, 1, protectedNoFault
);
1745 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1746 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1747 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1748 properties
->primitiveOverestimationSize
= 0;
1749 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1750 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1751 properties
->primitiveUnderestimation
= false;
1752 properties
->conservativePointAndLineRasterization
= false;
1753 properties
->degenerateTrianglesRasterized
= false;
1754 properties
->degenerateLinesRasterized
= false;
1755 properties
->fullyCoveredFragmentShaderInputVariable
= false;
1756 properties
->conservativeRasterizationPostDepthCoverage
= false;
1759 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1760 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1761 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1762 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1763 properties
->pciBus
= pdevice
->bus_info
.bus
;
1764 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1765 properties
->pciFunction
= pdevice
->bus_info
.func
;
1768 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES
: {
1769 VkPhysicalDeviceDriverProperties
*properties
=
1770 (VkPhysicalDeviceDriverProperties
*) ext
;
1771 CORE_PROPERTY(1, 2, driverID
);
1772 CORE_PROPERTY(1, 2, driverName
);
1773 CORE_PROPERTY(1, 2, driverInfo
);
1774 CORE_PROPERTY(1, 2, conformanceVersion
);
1777 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1778 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1779 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1780 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1781 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1782 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1783 properties
->maxTransformFeedbackStreamDataSize
= 512;
1784 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1785 properties
->maxTransformFeedbackBufferDataStride
= 512;
1786 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1787 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1788 properties
->transformFeedbackRasterizationStreamSelect
= false;
1789 properties
->transformFeedbackDraw
= true;
1792 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1793 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1794 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1796 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1797 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1798 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1799 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1800 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1803 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1804 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1805 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1806 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1807 VK_SAMPLE_COUNT_4_BIT
|
1808 VK_SAMPLE_COUNT_8_BIT
;
1809 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1810 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1811 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1812 properties
->sampleLocationSubPixelBits
= 4;
1813 properties
->variableSampleLocations
= false;
1816 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES
: {
1817 VkPhysicalDeviceDepthStencilResolveProperties
*properties
=
1818 (VkPhysicalDeviceDepthStencilResolveProperties
*)ext
;
1819 CORE_PROPERTY(1, 2, supportedDepthResolveModes
);
1820 CORE_PROPERTY(1, 2, supportedStencilResolveModes
);
1821 CORE_PROPERTY(1, 2, independentResolveNone
);
1822 CORE_PROPERTY(1, 2, independentResolve
);
1825 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1826 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*properties
=
1827 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1828 properties
->storageTexelBufferOffsetAlignmentBytes
= 4;
1829 properties
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1830 properties
->uniformTexelBufferOffsetAlignmentBytes
= 4;
1831 properties
->uniformTexelBufferOffsetSingleTexelAlignment
= true;
1834 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES
: {
1835 VkPhysicalDeviceFloatControlsProperties
*properties
=
1836 (VkPhysicalDeviceFloatControlsProperties
*)ext
;
1837 CORE_PROPERTY(1, 2, denormBehaviorIndependence
);
1838 CORE_PROPERTY(1, 2, roundingModeIndependence
);
1839 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat16
);
1840 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat16
);
1841 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat16
);
1842 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat16
);
1843 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat16
);
1844 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat32
);
1845 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat32
);
1846 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat32
);
1847 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat32
);
1848 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat32
);
1849 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat64
);
1850 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat64
);
1851 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat64
);
1852 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat64
);
1853 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat64
);
1856 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES
: {
1857 VkPhysicalDeviceTimelineSemaphoreProperties
*properties
=
1858 (VkPhysicalDeviceTimelineSemaphoreProperties
*) ext
;
1859 CORE_PROPERTY(1, 2, maxTimelineSemaphoreValueDifference
);
1862 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
1863 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
1864 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
1865 props
->minSubgroupSize
= 64;
1866 props
->maxSubgroupSize
= 64;
1867 props
->maxComputeWorkgroupSubgroups
= UINT32_MAX
;
1868 props
->requiredSubgroupSizeStages
= 0;
1870 if (pdevice
->rad_info
.chip_class
>= GFX10
) {
1871 /* Only GFX10+ supports wave32. */
1872 props
->minSubgroupSize
= 32;
1873 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1877 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
:
1878 radv_get_physical_device_properties_1_1(pdevice
, (void *)ext
);
1880 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
:
1881 radv_get_physical_device_properties_1_2(pdevice
, (void *)ext
);
1883 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1884 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1885 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1886 props
->lineSubPixelPrecisionBits
= 4;
1895 static void radv_get_physical_device_queue_family_properties(
1896 struct radv_physical_device
* pdevice
,
1898 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1900 int num_queue_families
= 1;
1902 if (pdevice
->rad_info
.num_rings
[RING_COMPUTE
] > 0 &&
1903 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1904 num_queue_families
++;
1906 if (pQueueFamilyProperties
== NULL
) {
1907 *pCount
= num_queue_families
;
1916 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1917 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1918 VK_QUEUE_COMPUTE_BIT
|
1919 VK_QUEUE_TRANSFER_BIT
|
1920 VK_QUEUE_SPARSE_BINDING_BIT
,
1922 .timestampValidBits
= 64,
1923 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1928 if (pdevice
->rad_info
.num_rings
[RING_COMPUTE
] > 0 &&
1929 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1930 if (*pCount
> idx
) {
1931 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1932 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1933 VK_QUEUE_TRANSFER_BIT
|
1934 VK_QUEUE_SPARSE_BINDING_BIT
,
1935 .queueCount
= pdevice
->rad_info
.num_rings
[RING_COMPUTE
],
1936 .timestampValidBits
= 64,
1937 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1945 void radv_GetPhysicalDeviceQueueFamilyProperties(
1946 VkPhysicalDevice physicalDevice
,
1948 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1950 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1951 if (!pQueueFamilyProperties
) {
1952 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1955 VkQueueFamilyProperties
*properties
[] = {
1956 pQueueFamilyProperties
+ 0,
1957 pQueueFamilyProperties
+ 1,
1958 pQueueFamilyProperties
+ 2,
1960 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1961 assert(*pCount
<= 3);
1964 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1965 VkPhysicalDevice physicalDevice
,
1967 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1969 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1970 if (!pQueueFamilyProperties
) {
1971 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1974 VkQueueFamilyProperties
*properties
[] = {
1975 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1976 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1977 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1979 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1980 assert(*pCount
<= 3);
1983 void radv_GetPhysicalDeviceMemoryProperties(
1984 VkPhysicalDevice physicalDevice
,
1985 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1987 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1989 *pMemoryProperties
= physical_device
->memory_properties
;
1993 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1994 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1996 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1997 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1998 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1999 uint64_t vram_size
= radv_get_vram_size(device
);
2000 uint64_t gtt_size
= device
->rad_info
.gart_size
;
2001 uint64_t heap_budget
, heap_usage
;
2003 /* For all memory heaps, the computation of budget is as follow:
2004 * heap_budget = heap_size - global_heap_usage + app_heap_usage
2006 * The Vulkan spec 1.1.97 says that the budget should include any
2007 * currently allocated device memory.
2009 * Note that the application heap usages are not really accurate (eg.
2010 * in presence of shared buffers).
2012 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
2013 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
2015 if ((device
->memory_domains
[i
] & RADEON_DOMAIN_VRAM
) && (device
->memory_flags
[i
] & RADEON_FLAG_NO_CPU_ACCESS
)) {
2016 heap_usage
= device
->ws
->query_value(device
->ws
,
2017 RADEON_ALLOCATED_VRAM
);
2019 heap_budget
= vram_size
-
2020 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
2023 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2024 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2025 } else if (device
->memory_domains
[i
] & RADEON_DOMAIN_VRAM
) {
2026 heap_usage
= device
->ws
->query_value(device
->ws
,
2027 RADEON_ALLOCATED_VRAM_VIS
);
2029 heap_budget
= visible_vram_size
-
2030 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
2033 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2034 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2036 assert(device
->memory_domains
[i
] & RADEON_DOMAIN_GTT
);
2038 heap_usage
= device
->ws
->query_value(device
->ws
,
2039 RADEON_ALLOCATED_GTT
);
2041 heap_budget
= gtt_size
-
2042 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
2045 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2046 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2050 /* The heapBudget and heapUsage values must be zero for array elements
2051 * greater than or equal to
2052 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
2054 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
2055 memoryBudget
->heapBudget
[i
] = 0;
2056 memoryBudget
->heapUsage
[i
] = 0;
2060 void radv_GetPhysicalDeviceMemoryProperties2(
2061 VkPhysicalDevice physicalDevice
,
2062 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
2064 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
2065 &pMemoryProperties
->memoryProperties
);
2067 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
2068 vk_find_struct(pMemoryProperties
->pNext
,
2069 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
2071 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
2074 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
2076 VkExternalMemoryHandleTypeFlagBits handleType
,
2077 const void *pHostPointer
,
2078 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
2080 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2084 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
2085 const struct radv_physical_device
*physical_device
= device
->physical_device
;
2086 uint32_t memoryTypeBits
= 0;
2087 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
2088 if (physical_device
->memory_domains
[i
] == RADEON_DOMAIN_GTT
&&
2089 !(physical_device
->memory_flags
[i
] & RADEON_FLAG_GTT_WC
)) {
2090 memoryTypeBits
= (1 << i
);
2094 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
2098 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
2102 static enum radeon_ctx_priority
2103 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
2105 /* Default to MEDIUM when a specific global priority isn't requested */
2107 return RADEON_CTX_PRIORITY_MEDIUM
;
2109 switch(pObj
->globalPriority
) {
2110 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2111 return RADEON_CTX_PRIORITY_REALTIME
;
2112 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2113 return RADEON_CTX_PRIORITY_HIGH
;
2114 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2115 return RADEON_CTX_PRIORITY_MEDIUM
;
2116 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2117 return RADEON_CTX_PRIORITY_LOW
;
2119 unreachable("Illegal global priority value");
2120 return RADEON_CTX_PRIORITY_INVALID
;
2125 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
2126 uint32_t queue_family_index
, int idx
,
2127 VkDeviceQueueCreateFlags flags
,
2128 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
2130 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2131 queue
->device
= device
;
2132 queue
->queue_family_index
= queue_family_index
;
2133 queue
->queue_idx
= idx
;
2134 queue
->priority
= radv_get_queue_global_priority(global_priority
);
2135 queue
->flags
= flags
;
2137 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
2139 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2141 list_inithead(&queue
->pending_submissions
);
2142 pthread_mutex_init(&queue
->pending_mutex
, NULL
);
2148 radv_queue_finish(struct radv_queue
*queue
)
2150 pthread_mutex_destroy(&queue
->pending_mutex
);
2153 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
2155 if (queue
->initial_full_flush_preamble_cs
)
2156 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2157 if (queue
->initial_preamble_cs
)
2158 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2159 if (queue
->continue_preamble_cs
)
2160 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2161 if (queue
->descriptor_bo
)
2162 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2163 if (queue
->scratch_bo
)
2164 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2165 if (queue
->esgs_ring_bo
)
2166 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2167 if (queue
->gsvs_ring_bo
)
2168 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2169 if (queue
->tess_rings_bo
)
2170 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
2172 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
2173 if (queue
->gds_oa_bo
)
2174 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
2175 if (queue
->compute_scratch_bo
)
2176 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2180 radv_bo_list_init(struct radv_bo_list
*bo_list
)
2182 pthread_mutex_init(&bo_list
->mutex
, NULL
);
2183 bo_list
->list
.count
= bo_list
->capacity
= 0;
2184 bo_list
->list
.bos
= NULL
;
2188 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
2190 free(bo_list
->list
.bos
);
2191 pthread_mutex_destroy(&bo_list
->mutex
);
2194 VkResult
radv_bo_list_add(struct radv_device
*device
,
2195 struct radeon_winsys_bo
*bo
)
2197 struct radv_bo_list
*bo_list
= &device
->bo_list
;
2202 if (unlikely(!device
->use_global_bo_list
))
2205 pthread_mutex_lock(&bo_list
->mutex
);
2206 if (bo_list
->list
.count
== bo_list
->capacity
) {
2207 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
2208 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
2211 pthread_mutex_unlock(&bo_list
->mutex
);
2212 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2215 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
2216 bo_list
->capacity
= capacity
;
2219 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
2220 pthread_mutex_unlock(&bo_list
->mutex
);
2224 void radv_bo_list_remove(struct radv_device
*device
,
2225 struct radeon_winsys_bo
*bo
)
2227 struct radv_bo_list
*bo_list
= &device
->bo_list
;
2232 if (unlikely(!device
->use_global_bo_list
))
2235 pthread_mutex_lock(&bo_list
->mutex
);
2236 /* Loop the list backwards so we find the most recently added
2238 for(unsigned i
= bo_list
->list
.count
; i
-- > 0;) {
2239 if (bo_list
->list
.bos
[i
] == bo
) {
2240 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
2241 --bo_list
->list
.count
;
2245 pthread_mutex_unlock(&bo_list
->mutex
);
2249 radv_device_init_gs_info(struct radv_device
*device
)
2251 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
2252 device
->physical_device
->rad_info
.family
);
2255 static int radv_get_device_extension_index(const char *name
)
2257 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
2258 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
2265 radv_get_int_debug_option(const char *name
, int default_value
)
2272 result
= default_value
;
2276 result
= strtol(str
, &endptr
, 0);
2277 if (str
== endptr
) {
2278 /* No digits founs. */
2279 result
= default_value
;
2286 static int install_seccomp_filter() {
2288 struct sock_filter filter
[] = {
2289 /* Check arch is 64bit x86 */
2290 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, arch
))),
2291 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, AUDIT_ARCH_X86_64
, 0, 12),
2293 /* Futex is required for mutex locks */
2294 #if defined __NR__newselect
2295 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2296 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR__newselect
, 11, 0),
2297 #elif defined __NR_select
2298 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2299 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_select
, 11, 0),
2301 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2302 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_pselect6
, 11, 0),
2305 /* Allow system exit calls for the forked process */
2306 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2307 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_exit_group
, 9, 0),
2309 /* Allow system read calls */
2310 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2311 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_read
, 7, 0),
2313 /* Allow system write calls */
2314 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2315 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_write
, 5, 0),
2317 /* Allow system brk calls (we need this for malloc) */
2318 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2319 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_brk
, 3, 0),
2321 /* Futex is required for mutex locks */
2322 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2323 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_futex
, 1, 0),
2325 /* Return error if we hit a system call not on the whitelist */
2326 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ERRNO
| (EPERM
& SECCOMP_RET_DATA
)),
2328 /* Allow whitelisted system calls */
2329 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ALLOW
),
2332 struct sock_fprog prog
= {
2333 .len
= (unsigned short)(sizeof(filter
) / sizeof(filter
[0])),
2337 if (prctl(PR_SET_NO_NEW_PRIVS
, 1, 0, 0, 0))
2340 if (prctl(PR_SET_SECCOMP
, SECCOMP_MODE_FILTER
, &prog
))
2346 /* Helper function with timeout support for reading from the pipe between
2347 * processes used for secure compile.
2349 bool radv_sc_read(int fd
, void *buf
, size_t size
, bool timeout
)
2358 /* We can't rely on the value of tv after calling select() so
2359 * we must reset it on each iteration of the loop.
2364 int rval
= select(fd
+ 1, &fds
, NULL
, NULL
, timeout
? &tv
: NULL
);
2370 ssize_t bytes_read
= read(fd
, buf
, size
);
2379 /* select timeout */
2385 static bool radv_close_all_fds(const int *keep_fds
, int keep_fd_count
)
2389 d
= opendir("/proc/self/fd");
2392 int dir_fd
= dirfd(d
);
2394 while ((dir
= readdir(d
)) != NULL
) {
2395 if (dir
->d_name
[0] == '.')
2398 int fd
= atoi(dir
->d_name
);
2403 for (int i
= 0; !keep
&& i
< keep_fd_count
; ++i
)
2404 if (keep_fds
[i
] == fd
)
2416 static bool secure_compile_open_fifo_fds(struct radv_secure_compile_state
*sc
,
2417 int *fd_server
, int *fd_client
,
2418 unsigned process
, bool make_fifo
)
2420 bool result
= false;
2421 char *fifo_server_path
= NULL
;
2422 char *fifo_client_path
= NULL
;
2424 if (asprintf(&fifo_server_path
, "/tmp/radv_server_%s_%u", sc
->uid
, process
) == -1)
2425 goto open_fifo_exit
;
2427 if (asprintf(&fifo_client_path
, "/tmp/radv_client_%s_%u", sc
->uid
, process
) == -1)
2428 goto open_fifo_exit
;
2431 int file1
= mkfifo(fifo_server_path
, 0666);
2433 goto open_fifo_exit
;
2435 int file2
= mkfifo(fifo_client_path
, 0666);
2437 goto open_fifo_exit
;
2440 *fd_server
= open(fifo_server_path
, O_RDWR
);
2442 goto open_fifo_exit
;
2444 *fd_client
= open(fifo_client_path
, O_RDWR
);
2445 if(*fd_client
< 1) {
2447 goto open_fifo_exit
;
2453 free(fifo_server_path
);
2454 free(fifo_client_path
);
2459 static void run_secure_compile_device(struct radv_device
*device
, unsigned process
,
2460 int fd_idle_device_output
)
2462 int fd_secure_input
;
2463 int fd_secure_output
;
2464 bool fifo_result
= secure_compile_open_fifo_fds(device
->sc_state
,
2469 enum radv_secure_compile_type sc_type
;
2471 const int needed_fds
[] = {
2474 fd_idle_device_output
,
2477 if (!fifo_result
|| !radv_close_all_fds(needed_fds
, ARRAY_SIZE(needed_fds
)) ||
2478 install_seccomp_filter() == -1) {
2479 sc_type
= RADV_SC_TYPE_INIT_FAILURE
;
2481 sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2482 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
;
2483 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
;
2486 write(fd_idle_device_output
, &sc_type
, sizeof(sc_type
));
2488 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2489 goto secure_compile_exit
;
2492 radv_sc_read(fd_secure_input
, &sc_type
, sizeof(sc_type
), false);
2494 if (sc_type
== RADV_SC_TYPE_COMPILE_PIPELINE
) {
2495 struct radv_pipeline
*pipeline
;
2496 bool sc_read
= true;
2498 pipeline
= vk_zalloc2(&device
->alloc
, NULL
, sizeof(*pipeline
), 8,
2499 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2501 pipeline
->device
= device
;
2503 /* Read pipeline layout */
2504 struct radv_pipeline_layout layout
;
2505 sc_read
= radv_sc_read(fd_secure_input
, &layout
, sizeof(struct radv_pipeline_layout
), true);
2506 sc_read
&= radv_sc_read(fd_secure_input
, &layout
.num_sets
, sizeof(uint32_t), true);
2508 goto secure_compile_exit
;
2510 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++) {
2511 uint32_t layout_size
;
2512 sc_read
&= radv_sc_read(fd_secure_input
, &layout_size
, sizeof(uint32_t), true);
2514 goto secure_compile_exit
;
2516 layout
.set
[set
].layout
= malloc(layout_size
);
2517 layout
.set
[set
].layout
->layout_size
= layout_size
;
2518 sc_read
&= radv_sc_read(fd_secure_input
, layout
.set
[set
].layout
,
2519 layout
.set
[set
].layout
->layout_size
, true);
2522 pipeline
->layout
= &layout
;
2524 /* Read pipeline key */
2525 struct radv_pipeline_key key
;
2526 sc_read
&= radv_sc_read(fd_secure_input
, &key
, sizeof(struct radv_pipeline_key
), true);
2528 /* Read pipeline create flags */
2529 VkPipelineCreateFlags flags
;
2530 sc_read
&= radv_sc_read(fd_secure_input
, &flags
, sizeof(VkPipelineCreateFlags
), true);
2532 /* Read stage and shader information */
2533 uint32_t num_stages
;
2534 const VkPipelineShaderStageCreateInfo
*pStages
[MESA_SHADER_STAGES
] = { 0, };
2535 sc_read
&= radv_sc_read(fd_secure_input
, &num_stages
, sizeof(uint32_t), true);
2537 goto secure_compile_exit
;
2539 for (uint32_t i
= 0; i
< num_stages
; i
++) {
2542 gl_shader_stage stage
;
2543 sc_read
&= radv_sc_read(fd_secure_input
, &stage
, sizeof(gl_shader_stage
), true);
2545 VkPipelineShaderStageCreateInfo
*pStage
= calloc(1, sizeof(VkPipelineShaderStageCreateInfo
));
2547 /* Read entry point name */
2549 sc_read
&= radv_sc_read(fd_secure_input
, &name_size
, sizeof(size_t), true);
2551 goto secure_compile_exit
;
2553 char *ep_name
= malloc(name_size
);
2554 sc_read
&= radv_sc_read(fd_secure_input
, ep_name
, name_size
, true);
2555 pStage
->pName
= ep_name
;
2557 /* Read shader module */
2559 sc_read
&= radv_sc_read(fd_secure_input
, &module_size
, sizeof(size_t), true);
2561 goto secure_compile_exit
;
2563 struct radv_shader_module
*module
= malloc(module_size
);
2564 sc_read
&= radv_sc_read(fd_secure_input
, module
, module_size
, true);
2565 pStage
->module
= radv_shader_module_to_handle(module
);
2567 /* Read specialization info */
2569 sc_read
&= radv_sc_read(fd_secure_input
, &has_spec_info
, sizeof(bool), true);
2571 goto secure_compile_exit
;
2573 if (has_spec_info
) {
2574 VkSpecializationInfo
*specInfo
= malloc(sizeof(VkSpecializationInfo
));
2575 pStage
->pSpecializationInfo
= specInfo
;
2577 sc_read
&= radv_sc_read(fd_secure_input
, &specInfo
->dataSize
, sizeof(size_t), true);
2579 goto secure_compile_exit
;
2581 void *si_data
= malloc(specInfo
->dataSize
);
2582 sc_read
&= radv_sc_read(fd_secure_input
, si_data
, specInfo
->dataSize
, true);
2583 specInfo
->pData
= si_data
;
2585 sc_read
&= radv_sc_read(fd_secure_input
, &specInfo
->mapEntryCount
, sizeof(uint32_t), true);
2587 goto secure_compile_exit
;
2589 VkSpecializationMapEntry
*mapEntries
= malloc(sizeof(VkSpecializationMapEntry
) * specInfo
->mapEntryCount
);
2590 for (uint32_t j
= 0; j
< specInfo
->mapEntryCount
; j
++) {
2591 sc_read
&= radv_sc_read(fd_secure_input
, &mapEntries
[j
], sizeof(VkSpecializationMapEntry
), true);
2593 goto secure_compile_exit
;
2596 specInfo
->pMapEntries
= mapEntries
;
2599 pStages
[stage
] = pStage
;
2602 /* Compile the shaders */
2603 VkPipelineCreationFeedbackEXT
*stage_feedbacks
[MESA_SHADER_STAGES
] = { 0 };
2604 radv_create_shaders(pipeline
, device
, NULL
, &key
, pStages
, flags
, NULL
, stage_feedbacks
);
2606 /* free memory allocated above */
2607 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++)
2608 free(layout
.set
[set
].layout
);
2610 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
2614 free((void *) pStages
[i
]->pName
);
2615 free(radv_shader_module_from_handle(pStages
[i
]->module
));
2616 if (pStages
[i
]->pSpecializationInfo
) {
2617 free((void *) pStages
[i
]->pSpecializationInfo
->pData
);
2618 free((void *) pStages
[i
]->pSpecializationInfo
->pMapEntries
);
2619 free((void *) pStages
[i
]->pSpecializationInfo
);
2621 free((void *) pStages
[i
]);
2624 vk_free(&device
->alloc
, pipeline
);
2626 sc_type
= RADV_SC_TYPE_COMPILE_PIPELINE_FINISHED
;
2627 write(fd_secure_output
, &sc_type
, sizeof(sc_type
));
2629 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2630 goto secure_compile_exit
;
2634 secure_compile_exit
:
2635 close(fd_secure_input
);
2636 close(fd_secure_output
);
2637 close(fd_idle_device_output
);
2641 static enum radv_secure_compile_type
fork_secure_compile_device(struct radv_device
*device
, unsigned process
)
2643 int fd_secure_input
[2];
2644 int fd_secure_output
[2];
2646 /* create pipe descriptors (used to communicate between processes) */
2647 if (pipe(fd_secure_input
) == -1 || pipe(fd_secure_output
) == -1)
2648 return RADV_SC_TYPE_INIT_FAILURE
;
2652 if ((sc_pid
= fork()) == 0) {
2653 device
->sc_state
->secure_compile_thread_counter
= process
;
2654 run_secure_compile_device(device
, process
, fd_secure_output
[1]);
2657 return RADV_SC_TYPE_INIT_FAILURE
;
2659 /* Read the init result returned from the secure process */
2660 enum radv_secure_compile_type sc_type
;
2661 bool sc_read
= radv_sc_read(fd_secure_output
[0], &sc_type
, sizeof(sc_type
), true);
2663 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
) {
2664 close(fd_secure_input
[0]);
2665 close(fd_secure_input
[1]);
2666 close(fd_secure_output
[1]);
2667 close(fd_secure_output
[0]);
2669 waitpid(sc_pid
, &status
, 0);
2671 return RADV_SC_TYPE_INIT_FAILURE
;
2673 assert(sc_type
== RADV_SC_TYPE_INIT_SUCCESS
);
2674 write(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
, &sc_type
, sizeof(sc_type
));
2676 close(fd_secure_input
[0]);
2677 close(fd_secure_input
[1]);
2678 close(fd_secure_output
[1]);
2679 close(fd_secure_output
[0]);
2682 waitpid(sc_pid
, &status
, 0);
2686 return RADV_SC_TYPE_INIT_SUCCESS
;
2689 /* Run a bare bones fork of a device that was forked right after its creation.
2690 * This device will have low overhead when it is forked again before each
2691 * pipeline compilation. This device sits idle and its only job is to fork
2694 static void run_secure_compile_idle_device(struct radv_device
*device
, unsigned process
,
2695 int fd_secure_input
, int fd_secure_output
)
2697 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2698 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
;
2699 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
;
2701 write(fd_secure_output
, &sc_type
, sizeof(sc_type
));
2704 radv_sc_read(fd_secure_input
, &sc_type
, sizeof(sc_type
), false);
2706 if (sc_type
== RADV_SC_TYPE_FORK_DEVICE
) {
2707 sc_type
= fork_secure_compile_device(device
, process
);
2709 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2710 goto secure_compile_exit
;
2712 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2713 goto secure_compile_exit
;
2717 secure_compile_exit
:
2718 close(fd_secure_input
);
2719 close(fd_secure_output
);
2723 static void destroy_secure_compile_device(struct radv_device
*device
, unsigned process
)
2725 int fd_secure_input
= device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
;
2727 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_DESTROY_DEVICE
;
2728 write(fd_secure_input
, &sc_type
, sizeof(sc_type
));
2730 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
);
2731 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
);
2734 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2737 static VkResult
fork_secure_compile_idle_device(struct radv_device
*device
)
2739 device
->sc_state
= vk_zalloc(&device
->alloc
,
2740 sizeof(struct radv_secure_compile_state
),
2741 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2743 mtx_init(&device
->sc_state
->secure_compile_mutex
, mtx_plain
);
2745 pid_t upid
= getpid();
2746 time_t seconds
= time(NULL
);
2749 if (asprintf(&uid
, "%ld_%ld", (long) upid
, (long) seconds
) == -1)
2750 return VK_ERROR_INITIALIZATION_FAILED
;
2752 device
->sc_state
->uid
= uid
;
2754 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
2755 int fd_secure_input
[MAX_SC_PROCS
][2];
2756 int fd_secure_output
[MAX_SC_PROCS
][2];
2758 /* create pipe descriptors (used to communicate between processes) */
2759 for (unsigned i
= 0; i
< sc_threads
; i
++) {
2760 if (pipe(fd_secure_input
[i
]) == -1 ||
2761 pipe(fd_secure_output
[i
]) == -1) {
2762 return VK_ERROR_INITIALIZATION_FAILED
;
2766 device
->sc_state
->secure_compile_processes
= vk_zalloc(&device
->alloc
,
2767 sizeof(struct radv_secure_compile_process
) * sc_threads
, 8,
2768 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2770 for (unsigned process
= 0; process
< sc_threads
; process
++) {
2771 if ((device
->sc_state
->secure_compile_processes
[process
].sc_pid
= fork()) == 0) {
2772 device
->sc_state
->secure_compile_thread_counter
= process
;
2773 run_secure_compile_idle_device(device
, process
, fd_secure_input
[process
][0], fd_secure_output
[process
][1]);
2775 if (device
->sc_state
->secure_compile_processes
[process
].sc_pid
== -1)
2776 return VK_ERROR_INITIALIZATION_FAILED
;
2778 /* Read the init result returned from the secure process */
2779 enum radv_secure_compile_type sc_type
;
2780 bool sc_read
= radv_sc_read(fd_secure_output
[process
][0], &sc_type
, sizeof(sc_type
), true);
2783 if (sc_read
&& sc_type
== RADV_SC_TYPE_INIT_SUCCESS
) {
2784 fifo_result
= secure_compile_open_fifo_fds(device
->sc_state
,
2785 &device
->sc_state
->secure_compile_processes
[process
].fd_server
,
2786 &device
->sc_state
->secure_compile_processes
[process
].fd_client
,
2789 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
[process
][1];
2790 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
[process
][0];
2793 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
|| !fifo_result
) {
2794 close(fd_secure_input
[process
][0]);
2795 close(fd_secure_input
[process
][1]);
2796 close(fd_secure_output
[process
][1]);
2797 close(fd_secure_output
[process
][0]);
2799 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2801 /* Destroy any forks that were created sucessfully */
2802 for (unsigned i
= 0; i
< process
; i
++) {
2803 destroy_secure_compile_device(device
, i
);
2806 return VK_ERROR_INITIALIZATION_FAILED
;
2814 radv_device_init_dispatch(struct radv_device
*device
)
2816 const struct radv_instance
*instance
= device
->physical_device
->instance
;
2817 const struct radv_device_dispatch_table
*dispatch_table_layer
= NULL
;
2818 bool unchecked
= instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
;
2819 int radv_thread_trace
= radv_get_int_debug_option("RADV_THREAD_TRACE", -1);
2821 if (radv_thread_trace
>= 0) {
2822 /* Use device entrypoints from the SQTT layer if enabled. */
2823 dispatch_table_layer
= &sqtt_device_dispatch_table
;
2826 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2827 /* Vulkan requires that entrypoints for extensions which have not been
2828 * enabled must not be advertised.
2831 !radv_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
2832 &instance
->enabled_extensions
,
2833 &device
->enabled_extensions
)) {
2834 device
->dispatch
.entrypoints
[i
] = NULL
;
2835 } else if (dispatch_table_layer
&&
2836 dispatch_table_layer
->entrypoints
[i
]) {
2837 device
->dispatch
.entrypoints
[i
] =
2838 dispatch_table_layer
->entrypoints
[i
];
2840 device
->dispatch
.entrypoints
[i
] =
2841 radv_device_dispatch_table
.entrypoints
[i
];
2847 radv_create_pthread_cond(pthread_cond_t
*cond
)
2849 pthread_condattr_t condattr
;
2850 if (pthread_condattr_init(&condattr
)) {
2851 return VK_ERROR_INITIALIZATION_FAILED
;
2854 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
)) {
2855 pthread_condattr_destroy(&condattr
);
2856 return VK_ERROR_INITIALIZATION_FAILED
;
2858 if (pthread_cond_init(cond
, &condattr
)) {
2859 pthread_condattr_destroy(&condattr
);
2860 return VK_ERROR_INITIALIZATION_FAILED
;
2862 pthread_condattr_destroy(&condattr
);
2867 check_physical_device_features(VkPhysicalDevice physicalDevice
,
2868 const VkPhysicalDeviceFeatures
*features
)
2870 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2871 VkPhysicalDeviceFeatures supported_features
;
2872 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2873 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2874 VkBool32
*enabled_feature
= (VkBool32
*)features
;
2875 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2876 for (uint32_t i
= 0; i
< num_features
; i
++) {
2877 if (enabled_feature
[i
] && !supported_feature
[i
])
2878 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
2884 VkResult
radv_CreateDevice(
2885 VkPhysicalDevice physicalDevice
,
2886 const VkDeviceCreateInfo
* pCreateInfo
,
2887 const VkAllocationCallbacks
* pAllocator
,
2890 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2892 struct radv_device
*device
;
2894 bool keep_shader_info
= false;
2895 bool robust_buffer_access
= false;
2896 bool overallocation_disallowed
= false;
2898 /* Check enabled features */
2899 if (pCreateInfo
->pEnabledFeatures
) {
2900 result
= check_physical_device_features(physicalDevice
,
2901 pCreateInfo
->pEnabledFeatures
);
2902 if (result
!= VK_SUCCESS
)
2905 if (pCreateInfo
->pEnabledFeatures
->robustBufferAccess
)
2906 robust_buffer_access
= true;
2909 vk_foreach_struct_const(ext
, pCreateInfo
->pNext
) {
2910 switch (ext
->sType
) {
2911 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2
: {
2912 const VkPhysicalDeviceFeatures2
*features
= (const void *)ext
;
2913 result
= check_physical_device_features(physicalDevice
,
2914 &features
->features
);
2915 if (result
!= VK_SUCCESS
)
2918 if (features
->features
.robustBufferAccess
)
2919 robust_buffer_access
= true;
2922 case VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD
: {
2923 const VkDeviceMemoryOverallocationCreateInfoAMD
*overallocation
= (const void *)ext
;
2924 if (overallocation
->overallocationBehavior
== VK_MEMORY_OVERALLOCATION_BEHAVIOR_DISALLOWED_AMD
)
2925 overallocation_disallowed
= true;
2933 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
2935 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2937 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2939 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2940 device
->instance
= physical_device
->instance
;
2941 device
->physical_device
= physical_device
;
2943 device
->ws
= physical_device
->ws
;
2945 device
->alloc
= *pAllocator
;
2947 device
->alloc
= physical_device
->instance
->alloc
;
2949 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
2950 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
2951 int index
= radv_get_device_extension_index(ext_name
);
2952 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
2953 vk_free(&device
->alloc
, device
);
2954 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
2957 device
->enabled_extensions
.extensions
[index
] = true;
2960 radv_device_init_dispatch(device
);
2962 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
2964 /* With update after bind we can't attach bo's to the command buffer
2965 * from the descriptor set anymore, so we have to use a global BO list.
2967 device
->use_global_bo_list
=
2968 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
2969 device
->enabled_extensions
.EXT_descriptor_indexing
||
2970 device
->enabled_extensions
.EXT_buffer_device_address
||
2971 device
->enabled_extensions
.KHR_buffer_device_address
;
2973 device
->robust_buffer_access
= robust_buffer_access
;
2975 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
2976 list_inithead(&device
->shader_slabs
);
2978 device
->overallocation_disallowed
= overallocation_disallowed
;
2979 mtx_init(&device
->overallocation_mutex
, mtx_plain
);
2981 radv_bo_list_init(&device
->bo_list
);
2983 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
2984 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
2985 uint32_t qfi
= queue_create
->queueFamilyIndex
;
2986 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
2987 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
2989 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
2991 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
2992 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2993 if (!device
->queues
[qfi
]) {
2994 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
2998 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
3000 device
->queue_count
[qfi
] = queue_create
->queueCount
;
3002 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
3003 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
3004 qfi
, q
, queue_create
->flags
,
3006 if (result
!= VK_SUCCESS
)
3011 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
3012 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
3014 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
3015 device
->dfsm_allowed
= device
->pbb_allowed
&&
3016 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
3018 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
3020 /* The maximum number of scratch waves. Scratch space isn't divided
3021 * evenly between CUs. The number is only a function of the number of CUs.
3022 * We can decrease the constant to decrease the scratch buffer size.
3024 * sctx->scratch_waves must be >= the maximum possible size of
3025 * 1 threadgroup, so that the hw doesn't hang from being unable
3028 * The recommended value is 4 per CU at most. Higher numbers don't
3029 * bring much benefit, but they still occupy chip resources (think
3030 * async compute). I've seen ~2% performance difference between 4 and 32.
3032 uint32_t max_threads_per_block
= 2048;
3033 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
3034 max_threads_per_block
/ 64);
3036 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
3038 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3039 /* If the KMD allows it (there is a KMD hw register for it),
3040 * allow launching waves out-of-order.
3042 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
3045 radv_device_init_gs_info(device
);
3047 device
->tess_offchip_block_dw_size
=
3048 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
3050 if (getenv("RADV_TRACE_FILE")) {
3051 const char *filename
= getenv("RADV_TRACE_FILE");
3053 keep_shader_info
= true;
3055 if (!radv_init_trace(device
))
3058 fprintf(stderr
, "*****************************************************************************\n");
3059 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
3060 fprintf(stderr
, "*****************************************************************************\n");
3062 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
3063 radv_dump_enabled_options(device
, stderr
);
3066 int radv_thread_trace
= radv_get_int_debug_option("RADV_THREAD_TRACE", -1);
3067 if (radv_thread_trace
>= 0) {
3068 fprintf(stderr
, "*************************************************\n");
3069 fprintf(stderr
, "* WARNING: Thread trace support is experimental *\n");
3070 fprintf(stderr
, "*************************************************\n");
3072 if (device
->physical_device
->rad_info
.chip_class
< GFX8
) {
3073 fprintf(stderr
, "GPU hardware not supported: refer to "
3074 "the RGP documentation for the list of "
3075 "supported GPUs!\n");
3079 /* Default buffer size set to 1MB per SE. */
3080 device
->thread_trace_buffer_size
=
3081 radv_get_int_debug_option("RADV_THREAD_TRACE_BUFFER_SIZE", 1024 * 1024);
3082 device
->thread_trace_start_frame
= radv_thread_trace
;
3084 if (!radv_thread_trace_init(device
))
3088 /* Temporarily disable secure compile while we create meta shaders, etc */
3089 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
3091 device
->instance
->num_sc_threads
= 0;
3093 device
->keep_shader_info
= keep_shader_info
;
3094 result
= radv_device_init_meta(device
);
3095 if (result
!= VK_SUCCESS
)
3098 radv_device_init_msaa(device
);
3100 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
3101 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
3103 case RADV_QUEUE_GENERAL
:
3104 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
3105 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
3106 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
3108 case RADV_QUEUE_COMPUTE
:
3109 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
3110 radeon_emit(device
->empty_cs
[family
], 0);
3113 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
3116 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
3117 cik_create_gfx_config(device
);
3119 VkPipelineCacheCreateInfo ci
;
3120 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
3123 ci
.pInitialData
= NULL
;
3124 ci
.initialDataSize
= 0;
3126 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
3128 if (result
!= VK_SUCCESS
)
3131 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
3133 result
= radv_create_pthread_cond(&device
->timeline_cond
);
3134 if (result
!= VK_SUCCESS
)
3135 goto fail_mem_cache
;
3137 device
->force_aniso
=
3138 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
3139 if (device
->force_aniso
>= 0) {
3140 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
3141 1 << util_logbase2(device
->force_aniso
));
3144 /* Fork device for secure compile as required */
3145 device
->instance
->num_sc_threads
= sc_threads
;
3146 if (radv_device_use_secure_compile(device
->instance
)) {
3148 result
= fork_secure_compile_idle_device(device
);
3149 if (result
!= VK_SUCCESS
)
3153 *pDevice
= radv_device_to_handle(device
);
3157 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
3159 radv_device_finish_meta(device
);
3161 radv_bo_list_finish(&device
->bo_list
);
3163 radv_thread_trace_finish(device
);
3165 if (device
->trace_bo
)
3166 device
->ws
->buffer_destroy(device
->trace_bo
);
3168 if (device
->gfx_init
)
3169 device
->ws
->buffer_destroy(device
->gfx_init
);
3171 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3172 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
3173 radv_queue_finish(&device
->queues
[i
][q
]);
3174 if (device
->queue_count
[i
])
3175 vk_free(&device
->alloc
, device
->queues
[i
]);
3178 vk_free(&device
->alloc
, device
);
3182 void radv_DestroyDevice(
3184 const VkAllocationCallbacks
* pAllocator
)
3186 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3191 if (device
->trace_bo
)
3192 device
->ws
->buffer_destroy(device
->trace_bo
);
3194 if (device
->gfx_init
)
3195 device
->ws
->buffer_destroy(device
->gfx_init
);
3197 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3198 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
3199 radv_queue_finish(&device
->queues
[i
][q
]);
3200 if (device
->queue_count
[i
])
3201 vk_free(&device
->alloc
, device
->queues
[i
]);
3202 if (device
->empty_cs
[i
])
3203 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
3205 radv_device_finish_meta(device
);
3207 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
3208 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
3210 radv_destroy_shader_slabs(device
);
3212 pthread_cond_destroy(&device
->timeline_cond
);
3213 radv_bo_list_finish(&device
->bo_list
);
3215 radv_thread_trace_finish(device
);
3217 if (radv_device_use_secure_compile(device
->instance
)) {
3218 for (unsigned i
= 0; i
< device
->instance
->num_sc_threads
; i
++ ) {
3219 destroy_secure_compile_device(device
, i
);
3223 if (device
->sc_state
) {
3224 free(device
->sc_state
->uid
);
3225 vk_free(&device
->alloc
, device
->sc_state
->secure_compile_processes
);
3227 vk_free(&device
->alloc
, device
->sc_state
);
3228 vk_free(&device
->alloc
, device
);
3231 VkResult
radv_EnumerateInstanceLayerProperties(
3232 uint32_t* pPropertyCount
,
3233 VkLayerProperties
* pProperties
)
3235 if (pProperties
== NULL
) {
3236 *pPropertyCount
= 0;
3240 /* None supported at this time */
3241 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
3244 VkResult
radv_EnumerateDeviceLayerProperties(
3245 VkPhysicalDevice physicalDevice
,
3246 uint32_t* pPropertyCount
,
3247 VkLayerProperties
* pProperties
)
3249 if (pProperties
== NULL
) {
3250 *pPropertyCount
= 0;
3254 /* None supported at this time */
3255 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
3258 void radv_GetDeviceQueue2(
3260 const VkDeviceQueueInfo2
* pQueueInfo
,
3263 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3264 struct radv_queue
*queue
;
3266 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
3267 if (pQueueInfo
->flags
!= queue
->flags
) {
3268 /* From the Vulkan 1.1.70 spec:
3270 * "The queue returned by vkGetDeviceQueue2 must have the same
3271 * flags value from this structure as that used at device
3272 * creation time in a VkDeviceQueueCreateInfo instance. If no
3273 * matching flags were specified at device creation time then
3274 * pQueue will return VK_NULL_HANDLE."
3276 *pQueue
= VK_NULL_HANDLE
;
3280 *pQueue
= radv_queue_to_handle(queue
);
3283 void radv_GetDeviceQueue(
3285 uint32_t queueFamilyIndex
,
3286 uint32_t queueIndex
,
3289 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
3290 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
3291 .queueFamilyIndex
= queueFamilyIndex
,
3292 .queueIndex
= queueIndex
3295 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
3299 fill_geom_tess_rings(struct radv_queue
*queue
,
3301 bool add_sample_positions
,
3302 uint32_t esgs_ring_size
,
3303 struct radeon_winsys_bo
*esgs_ring_bo
,
3304 uint32_t gsvs_ring_size
,
3305 struct radeon_winsys_bo
*gsvs_ring_bo
,
3306 uint32_t tess_factor_ring_size
,
3307 uint32_t tess_offchip_ring_offset
,
3308 uint32_t tess_offchip_ring_size
,
3309 struct radeon_winsys_bo
*tess_rings_bo
)
3311 uint32_t *desc
= &map
[4];
3314 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
3316 /* stride 0, num records - size, add tid, swizzle, elsize4,
3319 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
3320 S_008F04_SWIZZLE_ENABLE(true);
3321 desc
[2] = esgs_ring_size
;
3322 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3323 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3324 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3325 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
3326 S_008F0C_INDEX_STRIDE(3) |
3327 S_008F0C_ADD_TID_ENABLE(1);
3329 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3330 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3331 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3332 S_008F0C_RESOURCE_LEVEL(1);
3334 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3335 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
3336 S_008F0C_ELEMENT_SIZE(1);
3339 /* GS entry for ES->GS ring */
3340 /* stride 0, num records - size, elsize0,
3343 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
3344 desc
[6] = esgs_ring_size
;
3345 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3346 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3347 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3348 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3350 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3351 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3352 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3353 S_008F0C_RESOURCE_LEVEL(1);
3355 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3356 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3363 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
3365 /* VS entry for GS->VS ring */
3366 /* stride 0, num records - size, elsize0,
3369 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
3370 desc
[2] = gsvs_ring_size
;
3371 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3372 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3373 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3374 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3376 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3377 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3378 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3379 S_008F0C_RESOURCE_LEVEL(1);
3381 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3382 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3385 /* stride gsvs_itemsize, num records 64
3386 elsize 4, index stride 16 */
3387 /* shader will patch stride and desc[2] */
3389 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
3390 S_008F04_SWIZZLE_ENABLE(1);
3392 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3393 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3394 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3395 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
3396 S_008F0C_INDEX_STRIDE(1) |
3397 S_008F0C_ADD_TID_ENABLE(true);
3399 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3400 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3401 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3402 S_008F0C_RESOURCE_LEVEL(1);
3404 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3405 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
3406 S_008F0C_ELEMENT_SIZE(1);
3413 if (tess_rings_bo
) {
3414 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
3415 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
3418 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
3419 desc
[2] = tess_factor_ring_size
;
3420 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3421 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3422 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3423 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3425 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3426 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3427 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW
) |
3428 S_008F0C_RESOURCE_LEVEL(1);
3430 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3431 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3434 desc
[4] = tess_offchip_va
;
3435 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
3436 desc
[6] = tess_offchip_ring_size
;
3437 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3438 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3439 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3440 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3442 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3443 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3444 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW
) |
3445 S_008F0C_RESOURCE_LEVEL(1);
3447 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3448 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3454 if (add_sample_positions
) {
3455 /* add sample positions after all rings */
3456 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
3458 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
3460 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
3462 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
3467 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
3469 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
3470 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
3471 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
3472 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
3473 unsigned max_offchip_buffers
;
3474 unsigned offchip_granularity
;
3475 unsigned hs_offchip_param
;
3479 * This must be one less than the maximum number due to a hw limitation.
3480 * Various hardware bugs need thGFX7
3483 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
3484 * Gfx7 should limit max_offchip_buffers to 508
3485 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
3487 * Follow AMDVLK here.
3489 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3490 max_offchip_buffers_per_se
= 256;
3491 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
3492 device
->physical_device
->rad_info
.chip_class
== GFX7
||
3493 device
->physical_device
->rad_info
.chip_class
== GFX6
)
3494 --max_offchip_buffers_per_se
;
3496 max_offchip_buffers
= max_offchip_buffers_per_se
*
3497 device
->physical_device
->rad_info
.max_se
;
3499 /* Hawaii has a bug with offchip buffers > 256 that can be worked
3500 * around by setting 4K granularity.
3502 if (device
->tess_offchip_block_dw_size
== 4096) {
3503 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
3504 offchip_granularity
= V_03093C_X_4K_DWORDS
;
3506 assert(device
->tess_offchip_block_dw_size
== 8192);
3507 offchip_granularity
= V_03093C_X_8K_DWORDS
;
3510 switch (device
->physical_device
->rad_info
.chip_class
) {
3512 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
3517 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
3525 *max_offchip_buffers_p
= max_offchip_buffers
;
3526 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3527 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
3528 --max_offchip_buffers
;
3530 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
3531 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
3534 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
3536 return hs_offchip_param
;
3540 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3541 struct radeon_winsys_bo
*esgs_ring_bo
,
3542 uint32_t esgs_ring_size
,
3543 struct radeon_winsys_bo
*gsvs_ring_bo
,
3544 uint32_t gsvs_ring_size
)
3546 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
3550 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
3553 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
3555 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3556 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
3557 radeon_emit(cs
, esgs_ring_size
>> 8);
3558 radeon_emit(cs
, gsvs_ring_size
>> 8);
3560 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
3561 radeon_emit(cs
, esgs_ring_size
>> 8);
3562 radeon_emit(cs
, gsvs_ring_size
>> 8);
3567 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3568 unsigned hs_offchip_param
, unsigned tf_ring_size
,
3569 struct radeon_winsys_bo
*tess_rings_bo
)
3576 tf_va
= radv_buffer_get_va(tess_rings_bo
);
3578 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
3580 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3581 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
3582 S_030938_SIZE(tf_ring_size
/ 4));
3583 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
3586 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3587 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
3588 S_030984_BASE_HI(tf_va
>> 40));
3589 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3590 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
3591 S_030944_BASE_HI(tf_va
>> 40));
3593 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
3596 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
3597 S_008988_SIZE(tf_ring_size
/ 4));
3598 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
3600 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
3606 radv_emit_graphics_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3607 uint32_t size_per_wave
, uint32_t waves
,
3608 struct radeon_winsys_bo
*scratch_bo
)
3610 if (queue
->queue_family_index
!= RADV_QUEUE_GENERAL
)
3616 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
3618 radeon_set_context_reg(cs
, R_0286E8_SPI_TMPRING_SIZE
,
3619 S_0286E8_WAVES(waves
) |
3620 S_0286E8_WAVESIZE(round_up_u32(size_per_wave
, 1024)));
3624 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3625 uint32_t size_per_wave
, uint32_t waves
,
3626 struct radeon_winsys_bo
*compute_scratch_bo
)
3628 uint64_t scratch_va
;
3630 if (!compute_scratch_bo
)
3633 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
3635 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
3637 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
3638 radeon_emit(cs
, scratch_va
);
3639 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3640 S_008F04_SWIZZLE_ENABLE(1));
3642 radeon_set_sh_reg(cs
, R_00B860_COMPUTE_TMPRING_SIZE
,
3643 S_00B860_WAVES(waves
) |
3644 S_00B860_WAVESIZE(round_up_u32(size_per_wave
, 1024)));
3648 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
3649 struct radeon_cmdbuf
*cs
,
3650 struct radeon_winsys_bo
*descriptor_bo
)
3657 va
= radv_buffer_get_va(descriptor_bo
);
3659 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
3661 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3662 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3663 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3664 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3665 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3667 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3668 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3671 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3672 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3673 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3674 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3675 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3677 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3678 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3682 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3683 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3684 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
3685 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
3686 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
3687 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
3689 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3690 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3697 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3699 struct radv_device
*device
= queue
->device
;
3701 if (device
->gfx_init
) {
3702 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
3704 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
3705 radeon_emit(cs
, va
);
3706 radeon_emit(cs
, va
>> 32);
3707 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
3709 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
3711 si_emit_graphics(device
, cs
);
3716 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3718 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
3719 si_emit_compute(physical_device
, cs
);
3723 radv_get_preamble_cs(struct radv_queue
*queue
,
3724 uint32_t scratch_size_per_wave
,
3725 uint32_t scratch_waves
,
3726 uint32_t compute_scratch_size_per_wave
,
3727 uint32_t compute_scratch_waves
,
3728 uint32_t esgs_ring_size
,
3729 uint32_t gsvs_ring_size
,
3730 bool needs_tess_rings
,
3733 bool needs_sample_positions
,
3734 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
3735 struct radeon_cmdbuf
**initial_preamble_cs
,
3736 struct radeon_cmdbuf
**continue_preamble_cs
)
3738 struct radeon_winsys_bo
*scratch_bo
= NULL
;
3739 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
3740 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
3741 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
3742 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
3743 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
3744 struct radeon_winsys_bo
*gds_bo
= NULL
;
3745 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
3746 struct radeon_cmdbuf
*dest_cs
[3] = {0};
3747 bool add_tess_rings
= false, add_gds
= false, add_gds_oa
= false, add_sample_positions
= false;
3748 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
3749 unsigned max_offchip_buffers
;
3750 unsigned hs_offchip_param
= 0;
3751 unsigned tess_offchip_ring_offset
;
3752 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3753 if (!queue
->has_tess_rings
) {
3754 if (needs_tess_rings
)
3755 add_tess_rings
= true;
3757 if (!queue
->has_gds
) {
3761 if (!queue
->has_gds_oa
) {
3765 if (!queue
->has_sample_positions
) {
3766 if (needs_sample_positions
)
3767 add_sample_positions
= true;
3769 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
3770 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
3771 &max_offchip_buffers
);
3772 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
3773 tess_offchip_ring_size
= max_offchip_buffers
*
3774 queue
->device
->tess_offchip_block_dw_size
* 4;
3776 scratch_size_per_wave
= MAX2(scratch_size_per_wave
, queue
->scratch_size_per_wave
);
3777 if (scratch_size_per_wave
)
3778 scratch_waves
= MIN2(scratch_waves
, UINT32_MAX
/ scratch_size_per_wave
);
3782 compute_scratch_size_per_wave
= MAX2(compute_scratch_size_per_wave
, queue
->compute_scratch_size_per_wave
);
3783 if (compute_scratch_size_per_wave
)
3784 compute_scratch_waves
= MIN2(compute_scratch_waves
, UINT32_MAX
/ compute_scratch_size_per_wave
);
3786 compute_scratch_waves
= 0;
3788 if (scratch_size_per_wave
<= queue
->scratch_size_per_wave
&&
3789 scratch_waves
<= queue
->scratch_waves
&&
3790 compute_scratch_size_per_wave
<= queue
->compute_scratch_size_per_wave
&&
3791 compute_scratch_waves
<= queue
->compute_scratch_waves
&&
3792 esgs_ring_size
<= queue
->esgs_ring_size
&&
3793 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
3794 !add_tess_rings
&& !add_gds
&& !add_gds_oa
&& !add_sample_positions
&&
3795 queue
->initial_preamble_cs
) {
3796 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
3797 *initial_preamble_cs
= queue
->initial_preamble_cs
;
3798 *continue_preamble_cs
= queue
->continue_preamble_cs
;
3799 if (!scratch_size_per_wave
&& !compute_scratch_size_per_wave
&&
3800 !esgs_ring_size
&& !gsvs_ring_size
&& !needs_tess_rings
&&
3801 !needs_gds
&& !needs_gds_oa
&& !needs_sample_positions
)
3802 *continue_preamble_cs
= NULL
;
3806 uint32_t scratch_size
= scratch_size_per_wave
* scratch_waves
;
3807 uint32_t queue_scratch_size
= queue
->scratch_size_per_wave
* queue
->scratch_waves
;
3808 if (scratch_size
> queue_scratch_size
) {
3809 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3814 RADV_BO_PRIORITY_SCRATCH
);
3818 scratch_bo
= queue
->scratch_bo
;
3820 uint32_t compute_scratch_size
= compute_scratch_size_per_wave
* compute_scratch_waves
;
3821 uint32_t compute_queue_scratch_size
= queue
->compute_scratch_size_per_wave
* queue
->compute_scratch_waves
;
3822 if (compute_scratch_size
> compute_queue_scratch_size
) {
3823 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3824 compute_scratch_size
,
3828 RADV_BO_PRIORITY_SCRATCH
);
3829 if (!compute_scratch_bo
)
3833 compute_scratch_bo
= queue
->compute_scratch_bo
;
3835 if (esgs_ring_size
> queue
->esgs_ring_size
) {
3836 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3841 RADV_BO_PRIORITY_SCRATCH
);
3845 esgs_ring_bo
= queue
->esgs_ring_bo
;
3846 esgs_ring_size
= queue
->esgs_ring_size
;
3849 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
3850 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3855 RADV_BO_PRIORITY_SCRATCH
);
3859 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
3860 gsvs_ring_size
= queue
->gsvs_ring_size
;
3863 if (add_tess_rings
) {
3864 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3865 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
3869 RADV_BO_PRIORITY_SCRATCH
);
3873 tess_rings_bo
= queue
->tess_rings_bo
;
3877 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
3879 /* 4 streamout GDS counters.
3880 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
3882 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3886 RADV_BO_PRIORITY_SCRATCH
);
3890 gds_bo
= queue
->gds_bo
;
3894 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
3896 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3900 RADV_BO_PRIORITY_SCRATCH
);
3904 gds_oa_bo
= queue
->gds_oa_bo
;
3907 if (scratch_bo
!= queue
->scratch_bo
||
3908 esgs_ring_bo
!= queue
->esgs_ring_bo
||
3909 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
3910 tess_rings_bo
!= queue
->tess_rings_bo
||
3911 add_sample_positions
) {
3913 if (gsvs_ring_bo
|| esgs_ring_bo
||
3914 tess_rings_bo
|| add_sample_positions
) {
3915 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
3916 if (add_sample_positions
)
3917 size
+= 128; /* 64+32+16+8 = 120 bytes */
3919 else if (scratch_bo
)
3920 size
= 8; /* 2 dword */
3922 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3926 RADEON_FLAG_CPU_ACCESS
|
3927 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
3928 RADEON_FLAG_READ_ONLY
,
3929 RADV_BO_PRIORITY_DESCRIPTOR
);
3933 descriptor_bo
= queue
->descriptor_bo
;
3935 if (descriptor_bo
!= queue
->descriptor_bo
) {
3936 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
3939 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
3940 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3941 S_008F04_SWIZZLE_ENABLE(1);
3942 map
[0] = scratch_va
;
3946 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
3947 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
3948 esgs_ring_size
, esgs_ring_bo
,
3949 gsvs_ring_size
, gsvs_ring_bo
,
3950 tess_factor_ring_size
,
3951 tess_offchip_ring_offset
,
3952 tess_offchip_ring_size
,
3955 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
3958 for(int i
= 0; i
< 3; ++i
) {
3959 struct radeon_cmdbuf
*cs
= NULL
;
3960 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
3961 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
3968 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
3970 /* Emit initial configuration. */
3971 switch (queue
->queue_family_index
) {
3972 case RADV_QUEUE_GENERAL
:
3973 radv_init_graphics_state(cs
, queue
);
3975 case RADV_QUEUE_COMPUTE
:
3976 radv_init_compute_state(cs
, queue
);
3978 case RADV_QUEUE_TRANSFER
:
3982 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
3983 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
3984 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
3986 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
3987 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
3990 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
3991 gsvs_ring_bo
, gsvs_ring_size
);
3992 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
3993 tess_factor_ring_size
, tess_rings_bo
);
3994 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
3995 radv_emit_compute_scratch(queue
, cs
, compute_scratch_size_per_wave
,
3996 compute_scratch_waves
, compute_scratch_bo
);
3997 radv_emit_graphics_scratch(queue
, cs
, scratch_size_per_wave
,
3998 scratch_waves
, scratch_bo
);
4001 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
4003 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
4005 if (queue
->device
->trace_bo
)
4006 radv_cs_add_buffer(queue
->device
->ws
, cs
, queue
->device
->trace_bo
);
4009 si_cs_emit_cache_flush(cs
,
4010 queue
->device
->physical_device
->rad_info
.chip_class
,
4012 queue
->queue_family_index
== RING_COMPUTE
&&
4013 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
4014 (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
)) |
4015 RADV_CMD_FLAG_INV_ICACHE
|
4016 RADV_CMD_FLAG_INV_SCACHE
|
4017 RADV_CMD_FLAG_INV_VCACHE
|
4018 RADV_CMD_FLAG_INV_L2
|
4019 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
4020 } else if (i
== 1) {
4021 si_cs_emit_cache_flush(cs
,
4022 queue
->device
->physical_device
->rad_info
.chip_class
,
4024 queue
->queue_family_index
== RING_COMPUTE
&&
4025 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
4026 RADV_CMD_FLAG_INV_ICACHE
|
4027 RADV_CMD_FLAG_INV_SCACHE
|
4028 RADV_CMD_FLAG_INV_VCACHE
|
4029 RADV_CMD_FLAG_INV_L2
|
4030 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
4033 if (!queue
->device
->ws
->cs_finalize(cs
))
4037 if (queue
->initial_full_flush_preamble_cs
)
4038 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
4040 if (queue
->initial_preamble_cs
)
4041 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
4043 if (queue
->continue_preamble_cs
)
4044 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
4046 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
4047 queue
->initial_preamble_cs
= dest_cs
[1];
4048 queue
->continue_preamble_cs
= dest_cs
[2];
4050 if (scratch_bo
!= queue
->scratch_bo
) {
4051 if (queue
->scratch_bo
)
4052 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
4053 queue
->scratch_bo
= scratch_bo
;
4055 queue
->scratch_size_per_wave
= scratch_size_per_wave
;
4056 queue
->scratch_waves
= scratch_waves
;
4058 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
4059 if (queue
->compute_scratch_bo
)
4060 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
4061 queue
->compute_scratch_bo
= compute_scratch_bo
;
4063 queue
->compute_scratch_size_per_wave
= compute_scratch_size_per_wave
;
4064 queue
->compute_scratch_waves
= compute_scratch_waves
;
4066 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
4067 if (queue
->esgs_ring_bo
)
4068 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
4069 queue
->esgs_ring_bo
= esgs_ring_bo
;
4070 queue
->esgs_ring_size
= esgs_ring_size
;
4073 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
4074 if (queue
->gsvs_ring_bo
)
4075 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
4076 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
4077 queue
->gsvs_ring_size
= gsvs_ring_size
;
4080 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
4081 queue
->tess_rings_bo
= tess_rings_bo
;
4082 queue
->has_tess_rings
= true;
4085 if (gds_bo
!= queue
->gds_bo
) {
4086 queue
->gds_bo
= gds_bo
;
4087 queue
->has_gds
= true;
4090 if (gds_oa_bo
!= queue
->gds_oa_bo
) {
4091 queue
->gds_oa_bo
= gds_oa_bo
;
4092 queue
->has_gds_oa
= true;
4095 if (descriptor_bo
!= queue
->descriptor_bo
) {
4096 if (queue
->descriptor_bo
)
4097 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
4099 queue
->descriptor_bo
= descriptor_bo
;
4102 if (add_sample_positions
)
4103 queue
->has_sample_positions
= true;
4105 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
4106 *initial_preamble_cs
= queue
->initial_preamble_cs
;
4107 *continue_preamble_cs
= queue
->continue_preamble_cs
;
4108 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
4109 *continue_preamble_cs
= NULL
;
4112 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
4114 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
4115 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
4116 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
4117 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
4118 queue
->device
->ws
->buffer_destroy(scratch_bo
);
4119 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
4120 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
4121 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
4122 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
4123 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
4124 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
4125 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
4126 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
4127 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
4128 queue
->device
->ws
->buffer_destroy(gds_bo
);
4129 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
4130 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
4132 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4135 static VkResult
radv_alloc_sem_counts(struct radv_device
*device
,
4136 struct radv_winsys_sem_counts
*counts
,
4138 struct radv_semaphore_part
**sems
,
4139 const uint64_t *timeline_values
,
4143 int syncobj_idx
= 0, sem_idx
= 0;
4145 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
4148 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4149 switch(sems
[i
]->kind
) {
4150 case RADV_SEMAPHORE_SYNCOBJ
:
4151 counts
->syncobj_count
++;
4153 case RADV_SEMAPHORE_WINSYS
:
4154 counts
->sem_count
++;
4156 case RADV_SEMAPHORE_NONE
:
4158 case RADV_SEMAPHORE_TIMELINE
:
4159 counts
->syncobj_count
++;
4164 if (_fence
!= VK_NULL_HANDLE
) {
4165 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4166 if (fence
->temp_syncobj
|| fence
->syncobj
)
4167 counts
->syncobj_count
++;
4170 if (counts
->syncobj_count
) {
4171 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
4172 if (!counts
->syncobj
)
4173 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4176 if (counts
->sem_count
) {
4177 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
4179 free(counts
->syncobj
);
4180 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4184 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4185 switch(sems
[i
]->kind
) {
4186 case RADV_SEMAPHORE_NONE
:
4187 unreachable("Empty semaphore");
4189 case RADV_SEMAPHORE_SYNCOBJ
:
4190 counts
->syncobj
[syncobj_idx
++] = sems
[i
]->syncobj
;
4192 case RADV_SEMAPHORE_WINSYS
:
4193 counts
->sem
[sem_idx
++] = sems
[i
]->ws_sem
;
4195 case RADV_SEMAPHORE_TIMELINE
: {
4196 pthread_mutex_lock(&sems
[i
]->timeline
.mutex
);
4197 struct radv_timeline_point
*point
= NULL
;
4199 point
= radv_timeline_add_point_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
4201 point
= radv_timeline_find_point_at_least_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
4204 pthread_mutex_unlock(&sems
[i
]->timeline
.mutex
);
4207 counts
->syncobj
[syncobj_idx
++] = point
->syncobj
;
4209 /* Explicitly remove the semaphore so we might not find
4210 * a point later post-submit. */
4218 if (_fence
!= VK_NULL_HANDLE
) {
4219 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4220 if (fence
->temp_syncobj
)
4221 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
4222 else if (fence
->syncobj
)
4223 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
4226 assert(syncobj_idx
<= counts
->syncobj_count
);
4227 counts
->syncobj_count
= syncobj_idx
;
4233 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
4235 free(sem_info
->wait
.syncobj
);
4236 free(sem_info
->wait
.sem
);
4237 free(sem_info
->signal
.syncobj
);
4238 free(sem_info
->signal
.sem
);
4242 static void radv_free_temp_syncobjs(struct radv_device
*device
,
4244 struct radv_semaphore_part
*sems
)
4246 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4247 radv_destroy_semaphore_part(device
, sems
+ i
);
4252 radv_alloc_sem_info(struct radv_device
*device
,
4253 struct radv_winsys_sem_info
*sem_info
,
4255 struct radv_semaphore_part
**wait_sems
,
4256 const uint64_t *wait_values
,
4257 int num_signal_sems
,
4258 struct radv_semaphore_part
**signal_sems
,
4259 const uint64_t *signal_values
,
4263 memset(sem_info
, 0, sizeof(*sem_info
));
4265 ret
= radv_alloc_sem_counts(device
, &sem_info
->wait
, num_wait_sems
, wait_sems
, wait_values
, VK_NULL_HANDLE
, false);
4268 ret
= radv_alloc_sem_counts(device
, &sem_info
->signal
, num_signal_sems
, signal_sems
, signal_values
, fence
, true);
4270 radv_free_sem_info(sem_info
);
4272 /* caller can override these */
4273 sem_info
->cs_emit_wait
= true;
4274 sem_info
->cs_emit_signal
= true;
4279 radv_finalize_timelines(struct radv_device
*device
,
4280 uint32_t num_wait_sems
,
4281 struct radv_semaphore_part
**wait_sems
,
4282 const uint64_t *wait_values
,
4283 uint32_t num_signal_sems
,
4284 struct radv_semaphore_part
**signal_sems
,
4285 const uint64_t *signal_values
,
4286 struct list_head
*processing_list
)
4288 for (uint32_t i
= 0; i
< num_wait_sems
; ++i
) {
4289 if (wait_sems
[i
] && wait_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4290 pthread_mutex_lock(&wait_sems
[i
]->timeline
.mutex
);
4291 struct radv_timeline_point
*point
=
4292 radv_timeline_find_point_at_least_locked(device
, &wait_sems
[i
]->timeline
, wait_values
[i
]);
4293 point
->wait_count
-= 2;
4294 pthread_mutex_unlock(&wait_sems
[i
]->timeline
.mutex
);
4297 for (uint32_t i
= 0; i
< num_signal_sems
; ++i
) {
4298 if (signal_sems
[i
] && signal_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4299 pthread_mutex_lock(&signal_sems
[i
]->timeline
.mutex
);
4300 struct radv_timeline_point
*point
=
4301 radv_timeline_find_point_at_least_locked(device
, &signal_sems
[i
]->timeline
, signal_values
[i
]);
4302 signal_sems
[i
]->timeline
.highest_submitted
=
4303 MAX2(signal_sems
[i
]->timeline
.highest_submitted
, point
->value
);
4304 point
->wait_count
-= 2;
4305 radv_timeline_trigger_waiters_locked(&signal_sems
[i
]->timeline
, processing_list
);
4306 pthread_mutex_unlock(&signal_sems
[i
]->timeline
.mutex
);
4312 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
4313 const VkSparseBufferMemoryBindInfo
*bind
)
4315 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
4317 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
4318 struct radv_device_memory
*mem
= NULL
;
4320 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
4321 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
4323 device
->ws
->buffer_virtual_bind(buffer
->bo
,
4324 bind
->pBinds
[i
].resourceOffset
,
4325 bind
->pBinds
[i
].size
,
4326 mem
? mem
->bo
: NULL
,
4327 bind
->pBinds
[i
].memoryOffset
);
4332 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
4333 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
4335 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
4337 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
4338 struct radv_device_memory
*mem
= NULL
;
4340 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
4341 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
4343 device
->ws
->buffer_virtual_bind(image
->bo
,
4344 bind
->pBinds
[i
].resourceOffset
,
4345 bind
->pBinds
[i
].size
,
4346 mem
? mem
->bo
: NULL
,
4347 bind
->pBinds
[i
].memoryOffset
);
4352 radv_get_preambles(struct radv_queue
*queue
,
4353 const VkCommandBuffer
*cmd_buffers
,
4354 uint32_t cmd_buffer_count
,
4355 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
4356 struct radeon_cmdbuf
**initial_preamble_cs
,
4357 struct radeon_cmdbuf
**continue_preamble_cs
)
4359 uint32_t scratch_size_per_wave
= 0, waves_wanted
= 0;
4360 uint32_t compute_scratch_size_per_wave
= 0, compute_waves_wanted
= 0;
4361 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
4362 bool tess_rings_needed
= false;
4363 bool gds_needed
= false;
4364 bool gds_oa_needed
= false;
4365 bool sample_positions_needed
= false;
4367 for (uint32_t j
= 0; j
< cmd_buffer_count
; j
++) {
4368 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
4371 scratch_size_per_wave
= MAX2(scratch_size_per_wave
, cmd_buffer
->scratch_size_per_wave_needed
);
4372 waves_wanted
= MAX2(waves_wanted
, cmd_buffer
->scratch_waves_wanted
);
4373 compute_scratch_size_per_wave
= MAX2(compute_scratch_size_per_wave
,
4374 cmd_buffer
->compute_scratch_size_per_wave_needed
);
4375 compute_waves_wanted
= MAX2(compute_waves_wanted
,
4376 cmd_buffer
->compute_scratch_waves_wanted
);
4377 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
4378 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
4379 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
4380 gds_needed
|= cmd_buffer
->gds_needed
;
4381 gds_oa_needed
|= cmd_buffer
->gds_oa_needed
;
4382 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
4385 return radv_get_preamble_cs(queue
, scratch_size_per_wave
, waves_wanted
,
4386 compute_scratch_size_per_wave
, compute_waves_wanted
,
4387 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
4388 gds_needed
, gds_oa_needed
, sample_positions_needed
,
4389 initial_full_flush_preamble_cs
,
4390 initial_preamble_cs
, continue_preamble_cs
);
4393 struct radv_deferred_queue_submission
{
4394 struct radv_queue
*queue
;
4395 VkCommandBuffer
*cmd_buffers
;
4396 uint32_t cmd_buffer_count
;
4398 /* Sparse bindings that happen on a queue. */
4399 VkSparseBufferMemoryBindInfo
*buffer_binds
;
4400 uint32_t buffer_bind_count
;
4401 VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
4402 uint32_t image_opaque_bind_count
;
4405 VkShaderStageFlags wait_dst_stage_mask
;
4406 struct radv_semaphore_part
**wait_semaphores
;
4407 uint32_t wait_semaphore_count
;
4408 struct radv_semaphore_part
**signal_semaphores
;
4409 uint32_t signal_semaphore_count
;
4412 uint64_t *wait_values
;
4413 uint64_t *signal_values
;
4415 struct radv_semaphore_part
*temporary_semaphore_parts
;
4416 uint32_t temporary_semaphore_part_count
;
4418 struct list_head queue_pending_list
;
4419 uint32_t submission_wait_count
;
4420 struct radv_timeline_waiter
*wait_nodes
;
4422 struct list_head processing_list
;
4425 struct radv_queue_submission
{
4426 const VkCommandBuffer
*cmd_buffers
;
4427 uint32_t cmd_buffer_count
;
4429 /* Sparse bindings that happen on a queue. */
4430 const VkSparseBufferMemoryBindInfo
*buffer_binds
;
4431 uint32_t buffer_bind_count
;
4432 const VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
4433 uint32_t image_opaque_bind_count
;
4436 VkPipelineStageFlags wait_dst_stage_mask
;
4437 const VkSemaphore
*wait_semaphores
;
4438 uint32_t wait_semaphore_count
;
4439 const VkSemaphore
*signal_semaphores
;
4440 uint32_t signal_semaphore_count
;
4443 const uint64_t *wait_values
;
4444 uint32_t wait_value_count
;
4445 const uint64_t *signal_values
;
4446 uint32_t signal_value_count
;
4450 radv_create_deferred_submission(struct radv_queue
*queue
,
4451 const struct radv_queue_submission
*submission
,
4452 struct radv_deferred_queue_submission
**out
)
4454 struct radv_deferred_queue_submission
*deferred
= NULL
;
4455 size_t size
= sizeof(struct radv_deferred_queue_submission
);
4457 uint32_t temporary_count
= 0;
4458 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4459 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
4460 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
)
4464 size
+= submission
->cmd_buffer_count
* sizeof(VkCommandBuffer
);
4465 size
+= submission
->buffer_bind_count
* sizeof(VkSparseBufferMemoryBindInfo
);
4466 size
+= submission
->image_opaque_bind_count
* sizeof(VkSparseImageOpaqueMemoryBindInfo
);
4467 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_semaphore_part
*);
4468 size
+= temporary_count
* sizeof(struct radv_semaphore_part
);
4469 size
+= submission
->signal_semaphore_count
* sizeof(struct radv_semaphore_part
*);
4470 size
+= submission
->wait_value_count
* sizeof(uint64_t);
4471 size
+= submission
->signal_value_count
* sizeof(uint64_t);
4472 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_timeline_waiter
);
4474 deferred
= calloc(1, size
);
4476 return VK_ERROR_OUT_OF_HOST_MEMORY
;
4478 deferred
->queue
= queue
;
4480 deferred
->cmd_buffers
= (void*)(deferred
+ 1);
4481 deferred
->cmd_buffer_count
= submission
->cmd_buffer_count
;
4482 memcpy(deferred
->cmd_buffers
, submission
->cmd_buffers
,
4483 submission
->cmd_buffer_count
* sizeof(*deferred
->cmd_buffers
));
4485 deferred
->buffer_binds
= (void*)(deferred
->cmd_buffers
+ submission
->cmd_buffer_count
);
4486 deferred
->buffer_bind_count
= submission
->buffer_bind_count
;
4487 memcpy(deferred
->buffer_binds
, submission
->buffer_binds
,
4488 submission
->buffer_bind_count
* sizeof(*deferred
->buffer_binds
));
4490 deferred
->image_opaque_binds
= (void*)(deferred
->buffer_binds
+ submission
->buffer_bind_count
);
4491 deferred
->image_opaque_bind_count
= submission
->image_opaque_bind_count
;
4492 memcpy(deferred
->image_opaque_binds
, submission
->image_opaque_binds
,
4493 submission
->image_opaque_bind_count
* sizeof(*deferred
->image_opaque_binds
));
4495 deferred
->flush_caches
= submission
->flush_caches
;
4496 deferred
->wait_dst_stage_mask
= submission
->wait_dst_stage_mask
;
4498 deferred
->wait_semaphores
= (void*)(deferred
->image_opaque_binds
+ deferred
->image_opaque_bind_count
);
4499 deferred
->wait_semaphore_count
= submission
->wait_semaphore_count
;
4501 deferred
->signal_semaphores
= (void*)(deferred
->wait_semaphores
+ deferred
->wait_semaphore_count
);
4502 deferred
->signal_semaphore_count
= submission
->signal_semaphore_count
;
4504 deferred
->fence
= submission
->fence
;
4506 deferred
->temporary_semaphore_parts
= (void*)(deferred
->signal_semaphores
+ deferred
->signal_semaphore_count
);
4507 deferred
->temporary_semaphore_part_count
= temporary_count
;
4509 uint32_t temporary_idx
= 0;
4510 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4511 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
4512 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
4513 deferred
->wait_semaphores
[i
] = &deferred
->temporary_semaphore_parts
[temporary_idx
];
4514 deferred
->temporary_semaphore_parts
[temporary_idx
] = semaphore
->temporary
;
4515 semaphore
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
4518 deferred
->wait_semaphores
[i
] = &semaphore
->permanent
;
4521 for (uint32_t i
= 0; i
< submission
->signal_semaphore_count
; ++i
) {
4522 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->signal_semaphores
[i
]);
4523 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
4524 deferred
->signal_semaphores
[i
] = &semaphore
->temporary
;
4526 deferred
->signal_semaphores
[i
] = &semaphore
->permanent
;
4530 deferred
->wait_values
= (void*)(deferred
->temporary_semaphore_parts
+ temporary_count
);
4531 memcpy(deferred
->wait_values
, submission
->wait_values
, submission
->wait_value_count
* sizeof(uint64_t));
4532 deferred
->signal_values
= deferred
->wait_values
+ submission
->wait_value_count
;
4533 memcpy(deferred
->signal_values
, submission
->signal_values
, submission
->signal_value_count
* sizeof(uint64_t));
4535 deferred
->wait_nodes
= (void*)(deferred
->signal_values
+ submission
->signal_value_count
);
4536 /* This is worst-case. radv_queue_enqueue_submission will fill in further, but this
4537 * ensure the submission is not accidentally triggered early when adding wait timelines. */
4538 deferred
->submission_wait_count
= 1 + submission
->wait_semaphore_count
;
4545 radv_queue_enqueue_submission(struct radv_deferred_queue_submission
*submission
,
4546 struct list_head
*processing_list
)
4548 uint32_t wait_cnt
= 0;
4549 struct radv_timeline_waiter
*waiter
= submission
->wait_nodes
;
4550 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4551 if (submission
->wait_semaphores
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4552 pthread_mutex_lock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
4553 if (submission
->wait_semaphores
[i
]->timeline
.highest_submitted
< submission
->wait_values
[i
]) {
4555 waiter
->value
= submission
->wait_values
[i
];
4556 waiter
->submission
= submission
;
4557 list_addtail(&waiter
->list
, &submission
->wait_semaphores
[i
]->timeline
.waiters
);
4560 pthread_mutex_unlock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
4564 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
4566 bool is_first
= list_is_empty(&submission
->queue
->pending_submissions
);
4567 list_addtail(&submission
->queue_pending_list
, &submission
->queue
->pending_submissions
);
4569 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
4571 /* If there is already a submission in the queue, that will decrement the counter by 1 when
4572 * submitted, but if the queue was empty, we decrement ourselves as there is no previous
4574 uint32_t decrement
= submission
->wait_semaphore_count
- wait_cnt
+ (is_first
? 1 : 0);
4575 if (__atomic_sub_fetch(&submission
->submission_wait_count
, decrement
, __ATOMIC_ACQ_REL
) == 0) {
4576 list_addtail(&submission
->processing_list
, processing_list
);
4581 radv_queue_submission_update_queue(struct radv_deferred_queue_submission
*submission
,
4582 struct list_head
*processing_list
)
4584 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
4585 list_del(&submission
->queue_pending_list
);
4587 /* trigger the next submission in the queue. */
4588 if (!list_is_empty(&submission
->queue
->pending_submissions
)) {
4589 struct radv_deferred_queue_submission
*next_submission
=
4590 list_first_entry(&submission
->queue
->pending_submissions
,
4591 struct radv_deferred_queue_submission
,
4592 queue_pending_list
);
4593 if (p_atomic_dec_zero(&next_submission
->submission_wait_count
)) {
4594 list_addtail(&next_submission
->processing_list
, processing_list
);
4597 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
4599 pthread_cond_broadcast(&submission
->queue
->device
->timeline_cond
);
4603 radv_queue_submit_deferred(struct radv_deferred_queue_submission
*submission
,
4604 struct list_head
*processing_list
)
4606 RADV_FROM_HANDLE(radv_fence
, fence
, submission
->fence
);
4607 struct radv_queue
*queue
= submission
->queue
;
4608 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
4609 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
4610 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
4611 bool do_flush
= submission
->flush_caches
|| submission
->wait_dst_stage_mask
;
4612 bool can_patch
= true;
4614 struct radv_winsys_sem_info sem_info
;
4617 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
;
4618 struct radeon_cmdbuf
*initial_flush_preamble_cs
= NULL
;
4619 struct radeon_cmdbuf
*continue_preamble_cs
= NULL
;
4621 result
= radv_get_preambles(queue
, submission
->cmd_buffers
,
4622 submission
->cmd_buffer_count
,
4623 &initial_preamble_cs
,
4624 &initial_flush_preamble_cs
,
4625 &continue_preamble_cs
);
4626 if (result
!= VK_SUCCESS
)
4629 result
= radv_alloc_sem_info(queue
->device
,
4631 submission
->wait_semaphore_count
,
4632 submission
->wait_semaphores
,
4633 submission
->wait_values
,
4634 submission
->signal_semaphore_count
,
4635 submission
->signal_semaphores
,
4636 submission
->signal_values
,
4638 if (result
!= VK_SUCCESS
)
4641 for (uint32_t i
= 0; i
< submission
->buffer_bind_count
; ++i
) {
4642 radv_sparse_buffer_bind_memory(queue
->device
,
4643 submission
->buffer_binds
+ i
);
4646 for (uint32_t i
= 0; i
< submission
->image_opaque_bind_count
; ++i
) {
4647 radv_sparse_image_opaque_bind_memory(queue
->device
,
4648 submission
->image_opaque_binds
+ i
);
4651 if (!submission
->cmd_buffer_count
) {
4652 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
4653 &queue
->device
->empty_cs
[queue
->queue_family_index
],
4658 radv_loge("failed to submit CS\n");
4664 struct radeon_cmdbuf
**cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
4665 (submission
->cmd_buffer_count
));
4667 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
++) {
4668 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, submission
->cmd_buffers
[j
]);
4669 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
4671 cs_array
[j
] = cmd_buffer
->cs
;
4672 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
4675 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
4678 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
+= advance
) {
4679 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
4680 const struct radv_winsys_bo_list
*bo_list
= NULL
;
4682 advance
= MIN2(max_cs_submission
,
4683 submission
->cmd_buffer_count
- j
);
4685 if (queue
->device
->trace_bo
)
4686 *queue
->device
->trace_id_ptr
= 0;
4688 sem_info
.cs_emit_wait
= j
== 0;
4689 sem_info
.cs_emit_signal
= j
+ advance
== submission
->cmd_buffer_count
;
4691 if (unlikely(queue
->device
->use_global_bo_list
)) {
4692 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
4693 bo_list
= &queue
->device
->bo_list
.list
;
4696 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
4697 advance
, initial_preamble
, continue_preamble_cs
,
4699 can_patch
, base_fence
);
4701 if (unlikely(queue
->device
->use_global_bo_list
))
4702 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
4705 radv_loge("failed to submit CS\n");
4708 if (queue
->device
->trace_bo
) {
4709 radv_check_gpu_hangs(queue
, cs_array
[j
]);
4717 radv_free_temp_syncobjs(queue
->device
,
4718 submission
->temporary_semaphore_part_count
,
4719 submission
->temporary_semaphore_parts
);
4720 radv_finalize_timelines(queue
->device
,
4721 submission
->wait_semaphore_count
,
4722 submission
->wait_semaphores
,
4723 submission
->wait_values
,
4724 submission
->signal_semaphore_count
,
4725 submission
->signal_semaphores
,
4726 submission
->signal_values
,
4728 /* Has to happen after timeline finalization to make sure the
4729 * condition variable is only triggered when timelines and queue have
4731 radv_queue_submission_update_queue(submission
, processing_list
);
4732 radv_free_sem_info(&sem_info
);
4737 radv_free_temp_syncobjs(queue
->device
,
4738 submission
->temporary_semaphore_part_count
,
4739 submission
->temporary_semaphore_parts
);
4741 return VK_ERROR_DEVICE_LOST
;
4745 radv_process_submissions(struct list_head
*processing_list
)
4747 while(!list_is_empty(processing_list
)) {
4748 struct radv_deferred_queue_submission
*submission
=
4749 list_first_entry(processing_list
, struct radv_deferred_queue_submission
, processing_list
);
4750 list_del(&submission
->processing_list
);
4752 VkResult result
= radv_queue_submit_deferred(submission
, processing_list
);
4753 if (result
!= VK_SUCCESS
)
4759 static VkResult
radv_queue_submit(struct radv_queue
*queue
,
4760 const struct radv_queue_submission
*submission
)
4762 struct radv_deferred_queue_submission
*deferred
= NULL
;
4764 VkResult result
= radv_create_deferred_submission(queue
, submission
, &deferred
);
4765 if (result
!= VK_SUCCESS
)
4768 struct list_head processing_list
;
4769 list_inithead(&processing_list
);
4771 radv_queue_enqueue_submission(deferred
, &processing_list
);
4772 return radv_process_submissions(&processing_list
);
4776 radv_queue_internal_submit(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
)
4778 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
4779 struct radv_winsys_sem_info sem_info
;
4783 result
= radv_alloc_sem_info(queue
->device
, &sem_info
, 0, NULL
, 0, 0,
4784 0, NULL
, VK_NULL_HANDLE
);
4785 if (result
!= VK_SUCCESS
)
4788 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, &cs
, 1, NULL
,
4789 NULL
, &sem_info
, NULL
, false, NULL
);
4790 radv_free_sem_info(&sem_info
);
4794 /* Signals fence as soon as all the work currently put on queue is done. */
4795 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
4798 return radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4803 static bool radv_submit_has_effects(const VkSubmitInfo
*info
)
4805 return info
->commandBufferCount
||
4806 info
->waitSemaphoreCount
||
4807 info
->signalSemaphoreCount
;
4810 VkResult
radv_QueueSubmit(
4812 uint32_t submitCount
,
4813 const VkSubmitInfo
* pSubmits
,
4816 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4818 uint32_t fence_idx
= 0;
4819 bool flushed_caches
= false;
4821 if (fence
!= VK_NULL_HANDLE
) {
4822 for (uint32_t i
= 0; i
< submitCount
; ++i
)
4823 if (radv_submit_has_effects(pSubmits
+ i
))
4826 fence_idx
= UINT32_MAX
;
4828 for (uint32_t i
= 0; i
< submitCount
; i
++) {
4829 if (!radv_submit_has_effects(pSubmits
+ i
) && fence_idx
!= i
)
4832 VkPipelineStageFlags wait_dst_stage_mask
= 0;
4833 for (unsigned j
= 0; j
< pSubmits
[i
].waitSemaphoreCount
; ++j
) {
4834 wait_dst_stage_mask
|= pSubmits
[i
].pWaitDstStageMask
[j
];
4837 const VkTimelineSemaphoreSubmitInfo
*timeline_info
=
4838 vk_find_struct_const(pSubmits
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO
);
4840 result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4841 .cmd_buffers
= pSubmits
[i
].pCommandBuffers
,
4842 .cmd_buffer_count
= pSubmits
[i
].commandBufferCount
,
4843 .wait_dst_stage_mask
= wait_dst_stage_mask
,
4844 .flush_caches
= !flushed_caches
,
4845 .wait_semaphores
= pSubmits
[i
].pWaitSemaphores
,
4846 .wait_semaphore_count
= pSubmits
[i
].waitSemaphoreCount
,
4847 .signal_semaphores
= pSubmits
[i
].pSignalSemaphores
,
4848 .signal_semaphore_count
= pSubmits
[i
].signalSemaphoreCount
,
4849 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
4850 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
4851 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
4852 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
4853 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
4855 if (result
!= VK_SUCCESS
)
4858 flushed_caches
= true;
4861 if (fence
!= VK_NULL_HANDLE
&& !submitCount
) {
4862 result
= radv_signal_fence(queue
, fence
);
4863 if (result
!= VK_SUCCESS
)
4870 VkResult
radv_QueueWaitIdle(
4873 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4875 pthread_mutex_lock(&queue
->pending_mutex
);
4876 while (!list_is_empty(&queue
->pending_submissions
)) {
4877 pthread_cond_wait(&queue
->device
->timeline_cond
, &queue
->pending_mutex
);
4879 pthread_mutex_unlock(&queue
->pending_mutex
);
4881 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
4882 radv_queue_family_to_ring(queue
->queue_family_index
),
4887 VkResult
radv_DeviceWaitIdle(
4890 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4892 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
4893 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
4894 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
4900 VkResult
radv_EnumerateInstanceExtensionProperties(
4901 const char* pLayerName
,
4902 uint32_t* pPropertyCount
,
4903 VkExtensionProperties
* pProperties
)
4905 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
4907 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
4908 if (radv_supported_instance_extensions
.extensions
[i
]) {
4909 vk_outarray_append(&out
, prop
) {
4910 *prop
= radv_instance_extensions
[i
];
4915 return vk_outarray_status(&out
);
4918 VkResult
radv_EnumerateDeviceExtensionProperties(
4919 VkPhysicalDevice physicalDevice
,
4920 const char* pLayerName
,
4921 uint32_t* pPropertyCount
,
4922 VkExtensionProperties
* pProperties
)
4924 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
4925 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
4927 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
4928 if (device
->supported_extensions
.extensions
[i
]) {
4929 vk_outarray_append(&out
, prop
) {
4930 *prop
= radv_device_extensions
[i
];
4935 return vk_outarray_status(&out
);
4938 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
4939 VkInstance _instance
,
4942 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4944 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
4945 * when we have to return valid function pointers, NULL, or it's left
4946 * undefined. See the table for exact details.
4951 #define LOOKUP_RADV_ENTRYPOINT(entrypoint) \
4952 if (strcmp(pName, "vk" #entrypoint) == 0) \
4953 return (PFN_vkVoidFunction)radv_##entrypoint
4955 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
4956 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
4957 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceVersion
);
4958 LOOKUP_RADV_ENTRYPOINT(CreateInstance
);
4960 /* GetInstanceProcAddr() can also be called with a NULL instance.
4961 * See https://gitlab.khronos.org/vulkan/vulkan/issues/2057
4963 LOOKUP_RADV_ENTRYPOINT(GetInstanceProcAddr
);
4965 #undef LOOKUP_RADV_ENTRYPOINT
4967 if (instance
== NULL
)
4970 int idx
= radv_get_instance_entrypoint_index(pName
);
4972 return instance
->dispatch
.entrypoints
[idx
];
4974 idx
= radv_get_physical_device_entrypoint_index(pName
);
4976 return instance
->physical_device_dispatch
.entrypoints
[idx
];
4978 idx
= radv_get_device_entrypoint_index(pName
);
4980 return instance
->device_dispatch
.entrypoints
[idx
];
4985 /* The loader wants us to expose a second GetInstanceProcAddr function
4986 * to work around certain LD_PRELOAD issues seen in apps.
4989 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
4990 VkInstance instance
,
4994 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
4995 VkInstance instance
,
4998 return radv_GetInstanceProcAddr(instance
, pName
);
5002 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
5003 VkInstance _instance
,
5007 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
5008 VkInstance _instance
,
5011 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5013 if (!pName
|| !instance
)
5016 int idx
= radv_get_physical_device_entrypoint_index(pName
);
5020 return instance
->physical_device_dispatch
.entrypoints
[idx
];
5023 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
5027 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5029 if (!device
|| !pName
)
5032 int idx
= radv_get_device_entrypoint_index(pName
);
5036 return device
->dispatch
.entrypoints
[idx
];
5039 bool radv_get_memory_fd(struct radv_device
*device
,
5040 struct radv_device_memory
*memory
,
5043 struct radeon_bo_metadata metadata
;
5045 if (memory
->image
) {
5046 if (memory
->image
->tiling
!= VK_IMAGE_TILING_LINEAR
)
5047 radv_init_metadata(device
, memory
->image
, &metadata
);
5048 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
5051 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
5056 static void radv_free_memory(struct radv_device
*device
,
5057 const VkAllocationCallbacks
* pAllocator
,
5058 struct radv_device_memory
*mem
)
5063 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
5064 if (mem
->android_hardware_buffer
)
5065 AHardwareBuffer_release(mem
->android_hardware_buffer
);
5069 if (device
->overallocation_disallowed
) {
5070 mtx_lock(&device
->overallocation_mutex
);
5071 device
->allocated_memory_size
[mem
->heap_index
] -= mem
->alloc_size
;
5072 mtx_unlock(&device
->overallocation_mutex
);
5075 radv_bo_list_remove(device
, mem
->bo
);
5076 device
->ws
->buffer_destroy(mem
->bo
);
5080 vk_free2(&device
->alloc
, pAllocator
, mem
);
5083 static VkResult
radv_alloc_memory(struct radv_device
*device
,
5084 const VkMemoryAllocateInfo
* pAllocateInfo
,
5085 const VkAllocationCallbacks
* pAllocator
,
5086 VkDeviceMemory
* pMem
)
5088 struct radv_device_memory
*mem
;
5090 enum radeon_bo_domain domain
;
5093 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
5095 const VkImportMemoryFdInfoKHR
*import_info
=
5096 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
5097 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
5098 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
5099 const VkExportMemoryAllocateInfo
*export_info
=
5100 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
5101 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahb_import_info
=
5102 vk_find_struct_const(pAllocateInfo
->pNext
,
5103 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
5104 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
5105 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
5107 const struct wsi_memory_allocate_info
*wsi_info
=
5108 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
5110 if (pAllocateInfo
->allocationSize
== 0 && !ahb_import_info
&&
5111 !(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
))) {
5112 /* Apparently, this is allowed */
5113 *pMem
= VK_NULL_HANDLE
;
5117 mem
= vk_zalloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
5118 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5120 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5122 if (wsi_info
&& wsi_info
->implicit_sync
)
5123 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
5125 if (dedicate_info
) {
5126 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
5127 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
5133 float priority_float
= 0.5;
5134 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
5135 vk_find_struct_const(pAllocateInfo
->pNext
,
5136 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
5138 priority_float
= priority_ext
->priority
;
5140 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
5141 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
5143 mem
->user_ptr
= NULL
;
5146 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
5147 mem
->android_hardware_buffer
= NULL
;
5150 if (ahb_import_info
) {
5151 result
= radv_import_ahb_memory(device
, mem
, priority
, ahb_import_info
);
5152 if (result
!= VK_SUCCESS
)
5154 } else if(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)) {
5155 result
= radv_create_ahb_memory(device
, mem
, priority
, pAllocateInfo
);
5156 if (result
!= VK_SUCCESS
)
5158 } else if (import_info
) {
5159 assert(import_info
->handleType
==
5160 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5161 import_info
->handleType
==
5162 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5163 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
5166 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
5169 close(import_info
->fd
);
5171 } else if (host_ptr_info
) {
5172 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
5173 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
5174 pAllocateInfo
->allocationSize
,
5177 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
5180 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
5183 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
5184 uint32_t heap_index
;
5186 heap_index
= device
->physical_device
->memory_properties
.memoryTypes
[pAllocateInfo
->memoryTypeIndex
].heapIndex
;
5187 domain
= device
->physical_device
->memory_domains
[pAllocateInfo
->memoryTypeIndex
];
5188 flags
= device
->physical_device
->memory_flags
[pAllocateInfo
->memoryTypeIndex
];
5190 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
5191 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
5192 if (device
->use_global_bo_list
) {
5193 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
5197 if (device
->overallocation_disallowed
) {
5198 uint64_t total_size
=
5199 device
->physical_device
->memory_properties
.memoryHeaps
[heap_index
].size
;
5201 mtx_lock(&device
->overallocation_mutex
);
5202 if (device
->allocated_memory_size
[heap_index
] + alloc_size
> total_size
) {
5203 mtx_unlock(&device
->overallocation_mutex
);
5204 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
5207 device
->allocated_memory_size
[heap_index
] += alloc_size
;
5208 mtx_unlock(&device
->overallocation_mutex
);
5211 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
5212 domain
, flags
, priority
);
5215 if (device
->overallocation_disallowed
) {
5216 mtx_lock(&device
->overallocation_mutex
);
5217 device
->allocated_memory_size
[heap_index
] -= alloc_size
;
5218 mtx_unlock(&device
->overallocation_mutex
);
5220 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
5224 mem
->heap_index
= heap_index
;
5225 mem
->alloc_size
= alloc_size
;
5229 result
= radv_bo_list_add(device
, mem
->bo
);
5230 if (result
!= VK_SUCCESS
)
5234 *pMem
= radv_device_memory_to_handle(mem
);
5239 radv_free_memory(device
, pAllocator
,mem
);
5244 VkResult
radv_AllocateMemory(
5246 const VkMemoryAllocateInfo
* pAllocateInfo
,
5247 const VkAllocationCallbacks
* pAllocator
,
5248 VkDeviceMemory
* pMem
)
5250 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5251 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
5254 void radv_FreeMemory(
5256 VkDeviceMemory _mem
,
5257 const VkAllocationCallbacks
* pAllocator
)
5259 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5260 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
5262 radv_free_memory(device
, pAllocator
, mem
);
5265 VkResult
radv_MapMemory(
5267 VkDeviceMemory _memory
,
5268 VkDeviceSize offset
,
5270 VkMemoryMapFlags flags
,
5273 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5274 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
5282 *ppData
= mem
->user_ptr
;
5284 *ppData
= device
->ws
->buffer_map(mem
->bo
);
5291 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
5294 void radv_UnmapMemory(
5296 VkDeviceMemory _memory
)
5298 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5299 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
5304 if (mem
->user_ptr
== NULL
)
5305 device
->ws
->buffer_unmap(mem
->bo
);
5308 VkResult
radv_FlushMappedMemoryRanges(
5310 uint32_t memoryRangeCount
,
5311 const VkMappedMemoryRange
* pMemoryRanges
)
5316 VkResult
radv_InvalidateMappedMemoryRanges(
5318 uint32_t memoryRangeCount
,
5319 const VkMappedMemoryRange
* pMemoryRanges
)
5324 void radv_GetBufferMemoryRequirements(
5327 VkMemoryRequirements
* pMemoryRequirements
)
5329 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5330 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
5332 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
5334 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
5335 pMemoryRequirements
->alignment
= 4096;
5337 pMemoryRequirements
->alignment
= 16;
5339 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
5342 void radv_GetBufferMemoryRequirements2(
5344 const VkBufferMemoryRequirementsInfo2
*pInfo
,
5345 VkMemoryRequirements2
*pMemoryRequirements
)
5347 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
5348 &pMemoryRequirements
->memoryRequirements
);
5349 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
5350 switch (ext
->sType
) {
5351 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
5352 VkMemoryDedicatedRequirements
*req
=
5353 (VkMemoryDedicatedRequirements
*) ext
;
5354 req
->requiresDedicatedAllocation
= false;
5355 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
5364 void radv_GetImageMemoryRequirements(
5367 VkMemoryRequirements
* pMemoryRequirements
)
5369 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5370 RADV_FROM_HANDLE(radv_image
, image
, _image
);
5372 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
5374 pMemoryRequirements
->size
= image
->size
;
5375 pMemoryRequirements
->alignment
= image
->alignment
;
5378 void radv_GetImageMemoryRequirements2(
5380 const VkImageMemoryRequirementsInfo2
*pInfo
,
5381 VkMemoryRequirements2
*pMemoryRequirements
)
5383 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
5384 &pMemoryRequirements
->memoryRequirements
);
5386 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
5388 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
5389 switch (ext
->sType
) {
5390 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
5391 VkMemoryDedicatedRequirements
*req
=
5392 (VkMemoryDedicatedRequirements
*) ext
;
5393 req
->requiresDedicatedAllocation
= image
->shareable
&&
5394 image
->tiling
!= VK_IMAGE_TILING_LINEAR
;
5395 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
5404 void radv_GetImageSparseMemoryRequirements(
5407 uint32_t* pSparseMemoryRequirementCount
,
5408 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
5413 void radv_GetImageSparseMemoryRequirements2(
5415 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
5416 uint32_t* pSparseMemoryRequirementCount
,
5417 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
5422 void radv_GetDeviceMemoryCommitment(
5424 VkDeviceMemory memory
,
5425 VkDeviceSize
* pCommittedMemoryInBytes
)
5427 *pCommittedMemoryInBytes
= 0;
5430 VkResult
radv_BindBufferMemory2(VkDevice device
,
5431 uint32_t bindInfoCount
,
5432 const VkBindBufferMemoryInfo
*pBindInfos
)
5434 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5435 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
5436 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
5439 buffer
->bo
= mem
->bo
;
5440 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
5448 VkResult
radv_BindBufferMemory(
5451 VkDeviceMemory memory
,
5452 VkDeviceSize memoryOffset
)
5454 const VkBindBufferMemoryInfo info
= {
5455 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
5458 .memoryOffset
= memoryOffset
5461 return radv_BindBufferMemory2(device
, 1, &info
);
5464 VkResult
radv_BindImageMemory2(VkDevice device
,
5465 uint32_t bindInfoCount
,
5466 const VkBindImageMemoryInfo
*pBindInfos
)
5468 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5469 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
5470 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
5473 image
->bo
= mem
->bo
;
5474 image
->offset
= pBindInfos
[i
].memoryOffset
;
5484 VkResult
radv_BindImageMemory(
5487 VkDeviceMemory memory
,
5488 VkDeviceSize memoryOffset
)
5490 const VkBindImageMemoryInfo info
= {
5491 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
5494 .memoryOffset
= memoryOffset
5497 return radv_BindImageMemory2(device
, 1, &info
);
5500 static bool radv_sparse_bind_has_effects(const VkBindSparseInfo
*info
)
5502 return info
->bufferBindCount
||
5503 info
->imageOpaqueBindCount
||
5504 info
->imageBindCount
||
5505 info
->waitSemaphoreCount
||
5506 info
->signalSemaphoreCount
;
5509 VkResult
radv_QueueBindSparse(
5511 uint32_t bindInfoCount
,
5512 const VkBindSparseInfo
* pBindInfo
,
5515 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
5517 uint32_t fence_idx
= 0;
5519 if (fence
!= VK_NULL_HANDLE
) {
5520 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
)
5521 if (radv_sparse_bind_has_effects(pBindInfo
+ i
))
5524 fence_idx
= UINT32_MAX
;
5526 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5527 if (i
!= fence_idx
&& !radv_sparse_bind_has_effects(pBindInfo
+ i
))
5530 const VkTimelineSemaphoreSubmitInfo
*timeline_info
=
5531 vk_find_struct_const(pBindInfo
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO
);
5533 VkResult result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
5534 .buffer_binds
= pBindInfo
[i
].pBufferBinds
,
5535 .buffer_bind_count
= pBindInfo
[i
].bufferBindCount
,
5536 .image_opaque_binds
= pBindInfo
[i
].pImageOpaqueBinds
,
5537 .image_opaque_bind_count
= pBindInfo
[i
].imageOpaqueBindCount
,
5538 .wait_semaphores
= pBindInfo
[i
].pWaitSemaphores
,
5539 .wait_semaphore_count
= pBindInfo
[i
].waitSemaphoreCount
,
5540 .signal_semaphores
= pBindInfo
[i
].pSignalSemaphores
,
5541 .signal_semaphore_count
= pBindInfo
[i
].signalSemaphoreCount
,
5542 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
5543 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
5544 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
5545 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
5546 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
5549 if (result
!= VK_SUCCESS
)
5553 if (fence
!= VK_NULL_HANDLE
&& !bindInfoCount
) {
5554 result
= radv_signal_fence(queue
, fence
);
5555 if (result
!= VK_SUCCESS
)
5562 VkResult
radv_CreateFence(
5564 const VkFenceCreateInfo
* pCreateInfo
,
5565 const VkAllocationCallbacks
* pAllocator
,
5568 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5569 const VkExportFenceCreateInfo
*export
=
5570 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
5571 VkExternalFenceHandleTypeFlags handleTypes
=
5572 export
? export
->handleTypes
: 0;
5574 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
5576 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5579 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5581 fence
->fence_wsi
= NULL
;
5582 fence
->temp_syncobj
= 0;
5583 if (device
->always_use_syncobj
|| handleTypes
) {
5584 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
5586 vk_free2(&device
->alloc
, pAllocator
, fence
);
5587 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5589 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
5590 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
5592 fence
->fence
= NULL
;
5594 fence
->fence
= device
->ws
->create_fence();
5595 if (!fence
->fence
) {
5596 vk_free2(&device
->alloc
, pAllocator
, fence
);
5597 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5600 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
5601 device
->ws
->signal_fence(fence
->fence
);
5604 *pFence
= radv_fence_to_handle(fence
);
5609 void radv_DestroyFence(
5612 const VkAllocationCallbacks
* pAllocator
)
5614 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5615 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5620 if (fence
->temp_syncobj
)
5621 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5623 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
5625 device
->ws
->destroy_fence(fence
->fence
);
5626 if (fence
->fence_wsi
)
5627 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
5628 vk_free2(&device
->alloc
, pAllocator
, fence
);
5632 uint64_t radv_get_current_time(void)
5635 clock_gettime(CLOCK_MONOTONIC
, &tv
);
5636 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
5639 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
5641 uint64_t current_time
= radv_get_current_time();
5643 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
5645 return current_time
+ timeout
;
5649 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
5650 uint32_t fenceCount
, const VkFence
*pFences
)
5652 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5653 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5654 if (fence
->fence
== NULL
|| fence
->syncobj
||
5655 fence
->temp_syncobj
|| fence
->fence_wsi
||
5656 (!device
->ws
->is_fence_waitable(fence
->fence
)))
5662 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
5664 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5665 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5666 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
5672 VkResult
radv_WaitForFences(
5674 uint32_t fenceCount
,
5675 const VkFence
* pFences
,
5679 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5680 timeout
= radv_get_absolute_timeout(timeout
);
5682 if (device
->always_use_syncobj
&&
5683 radv_all_fences_syncobj(fenceCount
, pFences
))
5685 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
5687 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5689 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5690 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5691 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
5694 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
5697 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5700 if (!waitAll
&& fenceCount
> 1) {
5701 /* Not doing this by default for waitAll, due to needing to allocate twice. */
5702 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
5703 uint32_t wait_count
= 0;
5704 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
5706 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5708 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5709 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5711 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
5716 fences
[wait_count
++] = fence
->fence
;
5719 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
5720 waitAll
, timeout
- radv_get_current_time());
5723 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5726 while(radv_get_current_time() <= timeout
) {
5727 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5728 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
5735 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5736 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5737 bool expired
= false;
5739 if (fence
->temp_syncobj
) {
5740 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
5745 if (fence
->syncobj
) {
5746 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
5752 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
5753 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
5754 radv_get_current_time() <= timeout
)
5758 expired
= device
->ws
->fence_wait(device
->ws
,
5765 if (fence
->fence_wsi
) {
5766 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
5767 if (result
!= VK_SUCCESS
)
5775 VkResult
radv_ResetFences(VkDevice _device
,
5776 uint32_t fenceCount
,
5777 const VkFence
*pFences
)
5779 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5781 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
5782 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5784 device
->ws
->reset_fence(fence
->fence
);
5786 /* Per spec, we first restore the permanent payload, and then reset, so
5787 * having a temp syncobj should not skip resetting the permanent syncobj. */
5788 if (fence
->temp_syncobj
) {
5789 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5790 fence
->temp_syncobj
= 0;
5793 if (fence
->syncobj
) {
5794 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
5801 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
5803 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5804 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5806 if (fence
->temp_syncobj
) {
5807 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
5808 return success
? VK_SUCCESS
: VK_NOT_READY
;
5811 if (fence
->syncobj
) {
5812 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
5813 return success
? VK_SUCCESS
: VK_NOT_READY
;
5817 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
5818 return VK_NOT_READY
;
5820 if (fence
->fence_wsi
) {
5821 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
5823 if (result
!= VK_SUCCESS
) {
5824 if (result
== VK_TIMEOUT
)
5825 return VK_NOT_READY
;
5833 // Queue semaphore functions
5836 radv_create_timeline(struct radv_timeline
*timeline
, uint64_t value
)
5838 timeline
->highest_signaled
= value
;
5839 timeline
->highest_submitted
= value
;
5840 list_inithead(&timeline
->points
);
5841 list_inithead(&timeline
->free_points
);
5842 list_inithead(&timeline
->waiters
);
5843 pthread_mutex_init(&timeline
->mutex
, NULL
);
5847 radv_destroy_timeline(struct radv_device
*device
,
5848 struct radv_timeline
*timeline
)
5850 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5851 &timeline
->free_points
, list
) {
5852 list_del(&point
->list
);
5853 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
5856 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5857 &timeline
->points
, list
) {
5858 list_del(&point
->list
);
5859 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
5862 pthread_mutex_destroy(&timeline
->mutex
);
5866 radv_timeline_gc_locked(struct radv_device
*device
,
5867 struct radv_timeline
*timeline
)
5869 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5870 &timeline
->points
, list
) {
5871 if (point
->wait_count
|| point
->value
> timeline
->highest_submitted
)
5874 if (device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, 0)) {
5875 timeline
->highest_signaled
= point
->value
;
5876 list_del(&point
->list
);
5877 list_add(&point
->list
, &timeline
->free_points
);
5882 static struct radv_timeline_point
*
5883 radv_timeline_find_point_at_least_locked(struct radv_device
*device
,
5884 struct radv_timeline
*timeline
,
5887 radv_timeline_gc_locked(device
, timeline
);
5889 if (p
<= timeline
->highest_signaled
)
5892 list_for_each_entry(struct radv_timeline_point
, point
,
5893 &timeline
->points
, list
) {
5894 if (point
->value
>= p
) {
5895 ++point
->wait_count
;
5902 static struct radv_timeline_point
*
5903 radv_timeline_add_point_locked(struct radv_device
*device
,
5904 struct radv_timeline
*timeline
,
5907 radv_timeline_gc_locked(device
, timeline
);
5909 struct radv_timeline_point
*ret
= NULL
;
5910 struct radv_timeline_point
*prev
= NULL
;
5912 if (p
<= timeline
->highest_signaled
)
5915 list_for_each_entry(struct radv_timeline_point
, point
,
5916 &timeline
->points
, list
) {
5917 if (point
->value
== p
) {
5921 if (point
->value
< p
)
5925 if (list_is_empty(&timeline
->free_points
)) {
5926 ret
= malloc(sizeof(struct radv_timeline_point
));
5927 device
->ws
->create_syncobj(device
->ws
, &ret
->syncobj
);
5929 ret
= list_first_entry(&timeline
->free_points
, struct radv_timeline_point
, list
);
5930 list_del(&ret
->list
);
5932 device
->ws
->reset_syncobj(device
->ws
, ret
->syncobj
);
5936 ret
->wait_count
= 1;
5939 list_add(&ret
->list
, &prev
->list
);
5941 list_addtail(&ret
->list
, &timeline
->points
);
5948 radv_timeline_wait_locked(struct radv_device
*device
,
5949 struct radv_timeline
*timeline
,
5951 uint64_t abs_timeout
)
5953 while(timeline
->highest_submitted
< value
) {
5954 struct timespec abstime
;
5955 timespec_from_nsec(&abstime
, abs_timeout
);
5957 pthread_cond_timedwait(&device
->timeline_cond
, &timeline
->mutex
, &abstime
);
5959 if (radv_get_current_time() >= abs_timeout
&& timeline
->highest_submitted
< value
)
5963 struct radv_timeline_point
*point
= radv_timeline_find_point_at_least_locked(device
, timeline
, value
);
5967 pthread_mutex_unlock(&timeline
->mutex
);
5969 bool success
= device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, abs_timeout
);
5971 pthread_mutex_lock(&timeline
->mutex
);
5972 point
->wait_count
--;
5973 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5977 radv_timeline_trigger_waiters_locked(struct radv_timeline
*timeline
,
5978 struct list_head
*processing_list
)
5980 list_for_each_entry_safe(struct radv_timeline_waiter
, waiter
,
5981 &timeline
->waiters
, list
) {
5982 if (waiter
->value
> timeline
->highest_submitted
)
5985 if (p_atomic_dec_zero(&waiter
->submission
->submission_wait_count
)) {
5986 list_addtail(&waiter
->submission
->processing_list
, processing_list
);
5988 list_del(&waiter
->list
);
5993 void radv_destroy_semaphore_part(struct radv_device
*device
,
5994 struct radv_semaphore_part
*part
)
5996 switch(part
->kind
) {
5997 case RADV_SEMAPHORE_NONE
:
5999 case RADV_SEMAPHORE_WINSYS
:
6000 device
->ws
->destroy_sem(part
->ws_sem
);
6002 case RADV_SEMAPHORE_TIMELINE
:
6003 radv_destroy_timeline(device
, &part
->timeline
);
6005 case RADV_SEMAPHORE_SYNCOBJ
:
6006 device
->ws
->destroy_syncobj(device
->ws
, part
->syncobj
);
6009 part
->kind
= RADV_SEMAPHORE_NONE
;
6012 static VkSemaphoreTypeKHR
6013 radv_get_semaphore_type(const void *pNext
, uint64_t *initial_value
)
6015 const VkSemaphoreTypeCreateInfo
*type_info
=
6016 vk_find_struct_const(pNext
, SEMAPHORE_TYPE_CREATE_INFO
);
6019 return VK_SEMAPHORE_TYPE_BINARY
;
6022 *initial_value
= type_info
->initialValue
;
6023 return type_info
->semaphoreType
;
6026 VkResult
radv_CreateSemaphore(
6028 const VkSemaphoreCreateInfo
* pCreateInfo
,
6029 const VkAllocationCallbacks
* pAllocator
,
6030 VkSemaphore
* pSemaphore
)
6032 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6033 const VkExportSemaphoreCreateInfo
*export
=
6034 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
6035 VkExternalSemaphoreHandleTypeFlags handleTypes
=
6036 export
? export
->handleTypes
: 0;
6037 uint64_t initial_value
= 0;
6038 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pCreateInfo
->pNext
, &initial_value
);
6040 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
6042 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6044 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6046 sem
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
6047 sem
->permanent
.kind
= RADV_SEMAPHORE_NONE
;
6049 if (type
== VK_SEMAPHORE_TYPE_TIMELINE
) {
6050 radv_create_timeline(&sem
->permanent
.timeline
, initial_value
);
6051 sem
->permanent
.kind
= RADV_SEMAPHORE_TIMELINE
;
6052 } else if (device
->always_use_syncobj
|| handleTypes
) {
6053 assert (device
->physical_device
->rad_info
.has_syncobj
);
6054 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->permanent
.syncobj
);
6056 vk_free2(&device
->alloc
, pAllocator
, sem
);
6057 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6059 sem
->permanent
.kind
= RADV_SEMAPHORE_SYNCOBJ
;
6061 sem
->permanent
.ws_sem
= device
->ws
->create_sem(device
->ws
);
6062 if (!sem
->permanent
.ws_sem
) {
6063 vk_free2(&device
->alloc
, pAllocator
, sem
);
6064 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6066 sem
->permanent
.kind
= RADV_SEMAPHORE_WINSYS
;
6069 *pSemaphore
= radv_semaphore_to_handle(sem
);
6073 void radv_DestroySemaphore(
6075 VkSemaphore _semaphore
,
6076 const VkAllocationCallbacks
* pAllocator
)
6078 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6079 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
6083 radv_destroy_semaphore_part(device
, &sem
->temporary
);
6084 radv_destroy_semaphore_part(device
, &sem
->permanent
);
6085 vk_free2(&device
->alloc
, pAllocator
, sem
);
6089 radv_GetSemaphoreCounterValue(VkDevice _device
,
6090 VkSemaphore _semaphore
,
6093 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6094 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, _semaphore
);
6096 struct radv_semaphore_part
*part
=
6097 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
6099 switch (part
->kind
) {
6100 case RADV_SEMAPHORE_TIMELINE
: {
6101 pthread_mutex_lock(&part
->timeline
.mutex
);
6102 radv_timeline_gc_locked(device
, &part
->timeline
);
6103 *pValue
= part
->timeline
.highest_signaled
;
6104 pthread_mutex_unlock(&part
->timeline
.mutex
);
6107 case RADV_SEMAPHORE_NONE
:
6108 case RADV_SEMAPHORE_SYNCOBJ
:
6109 case RADV_SEMAPHORE_WINSYS
:
6110 unreachable("Invalid semaphore type");
6112 unreachable("Unhandled semaphore type");
6117 radv_wait_timelines(struct radv_device
*device
,
6118 const VkSemaphoreWaitInfo
* pWaitInfo
,
6119 uint64_t abs_timeout
)
6121 if ((pWaitInfo
->flags
& VK_SEMAPHORE_WAIT_ANY_BIT_KHR
) && pWaitInfo
->semaphoreCount
> 1) {
6123 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
6124 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
6125 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
6126 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], 0);
6127 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
6129 if (result
== VK_SUCCESS
)
6132 if (radv_get_current_time() > abs_timeout
)
6137 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
6138 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
6139 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
6140 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], abs_timeout
);
6141 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
6143 if (result
!= VK_SUCCESS
)
6149 radv_WaitSemaphores(VkDevice _device
,
6150 const VkSemaphoreWaitInfo
* pWaitInfo
,
6153 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6154 uint64_t abs_timeout
= radv_get_absolute_timeout(timeout
);
6155 return radv_wait_timelines(device
, pWaitInfo
, abs_timeout
);
6159 radv_SignalSemaphore(VkDevice _device
,
6160 const VkSemaphoreSignalInfo
* pSignalInfo
)
6162 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6163 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pSignalInfo
->semaphore
);
6165 struct radv_semaphore_part
*part
=
6166 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
6168 switch(part
->kind
) {
6169 case RADV_SEMAPHORE_TIMELINE
: {
6170 pthread_mutex_lock(&part
->timeline
.mutex
);
6171 radv_timeline_gc_locked(device
, &part
->timeline
);
6172 part
->timeline
.highest_submitted
= MAX2(part
->timeline
.highest_submitted
, pSignalInfo
->value
);
6173 part
->timeline
.highest_signaled
= MAX2(part
->timeline
.highest_signaled
, pSignalInfo
->value
);
6175 struct list_head processing_list
;
6176 list_inithead(&processing_list
);
6177 radv_timeline_trigger_waiters_locked(&part
->timeline
, &processing_list
);
6178 pthread_mutex_unlock(&part
->timeline
.mutex
);
6180 return radv_process_submissions(&processing_list
);
6182 case RADV_SEMAPHORE_NONE
:
6183 case RADV_SEMAPHORE_SYNCOBJ
:
6184 case RADV_SEMAPHORE_WINSYS
:
6185 unreachable("Invalid semaphore type");
6192 VkResult
radv_CreateEvent(
6194 const VkEventCreateInfo
* pCreateInfo
,
6195 const VkAllocationCallbacks
* pAllocator
,
6198 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6199 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
6201 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6204 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6206 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
6208 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
6209 RADV_BO_PRIORITY_FENCE
);
6211 vk_free2(&device
->alloc
, pAllocator
, event
);
6212 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6215 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
6217 *pEvent
= radv_event_to_handle(event
);
6222 void radv_DestroyEvent(
6225 const VkAllocationCallbacks
* pAllocator
)
6227 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6228 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6232 device
->ws
->buffer_destroy(event
->bo
);
6233 vk_free2(&device
->alloc
, pAllocator
, event
);
6236 VkResult
radv_GetEventStatus(
6240 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6242 if (*event
->map
== 1)
6243 return VK_EVENT_SET
;
6244 return VK_EVENT_RESET
;
6247 VkResult
radv_SetEvent(
6251 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6257 VkResult
radv_ResetEvent(
6261 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6267 VkResult
radv_CreateBuffer(
6269 const VkBufferCreateInfo
* pCreateInfo
,
6270 const VkAllocationCallbacks
* pAllocator
,
6273 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6274 struct radv_buffer
*buffer
;
6276 if (pCreateInfo
->size
> RADV_MAX_MEMORY_ALLOCATION_SIZE
)
6277 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
6279 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
6281 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
6282 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6284 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6286 buffer
->size
= pCreateInfo
->size
;
6287 buffer
->usage
= pCreateInfo
->usage
;
6290 buffer
->flags
= pCreateInfo
->flags
;
6292 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
6293 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
6295 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
6296 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
6297 align64(buffer
->size
, 4096),
6298 4096, 0, RADEON_FLAG_VIRTUAL
,
6299 RADV_BO_PRIORITY_VIRTUAL
);
6301 vk_free2(&device
->alloc
, pAllocator
, buffer
);
6302 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6306 *pBuffer
= radv_buffer_to_handle(buffer
);
6311 void radv_DestroyBuffer(
6314 const VkAllocationCallbacks
* pAllocator
)
6316 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6317 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
6322 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
6323 device
->ws
->buffer_destroy(buffer
->bo
);
6325 vk_free2(&device
->alloc
, pAllocator
, buffer
);
6328 VkDeviceAddress
radv_GetBufferDeviceAddress(
6330 const VkBufferDeviceAddressInfo
* pInfo
)
6332 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
6333 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
6337 uint64_t radv_GetBufferOpaqueCaptureAddress(VkDevice device
,
6338 const VkBufferDeviceAddressInfo
* pInfo
)
6343 uint64_t radv_GetDeviceMemoryOpaqueCaptureAddress(VkDevice device
,
6344 const VkDeviceMemoryOpaqueCaptureAddressInfo
* pInfo
)
6349 static inline unsigned
6350 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
6353 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
6355 return plane
->surface
.u
.legacy
.tiling_index
[level
];
6358 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
6360 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
6364 radv_init_dcc_control_reg(struct radv_device
*device
,
6365 struct radv_image_view
*iview
)
6367 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
6368 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
6369 unsigned max_compressed_block_size
;
6370 unsigned independent_128b_blocks
;
6371 unsigned independent_64b_blocks
;
6373 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
6376 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
6377 /* amdvlk: [min-compressed-block-size] should be set to 32 for
6378 * dGPU and 64 for APU because all of our APUs to date use
6379 * DIMMs which have a request granularity size of 64B while all
6380 * other chips have a 32B request size.
6382 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
6385 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6386 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
6387 independent_64b_blocks
= 0;
6388 independent_128b_blocks
= 1;
6390 independent_128b_blocks
= 0;
6392 if (iview
->image
->info
.samples
> 1) {
6393 if (iview
->image
->planes
[0].surface
.bpe
== 1)
6394 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
6395 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
6396 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
6399 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
6400 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
6401 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
6402 /* If this DCC image is potentially going to be used in texture
6403 * fetches, we need some special settings.
6405 independent_64b_blocks
= 1;
6406 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
6408 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
6409 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
6410 * big as possible for better compression state.
6412 independent_64b_blocks
= 0;
6413 max_compressed_block_size
= max_uncompressed_block_size
;
6417 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
6418 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
6419 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
6420 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
6421 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
6425 radv_initialise_color_surface(struct radv_device
*device
,
6426 struct radv_color_buffer_info
*cb
,
6427 struct radv_image_view
*iview
)
6429 const struct vk_format_description
*desc
;
6430 unsigned ntype
, format
, swap
, endian
;
6431 unsigned blend_clamp
= 0, blend_bypass
= 0;
6433 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
6434 const struct radeon_surf
*surf
= &plane
->surface
;
6436 desc
= vk_format_description(iview
->vk_format
);
6438 memset(cb
, 0, sizeof(*cb
));
6440 /* Intensity is implemented as Red, so treat it that way. */
6441 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
6443 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
6445 cb
->cb_color_base
= va
>> 8;
6447 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6448 struct gfx9_surf_meta_flags meta
;
6449 if (iview
->image
->dcc_offset
)
6450 meta
= surf
->u
.gfx9
.dcc
;
6452 meta
= surf
->u
.gfx9
.cmask
;
6454 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6455 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6456 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
6457 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
6458 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
6460 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6461 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
6462 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
6463 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
6464 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
6467 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
6468 cb
->cb_color_base
|= surf
->tile_swizzle
;
6470 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
6471 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
6473 cb
->cb_color_base
+= level_info
->offset
>> 8;
6474 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
6475 cb
->cb_color_base
|= surf
->tile_swizzle
;
6477 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
6478 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
6479 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
6481 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
6482 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
6483 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
6485 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
6487 if (radv_image_has_fmask(iview
->image
)) {
6488 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
6489 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
6490 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
6491 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
6493 /* This must be set for fast clear to work without FMASK. */
6494 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
6495 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
6496 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
6497 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
6501 /* CMASK variables */
6502 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6503 va
+= iview
->image
->cmask_offset
;
6504 cb
->cb_color_cmask
= va
>> 8;
6506 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6507 va
+= iview
->image
->dcc_offset
;
6509 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
6510 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
6511 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
6513 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
6514 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
6516 cb
->cb_dcc_base
= va
>> 8;
6517 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
6519 /* GFX10 field has the same base shift as the GFX6 field. */
6520 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
6521 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
6522 S_028C6C_SLICE_MAX_GFX10(max_slice
);
6524 if (iview
->image
->info
.samples
> 1) {
6525 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
6527 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
6528 S_028C74_NUM_FRAGMENTS(log_samples
);
6531 if (radv_image_has_fmask(iview
->image
)) {
6532 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
6533 cb
->cb_color_fmask
= va
>> 8;
6534 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
6536 cb
->cb_color_fmask
= cb
->cb_color_base
;
6539 ntype
= radv_translate_color_numformat(iview
->vk_format
,
6541 vk_format_get_first_non_void_channel(iview
->vk_format
));
6542 format
= radv_translate_colorformat(iview
->vk_format
);
6543 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
6544 radv_finishme("Illegal color\n");
6545 swap
= radv_translate_colorswap(iview
->vk_format
, false);
6546 endian
= radv_colorformat_endian_swap(format
);
6548 /* blend clamp should be set for all NORM/SRGB types */
6549 if (ntype
== V_028C70_NUMBER_UNORM
||
6550 ntype
== V_028C70_NUMBER_SNORM
||
6551 ntype
== V_028C70_NUMBER_SRGB
)
6554 /* set blend bypass according to docs if SINT/UINT or
6555 8/24 COLOR variants */
6556 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
6557 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
6558 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
6563 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
6564 (format
== V_028C70_COLOR_8
||
6565 format
== V_028C70_COLOR_8_8
||
6566 format
== V_028C70_COLOR_8_8_8_8
))
6567 ->color_is_int8
= true;
6569 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
6570 S_028C70_COMP_SWAP(swap
) |
6571 S_028C70_BLEND_CLAMP(blend_clamp
) |
6572 S_028C70_BLEND_BYPASS(blend_bypass
) |
6573 S_028C70_SIMPLE_FLOAT(1) |
6574 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
6575 ntype
!= V_028C70_NUMBER_SNORM
&&
6576 ntype
!= V_028C70_NUMBER_SRGB
&&
6577 format
!= V_028C70_COLOR_8_24
&&
6578 format
!= V_028C70_COLOR_24_8
) |
6579 S_028C70_NUMBER_TYPE(ntype
) |
6580 S_028C70_ENDIAN(endian
);
6581 if (radv_image_has_fmask(iview
->image
)) {
6582 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
6583 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
6584 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
6585 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
6588 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
6589 /* Allow the texture block to read FMASK directly
6590 * without decompressing it. This bit must be cleared
6591 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
6592 * otherwise the operation doesn't happen.
6594 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
6596 /* Set CMASK into a tiling format that allows the
6597 * texture block to read it.
6599 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
6603 if (radv_image_has_cmask(iview
->image
) &&
6604 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
6605 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
6607 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
6608 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
6610 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
6612 /* This must be set for fast clear to work without FMASK. */
6613 if (!radv_image_has_fmask(iview
->image
) &&
6614 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
6615 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
6616 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
6619 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6620 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
6622 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
6623 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
6624 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
6625 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
6627 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6628 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
6630 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
6631 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
6632 S_028EE0_RESOURCE_LEVEL(1);
6634 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
6635 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
6636 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
6639 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
6640 S_028C68_MIP0_HEIGHT(height
- 1) |
6641 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
6646 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
6647 struct radv_image_view
*iview
)
6649 unsigned max_zplanes
= 0;
6651 assert(radv_image_is_tc_compat_htile(iview
->image
));
6653 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6654 /* Default value for 32-bit depth surfaces. */
6657 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
6658 iview
->image
->info
.samples
> 1)
6661 max_zplanes
= max_zplanes
+ 1;
6663 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
6664 /* Do not enable Z plane compression for 16-bit depth
6665 * surfaces because isn't supported on GFX8. Only
6666 * 32-bit depth surfaces are supported by the hardware.
6667 * This allows to maintain shader compatibility and to
6668 * reduce the number of depth decompressions.
6672 if (iview
->image
->info
.samples
<= 1)
6674 else if (iview
->image
->info
.samples
<= 4)
6685 radv_initialise_ds_surface(struct radv_device
*device
,
6686 struct radv_ds_buffer_info
*ds
,
6687 struct radv_image_view
*iview
)
6689 unsigned level
= iview
->base_mip
;
6690 unsigned format
, stencil_format
;
6691 uint64_t va
, s_offs
, z_offs
;
6692 bool stencil_only
= false;
6693 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
6694 const struct radeon_surf
*surf
= &plane
->surface
;
6696 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
6698 memset(ds
, 0, sizeof(*ds
));
6699 switch (iview
->image
->vk_format
) {
6700 case VK_FORMAT_D24_UNORM_S8_UINT
:
6701 case VK_FORMAT_X8_D24_UNORM_PACK32
:
6702 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
6703 ds
->offset_scale
= 2.0f
;
6705 case VK_FORMAT_D16_UNORM
:
6706 case VK_FORMAT_D16_UNORM_S8_UINT
:
6707 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
6708 ds
->offset_scale
= 4.0f
;
6710 case VK_FORMAT_D32_SFLOAT
:
6711 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
6712 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
6713 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
6714 ds
->offset_scale
= 1.0f
;
6716 case VK_FORMAT_S8_UINT
:
6717 stencil_only
= true;
6723 format
= radv_translate_dbformat(iview
->image
->vk_format
);
6724 stencil_format
= surf
->has_stencil
?
6725 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
6727 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
6728 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
6729 S_028008_SLICE_MAX(max_slice
);
6730 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6731 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
6732 S_028008_SLICE_MAX_HI(max_slice
>> 11);
6735 ds
->db_htile_data_base
= 0;
6736 ds
->db_htile_surface
= 0;
6738 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6739 s_offs
= z_offs
= va
;
6741 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6742 assert(surf
->u
.gfx9
.surf_offset
== 0);
6743 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
6745 ds
->db_z_info
= S_028038_FORMAT(format
) |
6746 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
6747 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6748 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
6749 S_028038_ZRANGE_PRECISION(1);
6750 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
6751 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
6753 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6754 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
6755 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
6758 ds
->db_depth_view
|= S_028008_MIPID(level
);
6759 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
6760 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
6762 if (radv_htile_enabled(iview
->image
, level
)) {
6763 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
6765 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6766 unsigned max_zplanes
=
6767 radv_calc_decompress_on_z_planes(device
, iview
);
6769 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6771 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6772 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
6773 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
6775 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
6776 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
6780 if (!surf
->has_stencil
)
6781 /* Use all of the htile_buffer for depth if there's no stencil. */
6782 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
6783 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6784 iview
->image
->htile_offset
;
6785 ds
->db_htile_data_base
= va
>> 8;
6786 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
6787 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
6789 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6790 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
6794 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
6797 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
6799 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
6800 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
6802 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
6803 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
6804 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
6806 if (iview
->image
->info
.samples
> 1)
6807 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
6809 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
6810 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
6811 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
6812 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
6813 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
6814 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
6815 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
6816 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
6819 tile_mode
= stencil_tile_mode
;
6821 ds
->db_depth_info
|=
6822 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
6823 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
6824 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
6825 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
6826 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
6827 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
6828 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
6829 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
6831 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
6832 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
6833 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
6834 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
6836 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
6839 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
6840 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
6841 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
6843 if (radv_htile_enabled(iview
->image
, level
)) {
6844 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
6846 if (!surf
->has_stencil
&&
6847 !radv_image_is_tc_compat_htile(iview
->image
))
6848 /* Use all of the htile_buffer for depth if there's no stencil. */
6849 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
6851 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6852 iview
->image
->htile_offset
;
6853 ds
->db_htile_data_base
= va
>> 8;
6854 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
6856 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6857 unsigned max_zplanes
=
6858 radv_calc_decompress_on_z_planes(device
, iview
);
6860 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
6861 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6866 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
6867 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
6870 VkResult
radv_CreateFramebuffer(
6872 const VkFramebufferCreateInfo
* pCreateInfo
,
6873 const VkAllocationCallbacks
* pAllocator
,
6874 VkFramebuffer
* pFramebuffer
)
6876 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6877 struct radv_framebuffer
*framebuffer
;
6878 const VkFramebufferAttachmentsCreateInfo
*imageless_create_info
=
6879 vk_find_struct_const(pCreateInfo
->pNext
,
6880 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO
);
6882 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
6884 size_t size
= sizeof(*framebuffer
);
6885 if (!imageless_create_info
)
6886 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
6887 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
6888 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6889 if (framebuffer
== NULL
)
6890 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6892 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
6893 framebuffer
->width
= pCreateInfo
->width
;
6894 framebuffer
->height
= pCreateInfo
->height
;
6895 framebuffer
->layers
= pCreateInfo
->layers
;
6896 if (imageless_create_info
) {
6897 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
6898 const VkFramebufferAttachmentImageInfo
*attachment
=
6899 imageless_create_info
->pAttachmentImageInfos
+ i
;
6900 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
6901 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
6902 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
6905 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
6906 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
6907 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
6908 framebuffer
->attachments
[i
] = iview
;
6909 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
6910 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
6911 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
6915 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
6919 void radv_DestroyFramebuffer(
6922 const VkAllocationCallbacks
* pAllocator
)
6924 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6925 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
6929 vk_free2(&device
->alloc
, pAllocator
, fb
);
6932 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
6934 switch (address_mode
) {
6935 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
6936 return V_008F30_SQ_TEX_WRAP
;
6937 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
6938 return V_008F30_SQ_TEX_MIRROR
;
6939 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
6940 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
6941 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
6942 return V_008F30_SQ_TEX_CLAMP_BORDER
;
6943 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
6944 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
6946 unreachable("illegal tex wrap mode");
6952 radv_tex_compare(VkCompareOp op
)
6955 case VK_COMPARE_OP_NEVER
:
6956 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
6957 case VK_COMPARE_OP_LESS
:
6958 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
6959 case VK_COMPARE_OP_EQUAL
:
6960 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
6961 case VK_COMPARE_OP_LESS_OR_EQUAL
:
6962 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
6963 case VK_COMPARE_OP_GREATER
:
6964 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
6965 case VK_COMPARE_OP_NOT_EQUAL
:
6966 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
6967 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
6968 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
6969 case VK_COMPARE_OP_ALWAYS
:
6970 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
6972 unreachable("illegal compare mode");
6978 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
6981 case VK_FILTER_NEAREST
:
6982 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
6983 V_008F38_SQ_TEX_XY_FILTER_POINT
);
6984 case VK_FILTER_LINEAR
:
6985 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
6986 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
6987 case VK_FILTER_CUBIC_IMG
:
6989 fprintf(stderr
, "illegal texture filter");
6995 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
6998 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
6999 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
7000 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
7001 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
7003 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
7008 radv_tex_bordercolor(VkBorderColor bcolor
)
7011 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
7012 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
7013 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
7014 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
7015 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
7016 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
7017 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
7018 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
7019 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
7027 radv_tex_aniso_filter(unsigned filter
)
7041 radv_tex_filter_mode(VkSamplerReductionMode mode
)
7044 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
7045 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
7046 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
7047 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
7048 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
7049 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
7057 radv_get_max_anisotropy(struct radv_device
*device
,
7058 const VkSamplerCreateInfo
*pCreateInfo
)
7060 if (device
->force_aniso
>= 0)
7061 return device
->force_aniso
;
7063 if (pCreateInfo
->anisotropyEnable
&&
7064 pCreateInfo
->maxAnisotropy
> 1.0f
)
7065 return (uint32_t)pCreateInfo
->maxAnisotropy
;
7070 static inline int S_FIXED(float value
, unsigned frac_bits
)
7072 return value
* (1 << frac_bits
);
7076 radv_init_sampler(struct radv_device
*device
,
7077 struct radv_sampler
*sampler
,
7078 const VkSamplerCreateInfo
*pCreateInfo
)
7080 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
7081 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
7082 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
7083 device
->physical_device
->rad_info
.chip_class
== GFX9
;
7084 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
7085 unsigned depth_compare_func
= V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
7086 bool trunc_coord
= pCreateInfo
->minFilter
== VK_FILTER_NEAREST
&& pCreateInfo
->magFilter
== VK_FILTER_NEAREST
;
7088 const struct VkSamplerReductionModeCreateInfo
*sampler_reduction
=
7089 vk_find_struct_const(pCreateInfo
->pNext
,
7090 SAMPLER_REDUCTION_MODE_CREATE_INFO
);
7091 if (sampler_reduction
)
7092 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
7094 if (pCreateInfo
->compareEnable
)
7095 depth_compare_func
= radv_tex_compare(pCreateInfo
->compareOp
);
7097 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
7098 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
7099 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
7100 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
7101 S_008F30_DEPTH_COMPARE_FUNC(depth_compare_func
) |
7102 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
7103 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
7104 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
7105 S_008F30_DISABLE_CUBE_WRAP(0) |
7106 S_008F30_COMPAT_MODE(compat_mode
) |
7107 S_008F30_FILTER_MODE(filter_mode
) |
7108 S_008F30_TRUNC_COORD(trunc_coord
));
7109 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
7110 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
7111 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
7112 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
7113 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
7114 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
7115 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
7116 S_008F38_MIP_POINT_PRECLAMP(0));
7117 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
7118 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
7120 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
7121 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
7123 sampler
->state
[2] |=
7124 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
7125 S_008F38_FILTER_PREC_FIX(1) |
7126 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
7130 VkResult
radv_CreateSampler(
7132 const VkSamplerCreateInfo
* pCreateInfo
,
7133 const VkAllocationCallbacks
* pAllocator
,
7134 VkSampler
* pSampler
)
7136 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7137 struct radv_sampler
*sampler
;
7139 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
7140 vk_find_struct_const(pCreateInfo
->pNext
,
7141 SAMPLER_YCBCR_CONVERSION_INFO
);
7143 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
7145 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
7146 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
7148 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
7150 radv_init_sampler(device
, sampler
, pCreateInfo
);
7152 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
7153 *pSampler
= radv_sampler_to_handle(sampler
);
7158 void radv_DestroySampler(
7161 const VkAllocationCallbacks
* pAllocator
)
7163 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7164 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
7168 vk_free2(&device
->alloc
, pAllocator
, sampler
);
7171 /* vk_icd.h does not declare this function, so we declare it here to
7172 * suppress Wmissing-prototypes.
7174 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
7175 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
7177 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
7178 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
7180 /* For the full details on loader interface versioning, see
7181 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
7182 * What follows is a condensed summary, to help you navigate the large and
7183 * confusing official doc.
7185 * - Loader interface v0 is incompatible with later versions. We don't
7188 * - In loader interface v1:
7189 * - The first ICD entrypoint called by the loader is
7190 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
7192 * - The ICD must statically expose no other Vulkan symbol unless it is
7193 * linked with -Bsymbolic.
7194 * - Each dispatchable Vulkan handle created by the ICD must be
7195 * a pointer to a struct whose first member is VK_LOADER_DATA. The
7196 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
7197 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
7198 * vkDestroySurfaceKHR(). The ICD must be capable of working with
7199 * such loader-managed surfaces.
7201 * - Loader interface v2 differs from v1 in:
7202 * - The first ICD entrypoint called by the loader is
7203 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
7204 * statically expose this entrypoint.
7206 * - Loader interface v3 differs from v2 in:
7207 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
7208 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
7209 * because the loader no longer does so.
7211 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
7215 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
7216 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
7219 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7220 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
7222 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
7224 /* At the moment, we support only the below handle types. */
7225 assert(pGetFdInfo
->handleType
==
7226 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
7227 pGetFdInfo
->handleType
==
7228 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
7230 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
7232 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
7236 static uint32_t radv_compute_valid_memory_types_attempt(struct radv_physical_device
*dev
,
7237 enum radeon_bo_domain domains
,
7238 enum radeon_bo_flag flags
,
7239 enum radeon_bo_flag ignore_flags
)
7241 /* Don't count GTT/CPU as relevant:
7243 * - We're not fully consistent between the two.
7244 * - Sometimes VRAM gets VRAM|GTT.
7246 const enum radeon_bo_domain relevant_domains
= RADEON_DOMAIN_VRAM
|
7250 for (unsigned i
= 0; i
< dev
->memory_properties
.memoryTypeCount
; ++i
) {
7251 if ((domains
& relevant_domains
) != (dev
->memory_domains
[i
] & relevant_domains
))
7254 if ((flags
& ~ignore_flags
) != (dev
->memory_flags
[i
] & ~ignore_flags
))
7263 static uint32_t radv_compute_valid_memory_types(struct radv_physical_device
*dev
,
7264 enum radeon_bo_domain domains
,
7265 enum radeon_bo_flag flags
)
7267 enum radeon_bo_flag ignore_flags
= ~(RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_GTT_WC
);
7268 uint32_t bits
= radv_compute_valid_memory_types_attempt(dev
, domains
, flags
, ignore_flags
);
7271 ignore_flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
7272 bits
= radv_compute_valid_memory_types_attempt(dev
, domains
, flags
, ignore_flags
);
7277 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
7278 VkExternalMemoryHandleTypeFlagBits handleType
,
7280 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
7282 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7284 switch (handleType
) {
7285 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
: {
7286 enum radeon_bo_domain domains
;
7287 enum radeon_bo_flag flags
;
7288 if (!device
->ws
->buffer_get_flags_from_fd(device
->ws
, fd
, &domains
, &flags
))
7289 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7291 pMemoryFdProperties
->memoryTypeBits
= radv_compute_valid_memory_types(device
->physical_device
, domains
, flags
);
7295 /* The valid usage section for this function says:
7297 * "handleType must not be one of the handle types defined as
7300 * So opaque handle types fall into the default "unsupported" case.
7302 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7306 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
7310 uint32_t syncobj_handle
= 0;
7311 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
7313 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7316 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
7318 *syncobj
= syncobj_handle
;
7324 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
7328 /* If we create a syncobj we do it locally so that if we have an error, we don't
7329 * leave a syncobj in an undetermined state in the fence. */
7330 uint32_t syncobj_handle
= *syncobj
;
7331 if (!syncobj_handle
) {
7332 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
7334 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7339 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
7341 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
7343 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7346 *syncobj
= syncobj_handle
;
7353 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
7354 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
7356 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7357 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
7359 struct radv_semaphore_part
*dst
= NULL
;
7361 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
7362 dst
= &sem
->temporary
;
7364 dst
= &sem
->permanent
;
7367 uint32_t syncobj
= dst
->kind
== RADV_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
7369 switch(pImportSemaphoreFdInfo
->handleType
) {
7370 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7371 result
= radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
7373 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
7374 result
= radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
7377 unreachable("Unhandled semaphore handle type");
7380 if (result
== VK_SUCCESS
) {
7381 dst
->syncobj
= syncobj
;
7382 dst
->kind
= RADV_SEMAPHORE_SYNCOBJ
;
7388 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
7389 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
7392 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7393 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
7395 uint32_t syncobj_handle
;
7397 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
7398 assert(sem
->temporary
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
7399 syncobj_handle
= sem
->temporary
.syncobj
;
7401 assert(sem
->permanent
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
7402 syncobj_handle
= sem
->permanent
.syncobj
;
7405 switch(pGetFdInfo
->handleType
) {
7406 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7407 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
7409 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
7410 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
7412 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
7413 radv_destroy_semaphore_part(device
, &sem
->temporary
);
7415 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
7420 unreachable("Unhandled semaphore handle type");
7424 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7428 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
7429 VkPhysicalDevice physicalDevice
,
7430 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
7431 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
7433 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
7434 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pExternalSemaphoreInfo
->pNext
, NULL
);
7436 if (type
== VK_SEMAPHORE_TYPE_TIMELINE
) {
7437 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
7438 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
7439 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
7441 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
7442 } else if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
7443 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
7444 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
7445 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
7446 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
7447 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
7448 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7449 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
7450 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
7451 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
7452 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
7453 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7455 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
7456 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
7457 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
7461 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
7462 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
7464 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7465 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
7466 uint32_t *syncobj_dst
= NULL
;
7469 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
7470 syncobj_dst
= &fence
->temp_syncobj
;
7472 syncobj_dst
= &fence
->syncobj
;
7475 switch(pImportFenceFdInfo
->handleType
) {
7476 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7477 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
7478 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
7479 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
7481 unreachable("Unhandled fence handle type");
7485 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
7486 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
7489 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7490 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
7492 uint32_t syncobj_handle
;
7494 if (fence
->temp_syncobj
)
7495 syncobj_handle
= fence
->temp_syncobj
;
7497 syncobj_handle
= fence
->syncobj
;
7499 switch(pGetFdInfo
->handleType
) {
7500 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7501 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
7503 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
7504 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
7506 if (fence
->temp_syncobj
) {
7507 close (fence
->temp_syncobj
);
7508 fence
->temp_syncobj
= 0;
7510 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
7515 unreachable("Unhandled fence handle type");
7519 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7523 void radv_GetPhysicalDeviceExternalFenceProperties(
7524 VkPhysicalDevice physicalDevice
,
7525 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
7526 VkExternalFenceProperties
*pExternalFenceProperties
)
7528 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
7530 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
7531 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
7532 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
7533 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
7534 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
7535 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
7536 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7538 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
7539 pExternalFenceProperties
->compatibleHandleTypes
= 0;
7540 pExternalFenceProperties
->externalFenceFeatures
= 0;
7545 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
7546 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
7547 const VkAllocationCallbacks
* pAllocator
,
7548 VkDebugReportCallbackEXT
* pCallback
)
7550 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7551 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
7552 pCreateInfo
, pAllocator
, &instance
->alloc
,
7557 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
7558 VkDebugReportCallbackEXT _callback
,
7559 const VkAllocationCallbacks
* pAllocator
)
7561 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7562 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
7563 _callback
, pAllocator
, &instance
->alloc
);
7567 radv_DebugReportMessageEXT(VkInstance _instance
,
7568 VkDebugReportFlagsEXT flags
,
7569 VkDebugReportObjectTypeEXT objectType
,
7572 int32_t messageCode
,
7573 const char* pLayerPrefix
,
7574 const char* pMessage
)
7576 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7577 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
7578 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
7582 radv_GetDeviceGroupPeerMemoryFeatures(
7585 uint32_t localDeviceIndex
,
7586 uint32_t remoteDeviceIndex
,
7587 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
7589 assert(localDeviceIndex
== remoteDeviceIndex
);
7591 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
7592 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
7593 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
7594 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
7597 static const VkTimeDomainEXT radv_time_domains
[] = {
7598 VK_TIME_DOMAIN_DEVICE_EXT
,
7599 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
7600 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
7603 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
7604 VkPhysicalDevice physicalDevice
,
7605 uint32_t *pTimeDomainCount
,
7606 VkTimeDomainEXT
*pTimeDomains
)
7609 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
7611 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
7612 vk_outarray_append(&out
, i
) {
7613 *i
= radv_time_domains
[d
];
7617 return vk_outarray_status(&out
);
7621 radv_clock_gettime(clockid_t clock_id
)
7623 struct timespec current
;
7626 ret
= clock_gettime(clock_id
, ¤t
);
7627 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
7628 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
7632 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
7635 VkResult
radv_GetCalibratedTimestampsEXT(
7637 uint32_t timestampCount
,
7638 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
7639 uint64_t *pTimestamps
,
7640 uint64_t *pMaxDeviation
)
7642 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7643 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
7645 uint64_t begin
, end
;
7646 uint64_t max_clock_period
= 0;
7648 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
7650 for (d
= 0; d
< timestampCount
; d
++) {
7651 switch (pTimestampInfos
[d
].timeDomain
) {
7652 case VK_TIME_DOMAIN_DEVICE_EXT
:
7653 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
7655 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
7656 max_clock_period
= MAX2(max_clock_period
, device_period
);
7658 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
7659 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
7660 max_clock_period
= MAX2(max_clock_period
, 1);
7663 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
7664 pTimestamps
[d
] = begin
;
7672 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
7675 * The maximum deviation is the sum of the interval over which we
7676 * perform the sampling and the maximum period of any sampled
7677 * clock. That's because the maximum skew between any two sampled
7678 * clock edges is when the sampled clock with the largest period is
7679 * sampled at the end of that period but right at the beginning of the
7680 * sampling interval and some other clock is sampled right at the
7681 * begining of its sampling period and right at the end of the
7682 * sampling interval. Let's assume the GPU has the longest clock
7683 * period and that the application is sampling GPU and monotonic:
7686 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
7687 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
7691 * GPU -----_____-----_____-----_____-----_____
7694 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
7695 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
7697 * Interval <----------------->
7698 * Deviation <-------------------------->
7702 * m = read(monotonic) 2
7705 * We round the sample interval up by one tick to cover sampling error
7706 * in the interval clock
7709 uint64_t sample_interval
= end
- begin
+ 1;
7711 *pMaxDeviation
= sample_interval
+ max_clock_period
;
7716 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
7717 VkPhysicalDevice physicalDevice
,
7718 VkSampleCountFlagBits samples
,
7719 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
7721 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
7722 VK_SAMPLE_COUNT_4_BIT
|
7723 VK_SAMPLE_COUNT_8_BIT
)) {
7724 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
7726 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };