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_get_compiler_string(struct radv_physical_device
*pdevice
)
244 if (pdevice
->use_aco
) {
245 /* Some games like SotTR apply shader workarounds if the LLVM
246 * version is too old or if the LLVM version string is
247 * missing. This gives 2-5% performance with SotTR and ACO.
249 if (driQueryOptionb(&pdevice
->instance
->dri_options
,
250 "radv_report_llvm9_version_string")) {
251 return "ACO/LLVM 9.0.1";
257 return "LLVM " MESA_LLVM_VERSION_STRING
;
261 radv_physical_device_try_create(struct radv_instance
*instance
,
262 drmDevicePtr drm_device
,
263 struct radv_physical_device
**device_out
)
270 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
271 drmVersionPtr version
;
273 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
275 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
276 radv_logi("Could not open device '%s'", path
);
278 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
281 version
= drmGetVersion(fd
);
285 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
286 radv_logi("Could not get the kernel driver version for device '%s'", path
);
288 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
289 "failed to get version %s: %m", path
);
292 if (strcmp(version
->name
, "amdgpu")) {
293 drmFreeVersion(version
);
296 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
297 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
299 return VK_ERROR_INCOMPATIBLE_DRIVER
;
301 drmFreeVersion(version
);
303 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
304 radv_logi("Found compatible device '%s'.", path
);
307 struct radv_physical_device
*device
=
308 vk_zalloc2(&instance
->alloc
, NULL
, sizeof(*device
), 8,
309 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
311 result
= vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
315 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
316 device
->instance
= instance
;
319 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
320 instance
->perftest_flags
);
322 device
->ws
= radv_null_winsys_create();
326 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
327 "failed to initialize winsys");
331 if (drm_device
&& instance
->enabled_extensions
.KHR_display
) {
332 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
333 if (master_fd
>= 0) {
334 uint32_t accel_working
= 0;
335 struct drm_amdgpu_info request
= {
336 .return_pointer
= (uintptr_t)&accel_working
,
337 .return_size
= sizeof(accel_working
),
338 .query
= AMDGPU_INFO_ACCEL_WORKING
341 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
348 device
->master_fd
= master_fd
;
349 device
->local_fd
= fd
;
350 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
352 device
->use_aco
= instance
->perftest_flags
& RADV_PERFTEST_ACO
;
354 snprintf(device
->name
, sizeof(device
->name
),
356 device
->rad_info
.name
, radv_get_compiler_string(device
));
358 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
359 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
360 "cannot generate UUID");
364 /* These flags affect shader compilation. */
365 uint64_t shader_env_flags
= (device
->use_aco
? 0x2 : 0);
367 /* The gpu id is already embedded in the uuid so we just pass "radv"
368 * when creating the cache.
370 char buf
[VK_UUID_SIZE
* 2 + 1];
371 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
372 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
374 if (device
->rad_info
.chip_class
< GFX8
)
375 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
377 radv_get_driver_uuid(&device
->driver_uuid
);
378 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
380 device
->out_of_order_rast_allowed
= device
->rad_info
.has_out_of_order_rast
&&
381 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
383 device
->dcc_msaa_allowed
=
384 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
386 device
->use_shader_ballot
= (device
->use_aco
&& device
->rad_info
.chip_class
>= GFX8
) ||
387 (device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
);
389 device
->use_ngg
= device
->rad_info
.chip_class
>= GFX10
&&
390 device
->rad_info
.family
!= CHIP_NAVI14
&&
391 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_NGG
);
393 /* TODO: Implement NGG GS with ACO. */
394 device
->use_ngg_gs
= device
->use_ngg
&& !device
->use_aco
;
395 device
->use_ngg_streamout
= false;
397 /* Determine the number of threads per wave for all stages. */
398 device
->cs_wave_size
= 64;
399 device
->ps_wave_size
= 64;
400 device
->ge_wave_size
= 64;
402 if (device
->rad_info
.chip_class
>= GFX10
) {
403 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
404 device
->cs_wave_size
= 32;
406 /* For pixel shaders, wave64 is recommanded. */
407 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
408 device
->ps_wave_size
= 32;
410 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
411 device
->ge_wave_size
= 32;
414 radv_physical_device_init_mem_types(device
);
416 radv_physical_device_get_supported_extensions(device
,
417 &device
->supported_extensions
);
420 device
->bus_info
= *drm_device
->businfo
.pci
;
422 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
423 ac_print_gpu_info(&device
->rad_info
);
425 /* The WSI is structured as a layer on top of the driver, so this has
426 * to be the last part of initialization (at least until we get other
429 result
= radv_init_wsi(device
);
430 if (result
!= VK_SUCCESS
) {
431 vk_error(instance
, result
);
432 goto fail_disk_cache
;
435 *device_out
= device
;
440 disk_cache_destroy(device
->disk_cache
);
442 device
->ws
->destroy(device
->ws
);
444 vk_free(&instance
->alloc
, device
);
453 radv_physical_device_destroy(struct radv_physical_device
*device
)
455 radv_finish_wsi(device
);
456 device
->ws
->destroy(device
->ws
);
457 disk_cache_destroy(device
->disk_cache
);
458 close(device
->local_fd
);
459 if (device
->master_fd
!= -1)
460 close(device
->master_fd
);
461 vk_free(&device
->instance
->alloc
, device
);
465 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
466 VkSystemAllocationScope allocationScope
)
472 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
473 size_t align
, VkSystemAllocationScope allocationScope
)
475 return realloc(pOriginal
, size
);
479 default_free_func(void *pUserData
, void *pMemory
)
484 static const VkAllocationCallbacks default_alloc
= {
486 .pfnAllocation
= default_alloc_func
,
487 .pfnReallocation
= default_realloc_func
,
488 .pfnFree
= default_free_func
,
491 static const struct debug_control radv_debug_options
[] = {
492 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
493 {"nodcc", RADV_DEBUG_NO_DCC
},
494 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
495 {"nocache", RADV_DEBUG_NO_CACHE
},
496 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
497 {"nohiz", RADV_DEBUG_NO_HIZ
},
498 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
499 {"allbos", RADV_DEBUG_ALL_BOS
},
500 {"noibs", RADV_DEBUG_NO_IBS
},
501 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
502 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
503 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
504 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
505 {"preoptir", RADV_DEBUG_PREOPTIR
},
506 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
507 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
508 {"info", RADV_DEBUG_INFO
},
509 {"errors", RADV_DEBUG_ERRORS
},
510 {"startup", RADV_DEBUG_STARTUP
},
511 {"checkir", RADV_DEBUG_CHECKIR
},
512 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
513 {"nobinning", RADV_DEBUG_NOBINNING
},
514 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
515 {"nongg", RADV_DEBUG_NO_NGG
},
516 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
517 {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS
},
518 {"metashaders", RADV_DEBUG_DUMP_META_SHADERS
},
519 {"nomemorycache", RADV_DEBUG_NO_MEMORY_CACHE
},
524 radv_get_debug_option_name(int id
)
526 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
527 return radv_debug_options
[id
].string
;
530 static const struct debug_control radv_perftest_options
[] = {
531 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
532 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
533 {"bolist", RADV_PERFTEST_BO_LIST
},
534 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
535 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
536 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
537 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
538 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
539 {"dfsm", RADV_PERFTEST_DFSM
},
540 {"aco", RADV_PERFTEST_ACO
},
545 radv_get_perftest_option_name(int id
)
547 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
548 return radv_perftest_options
[id
].string
;
552 radv_handle_per_app_options(struct radv_instance
*instance
,
553 const VkApplicationInfo
*info
)
555 const char *name
= info
? info
->pApplicationName
: NULL
;
560 if (!strcmp(name
, "DOOM_VFR")) {
561 /* Work around a Doom VFR game bug */
562 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
563 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
564 /* Workaround for a WaW hazard when LLVM moves/merges
565 * load/store memory operations.
566 * See https://reviews.llvm.org/D61313
568 if (LLVM_VERSION_MAJOR
< 9)
569 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
570 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
571 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
) &&
572 !(instance
->perftest_flags
& RADV_PERFTEST_ACO
)) {
573 /* Force enable VK_AMD_shader_ballot because it looks
574 * safe and it gives a nice boost (+20% on Vega 56 at
575 * this time). It also prevents corruption on LLVM.
577 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
579 } else if (!strcmp(name
, "Fledge")) {
581 * Zero VRAM for "The Surge 2"
583 * This avoid a hang when when rendering any level. Likely
584 * uninitialized data in an indirect draw.
586 instance
->debug_flags
|= RADV_DEBUG_ZERO_VRAM
;
587 } else if (!strcmp(name
, "No Man's Sky")) {
588 /* Work around a NMS game bug */
589 instance
->debug_flags
|= RADV_DEBUG_DISCARD_TO_DEMOTE
;
593 static const char radv_dri_options_xml
[] =
595 DRI_CONF_SECTION_PERFORMANCE
596 DRI_CONF_ADAPTIVE_SYNC("true")
597 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
598 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
599 DRI_CONF_RADV_REPORT_LLVM9_VERSION_STRING("false")
602 DRI_CONF_SECTION_DEBUG
603 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
607 static void radv_init_dri_options(struct radv_instance
*instance
)
609 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
610 driParseConfigFiles(&instance
->dri_options
,
611 &instance
->available_dri_options
,
613 instance
->engineName
,
614 instance
->engineVersion
);
617 VkResult
radv_CreateInstance(
618 const VkInstanceCreateInfo
* pCreateInfo
,
619 const VkAllocationCallbacks
* pAllocator
,
620 VkInstance
* pInstance
)
622 struct radv_instance
*instance
;
625 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
626 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
628 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
630 vk_object_base_init(NULL
, &instance
->base
, VK_OBJECT_TYPE_INSTANCE
);
633 instance
->alloc
= *pAllocator
;
635 instance
->alloc
= default_alloc
;
637 if (pCreateInfo
->pApplicationInfo
) {
638 const VkApplicationInfo
*app
= pCreateInfo
->pApplicationInfo
;
640 instance
->engineName
=
641 vk_strdup(&instance
->alloc
, app
->pEngineName
,
642 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
643 instance
->engineVersion
= app
->engineVersion
;
644 instance
->apiVersion
= app
->apiVersion
;
647 if (instance
->apiVersion
== 0)
648 instance
->apiVersion
= VK_API_VERSION_1_0
;
650 /* Get secure compile thread count. NOTE: We cap this at 32 */
651 #define MAX_SC_PROCS 32
652 char *num_sc_threads
= getenv("RADV_SECURE_COMPILE_THREADS");
654 instance
->num_sc_threads
= MIN2(strtoul(num_sc_threads
, NULL
, 10), MAX_SC_PROCS
);
656 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
659 /* Disable memory cache when secure compile is set */
660 if (radv_device_use_secure_compile(instance
))
661 instance
->debug_flags
|= RADV_DEBUG_NO_MEMORY_CACHE
;
663 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
664 radv_perftest_options
);
666 if (instance
->perftest_flags
& RADV_PERFTEST_ACO
)
667 fprintf(stderr
, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
669 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
670 radv_logi("Created an instance");
672 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
674 for (idx
= 0; idx
< RADV_INSTANCE_EXTENSION_COUNT
; idx
++) {
675 if (!strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
676 radv_instance_extensions
[idx
].extensionName
))
680 if (idx
>= RADV_INSTANCE_EXTENSION_COUNT
||
681 !radv_instance_extensions_supported
.extensions
[idx
]) {
682 vk_free2(&default_alloc
, pAllocator
, instance
);
683 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
686 instance
->enabled_extensions
.extensions
[idx
] = true;
689 bool unchecked
= instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
;
691 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
692 /* Vulkan requires that entrypoints for extensions which have
693 * not been enabled must not be advertised.
696 !radv_instance_entrypoint_is_enabled(i
, instance
->apiVersion
,
697 &instance
->enabled_extensions
)) {
698 instance
->dispatch
.entrypoints
[i
] = NULL
;
700 instance
->dispatch
.entrypoints
[i
] =
701 radv_instance_dispatch_table
.entrypoints
[i
];
705 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->physical_device_dispatch
.entrypoints
); i
++) {
706 /* Vulkan requires that entrypoints for extensions which have
707 * not been enabled must not be advertised.
710 !radv_physical_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
711 &instance
->enabled_extensions
)) {
712 instance
->physical_device_dispatch
.entrypoints
[i
] = NULL
;
714 instance
->physical_device_dispatch
.entrypoints
[i
] =
715 radv_physical_device_dispatch_table
.entrypoints
[i
];
719 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->device_dispatch
.entrypoints
); i
++) {
720 /* Vulkan requires that entrypoints for extensions which have
721 * not been enabled must not be advertised.
724 !radv_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
725 &instance
->enabled_extensions
, NULL
)) {
726 instance
->device_dispatch
.entrypoints
[i
] = NULL
;
728 instance
->device_dispatch
.entrypoints
[i
] =
729 radv_device_dispatch_table
.entrypoints
[i
];
733 instance
->physical_devices_enumerated
= false;
734 list_inithead(&instance
->physical_devices
);
736 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
737 if (result
!= VK_SUCCESS
) {
738 vk_free2(&default_alloc
, pAllocator
, instance
);
739 return vk_error(instance
, result
);
742 glsl_type_singleton_init_or_ref();
744 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
746 radv_init_dri_options(instance
);
747 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
749 *pInstance
= radv_instance_to_handle(instance
);
754 void radv_DestroyInstance(
755 VkInstance _instance
,
756 const VkAllocationCallbacks
* pAllocator
)
758 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
763 list_for_each_entry_safe(struct radv_physical_device
, pdevice
,
764 &instance
->physical_devices
, link
) {
765 radv_physical_device_destroy(pdevice
);
768 vk_free(&instance
->alloc
, instance
->engineName
);
770 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
772 glsl_type_singleton_decref();
774 driDestroyOptionCache(&instance
->dri_options
);
775 driDestroyOptionInfo(&instance
->available_dri_options
);
777 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
779 vk_object_base_finish(&instance
->base
);
780 vk_free(&instance
->alloc
, instance
);
784 radv_enumerate_physical_devices(struct radv_instance
*instance
)
786 if (instance
->physical_devices_enumerated
)
789 instance
->physical_devices_enumerated
= true;
791 /* TODO: Check for more devices ? */
792 drmDevicePtr devices
[8];
793 VkResult result
= VK_SUCCESS
;
796 if (getenv("RADV_FORCE_FAMILY")) {
797 /* When RADV_FORCE_FAMILY is set, the driver creates a nul
798 * device that allows to test the compiler without having an
801 struct radv_physical_device
*pdevice
;
803 result
= radv_physical_device_try_create(instance
, NULL
, &pdevice
);
804 if (result
!= VK_SUCCESS
)
807 list_addtail(&pdevice
->link
, &instance
->physical_devices
);
811 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
813 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
814 radv_logi("Found %d drm nodes", max_devices
);
817 return vk_error(instance
, VK_SUCCESS
);
819 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
820 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
821 devices
[i
]->bustype
== DRM_BUS_PCI
&&
822 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
824 struct radv_physical_device
*pdevice
;
825 result
= radv_physical_device_try_create(instance
, devices
[i
],
827 /* Incompatible DRM device, skip. */
828 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
833 /* Error creating the physical device, report the error. */
834 if (result
!= VK_SUCCESS
)
837 list_addtail(&pdevice
->link
, &instance
->physical_devices
);
840 drmFreeDevices(devices
, max_devices
);
842 /* If we successfully enumerated any devices, call it success */
846 VkResult
radv_EnumeratePhysicalDevices(
847 VkInstance _instance
,
848 uint32_t* pPhysicalDeviceCount
,
849 VkPhysicalDevice
* pPhysicalDevices
)
851 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
852 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
854 VkResult result
= radv_enumerate_physical_devices(instance
);
855 if (result
!= VK_SUCCESS
)
858 list_for_each_entry(struct radv_physical_device
, pdevice
,
859 &instance
->physical_devices
, link
) {
860 vk_outarray_append(&out
, i
) {
861 *i
= radv_physical_device_to_handle(pdevice
);
865 return vk_outarray_status(&out
);
868 VkResult
radv_EnumeratePhysicalDeviceGroups(
869 VkInstance _instance
,
870 uint32_t* pPhysicalDeviceGroupCount
,
871 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
873 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
874 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
875 pPhysicalDeviceGroupCount
);
877 VkResult result
= radv_enumerate_physical_devices(instance
);
878 if (result
!= VK_SUCCESS
)
881 list_for_each_entry(struct radv_physical_device
, pdevice
,
882 &instance
->physical_devices
, link
) {
883 vk_outarray_append(&out
, p
) {
884 p
->physicalDeviceCount
= 1;
885 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
886 p
->physicalDevices
[0] = radv_physical_device_to_handle(pdevice
);
887 p
->subsetAllocation
= false;
891 return vk_outarray_status(&out
);
894 void radv_GetPhysicalDeviceFeatures(
895 VkPhysicalDevice physicalDevice
,
896 VkPhysicalDeviceFeatures
* pFeatures
)
898 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
899 memset(pFeatures
, 0, sizeof(*pFeatures
));
901 *pFeatures
= (VkPhysicalDeviceFeatures
) {
902 .robustBufferAccess
= true,
903 .fullDrawIndexUint32
= true,
904 .imageCubeArray
= true,
905 .independentBlend
= true,
906 .geometryShader
= true,
907 .tessellationShader
= true,
908 .sampleRateShading
= true,
909 .dualSrcBlend
= true,
911 .multiDrawIndirect
= true,
912 .drawIndirectFirstInstance
= true,
914 .depthBiasClamp
= true,
915 .fillModeNonSolid
= true,
920 .multiViewport
= true,
921 .samplerAnisotropy
= true,
922 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
923 .textureCompressionASTC_LDR
= false,
924 .textureCompressionBC
= true,
925 .occlusionQueryPrecise
= true,
926 .pipelineStatisticsQuery
= true,
927 .vertexPipelineStoresAndAtomics
= true,
928 .fragmentStoresAndAtomics
= true,
929 .shaderTessellationAndGeometryPointSize
= true,
930 .shaderImageGatherExtended
= true,
931 .shaderStorageImageExtendedFormats
= true,
932 .shaderStorageImageMultisample
= true,
933 .shaderUniformBufferArrayDynamicIndexing
= true,
934 .shaderSampledImageArrayDynamicIndexing
= true,
935 .shaderStorageBufferArrayDynamicIndexing
= true,
936 .shaderStorageImageArrayDynamicIndexing
= true,
937 .shaderStorageImageReadWithoutFormat
= true,
938 .shaderStorageImageWriteWithoutFormat
= true,
939 .shaderClipDistance
= true,
940 .shaderCullDistance
= true,
941 .shaderFloat64
= true,
943 .shaderInt16
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
,
944 .sparseBinding
= true,
945 .variableMultisampleRate
= true,
946 .inheritedQueries
= true,
950 void radv_GetPhysicalDeviceFeatures2(
951 VkPhysicalDevice physicalDevice
,
952 VkPhysicalDeviceFeatures2
*pFeatures
)
954 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
955 vk_foreach_struct(ext
, pFeatures
->pNext
) {
956 switch (ext
->sType
) {
957 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
958 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
959 features
->variablePointersStorageBuffer
= true;
960 features
->variablePointers
= true;
963 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
964 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
965 features
->multiview
= true;
966 features
->multiviewGeometryShader
= true;
967 features
->multiviewTessellationShader
= true;
970 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
971 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
972 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
973 features
->shaderDrawParameters
= true;
976 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
977 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
978 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
979 features
->protectedMemory
= false;
982 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
983 VkPhysicalDevice16BitStorageFeatures
*features
=
984 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
985 bool enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
986 features
->storageBuffer16BitAccess
= enable
;
987 features
->uniformAndStorageBuffer16BitAccess
= enable
;
988 features
->storagePushConstant16
= enable
;
989 features
->storageInputOutput16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
&& LLVM_VERSION_MAJOR
>= 9;
992 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
993 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
994 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
995 features
->samplerYcbcrConversion
= true;
998 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES
: {
999 VkPhysicalDeviceDescriptorIndexingFeatures
*features
=
1000 (VkPhysicalDeviceDescriptorIndexingFeatures
*)ext
;
1001 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
1002 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
1003 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
1004 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
1005 features
->shaderSampledImageArrayNonUniformIndexing
= true;
1006 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
1007 features
->shaderStorageImageArrayNonUniformIndexing
= true;
1008 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
1009 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
1010 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
1011 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
1012 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
1013 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
1014 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
1015 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
1016 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
1017 features
->descriptorBindingUpdateUnusedWhilePending
= true;
1018 features
->descriptorBindingPartiallyBound
= true;
1019 features
->descriptorBindingVariableDescriptorCount
= true;
1020 features
->runtimeDescriptorArray
= true;
1023 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
1024 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
1025 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
1026 features
->conditionalRendering
= true;
1027 features
->inheritedConditionalRendering
= false;
1030 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
1031 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1032 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1033 features
->vertexAttributeInstanceRateDivisor
= true;
1034 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1037 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1038 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1039 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1040 features
->transformFeedback
= true;
1041 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
1044 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES
: {
1045 VkPhysicalDeviceScalarBlockLayoutFeatures
*features
=
1046 (VkPhysicalDeviceScalarBlockLayoutFeatures
*)ext
;
1047 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
1050 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
1051 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
1052 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
1053 features
->memoryPriority
= true;
1056 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1057 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
1058 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
1059 features
->bufferDeviceAddress
= true;
1060 features
->bufferDeviceAddressCaptureReplay
= false;
1061 features
->bufferDeviceAddressMultiDevice
= false;
1064 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES
: {
1065 VkPhysicalDeviceBufferDeviceAddressFeatures
*features
=
1066 (VkPhysicalDeviceBufferDeviceAddressFeatures
*)ext
;
1067 features
->bufferDeviceAddress
= true;
1068 features
->bufferDeviceAddressCaptureReplay
= false;
1069 features
->bufferDeviceAddressMultiDevice
= false;
1072 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1073 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1074 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1075 features
->depthClipEnable
= true;
1078 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES
: {
1079 VkPhysicalDeviceHostQueryResetFeatures
*features
=
1080 (VkPhysicalDeviceHostQueryResetFeatures
*)ext
;
1081 features
->hostQueryReset
= true;
1084 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES
: {
1085 VkPhysicalDevice8BitStorageFeatures
*features
=
1086 (VkPhysicalDevice8BitStorageFeatures
*)ext
;
1087 bool enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1088 features
->storageBuffer8BitAccess
= enable
;
1089 features
->uniformAndStorageBuffer8BitAccess
= enable
;
1090 features
->storagePushConstant8
= enable
;
1093 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES
: {
1094 VkPhysicalDeviceShaderFloat16Int8Features
*features
=
1095 (VkPhysicalDeviceShaderFloat16Int8Features
*)ext
;
1096 features
->shaderFloat16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
;
1097 features
->shaderInt8
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1100 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES
: {
1101 VkPhysicalDeviceShaderAtomicInt64Features
*features
=
1102 (VkPhysicalDeviceShaderAtomicInt64Features
*)ext
;
1103 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1104 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1107 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1108 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
=
1109 (VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*)ext
;
1110 features
->shaderDemoteToHelperInvocation
= pdevice
->use_aco
;
1113 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1114 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1115 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1117 features
->inlineUniformBlock
= true;
1118 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1121 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1122 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1123 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1124 features
->computeDerivativeGroupQuads
= false;
1125 features
->computeDerivativeGroupLinear
= true;
1128 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1129 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1130 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1131 features
->ycbcrImageArrays
= true;
1134 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES
: {
1135 VkPhysicalDeviceUniformBufferStandardLayoutFeatures
*features
=
1136 (VkPhysicalDeviceUniformBufferStandardLayoutFeatures
*)ext
;
1137 features
->uniformBufferStandardLayout
= true;
1140 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1141 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1142 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1143 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES
: {
1147 VkPhysicalDeviceImagelessFramebufferFeatures
*features
=
1148 (VkPhysicalDeviceImagelessFramebufferFeatures
*)ext
;
1149 features
->imagelessFramebuffer
= true;
1152 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1153 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1154 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1155 features
->pipelineExecutableInfo
= true;
1158 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1159 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1160 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1161 features
->shaderSubgroupClock
= true;
1162 features
->shaderDeviceClock
= false;
1165 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1166 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1167 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1168 features
->texelBufferAlignment
= true;
1171 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES
: {
1172 VkPhysicalDeviceTimelineSemaphoreFeatures
*features
=
1173 (VkPhysicalDeviceTimelineSemaphoreFeatures
*) ext
;
1174 features
->timelineSemaphore
= true;
1177 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1178 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1179 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1180 features
->subgroupSizeControl
= true;
1181 features
->computeFullSubgroups
= true;
1184 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COHERENT_MEMORY_FEATURES_AMD
: {
1185 VkPhysicalDeviceCoherentMemoryFeaturesAMD
*features
=
1186 (VkPhysicalDeviceCoherentMemoryFeaturesAMD
*)ext
;
1187 features
->deviceCoherentMemory
= pdevice
->rad_info
.has_l2_uncached
;
1190 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES
: {
1191 VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
*features
=
1192 (VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
*)ext
;
1193 features
->shaderSubgroupExtendedTypes
= !pdevice
->use_aco
;
1196 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES_KHR
: {
1197 VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*features
=
1198 (VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*)ext
;
1199 features
->separateDepthStencilLayouts
= true;
1202 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
: {
1203 VkPhysicalDeviceVulkan11Features
*features
=
1204 (VkPhysicalDeviceVulkan11Features
*)ext
;
1205 bool storage16_enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1206 features
->storageBuffer16BitAccess
= storage16_enable
;
1207 features
->uniformAndStorageBuffer16BitAccess
= storage16_enable
;
1208 features
->storagePushConstant16
= storage16_enable
;
1209 features
->storageInputOutput16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
&& LLVM_VERSION_MAJOR
>= 9;
1210 features
->multiview
= true;
1211 features
->multiviewGeometryShader
= true;
1212 features
->multiviewTessellationShader
= true;
1213 features
->variablePointersStorageBuffer
= true;
1214 features
->variablePointers
= true;
1215 features
->protectedMemory
= false;
1216 features
->samplerYcbcrConversion
= true;
1217 features
->shaderDrawParameters
= true;
1220 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
: {
1221 VkPhysicalDeviceVulkan12Features
*features
=
1222 (VkPhysicalDeviceVulkan12Features
*)ext
;
1223 bool int8_enable
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1224 features
->samplerMirrorClampToEdge
= true;
1225 features
->drawIndirectCount
= true;
1226 features
->storageBuffer8BitAccess
= int8_enable
;
1227 features
->uniformAndStorageBuffer8BitAccess
= int8_enable
;
1228 features
->storagePushConstant8
= int8_enable
;
1229 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1230 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1231 features
->shaderFloat16
= pdevice
->rad_info
.has_double_rate_fp16
&& !pdevice
->use_aco
;
1232 features
->shaderInt8
= int8_enable
;
1233 features
->descriptorIndexing
= true;
1234 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
1235 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
1236 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
1237 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
1238 features
->shaderSampledImageArrayNonUniformIndexing
= true;
1239 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
1240 features
->shaderStorageImageArrayNonUniformIndexing
= true;
1241 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
1242 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
1243 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
1244 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
1245 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
1246 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
1247 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
1248 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
1249 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
1250 features
->descriptorBindingUpdateUnusedWhilePending
= true;
1251 features
->descriptorBindingPartiallyBound
= true;
1252 features
->descriptorBindingVariableDescriptorCount
= true;
1253 features
->runtimeDescriptorArray
= true;
1254 features
->samplerFilterMinmax
= true;
1255 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
1256 features
->imagelessFramebuffer
= true;
1257 features
->uniformBufferStandardLayout
= true;
1258 features
->shaderSubgroupExtendedTypes
= !pdevice
->use_aco
;
1259 features
->separateDepthStencilLayouts
= true;
1260 features
->hostQueryReset
= true;
1261 features
->timelineSemaphore
= pdevice
->rad_info
.has_syncobj_wait_for_submit
;
1262 features
->bufferDeviceAddress
= true;
1263 features
->bufferDeviceAddressCaptureReplay
= false;
1264 features
->bufferDeviceAddressMultiDevice
= false;
1265 features
->vulkanMemoryModel
= false;
1266 features
->vulkanMemoryModelDeviceScope
= false;
1267 features
->vulkanMemoryModelAvailabilityVisibilityChains
= false;
1268 features
->shaderOutputViewportIndex
= true;
1269 features
->shaderOutputLayer
= true;
1270 features
->subgroupBroadcastDynamicId
= true;
1273 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1274 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1275 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1276 features
->rectangularLines
= false;
1277 features
->bresenhamLines
= true;
1278 features
->smoothLines
= false;
1279 features
->stippledRectangularLines
= false;
1280 features
->stippledBresenhamLines
= true;
1281 features
->stippledSmoothLines
= false;
1284 case VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD
: {
1285 VkDeviceMemoryOverallocationCreateInfoAMD
*features
=
1286 (VkDeviceMemoryOverallocationCreateInfoAMD
*)ext
;
1287 features
->overallocationBehavior
= true;
1290 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT
: {
1291 VkPhysicalDeviceRobustness2FeaturesEXT
*features
=
1292 (VkPhysicalDeviceRobustness2FeaturesEXT
*)ext
;
1293 features
->robustBufferAccess2
= true;
1294 features
->robustImageAccess2
= true;
1295 features
->nullDescriptor
= true;
1298 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT
: {
1299 VkPhysicalDevicePrivateDataFeaturesEXT
*features
=
1300 (VkPhysicalDevicePrivateDataFeaturesEXT
*)ext
;
1301 features
->privateData
= true;
1308 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1312 radv_max_descriptor_set_size()
1314 /* make sure that the entire descriptor set is addressable with a signed
1315 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1316 * be at most 2 GiB. the combined image & samples object count as one of
1317 * both. This limit is for the pipeline layout, not for the set layout, but
1318 * there is no set limit, so we just set a pipeline limit. I don't think
1319 * any app is going to hit this soon. */
1320 return ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
1321 - MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1322 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1323 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1324 32 /* sampler, largest when combined with image */ +
1325 64 /* sampled image */ +
1326 64 /* storage image */);
1329 void radv_GetPhysicalDeviceProperties(
1330 VkPhysicalDevice physicalDevice
,
1331 VkPhysicalDeviceProperties
* pProperties
)
1333 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1334 VkSampleCountFlags sample_counts
= 0xf;
1336 size_t max_descriptor_set_size
= radv_max_descriptor_set_size();
1338 VkPhysicalDeviceLimits limits
= {
1339 .maxImageDimension1D
= (1 << 14),
1340 .maxImageDimension2D
= (1 << 14),
1341 .maxImageDimension3D
= (1 << 11),
1342 .maxImageDimensionCube
= (1 << 14),
1343 .maxImageArrayLayers
= (1 << 11),
1344 .maxTexelBufferElements
= UINT32_MAX
,
1345 .maxUniformBufferRange
= UINT32_MAX
,
1346 .maxStorageBufferRange
= UINT32_MAX
,
1347 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1348 .maxMemoryAllocationCount
= UINT32_MAX
,
1349 .maxSamplerAllocationCount
= 64 * 1024,
1350 .bufferImageGranularity
= 64, /* A cache line */
1351 .sparseAddressSpaceSize
= RADV_MAX_MEMORY_ALLOCATION_SIZE
, /* buffer max size */
1352 .maxBoundDescriptorSets
= MAX_SETS
,
1353 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1354 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1355 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1356 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1357 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1358 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1359 .maxPerStageResources
= max_descriptor_set_size
,
1360 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1361 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1362 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1363 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1364 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1365 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1366 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1367 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1368 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1369 .maxVertexInputBindings
= MAX_VBS
,
1370 .maxVertexInputAttributeOffset
= 2047,
1371 .maxVertexInputBindingStride
= 2048,
1372 .maxVertexOutputComponents
= 128,
1373 .maxTessellationGenerationLevel
= 64,
1374 .maxTessellationPatchSize
= 32,
1375 .maxTessellationControlPerVertexInputComponents
= 128,
1376 .maxTessellationControlPerVertexOutputComponents
= 128,
1377 .maxTessellationControlPerPatchOutputComponents
= 120,
1378 .maxTessellationControlTotalOutputComponents
= 4096,
1379 .maxTessellationEvaluationInputComponents
= 128,
1380 .maxTessellationEvaluationOutputComponents
= 128,
1381 .maxGeometryShaderInvocations
= 127,
1382 .maxGeometryInputComponents
= 64,
1383 .maxGeometryOutputComponents
= 128,
1384 .maxGeometryOutputVertices
= 256,
1385 .maxGeometryTotalOutputComponents
= 1024,
1386 .maxFragmentInputComponents
= 128,
1387 .maxFragmentOutputAttachments
= 8,
1388 .maxFragmentDualSrcAttachments
= 1,
1389 .maxFragmentCombinedOutputResources
= 8,
1390 .maxComputeSharedMemorySize
= 32768,
1391 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1392 .maxComputeWorkGroupInvocations
= 1024,
1393 .maxComputeWorkGroupSize
= {
1398 .subPixelPrecisionBits
= 8,
1399 .subTexelPrecisionBits
= 8,
1400 .mipmapPrecisionBits
= 8,
1401 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1402 .maxDrawIndirectCount
= UINT32_MAX
,
1403 .maxSamplerLodBias
= 16,
1404 .maxSamplerAnisotropy
= 16,
1405 .maxViewports
= MAX_VIEWPORTS
,
1406 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1407 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1408 .viewportSubPixelBits
= 8,
1409 .minMemoryMapAlignment
= 4096, /* A page */
1410 .minTexelBufferOffsetAlignment
= 4,
1411 .minUniformBufferOffsetAlignment
= 4,
1412 .minStorageBufferOffsetAlignment
= 4,
1413 .minTexelOffset
= -32,
1414 .maxTexelOffset
= 31,
1415 .minTexelGatherOffset
= -32,
1416 .maxTexelGatherOffset
= 31,
1417 .minInterpolationOffset
= -2,
1418 .maxInterpolationOffset
= 2,
1419 .subPixelInterpolationOffsetBits
= 8,
1420 .maxFramebufferWidth
= (1 << 14),
1421 .maxFramebufferHeight
= (1 << 14),
1422 .maxFramebufferLayers
= (1 << 10),
1423 .framebufferColorSampleCounts
= sample_counts
,
1424 .framebufferDepthSampleCounts
= sample_counts
,
1425 .framebufferStencilSampleCounts
= sample_counts
,
1426 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1427 .maxColorAttachments
= MAX_RTS
,
1428 .sampledImageColorSampleCounts
= sample_counts
,
1429 .sampledImageIntegerSampleCounts
= sample_counts
,
1430 .sampledImageDepthSampleCounts
= sample_counts
,
1431 .sampledImageStencilSampleCounts
= sample_counts
,
1432 .storageImageSampleCounts
= sample_counts
,
1433 .maxSampleMaskWords
= 1,
1434 .timestampComputeAndGraphics
= true,
1435 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1436 .maxClipDistances
= 8,
1437 .maxCullDistances
= 8,
1438 .maxCombinedClipAndCullDistances
= 8,
1439 .discreteQueuePriorities
= 2,
1440 .pointSizeRange
= { 0.0, 8192.0 },
1441 .lineWidthRange
= { 0.0, 8192.0 },
1442 .pointSizeGranularity
= (1.0 / 8.0),
1443 .lineWidthGranularity
= (1.0 / 8.0),
1444 .strictLines
= false, /* FINISHME */
1445 .standardSampleLocations
= true,
1446 .optimalBufferCopyOffsetAlignment
= 128,
1447 .optimalBufferCopyRowPitchAlignment
= 128,
1448 .nonCoherentAtomSize
= 64,
1451 *pProperties
= (VkPhysicalDeviceProperties
) {
1452 .apiVersion
= radv_physical_device_api_version(pdevice
),
1453 .driverVersion
= vk_get_driver_version(),
1454 .vendorID
= ATI_VENDOR_ID
,
1455 .deviceID
= pdevice
->rad_info
.pci_id
,
1456 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1458 .sparseProperties
= {0},
1461 strcpy(pProperties
->deviceName
, pdevice
->name
);
1462 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1466 radv_get_physical_device_properties_1_1(struct radv_physical_device
*pdevice
,
1467 VkPhysicalDeviceVulkan11Properties
*p
)
1469 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
);
1471 memcpy(p
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1472 memcpy(p
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1473 memset(p
->deviceLUID
, 0, VK_LUID_SIZE
);
1474 /* The LUID is for Windows. */
1475 p
->deviceLUIDValid
= false;
1476 p
->deviceNodeMask
= 0;
1478 p
->subgroupSize
= RADV_SUBGROUP_SIZE
;
1479 p
->subgroupSupportedStages
= VK_SHADER_STAGE_ALL_GRAPHICS
|
1480 VK_SHADER_STAGE_COMPUTE_BIT
;
1481 p
->subgroupSupportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1482 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1483 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1484 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1485 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1486 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1488 if (((pdevice
->rad_info
.chip_class
== GFX6
||
1489 pdevice
->rad_info
.chip_class
== GFX7
) && !pdevice
->use_aco
) ||
1490 pdevice
->rad_info
.chip_class
>= GFX8
) {
1491 p
->subgroupSupportedOperations
|= VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1492 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1494 p
->subgroupQuadOperationsInAllStages
= true;
1496 p
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1497 p
->maxMultiviewViewCount
= MAX_VIEWS
;
1498 p
->maxMultiviewInstanceIndex
= INT_MAX
;
1499 p
->protectedNoFault
= false;
1500 p
->maxPerSetDescriptors
= RADV_MAX_PER_SET_DESCRIPTORS
;
1501 p
->maxMemoryAllocationSize
= RADV_MAX_MEMORY_ALLOCATION_SIZE
;
1505 radv_get_physical_device_properties_1_2(struct radv_physical_device
*pdevice
,
1506 VkPhysicalDeviceVulkan12Properties
*p
)
1508 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
);
1510 p
->driverID
= VK_DRIVER_ID_MESA_RADV
;
1511 snprintf(p
->driverName
, VK_MAX_DRIVER_NAME_SIZE
, "radv");
1512 snprintf(p
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE
,
1513 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
" (%s)",
1514 radv_get_compiler_string(pdevice
));
1515 p
->conformanceVersion
= (VkConformanceVersion
) {
1522 /* On AMD hardware, denormals and rounding modes for fp16/fp64 are
1523 * controlled by the same config register.
1525 if (pdevice
->rad_info
.has_double_rate_fp16
) {
1526 p
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1527 p
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1529 p
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1530 p
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1533 /* Do not allow both preserving and flushing denorms because different
1534 * shaders in the same pipeline can have different settings and this
1535 * won't work for merged shaders. To make it work, this requires LLVM
1536 * support for changing the register. The same logic applies for the
1537 * rounding modes because they are configured with the same config
1538 * register. TODO: we can enable a lot of these for ACO when it
1539 * supports all stages.
1541 p
->shaderDenormFlushToZeroFloat32
= true;
1542 p
->shaderDenormPreserveFloat32
= false;
1543 p
->shaderRoundingModeRTEFloat32
= true;
1544 p
->shaderRoundingModeRTZFloat32
= false;
1545 p
->shaderSignedZeroInfNanPreserveFloat32
= true;
1547 p
->shaderDenormFlushToZeroFloat16
= false;
1548 p
->shaderDenormPreserveFloat16
= pdevice
->rad_info
.has_double_rate_fp16
;
1549 p
->shaderRoundingModeRTEFloat16
= pdevice
->rad_info
.has_double_rate_fp16
;
1550 p
->shaderRoundingModeRTZFloat16
= false;
1551 p
->shaderSignedZeroInfNanPreserveFloat16
= pdevice
->rad_info
.has_double_rate_fp16
;
1553 p
->shaderDenormFlushToZeroFloat64
= false;
1554 p
->shaderDenormPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1555 p
->shaderRoundingModeRTEFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1556 p
->shaderRoundingModeRTZFloat64
= false;
1557 p
->shaderSignedZeroInfNanPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1559 p
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1560 p
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1561 p
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1562 p
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1563 p
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1564 p
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1565 p
->robustBufferAccessUpdateAfterBind
= false;
1566 p
->quadDivergentImplicitLod
= false;
1568 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1569 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1570 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1571 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1572 32 /* sampler, largest when combined with image */ +
1573 64 /* sampled image */ +
1574 64 /* storage image */);
1575 p
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1576 p
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1577 p
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1578 p
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1579 p
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1580 p
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1581 p
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1582 p
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1583 p
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1584 p
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1585 p
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1586 p
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1587 p
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1588 p
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1589 p
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1591 /* We support all of the depth resolve modes */
1592 p
->supportedDepthResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1593 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1594 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1595 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1597 /* Average doesn't make sense for stencil so we don't support that */
1598 p
->supportedStencilResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1599 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1600 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1602 p
->independentResolveNone
= true;
1603 p
->independentResolve
= true;
1605 /* GFX6-8 only support single channel min/max filter. */
1606 p
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1607 p
->filterMinmaxSingleComponentFormats
= true;
1609 p
->maxTimelineSemaphoreValueDifference
= UINT64_MAX
;
1611 p
->framebufferIntegerColorSampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1614 void radv_GetPhysicalDeviceProperties2(
1615 VkPhysicalDevice physicalDevice
,
1616 VkPhysicalDeviceProperties2
*pProperties
)
1618 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1619 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1621 VkPhysicalDeviceVulkan11Properties core_1_1
= {
1622 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
,
1624 radv_get_physical_device_properties_1_1(pdevice
, &core_1_1
);
1626 VkPhysicalDeviceVulkan12Properties core_1_2
= {
1627 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
,
1629 radv_get_physical_device_properties_1_2(pdevice
, &core_1_2
);
1631 #define CORE_RENAMED_PROPERTY(major, minor, ext_property, core_property) \
1632 memcpy(&properties->ext_property, &core_##major##_##minor.core_property, \
1633 sizeof(core_##major##_##minor.core_property))
1635 #define CORE_PROPERTY(major, minor, property) \
1636 CORE_RENAMED_PROPERTY(major, minor, property, property)
1638 vk_foreach_struct(ext
, pProperties
->pNext
) {
1639 switch (ext
->sType
) {
1640 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1641 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1642 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1643 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1646 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1647 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1648 CORE_PROPERTY(1, 1, deviceUUID
);
1649 CORE_PROPERTY(1, 1, driverUUID
);
1650 CORE_PROPERTY(1, 1, deviceLUID
);
1651 CORE_PROPERTY(1, 1, deviceLUIDValid
);
1654 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1655 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1656 CORE_PROPERTY(1, 1, maxMultiviewViewCount
);
1657 CORE_PROPERTY(1, 1, maxMultiviewInstanceIndex
);
1660 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1661 VkPhysicalDevicePointClippingProperties
*properties
=
1662 (VkPhysicalDevicePointClippingProperties
*)ext
;
1663 CORE_PROPERTY(1, 1, pointClippingBehavior
);
1666 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1667 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1668 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1669 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1672 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1673 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1674 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1675 properties
->minImportedHostPointerAlignment
= 4096;
1678 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1679 VkPhysicalDeviceSubgroupProperties
*properties
=
1680 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1681 CORE_PROPERTY(1, 1, subgroupSize
);
1682 CORE_RENAMED_PROPERTY(1, 1, supportedStages
,
1683 subgroupSupportedStages
);
1684 CORE_RENAMED_PROPERTY(1, 1, supportedOperations
,
1685 subgroupSupportedOperations
);
1686 CORE_RENAMED_PROPERTY(1, 1, quadOperationsInAllStages
,
1687 subgroupQuadOperationsInAllStages
);
1690 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1691 VkPhysicalDeviceMaintenance3Properties
*properties
=
1692 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1693 CORE_PROPERTY(1, 1, maxPerSetDescriptors
);
1694 CORE_PROPERTY(1, 1, maxMemoryAllocationSize
);
1697 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES
: {
1698 VkPhysicalDeviceSamplerFilterMinmaxProperties
*properties
=
1699 (VkPhysicalDeviceSamplerFilterMinmaxProperties
*)ext
;
1700 CORE_PROPERTY(1, 2, filterMinmaxImageComponentMapping
);
1701 CORE_PROPERTY(1, 2, filterMinmaxSingleComponentFormats
);
1704 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1705 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1706 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1708 /* Shader engines. */
1709 properties
->shaderEngineCount
=
1710 pdevice
->rad_info
.max_se
;
1711 properties
->shaderArraysPerEngineCount
=
1712 pdevice
->rad_info
.max_sh_per_se
;
1713 properties
->computeUnitsPerShaderArray
=
1714 pdevice
->rad_info
.num_good_cu_per_sh
;
1715 properties
->simdPerComputeUnit
=
1716 pdevice
->rad_info
.num_simd_per_compute_unit
;
1717 properties
->wavefrontsPerSimd
=
1718 pdevice
->rad_info
.max_wave64_per_simd
;
1719 properties
->wavefrontSize
= 64;
1722 properties
->sgprsPerSimd
=
1723 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1724 properties
->minSgprAllocation
=
1725 pdevice
->rad_info
.min_sgpr_alloc
;
1726 properties
->maxSgprAllocation
=
1727 pdevice
->rad_info
.max_sgpr_alloc
;
1728 properties
->sgprAllocationGranularity
=
1729 pdevice
->rad_info
.sgpr_alloc_granularity
;
1732 properties
->vgprsPerSimd
=
1733 pdevice
->rad_info
.num_physical_wave64_vgprs_per_simd
;
1734 properties
->minVgprAllocation
=
1735 pdevice
->rad_info
.min_wave64_vgpr_alloc
;
1736 properties
->maxVgprAllocation
=
1737 pdevice
->rad_info
.max_vgpr_alloc
;
1738 properties
->vgprAllocationGranularity
=
1739 pdevice
->rad_info
.wave64_vgpr_alloc_granularity
;
1742 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1743 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1744 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1746 properties
->shaderCoreFeatures
= 0;
1747 properties
->activeComputeUnitCount
=
1748 pdevice
->rad_info
.num_good_compute_units
;
1751 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1752 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1753 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1754 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1757 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES
: {
1758 VkPhysicalDeviceDescriptorIndexingProperties
*properties
=
1759 (VkPhysicalDeviceDescriptorIndexingProperties
*)ext
;
1760 CORE_PROPERTY(1, 2, maxUpdateAfterBindDescriptorsInAllPools
);
1761 CORE_PROPERTY(1, 2, shaderUniformBufferArrayNonUniformIndexingNative
);
1762 CORE_PROPERTY(1, 2, shaderSampledImageArrayNonUniformIndexingNative
);
1763 CORE_PROPERTY(1, 2, shaderStorageBufferArrayNonUniformIndexingNative
);
1764 CORE_PROPERTY(1, 2, shaderStorageImageArrayNonUniformIndexingNative
);
1765 CORE_PROPERTY(1, 2, shaderInputAttachmentArrayNonUniformIndexingNative
);
1766 CORE_PROPERTY(1, 2, robustBufferAccessUpdateAfterBind
);
1767 CORE_PROPERTY(1, 2, quadDivergentImplicitLod
);
1768 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSamplers
);
1769 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindUniformBuffers
);
1770 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageBuffers
);
1771 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSampledImages
);
1772 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageImages
);
1773 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindInputAttachments
);
1774 CORE_PROPERTY(1, 2, maxPerStageUpdateAfterBindResources
);
1775 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSamplers
);
1776 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffers
);
1777 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
);
1778 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffers
);
1779 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
);
1780 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSampledImages
);
1781 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageImages
);
1782 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindInputAttachments
);
1785 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1786 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1787 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1788 CORE_PROPERTY(1, 1, protectedNoFault
);
1791 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1792 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1793 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1794 properties
->primitiveOverestimationSize
= 0;
1795 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1796 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1797 properties
->primitiveUnderestimation
= false;
1798 properties
->conservativePointAndLineRasterization
= false;
1799 properties
->degenerateTrianglesRasterized
= false;
1800 properties
->degenerateLinesRasterized
= false;
1801 properties
->fullyCoveredFragmentShaderInputVariable
= false;
1802 properties
->conservativeRasterizationPostDepthCoverage
= false;
1805 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1806 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1807 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1808 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1809 properties
->pciBus
= pdevice
->bus_info
.bus
;
1810 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1811 properties
->pciFunction
= pdevice
->bus_info
.func
;
1814 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES
: {
1815 VkPhysicalDeviceDriverProperties
*properties
=
1816 (VkPhysicalDeviceDriverProperties
*) ext
;
1817 CORE_PROPERTY(1, 2, driverID
);
1818 CORE_PROPERTY(1, 2, driverName
);
1819 CORE_PROPERTY(1, 2, driverInfo
);
1820 CORE_PROPERTY(1, 2, conformanceVersion
);
1823 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1824 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1825 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1826 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1827 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1828 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1829 properties
->maxTransformFeedbackStreamDataSize
= 512;
1830 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1831 properties
->maxTransformFeedbackBufferDataStride
= 512;
1832 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1833 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1834 properties
->transformFeedbackRasterizationStreamSelect
= false;
1835 properties
->transformFeedbackDraw
= true;
1838 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1839 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1840 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1842 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1843 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1844 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1845 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1846 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1849 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1850 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1851 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1852 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1853 VK_SAMPLE_COUNT_4_BIT
|
1854 VK_SAMPLE_COUNT_8_BIT
;
1855 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1856 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1857 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1858 properties
->sampleLocationSubPixelBits
= 4;
1859 properties
->variableSampleLocations
= false;
1862 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES
: {
1863 VkPhysicalDeviceDepthStencilResolveProperties
*properties
=
1864 (VkPhysicalDeviceDepthStencilResolveProperties
*)ext
;
1865 CORE_PROPERTY(1, 2, supportedDepthResolveModes
);
1866 CORE_PROPERTY(1, 2, supportedStencilResolveModes
);
1867 CORE_PROPERTY(1, 2, independentResolveNone
);
1868 CORE_PROPERTY(1, 2, independentResolve
);
1871 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1872 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*properties
=
1873 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1874 properties
->storageTexelBufferOffsetAlignmentBytes
= 4;
1875 properties
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1876 properties
->uniformTexelBufferOffsetAlignmentBytes
= 4;
1877 properties
->uniformTexelBufferOffsetSingleTexelAlignment
= true;
1880 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES
: {
1881 VkPhysicalDeviceFloatControlsProperties
*properties
=
1882 (VkPhysicalDeviceFloatControlsProperties
*)ext
;
1883 CORE_PROPERTY(1, 2, denormBehaviorIndependence
);
1884 CORE_PROPERTY(1, 2, roundingModeIndependence
);
1885 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat16
);
1886 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat16
);
1887 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat16
);
1888 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat16
);
1889 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat16
);
1890 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat32
);
1891 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat32
);
1892 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat32
);
1893 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat32
);
1894 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat32
);
1895 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat64
);
1896 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat64
);
1897 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat64
);
1898 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat64
);
1899 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat64
);
1902 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES
: {
1903 VkPhysicalDeviceTimelineSemaphoreProperties
*properties
=
1904 (VkPhysicalDeviceTimelineSemaphoreProperties
*) ext
;
1905 CORE_PROPERTY(1, 2, maxTimelineSemaphoreValueDifference
);
1908 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
1909 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
1910 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
1911 props
->minSubgroupSize
= 64;
1912 props
->maxSubgroupSize
= 64;
1913 props
->maxComputeWorkgroupSubgroups
= UINT32_MAX
;
1914 props
->requiredSubgroupSizeStages
= 0;
1916 if (pdevice
->rad_info
.chip_class
>= GFX10
) {
1917 /* Only GFX10+ supports wave32. */
1918 props
->minSubgroupSize
= 32;
1919 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1923 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
:
1924 radv_get_physical_device_properties_1_1(pdevice
, (void *)ext
);
1926 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
:
1927 radv_get_physical_device_properties_1_2(pdevice
, (void *)ext
);
1929 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1930 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1931 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1932 props
->lineSubPixelPrecisionBits
= 4;
1935 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_PROPERTIES_EXT
: {
1936 VkPhysicalDeviceRobustness2PropertiesEXT
*properties
=
1937 (VkPhysicalDeviceRobustness2PropertiesEXT
*)ext
;
1938 properties
->robustStorageBufferAccessSizeAlignment
= 4;
1939 properties
->robustUniformBufferAccessSizeAlignment
= 4;
1948 static void radv_get_physical_device_queue_family_properties(
1949 struct radv_physical_device
* pdevice
,
1951 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1953 int num_queue_families
= 1;
1955 if (pdevice
->rad_info
.num_rings
[RING_COMPUTE
] > 0 &&
1956 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1957 num_queue_families
++;
1959 if (pQueueFamilyProperties
== NULL
) {
1960 *pCount
= num_queue_families
;
1969 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1970 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1971 VK_QUEUE_COMPUTE_BIT
|
1972 VK_QUEUE_TRANSFER_BIT
|
1973 VK_QUEUE_SPARSE_BINDING_BIT
,
1975 .timestampValidBits
= 64,
1976 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1981 if (pdevice
->rad_info
.num_rings
[RING_COMPUTE
] > 0 &&
1982 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1983 if (*pCount
> idx
) {
1984 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1985 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1986 VK_QUEUE_TRANSFER_BIT
|
1987 VK_QUEUE_SPARSE_BINDING_BIT
,
1988 .queueCount
= pdevice
->rad_info
.num_rings
[RING_COMPUTE
],
1989 .timestampValidBits
= 64,
1990 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1998 void radv_GetPhysicalDeviceQueueFamilyProperties(
1999 VkPhysicalDevice physicalDevice
,
2001 VkQueueFamilyProperties
* pQueueFamilyProperties
)
2003 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
2004 if (!pQueueFamilyProperties
) {
2005 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
2008 VkQueueFamilyProperties
*properties
[] = {
2009 pQueueFamilyProperties
+ 0,
2010 pQueueFamilyProperties
+ 1,
2011 pQueueFamilyProperties
+ 2,
2013 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
2014 assert(*pCount
<= 3);
2017 void radv_GetPhysicalDeviceQueueFamilyProperties2(
2018 VkPhysicalDevice physicalDevice
,
2020 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
2022 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
2023 if (!pQueueFamilyProperties
) {
2024 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
2027 VkQueueFamilyProperties
*properties
[] = {
2028 &pQueueFamilyProperties
[0].queueFamilyProperties
,
2029 &pQueueFamilyProperties
[1].queueFamilyProperties
,
2030 &pQueueFamilyProperties
[2].queueFamilyProperties
,
2032 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
2033 assert(*pCount
<= 3);
2036 void radv_GetPhysicalDeviceMemoryProperties(
2037 VkPhysicalDevice physicalDevice
,
2038 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
2040 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2042 *pMemoryProperties
= physical_device
->memory_properties
;
2046 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
2047 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
2049 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2050 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
2051 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
2052 uint64_t vram_size
= radv_get_vram_size(device
);
2053 uint64_t gtt_size
= device
->rad_info
.gart_size
;
2054 uint64_t heap_budget
, heap_usage
;
2056 /* For all memory heaps, the computation of budget is as follow:
2057 * heap_budget = heap_size - global_heap_usage + app_heap_usage
2059 * The Vulkan spec 1.1.97 says that the budget should include any
2060 * currently allocated device memory.
2062 * Note that the application heap usages are not really accurate (eg.
2063 * in presence of shared buffers).
2065 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
2066 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
2068 if ((device
->memory_domains
[i
] & RADEON_DOMAIN_VRAM
) && (device
->memory_flags
[i
] & RADEON_FLAG_NO_CPU_ACCESS
)) {
2069 heap_usage
= device
->ws
->query_value(device
->ws
,
2070 RADEON_ALLOCATED_VRAM
);
2072 heap_budget
= vram_size
-
2073 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
2076 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2077 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2078 } else if (device
->memory_domains
[i
] & RADEON_DOMAIN_VRAM
) {
2079 heap_usage
= device
->ws
->query_value(device
->ws
,
2080 RADEON_ALLOCATED_VRAM_VIS
);
2082 heap_budget
= visible_vram_size
-
2083 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
2086 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2087 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2089 assert(device
->memory_domains
[i
] & RADEON_DOMAIN_GTT
);
2091 heap_usage
= device
->ws
->query_value(device
->ws
,
2092 RADEON_ALLOCATED_GTT
);
2094 heap_budget
= gtt_size
-
2095 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
2098 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2099 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2103 /* The heapBudget and heapUsage values must be zero for array elements
2104 * greater than or equal to
2105 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
2107 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
2108 memoryBudget
->heapBudget
[i
] = 0;
2109 memoryBudget
->heapUsage
[i
] = 0;
2113 void radv_GetPhysicalDeviceMemoryProperties2(
2114 VkPhysicalDevice physicalDevice
,
2115 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
2117 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
2118 &pMemoryProperties
->memoryProperties
);
2120 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
2121 vk_find_struct(pMemoryProperties
->pNext
,
2122 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
2124 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
2127 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
2129 VkExternalMemoryHandleTypeFlagBits handleType
,
2130 const void *pHostPointer
,
2131 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
2133 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2137 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
2138 const struct radv_physical_device
*physical_device
= device
->physical_device
;
2139 uint32_t memoryTypeBits
= 0;
2140 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
2141 if (physical_device
->memory_domains
[i
] == RADEON_DOMAIN_GTT
&&
2142 !(physical_device
->memory_flags
[i
] & RADEON_FLAG_GTT_WC
)) {
2143 memoryTypeBits
= (1 << i
);
2147 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
2151 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
2155 static enum radeon_ctx_priority
2156 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
2158 /* Default to MEDIUM when a specific global priority isn't requested */
2160 return RADEON_CTX_PRIORITY_MEDIUM
;
2162 switch(pObj
->globalPriority
) {
2163 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2164 return RADEON_CTX_PRIORITY_REALTIME
;
2165 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2166 return RADEON_CTX_PRIORITY_HIGH
;
2167 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2168 return RADEON_CTX_PRIORITY_MEDIUM
;
2169 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2170 return RADEON_CTX_PRIORITY_LOW
;
2172 unreachable("Illegal global priority value");
2173 return RADEON_CTX_PRIORITY_INVALID
;
2178 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
2179 uint32_t queue_family_index
, int idx
,
2180 VkDeviceQueueCreateFlags flags
,
2181 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
2183 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2184 queue
->device
= device
;
2185 queue
->queue_family_index
= queue_family_index
;
2186 queue
->queue_idx
= idx
;
2187 queue
->priority
= radv_get_queue_global_priority(global_priority
);
2188 queue
->flags
= flags
;
2190 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
2192 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2194 list_inithead(&queue
->pending_submissions
);
2195 pthread_mutex_init(&queue
->pending_mutex
, NULL
);
2201 radv_queue_finish(struct radv_queue
*queue
)
2203 pthread_mutex_destroy(&queue
->pending_mutex
);
2206 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
2208 if (queue
->initial_full_flush_preamble_cs
)
2209 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2210 if (queue
->initial_preamble_cs
)
2211 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2212 if (queue
->continue_preamble_cs
)
2213 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2214 if (queue
->descriptor_bo
)
2215 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2216 if (queue
->scratch_bo
)
2217 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2218 if (queue
->esgs_ring_bo
)
2219 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2220 if (queue
->gsvs_ring_bo
)
2221 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2222 if (queue
->tess_rings_bo
)
2223 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
2225 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
2226 if (queue
->gds_oa_bo
)
2227 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
2228 if (queue
->compute_scratch_bo
)
2229 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2233 radv_bo_list_init(struct radv_bo_list
*bo_list
)
2235 pthread_mutex_init(&bo_list
->mutex
, NULL
);
2236 bo_list
->list
.count
= bo_list
->capacity
= 0;
2237 bo_list
->list
.bos
= NULL
;
2241 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
2243 free(bo_list
->list
.bos
);
2244 pthread_mutex_destroy(&bo_list
->mutex
);
2247 VkResult
radv_bo_list_add(struct radv_device
*device
,
2248 struct radeon_winsys_bo
*bo
)
2250 struct radv_bo_list
*bo_list
= &device
->bo_list
;
2255 if (unlikely(!device
->use_global_bo_list
))
2258 pthread_mutex_lock(&bo_list
->mutex
);
2259 if (bo_list
->list
.count
== bo_list
->capacity
) {
2260 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
2261 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
2264 pthread_mutex_unlock(&bo_list
->mutex
);
2265 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2268 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
2269 bo_list
->capacity
= capacity
;
2272 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
2273 pthread_mutex_unlock(&bo_list
->mutex
);
2277 void radv_bo_list_remove(struct radv_device
*device
,
2278 struct radeon_winsys_bo
*bo
)
2280 struct radv_bo_list
*bo_list
= &device
->bo_list
;
2285 if (unlikely(!device
->use_global_bo_list
))
2288 pthread_mutex_lock(&bo_list
->mutex
);
2289 /* Loop the list backwards so we find the most recently added
2291 for(unsigned i
= bo_list
->list
.count
; i
-- > 0;) {
2292 if (bo_list
->list
.bos
[i
] == bo
) {
2293 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
2294 --bo_list
->list
.count
;
2298 pthread_mutex_unlock(&bo_list
->mutex
);
2302 radv_device_init_gs_info(struct radv_device
*device
)
2304 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
2305 device
->physical_device
->rad_info
.family
);
2308 static int radv_get_device_extension_index(const char *name
)
2310 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
2311 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
2318 radv_get_int_debug_option(const char *name
, int default_value
)
2325 result
= default_value
;
2329 result
= strtol(str
, &endptr
, 0);
2330 if (str
== endptr
) {
2331 /* No digits founs. */
2332 result
= default_value
;
2339 static int install_seccomp_filter() {
2341 struct sock_filter filter
[] = {
2342 /* Check arch is 64bit x86 */
2343 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, arch
))),
2344 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, AUDIT_ARCH_X86_64
, 0, 12),
2346 /* Futex is required for mutex locks */
2347 #if defined __NR__newselect
2348 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2349 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR__newselect
, 11, 0),
2350 #elif defined __NR_select
2351 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2352 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_select
, 11, 0),
2354 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2355 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_pselect6
, 11, 0),
2358 /* Allow system exit calls for the forked process */
2359 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2360 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_exit_group
, 9, 0),
2362 /* Allow system read calls */
2363 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2364 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_read
, 7, 0),
2366 /* Allow system write calls */
2367 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2368 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_write
, 5, 0),
2370 /* Allow system brk calls (we need this for malloc) */
2371 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2372 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_brk
, 3, 0),
2374 /* Futex is required for mutex locks */
2375 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2376 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_futex
, 1, 0),
2378 /* Return error if we hit a system call not on the whitelist */
2379 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ERRNO
| (EPERM
& SECCOMP_RET_DATA
)),
2381 /* Allow whitelisted system calls */
2382 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ALLOW
),
2385 struct sock_fprog prog
= {
2386 .len
= (unsigned short)(sizeof(filter
) / sizeof(filter
[0])),
2390 if (prctl(PR_SET_NO_NEW_PRIVS
, 1, 0, 0, 0))
2393 if (prctl(PR_SET_SECCOMP
, SECCOMP_MODE_FILTER
, &prog
))
2399 /* Helper function with timeout support for reading from the pipe between
2400 * processes used for secure compile.
2402 bool radv_sc_read(int fd
, void *buf
, size_t size
, bool timeout
)
2411 /* We can't rely on the value of tv after calling select() so
2412 * we must reset it on each iteration of the loop.
2417 int rval
= select(fd
+ 1, &fds
, NULL
, NULL
, timeout
? &tv
: NULL
);
2423 ssize_t bytes_read
= read(fd
, buf
, size
);
2432 /* select timeout */
2438 static bool radv_close_all_fds(const int *keep_fds
, int keep_fd_count
)
2442 d
= opendir("/proc/self/fd");
2445 int dir_fd
= dirfd(d
);
2447 while ((dir
= readdir(d
)) != NULL
) {
2448 if (dir
->d_name
[0] == '.')
2451 int fd
= atoi(dir
->d_name
);
2456 for (int i
= 0; !keep
&& i
< keep_fd_count
; ++i
)
2457 if (keep_fds
[i
] == fd
)
2469 static bool secure_compile_open_fifo_fds(struct radv_secure_compile_state
*sc
,
2470 int *fd_server
, int *fd_client
,
2471 unsigned process
, bool make_fifo
)
2473 bool result
= false;
2474 char *fifo_server_path
= NULL
;
2475 char *fifo_client_path
= NULL
;
2477 if (asprintf(&fifo_server_path
, "/tmp/radv_server_%s_%u", sc
->uid
, process
) == -1)
2478 goto open_fifo_exit
;
2480 if (asprintf(&fifo_client_path
, "/tmp/radv_client_%s_%u", sc
->uid
, process
) == -1)
2481 goto open_fifo_exit
;
2484 int file1
= mkfifo(fifo_server_path
, 0666);
2486 goto open_fifo_exit
;
2488 int file2
= mkfifo(fifo_client_path
, 0666);
2490 goto open_fifo_exit
;
2493 *fd_server
= open(fifo_server_path
, O_RDWR
);
2495 goto open_fifo_exit
;
2497 *fd_client
= open(fifo_client_path
, O_RDWR
);
2498 if(*fd_client
< 1) {
2500 goto open_fifo_exit
;
2506 free(fifo_server_path
);
2507 free(fifo_client_path
);
2512 static void run_secure_compile_device(struct radv_device
*device
, unsigned process
,
2513 int fd_idle_device_output
)
2515 int fd_secure_input
;
2516 int fd_secure_output
;
2517 bool fifo_result
= secure_compile_open_fifo_fds(device
->sc_state
,
2522 enum radv_secure_compile_type sc_type
;
2524 const int needed_fds
[] = {
2527 fd_idle_device_output
,
2530 if (!fifo_result
|| !radv_close_all_fds(needed_fds
, ARRAY_SIZE(needed_fds
)) ||
2531 install_seccomp_filter() == -1) {
2532 sc_type
= RADV_SC_TYPE_INIT_FAILURE
;
2534 sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2535 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
;
2536 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
;
2539 write(fd_idle_device_output
, &sc_type
, sizeof(sc_type
));
2541 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2542 goto secure_compile_exit
;
2545 radv_sc_read(fd_secure_input
, &sc_type
, sizeof(sc_type
), false);
2547 if (sc_type
== RADV_SC_TYPE_COMPILE_PIPELINE
) {
2548 struct radv_pipeline
*pipeline
;
2549 bool sc_read
= true;
2551 pipeline
= vk_zalloc2(&device
->vk
.alloc
, NULL
, sizeof(*pipeline
), 8,
2552 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2554 pipeline
->device
= device
;
2556 /* Read pipeline layout */
2557 struct radv_pipeline_layout layout
;
2558 sc_read
= radv_sc_read(fd_secure_input
, &layout
, sizeof(struct radv_pipeline_layout
), true);
2559 sc_read
&= radv_sc_read(fd_secure_input
, &layout
.num_sets
, sizeof(uint32_t), true);
2561 goto secure_compile_exit
;
2563 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++) {
2564 uint32_t layout_size
;
2565 sc_read
&= radv_sc_read(fd_secure_input
, &layout_size
, sizeof(uint32_t), true);
2567 goto secure_compile_exit
;
2569 layout
.set
[set
].layout
= malloc(layout_size
);
2570 layout
.set
[set
].layout
->layout_size
= layout_size
;
2571 sc_read
&= radv_sc_read(fd_secure_input
, layout
.set
[set
].layout
,
2572 layout
.set
[set
].layout
->layout_size
, true);
2575 pipeline
->layout
= &layout
;
2577 /* Read pipeline key */
2578 struct radv_pipeline_key key
;
2579 sc_read
&= radv_sc_read(fd_secure_input
, &key
, sizeof(struct radv_pipeline_key
), true);
2581 /* Read pipeline create flags */
2582 VkPipelineCreateFlags flags
;
2583 sc_read
&= radv_sc_read(fd_secure_input
, &flags
, sizeof(VkPipelineCreateFlags
), true);
2585 /* Read stage and shader information */
2586 uint32_t num_stages
;
2587 const VkPipelineShaderStageCreateInfo
*pStages
[MESA_SHADER_STAGES
] = { 0, };
2588 sc_read
&= radv_sc_read(fd_secure_input
, &num_stages
, sizeof(uint32_t), true);
2590 goto secure_compile_exit
;
2592 for (uint32_t i
= 0; i
< num_stages
; i
++) {
2595 gl_shader_stage stage
;
2596 sc_read
&= radv_sc_read(fd_secure_input
, &stage
, sizeof(gl_shader_stage
), true);
2598 VkPipelineShaderStageCreateInfo
*pStage
= calloc(1, sizeof(VkPipelineShaderStageCreateInfo
));
2600 /* Read entry point name */
2602 sc_read
&= radv_sc_read(fd_secure_input
, &name_size
, sizeof(size_t), true);
2604 goto secure_compile_exit
;
2606 char *ep_name
= malloc(name_size
);
2607 sc_read
&= radv_sc_read(fd_secure_input
, ep_name
, name_size
, true);
2608 pStage
->pName
= ep_name
;
2610 /* Read shader module */
2612 sc_read
&= radv_sc_read(fd_secure_input
, &module_size
, sizeof(size_t), true);
2614 goto secure_compile_exit
;
2616 struct radv_shader_module
*module
= malloc(module_size
);
2617 sc_read
&= radv_sc_read(fd_secure_input
, module
, module_size
, true);
2618 pStage
->module
= radv_shader_module_to_handle(module
);
2620 /* Read specialization info */
2622 sc_read
&= radv_sc_read(fd_secure_input
, &has_spec_info
, sizeof(bool), true);
2624 goto secure_compile_exit
;
2626 if (has_spec_info
) {
2627 VkSpecializationInfo
*specInfo
= malloc(sizeof(VkSpecializationInfo
));
2628 pStage
->pSpecializationInfo
= specInfo
;
2630 sc_read
&= radv_sc_read(fd_secure_input
, &specInfo
->dataSize
, sizeof(size_t), true);
2632 goto secure_compile_exit
;
2634 void *si_data
= malloc(specInfo
->dataSize
);
2635 sc_read
&= radv_sc_read(fd_secure_input
, si_data
, specInfo
->dataSize
, true);
2636 specInfo
->pData
= si_data
;
2638 sc_read
&= radv_sc_read(fd_secure_input
, &specInfo
->mapEntryCount
, sizeof(uint32_t), true);
2640 goto secure_compile_exit
;
2642 VkSpecializationMapEntry
*mapEntries
= malloc(sizeof(VkSpecializationMapEntry
) * specInfo
->mapEntryCount
);
2643 for (uint32_t j
= 0; j
< specInfo
->mapEntryCount
; j
++) {
2644 sc_read
&= radv_sc_read(fd_secure_input
, &mapEntries
[j
], sizeof(VkSpecializationMapEntry
), true);
2646 goto secure_compile_exit
;
2649 specInfo
->pMapEntries
= mapEntries
;
2652 pStages
[stage
] = pStage
;
2655 /* Compile the shaders */
2656 VkPipelineCreationFeedbackEXT
*stage_feedbacks
[MESA_SHADER_STAGES
] = { 0 };
2657 radv_create_shaders(pipeline
, device
, NULL
, &key
, pStages
, flags
, NULL
, stage_feedbacks
);
2659 /* free memory allocated above */
2660 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++)
2661 free(layout
.set
[set
].layout
);
2663 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
2667 free((void *) pStages
[i
]->pName
);
2668 free(radv_shader_module_from_handle(pStages
[i
]->module
));
2669 if (pStages
[i
]->pSpecializationInfo
) {
2670 free((void *) pStages
[i
]->pSpecializationInfo
->pData
);
2671 free((void *) pStages
[i
]->pSpecializationInfo
->pMapEntries
);
2672 free((void *) pStages
[i
]->pSpecializationInfo
);
2674 free((void *) pStages
[i
]);
2677 vk_free(&device
->vk
.alloc
, pipeline
);
2679 sc_type
= RADV_SC_TYPE_COMPILE_PIPELINE_FINISHED
;
2680 write(fd_secure_output
, &sc_type
, sizeof(sc_type
));
2682 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2683 goto secure_compile_exit
;
2687 secure_compile_exit
:
2688 close(fd_secure_input
);
2689 close(fd_secure_output
);
2690 close(fd_idle_device_output
);
2694 static enum radv_secure_compile_type
fork_secure_compile_device(struct radv_device
*device
, unsigned process
)
2696 int fd_secure_input
[2];
2697 int fd_secure_output
[2];
2699 /* create pipe descriptors (used to communicate between processes) */
2700 if (pipe(fd_secure_input
) == -1 || pipe(fd_secure_output
) == -1)
2701 return RADV_SC_TYPE_INIT_FAILURE
;
2705 if ((sc_pid
= fork()) == 0) {
2706 device
->sc_state
->secure_compile_thread_counter
= process
;
2707 run_secure_compile_device(device
, process
, fd_secure_output
[1]);
2710 return RADV_SC_TYPE_INIT_FAILURE
;
2712 /* Read the init result returned from the secure process */
2713 enum radv_secure_compile_type sc_type
;
2714 bool sc_read
= radv_sc_read(fd_secure_output
[0], &sc_type
, sizeof(sc_type
), true);
2716 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
) {
2717 close(fd_secure_input
[0]);
2718 close(fd_secure_input
[1]);
2719 close(fd_secure_output
[1]);
2720 close(fd_secure_output
[0]);
2722 waitpid(sc_pid
, &status
, 0);
2724 return RADV_SC_TYPE_INIT_FAILURE
;
2726 assert(sc_type
== RADV_SC_TYPE_INIT_SUCCESS
);
2727 write(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
, &sc_type
, sizeof(sc_type
));
2729 close(fd_secure_input
[0]);
2730 close(fd_secure_input
[1]);
2731 close(fd_secure_output
[1]);
2732 close(fd_secure_output
[0]);
2735 waitpid(sc_pid
, &status
, 0);
2739 return RADV_SC_TYPE_INIT_SUCCESS
;
2742 /* Run a bare bones fork of a device that was forked right after its creation.
2743 * This device will have low overhead when it is forked again before each
2744 * pipeline compilation. This device sits idle and its only job is to fork
2747 static void run_secure_compile_idle_device(struct radv_device
*device
, unsigned process
,
2748 int fd_secure_input
, int fd_secure_output
)
2750 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2751 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
;
2752 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
;
2754 write(fd_secure_output
, &sc_type
, sizeof(sc_type
));
2757 radv_sc_read(fd_secure_input
, &sc_type
, sizeof(sc_type
), false);
2759 if (sc_type
== RADV_SC_TYPE_FORK_DEVICE
) {
2760 sc_type
= fork_secure_compile_device(device
, process
);
2762 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2763 goto secure_compile_exit
;
2765 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2766 goto secure_compile_exit
;
2770 secure_compile_exit
:
2771 close(fd_secure_input
);
2772 close(fd_secure_output
);
2776 static void destroy_secure_compile_device(struct radv_device
*device
, unsigned process
)
2778 int fd_secure_input
= device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
;
2780 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_DESTROY_DEVICE
;
2781 write(fd_secure_input
, &sc_type
, sizeof(sc_type
));
2783 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
);
2784 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
);
2787 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2790 static VkResult
fork_secure_compile_idle_device(struct radv_device
*device
)
2792 device
->sc_state
= vk_zalloc(&device
->vk
.alloc
,
2793 sizeof(struct radv_secure_compile_state
),
2794 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2796 mtx_init(&device
->sc_state
->secure_compile_mutex
, mtx_plain
);
2798 pid_t upid
= getpid();
2799 time_t seconds
= time(NULL
);
2802 if (asprintf(&uid
, "%ld_%ld", (long) upid
, (long) seconds
) == -1)
2803 return VK_ERROR_INITIALIZATION_FAILED
;
2805 device
->sc_state
->uid
= uid
;
2807 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
2808 int fd_secure_input
[MAX_SC_PROCS
][2];
2809 int fd_secure_output
[MAX_SC_PROCS
][2];
2811 /* create pipe descriptors (used to communicate between processes) */
2812 for (unsigned i
= 0; i
< sc_threads
; i
++) {
2813 if (pipe(fd_secure_input
[i
]) == -1 ||
2814 pipe(fd_secure_output
[i
]) == -1) {
2815 return VK_ERROR_INITIALIZATION_FAILED
;
2819 device
->sc_state
->secure_compile_processes
= vk_zalloc(&device
->vk
.alloc
,
2820 sizeof(struct radv_secure_compile_process
) * sc_threads
, 8,
2821 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2823 for (unsigned process
= 0; process
< sc_threads
; process
++) {
2824 if ((device
->sc_state
->secure_compile_processes
[process
].sc_pid
= fork()) == 0) {
2825 device
->sc_state
->secure_compile_thread_counter
= process
;
2826 run_secure_compile_idle_device(device
, process
, fd_secure_input
[process
][0], fd_secure_output
[process
][1]);
2828 if (device
->sc_state
->secure_compile_processes
[process
].sc_pid
== -1)
2829 return VK_ERROR_INITIALIZATION_FAILED
;
2831 /* Read the init result returned from the secure process */
2832 enum radv_secure_compile_type sc_type
;
2833 bool sc_read
= radv_sc_read(fd_secure_output
[process
][0], &sc_type
, sizeof(sc_type
), true);
2836 if (sc_read
&& sc_type
== RADV_SC_TYPE_INIT_SUCCESS
) {
2837 fifo_result
= secure_compile_open_fifo_fds(device
->sc_state
,
2838 &device
->sc_state
->secure_compile_processes
[process
].fd_server
,
2839 &device
->sc_state
->secure_compile_processes
[process
].fd_client
,
2842 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
[process
][1];
2843 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
[process
][0];
2846 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
|| !fifo_result
) {
2847 close(fd_secure_input
[process
][0]);
2848 close(fd_secure_input
[process
][1]);
2849 close(fd_secure_output
[process
][1]);
2850 close(fd_secure_output
[process
][0]);
2852 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2854 /* Destroy any forks that were created sucessfully */
2855 for (unsigned i
= 0; i
< process
; i
++) {
2856 destroy_secure_compile_device(device
, i
);
2859 return VK_ERROR_INITIALIZATION_FAILED
;
2867 radv_device_init_dispatch(struct radv_device
*device
)
2869 const struct radv_instance
*instance
= device
->physical_device
->instance
;
2870 const struct radv_device_dispatch_table
*dispatch_table_layer
= NULL
;
2871 bool unchecked
= instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
;
2872 int radv_thread_trace
= radv_get_int_debug_option("RADV_THREAD_TRACE", -1);
2874 if (radv_thread_trace
>= 0) {
2875 /* Use device entrypoints from the SQTT layer if enabled. */
2876 dispatch_table_layer
= &sqtt_device_dispatch_table
;
2879 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2880 /* Vulkan requires that entrypoints for extensions which have not been
2881 * enabled must not be advertised.
2884 !radv_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
2885 &instance
->enabled_extensions
,
2886 &device
->enabled_extensions
)) {
2887 device
->dispatch
.entrypoints
[i
] = NULL
;
2888 } else if (dispatch_table_layer
&&
2889 dispatch_table_layer
->entrypoints
[i
]) {
2890 device
->dispatch
.entrypoints
[i
] =
2891 dispatch_table_layer
->entrypoints
[i
];
2893 device
->dispatch
.entrypoints
[i
] =
2894 radv_device_dispatch_table
.entrypoints
[i
];
2900 radv_create_pthread_cond(pthread_cond_t
*cond
)
2902 pthread_condattr_t condattr
;
2903 if (pthread_condattr_init(&condattr
)) {
2904 return VK_ERROR_INITIALIZATION_FAILED
;
2907 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
)) {
2908 pthread_condattr_destroy(&condattr
);
2909 return VK_ERROR_INITIALIZATION_FAILED
;
2911 if (pthread_cond_init(cond
, &condattr
)) {
2912 pthread_condattr_destroy(&condattr
);
2913 return VK_ERROR_INITIALIZATION_FAILED
;
2915 pthread_condattr_destroy(&condattr
);
2920 check_physical_device_features(VkPhysicalDevice physicalDevice
,
2921 const VkPhysicalDeviceFeatures
*features
)
2923 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2924 VkPhysicalDeviceFeatures supported_features
;
2925 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2926 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2927 VkBool32
*enabled_feature
= (VkBool32
*)features
;
2928 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2929 for (uint32_t i
= 0; i
< num_features
; i
++) {
2930 if (enabled_feature
[i
] && !supported_feature
[i
])
2931 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
2937 VkResult
radv_CreateDevice(
2938 VkPhysicalDevice physicalDevice
,
2939 const VkDeviceCreateInfo
* pCreateInfo
,
2940 const VkAllocationCallbacks
* pAllocator
,
2943 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2945 struct radv_device
*device
;
2947 bool keep_shader_info
= false;
2948 bool robust_buffer_access
= false;
2949 bool overallocation_disallowed
= false;
2951 /* Check enabled features */
2952 if (pCreateInfo
->pEnabledFeatures
) {
2953 result
= check_physical_device_features(physicalDevice
,
2954 pCreateInfo
->pEnabledFeatures
);
2955 if (result
!= VK_SUCCESS
)
2958 if (pCreateInfo
->pEnabledFeatures
->robustBufferAccess
)
2959 robust_buffer_access
= true;
2962 vk_foreach_struct_const(ext
, pCreateInfo
->pNext
) {
2963 switch (ext
->sType
) {
2964 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2
: {
2965 const VkPhysicalDeviceFeatures2
*features
= (const void *)ext
;
2966 result
= check_physical_device_features(physicalDevice
,
2967 &features
->features
);
2968 if (result
!= VK_SUCCESS
)
2971 if (features
->features
.robustBufferAccess
)
2972 robust_buffer_access
= true;
2975 case VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD
: {
2976 const VkDeviceMemoryOverallocationCreateInfoAMD
*overallocation
= (const void *)ext
;
2977 if (overallocation
->overallocationBehavior
== VK_MEMORY_OVERALLOCATION_BEHAVIOR_DISALLOWED_AMD
)
2978 overallocation_disallowed
= true;
2986 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
2988 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2990 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2992 vk_device_init(&device
->vk
, pCreateInfo
,
2993 &physical_device
->instance
->alloc
, pAllocator
);
2995 device
->instance
= physical_device
->instance
;
2996 device
->physical_device
= physical_device
;
2998 device
->ws
= physical_device
->ws
;
3000 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
3001 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
3002 int index
= radv_get_device_extension_index(ext_name
);
3003 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
3004 vk_free(&device
->vk
.alloc
, device
);
3005 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
3008 device
->enabled_extensions
.extensions
[index
] = true;
3011 radv_device_init_dispatch(device
);
3013 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
3015 /* With update after bind we can't attach bo's to the command buffer
3016 * from the descriptor set anymore, so we have to use a global BO list.
3018 device
->use_global_bo_list
=
3019 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
3020 device
->enabled_extensions
.EXT_descriptor_indexing
||
3021 device
->enabled_extensions
.EXT_buffer_device_address
||
3022 device
->enabled_extensions
.KHR_buffer_device_address
;
3024 device
->robust_buffer_access
= robust_buffer_access
;
3026 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
3027 list_inithead(&device
->shader_slabs
);
3029 device
->overallocation_disallowed
= overallocation_disallowed
;
3030 mtx_init(&device
->overallocation_mutex
, mtx_plain
);
3032 radv_bo_list_init(&device
->bo_list
);
3034 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
3035 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
3036 uint32_t qfi
= queue_create
->queueFamilyIndex
;
3037 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
3038 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
3040 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
3042 device
->queues
[qfi
] = vk_alloc(&device
->vk
.alloc
,
3043 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
3044 if (!device
->queues
[qfi
]) {
3045 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
3049 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
3051 device
->queue_count
[qfi
] = queue_create
->queueCount
;
3053 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
3054 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
3055 qfi
, q
, queue_create
->flags
,
3057 if (result
!= VK_SUCCESS
)
3062 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
3063 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
3065 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
3066 device
->dfsm_allowed
= device
->pbb_allowed
&&
3067 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
3069 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
3071 /* The maximum number of scratch waves. Scratch space isn't divided
3072 * evenly between CUs. The number is only a function of the number of CUs.
3073 * We can decrease the constant to decrease the scratch buffer size.
3075 * sctx->scratch_waves must be >= the maximum possible size of
3076 * 1 threadgroup, so that the hw doesn't hang from being unable
3079 * The recommended value is 4 per CU at most. Higher numbers don't
3080 * bring much benefit, but they still occupy chip resources (think
3081 * async compute). I've seen ~2% performance difference between 4 and 32.
3083 uint32_t max_threads_per_block
= 2048;
3084 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
3085 max_threads_per_block
/ 64);
3087 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
3089 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3090 /* If the KMD allows it (there is a KMD hw register for it),
3091 * allow launching waves out-of-order.
3093 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
3096 radv_device_init_gs_info(device
);
3098 device
->tess_offchip_block_dw_size
=
3099 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
3101 if (getenv("RADV_TRACE_FILE")) {
3102 const char *filename
= getenv("RADV_TRACE_FILE");
3104 keep_shader_info
= true;
3106 if (!radv_init_trace(device
))
3109 fprintf(stderr
, "*****************************************************************************\n");
3110 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
3111 fprintf(stderr
, "*****************************************************************************\n");
3113 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
3114 radv_dump_enabled_options(device
, stderr
);
3117 int radv_thread_trace
= radv_get_int_debug_option("RADV_THREAD_TRACE", -1);
3118 if (radv_thread_trace
>= 0) {
3119 fprintf(stderr
, "*************************************************\n");
3120 fprintf(stderr
, "* WARNING: Thread trace support is experimental *\n");
3121 fprintf(stderr
, "*************************************************\n");
3123 if (device
->physical_device
->rad_info
.chip_class
< GFX8
) {
3124 fprintf(stderr
, "GPU hardware not supported: refer to "
3125 "the RGP documentation for the list of "
3126 "supported GPUs!\n");
3130 /* Default buffer size set to 1MB per SE. */
3131 device
->thread_trace_buffer_size
=
3132 radv_get_int_debug_option("RADV_THREAD_TRACE_BUFFER_SIZE", 1024 * 1024);
3133 device
->thread_trace_start_frame
= radv_thread_trace
;
3135 if (!radv_thread_trace_init(device
))
3139 /* Temporarily disable secure compile while we create meta shaders, etc */
3140 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
3142 device
->instance
->num_sc_threads
= 0;
3144 device
->keep_shader_info
= keep_shader_info
;
3145 result
= radv_device_init_meta(device
);
3146 if (result
!= VK_SUCCESS
)
3149 radv_device_init_msaa(device
);
3151 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
3152 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
3154 case RADV_QUEUE_GENERAL
:
3155 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
3156 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
3157 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
3159 case RADV_QUEUE_COMPUTE
:
3160 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
3161 radeon_emit(device
->empty_cs
[family
], 0);
3164 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
3167 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
3168 cik_create_gfx_config(device
);
3170 VkPipelineCacheCreateInfo ci
;
3171 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
3174 ci
.pInitialData
= NULL
;
3175 ci
.initialDataSize
= 0;
3177 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
3179 if (result
!= VK_SUCCESS
)
3182 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
3184 result
= radv_create_pthread_cond(&device
->timeline_cond
);
3185 if (result
!= VK_SUCCESS
)
3186 goto fail_mem_cache
;
3188 device
->force_aniso
=
3189 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
3190 if (device
->force_aniso
>= 0) {
3191 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
3192 1 << util_logbase2(device
->force_aniso
));
3195 /* Fork device for secure compile as required */
3196 device
->instance
->num_sc_threads
= sc_threads
;
3197 if (radv_device_use_secure_compile(device
->instance
)) {
3199 result
= fork_secure_compile_idle_device(device
);
3200 if (result
!= VK_SUCCESS
)
3204 *pDevice
= radv_device_to_handle(device
);
3208 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
3210 radv_device_finish_meta(device
);
3212 radv_bo_list_finish(&device
->bo_list
);
3214 radv_thread_trace_finish(device
);
3216 if (device
->trace_bo
)
3217 device
->ws
->buffer_destroy(device
->trace_bo
);
3219 if (device
->gfx_init
)
3220 device
->ws
->buffer_destroy(device
->gfx_init
);
3222 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3223 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
3224 radv_queue_finish(&device
->queues
[i
][q
]);
3225 if (device
->queue_count
[i
])
3226 vk_free(&device
->vk
.alloc
, device
->queues
[i
]);
3229 vk_free(&device
->vk
.alloc
, device
);
3233 void radv_DestroyDevice(
3235 const VkAllocationCallbacks
* pAllocator
)
3237 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3242 if (device
->trace_bo
)
3243 device
->ws
->buffer_destroy(device
->trace_bo
);
3245 if (device
->gfx_init
)
3246 device
->ws
->buffer_destroy(device
->gfx_init
);
3248 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3249 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
3250 radv_queue_finish(&device
->queues
[i
][q
]);
3251 if (device
->queue_count
[i
])
3252 vk_free(&device
->vk
.alloc
, device
->queues
[i
]);
3253 if (device
->empty_cs
[i
])
3254 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
3256 radv_device_finish_meta(device
);
3258 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
3259 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
3261 radv_destroy_shader_slabs(device
);
3263 pthread_cond_destroy(&device
->timeline_cond
);
3264 radv_bo_list_finish(&device
->bo_list
);
3266 radv_thread_trace_finish(device
);
3268 if (radv_device_use_secure_compile(device
->instance
)) {
3269 for (unsigned i
= 0; i
< device
->instance
->num_sc_threads
; i
++ ) {
3270 destroy_secure_compile_device(device
, i
);
3274 if (device
->sc_state
) {
3275 free(device
->sc_state
->uid
);
3276 vk_free(&device
->vk
.alloc
, device
->sc_state
->secure_compile_processes
);
3278 vk_free(&device
->vk
.alloc
, device
->sc_state
);
3279 vk_free(&device
->vk
.alloc
, device
);
3282 VkResult
radv_EnumerateInstanceLayerProperties(
3283 uint32_t* pPropertyCount
,
3284 VkLayerProperties
* pProperties
)
3286 if (pProperties
== NULL
) {
3287 *pPropertyCount
= 0;
3291 /* None supported at this time */
3292 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
3295 VkResult
radv_EnumerateDeviceLayerProperties(
3296 VkPhysicalDevice physicalDevice
,
3297 uint32_t* pPropertyCount
,
3298 VkLayerProperties
* pProperties
)
3300 if (pProperties
== NULL
) {
3301 *pPropertyCount
= 0;
3305 /* None supported at this time */
3306 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
3309 void radv_GetDeviceQueue2(
3311 const VkDeviceQueueInfo2
* pQueueInfo
,
3314 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3315 struct radv_queue
*queue
;
3317 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
3318 if (pQueueInfo
->flags
!= queue
->flags
) {
3319 /* From the Vulkan 1.1.70 spec:
3321 * "The queue returned by vkGetDeviceQueue2 must have the same
3322 * flags value from this structure as that used at device
3323 * creation time in a VkDeviceQueueCreateInfo instance. If no
3324 * matching flags were specified at device creation time then
3325 * pQueue will return VK_NULL_HANDLE."
3327 *pQueue
= VK_NULL_HANDLE
;
3331 *pQueue
= radv_queue_to_handle(queue
);
3334 void radv_GetDeviceQueue(
3336 uint32_t queueFamilyIndex
,
3337 uint32_t queueIndex
,
3340 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
3341 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
3342 .queueFamilyIndex
= queueFamilyIndex
,
3343 .queueIndex
= queueIndex
3346 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
3350 fill_geom_tess_rings(struct radv_queue
*queue
,
3352 bool add_sample_positions
,
3353 uint32_t esgs_ring_size
,
3354 struct radeon_winsys_bo
*esgs_ring_bo
,
3355 uint32_t gsvs_ring_size
,
3356 struct radeon_winsys_bo
*gsvs_ring_bo
,
3357 uint32_t tess_factor_ring_size
,
3358 uint32_t tess_offchip_ring_offset
,
3359 uint32_t tess_offchip_ring_size
,
3360 struct radeon_winsys_bo
*tess_rings_bo
)
3362 uint32_t *desc
= &map
[4];
3365 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
3367 /* stride 0, num records - size, add tid, swizzle, elsize4,
3370 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
3371 S_008F04_SWIZZLE_ENABLE(true);
3372 desc
[2] = esgs_ring_size
;
3373 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3374 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3375 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3376 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
3377 S_008F0C_INDEX_STRIDE(3) |
3378 S_008F0C_ADD_TID_ENABLE(1);
3380 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3381 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3382 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3383 S_008F0C_RESOURCE_LEVEL(1);
3385 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3386 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
3387 S_008F0C_ELEMENT_SIZE(1);
3390 /* GS entry for ES->GS ring */
3391 /* stride 0, num records - size, elsize0,
3394 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
3395 desc
[6] = esgs_ring_size
;
3396 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3397 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3398 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3399 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3401 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3402 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3403 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3404 S_008F0C_RESOURCE_LEVEL(1);
3406 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3407 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3414 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
3416 /* VS entry for GS->VS ring */
3417 /* stride 0, num records - size, elsize0,
3420 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
3421 desc
[2] = gsvs_ring_size
;
3422 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3423 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3424 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3425 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3427 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3428 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3429 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3430 S_008F0C_RESOURCE_LEVEL(1);
3432 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3433 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3436 /* stride gsvs_itemsize, num records 64
3437 elsize 4, index stride 16 */
3438 /* shader will patch stride and desc[2] */
3440 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
3441 S_008F04_SWIZZLE_ENABLE(1);
3443 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3444 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3445 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3446 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
3447 S_008F0C_INDEX_STRIDE(1) |
3448 S_008F0C_ADD_TID_ENABLE(true);
3450 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3451 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3452 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3453 S_008F0C_RESOURCE_LEVEL(1);
3455 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3456 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
3457 S_008F0C_ELEMENT_SIZE(1);
3464 if (tess_rings_bo
) {
3465 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
3466 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
3469 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
3470 desc
[2] = tess_factor_ring_size
;
3471 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3472 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3473 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3474 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3476 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3477 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3478 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW
) |
3479 S_008F0C_RESOURCE_LEVEL(1);
3481 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3482 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3485 desc
[4] = tess_offchip_va
;
3486 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
3487 desc
[6] = tess_offchip_ring_size
;
3488 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3489 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3490 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3491 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3493 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3494 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3495 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW
) |
3496 S_008F0C_RESOURCE_LEVEL(1);
3498 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3499 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3505 if (add_sample_positions
) {
3506 /* add sample positions after all rings */
3507 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
3509 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
3511 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
3513 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
3518 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
3520 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
3521 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
3522 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
3523 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
3524 unsigned max_offchip_buffers
;
3525 unsigned offchip_granularity
;
3526 unsigned hs_offchip_param
;
3530 * This must be one less than the maximum number due to a hw limitation.
3531 * Various hardware bugs need thGFX7
3534 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
3535 * Gfx7 should limit max_offchip_buffers to 508
3536 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
3538 * Follow AMDVLK here.
3540 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3541 max_offchip_buffers_per_se
= 256;
3542 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
3543 device
->physical_device
->rad_info
.chip_class
== GFX7
||
3544 device
->physical_device
->rad_info
.chip_class
== GFX6
)
3545 --max_offchip_buffers_per_se
;
3547 max_offchip_buffers
= max_offchip_buffers_per_se
*
3548 device
->physical_device
->rad_info
.max_se
;
3550 /* Hawaii has a bug with offchip buffers > 256 that can be worked
3551 * around by setting 4K granularity.
3553 if (device
->tess_offchip_block_dw_size
== 4096) {
3554 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
3555 offchip_granularity
= V_03093C_X_4K_DWORDS
;
3557 assert(device
->tess_offchip_block_dw_size
== 8192);
3558 offchip_granularity
= V_03093C_X_8K_DWORDS
;
3561 switch (device
->physical_device
->rad_info
.chip_class
) {
3563 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
3568 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
3576 *max_offchip_buffers_p
= max_offchip_buffers
;
3577 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3578 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
3579 --max_offchip_buffers
;
3581 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
3582 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
3585 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
3587 return hs_offchip_param
;
3591 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3592 struct radeon_winsys_bo
*esgs_ring_bo
,
3593 uint32_t esgs_ring_size
,
3594 struct radeon_winsys_bo
*gsvs_ring_bo
,
3595 uint32_t gsvs_ring_size
)
3597 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
3601 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
3604 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
3606 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3607 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
3608 radeon_emit(cs
, esgs_ring_size
>> 8);
3609 radeon_emit(cs
, gsvs_ring_size
>> 8);
3611 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
3612 radeon_emit(cs
, esgs_ring_size
>> 8);
3613 radeon_emit(cs
, gsvs_ring_size
>> 8);
3618 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3619 unsigned hs_offchip_param
, unsigned tf_ring_size
,
3620 struct radeon_winsys_bo
*tess_rings_bo
)
3627 tf_va
= radv_buffer_get_va(tess_rings_bo
);
3629 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
3631 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3632 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
3633 S_030938_SIZE(tf_ring_size
/ 4));
3634 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
3637 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3638 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
3639 S_030984_BASE_HI(tf_va
>> 40));
3640 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3641 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
3642 S_030944_BASE_HI(tf_va
>> 40));
3644 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
3647 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
3648 S_008988_SIZE(tf_ring_size
/ 4));
3649 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
3651 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
3657 radv_emit_graphics_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3658 uint32_t size_per_wave
, uint32_t waves
,
3659 struct radeon_winsys_bo
*scratch_bo
)
3661 if (queue
->queue_family_index
!= RADV_QUEUE_GENERAL
)
3667 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
3669 radeon_set_context_reg(cs
, R_0286E8_SPI_TMPRING_SIZE
,
3670 S_0286E8_WAVES(waves
) |
3671 S_0286E8_WAVESIZE(round_up_u32(size_per_wave
, 1024)));
3675 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3676 uint32_t size_per_wave
, uint32_t waves
,
3677 struct radeon_winsys_bo
*compute_scratch_bo
)
3679 uint64_t scratch_va
;
3681 if (!compute_scratch_bo
)
3684 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
3686 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
3688 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
3689 radeon_emit(cs
, scratch_va
);
3690 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3691 S_008F04_SWIZZLE_ENABLE(1));
3693 radeon_set_sh_reg(cs
, R_00B860_COMPUTE_TMPRING_SIZE
,
3694 S_00B860_WAVES(waves
) |
3695 S_00B860_WAVESIZE(round_up_u32(size_per_wave
, 1024)));
3699 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
3700 struct radeon_cmdbuf
*cs
,
3701 struct radeon_winsys_bo
*descriptor_bo
)
3708 va
= radv_buffer_get_va(descriptor_bo
);
3710 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
3712 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3713 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3714 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3715 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3716 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3718 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3719 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3722 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3723 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3724 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3725 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3726 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3728 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3729 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3733 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3734 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3735 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
3736 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
3737 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
3738 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
3740 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3741 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3748 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3750 struct radv_device
*device
= queue
->device
;
3752 if (device
->gfx_init
) {
3753 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
3755 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
3756 radeon_emit(cs
, va
);
3757 radeon_emit(cs
, va
>> 32);
3758 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
3760 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
3762 si_emit_graphics(device
, cs
);
3767 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3769 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
3770 si_emit_compute(physical_device
, cs
);
3774 radv_get_preamble_cs(struct radv_queue
*queue
,
3775 uint32_t scratch_size_per_wave
,
3776 uint32_t scratch_waves
,
3777 uint32_t compute_scratch_size_per_wave
,
3778 uint32_t compute_scratch_waves
,
3779 uint32_t esgs_ring_size
,
3780 uint32_t gsvs_ring_size
,
3781 bool needs_tess_rings
,
3784 bool needs_sample_positions
,
3785 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
3786 struct radeon_cmdbuf
**initial_preamble_cs
,
3787 struct radeon_cmdbuf
**continue_preamble_cs
)
3789 struct radeon_winsys_bo
*scratch_bo
= NULL
;
3790 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
3791 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
3792 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
3793 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
3794 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
3795 struct radeon_winsys_bo
*gds_bo
= NULL
;
3796 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
3797 struct radeon_cmdbuf
*dest_cs
[3] = {0};
3798 bool add_tess_rings
= false, add_gds
= false, add_gds_oa
= false, add_sample_positions
= false;
3799 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
3800 unsigned max_offchip_buffers
;
3801 unsigned hs_offchip_param
= 0;
3802 unsigned tess_offchip_ring_offset
;
3803 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3804 if (!queue
->has_tess_rings
) {
3805 if (needs_tess_rings
)
3806 add_tess_rings
= true;
3808 if (!queue
->has_gds
) {
3812 if (!queue
->has_gds_oa
) {
3816 if (!queue
->has_sample_positions
) {
3817 if (needs_sample_positions
)
3818 add_sample_positions
= true;
3820 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
3821 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
3822 &max_offchip_buffers
);
3823 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
3824 tess_offchip_ring_size
= max_offchip_buffers
*
3825 queue
->device
->tess_offchip_block_dw_size
* 4;
3827 scratch_size_per_wave
= MAX2(scratch_size_per_wave
, queue
->scratch_size_per_wave
);
3828 if (scratch_size_per_wave
)
3829 scratch_waves
= MIN2(scratch_waves
, UINT32_MAX
/ scratch_size_per_wave
);
3833 compute_scratch_size_per_wave
= MAX2(compute_scratch_size_per_wave
, queue
->compute_scratch_size_per_wave
);
3834 if (compute_scratch_size_per_wave
)
3835 compute_scratch_waves
= MIN2(compute_scratch_waves
, UINT32_MAX
/ compute_scratch_size_per_wave
);
3837 compute_scratch_waves
= 0;
3839 if (scratch_size_per_wave
<= queue
->scratch_size_per_wave
&&
3840 scratch_waves
<= queue
->scratch_waves
&&
3841 compute_scratch_size_per_wave
<= queue
->compute_scratch_size_per_wave
&&
3842 compute_scratch_waves
<= queue
->compute_scratch_waves
&&
3843 esgs_ring_size
<= queue
->esgs_ring_size
&&
3844 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
3845 !add_tess_rings
&& !add_gds
&& !add_gds_oa
&& !add_sample_positions
&&
3846 queue
->initial_preamble_cs
) {
3847 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
3848 *initial_preamble_cs
= queue
->initial_preamble_cs
;
3849 *continue_preamble_cs
= queue
->continue_preamble_cs
;
3850 if (!scratch_size_per_wave
&& !compute_scratch_size_per_wave
&&
3851 !esgs_ring_size
&& !gsvs_ring_size
&& !needs_tess_rings
&&
3852 !needs_gds
&& !needs_gds_oa
&& !needs_sample_positions
)
3853 *continue_preamble_cs
= NULL
;
3857 uint32_t scratch_size
= scratch_size_per_wave
* scratch_waves
;
3858 uint32_t queue_scratch_size
= queue
->scratch_size_per_wave
* queue
->scratch_waves
;
3859 if (scratch_size
> queue_scratch_size
) {
3860 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3865 RADV_BO_PRIORITY_SCRATCH
);
3869 scratch_bo
= queue
->scratch_bo
;
3871 uint32_t compute_scratch_size
= compute_scratch_size_per_wave
* compute_scratch_waves
;
3872 uint32_t compute_queue_scratch_size
= queue
->compute_scratch_size_per_wave
* queue
->compute_scratch_waves
;
3873 if (compute_scratch_size
> compute_queue_scratch_size
) {
3874 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3875 compute_scratch_size
,
3879 RADV_BO_PRIORITY_SCRATCH
);
3880 if (!compute_scratch_bo
)
3884 compute_scratch_bo
= queue
->compute_scratch_bo
;
3886 if (esgs_ring_size
> queue
->esgs_ring_size
) {
3887 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3892 RADV_BO_PRIORITY_SCRATCH
);
3896 esgs_ring_bo
= queue
->esgs_ring_bo
;
3897 esgs_ring_size
= queue
->esgs_ring_size
;
3900 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
3901 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3906 RADV_BO_PRIORITY_SCRATCH
);
3910 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
3911 gsvs_ring_size
= queue
->gsvs_ring_size
;
3914 if (add_tess_rings
) {
3915 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3916 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
3920 RADV_BO_PRIORITY_SCRATCH
);
3924 tess_rings_bo
= queue
->tess_rings_bo
;
3928 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
3930 /* 4 streamout GDS counters.
3931 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
3933 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3937 RADV_BO_PRIORITY_SCRATCH
);
3941 gds_bo
= queue
->gds_bo
;
3945 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
3947 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3951 RADV_BO_PRIORITY_SCRATCH
);
3955 gds_oa_bo
= queue
->gds_oa_bo
;
3958 if (scratch_bo
!= queue
->scratch_bo
||
3959 esgs_ring_bo
!= queue
->esgs_ring_bo
||
3960 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
3961 tess_rings_bo
!= queue
->tess_rings_bo
||
3962 add_sample_positions
) {
3964 if (gsvs_ring_bo
|| esgs_ring_bo
||
3965 tess_rings_bo
|| add_sample_positions
) {
3966 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
3967 if (add_sample_positions
)
3968 size
+= 128; /* 64+32+16+8 = 120 bytes */
3970 else if (scratch_bo
)
3971 size
= 8; /* 2 dword */
3973 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3977 RADEON_FLAG_CPU_ACCESS
|
3978 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
3979 RADEON_FLAG_READ_ONLY
,
3980 RADV_BO_PRIORITY_DESCRIPTOR
);
3984 descriptor_bo
= queue
->descriptor_bo
;
3986 if (descriptor_bo
!= queue
->descriptor_bo
) {
3987 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
3990 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
3991 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3992 S_008F04_SWIZZLE_ENABLE(1);
3993 map
[0] = scratch_va
;
3997 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
3998 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
3999 esgs_ring_size
, esgs_ring_bo
,
4000 gsvs_ring_size
, gsvs_ring_bo
,
4001 tess_factor_ring_size
,
4002 tess_offchip_ring_offset
,
4003 tess_offchip_ring_size
,
4006 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
4009 for(int i
= 0; i
< 3; ++i
) {
4010 struct radeon_cmdbuf
*cs
= NULL
;
4011 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
4012 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
4019 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
4021 /* Emit initial configuration. */
4022 switch (queue
->queue_family_index
) {
4023 case RADV_QUEUE_GENERAL
:
4024 radv_init_graphics_state(cs
, queue
);
4026 case RADV_QUEUE_COMPUTE
:
4027 radv_init_compute_state(cs
, queue
);
4029 case RADV_QUEUE_TRANSFER
:
4033 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
4034 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
4035 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
4037 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
4038 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
4041 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
4042 gsvs_ring_bo
, gsvs_ring_size
);
4043 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
4044 tess_factor_ring_size
, tess_rings_bo
);
4045 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
4046 radv_emit_compute_scratch(queue
, cs
, compute_scratch_size_per_wave
,
4047 compute_scratch_waves
, compute_scratch_bo
);
4048 radv_emit_graphics_scratch(queue
, cs
, scratch_size_per_wave
,
4049 scratch_waves
, scratch_bo
);
4052 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
4054 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
4056 if (queue
->device
->trace_bo
)
4057 radv_cs_add_buffer(queue
->device
->ws
, cs
, queue
->device
->trace_bo
);
4060 si_cs_emit_cache_flush(cs
,
4061 queue
->device
->physical_device
->rad_info
.chip_class
,
4063 queue
->queue_family_index
== RING_COMPUTE
&&
4064 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
4065 (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
)) |
4066 RADV_CMD_FLAG_INV_ICACHE
|
4067 RADV_CMD_FLAG_INV_SCACHE
|
4068 RADV_CMD_FLAG_INV_VCACHE
|
4069 RADV_CMD_FLAG_INV_L2
|
4070 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
4071 } else if (i
== 1) {
4072 si_cs_emit_cache_flush(cs
,
4073 queue
->device
->physical_device
->rad_info
.chip_class
,
4075 queue
->queue_family_index
== RING_COMPUTE
&&
4076 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
4077 RADV_CMD_FLAG_INV_ICACHE
|
4078 RADV_CMD_FLAG_INV_SCACHE
|
4079 RADV_CMD_FLAG_INV_VCACHE
|
4080 RADV_CMD_FLAG_INV_L2
|
4081 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
4084 if (!queue
->device
->ws
->cs_finalize(cs
))
4088 if (queue
->initial_full_flush_preamble_cs
)
4089 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
4091 if (queue
->initial_preamble_cs
)
4092 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
4094 if (queue
->continue_preamble_cs
)
4095 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
4097 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
4098 queue
->initial_preamble_cs
= dest_cs
[1];
4099 queue
->continue_preamble_cs
= dest_cs
[2];
4101 if (scratch_bo
!= queue
->scratch_bo
) {
4102 if (queue
->scratch_bo
)
4103 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
4104 queue
->scratch_bo
= scratch_bo
;
4106 queue
->scratch_size_per_wave
= scratch_size_per_wave
;
4107 queue
->scratch_waves
= scratch_waves
;
4109 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
4110 if (queue
->compute_scratch_bo
)
4111 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
4112 queue
->compute_scratch_bo
= compute_scratch_bo
;
4114 queue
->compute_scratch_size_per_wave
= compute_scratch_size_per_wave
;
4115 queue
->compute_scratch_waves
= compute_scratch_waves
;
4117 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
4118 if (queue
->esgs_ring_bo
)
4119 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
4120 queue
->esgs_ring_bo
= esgs_ring_bo
;
4121 queue
->esgs_ring_size
= esgs_ring_size
;
4124 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
4125 if (queue
->gsvs_ring_bo
)
4126 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
4127 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
4128 queue
->gsvs_ring_size
= gsvs_ring_size
;
4131 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
4132 queue
->tess_rings_bo
= tess_rings_bo
;
4133 queue
->has_tess_rings
= true;
4136 if (gds_bo
!= queue
->gds_bo
) {
4137 queue
->gds_bo
= gds_bo
;
4138 queue
->has_gds
= true;
4141 if (gds_oa_bo
!= queue
->gds_oa_bo
) {
4142 queue
->gds_oa_bo
= gds_oa_bo
;
4143 queue
->has_gds_oa
= true;
4146 if (descriptor_bo
!= queue
->descriptor_bo
) {
4147 if (queue
->descriptor_bo
)
4148 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
4150 queue
->descriptor_bo
= descriptor_bo
;
4153 if (add_sample_positions
)
4154 queue
->has_sample_positions
= true;
4156 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
4157 *initial_preamble_cs
= queue
->initial_preamble_cs
;
4158 *continue_preamble_cs
= queue
->continue_preamble_cs
;
4159 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
4160 *continue_preamble_cs
= NULL
;
4163 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
4165 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
4166 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
4167 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
4168 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
4169 queue
->device
->ws
->buffer_destroy(scratch_bo
);
4170 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
4171 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
4172 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
4173 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
4174 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
4175 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
4176 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
4177 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
4178 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
4179 queue
->device
->ws
->buffer_destroy(gds_bo
);
4180 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
4181 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
4183 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4186 static VkResult
radv_alloc_sem_counts(struct radv_device
*device
,
4187 struct radv_winsys_sem_counts
*counts
,
4189 struct radv_semaphore_part
**sems
,
4190 const uint64_t *timeline_values
,
4194 int syncobj_idx
= 0, sem_idx
= 0;
4196 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
4199 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4200 switch(sems
[i
]->kind
) {
4201 case RADV_SEMAPHORE_SYNCOBJ
:
4202 counts
->syncobj_count
++;
4204 case RADV_SEMAPHORE_WINSYS
:
4205 counts
->sem_count
++;
4207 case RADV_SEMAPHORE_NONE
:
4209 case RADV_SEMAPHORE_TIMELINE
:
4210 counts
->syncobj_count
++;
4215 if (_fence
!= VK_NULL_HANDLE
) {
4216 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4217 if (fence
->temp_syncobj
|| fence
->syncobj
)
4218 counts
->syncobj_count
++;
4221 if (counts
->syncobj_count
) {
4222 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
4223 if (!counts
->syncobj
)
4224 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4227 if (counts
->sem_count
) {
4228 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
4230 free(counts
->syncobj
);
4231 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4235 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4236 switch(sems
[i
]->kind
) {
4237 case RADV_SEMAPHORE_NONE
:
4238 unreachable("Empty semaphore");
4240 case RADV_SEMAPHORE_SYNCOBJ
:
4241 counts
->syncobj
[syncobj_idx
++] = sems
[i
]->syncobj
;
4243 case RADV_SEMAPHORE_WINSYS
:
4244 counts
->sem
[sem_idx
++] = sems
[i
]->ws_sem
;
4246 case RADV_SEMAPHORE_TIMELINE
: {
4247 pthread_mutex_lock(&sems
[i
]->timeline
.mutex
);
4248 struct radv_timeline_point
*point
= NULL
;
4250 point
= radv_timeline_add_point_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
4252 point
= radv_timeline_find_point_at_least_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
4255 pthread_mutex_unlock(&sems
[i
]->timeline
.mutex
);
4258 counts
->syncobj
[syncobj_idx
++] = point
->syncobj
;
4260 /* Explicitly remove the semaphore so we might not find
4261 * a point later post-submit. */
4269 if (_fence
!= VK_NULL_HANDLE
) {
4270 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4271 if (fence
->temp_syncobj
)
4272 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
4273 else if (fence
->syncobj
)
4274 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
4277 assert(syncobj_idx
<= counts
->syncobj_count
);
4278 counts
->syncobj_count
= syncobj_idx
;
4284 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
4286 free(sem_info
->wait
.syncobj
);
4287 free(sem_info
->wait
.sem
);
4288 free(sem_info
->signal
.syncobj
);
4289 free(sem_info
->signal
.sem
);
4293 static void radv_free_temp_syncobjs(struct radv_device
*device
,
4295 struct radv_semaphore_part
*sems
)
4297 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4298 radv_destroy_semaphore_part(device
, sems
+ i
);
4303 radv_alloc_sem_info(struct radv_device
*device
,
4304 struct radv_winsys_sem_info
*sem_info
,
4306 struct radv_semaphore_part
**wait_sems
,
4307 const uint64_t *wait_values
,
4308 int num_signal_sems
,
4309 struct radv_semaphore_part
**signal_sems
,
4310 const uint64_t *signal_values
,
4314 memset(sem_info
, 0, sizeof(*sem_info
));
4316 ret
= radv_alloc_sem_counts(device
, &sem_info
->wait
, num_wait_sems
, wait_sems
, wait_values
, VK_NULL_HANDLE
, false);
4319 ret
= radv_alloc_sem_counts(device
, &sem_info
->signal
, num_signal_sems
, signal_sems
, signal_values
, fence
, true);
4321 radv_free_sem_info(sem_info
);
4323 /* caller can override these */
4324 sem_info
->cs_emit_wait
= true;
4325 sem_info
->cs_emit_signal
= true;
4330 radv_finalize_timelines(struct radv_device
*device
,
4331 uint32_t num_wait_sems
,
4332 struct radv_semaphore_part
**wait_sems
,
4333 const uint64_t *wait_values
,
4334 uint32_t num_signal_sems
,
4335 struct radv_semaphore_part
**signal_sems
,
4336 const uint64_t *signal_values
,
4337 struct list_head
*processing_list
)
4339 for (uint32_t i
= 0; i
< num_wait_sems
; ++i
) {
4340 if (wait_sems
[i
] && wait_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4341 pthread_mutex_lock(&wait_sems
[i
]->timeline
.mutex
);
4342 struct radv_timeline_point
*point
=
4343 radv_timeline_find_point_at_least_locked(device
, &wait_sems
[i
]->timeline
, wait_values
[i
]);
4344 point
->wait_count
-= 2;
4345 pthread_mutex_unlock(&wait_sems
[i
]->timeline
.mutex
);
4348 for (uint32_t i
= 0; i
< num_signal_sems
; ++i
) {
4349 if (signal_sems
[i
] && signal_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4350 pthread_mutex_lock(&signal_sems
[i
]->timeline
.mutex
);
4351 struct radv_timeline_point
*point
=
4352 radv_timeline_find_point_at_least_locked(device
, &signal_sems
[i
]->timeline
, signal_values
[i
]);
4353 signal_sems
[i
]->timeline
.highest_submitted
=
4354 MAX2(signal_sems
[i
]->timeline
.highest_submitted
, point
->value
);
4355 point
->wait_count
-= 2;
4356 radv_timeline_trigger_waiters_locked(&signal_sems
[i
]->timeline
, processing_list
);
4357 pthread_mutex_unlock(&signal_sems
[i
]->timeline
.mutex
);
4363 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
4364 const VkSparseBufferMemoryBindInfo
*bind
)
4366 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
4368 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
4369 struct radv_device_memory
*mem
= NULL
;
4371 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
4372 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
4374 device
->ws
->buffer_virtual_bind(buffer
->bo
,
4375 bind
->pBinds
[i
].resourceOffset
,
4376 bind
->pBinds
[i
].size
,
4377 mem
? mem
->bo
: NULL
,
4378 bind
->pBinds
[i
].memoryOffset
);
4383 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
4384 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
4386 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
4388 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
4389 struct radv_device_memory
*mem
= NULL
;
4391 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
4392 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
4394 device
->ws
->buffer_virtual_bind(image
->bo
,
4395 bind
->pBinds
[i
].resourceOffset
,
4396 bind
->pBinds
[i
].size
,
4397 mem
? mem
->bo
: NULL
,
4398 bind
->pBinds
[i
].memoryOffset
);
4403 radv_get_preambles(struct radv_queue
*queue
,
4404 const VkCommandBuffer
*cmd_buffers
,
4405 uint32_t cmd_buffer_count
,
4406 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
4407 struct radeon_cmdbuf
**initial_preamble_cs
,
4408 struct radeon_cmdbuf
**continue_preamble_cs
)
4410 uint32_t scratch_size_per_wave
= 0, waves_wanted
= 0;
4411 uint32_t compute_scratch_size_per_wave
= 0, compute_waves_wanted
= 0;
4412 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
4413 bool tess_rings_needed
= false;
4414 bool gds_needed
= false;
4415 bool gds_oa_needed
= false;
4416 bool sample_positions_needed
= false;
4418 for (uint32_t j
= 0; j
< cmd_buffer_count
; j
++) {
4419 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
4422 scratch_size_per_wave
= MAX2(scratch_size_per_wave
, cmd_buffer
->scratch_size_per_wave_needed
);
4423 waves_wanted
= MAX2(waves_wanted
, cmd_buffer
->scratch_waves_wanted
);
4424 compute_scratch_size_per_wave
= MAX2(compute_scratch_size_per_wave
,
4425 cmd_buffer
->compute_scratch_size_per_wave_needed
);
4426 compute_waves_wanted
= MAX2(compute_waves_wanted
,
4427 cmd_buffer
->compute_scratch_waves_wanted
);
4428 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
4429 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
4430 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
4431 gds_needed
|= cmd_buffer
->gds_needed
;
4432 gds_oa_needed
|= cmd_buffer
->gds_oa_needed
;
4433 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
4436 return radv_get_preamble_cs(queue
, scratch_size_per_wave
, waves_wanted
,
4437 compute_scratch_size_per_wave
, compute_waves_wanted
,
4438 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
4439 gds_needed
, gds_oa_needed
, sample_positions_needed
,
4440 initial_full_flush_preamble_cs
,
4441 initial_preamble_cs
, continue_preamble_cs
);
4444 struct radv_deferred_queue_submission
{
4445 struct radv_queue
*queue
;
4446 VkCommandBuffer
*cmd_buffers
;
4447 uint32_t cmd_buffer_count
;
4449 /* Sparse bindings that happen on a queue. */
4450 VkSparseBufferMemoryBindInfo
*buffer_binds
;
4451 uint32_t buffer_bind_count
;
4452 VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
4453 uint32_t image_opaque_bind_count
;
4456 VkShaderStageFlags wait_dst_stage_mask
;
4457 struct radv_semaphore_part
**wait_semaphores
;
4458 uint32_t wait_semaphore_count
;
4459 struct radv_semaphore_part
**signal_semaphores
;
4460 uint32_t signal_semaphore_count
;
4463 uint64_t *wait_values
;
4464 uint64_t *signal_values
;
4466 struct radv_semaphore_part
*temporary_semaphore_parts
;
4467 uint32_t temporary_semaphore_part_count
;
4469 struct list_head queue_pending_list
;
4470 uint32_t submission_wait_count
;
4471 struct radv_timeline_waiter
*wait_nodes
;
4473 struct list_head processing_list
;
4476 struct radv_queue_submission
{
4477 const VkCommandBuffer
*cmd_buffers
;
4478 uint32_t cmd_buffer_count
;
4480 /* Sparse bindings that happen on a queue. */
4481 const VkSparseBufferMemoryBindInfo
*buffer_binds
;
4482 uint32_t buffer_bind_count
;
4483 const VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
4484 uint32_t image_opaque_bind_count
;
4487 VkPipelineStageFlags wait_dst_stage_mask
;
4488 const VkSemaphore
*wait_semaphores
;
4489 uint32_t wait_semaphore_count
;
4490 const VkSemaphore
*signal_semaphores
;
4491 uint32_t signal_semaphore_count
;
4494 const uint64_t *wait_values
;
4495 uint32_t wait_value_count
;
4496 const uint64_t *signal_values
;
4497 uint32_t signal_value_count
;
4501 radv_create_deferred_submission(struct radv_queue
*queue
,
4502 const struct radv_queue_submission
*submission
,
4503 struct radv_deferred_queue_submission
**out
)
4505 struct radv_deferred_queue_submission
*deferred
= NULL
;
4506 size_t size
= sizeof(struct radv_deferred_queue_submission
);
4508 uint32_t temporary_count
= 0;
4509 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4510 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
4511 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
)
4515 size
+= submission
->cmd_buffer_count
* sizeof(VkCommandBuffer
);
4516 size
+= submission
->buffer_bind_count
* sizeof(VkSparseBufferMemoryBindInfo
);
4517 size
+= submission
->image_opaque_bind_count
* sizeof(VkSparseImageOpaqueMemoryBindInfo
);
4518 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_semaphore_part
*);
4519 size
+= temporary_count
* sizeof(struct radv_semaphore_part
);
4520 size
+= submission
->signal_semaphore_count
* sizeof(struct radv_semaphore_part
*);
4521 size
+= submission
->wait_value_count
* sizeof(uint64_t);
4522 size
+= submission
->signal_value_count
* sizeof(uint64_t);
4523 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_timeline_waiter
);
4525 deferred
= calloc(1, size
);
4527 return VK_ERROR_OUT_OF_HOST_MEMORY
;
4529 deferred
->queue
= queue
;
4531 deferred
->cmd_buffers
= (void*)(deferred
+ 1);
4532 deferred
->cmd_buffer_count
= submission
->cmd_buffer_count
;
4533 memcpy(deferred
->cmd_buffers
, submission
->cmd_buffers
,
4534 submission
->cmd_buffer_count
* sizeof(*deferred
->cmd_buffers
));
4536 deferred
->buffer_binds
= (void*)(deferred
->cmd_buffers
+ submission
->cmd_buffer_count
);
4537 deferred
->buffer_bind_count
= submission
->buffer_bind_count
;
4538 memcpy(deferred
->buffer_binds
, submission
->buffer_binds
,
4539 submission
->buffer_bind_count
* sizeof(*deferred
->buffer_binds
));
4541 deferred
->image_opaque_binds
= (void*)(deferred
->buffer_binds
+ submission
->buffer_bind_count
);
4542 deferred
->image_opaque_bind_count
= submission
->image_opaque_bind_count
;
4543 memcpy(deferred
->image_opaque_binds
, submission
->image_opaque_binds
,
4544 submission
->image_opaque_bind_count
* sizeof(*deferred
->image_opaque_binds
));
4546 deferred
->flush_caches
= submission
->flush_caches
;
4547 deferred
->wait_dst_stage_mask
= submission
->wait_dst_stage_mask
;
4549 deferred
->wait_semaphores
= (void*)(deferred
->image_opaque_binds
+ deferred
->image_opaque_bind_count
);
4550 deferred
->wait_semaphore_count
= submission
->wait_semaphore_count
;
4552 deferred
->signal_semaphores
= (void*)(deferred
->wait_semaphores
+ deferred
->wait_semaphore_count
);
4553 deferred
->signal_semaphore_count
= submission
->signal_semaphore_count
;
4555 deferred
->fence
= submission
->fence
;
4557 deferred
->temporary_semaphore_parts
= (void*)(deferred
->signal_semaphores
+ deferred
->signal_semaphore_count
);
4558 deferred
->temporary_semaphore_part_count
= temporary_count
;
4560 uint32_t temporary_idx
= 0;
4561 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4562 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
4563 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
4564 deferred
->wait_semaphores
[i
] = &deferred
->temporary_semaphore_parts
[temporary_idx
];
4565 deferred
->temporary_semaphore_parts
[temporary_idx
] = semaphore
->temporary
;
4566 semaphore
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
4569 deferred
->wait_semaphores
[i
] = &semaphore
->permanent
;
4572 for (uint32_t i
= 0; i
< submission
->signal_semaphore_count
; ++i
) {
4573 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->signal_semaphores
[i
]);
4574 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
4575 deferred
->signal_semaphores
[i
] = &semaphore
->temporary
;
4577 deferred
->signal_semaphores
[i
] = &semaphore
->permanent
;
4581 deferred
->wait_values
= (void*)(deferred
->temporary_semaphore_parts
+ temporary_count
);
4582 memcpy(deferred
->wait_values
, submission
->wait_values
, submission
->wait_value_count
* sizeof(uint64_t));
4583 deferred
->signal_values
= deferred
->wait_values
+ submission
->wait_value_count
;
4584 memcpy(deferred
->signal_values
, submission
->signal_values
, submission
->signal_value_count
* sizeof(uint64_t));
4586 deferred
->wait_nodes
= (void*)(deferred
->signal_values
+ submission
->signal_value_count
);
4587 /* This is worst-case. radv_queue_enqueue_submission will fill in further, but this
4588 * ensure the submission is not accidentally triggered early when adding wait timelines. */
4589 deferred
->submission_wait_count
= 1 + submission
->wait_semaphore_count
;
4596 radv_queue_enqueue_submission(struct radv_deferred_queue_submission
*submission
,
4597 struct list_head
*processing_list
)
4599 uint32_t wait_cnt
= 0;
4600 struct radv_timeline_waiter
*waiter
= submission
->wait_nodes
;
4601 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4602 if (submission
->wait_semaphores
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4603 pthread_mutex_lock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
4604 if (submission
->wait_semaphores
[i
]->timeline
.highest_submitted
< submission
->wait_values
[i
]) {
4606 waiter
->value
= submission
->wait_values
[i
];
4607 waiter
->submission
= submission
;
4608 list_addtail(&waiter
->list
, &submission
->wait_semaphores
[i
]->timeline
.waiters
);
4611 pthread_mutex_unlock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
4615 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
4617 bool is_first
= list_is_empty(&submission
->queue
->pending_submissions
);
4618 list_addtail(&submission
->queue_pending_list
, &submission
->queue
->pending_submissions
);
4620 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
4622 /* If there is already a submission in the queue, that will decrement the counter by 1 when
4623 * submitted, but if the queue was empty, we decrement ourselves as there is no previous
4625 uint32_t decrement
= submission
->wait_semaphore_count
- wait_cnt
+ (is_first
? 1 : 0);
4626 if (__atomic_sub_fetch(&submission
->submission_wait_count
, decrement
, __ATOMIC_ACQ_REL
) == 0) {
4627 list_addtail(&submission
->processing_list
, processing_list
);
4632 radv_queue_submission_update_queue(struct radv_deferred_queue_submission
*submission
,
4633 struct list_head
*processing_list
)
4635 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
4636 list_del(&submission
->queue_pending_list
);
4638 /* trigger the next submission in the queue. */
4639 if (!list_is_empty(&submission
->queue
->pending_submissions
)) {
4640 struct radv_deferred_queue_submission
*next_submission
=
4641 list_first_entry(&submission
->queue
->pending_submissions
,
4642 struct radv_deferred_queue_submission
,
4643 queue_pending_list
);
4644 if (p_atomic_dec_zero(&next_submission
->submission_wait_count
)) {
4645 list_addtail(&next_submission
->processing_list
, processing_list
);
4648 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
4650 pthread_cond_broadcast(&submission
->queue
->device
->timeline_cond
);
4654 radv_queue_submit_deferred(struct radv_deferred_queue_submission
*submission
,
4655 struct list_head
*processing_list
)
4657 RADV_FROM_HANDLE(radv_fence
, fence
, submission
->fence
);
4658 struct radv_queue
*queue
= submission
->queue
;
4659 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
4660 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
4661 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
4662 bool do_flush
= submission
->flush_caches
|| submission
->wait_dst_stage_mask
;
4663 bool can_patch
= true;
4665 struct radv_winsys_sem_info sem_info
;
4668 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
;
4669 struct radeon_cmdbuf
*initial_flush_preamble_cs
= NULL
;
4670 struct radeon_cmdbuf
*continue_preamble_cs
= NULL
;
4672 result
= radv_get_preambles(queue
, submission
->cmd_buffers
,
4673 submission
->cmd_buffer_count
,
4674 &initial_preamble_cs
,
4675 &initial_flush_preamble_cs
,
4676 &continue_preamble_cs
);
4677 if (result
!= VK_SUCCESS
)
4680 result
= radv_alloc_sem_info(queue
->device
,
4682 submission
->wait_semaphore_count
,
4683 submission
->wait_semaphores
,
4684 submission
->wait_values
,
4685 submission
->signal_semaphore_count
,
4686 submission
->signal_semaphores
,
4687 submission
->signal_values
,
4689 if (result
!= VK_SUCCESS
)
4692 for (uint32_t i
= 0; i
< submission
->buffer_bind_count
; ++i
) {
4693 radv_sparse_buffer_bind_memory(queue
->device
,
4694 submission
->buffer_binds
+ i
);
4697 for (uint32_t i
= 0; i
< submission
->image_opaque_bind_count
; ++i
) {
4698 radv_sparse_image_opaque_bind_memory(queue
->device
,
4699 submission
->image_opaque_binds
+ i
);
4702 if (!submission
->cmd_buffer_count
) {
4703 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
4704 &queue
->device
->empty_cs
[queue
->queue_family_index
],
4709 radv_loge("failed to submit CS\n");
4715 struct radeon_cmdbuf
**cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
4716 (submission
->cmd_buffer_count
));
4718 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
++) {
4719 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, submission
->cmd_buffers
[j
]);
4720 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
4722 cs_array
[j
] = cmd_buffer
->cs
;
4723 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
4726 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
4729 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
+= advance
) {
4730 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
4731 const struct radv_winsys_bo_list
*bo_list
= NULL
;
4733 advance
= MIN2(max_cs_submission
,
4734 submission
->cmd_buffer_count
- j
);
4736 if (queue
->device
->trace_bo
)
4737 *queue
->device
->trace_id_ptr
= 0;
4739 sem_info
.cs_emit_wait
= j
== 0;
4740 sem_info
.cs_emit_signal
= j
+ advance
== submission
->cmd_buffer_count
;
4742 if (unlikely(queue
->device
->use_global_bo_list
)) {
4743 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
4744 bo_list
= &queue
->device
->bo_list
.list
;
4747 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
4748 advance
, initial_preamble
, continue_preamble_cs
,
4750 can_patch
, base_fence
);
4752 if (unlikely(queue
->device
->use_global_bo_list
))
4753 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
4756 radv_loge("failed to submit CS\n");
4759 if (queue
->device
->trace_bo
) {
4760 radv_check_gpu_hangs(queue
, cs_array
[j
]);
4768 radv_free_temp_syncobjs(queue
->device
,
4769 submission
->temporary_semaphore_part_count
,
4770 submission
->temporary_semaphore_parts
);
4771 radv_finalize_timelines(queue
->device
,
4772 submission
->wait_semaphore_count
,
4773 submission
->wait_semaphores
,
4774 submission
->wait_values
,
4775 submission
->signal_semaphore_count
,
4776 submission
->signal_semaphores
,
4777 submission
->signal_values
,
4779 /* Has to happen after timeline finalization to make sure the
4780 * condition variable is only triggered when timelines and queue have
4782 radv_queue_submission_update_queue(submission
, processing_list
);
4783 radv_free_sem_info(&sem_info
);
4788 radv_free_temp_syncobjs(queue
->device
,
4789 submission
->temporary_semaphore_part_count
,
4790 submission
->temporary_semaphore_parts
);
4792 return VK_ERROR_DEVICE_LOST
;
4796 radv_process_submissions(struct list_head
*processing_list
)
4798 while(!list_is_empty(processing_list
)) {
4799 struct radv_deferred_queue_submission
*submission
=
4800 list_first_entry(processing_list
, struct radv_deferred_queue_submission
, processing_list
);
4801 list_del(&submission
->processing_list
);
4803 VkResult result
= radv_queue_submit_deferred(submission
, processing_list
);
4804 if (result
!= VK_SUCCESS
)
4810 static VkResult
radv_queue_submit(struct radv_queue
*queue
,
4811 const struct radv_queue_submission
*submission
)
4813 struct radv_deferred_queue_submission
*deferred
= NULL
;
4815 VkResult result
= radv_create_deferred_submission(queue
, submission
, &deferred
);
4816 if (result
!= VK_SUCCESS
)
4819 struct list_head processing_list
;
4820 list_inithead(&processing_list
);
4822 radv_queue_enqueue_submission(deferred
, &processing_list
);
4823 return radv_process_submissions(&processing_list
);
4827 radv_queue_internal_submit(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
)
4829 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
4830 struct radv_winsys_sem_info sem_info
;
4834 result
= radv_alloc_sem_info(queue
->device
, &sem_info
, 0, NULL
, 0, 0,
4835 0, NULL
, VK_NULL_HANDLE
);
4836 if (result
!= VK_SUCCESS
)
4839 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, &cs
, 1, NULL
,
4840 NULL
, &sem_info
, NULL
, false, NULL
);
4841 radv_free_sem_info(&sem_info
);
4845 /* Signals fence as soon as all the work currently put on queue is done. */
4846 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
4849 return radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4854 static bool radv_submit_has_effects(const VkSubmitInfo
*info
)
4856 return info
->commandBufferCount
||
4857 info
->waitSemaphoreCount
||
4858 info
->signalSemaphoreCount
;
4861 VkResult
radv_QueueSubmit(
4863 uint32_t submitCount
,
4864 const VkSubmitInfo
* pSubmits
,
4867 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4869 uint32_t fence_idx
= 0;
4870 bool flushed_caches
= false;
4872 if (fence
!= VK_NULL_HANDLE
) {
4873 for (uint32_t i
= 0; i
< submitCount
; ++i
)
4874 if (radv_submit_has_effects(pSubmits
+ i
))
4877 fence_idx
= UINT32_MAX
;
4879 for (uint32_t i
= 0; i
< submitCount
; i
++) {
4880 if (!radv_submit_has_effects(pSubmits
+ i
) && fence_idx
!= i
)
4883 VkPipelineStageFlags wait_dst_stage_mask
= 0;
4884 for (unsigned j
= 0; j
< pSubmits
[i
].waitSemaphoreCount
; ++j
) {
4885 wait_dst_stage_mask
|= pSubmits
[i
].pWaitDstStageMask
[j
];
4888 const VkTimelineSemaphoreSubmitInfo
*timeline_info
=
4889 vk_find_struct_const(pSubmits
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO
);
4891 result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4892 .cmd_buffers
= pSubmits
[i
].pCommandBuffers
,
4893 .cmd_buffer_count
= pSubmits
[i
].commandBufferCount
,
4894 .wait_dst_stage_mask
= wait_dst_stage_mask
,
4895 .flush_caches
= !flushed_caches
,
4896 .wait_semaphores
= pSubmits
[i
].pWaitSemaphores
,
4897 .wait_semaphore_count
= pSubmits
[i
].waitSemaphoreCount
,
4898 .signal_semaphores
= pSubmits
[i
].pSignalSemaphores
,
4899 .signal_semaphore_count
= pSubmits
[i
].signalSemaphoreCount
,
4900 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
4901 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
4902 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
4903 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
4904 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
4906 if (result
!= VK_SUCCESS
)
4909 flushed_caches
= true;
4912 if (fence
!= VK_NULL_HANDLE
&& !submitCount
) {
4913 result
= radv_signal_fence(queue
, fence
);
4914 if (result
!= VK_SUCCESS
)
4921 VkResult
radv_QueueWaitIdle(
4924 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4926 pthread_mutex_lock(&queue
->pending_mutex
);
4927 while (!list_is_empty(&queue
->pending_submissions
)) {
4928 pthread_cond_wait(&queue
->device
->timeline_cond
, &queue
->pending_mutex
);
4930 pthread_mutex_unlock(&queue
->pending_mutex
);
4932 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
4933 radv_queue_family_to_ring(queue
->queue_family_index
),
4938 VkResult
radv_DeviceWaitIdle(
4941 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4943 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
4944 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
4945 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
4951 VkResult
radv_EnumerateInstanceExtensionProperties(
4952 const char* pLayerName
,
4953 uint32_t* pPropertyCount
,
4954 VkExtensionProperties
* pProperties
)
4956 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
4958 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
4959 if (radv_instance_extensions_supported
.extensions
[i
]) {
4960 vk_outarray_append(&out
, prop
) {
4961 *prop
= radv_instance_extensions
[i
];
4966 return vk_outarray_status(&out
);
4969 VkResult
radv_EnumerateDeviceExtensionProperties(
4970 VkPhysicalDevice physicalDevice
,
4971 const char* pLayerName
,
4972 uint32_t* pPropertyCount
,
4973 VkExtensionProperties
* pProperties
)
4975 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
4976 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
4978 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
4979 if (device
->supported_extensions
.extensions
[i
]) {
4980 vk_outarray_append(&out
, prop
) {
4981 *prop
= radv_device_extensions
[i
];
4986 return vk_outarray_status(&out
);
4989 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
4990 VkInstance _instance
,
4993 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4995 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
4996 * when we have to return valid function pointers, NULL, or it's left
4997 * undefined. See the table for exact details.
5002 #define LOOKUP_RADV_ENTRYPOINT(entrypoint) \
5003 if (strcmp(pName, "vk" #entrypoint) == 0) \
5004 return (PFN_vkVoidFunction)radv_##entrypoint
5006 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
5007 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
5008 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceVersion
);
5009 LOOKUP_RADV_ENTRYPOINT(CreateInstance
);
5011 /* GetInstanceProcAddr() can also be called with a NULL instance.
5012 * See https://gitlab.khronos.org/vulkan/vulkan/issues/2057
5014 LOOKUP_RADV_ENTRYPOINT(GetInstanceProcAddr
);
5016 #undef LOOKUP_RADV_ENTRYPOINT
5018 if (instance
== NULL
)
5021 int idx
= radv_get_instance_entrypoint_index(pName
);
5023 return instance
->dispatch
.entrypoints
[idx
];
5025 idx
= radv_get_physical_device_entrypoint_index(pName
);
5027 return instance
->physical_device_dispatch
.entrypoints
[idx
];
5029 idx
= radv_get_device_entrypoint_index(pName
);
5031 return instance
->device_dispatch
.entrypoints
[idx
];
5036 /* The loader wants us to expose a second GetInstanceProcAddr function
5037 * to work around certain LD_PRELOAD issues seen in apps.
5040 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
5041 VkInstance instance
,
5045 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
5046 VkInstance instance
,
5049 return radv_GetInstanceProcAddr(instance
, pName
);
5053 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
5054 VkInstance _instance
,
5058 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
5059 VkInstance _instance
,
5062 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5064 if (!pName
|| !instance
)
5067 int idx
= radv_get_physical_device_entrypoint_index(pName
);
5071 return instance
->physical_device_dispatch
.entrypoints
[idx
];
5074 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
5078 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5080 if (!device
|| !pName
)
5083 int idx
= radv_get_device_entrypoint_index(pName
);
5087 return device
->dispatch
.entrypoints
[idx
];
5090 bool radv_get_memory_fd(struct radv_device
*device
,
5091 struct radv_device_memory
*memory
,
5094 struct radeon_bo_metadata metadata
;
5096 if (memory
->image
) {
5097 if (memory
->image
->tiling
!= VK_IMAGE_TILING_LINEAR
)
5098 radv_init_metadata(device
, memory
->image
, &metadata
);
5099 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
5102 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
5107 static void radv_free_memory(struct radv_device
*device
,
5108 const VkAllocationCallbacks
* pAllocator
,
5109 struct radv_device_memory
*mem
)
5114 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
5115 if (mem
->android_hardware_buffer
)
5116 AHardwareBuffer_release(mem
->android_hardware_buffer
);
5120 if (device
->overallocation_disallowed
) {
5121 mtx_lock(&device
->overallocation_mutex
);
5122 device
->allocated_memory_size
[mem
->heap_index
] -= mem
->alloc_size
;
5123 mtx_unlock(&device
->overallocation_mutex
);
5126 radv_bo_list_remove(device
, mem
->bo
);
5127 device
->ws
->buffer_destroy(mem
->bo
);
5131 vk_object_base_finish(&mem
->base
);
5132 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);
5135 static VkResult
radv_alloc_memory(struct radv_device
*device
,
5136 const VkMemoryAllocateInfo
* pAllocateInfo
,
5137 const VkAllocationCallbacks
* pAllocator
,
5138 VkDeviceMemory
* pMem
)
5140 struct radv_device_memory
*mem
;
5142 enum radeon_bo_domain domain
;
5145 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
5147 const VkImportMemoryFdInfoKHR
*import_info
=
5148 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
5149 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
5150 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
5151 const VkExportMemoryAllocateInfo
*export_info
=
5152 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
5153 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahb_import_info
=
5154 vk_find_struct_const(pAllocateInfo
->pNext
,
5155 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
5156 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
5157 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
5159 const struct wsi_memory_allocate_info
*wsi_info
=
5160 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
5162 if (pAllocateInfo
->allocationSize
== 0 && !ahb_import_info
&&
5163 !(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
))) {
5164 /* Apparently, this is allowed */
5165 *pMem
= VK_NULL_HANDLE
;
5169 mem
= vk_zalloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*mem
), 8,
5170 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5172 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5174 vk_object_base_init(&device
->vk
, &mem
->base
,
5175 VK_OBJECT_TYPE_DEVICE_MEMORY
);
5177 if (wsi_info
&& wsi_info
->implicit_sync
)
5178 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
5180 if (dedicate_info
) {
5181 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
5182 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
5188 float priority_float
= 0.5;
5189 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
5190 vk_find_struct_const(pAllocateInfo
->pNext
,
5191 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
5193 priority_float
= priority_ext
->priority
;
5195 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
5196 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
5198 mem
->user_ptr
= NULL
;
5201 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
5202 mem
->android_hardware_buffer
= NULL
;
5205 if (ahb_import_info
) {
5206 result
= radv_import_ahb_memory(device
, mem
, priority
, ahb_import_info
);
5207 if (result
!= VK_SUCCESS
)
5209 } else if(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)) {
5210 result
= radv_create_ahb_memory(device
, mem
, priority
, pAllocateInfo
);
5211 if (result
!= VK_SUCCESS
)
5213 } else if (import_info
) {
5214 assert(import_info
->handleType
==
5215 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5216 import_info
->handleType
==
5217 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5218 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
5221 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
5224 close(import_info
->fd
);
5226 } else if (host_ptr_info
) {
5227 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
5228 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
5229 pAllocateInfo
->allocationSize
,
5232 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
5235 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
5238 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
5239 uint32_t heap_index
;
5241 heap_index
= device
->physical_device
->memory_properties
.memoryTypes
[pAllocateInfo
->memoryTypeIndex
].heapIndex
;
5242 domain
= device
->physical_device
->memory_domains
[pAllocateInfo
->memoryTypeIndex
];
5243 flags
|= device
->physical_device
->memory_flags
[pAllocateInfo
->memoryTypeIndex
];
5245 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
5246 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
5247 if (device
->use_global_bo_list
) {
5248 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
5252 if (device
->overallocation_disallowed
) {
5253 uint64_t total_size
=
5254 device
->physical_device
->memory_properties
.memoryHeaps
[heap_index
].size
;
5256 mtx_lock(&device
->overallocation_mutex
);
5257 if (device
->allocated_memory_size
[heap_index
] + alloc_size
> total_size
) {
5258 mtx_unlock(&device
->overallocation_mutex
);
5259 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
5262 device
->allocated_memory_size
[heap_index
] += alloc_size
;
5263 mtx_unlock(&device
->overallocation_mutex
);
5266 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
5267 domain
, flags
, priority
);
5270 if (device
->overallocation_disallowed
) {
5271 mtx_lock(&device
->overallocation_mutex
);
5272 device
->allocated_memory_size
[heap_index
] -= alloc_size
;
5273 mtx_unlock(&device
->overallocation_mutex
);
5275 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
5279 mem
->heap_index
= heap_index
;
5280 mem
->alloc_size
= alloc_size
;
5284 result
= radv_bo_list_add(device
, mem
->bo
);
5285 if (result
!= VK_SUCCESS
)
5289 *pMem
= radv_device_memory_to_handle(mem
);
5294 radv_free_memory(device
, pAllocator
,mem
);
5299 VkResult
radv_AllocateMemory(
5301 const VkMemoryAllocateInfo
* pAllocateInfo
,
5302 const VkAllocationCallbacks
* pAllocator
,
5303 VkDeviceMemory
* pMem
)
5305 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5306 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
5309 void radv_FreeMemory(
5311 VkDeviceMemory _mem
,
5312 const VkAllocationCallbacks
* pAllocator
)
5314 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5315 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
5317 radv_free_memory(device
, pAllocator
, mem
);
5320 VkResult
radv_MapMemory(
5322 VkDeviceMemory _memory
,
5323 VkDeviceSize offset
,
5325 VkMemoryMapFlags flags
,
5328 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5329 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
5337 *ppData
= mem
->user_ptr
;
5339 *ppData
= device
->ws
->buffer_map(mem
->bo
);
5346 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
5349 void radv_UnmapMemory(
5351 VkDeviceMemory _memory
)
5353 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5354 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
5359 if (mem
->user_ptr
== NULL
)
5360 device
->ws
->buffer_unmap(mem
->bo
);
5363 VkResult
radv_FlushMappedMemoryRanges(
5365 uint32_t memoryRangeCount
,
5366 const VkMappedMemoryRange
* pMemoryRanges
)
5371 VkResult
radv_InvalidateMappedMemoryRanges(
5373 uint32_t memoryRangeCount
,
5374 const VkMappedMemoryRange
* pMemoryRanges
)
5379 void radv_GetBufferMemoryRequirements(
5382 VkMemoryRequirements
* pMemoryRequirements
)
5384 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5385 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
5387 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
5389 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
5390 pMemoryRequirements
->alignment
= 4096;
5392 pMemoryRequirements
->alignment
= 16;
5394 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
5397 void radv_GetBufferMemoryRequirements2(
5399 const VkBufferMemoryRequirementsInfo2
*pInfo
,
5400 VkMemoryRequirements2
*pMemoryRequirements
)
5402 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
5403 &pMemoryRequirements
->memoryRequirements
);
5404 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
5405 switch (ext
->sType
) {
5406 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
5407 VkMemoryDedicatedRequirements
*req
=
5408 (VkMemoryDedicatedRequirements
*) ext
;
5409 req
->requiresDedicatedAllocation
= false;
5410 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
5419 void radv_GetImageMemoryRequirements(
5422 VkMemoryRequirements
* pMemoryRequirements
)
5424 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5425 RADV_FROM_HANDLE(radv_image
, image
, _image
);
5427 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
5429 pMemoryRequirements
->size
= image
->size
;
5430 pMemoryRequirements
->alignment
= image
->alignment
;
5433 void radv_GetImageMemoryRequirements2(
5435 const VkImageMemoryRequirementsInfo2
*pInfo
,
5436 VkMemoryRequirements2
*pMemoryRequirements
)
5438 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
5439 &pMemoryRequirements
->memoryRequirements
);
5441 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
5443 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
5444 switch (ext
->sType
) {
5445 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
5446 VkMemoryDedicatedRequirements
*req
=
5447 (VkMemoryDedicatedRequirements
*) ext
;
5448 req
->requiresDedicatedAllocation
= image
->shareable
&&
5449 image
->tiling
!= VK_IMAGE_TILING_LINEAR
;
5450 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
5459 void radv_GetImageSparseMemoryRequirements(
5462 uint32_t* pSparseMemoryRequirementCount
,
5463 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
5468 void radv_GetImageSparseMemoryRequirements2(
5470 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
5471 uint32_t* pSparseMemoryRequirementCount
,
5472 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
5477 void radv_GetDeviceMemoryCommitment(
5479 VkDeviceMemory memory
,
5480 VkDeviceSize
* pCommittedMemoryInBytes
)
5482 *pCommittedMemoryInBytes
= 0;
5485 VkResult
radv_BindBufferMemory2(VkDevice device
,
5486 uint32_t bindInfoCount
,
5487 const VkBindBufferMemoryInfo
*pBindInfos
)
5489 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5490 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
5491 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
5494 buffer
->bo
= mem
->bo
;
5495 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
5503 VkResult
radv_BindBufferMemory(
5506 VkDeviceMemory memory
,
5507 VkDeviceSize memoryOffset
)
5509 const VkBindBufferMemoryInfo info
= {
5510 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
5513 .memoryOffset
= memoryOffset
5516 return radv_BindBufferMemory2(device
, 1, &info
);
5519 VkResult
radv_BindImageMemory2(VkDevice device
,
5520 uint32_t bindInfoCount
,
5521 const VkBindImageMemoryInfo
*pBindInfos
)
5523 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5524 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
5525 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
5528 image
->bo
= mem
->bo
;
5529 image
->offset
= pBindInfos
[i
].memoryOffset
;
5539 VkResult
radv_BindImageMemory(
5542 VkDeviceMemory memory
,
5543 VkDeviceSize memoryOffset
)
5545 const VkBindImageMemoryInfo info
= {
5546 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
5549 .memoryOffset
= memoryOffset
5552 return radv_BindImageMemory2(device
, 1, &info
);
5555 static bool radv_sparse_bind_has_effects(const VkBindSparseInfo
*info
)
5557 return info
->bufferBindCount
||
5558 info
->imageOpaqueBindCount
||
5559 info
->imageBindCount
||
5560 info
->waitSemaphoreCount
||
5561 info
->signalSemaphoreCount
;
5564 VkResult
radv_QueueBindSparse(
5566 uint32_t bindInfoCount
,
5567 const VkBindSparseInfo
* pBindInfo
,
5570 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
5572 uint32_t fence_idx
= 0;
5574 if (fence
!= VK_NULL_HANDLE
) {
5575 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
)
5576 if (radv_sparse_bind_has_effects(pBindInfo
+ i
))
5579 fence_idx
= UINT32_MAX
;
5581 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5582 if (i
!= fence_idx
&& !radv_sparse_bind_has_effects(pBindInfo
+ i
))
5585 const VkTimelineSemaphoreSubmitInfo
*timeline_info
=
5586 vk_find_struct_const(pBindInfo
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO
);
5588 VkResult result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
5589 .buffer_binds
= pBindInfo
[i
].pBufferBinds
,
5590 .buffer_bind_count
= pBindInfo
[i
].bufferBindCount
,
5591 .image_opaque_binds
= pBindInfo
[i
].pImageOpaqueBinds
,
5592 .image_opaque_bind_count
= pBindInfo
[i
].imageOpaqueBindCount
,
5593 .wait_semaphores
= pBindInfo
[i
].pWaitSemaphores
,
5594 .wait_semaphore_count
= pBindInfo
[i
].waitSemaphoreCount
,
5595 .signal_semaphores
= pBindInfo
[i
].pSignalSemaphores
,
5596 .signal_semaphore_count
= pBindInfo
[i
].signalSemaphoreCount
,
5597 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
5598 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
5599 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
5600 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
5601 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
5604 if (result
!= VK_SUCCESS
)
5608 if (fence
!= VK_NULL_HANDLE
&& !bindInfoCount
) {
5609 result
= radv_signal_fence(queue
, fence
);
5610 if (result
!= VK_SUCCESS
)
5617 VkResult
radv_CreateFence(
5619 const VkFenceCreateInfo
* pCreateInfo
,
5620 const VkAllocationCallbacks
* pAllocator
,
5623 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5624 const VkExportFenceCreateInfo
*export
=
5625 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
5626 VkExternalFenceHandleTypeFlags handleTypes
=
5627 export
? export
->handleTypes
: 0;
5629 struct radv_fence
*fence
= vk_alloc2(&device
->vk
.alloc
, pAllocator
,
5631 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5634 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5636 vk_object_base_init(&device
->vk
, &fence
->base
, VK_OBJECT_TYPE_FENCE
);
5638 fence
->fence_wsi
= NULL
;
5639 fence
->temp_syncobj
= 0;
5640 if (device
->always_use_syncobj
|| handleTypes
) {
5641 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
5643 vk_free2(&device
->vk
.alloc
, pAllocator
, fence
);
5644 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5646 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
5647 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
5649 fence
->fence
= NULL
;
5651 fence
->fence
= device
->ws
->create_fence();
5652 if (!fence
->fence
) {
5653 vk_free2(&device
->vk
.alloc
, pAllocator
, fence
);
5654 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5657 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
5658 device
->ws
->signal_fence(fence
->fence
);
5661 *pFence
= radv_fence_to_handle(fence
);
5666 void radv_DestroyFence(
5669 const VkAllocationCallbacks
* pAllocator
)
5671 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5672 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5677 if (fence
->temp_syncobj
)
5678 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5680 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
5682 device
->ws
->destroy_fence(fence
->fence
);
5683 if (fence
->fence_wsi
)
5684 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
5686 vk_object_base_finish(&fence
->base
);
5687 vk_free2(&device
->vk
.alloc
, pAllocator
, fence
);
5691 uint64_t radv_get_current_time(void)
5694 clock_gettime(CLOCK_MONOTONIC
, &tv
);
5695 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
5698 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
5700 uint64_t current_time
= radv_get_current_time();
5702 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
5704 return current_time
+ timeout
;
5708 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
5709 uint32_t fenceCount
, const VkFence
*pFences
)
5711 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5712 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5713 if (fence
->fence
== NULL
|| fence
->syncobj
||
5714 fence
->temp_syncobj
|| fence
->fence_wsi
||
5715 (!device
->ws
->is_fence_waitable(fence
->fence
)))
5721 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
5723 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5724 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5725 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
5731 VkResult
radv_WaitForFences(
5733 uint32_t fenceCount
,
5734 const VkFence
* pFences
,
5738 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5739 timeout
= radv_get_absolute_timeout(timeout
);
5741 if (device
->always_use_syncobj
&&
5742 radv_all_fences_syncobj(fenceCount
, pFences
))
5744 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
5746 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5748 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5749 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5750 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
5753 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
5756 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5759 if (!waitAll
&& fenceCount
> 1) {
5760 /* Not doing this by default for waitAll, due to needing to allocate twice. */
5761 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
5762 uint32_t wait_count
= 0;
5763 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
5765 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5767 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5768 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5770 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
5775 fences
[wait_count
++] = fence
->fence
;
5778 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
5779 waitAll
, timeout
- radv_get_current_time());
5782 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5785 while(radv_get_current_time() <= timeout
) {
5786 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5787 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
5794 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5795 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5796 bool expired
= false;
5798 if (fence
->temp_syncobj
) {
5799 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
5804 if (fence
->syncobj
) {
5805 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
5811 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
5812 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
5813 radv_get_current_time() <= timeout
)
5817 expired
= device
->ws
->fence_wait(device
->ws
,
5824 if (fence
->fence_wsi
) {
5825 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
5826 if (result
!= VK_SUCCESS
)
5834 VkResult
radv_ResetFences(VkDevice _device
,
5835 uint32_t fenceCount
,
5836 const VkFence
*pFences
)
5838 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5840 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
5841 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5843 device
->ws
->reset_fence(fence
->fence
);
5845 /* Per spec, we first restore the permanent payload, and then reset, so
5846 * having a temp syncobj should not skip resetting the permanent syncobj. */
5847 if (fence
->temp_syncobj
) {
5848 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5849 fence
->temp_syncobj
= 0;
5852 if (fence
->syncobj
) {
5853 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
5860 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
5862 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5863 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5865 if (fence
->temp_syncobj
) {
5866 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
5867 return success
? VK_SUCCESS
: VK_NOT_READY
;
5870 if (fence
->syncobj
) {
5871 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
5872 return success
? VK_SUCCESS
: VK_NOT_READY
;
5876 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
5877 return VK_NOT_READY
;
5879 if (fence
->fence_wsi
) {
5880 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
5882 if (result
!= VK_SUCCESS
) {
5883 if (result
== VK_TIMEOUT
)
5884 return VK_NOT_READY
;
5892 // Queue semaphore functions
5895 radv_create_timeline(struct radv_timeline
*timeline
, uint64_t value
)
5897 timeline
->highest_signaled
= value
;
5898 timeline
->highest_submitted
= value
;
5899 list_inithead(&timeline
->points
);
5900 list_inithead(&timeline
->free_points
);
5901 list_inithead(&timeline
->waiters
);
5902 pthread_mutex_init(&timeline
->mutex
, NULL
);
5906 radv_destroy_timeline(struct radv_device
*device
,
5907 struct radv_timeline
*timeline
)
5909 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5910 &timeline
->free_points
, list
) {
5911 list_del(&point
->list
);
5912 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
5915 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5916 &timeline
->points
, list
) {
5917 list_del(&point
->list
);
5918 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
5921 pthread_mutex_destroy(&timeline
->mutex
);
5925 radv_timeline_gc_locked(struct radv_device
*device
,
5926 struct radv_timeline
*timeline
)
5928 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5929 &timeline
->points
, list
) {
5930 if (point
->wait_count
|| point
->value
> timeline
->highest_submitted
)
5933 if (device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, 0)) {
5934 timeline
->highest_signaled
= point
->value
;
5935 list_del(&point
->list
);
5936 list_add(&point
->list
, &timeline
->free_points
);
5941 static struct radv_timeline_point
*
5942 radv_timeline_find_point_at_least_locked(struct radv_device
*device
,
5943 struct radv_timeline
*timeline
,
5946 radv_timeline_gc_locked(device
, timeline
);
5948 if (p
<= timeline
->highest_signaled
)
5951 list_for_each_entry(struct radv_timeline_point
, point
,
5952 &timeline
->points
, list
) {
5953 if (point
->value
>= p
) {
5954 ++point
->wait_count
;
5961 static struct radv_timeline_point
*
5962 radv_timeline_add_point_locked(struct radv_device
*device
,
5963 struct radv_timeline
*timeline
,
5966 radv_timeline_gc_locked(device
, timeline
);
5968 struct radv_timeline_point
*ret
= NULL
;
5969 struct radv_timeline_point
*prev
= NULL
;
5971 if (p
<= timeline
->highest_signaled
)
5974 list_for_each_entry(struct radv_timeline_point
, point
,
5975 &timeline
->points
, list
) {
5976 if (point
->value
== p
) {
5980 if (point
->value
< p
)
5984 if (list_is_empty(&timeline
->free_points
)) {
5985 ret
= malloc(sizeof(struct radv_timeline_point
));
5986 device
->ws
->create_syncobj(device
->ws
, &ret
->syncobj
);
5988 ret
= list_first_entry(&timeline
->free_points
, struct radv_timeline_point
, list
);
5989 list_del(&ret
->list
);
5991 device
->ws
->reset_syncobj(device
->ws
, ret
->syncobj
);
5995 ret
->wait_count
= 1;
5998 list_add(&ret
->list
, &prev
->list
);
6000 list_addtail(&ret
->list
, &timeline
->points
);
6007 radv_timeline_wait_locked(struct radv_device
*device
,
6008 struct radv_timeline
*timeline
,
6010 uint64_t abs_timeout
)
6012 while(timeline
->highest_submitted
< value
) {
6013 struct timespec abstime
;
6014 timespec_from_nsec(&abstime
, abs_timeout
);
6016 pthread_cond_timedwait(&device
->timeline_cond
, &timeline
->mutex
, &abstime
);
6018 if (radv_get_current_time() >= abs_timeout
&& timeline
->highest_submitted
< value
)
6022 struct radv_timeline_point
*point
= radv_timeline_find_point_at_least_locked(device
, timeline
, value
);
6026 pthread_mutex_unlock(&timeline
->mutex
);
6028 bool success
= device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, abs_timeout
);
6030 pthread_mutex_lock(&timeline
->mutex
);
6031 point
->wait_count
--;
6032 return success
? VK_SUCCESS
: VK_TIMEOUT
;
6036 radv_timeline_trigger_waiters_locked(struct radv_timeline
*timeline
,
6037 struct list_head
*processing_list
)
6039 list_for_each_entry_safe(struct radv_timeline_waiter
, waiter
,
6040 &timeline
->waiters
, list
) {
6041 if (waiter
->value
> timeline
->highest_submitted
)
6044 if (p_atomic_dec_zero(&waiter
->submission
->submission_wait_count
)) {
6045 list_addtail(&waiter
->submission
->processing_list
, processing_list
);
6047 list_del(&waiter
->list
);
6052 void radv_destroy_semaphore_part(struct radv_device
*device
,
6053 struct radv_semaphore_part
*part
)
6055 switch(part
->kind
) {
6056 case RADV_SEMAPHORE_NONE
:
6058 case RADV_SEMAPHORE_WINSYS
:
6059 device
->ws
->destroy_sem(part
->ws_sem
);
6061 case RADV_SEMAPHORE_TIMELINE
:
6062 radv_destroy_timeline(device
, &part
->timeline
);
6064 case RADV_SEMAPHORE_SYNCOBJ
:
6065 device
->ws
->destroy_syncobj(device
->ws
, part
->syncobj
);
6068 part
->kind
= RADV_SEMAPHORE_NONE
;
6071 static VkSemaphoreTypeKHR
6072 radv_get_semaphore_type(const void *pNext
, uint64_t *initial_value
)
6074 const VkSemaphoreTypeCreateInfo
*type_info
=
6075 vk_find_struct_const(pNext
, SEMAPHORE_TYPE_CREATE_INFO
);
6078 return VK_SEMAPHORE_TYPE_BINARY
;
6081 *initial_value
= type_info
->initialValue
;
6082 return type_info
->semaphoreType
;
6085 VkResult
radv_CreateSemaphore(
6087 const VkSemaphoreCreateInfo
* pCreateInfo
,
6088 const VkAllocationCallbacks
* pAllocator
,
6089 VkSemaphore
* pSemaphore
)
6091 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6092 const VkExportSemaphoreCreateInfo
*export
=
6093 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
6094 VkExternalSemaphoreHandleTypeFlags handleTypes
=
6095 export
? export
->handleTypes
: 0;
6096 uint64_t initial_value
= 0;
6097 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pCreateInfo
->pNext
, &initial_value
);
6099 struct radv_semaphore
*sem
= vk_alloc2(&device
->vk
.alloc
, pAllocator
,
6101 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6103 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6105 vk_object_base_init(&device
->vk
, &sem
->base
,
6106 VK_OBJECT_TYPE_SEMAPHORE
);
6108 sem
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
6109 sem
->permanent
.kind
= RADV_SEMAPHORE_NONE
;
6111 if (type
== VK_SEMAPHORE_TYPE_TIMELINE
) {
6112 radv_create_timeline(&sem
->permanent
.timeline
, initial_value
);
6113 sem
->permanent
.kind
= RADV_SEMAPHORE_TIMELINE
;
6114 } else if (device
->always_use_syncobj
|| handleTypes
) {
6115 assert (device
->physical_device
->rad_info
.has_syncobj
);
6116 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->permanent
.syncobj
);
6118 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
6119 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6121 sem
->permanent
.kind
= RADV_SEMAPHORE_SYNCOBJ
;
6123 sem
->permanent
.ws_sem
= device
->ws
->create_sem(device
->ws
);
6124 if (!sem
->permanent
.ws_sem
) {
6125 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
6126 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6128 sem
->permanent
.kind
= RADV_SEMAPHORE_WINSYS
;
6131 *pSemaphore
= radv_semaphore_to_handle(sem
);
6135 void radv_DestroySemaphore(
6137 VkSemaphore _semaphore
,
6138 const VkAllocationCallbacks
* pAllocator
)
6140 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6141 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
6145 radv_destroy_semaphore_part(device
, &sem
->temporary
);
6146 radv_destroy_semaphore_part(device
, &sem
->permanent
);
6147 vk_object_base_finish(&sem
->base
);
6148 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
6152 radv_GetSemaphoreCounterValue(VkDevice _device
,
6153 VkSemaphore _semaphore
,
6156 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6157 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, _semaphore
);
6159 struct radv_semaphore_part
*part
=
6160 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
6162 switch (part
->kind
) {
6163 case RADV_SEMAPHORE_TIMELINE
: {
6164 pthread_mutex_lock(&part
->timeline
.mutex
);
6165 radv_timeline_gc_locked(device
, &part
->timeline
);
6166 *pValue
= part
->timeline
.highest_signaled
;
6167 pthread_mutex_unlock(&part
->timeline
.mutex
);
6170 case RADV_SEMAPHORE_NONE
:
6171 case RADV_SEMAPHORE_SYNCOBJ
:
6172 case RADV_SEMAPHORE_WINSYS
:
6173 unreachable("Invalid semaphore type");
6175 unreachable("Unhandled semaphore type");
6180 radv_wait_timelines(struct radv_device
*device
,
6181 const VkSemaphoreWaitInfo
* pWaitInfo
,
6182 uint64_t abs_timeout
)
6184 if ((pWaitInfo
->flags
& VK_SEMAPHORE_WAIT_ANY_BIT_KHR
) && pWaitInfo
->semaphoreCount
> 1) {
6186 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
6187 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
6188 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
6189 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], 0);
6190 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
6192 if (result
== VK_SUCCESS
)
6195 if (radv_get_current_time() > abs_timeout
)
6200 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
6201 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
6202 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
6203 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], abs_timeout
);
6204 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
6206 if (result
!= VK_SUCCESS
)
6212 radv_WaitSemaphores(VkDevice _device
,
6213 const VkSemaphoreWaitInfo
* pWaitInfo
,
6216 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6217 uint64_t abs_timeout
= radv_get_absolute_timeout(timeout
);
6218 return radv_wait_timelines(device
, pWaitInfo
, abs_timeout
);
6222 radv_SignalSemaphore(VkDevice _device
,
6223 const VkSemaphoreSignalInfo
* pSignalInfo
)
6225 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6226 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pSignalInfo
->semaphore
);
6228 struct radv_semaphore_part
*part
=
6229 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
6231 switch(part
->kind
) {
6232 case RADV_SEMAPHORE_TIMELINE
: {
6233 pthread_mutex_lock(&part
->timeline
.mutex
);
6234 radv_timeline_gc_locked(device
, &part
->timeline
);
6235 part
->timeline
.highest_submitted
= MAX2(part
->timeline
.highest_submitted
, pSignalInfo
->value
);
6236 part
->timeline
.highest_signaled
= MAX2(part
->timeline
.highest_signaled
, pSignalInfo
->value
);
6238 struct list_head processing_list
;
6239 list_inithead(&processing_list
);
6240 radv_timeline_trigger_waiters_locked(&part
->timeline
, &processing_list
);
6241 pthread_mutex_unlock(&part
->timeline
.mutex
);
6243 return radv_process_submissions(&processing_list
);
6245 case RADV_SEMAPHORE_NONE
:
6246 case RADV_SEMAPHORE_SYNCOBJ
:
6247 case RADV_SEMAPHORE_WINSYS
:
6248 unreachable("Invalid semaphore type");
6255 VkResult
radv_CreateEvent(
6257 const VkEventCreateInfo
* pCreateInfo
,
6258 const VkAllocationCallbacks
* pAllocator
,
6261 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6262 struct radv_event
*event
= vk_alloc2(&device
->vk
.alloc
, pAllocator
,
6264 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6267 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6269 vk_object_base_init(&device
->vk
, &event
->base
, VK_OBJECT_TYPE_EVENT
);
6271 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
6273 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
6274 RADV_BO_PRIORITY_FENCE
);
6276 vk_free2(&device
->vk
.alloc
, pAllocator
, event
);
6277 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6280 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
6282 *pEvent
= radv_event_to_handle(event
);
6287 void radv_DestroyEvent(
6290 const VkAllocationCallbacks
* pAllocator
)
6292 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6293 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6297 device
->ws
->buffer_destroy(event
->bo
);
6298 vk_object_base_finish(&event
->base
);
6299 vk_free2(&device
->vk
.alloc
, pAllocator
, event
);
6302 VkResult
radv_GetEventStatus(
6306 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6308 if (*event
->map
== 1)
6309 return VK_EVENT_SET
;
6310 return VK_EVENT_RESET
;
6313 VkResult
radv_SetEvent(
6317 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6323 VkResult
radv_ResetEvent(
6327 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6333 VkResult
radv_CreateBuffer(
6335 const VkBufferCreateInfo
* pCreateInfo
,
6336 const VkAllocationCallbacks
* pAllocator
,
6339 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6340 struct radv_buffer
*buffer
;
6342 if (pCreateInfo
->size
> RADV_MAX_MEMORY_ALLOCATION_SIZE
)
6343 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
6345 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
6347 buffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*buffer
), 8,
6348 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6350 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6352 vk_object_base_init(&device
->vk
, &buffer
->base
, VK_OBJECT_TYPE_BUFFER
);
6354 buffer
->size
= pCreateInfo
->size
;
6355 buffer
->usage
= pCreateInfo
->usage
;
6358 buffer
->flags
= pCreateInfo
->flags
;
6360 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
6361 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
6363 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
6364 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
6365 align64(buffer
->size
, 4096),
6366 4096, 0, RADEON_FLAG_VIRTUAL
,
6367 RADV_BO_PRIORITY_VIRTUAL
);
6369 vk_free2(&device
->vk
.alloc
, pAllocator
, buffer
);
6370 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6374 *pBuffer
= radv_buffer_to_handle(buffer
);
6379 void radv_DestroyBuffer(
6382 const VkAllocationCallbacks
* pAllocator
)
6384 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6385 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
6390 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
6391 device
->ws
->buffer_destroy(buffer
->bo
);
6393 vk_object_base_finish(&buffer
->base
);
6394 vk_free2(&device
->vk
.alloc
, pAllocator
, buffer
);
6397 VkDeviceAddress
radv_GetBufferDeviceAddress(
6399 const VkBufferDeviceAddressInfo
* pInfo
)
6401 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
6402 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
6406 uint64_t radv_GetBufferOpaqueCaptureAddress(VkDevice device
,
6407 const VkBufferDeviceAddressInfo
* pInfo
)
6412 uint64_t radv_GetDeviceMemoryOpaqueCaptureAddress(VkDevice device
,
6413 const VkDeviceMemoryOpaqueCaptureAddressInfo
* pInfo
)
6418 static inline unsigned
6419 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
6422 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
6424 return plane
->surface
.u
.legacy
.tiling_index
[level
];
6427 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
6429 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
6433 radv_init_dcc_control_reg(struct radv_device
*device
,
6434 struct radv_image_view
*iview
)
6436 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
6437 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
6438 unsigned max_compressed_block_size
;
6439 unsigned independent_128b_blocks
;
6440 unsigned independent_64b_blocks
;
6442 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
6445 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
6446 /* amdvlk: [min-compressed-block-size] should be set to 32 for
6447 * dGPU and 64 for APU because all of our APUs to date use
6448 * DIMMs which have a request granularity size of 64B while all
6449 * other chips have a 32B request size.
6451 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
6454 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6455 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
6456 independent_64b_blocks
= 0;
6457 independent_128b_blocks
= 1;
6459 independent_128b_blocks
= 0;
6461 if (iview
->image
->info
.samples
> 1) {
6462 if (iview
->image
->planes
[0].surface
.bpe
== 1)
6463 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
6464 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
6465 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
6468 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
6469 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
6470 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
6471 /* If this DCC image is potentially going to be used in texture
6472 * fetches, we need some special settings.
6474 independent_64b_blocks
= 1;
6475 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
6477 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
6478 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
6479 * big as possible for better compression state.
6481 independent_64b_blocks
= 0;
6482 max_compressed_block_size
= max_uncompressed_block_size
;
6486 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
6487 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
6488 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
6489 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
6490 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
6494 radv_initialise_color_surface(struct radv_device
*device
,
6495 struct radv_color_buffer_info
*cb
,
6496 struct radv_image_view
*iview
)
6498 const struct vk_format_description
*desc
;
6499 unsigned ntype
, format
, swap
, endian
;
6500 unsigned blend_clamp
= 0, blend_bypass
= 0;
6502 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
6503 const struct radeon_surf
*surf
= &plane
->surface
;
6505 desc
= vk_format_description(iview
->vk_format
);
6507 memset(cb
, 0, sizeof(*cb
));
6509 /* Intensity is implemented as Red, so treat it that way. */
6510 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
6512 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
6514 cb
->cb_color_base
= va
>> 8;
6516 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6517 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6518 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6519 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
6520 S_028EE0_CMASK_PIPE_ALIGNED(1) |
6521 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
6523 struct gfx9_surf_meta_flags meta
= {
6528 if (iview
->image
->dcc_offset
)
6529 meta
= surf
->u
.gfx9
.dcc
;
6531 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6532 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
6533 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
6534 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
6535 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
6538 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
6539 cb
->cb_color_base
|= surf
->tile_swizzle
;
6541 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
6542 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
6544 cb
->cb_color_base
+= level_info
->offset
>> 8;
6545 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
6546 cb
->cb_color_base
|= surf
->tile_swizzle
;
6548 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
6549 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
6550 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
6552 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
6553 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
6554 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
6556 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
6558 if (radv_image_has_fmask(iview
->image
)) {
6559 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
6560 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
6561 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
6562 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
6564 /* This must be set for fast clear to work without FMASK. */
6565 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
6566 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
6567 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
6568 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
6572 /* CMASK variables */
6573 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6574 va
+= iview
->image
->cmask_offset
;
6575 cb
->cb_color_cmask
= va
>> 8;
6577 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6578 va
+= iview
->image
->dcc_offset
;
6580 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
6581 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
6582 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
6584 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
6585 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
6587 cb
->cb_dcc_base
= va
>> 8;
6588 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
6590 /* GFX10 field has the same base shift as the GFX6 field. */
6591 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
6592 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
6593 S_028C6C_SLICE_MAX_GFX10(max_slice
);
6595 if (iview
->image
->info
.samples
> 1) {
6596 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
6598 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
6599 S_028C74_NUM_FRAGMENTS(log_samples
);
6602 if (radv_image_has_fmask(iview
->image
)) {
6603 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
6604 cb
->cb_color_fmask
= va
>> 8;
6605 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
6607 cb
->cb_color_fmask
= cb
->cb_color_base
;
6610 ntype
= radv_translate_color_numformat(iview
->vk_format
,
6612 vk_format_get_first_non_void_channel(iview
->vk_format
));
6613 format
= radv_translate_colorformat(iview
->vk_format
);
6614 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
6615 radv_finishme("Illegal color\n");
6616 swap
= radv_translate_colorswap(iview
->vk_format
, false);
6617 endian
= radv_colorformat_endian_swap(format
);
6619 /* blend clamp should be set for all NORM/SRGB types */
6620 if (ntype
== V_028C70_NUMBER_UNORM
||
6621 ntype
== V_028C70_NUMBER_SNORM
||
6622 ntype
== V_028C70_NUMBER_SRGB
)
6625 /* set blend bypass according to docs if SINT/UINT or
6626 8/24 COLOR variants */
6627 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
6628 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
6629 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
6634 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
6635 (format
== V_028C70_COLOR_8
||
6636 format
== V_028C70_COLOR_8_8
||
6637 format
== V_028C70_COLOR_8_8_8_8
))
6638 ->color_is_int8
= true;
6640 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
6641 S_028C70_COMP_SWAP(swap
) |
6642 S_028C70_BLEND_CLAMP(blend_clamp
) |
6643 S_028C70_BLEND_BYPASS(blend_bypass
) |
6644 S_028C70_SIMPLE_FLOAT(1) |
6645 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
6646 ntype
!= V_028C70_NUMBER_SNORM
&&
6647 ntype
!= V_028C70_NUMBER_SRGB
&&
6648 format
!= V_028C70_COLOR_8_24
&&
6649 format
!= V_028C70_COLOR_24_8
) |
6650 S_028C70_NUMBER_TYPE(ntype
) |
6651 S_028C70_ENDIAN(endian
);
6652 if (radv_image_has_fmask(iview
->image
)) {
6653 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
6654 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
6655 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
6656 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
6659 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
6660 /* Allow the texture block to read FMASK directly
6661 * without decompressing it. This bit must be cleared
6662 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
6663 * otherwise the operation doesn't happen.
6665 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
6667 /* Set CMASK into a tiling format that allows the
6668 * texture block to read it.
6670 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
6674 if (radv_image_has_cmask(iview
->image
) &&
6675 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
6676 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
6678 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
6679 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
6681 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
6683 /* This must be set for fast clear to work without FMASK. */
6684 if (!radv_image_has_fmask(iview
->image
) &&
6685 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
6686 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
6687 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
6690 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6691 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
6693 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
6694 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
6695 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
6696 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
6698 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6699 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
6701 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
6702 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
6703 S_028EE0_RESOURCE_LEVEL(1);
6705 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
6706 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
6707 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
6710 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
6711 S_028C68_MIP0_HEIGHT(height
- 1) |
6712 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
6717 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
6718 struct radv_image_view
*iview
)
6720 unsigned max_zplanes
= 0;
6722 assert(radv_image_is_tc_compat_htile(iview
->image
));
6724 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6725 /* Default value for 32-bit depth surfaces. */
6728 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
6729 iview
->image
->info
.samples
> 1)
6732 max_zplanes
= max_zplanes
+ 1;
6734 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
6735 /* Do not enable Z plane compression for 16-bit depth
6736 * surfaces because isn't supported on GFX8. Only
6737 * 32-bit depth surfaces are supported by the hardware.
6738 * This allows to maintain shader compatibility and to
6739 * reduce the number of depth decompressions.
6743 if (iview
->image
->info
.samples
<= 1)
6745 else if (iview
->image
->info
.samples
<= 4)
6756 radv_initialise_ds_surface(struct radv_device
*device
,
6757 struct radv_ds_buffer_info
*ds
,
6758 struct radv_image_view
*iview
)
6760 unsigned level
= iview
->base_mip
;
6761 unsigned format
, stencil_format
;
6762 uint64_t va
, s_offs
, z_offs
;
6763 bool stencil_only
= false;
6764 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
6765 const struct radeon_surf
*surf
= &plane
->surface
;
6767 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
6769 memset(ds
, 0, sizeof(*ds
));
6770 switch (iview
->image
->vk_format
) {
6771 case VK_FORMAT_D24_UNORM_S8_UINT
:
6772 case VK_FORMAT_X8_D24_UNORM_PACK32
:
6773 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
6774 ds
->offset_scale
= 2.0f
;
6776 case VK_FORMAT_D16_UNORM
:
6777 case VK_FORMAT_D16_UNORM_S8_UINT
:
6778 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
6779 ds
->offset_scale
= 4.0f
;
6781 case VK_FORMAT_D32_SFLOAT
:
6782 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
6783 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
6784 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
6785 ds
->offset_scale
= 1.0f
;
6787 case VK_FORMAT_S8_UINT
:
6788 stencil_only
= true;
6794 format
= radv_translate_dbformat(iview
->image
->vk_format
);
6795 stencil_format
= surf
->has_stencil
?
6796 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
6798 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
6799 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
6800 S_028008_SLICE_MAX(max_slice
);
6801 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6802 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
6803 S_028008_SLICE_MAX_HI(max_slice
>> 11);
6806 ds
->db_htile_data_base
= 0;
6807 ds
->db_htile_surface
= 0;
6809 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6810 s_offs
= z_offs
= va
;
6812 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6813 assert(surf
->u
.gfx9
.surf_offset
== 0);
6814 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
6816 ds
->db_z_info
= S_028038_FORMAT(format
) |
6817 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
6818 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6819 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
6820 S_028038_ZRANGE_PRECISION(1);
6821 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
6822 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
6824 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6825 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
6826 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
6829 ds
->db_depth_view
|= S_028008_MIPID(level
);
6830 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
6831 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
6833 if (radv_htile_enabled(iview
->image
, level
)) {
6834 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
6836 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6837 unsigned max_zplanes
=
6838 radv_calc_decompress_on_z_planes(device
, iview
);
6840 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6842 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6843 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
6844 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
6846 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
6847 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
6851 if (!surf
->has_stencil
)
6852 /* Use all of the htile_buffer for depth if there's no stencil. */
6853 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
6854 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6855 iview
->image
->htile_offset
;
6856 ds
->db_htile_data_base
= va
>> 8;
6857 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
6858 S_028ABC_PIPE_ALIGNED(1);
6860 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6861 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(1);
6865 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
6868 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
6870 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
6871 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
6873 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
6874 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
6875 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
6877 if (iview
->image
->info
.samples
> 1)
6878 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
6880 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
6881 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
6882 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
6883 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
6884 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
6885 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
6886 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
6887 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
6890 tile_mode
= stencil_tile_mode
;
6892 ds
->db_depth_info
|=
6893 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
6894 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
6895 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
6896 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
6897 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
6898 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
6899 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
6900 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
6902 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
6903 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
6904 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
6905 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
6907 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
6910 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
6911 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
6912 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
6914 if (radv_htile_enabled(iview
->image
, level
)) {
6915 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
6917 if (!surf
->has_stencil
&&
6918 !radv_image_is_tc_compat_htile(iview
->image
))
6919 /* Use all of the htile_buffer for depth if there's no stencil. */
6920 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
6922 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6923 iview
->image
->htile_offset
;
6924 ds
->db_htile_data_base
= va
>> 8;
6925 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
6927 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6928 unsigned max_zplanes
=
6929 radv_calc_decompress_on_z_planes(device
, iview
);
6931 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
6932 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6937 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
6938 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
6941 VkResult
radv_CreateFramebuffer(
6943 const VkFramebufferCreateInfo
* pCreateInfo
,
6944 const VkAllocationCallbacks
* pAllocator
,
6945 VkFramebuffer
* pFramebuffer
)
6947 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6948 struct radv_framebuffer
*framebuffer
;
6949 const VkFramebufferAttachmentsCreateInfo
*imageless_create_info
=
6950 vk_find_struct_const(pCreateInfo
->pNext
,
6951 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO
);
6953 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
6955 size_t size
= sizeof(*framebuffer
);
6956 if (!imageless_create_info
)
6957 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
6958 framebuffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
6959 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6960 if (framebuffer
== NULL
)
6961 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6963 vk_object_base_init(&device
->vk
, &framebuffer
->base
,
6964 VK_OBJECT_TYPE_FRAMEBUFFER
);
6966 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
6967 framebuffer
->width
= pCreateInfo
->width
;
6968 framebuffer
->height
= pCreateInfo
->height
;
6969 framebuffer
->layers
= pCreateInfo
->layers
;
6970 if (imageless_create_info
) {
6971 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
6972 const VkFramebufferAttachmentImageInfo
*attachment
=
6973 imageless_create_info
->pAttachmentImageInfos
+ i
;
6974 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
6975 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
6976 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
6979 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
6980 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
6981 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
6982 framebuffer
->attachments
[i
] = iview
;
6983 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
6984 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
6985 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
6989 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
6993 void radv_DestroyFramebuffer(
6996 const VkAllocationCallbacks
* pAllocator
)
6998 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6999 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
7003 vk_object_base_finish(&fb
->base
);
7004 vk_free2(&device
->vk
.alloc
, pAllocator
, fb
);
7007 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
7009 switch (address_mode
) {
7010 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
7011 return V_008F30_SQ_TEX_WRAP
;
7012 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
7013 return V_008F30_SQ_TEX_MIRROR
;
7014 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
7015 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
7016 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
7017 return V_008F30_SQ_TEX_CLAMP_BORDER
;
7018 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
7019 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
7021 unreachable("illegal tex wrap mode");
7027 radv_tex_compare(VkCompareOp op
)
7030 case VK_COMPARE_OP_NEVER
:
7031 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
7032 case VK_COMPARE_OP_LESS
:
7033 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
7034 case VK_COMPARE_OP_EQUAL
:
7035 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
7036 case VK_COMPARE_OP_LESS_OR_EQUAL
:
7037 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
7038 case VK_COMPARE_OP_GREATER
:
7039 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
7040 case VK_COMPARE_OP_NOT_EQUAL
:
7041 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
7042 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
7043 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
7044 case VK_COMPARE_OP_ALWAYS
:
7045 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
7047 unreachable("illegal compare mode");
7053 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
7056 case VK_FILTER_NEAREST
:
7057 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
7058 V_008F38_SQ_TEX_XY_FILTER_POINT
);
7059 case VK_FILTER_LINEAR
:
7060 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
7061 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
7062 case VK_FILTER_CUBIC_IMG
:
7064 fprintf(stderr
, "illegal texture filter");
7070 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
7073 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
7074 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
7075 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
7076 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
7078 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
7083 radv_tex_bordercolor(VkBorderColor bcolor
)
7086 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
7087 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
7088 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
7089 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
7090 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
7091 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
7092 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
7093 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
7094 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
7102 radv_tex_aniso_filter(unsigned filter
)
7116 radv_tex_filter_mode(VkSamplerReductionMode mode
)
7119 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
7120 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
7121 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
7122 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
7123 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
7124 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
7132 radv_get_max_anisotropy(struct radv_device
*device
,
7133 const VkSamplerCreateInfo
*pCreateInfo
)
7135 if (device
->force_aniso
>= 0)
7136 return device
->force_aniso
;
7138 if (pCreateInfo
->anisotropyEnable
&&
7139 pCreateInfo
->maxAnisotropy
> 1.0f
)
7140 return (uint32_t)pCreateInfo
->maxAnisotropy
;
7145 static inline int S_FIXED(float value
, unsigned frac_bits
)
7147 return value
* (1 << frac_bits
);
7151 radv_init_sampler(struct radv_device
*device
,
7152 struct radv_sampler
*sampler
,
7153 const VkSamplerCreateInfo
*pCreateInfo
)
7155 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
7156 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
7157 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
7158 device
->physical_device
->rad_info
.chip_class
== GFX9
;
7159 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
7160 unsigned depth_compare_func
= V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
7161 bool trunc_coord
= pCreateInfo
->minFilter
== VK_FILTER_NEAREST
&& pCreateInfo
->magFilter
== VK_FILTER_NEAREST
;
7163 const struct VkSamplerReductionModeCreateInfo
*sampler_reduction
=
7164 vk_find_struct_const(pCreateInfo
->pNext
,
7165 SAMPLER_REDUCTION_MODE_CREATE_INFO
);
7166 if (sampler_reduction
)
7167 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
7169 if (pCreateInfo
->compareEnable
)
7170 depth_compare_func
= radv_tex_compare(pCreateInfo
->compareOp
);
7172 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
7173 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
7174 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
7175 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
7176 S_008F30_DEPTH_COMPARE_FUNC(depth_compare_func
) |
7177 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
7178 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
7179 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
7180 S_008F30_DISABLE_CUBE_WRAP(0) |
7181 S_008F30_COMPAT_MODE(compat_mode
) |
7182 S_008F30_FILTER_MODE(filter_mode
) |
7183 S_008F30_TRUNC_COORD(trunc_coord
));
7184 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
7185 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
7186 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
7187 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
7188 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
7189 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
7190 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
7191 S_008F38_MIP_POINT_PRECLAMP(0));
7192 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
7193 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
7195 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
7196 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
7198 sampler
->state
[2] |=
7199 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
7200 S_008F38_FILTER_PREC_FIX(1) |
7201 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
7205 VkResult
radv_CreateSampler(
7207 const VkSamplerCreateInfo
* pCreateInfo
,
7208 const VkAllocationCallbacks
* pAllocator
,
7209 VkSampler
* pSampler
)
7211 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7212 struct radv_sampler
*sampler
;
7214 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
7215 vk_find_struct_const(pCreateInfo
->pNext
,
7216 SAMPLER_YCBCR_CONVERSION_INFO
);
7218 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
7220 sampler
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*sampler
), 8,
7221 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
7223 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
7225 vk_object_base_init(&device
->vk
, &sampler
->base
,
7226 VK_OBJECT_TYPE_SAMPLER
);
7228 radv_init_sampler(device
, sampler
, pCreateInfo
);
7230 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
7231 *pSampler
= radv_sampler_to_handle(sampler
);
7236 void radv_DestroySampler(
7239 const VkAllocationCallbacks
* pAllocator
)
7241 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7242 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
7246 vk_object_base_finish(&sampler
->base
);
7247 vk_free2(&device
->vk
.alloc
, pAllocator
, sampler
);
7250 /* vk_icd.h does not declare this function, so we declare it here to
7251 * suppress Wmissing-prototypes.
7253 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
7254 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
7256 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
7257 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
7259 /* For the full details on loader interface versioning, see
7260 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
7261 * What follows is a condensed summary, to help you navigate the large and
7262 * confusing official doc.
7264 * - Loader interface v0 is incompatible with later versions. We don't
7267 * - In loader interface v1:
7268 * - The first ICD entrypoint called by the loader is
7269 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
7271 * - The ICD must statically expose no other Vulkan symbol unless it is
7272 * linked with -Bsymbolic.
7273 * - Each dispatchable Vulkan handle created by the ICD must be
7274 * a pointer to a struct whose first member is VK_LOADER_DATA. The
7275 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
7276 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
7277 * vkDestroySurfaceKHR(). The ICD must be capable of working with
7278 * such loader-managed surfaces.
7280 * - Loader interface v2 differs from v1 in:
7281 * - The first ICD entrypoint called by the loader is
7282 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
7283 * statically expose this entrypoint.
7285 * - Loader interface v3 differs from v2 in:
7286 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
7287 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
7288 * because the loader no longer does so.
7290 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
7294 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
7295 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
7298 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7299 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
7301 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
7303 /* At the moment, we support only the below handle types. */
7304 assert(pGetFdInfo
->handleType
==
7305 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
7306 pGetFdInfo
->handleType
==
7307 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
7309 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
7311 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
7315 static uint32_t radv_compute_valid_memory_types_attempt(struct radv_physical_device
*dev
,
7316 enum radeon_bo_domain domains
,
7317 enum radeon_bo_flag flags
,
7318 enum radeon_bo_flag ignore_flags
)
7320 /* Don't count GTT/CPU as relevant:
7322 * - We're not fully consistent between the two.
7323 * - Sometimes VRAM gets VRAM|GTT.
7325 const enum radeon_bo_domain relevant_domains
= RADEON_DOMAIN_VRAM
|
7329 for (unsigned i
= 0; i
< dev
->memory_properties
.memoryTypeCount
; ++i
) {
7330 if ((domains
& relevant_domains
) != (dev
->memory_domains
[i
] & relevant_domains
))
7333 if ((flags
& ~ignore_flags
) != (dev
->memory_flags
[i
] & ~ignore_flags
))
7342 static uint32_t radv_compute_valid_memory_types(struct radv_physical_device
*dev
,
7343 enum radeon_bo_domain domains
,
7344 enum radeon_bo_flag flags
)
7346 enum radeon_bo_flag ignore_flags
= ~(RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_GTT_WC
);
7347 uint32_t bits
= radv_compute_valid_memory_types_attempt(dev
, domains
, flags
, ignore_flags
);
7350 ignore_flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
7351 bits
= radv_compute_valid_memory_types_attempt(dev
, domains
, flags
, ignore_flags
);
7356 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
7357 VkExternalMemoryHandleTypeFlagBits handleType
,
7359 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
7361 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7363 switch (handleType
) {
7364 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
: {
7365 enum radeon_bo_domain domains
;
7366 enum radeon_bo_flag flags
;
7367 if (!device
->ws
->buffer_get_flags_from_fd(device
->ws
, fd
, &domains
, &flags
))
7368 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7370 pMemoryFdProperties
->memoryTypeBits
= radv_compute_valid_memory_types(device
->physical_device
, domains
, flags
);
7374 /* The valid usage section for this function says:
7376 * "handleType must not be one of the handle types defined as
7379 * So opaque handle types fall into the default "unsupported" case.
7381 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7385 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
7389 uint32_t syncobj_handle
= 0;
7390 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
7392 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7395 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
7397 *syncobj
= syncobj_handle
;
7403 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
7407 /* If we create a syncobj we do it locally so that if we have an error, we don't
7408 * leave a syncobj in an undetermined state in the fence. */
7409 uint32_t syncobj_handle
= *syncobj
;
7410 if (!syncobj_handle
) {
7411 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
7413 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7418 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
7420 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
7422 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7425 *syncobj
= syncobj_handle
;
7432 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
7433 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
7435 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7436 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
7438 struct radv_semaphore_part
*dst
= NULL
;
7440 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
7441 dst
= &sem
->temporary
;
7443 dst
= &sem
->permanent
;
7446 uint32_t syncobj
= dst
->kind
== RADV_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
7448 switch(pImportSemaphoreFdInfo
->handleType
) {
7449 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7450 result
= radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
7452 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
7453 result
= radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
7456 unreachable("Unhandled semaphore handle type");
7459 if (result
== VK_SUCCESS
) {
7460 dst
->syncobj
= syncobj
;
7461 dst
->kind
= RADV_SEMAPHORE_SYNCOBJ
;
7467 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
7468 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
7471 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7472 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
7474 uint32_t syncobj_handle
;
7476 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
7477 assert(sem
->temporary
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
7478 syncobj_handle
= sem
->temporary
.syncobj
;
7480 assert(sem
->permanent
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
7481 syncobj_handle
= sem
->permanent
.syncobj
;
7484 switch(pGetFdInfo
->handleType
) {
7485 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7486 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
7488 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
7489 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
7491 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
7492 radv_destroy_semaphore_part(device
, &sem
->temporary
);
7494 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
7499 unreachable("Unhandled semaphore handle type");
7503 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7507 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
7508 VkPhysicalDevice physicalDevice
,
7509 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
7510 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
7512 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
7513 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pExternalSemaphoreInfo
->pNext
, NULL
);
7515 if (type
== VK_SEMAPHORE_TYPE_TIMELINE
) {
7516 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
7517 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
7518 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
7520 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
7521 } else if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
7522 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
7523 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
7524 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
7525 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
7526 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
7527 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7528 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
7529 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
7530 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
7531 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
7532 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7534 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
7535 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
7536 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
7540 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
7541 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
7543 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7544 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
7545 uint32_t *syncobj_dst
= NULL
;
7548 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
7549 syncobj_dst
= &fence
->temp_syncobj
;
7551 syncobj_dst
= &fence
->syncobj
;
7554 switch(pImportFenceFdInfo
->handleType
) {
7555 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7556 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
7557 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
7558 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
7560 unreachable("Unhandled fence handle type");
7564 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
7565 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
7568 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7569 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
7571 uint32_t syncobj_handle
;
7573 if (fence
->temp_syncobj
)
7574 syncobj_handle
= fence
->temp_syncobj
;
7576 syncobj_handle
= fence
->syncobj
;
7578 switch(pGetFdInfo
->handleType
) {
7579 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7580 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
7582 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
7583 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
7585 if (fence
->temp_syncobj
) {
7586 close (fence
->temp_syncobj
);
7587 fence
->temp_syncobj
= 0;
7589 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
7594 unreachable("Unhandled fence handle type");
7598 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7602 void radv_GetPhysicalDeviceExternalFenceProperties(
7603 VkPhysicalDevice physicalDevice
,
7604 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
7605 VkExternalFenceProperties
*pExternalFenceProperties
)
7607 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
7609 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
7610 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
7611 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
7612 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
7613 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
7614 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
7615 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7617 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
7618 pExternalFenceProperties
->compatibleHandleTypes
= 0;
7619 pExternalFenceProperties
->externalFenceFeatures
= 0;
7624 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
7625 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
7626 const VkAllocationCallbacks
* pAllocator
,
7627 VkDebugReportCallbackEXT
* pCallback
)
7629 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7630 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
7631 pCreateInfo
, pAllocator
, &instance
->alloc
,
7636 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
7637 VkDebugReportCallbackEXT _callback
,
7638 const VkAllocationCallbacks
* pAllocator
)
7640 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7641 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
7642 _callback
, pAllocator
, &instance
->alloc
);
7646 radv_DebugReportMessageEXT(VkInstance _instance
,
7647 VkDebugReportFlagsEXT flags
,
7648 VkDebugReportObjectTypeEXT objectType
,
7651 int32_t messageCode
,
7652 const char* pLayerPrefix
,
7653 const char* pMessage
)
7655 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7656 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
7657 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
7661 radv_GetDeviceGroupPeerMemoryFeatures(
7664 uint32_t localDeviceIndex
,
7665 uint32_t remoteDeviceIndex
,
7666 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
7668 assert(localDeviceIndex
== remoteDeviceIndex
);
7670 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
7671 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
7672 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
7673 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
7676 static const VkTimeDomainEXT radv_time_domains
[] = {
7677 VK_TIME_DOMAIN_DEVICE_EXT
,
7678 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
7679 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
7682 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
7683 VkPhysicalDevice physicalDevice
,
7684 uint32_t *pTimeDomainCount
,
7685 VkTimeDomainEXT
*pTimeDomains
)
7688 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
7690 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
7691 vk_outarray_append(&out
, i
) {
7692 *i
= radv_time_domains
[d
];
7696 return vk_outarray_status(&out
);
7700 radv_clock_gettime(clockid_t clock_id
)
7702 struct timespec current
;
7705 ret
= clock_gettime(clock_id
, ¤t
);
7706 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
7707 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
7711 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
7714 VkResult
radv_GetCalibratedTimestampsEXT(
7716 uint32_t timestampCount
,
7717 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
7718 uint64_t *pTimestamps
,
7719 uint64_t *pMaxDeviation
)
7721 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7722 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
7724 uint64_t begin
, end
;
7725 uint64_t max_clock_period
= 0;
7727 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
7729 for (d
= 0; d
< timestampCount
; d
++) {
7730 switch (pTimestampInfos
[d
].timeDomain
) {
7731 case VK_TIME_DOMAIN_DEVICE_EXT
:
7732 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
7734 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
7735 max_clock_period
= MAX2(max_clock_period
, device_period
);
7737 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
7738 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
7739 max_clock_period
= MAX2(max_clock_period
, 1);
7742 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
7743 pTimestamps
[d
] = begin
;
7751 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
7754 * The maximum deviation is the sum of the interval over which we
7755 * perform the sampling and the maximum period of any sampled
7756 * clock. That's because the maximum skew between any two sampled
7757 * clock edges is when the sampled clock with the largest period is
7758 * sampled at the end of that period but right at the beginning of the
7759 * sampling interval and some other clock is sampled right at the
7760 * begining of its sampling period and right at the end of the
7761 * sampling interval. Let's assume the GPU has the longest clock
7762 * period and that the application is sampling GPU and monotonic:
7765 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
7766 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
7770 * GPU -----_____-----_____-----_____-----_____
7773 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
7774 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
7776 * Interval <----------------->
7777 * Deviation <-------------------------->
7781 * m = read(monotonic) 2
7784 * We round the sample interval up by one tick to cover sampling error
7785 * in the interval clock
7788 uint64_t sample_interval
= end
- begin
+ 1;
7790 *pMaxDeviation
= sample_interval
+ max_clock_period
;
7795 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
7796 VkPhysicalDevice physicalDevice
,
7797 VkSampleCountFlagBits samples
,
7798 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
7800 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
7801 VK_SAMPLE_COUNT_4_BIT
|
7802 VK_SAMPLE_COUNT_8_BIT
)) {
7803 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
7805 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };
7809 VkResult
radv_CreatePrivateDataSlotEXT(
7811 const VkPrivateDataSlotCreateInfoEXT
* pCreateInfo
,
7812 const VkAllocationCallbacks
* pAllocator
,
7813 VkPrivateDataSlotEXT
* pPrivateDataSlot
)
7815 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7816 return vk_private_data_slot_create(&device
->vk
, pCreateInfo
, pAllocator
,
7820 void radv_DestroyPrivateDataSlotEXT(
7822 VkPrivateDataSlotEXT privateDataSlot
,
7823 const VkAllocationCallbacks
* pAllocator
)
7825 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7826 vk_private_data_slot_destroy(&device
->vk
, privateDataSlot
, pAllocator
);
7829 VkResult
radv_SetPrivateDataEXT(
7831 VkObjectType objectType
,
7832 uint64_t objectHandle
,
7833 VkPrivateDataSlotEXT privateDataSlot
,
7836 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7837 return vk_object_base_set_private_data(&device
->vk
, objectType
,
7838 objectHandle
, privateDataSlot
,
7842 void radv_GetPrivateDataEXT(
7844 VkObjectType objectType
,
7845 uint64_t objectHandle
,
7846 VkPrivateDataSlotEXT privateDataSlot
,
7849 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7850 vk_object_base_get_private_data(&device
->vk
, objectType
, objectHandle
,
7851 privateDataSlot
, pData
);