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
);
454 radv_physical_device_destroy(struct radv_physical_device
*device
)
456 radv_finish_wsi(device
);
457 device
->ws
->destroy(device
->ws
);
458 disk_cache_destroy(device
->disk_cache
);
459 close(device
->local_fd
);
460 if (device
->master_fd
!= -1)
461 close(device
->master_fd
);
462 vk_free(&device
->instance
->alloc
, device
);
466 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
467 VkSystemAllocationScope allocationScope
)
473 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
474 size_t align
, VkSystemAllocationScope allocationScope
)
476 return realloc(pOriginal
, size
);
480 default_free_func(void *pUserData
, void *pMemory
)
485 static const VkAllocationCallbacks default_alloc
= {
487 .pfnAllocation
= default_alloc_func
,
488 .pfnReallocation
= default_realloc_func
,
489 .pfnFree
= default_free_func
,
492 static const struct debug_control radv_debug_options
[] = {
493 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
494 {"nodcc", RADV_DEBUG_NO_DCC
},
495 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
496 {"nocache", RADV_DEBUG_NO_CACHE
},
497 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
498 {"nohiz", RADV_DEBUG_NO_HIZ
},
499 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
500 {"allbos", RADV_DEBUG_ALL_BOS
},
501 {"noibs", RADV_DEBUG_NO_IBS
},
502 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
503 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
504 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
505 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
506 {"preoptir", RADV_DEBUG_PREOPTIR
},
507 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
508 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
509 {"info", RADV_DEBUG_INFO
},
510 {"errors", RADV_DEBUG_ERRORS
},
511 {"startup", RADV_DEBUG_STARTUP
},
512 {"checkir", RADV_DEBUG_CHECKIR
},
513 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
514 {"nobinning", RADV_DEBUG_NOBINNING
},
515 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
516 {"nongg", RADV_DEBUG_NO_NGG
},
517 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
518 {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS
},
519 {"metashaders", RADV_DEBUG_DUMP_META_SHADERS
},
520 {"nomemorycache", RADV_DEBUG_NO_MEMORY_CACHE
},
525 radv_get_debug_option_name(int id
)
527 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
528 return radv_debug_options
[id
].string
;
531 static const struct debug_control radv_perftest_options
[] = {
532 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
533 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
534 {"bolist", RADV_PERFTEST_BO_LIST
},
535 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
536 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
537 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
538 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
539 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
540 {"dfsm", RADV_PERFTEST_DFSM
},
541 {"aco", RADV_PERFTEST_ACO
},
546 radv_get_perftest_option_name(int id
)
548 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
549 return radv_perftest_options
[id
].string
;
553 radv_handle_per_app_options(struct radv_instance
*instance
,
554 const VkApplicationInfo
*info
)
556 const char *name
= info
? info
->pApplicationName
: NULL
;
561 if (!strcmp(name
, "DOOM_VFR")) {
562 /* Work around a Doom VFR game bug */
563 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
564 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
565 /* Workaround for a WaW hazard when LLVM moves/merges
566 * load/store memory operations.
567 * See https://reviews.llvm.org/D61313
569 if (LLVM_VERSION_MAJOR
< 9)
570 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
571 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
572 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
) &&
573 !(instance
->perftest_flags
& RADV_PERFTEST_ACO
)) {
574 /* Force enable VK_AMD_shader_ballot because it looks
575 * safe and it gives a nice boost (+20% on Vega 56 at
576 * this time). It also prevents corruption on LLVM.
578 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
580 } else if (!strcmp(name
, "Fledge")) {
582 * Zero VRAM for "The Surge 2"
584 * This avoid a hang when when rendering any level. Likely
585 * uninitialized data in an indirect draw.
587 instance
->debug_flags
|= RADV_DEBUG_ZERO_VRAM
;
588 } else if (!strcmp(name
, "No Man's Sky")) {
589 /* Work around a NMS game bug */
590 instance
->debug_flags
|= RADV_DEBUG_DISCARD_TO_DEMOTE
;
594 static const char radv_dri_options_xml
[] =
596 DRI_CONF_SECTION_PERFORMANCE
597 DRI_CONF_ADAPTIVE_SYNC("true")
598 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
599 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
600 DRI_CONF_RADV_REPORT_LLVM9_VERSION_STRING("false")
603 DRI_CONF_SECTION_DEBUG
604 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
608 static void radv_init_dri_options(struct radv_instance
*instance
)
610 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
611 driParseConfigFiles(&instance
->dri_options
,
612 &instance
->available_dri_options
,
614 instance
->engineName
,
615 instance
->engineVersion
);
618 VkResult
radv_CreateInstance(
619 const VkInstanceCreateInfo
* pCreateInfo
,
620 const VkAllocationCallbacks
* pAllocator
,
621 VkInstance
* pInstance
)
623 struct radv_instance
*instance
;
626 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
627 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
629 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
631 vk_object_base_init(NULL
, &instance
->base
, VK_OBJECT_TYPE_INSTANCE
);
634 instance
->alloc
= *pAllocator
;
636 instance
->alloc
= default_alloc
;
638 if (pCreateInfo
->pApplicationInfo
) {
639 const VkApplicationInfo
*app
= pCreateInfo
->pApplicationInfo
;
641 instance
->engineName
=
642 vk_strdup(&instance
->alloc
, app
->pEngineName
,
643 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
644 instance
->engineVersion
= app
->engineVersion
;
645 instance
->apiVersion
= app
->apiVersion
;
648 if (instance
->apiVersion
== 0)
649 instance
->apiVersion
= VK_API_VERSION_1_0
;
651 /* Get secure compile thread count. NOTE: We cap this at 32 */
652 #define MAX_SC_PROCS 32
653 char *num_sc_threads
= getenv("RADV_SECURE_COMPILE_THREADS");
655 instance
->num_sc_threads
= MIN2(strtoul(num_sc_threads
, NULL
, 10), MAX_SC_PROCS
);
657 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
660 /* Disable memory cache when secure compile is set */
661 if (radv_device_use_secure_compile(instance
))
662 instance
->debug_flags
|= RADV_DEBUG_NO_MEMORY_CACHE
;
664 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
665 radv_perftest_options
);
667 if (instance
->perftest_flags
& RADV_PERFTEST_ACO
)
668 fprintf(stderr
, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
670 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
671 radv_logi("Created an instance");
673 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
675 for (idx
= 0; idx
< RADV_INSTANCE_EXTENSION_COUNT
; idx
++) {
676 if (!strcmp(pCreateInfo
->ppEnabledExtensionNames
[i
],
677 radv_instance_extensions
[idx
].extensionName
))
681 if (idx
>= RADV_INSTANCE_EXTENSION_COUNT
||
682 !radv_instance_extensions_supported
.extensions
[idx
]) {
683 vk_free2(&default_alloc
, pAllocator
, instance
);
684 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
687 instance
->enabled_extensions
.extensions
[idx
] = true;
690 bool unchecked
= instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
;
692 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->dispatch
.entrypoints
); i
++) {
693 /* Vulkan requires that entrypoints for extensions which have
694 * not been enabled must not be advertised.
697 !radv_instance_entrypoint_is_enabled(i
, instance
->apiVersion
,
698 &instance
->enabled_extensions
)) {
699 instance
->dispatch
.entrypoints
[i
] = NULL
;
701 instance
->dispatch
.entrypoints
[i
] =
702 radv_instance_dispatch_table
.entrypoints
[i
];
706 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->physical_device_dispatch
.entrypoints
); i
++) {
707 /* Vulkan requires that entrypoints for extensions which have
708 * not been enabled must not be advertised.
711 !radv_physical_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
712 &instance
->enabled_extensions
)) {
713 instance
->physical_device_dispatch
.entrypoints
[i
] = NULL
;
715 instance
->physical_device_dispatch
.entrypoints
[i
] =
716 radv_physical_device_dispatch_table
.entrypoints
[i
];
720 for (unsigned i
= 0; i
< ARRAY_SIZE(instance
->device_dispatch
.entrypoints
); i
++) {
721 /* Vulkan requires that entrypoints for extensions which have
722 * not been enabled must not be advertised.
725 !radv_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
726 &instance
->enabled_extensions
, NULL
)) {
727 instance
->device_dispatch
.entrypoints
[i
] = NULL
;
729 instance
->device_dispatch
.entrypoints
[i
] =
730 radv_device_dispatch_table
.entrypoints
[i
];
734 instance
->physical_devices_enumerated
= false;
735 list_inithead(&instance
->physical_devices
);
737 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
738 if (result
!= VK_SUCCESS
) {
739 vk_free2(&default_alloc
, pAllocator
, instance
);
740 return vk_error(instance
, result
);
743 glsl_type_singleton_init_or_ref();
745 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
747 radv_init_dri_options(instance
);
748 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
750 *pInstance
= radv_instance_to_handle(instance
);
755 void radv_DestroyInstance(
756 VkInstance _instance
,
757 const VkAllocationCallbacks
* pAllocator
)
759 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
764 list_for_each_entry_safe(struct radv_physical_device
, pdevice
,
765 &instance
->physical_devices
, link
) {
766 radv_physical_device_destroy(pdevice
);
769 vk_free(&instance
->alloc
, instance
->engineName
);
771 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
773 glsl_type_singleton_decref();
775 driDestroyOptionCache(&instance
->dri_options
);
776 driDestroyOptionInfo(&instance
->available_dri_options
);
778 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
780 vk_object_base_finish(&instance
->base
);
781 vk_free(&instance
->alloc
, instance
);
785 radv_enumerate_physical_devices(struct radv_instance
*instance
)
787 if (instance
->physical_devices_enumerated
)
790 instance
->physical_devices_enumerated
= true;
792 /* TODO: Check for more devices ? */
793 drmDevicePtr devices
[8];
794 VkResult result
= VK_SUCCESS
;
797 if (getenv("RADV_FORCE_FAMILY")) {
798 /* When RADV_FORCE_FAMILY is set, the driver creates a nul
799 * device that allows to test the compiler without having an
802 struct radv_physical_device
*pdevice
;
804 result
= radv_physical_device_try_create(instance
, NULL
, &pdevice
);
805 if (result
!= VK_SUCCESS
)
808 list_addtail(&pdevice
->link
, &instance
->physical_devices
);
812 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
814 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
815 radv_logi("Found %d drm nodes", max_devices
);
818 return vk_error(instance
, VK_SUCCESS
);
820 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
821 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
822 devices
[i
]->bustype
== DRM_BUS_PCI
&&
823 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
825 struct radv_physical_device
*pdevice
;
826 result
= radv_physical_device_try_create(instance
, devices
[i
],
828 /* Incompatible DRM device, skip. */
829 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
834 /* Error creating the physical device, report the error. */
835 if (result
!= VK_SUCCESS
)
838 list_addtail(&pdevice
->link
, &instance
->physical_devices
);
841 drmFreeDevices(devices
, max_devices
);
843 /* If we successfully enumerated any devices, call it success */
847 VkResult
radv_EnumeratePhysicalDevices(
848 VkInstance _instance
,
849 uint32_t* pPhysicalDeviceCount
,
850 VkPhysicalDevice
* pPhysicalDevices
)
852 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
853 VK_OUTARRAY_MAKE(out
, pPhysicalDevices
, pPhysicalDeviceCount
);
855 VkResult result
= radv_enumerate_physical_devices(instance
);
856 if (result
!= VK_SUCCESS
)
859 list_for_each_entry(struct radv_physical_device
, pdevice
,
860 &instance
->physical_devices
, link
) {
861 vk_outarray_append(&out
, i
) {
862 *i
= radv_physical_device_to_handle(pdevice
);
866 return vk_outarray_status(&out
);
869 VkResult
radv_EnumeratePhysicalDeviceGroups(
870 VkInstance _instance
,
871 uint32_t* pPhysicalDeviceGroupCount
,
872 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
874 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
875 VK_OUTARRAY_MAKE(out
, pPhysicalDeviceGroupProperties
,
876 pPhysicalDeviceGroupCount
);
878 VkResult result
= radv_enumerate_physical_devices(instance
);
879 if (result
!= VK_SUCCESS
)
882 list_for_each_entry(struct radv_physical_device
, pdevice
,
883 &instance
->physical_devices
, link
) {
884 vk_outarray_append(&out
, p
) {
885 p
->physicalDeviceCount
= 1;
886 memset(p
->physicalDevices
, 0, sizeof(p
->physicalDevices
));
887 p
->physicalDevices
[0] = radv_physical_device_to_handle(pdevice
);
888 p
->subsetAllocation
= false;
892 return vk_outarray_status(&out
);
895 void radv_GetPhysicalDeviceFeatures(
896 VkPhysicalDevice physicalDevice
,
897 VkPhysicalDeviceFeatures
* pFeatures
)
899 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
900 memset(pFeatures
, 0, sizeof(*pFeatures
));
902 *pFeatures
= (VkPhysicalDeviceFeatures
) {
903 .robustBufferAccess
= true,
904 .fullDrawIndexUint32
= true,
905 .imageCubeArray
= true,
906 .independentBlend
= true,
907 .geometryShader
= true,
908 .tessellationShader
= true,
909 .sampleRateShading
= true,
910 .dualSrcBlend
= true,
912 .multiDrawIndirect
= true,
913 .drawIndirectFirstInstance
= true,
915 .depthBiasClamp
= true,
916 .fillModeNonSolid
= true,
921 .multiViewport
= true,
922 .samplerAnisotropy
= true,
923 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
924 .textureCompressionASTC_LDR
= false,
925 .textureCompressionBC
= true,
926 .occlusionQueryPrecise
= true,
927 .pipelineStatisticsQuery
= true,
928 .vertexPipelineStoresAndAtomics
= true,
929 .fragmentStoresAndAtomics
= true,
930 .shaderTessellationAndGeometryPointSize
= true,
931 .shaderImageGatherExtended
= true,
932 .shaderStorageImageExtendedFormats
= true,
933 .shaderStorageImageMultisample
= true,
934 .shaderUniformBufferArrayDynamicIndexing
= true,
935 .shaderSampledImageArrayDynamicIndexing
= true,
936 .shaderStorageBufferArrayDynamicIndexing
= true,
937 .shaderStorageImageArrayDynamicIndexing
= true,
938 .shaderStorageImageReadWithoutFormat
= true,
939 .shaderStorageImageWriteWithoutFormat
= true,
940 .shaderClipDistance
= true,
941 .shaderCullDistance
= true,
942 .shaderFloat64
= true,
944 .shaderInt16
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
,
945 .sparseBinding
= true,
946 .variableMultisampleRate
= true,
947 .shaderResourceMinLod
= true,
948 .inheritedQueries
= true,
953 radv_get_physical_device_features_1_1(struct radv_physical_device
*pdevice
,
954 VkPhysicalDeviceVulkan11Features
*f
)
956 assert(f
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
);
958 f
->storageBuffer16BitAccess
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
959 f
->uniformAndStorageBuffer16BitAccess
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
960 f
->storagePushConstant16
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
961 f
->storageInputOutput16
= pdevice
->rad_info
.has_packed_math_16bit
&& (LLVM_VERSION_MAJOR
>= 9 || pdevice
->use_aco
);
963 f
->multiviewGeometryShader
= true;
964 f
->multiviewTessellationShader
= true;
965 f
->variablePointersStorageBuffer
= true;
966 f
->variablePointers
= true;
967 f
->protectedMemory
= false;
968 f
->samplerYcbcrConversion
= true;
969 f
->shaderDrawParameters
= true;
973 radv_get_physical_device_features_1_2(struct radv_physical_device
*pdevice
,
974 VkPhysicalDeviceVulkan12Features
*f
)
976 assert(f
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
);
978 f
->samplerMirrorClampToEdge
= true;
979 f
->drawIndirectCount
= true;
980 f
->storageBuffer8BitAccess
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
981 f
->uniformAndStorageBuffer8BitAccess
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
982 f
->storagePushConstant8
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
983 f
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
984 f
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
985 f
->shaderFloat16
= pdevice
->rad_info
.has_packed_math_16bit
&& !pdevice
->use_aco
;
986 f
->shaderInt8
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
988 f
->descriptorIndexing
= true;
989 f
->shaderInputAttachmentArrayDynamicIndexing
= true;
990 f
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
991 f
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
992 f
->shaderUniformBufferArrayNonUniformIndexing
= true;
993 f
->shaderSampledImageArrayNonUniformIndexing
= true;
994 f
->shaderStorageBufferArrayNonUniformIndexing
= true;
995 f
->shaderStorageImageArrayNonUniformIndexing
= true;
996 f
->shaderInputAttachmentArrayNonUniformIndexing
= true;
997 f
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
998 f
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
999 f
->descriptorBindingUniformBufferUpdateAfterBind
= true;
1000 f
->descriptorBindingSampledImageUpdateAfterBind
= true;
1001 f
->descriptorBindingStorageImageUpdateAfterBind
= true;
1002 f
->descriptorBindingStorageBufferUpdateAfterBind
= true;
1003 f
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
1004 f
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
1005 f
->descriptorBindingUpdateUnusedWhilePending
= true;
1006 f
->descriptorBindingPartiallyBound
= true;
1007 f
->descriptorBindingVariableDescriptorCount
= true;
1008 f
->runtimeDescriptorArray
= true;
1010 f
->samplerFilterMinmax
= true;
1011 f
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
1012 f
->imagelessFramebuffer
= true;
1013 f
->uniformBufferStandardLayout
= true;
1014 f
->shaderSubgroupExtendedTypes
= !pdevice
->use_aco
|| pdevice
->rad_info
.chip_class
>= GFX8
;
1015 f
->separateDepthStencilLayouts
= true;
1016 f
->hostQueryReset
= true;
1017 f
->timelineSemaphore
= pdevice
->rad_info
.has_syncobj_wait_for_submit
;
1018 f
->bufferDeviceAddress
= true;
1019 f
->bufferDeviceAddressCaptureReplay
= false;
1020 f
->bufferDeviceAddressMultiDevice
= false;
1021 f
->vulkanMemoryModel
= false;
1022 f
->vulkanMemoryModelDeviceScope
= false;
1023 f
->vulkanMemoryModelAvailabilityVisibilityChains
= false;
1024 f
->shaderOutputViewportIndex
= true;
1025 f
->shaderOutputLayer
= true;
1026 f
->subgroupBroadcastDynamicId
= true;
1029 void radv_GetPhysicalDeviceFeatures2(
1030 VkPhysicalDevice physicalDevice
,
1031 VkPhysicalDeviceFeatures2
*pFeatures
)
1033 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1034 radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1036 VkPhysicalDeviceVulkan11Features core_1_1
= {
1037 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
,
1039 radv_get_physical_device_features_1_1(pdevice
, &core_1_1
);
1041 VkPhysicalDeviceVulkan12Features core_1_2
= {
1042 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
,
1044 radv_get_physical_device_features_1_2(pdevice
, &core_1_2
);
1046 #define CORE_FEATURE(major, minor, feature) \
1047 features->feature = core_##major##_##minor.feature
1049 vk_foreach_struct(ext
, pFeatures
->pNext
) {
1050 switch (ext
->sType
) {
1051 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
1052 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
1053 CORE_FEATURE(1, 1, variablePointersStorageBuffer
);
1054 CORE_FEATURE(1, 1, variablePointers
);
1057 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
1058 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
1059 CORE_FEATURE(1, 1, multiview
);
1060 CORE_FEATURE(1, 1, multiviewGeometryShader
);
1061 CORE_FEATURE(1, 1, multiviewTessellationShader
);
1064 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
1065 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
1066 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
1067 CORE_FEATURE(1, 1, shaderDrawParameters
);
1070 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
1071 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
1072 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
1073 CORE_FEATURE(1, 1, protectedMemory
);
1076 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
1077 VkPhysicalDevice16BitStorageFeatures
*features
=
1078 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
1079 CORE_FEATURE(1, 1, storageBuffer16BitAccess
);
1080 CORE_FEATURE(1, 1, uniformAndStorageBuffer16BitAccess
);
1081 CORE_FEATURE(1, 1, storagePushConstant16
);
1082 CORE_FEATURE(1, 1, storageInputOutput16
);
1085 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
1086 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
1087 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
1088 CORE_FEATURE(1, 1, samplerYcbcrConversion
);
1091 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES
: {
1092 VkPhysicalDeviceDescriptorIndexingFeatures
*features
=
1093 (VkPhysicalDeviceDescriptorIndexingFeatures
*)ext
;
1094 CORE_FEATURE(1, 2, shaderInputAttachmentArrayDynamicIndexing
);
1095 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayDynamicIndexing
);
1096 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayDynamicIndexing
);
1097 CORE_FEATURE(1, 2, shaderUniformBufferArrayNonUniformIndexing
);
1098 CORE_FEATURE(1, 2, shaderSampledImageArrayNonUniformIndexing
);
1099 CORE_FEATURE(1, 2, shaderStorageBufferArrayNonUniformIndexing
);
1100 CORE_FEATURE(1, 2, shaderStorageImageArrayNonUniformIndexing
);
1101 CORE_FEATURE(1, 2, shaderInputAttachmentArrayNonUniformIndexing
);
1102 CORE_FEATURE(1, 2, shaderUniformTexelBufferArrayNonUniformIndexing
);
1103 CORE_FEATURE(1, 2, shaderStorageTexelBufferArrayNonUniformIndexing
);
1104 CORE_FEATURE(1, 2, descriptorBindingUniformBufferUpdateAfterBind
);
1105 CORE_FEATURE(1, 2, descriptorBindingSampledImageUpdateAfterBind
);
1106 CORE_FEATURE(1, 2, descriptorBindingStorageImageUpdateAfterBind
);
1107 CORE_FEATURE(1, 2, descriptorBindingStorageBufferUpdateAfterBind
);
1108 CORE_FEATURE(1, 2, descriptorBindingUniformTexelBufferUpdateAfterBind
);
1109 CORE_FEATURE(1, 2, descriptorBindingStorageTexelBufferUpdateAfterBind
);
1110 CORE_FEATURE(1, 2, descriptorBindingUpdateUnusedWhilePending
);
1111 CORE_FEATURE(1, 2, descriptorBindingPartiallyBound
);
1112 CORE_FEATURE(1, 2, descriptorBindingVariableDescriptorCount
);
1113 CORE_FEATURE(1, 2, runtimeDescriptorArray
);
1116 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
1117 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
1118 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
1119 features
->conditionalRendering
= true;
1120 features
->inheritedConditionalRendering
= false;
1123 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
1124 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
1125 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
1126 features
->vertexAttributeInstanceRateDivisor
= true;
1127 features
->vertexAttributeInstanceRateZeroDivisor
= true;
1130 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
1131 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
1132 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
1133 features
->transformFeedback
= true;
1134 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
1137 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES
: {
1138 VkPhysicalDeviceScalarBlockLayoutFeatures
*features
=
1139 (VkPhysicalDeviceScalarBlockLayoutFeatures
*)ext
;
1140 CORE_FEATURE(1, 2, scalarBlockLayout
);
1143 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
1144 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
1145 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
1146 features
->memoryPriority
= true;
1149 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
1150 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
1151 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
1152 features
->bufferDeviceAddress
= true;
1153 features
->bufferDeviceAddressCaptureReplay
= false;
1154 features
->bufferDeviceAddressMultiDevice
= false;
1157 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES
: {
1158 VkPhysicalDeviceBufferDeviceAddressFeatures
*features
=
1159 (VkPhysicalDeviceBufferDeviceAddressFeatures
*)ext
;
1160 CORE_FEATURE(1, 2, bufferDeviceAddress
);
1161 CORE_FEATURE(1, 2, bufferDeviceAddressCaptureReplay
);
1162 CORE_FEATURE(1, 2, bufferDeviceAddressMultiDevice
);
1165 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
1166 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
1167 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
1168 features
->depthClipEnable
= true;
1171 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES
: {
1172 VkPhysicalDeviceHostQueryResetFeatures
*features
=
1173 (VkPhysicalDeviceHostQueryResetFeatures
*)ext
;
1174 CORE_FEATURE(1, 2, hostQueryReset
);
1177 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES
: {
1178 VkPhysicalDevice8BitStorageFeatures
*features
=
1179 (VkPhysicalDevice8BitStorageFeatures
*)ext
;
1180 CORE_FEATURE(1, 2, storageBuffer8BitAccess
);
1181 CORE_FEATURE(1, 2, uniformAndStorageBuffer8BitAccess
);
1182 CORE_FEATURE(1, 2, storagePushConstant8
);
1185 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES
: {
1186 VkPhysicalDeviceShaderFloat16Int8Features
*features
=
1187 (VkPhysicalDeviceShaderFloat16Int8Features
*)ext
;
1188 CORE_FEATURE(1, 2, shaderFloat16
);
1189 CORE_FEATURE(1, 2, shaderInt8
);
1192 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES
: {
1193 VkPhysicalDeviceShaderAtomicInt64Features
*features
=
1194 (VkPhysicalDeviceShaderAtomicInt64Features
*)ext
;
1195 CORE_FEATURE(1, 2, shaderBufferInt64Atomics
);
1196 CORE_FEATURE(1, 2, shaderSharedInt64Atomics
);
1199 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1200 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
=
1201 (VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*)ext
;
1202 features
->shaderDemoteToHelperInvocation
= pdevice
->use_aco
;
1205 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1206 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1207 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1209 features
->inlineUniformBlock
= true;
1210 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1213 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1214 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1215 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1216 features
->computeDerivativeGroupQuads
= false;
1217 features
->computeDerivativeGroupLinear
= true;
1220 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1221 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1222 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1223 features
->ycbcrImageArrays
= true;
1226 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES
: {
1227 VkPhysicalDeviceUniformBufferStandardLayoutFeatures
*features
=
1228 (VkPhysicalDeviceUniformBufferStandardLayoutFeatures
*)ext
;
1229 CORE_FEATURE(1, 2, uniformBufferStandardLayout
);
1232 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1233 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1234 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1235 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1238 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES
: {
1239 VkPhysicalDeviceImagelessFramebufferFeatures
*features
=
1240 (VkPhysicalDeviceImagelessFramebufferFeatures
*)ext
;
1241 CORE_FEATURE(1, 2, imagelessFramebuffer
);
1244 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1245 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1246 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1247 features
->pipelineExecutableInfo
= true;
1250 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1251 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1252 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1253 features
->shaderSubgroupClock
= true;
1254 features
->shaderDeviceClock
= pdevice
->rad_info
.chip_class
>= GFX8
;
1257 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1258 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1259 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1260 features
->texelBufferAlignment
= true;
1263 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES
: {
1264 VkPhysicalDeviceTimelineSemaphoreFeatures
*features
=
1265 (VkPhysicalDeviceTimelineSemaphoreFeatures
*) ext
;
1266 CORE_FEATURE(1, 2, timelineSemaphore
);
1269 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT
: {
1270 VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*features
=
1271 (VkPhysicalDeviceSubgroupSizeControlFeaturesEXT
*)ext
;
1272 features
->subgroupSizeControl
= true;
1273 features
->computeFullSubgroups
= true;
1276 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COHERENT_MEMORY_FEATURES_AMD
: {
1277 VkPhysicalDeviceCoherentMemoryFeaturesAMD
*features
=
1278 (VkPhysicalDeviceCoherentMemoryFeaturesAMD
*)ext
;
1279 features
->deviceCoherentMemory
= pdevice
->rad_info
.has_l2_uncached
;
1282 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES
: {
1283 VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
*features
=
1284 (VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures
*)ext
;
1285 CORE_FEATURE(1, 2, shaderSubgroupExtendedTypes
);
1288 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES_KHR
: {
1289 VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*features
=
1290 (VkPhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR
*)ext
;
1291 CORE_FEATURE(1, 2, separateDepthStencilLayouts
);
1294 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES
: {
1295 radv_get_physical_device_features_1_1(pdevice
, (void *)ext
);
1298 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
: {
1299 radv_get_physical_device_features_1_2(pdevice
, (void *)ext
);
1302 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT
: {
1303 VkPhysicalDeviceLineRasterizationFeaturesEXT
*features
=
1304 (VkPhysicalDeviceLineRasterizationFeaturesEXT
*)ext
;
1305 features
->rectangularLines
= false;
1306 features
->bresenhamLines
= true;
1307 features
->smoothLines
= false;
1308 features
->stippledRectangularLines
= false;
1309 features
->stippledBresenhamLines
= true;
1310 features
->stippledSmoothLines
= false;
1313 case VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD
: {
1314 VkDeviceMemoryOverallocationCreateInfoAMD
*features
=
1315 (VkDeviceMemoryOverallocationCreateInfoAMD
*)ext
;
1316 features
->overallocationBehavior
= true;
1319 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT
: {
1320 VkPhysicalDeviceRobustness2FeaturesEXT
*features
=
1321 (VkPhysicalDeviceRobustness2FeaturesEXT
*)ext
;
1322 features
->robustBufferAccess2
= true;
1323 features
->robustImageAccess2
= true;
1324 features
->nullDescriptor
= true;
1327 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT
: {
1328 VkPhysicalDeviceCustomBorderColorFeaturesEXT
*features
=
1329 (VkPhysicalDeviceCustomBorderColorFeaturesEXT
*)ext
;
1330 features
->customBorderColors
= true;
1331 features
->customBorderColorWithoutFormat
= true;
1334 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT
: {
1335 VkPhysicalDevicePrivateDataFeaturesEXT
*features
=
1336 (VkPhysicalDevicePrivateDataFeaturesEXT
*)ext
;
1337 features
->privateData
= true;
1340 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES_EXT
: {
1341 VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT
*features
=
1342 (VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT
*)ext
;
1343 features
-> pipelineCreationCacheControl
= true;
1354 radv_max_descriptor_set_size()
1356 /* make sure that the entire descriptor set is addressable with a signed
1357 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1358 * be at most 2 GiB. the combined image & samples object count as one of
1359 * both. This limit is for the pipeline layout, not for the set layout, but
1360 * there is no set limit, so we just set a pipeline limit. I don't think
1361 * any app is going to hit this soon. */
1362 return ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
1363 - MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1364 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1365 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1366 32 /* sampler, largest when combined with image */ +
1367 64 /* sampled image */ +
1368 64 /* storage image */);
1371 void radv_GetPhysicalDeviceProperties(
1372 VkPhysicalDevice physicalDevice
,
1373 VkPhysicalDeviceProperties
* pProperties
)
1375 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1376 VkSampleCountFlags sample_counts
= 0xf;
1378 size_t max_descriptor_set_size
= radv_max_descriptor_set_size();
1380 VkPhysicalDeviceLimits limits
= {
1381 .maxImageDimension1D
= (1 << 14),
1382 .maxImageDimension2D
= (1 << 14),
1383 .maxImageDimension3D
= (1 << 11),
1384 .maxImageDimensionCube
= (1 << 14),
1385 .maxImageArrayLayers
= (1 << 11),
1386 .maxTexelBufferElements
= UINT32_MAX
,
1387 .maxUniformBufferRange
= UINT32_MAX
,
1388 .maxStorageBufferRange
= UINT32_MAX
,
1389 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1390 .maxMemoryAllocationCount
= UINT32_MAX
,
1391 .maxSamplerAllocationCount
= 64 * 1024,
1392 .bufferImageGranularity
= 64, /* A cache line */
1393 .sparseAddressSpaceSize
= RADV_MAX_MEMORY_ALLOCATION_SIZE
, /* buffer max size */
1394 .maxBoundDescriptorSets
= MAX_SETS
,
1395 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1396 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1397 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1398 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1399 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1400 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1401 .maxPerStageResources
= max_descriptor_set_size
,
1402 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1403 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1404 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1405 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1406 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1407 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1408 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1409 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1410 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1411 .maxVertexInputBindings
= MAX_VBS
,
1412 .maxVertexInputAttributeOffset
= 2047,
1413 .maxVertexInputBindingStride
= 2048,
1414 .maxVertexOutputComponents
= 128,
1415 .maxTessellationGenerationLevel
= 64,
1416 .maxTessellationPatchSize
= 32,
1417 .maxTessellationControlPerVertexInputComponents
= 128,
1418 .maxTessellationControlPerVertexOutputComponents
= 128,
1419 .maxTessellationControlPerPatchOutputComponents
= 120,
1420 .maxTessellationControlTotalOutputComponents
= 4096,
1421 .maxTessellationEvaluationInputComponents
= 128,
1422 .maxTessellationEvaluationOutputComponents
= 128,
1423 .maxGeometryShaderInvocations
= 127,
1424 .maxGeometryInputComponents
= 64,
1425 .maxGeometryOutputComponents
= 128,
1426 .maxGeometryOutputVertices
= 256,
1427 .maxGeometryTotalOutputComponents
= 1024,
1428 .maxFragmentInputComponents
= 128,
1429 .maxFragmentOutputAttachments
= 8,
1430 .maxFragmentDualSrcAttachments
= 1,
1431 .maxFragmentCombinedOutputResources
= 8,
1432 .maxComputeSharedMemorySize
= 32768,
1433 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1434 .maxComputeWorkGroupInvocations
= 1024,
1435 .maxComputeWorkGroupSize
= {
1440 .subPixelPrecisionBits
= 8,
1441 .subTexelPrecisionBits
= 8,
1442 .mipmapPrecisionBits
= 8,
1443 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1444 .maxDrawIndirectCount
= UINT32_MAX
,
1445 .maxSamplerLodBias
= 16,
1446 .maxSamplerAnisotropy
= 16,
1447 .maxViewports
= MAX_VIEWPORTS
,
1448 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1449 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1450 .viewportSubPixelBits
= 8,
1451 .minMemoryMapAlignment
= 4096, /* A page */
1452 .minTexelBufferOffsetAlignment
= 4,
1453 .minUniformBufferOffsetAlignment
= 4,
1454 .minStorageBufferOffsetAlignment
= 4,
1455 .minTexelOffset
= -32,
1456 .maxTexelOffset
= 31,
1457 .minTexelGatherOffset
= -32,
1458 .maxTexelGatherOffset
= 31,
1459 .minInterpolationOffset
= -2,
1460 .maxInterpolationOffset
= 2,
1461 .subPixelInterpolationOffsetBits
= 8,
1462 .maxFramebufferWidth
= (1 << 14),
1463 .maxFramebufferHeight
= (1 << 14),
1464 .maxFramebufferLayers
= (1 << 10),
1465 .framebufferColorSampleCounts
= sample_counts
,
1466 .framebufferDepthSampleCounts
= sample_counts
,
1467 .framebufferStencilSampleCounts
= sample_counts
,
1468 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1469 .maxColorAttachments
= MAX_RTS
,
1470 .sampledImageColorSampleCounts
= sample_counts
,
1471 .sampledImageIntegerSampleCounts
= sample_counts
,
1472 .sampledImageDepthSampleCounts
= sample_counts
,
1473 .sampledImageStencilSampleCounts
= sample_counts
,
1474 .storageImageSampleCounts
= sample_counts
,
1475 .maxSampleMaskWords
= 1,
1476 .timestampComputeAndGraphics
= true,
1477 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1478 .maxClipDistances
= 8,
1479 .maxCullDistances
= 8,
1480 .maxCombinedClipAndCullDistances
= 8,
1481 .discreteQueuePriorities
= 2,
1482 .pointSizeRange
= { 0.0, 8192.0 },
1483 .lineWidthRange
= { 0.0, 8192.0 },
1484 .pointSizeGranularity
= (1.0 / 8.0),
1485 .lineWidthGranularity
= (1.0 / 8.0),
1486 .strictLines
= false, /* FINISHME */
1487 .standardSampleLocations
= true,
1488 .optimalBufferCopyOffsetAlignment
= 128,
1489 .optimalBufferCopyRowPitchAlignment
= 128,
1490 .nonCoherentAtomSize
= 64,
1493 *pProperties
= (VkPhysicalDeviceProperties
) {
1494 .apiVersion
= radv_physical_device_api_version(pdevice
),
1495 .driverVersion
= vk_get_driver_version(),
1496 .vendorID
= ATI_VENDOR_ID
,
1497 .deviceID
= pdevice
->rad_info
.pci_id
,
1498 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1500 .sparseProperties
= {0},
1503 strcpy(pProperties
->deviceName
, pdevice
->name
);
1504 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1508 radv_get_physical_device_properties_1_1(struct radv_physical_device
*pdevice
,
1509 VkPhysicalDeviceVulkan11Properties
*p
)
1511 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
);
1513 memcpy(p
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1514 memcpy(p
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1515 memset(p
->deviceLUID
, 0, VK_LUID_SIZE
);
1516 /* The LUID is for Windows. */
1517 p
->deviceLUIDValid
= false;
1518 p
->deviceNodeMask
= 0;
1520 p
->subgroupSize
= RADV_SUBGROUP_SIZE
;
1521 p
->subgroupSupportedStages
= VK_SHADER_STAGE_ALL_GRAPHICS
|
1522 VK_SHADER_STAGE_COMPUTE_BIT
;
1523 p
->subgroupSupportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
|
1524 VK_SUBGROUP_FEATURE_VOTE_BIT
|
1525 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1526 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1527 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1528 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1529 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1530 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1531 p
->subgroupQuadOperationsInAllStages
= true;
1533 p
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1534 p
->maxMultiviewViewCount
= MAX_VIEWS
;
1535 p
->maxMultiviewInstanceIndex
= INT_MAX
;
1536 p
->protectedNoFault
= false;
1537 p
->maxPerSetDescriptors
= RADV_MAX_PER_SET_DESCRIPTORS
;
1538 p
->maxMemoryAllocationSize
= RADV_MAX_MEMORY_ALLOCATION_SIZE
;
1542 radv_get_physical_device_properties_1_2(struct radv_physical_device
*pdevice
,
1543 VkPhysicalDeviceVulkan12Properties
*p
)
1545 assert(p
->sType
== VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
);
1547 p
->driverID
= VK_DRIVER_ID_MESA_RADV
;
1548 snprintf(p
->driverName
, VK_MAX_DRIVER_NAME_SIZE
, "radv");
1549 snprintf(p
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE
,
1550 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
" (%s)",
1551 radv_get_compiler_string(pdevice
));
1552 p
->conformanceVersion
= (VkConformanceVersion
) {
1559 /* On AMD hardware, denormals and rounding modes for fp16/fp64 are
1560 * controlled by the same config register.
1562 if (pdevice
->rad_info
.has_packed_math_16bit
) {
1563 p
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1564 p
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1566 p
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1567 p
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR
;
1570 /* Do not allow both preserving and flushing denorms because different
1571 * shaders in the same pipeline can have different settings and this
1572 * won't work for merged shaders. To make it work, this requires LLVM
1573 * support for changing the register. The same logic applies for the
1574 * rounding modes because they are configured with the same config
1575 * register. TODO: we can enable a lot of these for ACO when it
1576 * supports all stages.
1578 p
->shaderDenormFlushToZeroFloat32
= true;
1579 p
->shaderDenormPreserveFloat32
= false;
1580 p
->shaderRoundingModeRTEFloat32
= true;
1581 p
->shaderRoundingModeRTZFloat32
= false;
1582 p
->shaderSignedZeroInfNanPreserveFloat32
= true;
1584 p
->shaderDenormFlushToZeroFloat16
= false;
1585 p
->shaderDenormPreserveFloat16
= pdevice
->rad_info
.has_packed_math_16bit
;
1586 p
->shaderRoundingModeRTEFloat16
= pdevice
->rad_info
.has_packed_math_16bit
;
1587 p
->shaderRoundingModeRTZFloat16
= false;
1588 p
->shaderSignedZeroInfNanPreserveFloat16
= pdevice
->rad_info
.has_packed_math_16bit
;
1590 p
->shaderDenormFlushToZeroFloat64
= false;
1591 p
->shaderDenormPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1592 p
->shaderRoundingModeRTEFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1593 p
->shaderRoundingModeRTZFloat64
= false;
1594 p
->shaderSignedZeroInfNanPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1596 p
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1597 p
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1598 p
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1599 p
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1600 p
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1601 p
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1602 p
->robustBufferAccessUpdateAfterBind
= false;
1603 p
->quadDivergentImplicitLod
= false;
1605 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1606 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1607 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1608 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1609 32 /* sampler, largest when combined with image */ +
1610 64 /* sampled image */ +
1611 64 /* storage image */);
1612 p
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1613 p
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1614 p
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1615 p
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1616 p
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1617 p
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1618 p
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1619 p
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1620 p
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1621 p
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1622 p
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1623 p
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1624 p
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1625 p
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1626 p
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1628 /* We support all of the depth resolve modes */
1629 p
->supportedDepthResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1630 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1631 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1632 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1634 /* Average doesn't make sense for stencil so we don't support that */
1635 p
->supportedStencilResolveModes
= VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1636 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1637 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1639 p
->independentResolveNone
= true;
1640 p
->independentResolve
= true;
1642 /* GFX6-8 only support single channel min/max filter. */
1643 p
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1644 p
->filterMinmaxSingleComponentFormats
= true;
1646 p
->maxTimelineSemaphoreValueDifference
= UINT64_MAX
;
1648 p
->framebufferIntegerColorSampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1651 void radv_GetPhysicalDeviceProperties2(
1652 VkPhysicalDevice physicalDevice
,
1653 VkPhysicalDeviceProperties2
*pProperties
)
1655 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1656 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1658 VkPhysicalDeviceVulkan11Properties core_1_1
= {
1659 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
,
1661 radv_get_physical_device_properties_1_1(pdevice
, &core_1_1
);
1663 VkPhysicalDeviceVulkan12Properties core_1_2
= {
1664 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
,
1666 radv_get_physical_device_properties_1_2(pdevice
, &core_1_2
);
1668 #define CORE_RENAMED_PROPERTY(major, minor, ext_property, core_property) \
1669 memcpy(&properties->ext_property, &core_##major##_##minor.core_property, \
1670 sizeof(core_##major##_##minor.core_property))
1672 #define CORE_PROPERTY(major, minor, property) \
1673 CORE_RENAMED_PROPERTY(major, minor, property, property)
1675 vk_foreach_struct(ext
, pProperties
->pNext
) {
1676 switch (ext
->sType
) {
1677 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1678 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1679 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1680 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1683 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1684 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1685 CORE_PROPERTY(1, 1, deviceUUID
);
1686 CORE_PROPERTY(1, 1, driverUUID
);
1687 CORE_PROPERTY(1, 1, deviceLUID
);
1688 CORE_PROPERTY(1, 1, deviceLUIDValid
);
1691 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1692 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1693 CORE_PROPERTY(1, 1, maxMultiviewViewCount
);
1694 CORE_PROPERTY(1, 1, maxMultiviewInstanceIndex
);
1697 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1698 VkPhysicalDevicePointClippingProperties
*properties
=
1699 (VkPhysicalDevicePointClippingProperties
*)ext
;
1700 CORE_PROPERTY(1, 1, pointClippingBehavior
);
1703 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1704 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1705 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1706 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1709 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1710 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1711 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1712 properties
->minImportedHostPointerAlignment
= 4096;
1715 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1716 VkPhysicalDeviceSubgroupProperties
*properties
=
1717 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1718 CORE_PROPERTY(1, 1, subgroupSize
);
1719 CORE_RENAMED_PROPERTY(1, 1, supportedStages
,
1720 subgroupSupportedStages
);
1721 CORE_RENAMED_PROPERTY(1, 1, supportedOperations
,
1722 subgroupSupportedOperations
);
1723 CORE_RENAMED_PROPERTY(1, 1, quadOperationsInAllStages
,
1724 subgroupQuadOperationsInAllStages
);
1727 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1728 VkPhysicalDeviceMaintenance3Properties
*properties
=
1729 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1730 CORE_PROPERTY(1, 1, maxPerSetDescriptors
);
1731 CORE_PROPERTY(1, 1, maxMemoryAllocationSize
);
1734 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES
: {
1735 VkPhysicalDeviceSamplerFilterMinmaxProperties
*properties
=
1736 (VkPhysicalDeviceSamplerFilterMinmaxProperties
*)ext
;
1737 CORE_PROPERTY(1, 2, filterMinmaxImageComponentMapping
);
1738 CORE_PROPERTY(1, 2, filterMinmaxSingleComponentFormats
);
1741 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1742 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1743 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1745 /* Shader engines. */
1746 properties
->shaderEngineCount
=
1747 pdevice
->rad_info
.max_se
;
1748 properties
->shaderArraysPerEngineCount
=
1749 pdevice
->rad_info
.max_sh_per_se
;
1750 properties
->computeUnitsPerShaderArray
=
1751 pdevice
->rad_info
.min_good_cu_per_sa
;
1752 properties
->simdPerComputeUnit
=
1753 pdevice
->rad_info
.num_simd_per_compute_unit
;
1754 properties
->wavefrontsPerSimd
=
1755 pdevice
->rad_info
.max_wave64_per_simd
;
1756 properties
->wavefrontSize
= 64;
1759 properties
->sgprsPerSimd
=
1760 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1761 properties
->minSgprAllocation
=
1762 pdevice
->rad_info
.min_sgpr_alloc
;
1763 properties
->maxSgprAllocation
=
1764 pdevice
->rad_info
.max_sgpr_alloc
;
1765 properties
->sgprAllocationGranularity
=
1766 pdevice
->rad_info
.sgpr_alloc_granularity
;
1769 properties
->vgprsPerSimd
=
1770 pdevice
->rad_info
.num_physical_wave64_vgprs_per_simd
;
1771 properties
->minVgprAllocation
=
1772 pdevice
->rad_info
.min_wave64_vgpr_alloc
;
1773 properties
->maxVgprAllocation
=
1774 pdevice
->rad_info
.max_vgpr_alloc
;
1775 properties
->vgprAllocationGranularity
=
1776 pdevice
->rad_info
.wave64_vgpr_alloc_granularity
;
1779 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1780 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1781 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1783 properties
->shaderCoreFeatures
= 0;
1784 properties
->activeComputeUnitCount
=
1785 pdevice
->rad_info
.num_good_compute_units
;
1788 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1789 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1790 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1791 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1794 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES
: {
1795 VkPhysicalDeviceDescriptorIndexingProperties
*properties
=
1796 (VkPhysicalDeviceDescriptorIndexingProperties
*)ext
;
1797 CORE_PROPERTY(1, 2, maxUpdateAfterBindDescriptorsInAllPools
);
1798 CORE_PROPERTY(1, 2, shaderUniformBufferArrayNonUniformIndexingNative
);
1799 CORE_PROPERTY(1, 2, shaderSampledImageArrayNonUniformIndexingNative
);
1800 CORE_PROPERTY(1, 2, shaderStorageBufferArrayNonUniformIndexingNative
);
1801 CORE_PROPERTY(1, 2, shaderStorageImageArrayNonUniformIndexingNative
);
1802 CORE_PROPERTY(1, 2, shaderInputAttachmentArrayNonUniformIndexingNative
);
1803 CORE_PROPERTY(1, 2, robustBufferAccessUpdateAfterBind
);
1804 CORE_PROPERTY(1, 2, quadDivergentImplicitLod
);
1805 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSamplers
);
1806 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindUniformBuffers
);
1807 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageBuffers
);
1808 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindSampledImages
);
1809 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindStorageImages
);
1810 CORE_PROPERTY(1, 2, maxPerStageDescriptorUpdateAfterBindInputAttachments
);
1811 CORE_PROPERTY(1, 2, maxPerStageUpdateAfterBindResources
);
1812 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSamplers
);
1813 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffers
);
1814 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
);
1815 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffers
);
1816 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
);
1817 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindSampledImages
);
1818 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindStorageImages
);
1819 CORE_PROPERTY(1, 2, maxDescriptorSetUpdateAfterBindInputAttachments
);
1822 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1823 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1824 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1825 CORE_PROPERTY(1, 1, protectedNoFault
);
1828 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1829 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1830 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1831 properties
->primitiveOverestimationSize
= 0;
1832 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1833 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1834 properties
->primitiveUnderestimation
= false;
1835 properties
->conservativePointAndLineRasterization
= false;
1836 properties
->degenerateTrianglesRasterized
= false;
1837 properties
->degenerateLinesRasterized
= false;
1838 properties
->fullyCoveredFragmentShaderInputVariable
= false;
1839 properties
->conservativeRasterizationPostDepthCoverage
= false;
1842 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1843 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1844 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1845 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1846 properties
->pciBus
= pdevice
->bus_info
.bus
;
1847 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1848 properties
->pciFunction
= pdevice
->bus_info
.func
;
1851 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES
: {
1852 VkPhysicalDeviceDriverProperties
*properties
=
1853 (VkPhysicalDeviceDriverProperties
*) ext
;
1854 CORE_PROPERTY(1, 2, driverID
);
1855 CORE_PROPERTY(1, 2, driverName
);
1856 CORE_PROPERTY(1, 2, driverInfo
);
1857 CORE_PROPERTY(1, 2, conformanceVersion
);
1860 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1861 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1862 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1863 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1864 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1865 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1866 properties
->maxTransformFeedbackStreamDataSize
= 512;
1867 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1868 properties
->maxTransformFeedbackBufferDataStride
= 512;
1869 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1870 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1871 properties
->transformFeedbackRasterizationStreamSelect
= false;
1872 properties
->transformFeedbackDraw
= true;
1875 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1876 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1877 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1879 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1880 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1881 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1882 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1883 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1886 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1887 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1888 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1889 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1890 VK_SAMPLE_COUNT_4_BIT
|
1891 VK_SAMPLE_COUNT_8_BIT
;
1892 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1893 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1894 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1895 properties
->sampleLocationSubPixelBits
= 4;
1896 properties
->variableSampleLocations
= false;
1899 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES
: {
1900 VkPhysicalDeviceDepthStencilResolveProperties
*properties
=
1901 (VkPhysicalDeviceDepthStencilResolveProperties
*)ext
;
1902 CORE_PROPERTY(1, 2, supportedDepthResolveModes
);
1903 CORE_PROPERTY(1, 2, supportedStencilResolveModes
);
1904 CORE_PROPERTY(1, 2, independentResolveNone
);
1905 CORE_PROPERTY(1, 2, independentResolve
);
1908 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1909 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*properties
=
1910 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1911 properties
->storageTexelBufferOffsetAlignmentBytes
= 4;
1912 properties
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1913 properties
->uniformTexelBufferOffsetAlignmentBytes
= 4;
1914 properties
->uniformTexelBufferOffsetSingleTexelAlignment
= true;
1917 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES
: {
1918 VkPhysicalDeviceFloatControlsProperties
*properties
=
1919 (VkPhysicalDeviceFloatControlsProperties
*)ext
;
1920 CORE_PROPERTY(1, 2, denormBehaviorIndependence
);
1921 CORE_PROPERTY(1, 2, roundingModeIndependence
);
1922 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat16
);
1923 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat16
);
1924 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat16
);
1925 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat16
);
1926 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat16
);
1927 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat32
);
1928 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat32
);
1929 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat32
);
1930 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat32
);
1931 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat32
);
1932 CORE_PROPERTY(1, 2, shaderDenormFlushToZeroFloat64
);
1933 CORE_PROPERTY(1, 2, shaderDenormPreserveFloat64
);
1934 CORE_PROPERTY(1, 2, shaderRoundingModeRTEFloat64
);
1935 CORE_PROPERTY(1, 2, shaderRoundingModeRTZFloat64
);
1936 CORE_PROPERTY(1, 2, shaderSignedZeroInfNanPreserveFloat64
);
1939 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES
: {
1940 VkPhysicalDeviceTimelineSemaphoreProperties
*properties
=
1941 (VkPhysicalDeviceTimelineSemaphoreProperties
*) ext
;
1942 CORE_PROPERTY(1, 2, maxTimelineSemaphoreValueDifference
);
1945 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT
: {
1946 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*props
=
1947 (VkPhysicalDeviceSubgroupSizeControlPropertiesEXT
*)ext
;
1948 props
->minSubgroupSize
= 64;
1949 props
->maxSubgroupSize
= 64;
1950 props
->maxComputeWorkgroupSubgroups
= UINT32_MAX
;
1951 props
->requiredSubgroupSizeStages
= 0;
1953 if (pdevice
->rad_info
.chip_class
>= GFX10
) {
1954 /* Only GFX10+ supports wave32. */
1955 props
->minSubgroupSize
= 32;
1956 props
->requiredSubgroupSizeStages
= VK_SHADER_STAGE_COMPUTE_BIT
;
1960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES
:
1961 radv_get_physical_device_properties_1_1(pdevice
, (void *)ext
);
1963 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES
:
1964 radv_get_physical_device_properties_1_2(pdevice
, (void *)ext
);
1966 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT
: {
1967 VkPhysicalDeviceLineRasterizationPropertiesEXT
*props
=
1968 (VkPhysicalDeviceLineRasterizationPropertiesEXT
*)ext
;
1969 props
->lineSubPixelPrecisionBits
= 4;
1972 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_PROPERTIES_EXT
: {
1973 VkPhysicalDeviceRobustness2PropertiesEXT
*properties
=
1974 (VkPhysicalDeviceRobustness2PropertiesEXT
*)ext
;
1975 properties
->robustStorageBufferAccessSizeAlignment
= 4;
1976 properties
->robustUniformBufferAccessSizeAlignment
= 4;
1979 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT
: {
1980 VkPhysicalDeviceCustomBorderColorPropertiesEXT
*props
=
1981 (VkPhysicalDeviceCustomBorderColorPropertiesEXT
*)ext
;
1982 props
->maxCustomBorderColorSamplers
= RADV_BORDER_COLOR_COUNT
;
1991 static void radv_get_physical_device_queue_family_properties(
1992 struct radv_physical_device
* pdevice
,
1994 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1996 int num_queue_families
= 1;
1998 if (pdevice
->rad_info
.num_rings
[RING_COMPUTE
] > 0 &&
1999 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
2000 num_queue_families
++;
2002 if (pQueueFamilyProperties
== NULL
) {
2003 *pCount
= num_queue_families
;
2012 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
2013 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
2014 VK_QUEUE_COMPUTE_BIT
|
2015 VK_QUEUE_TRANSFER_BIT
|
2016 VK_QUEUE_SPARSE_BINDING_BIT
,
2018 .timestampValidBits
= 64,
2019 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
2024 if (pdevice
->rad_info
.num_rings
[RING_COMPUTE
] > 0 &&
2025 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
2026 if (*pCount
> idx
) {
2027 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
2028 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
2029 VK_QUEUE_TRANSFER_BIT
|
2030 VK_QUEUE_SPARSE_BINDING_BIT
,
2031 .queueCount
= pdevice
->rad_info
.num_rings
[RING_COMPUTE
],
2032 .timestampValidBits
= 64,
2033 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
2041 void radv_GetPhysicalDeviceQueueFamilyProperties(
2042 VkPhysicalDevice physicalDevice
,
2044 VkQueueFamilyProperties
* pQueueFamilyProperties
)
2046 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
2047 if (!pQueueFamilyProperties
) {
2048 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
2051 VkQueueFamilyProperties
*properties
[] = {
2052 pQueueFamilyProperties
+ 0,
2053 pQueueFamilyProperties
+ 1,
2054 pQueueFamilyProperties
+ 2,
2056 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
2057 assert(*pCount
<= 3);
2060 void radv_GetPhysicalDeviceQueueFamilyProperties2(
2061 VkPhysicalDevice physicalDevice
,
2063 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
2065 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
2066 if (!pQueueFamilyProperties
) {
2067 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
2070 VkQueueFamilyProperties
*properties
[] = {
2071 &pQueueFamilyProperties
[0].queueFamilyProperties
,
2072 &pQueueFamilyProperties
[1].queueFamilyProperties
,
2073 &pQueueFamilyProperties
[2].queueFamilyProperties
,
2075 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
2076 assert(*pCount
<= 3);
2079 void radv_GetPhysicalDeviceMemoryProperties(
2080 VkPhysicalDevice physicalDevice
,
2081 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
2083 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2085 *pMemoryProperties
= physical_device
->memory_properties
;
2089 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
2090 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
2092 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2093 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
2094 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
2095 uint64_t vram_size
= radv_get_vram_size(device
);
2096 uint64_t gtt_size
= device
->rad_info
.gart_size
;
2097 uint64_t heap_budget
, heap_usage
;
2099 /* For all memory heaps, the computation of budget is as follow:
2100 * heap_budget = heap_size - global_heap_usage + app_heap_usage
2102 * The Vulkan spec 1.1.97 says that the budget should include any
2103 * currently allocated device memory.
2105 * Note that the application heap usages are not really accurate (eg.
2106 * in presence of shared buffers).
2108 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
2109 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
2111 if ((device
->memory_domains
[i
] & RADEON_DOMAIN_VRAM
) && (device
->memory_flags
[i
] & RADEON_FLAG_NO_CPU_ACCESS
)) {
2112 heap_usage
= device
->ws
->query_value(device
->ws
,
2113 RADEON_ALLOCATED_VRAM
);
2115 heap_budget
= vram_size
-
2116 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
2119 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2120 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2121 } else if (device
->memory_domains
[i
] & RADEON_DOMAIN_VRAM
) {
2122 heap_usage
= device
->ws
->query_value(device
->ws
,
2123 RADEON_ALLOCATED_VRAM_VIS
);
2125 heap_budget
= visible_vram_size
-
2126 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
2129 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2130 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2132 assert(device
->memory_domains
[i
] & RADEON_DOMAIN_GTT
);
2134 heap_usage
= device
->ws
->query_value(device
->ws
,
2135 RADEON_ALLOCATED_GTT
);
2137 heap_budget
= gtt_size
-
2138 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
2141 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
2142 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
2146 /* The heapBudget and heapUsage values must be zero for array elements
2147 * greater than or equal to
2148 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
2150 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
2151 memoryBudget
->heapBudget
[i
] = 0;
2152 memoryBudget
->heapUsage
[i
] = 0;
2156 void radv_GetPhysicalDeviceMemoryProperties2(
2157 VkPhysicalDevice physicalDevice
,
2158 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
2160 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
2161 &pMemoryProperties
->memoryProperties
);
2163 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
2164 vk_find_struct(pMemoryProperties
->pNext
,
2165 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
2167 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
2170 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
2172 VkExternalMemoryHandleTypeFlagBits handleType
,
2173 const void *pHostPointer
,
2174 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
2176 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2180 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
2181 const struct radv_physical_device
*physical_device
= device
->physical_device
;
2182 uint32_t memoryTypeBits
= 0;
2183 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
2184 if (physical_device
->memory_domains
[i
] == RADEON_DOMAIN_GTT
&&
2185 !(physical_device
->memory_flags
[i
] & RADEON_FLAG_GTT_WC
)) {
2186 memoryTypeBits
= (1 << i
);
2190 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
2194 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
2198 static enum radeon_ctx_priority
2199 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
2201 /* Default to MEDIUM when a specific global priority isn't requested */
2203 return RADEON_CTX_PRIORITY_MEDIUM
;
2205 switch(pObj
->globalPriority
) {
2206 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
2207 return RADEON_CTX_PRIORITY_REALTIME
;
2208 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
2209 return RADEON_CTX_PRIORITY_HIGH
;
2210 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
2211 return RADEON_CTX_PRIORITY_MEDIUM
;
2212 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
2213 return RADEON_CTX_PRIORITY_LOW
;
2215 unreachable("Illegal global priority value");
2216 return RADEON_CTX_PRIORITY_INVALID
;
2221 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
2222 uint32_t queue_family_index
, int idx
,
2223 VkDeviceQueueCreateFlags flags
,
2224 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
2226 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2227 queue
->device
= device
;
2228 queue
->queue_family_index
= queue_family_index
;
2229 queue
->queue_idx
= idx
;
2230 queue
->priority
= radv_get_queue_global_priority(global_priority
);
2231 queue
->flags
= flags
;
2232 queue
->hw_ctx
= NULL
;
2234 VkResult result
= device
->ws
->ctx_create(device
->ws
, queue
->priority
, &queue
->hw_ctx
);
2235 if (result
!= VK_SUCCESS
)
2236 return vk_error(device
->instance
, result
);
2238 list_inithead(&queue
->pending_submissions
);
2239 pthread_mutex_init(&queue
->pending_mutex
, NULL
);
2245 radv_queue_finish(struct radv_queue
*queue
)
2247 pthread_mutex_destroy(&queue
->pending_mutex
);
2250 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
2252 if (queue
->initial_full_flush_preamble_cs
)
2253 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2254 if (queue
->initial_preamble_cs
)
2255 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2256 if (queue
->continue_preamble_cs
)
2257 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2258 if (queue
->descriptor_bo
)
2259 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2260 if (queue
->scratch_bo
)
2261 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2262 if (queue
->esgs_ring_bo
)
2263 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2264 if (queue
->gsvs_ring_bo
)
2265 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2266 if (queue
->tess_rings_bo
)
2267 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
2269 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
2270 if (queue
->gds_oa_bo
)
2271 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
2272 if (queue
->compute_scratch_bo
)
2273 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2277 radv_bo_list_init(struct radv_bo_list
*bo_list
)
2279 pthread_mutex_init(&bo_list
->mutex
, NULL
);
2280 bo_list
->list
.count
= bo_list
->capacity
= 0;
2281 bo_list
->list
.bos
= NULL
;
2285 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
2287 free(bo_list
->list
.bos
);
2288 pthread_mutex_destroy(&bo_list
->mutex
);
2291 VkResult
radv_bo_list_add(struct radv_device
*device
,
2292 struct radeon_winsys_bo
*bo
)
2294 struct radv_bo_list
*bo_list
= &device
->bo_list
;
2299 if (unlikely(!device
->use_global_bo_list
))
2302 pthread_mutex_lock(&bo_list
->mutex
);
2303 if (bo_list
->list
.count
== bo_list
->capacity
) {
2304 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
2305 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
2308 pthread_mutex_unlock(&bo_list
->mutex
);
2309 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2312 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
2313 bo_list
->capacity
= capacity
;
2316 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
2317 pthread_mutex_unlock(&bo_list
->mutex
);
2321 void radv_bo_list_remove(struct radv_device
*device
,
2322 struct radeon_winsys_bo
*bo
)
2324 struct radv_bo_list
*bo_list
= &device
->bo_list
;
2329 if (unlikely(!device
->use_global_bo_list
))
2332 pthread_mutex_lock(&bo_list
->mutex
);
2333 /* Loop the list backwards so we find the most recently added
2335 for(unsigned i
= bo_list
->list
.count
; i
-- > 0;) {
2336 if (bo_list
->list
.bos
[i
] == bo
) {
2337 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
2338 --bo_list
->list
.count
;
2342 pthread_mutex_unlock(&bo_list
->mutex
);
2346 radv_device_init_gs_info(struct radv_device
*device
)
2348 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
2349 device
->physical_device
->rad_info
.family
);
2352 static int radv_get_device_extension_index(const char *name
)
2354 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
2355 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
2362 radv_get_int_debug_option(const char *name
, int default_value
)
2369 result
= default_value
;
2373 result
= strtol(str
, &endptr
, 0);
2374 if (str
== endptr
) {
2375 /* No digits founs. */
2376 result
= default_value
;
2383 static int install_seccomp_filter() {
2385 struct sock_filter filter
[] = {
2386 /* Check arch is 64bit x86 */
2387 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, arch
))),
2388 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, AUDIT_ARCH_X86_64
, 0, 12),
2390 /* Futex is required for mutex locks */
2391 #if defined __NR__newselect
2392 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2393 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR__newselect
, 11, 0),
2394 #elif defined __NR_select
2395 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2396 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_select
, 11, 0),
2398 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2399 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_pselect6
, 11, 0),
2402 /* Allow system exit calls for the forked process */
2403 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2404 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_exit_group
, 9, 0),
2406 /* Allow system read calls */
2407 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2408 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_read
, 7, 0),
2410 /* Allow system write calls */
2411 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2412 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_write
, 5, 0),
2414 /* Allow system brk calls (we need this for malloc) */
2415 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2416 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_brk
, 3, 0),
2418 /* Futex is required for mutex locks */
2419 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2420 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_futex
, 1, 0),
2422 /* Return error if we hit a system call not on the whitelist */
2423 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ERRNO
| (EPERM
& SECCOMP_RET_DATA
)),
2425 /* Allow whitelisted system calls */
2426 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ALLOW
),
2429 struct sock_fprog prog
= {
2430 .len
= (unsigned short)(sizeof(filter
) / sizeof(filter
[0])),
2434 if (prctl(PR_SET_NO_NEW_PRIVS
, 1, 0, 0, 0))
2437 if (prctl(PR_SET_SECCOMP
, SECCOMP_MODE_FILTER
, &prog
))
2443 /* Helper function with timeout support for reading from the pipe between
2444 * processes used for secure compile.
2446 bool radv_sc_read(int fd
, void *buf
, size_t size
, bool timeout
)
2455 /* We can't rely on the value of tv after calling select() so
2456 * we must reset it on each iteration of the loop.
2461 int rval
= select(fd
+ 1, &fds
, NULL
, NULL
, timeout
? &tv
: NULL
);
2467 ssize_t bytes_read
= read(fd
, buf
, size
);
2476 /* select timeout */
2482 static bool radv_close_all_fds(const int *keep_fds
, int keep_fd_count
)
2486 d
= opendir("/proc/self/fd");
2489 int dir_fd
= dirfd(d
);
2491 while ((dir
= readdir(d
)) != NULL
) {
2492 if (dir
->d_name
[0] == '.')
2495 int fd
= atoi(dir
->d_name
);
2500 for (int i
= 0; !keep
&& i
< keep_fd_count
; ++i
)
2501 if (keep_fds
[i
] == fd
)
2513 static bool secure_compile_open_fifo_fds(struct radv_secure_compile_state
*sc
,
2514 int *fd_server
, int *fd_client
,
2515 unsigned process
, bool make_fifo
)
2517 bool result
= false;
2518 char *fifo_server_path
= NULL
;
2519 char *fifo_client_path
= NULL
;
2521 if (asprintf(&fifo_server_path
, "/tmp/radv_server_%s_%u", sc
->uid
, process
) == -1)
2522 goto open_fifo_exit
;
2524 if (asprintf(&fifo_client_path
, "/tmp/radv_client_%s_%u", sc
->uid
, process
) == -1)
2525 goto open_fifo_exit
;
2528 int file1
= mkfifo(fifo_server_path
, 0666);
2530 goto open_fifo_exit
;
2532 int file2
= mkfifo(fifo_client_path
, 0666);
2534 goto open_fifo_exit
;
2537 *fd_server
= open(fifo_server_path
, O_RDWR
);
2539 goto open_fifo_exit
;
2541 *fd_client
= open(fifo_client_path
, O_RDWR
);
2542 if(*fd_client
< 1) {
2544 goto open_fifo_exit
;
2550 free(fifo_server_path
);
2551 free(fifo_client_path
);
2556 static void run_secure_compile_device(struct radv_device
*device
, unsigned process
,
2557 int fd_idle_device_output
)
2559 int fd_secure_input
;
2560 int fd_secure_output
;
2561 bool fifo_result
= secure_compile_open_fifo_fds(device
->sc_state
,
2566 enum radv_secure_compile_type sc_type
;
2568 const int needed_fds
[] = {
2571 fd_idle_device_output
,
2574 if (!fifo_result
|| !radv_close_all_fds(needed_fds
, ARRAY_SIZE(needed_fds
)) ||
2575 install_seccomp_filter() == -1) {
2576 sc_type
= RADV_SC_TYPE_INIT_FAILURE
;
2578 sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2579 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
;
2580 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
;
2583 write(fd_idle_device_output
, &sc_type
, sizeof(sc_type
));
2585 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2586 goto secure_compile_exit
;
2589 radv_sc_read(fd_secure_input
, &sc_type
, sizeof(sc_type
), false);
2591 if (sc_type
== RADV_SC_TYPE_COMPILE_PIPELINE
) {
2592 struct radv_pipeline
*pipeline
;
2593 bool sc_read
= true;
2595 pipeline
= vk_zalloc2(&device
->vk
.alloc
, NULL
, sizeof(*pipeline
), 8,
2596 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2598 pipeline
->device
= device
;
2600 /* Read pipeline layout */
2601 struct radv_pipeline_layout layout
;
2602 sc_read
= radv_sc_read(fd_secure_input
, &layout
, sizeof(struct radv_pipeline_layout
), true);
2603 sc_read
&= radv_sc_read(fd_secure_input
, &layout
.num_sets
, sizeof(uint32_t), true);
2605 goto secure_compile_exit
;
2607 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++) {
2608 uint32_t layout_size
;
2609 sc_read
&= radv_sc_read(fd_secure_input
, &layout_size
, sizeof(uint32_t), true);
2611 goto secure_compile_exit
;
2613 layout
.set
[set
].layout
= malloc(layout_size
);
2614 layout
.set
[set
].layout
->layout_size
= layout_size
;
2615 sc_read
&= radv_sc_read(fd_secure_input
, layout
.set
[set
].layout
,
2616 layout
.set
[set
].layout
->layout_size
, true);
2619 pipeline
->layout
= &layout
;
2621 /* Read pipeline key */
2622 struct radv_pipeline_key key
;
2623 sc_read
&= radv_sc_read(fd_secure_input
, &key
, sizeof(struct radv_pipeline_key
), true);
2625 /* Read pipeline create flags */
2626 VkPipelineCreateFlags flags
;
2627 sc_read
&= radv_sc_read(fd_secure_input
, &flags
, sizeof(VkPipelineCreateFlags
), true);
2629 /* Read stage and shader information */
2630 uint32_t num_stages
;
2631 const VkPipelineShaderStageCreateInfo
*pStages
[MESA_SHADER_STAGES
] = { 0, };
2632 sc_read
&= radv_sc_read(fd_secure_input
, &num_stages
, sizeof(uint32_t), true);
2634 goto secure_compile_exit
;
2636 for (uint32_t i
= 0; i
< num_stages
; i
++) {
2639 gl_shader_stage stage
;
2640 sc_read
&= radv_sc_read(fd_secure_input
, &stage
, sizeof(gl_shader_stage
), true);
2642 VkPipelineShaderStageCreateInfo
*pStage
= calloc(1, sizeof(VkPipelineShaderStageCreateInfo
));
2644 /* Read entry point name */
2646 sc_read
&= radv_sc_read(fd_secure_input
, &name_size
, sizeof(size_t), true);
2648 goto secure_compile_exit
;
2650 char *ep_name
= malloc(name_size
);
2651 sc_read
&= radv_sc_read(fd_secure_input
, ep_name
, name_size
, true);
2652 pStage
->pName
= ep_name
;
2654 /* Read shader module */
2656 sc_read
&= radv_sc_read(fd_secure_input
, &module_size
, sizeof(size_t), true);
2658 goto secure_compile_exit
;
2660 struct radv_shader_module
*module
= malloc(module_size
);
2661 sc_read
&= radv_sc_read(fd_secure_input
, module
, module_size
, true);
2662 pStage
->module
= radv_shader_module_to_handle(module
);
2664 /* Read specialization info */
2666 sc_read
&= radv_sc_read(fd_secure_input
, &has_spec_info
, sizeof(bool), true);
2668 goto secure_compile_exit
;
2670 if (has_spec_info
) {
2671 VkSpecializationInfo
*specInfo
= malloc(sizeof(VkSpecializationInfo
));
2672 pStage
->pSpecializationInfo
= specInfo
;
2674 sc_read
&= radv_sc_read(fd_secure_input
, &specInfo
->dataSize
, sizeof(size_t), true);
2676 goto secure_compile_exit
;
2678 void *si_data
= malloc(specInfo
->dataSize
);
2679 sc_read
&= radv_sc_read(fd_secure_input
, si_data
, specInfo
->dataSize
, true);
2680 specInfo
->pData
= si_data
;
2682 sc_read
&= radv_sc_read(fd_secure_input
, &specInfo
->mapEntryCount
, sizeof(uint32_t), true);
2684 goto secure_compile_exit
;
2686 VkSpecializationMapEntry
*mapEntries
= malloc(sizeof(VkSpecializationMapEntry
) * specInfo
->mapEntryCount
);
2687 for (uint32_t j
= 0; j
< specInfo
->mapEntryCount
; j
++) {
2688 sc_read
&= radv_sc_read(fd_secure_input
, &mapEntries
[j
], sizeof(VkSpecializationMapEntry
), true);
2690 goto secure_compile_exit
;
2693 specInfo
->pMapEntries
= mapEntries
;
2696 pStages
[stage
] = pStage
;
2699 /* Compile the shaders */
2700 VkPipelineCreationFeedbackEXT
*stage_feedbacks
[MESA_SHADER_STAGES
] = { 0 };
2702 /* Not fully to spec but if we're doing sandboxed compilations already this doesn't matter. */
2703 flags
&= ~VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT
;
2705 radv_create_shaders(pipeline
, device
, NULL
, &key
, pStages
, flags
, NULL
, stage_feedbacks
);
2707 /* free memory allocated above */
2708 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++)
2709 free(layout
.set
[set
].layout
);
2711 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
2715 free((void *) pStages
[i
]->pName
);
2716 free(radv_shader_module_from_handle(pStages
[i
]->module
));
2717 if (pStages
[i
]->pSpecializationInfo
) {
2718 free((void *) pStages
[i
]->pSpecializationInfo
->pData
);
2719 free((void *) pStages
[i
]->pSpecializationInfo
->pMapEntries
);
2720 free((void *) pStages
[i
]->pSpecializationInfo
);
2722 free((void *) pStages
[i
]);
2725 vk_free(&device
->vk
.alloc
, pipeline
);
2727 sc_type
= RADV_SC_TYPE_COMPILE_PIPELINE_FINISHED
;
2728 write(fd_secure_output
, &sc_type
, sizeof(sc_type
));
2730 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2731 goto secure_compile_exit
;
2735 secure_compile_exit
:
2736 close(fd_secure_input
);
2737 close(fd_secure_output
);
2738 close(fd_idle_device_output
);
2742 static enum radv_secure_compile_type
fork_secure_compile_device(struct radv_device
*device
, unsigned process
)
2744 int fd_secure_input
[2];
2745 int fd_secure_output
[2];
2747 /* create pipe descriptors (used to communicate between processes) */
2748 if (pipe(fd_secure_input
) == -1 || pipe(fd_secure_output
) == -1)
2749 return RADV_SC_TYPE_INIT_FAILURE
;
2753 if ((sc_pid
= fork()) == 0) {
2754 device
->sc_state
->secure_compile_thread_counter
= process
;
2755 run_secure_compile_device(device
, process
, fd_secure_output
[1]);
2758 return RADV_SC_TYPE_INIT_FAILURE
;
2760 /* Read the init result returned from the secure process */
2761 enum radv_secure_compile_type sc_type
;
2762 bool sc_read
= radv_sc_read(fd_secure_output
[0], &sc_type
, sizeof(sc_type
), true);
2764 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
) {
2765 close(fd_secure_input
[0]);
2766 close(fd_secure_input
[1]);
2767 close(fd_secure_output
[1]);
2768 close(fd_secure_output
[0]);
2770 waitpid(sc_pid
, &status
, 0);
2772 return RADV_SC_TYPE_INIT_FAILURE
;
2774 assert(sc_type
== RADV_SC_TYPE_INIT_SUCCESS
);
2775 write(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
, &sc_type
, sizeof(sc_type
));
2777 close(fd_secure_input
[0]);
2778 close(fd_secure_input
[1]);
2779 close(fd_secure_output
[1]);
2780 close(fd_secure_output
[0]);
2783 waitpid(sc_pid
, &status
, 0);
2787 return RADV_SC_TYPE_INIT_SUCCESS
;
2790 /* Run a bare bones fork of a device that was forked right after its creation.
2791 * This device will have low overhead when it is forked again before each
2792 * pipeline compilation. This device sits idle and its only job is to fork
2795 static void run_secure_compile_idle_device(struct radv_device
*device
, unsigned process
,
2796 int fd_secure_input
, int fd_secure_output
)
2798 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2799 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
;
2800 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
;
2802 write(fd_secure_output
, &sc_type
, sizeof(sc_type
));
2805 radv_sc_read(fd_secure_input
, &sc_type
, sizeof(sc_type
), false);
2807 if (sc_type
== RADV_SC_TYPE_FORK_DEVICE
) {
2808 sc_type
= fork_secure_compile_device(device
, process
);
2810 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2811 goto secure_compile_exit
;
2813 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2814 goto secure_compile_exit
;
2818 secure_compile_exit
:
2819 close(fd_secure_input
);
2820 close(fd_secure_output
);
2824 static void destroy_secure_compile_device(struct radv_device
*device
, unsigned process
)
2826 int fd_secure_input
= device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
;
2828 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_DESTROY_DEVICE
;
2829 write(fd_secure_input
, &sc_type
, sizeof(sc_type
));
2831 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
);
2832 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
);
2835 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2838 static VkResult
fork_secure_compile_idle_device(struct radv_device
*device
)
2840 device
->sc_state
= vk_zalloc(&device
->vk
.alloc
,
2841 sizeof(struct radv_secure_compile_state
),
2842 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2844 mtx_init(&device
->sc_state
->secure_compile_mutex
, mtx_plain
);
2846 pid_t upid
= getpid();
2847 time_t seconds
= time(NULL
);
2850 if (asprintf(&uid
, "%ld_%ld", (long) upid
, (long) seconds
) == -1)
2851 return VK_ERROR_INITIALIZATION_FAILED
;
2853 device
->sc_state
->uid
= uid
;
2855 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
2856 int fd_secure_input
[MAX_SC_PROCS
][2];
2857 int fd_secure_output
[MAX_SC_PROCS
][2];
2859 /* create pipe descriptors (used to communicate between processes) */
2860 for (unsigned i
= 0; i
< sc_threads
; i
++) {
2861 if (pipe(fd_secure_input
[i
]) == -1 ||
2862 pipe(fd_secure_output
[i
]) == -1) {
2863 return VK_ERROR_INITIALIZATION_FAILED
;
2867 device
->sc_state
->secure_compile_processes
= vk_zalloc(&device
->vk
.alloc
,
2868 sizeof(struct radv_secure_compile_process
) * sc_threads
, 8,
2869 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2871 for (unsigned process
= 0; process
< sc_threads
; process
++) {
2872 if ((device
->sc_state
->secure_compile_processes
[process
].sc_pid
= fork()) == 0) {
2873 device
->sc_state
->secure_compile_thread_counter
= process
;
2874 run_secure_compile_idle_device(device
, process
, fd_secure_input
[process
][0], fd_secure_output
[process
][1]);
2876 if (device
->sc_state
->secure_compile_processes
[process
].sc_pid
== -1)
2877 return VK_ERROR_INITIALIZATION_FAILED
;
2879 /* Read the init result returned from the secure process */
2880 enum radv_secure_compile_type sc_type
;
2881 bool sc_read
= radv_sc_read(fd_secure_output
[process
][0], &sc_type
, sizeof(sc_type
), true);
2884 if (sc_read
&& sc_type
== RADV_SC_TYPE_INIT_SUCCESS
) {
2885 fifo_result
= secure_compile_open_fifo_fds(device
->sc_state
,
2886 &device
->sc_state
->secure_compile_processes
[process
].fd_server
,
2887 &device
->sc_state
->secure_compile_processes
[process
].fd_client
,
2890 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
[process
][1];
2891 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
[process
][0];
2894 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
|| !fifo_result
) {
2895 close(fd_secure_input
[process
][0]);
2896 close(fd_secure_input
[process
][1]);
2897 close(fd_secure_output
[process
][1]);
2898 close(fd_secure_output
[process
][0]);
2900 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2902 /* Destroy any forks that were created sucessfully */
2903 for (unsigned i
= 0; i
< process
; i
++) {
2904 destroy_secure_compile_device(device
, i
);
2907 return VK_ERROR_INITIALIZATION_FAILED
;
2915 radv_device_init_dispatch(struct radv_device
*device
)
2917 const struct radv_instance
*instance
= device
->physical_device
->instance
;
2918 const struct radv_device_dispatch_table
*dispatch_table_layer
= NULL
;
2919 bool unchecked
= instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
;
2920 int radv_thread_trace
= radv_get_int_debug_option("RADV_THREAD_TRACE", -1);
2922 if (radv_thread_trace
>= 0) {
2923 /* Use device entrypoints from the SQTT layer if enabled. */
2924 dispatch_table_layer
= &sqtt_device_dispatch_table
;
2927 for (unsigned i
= 0; i
< ARRAY_SIZE(device
->dispatch
.entrypoints
); i
++) {
2928 /* Vulkan requires that entrypoints for extensions which have not been
2929 * enabled must not be advertised.
2932 !radv_device_entrypoint_is_enabled(i
, instance
->apiVersion
,
2933 &instance
->enabled_extensions
,
2934 &device
->enabled_extensions
)) {
2935 device
->dispatch
.entrypoints
[i
] = NULL
;
2936 } else if (dispatch_table_layer
&&
2937 dispatch_table_layer
->entrypoints
[i
]) {
2938 device
->dispatch
.entrypoints
[i
] =
2939 dispatch_table_layer
->entrypoints
[i
];
2941 device
->dispatch
.entrypoints
[i
] =
2942 radv_device_dispatch_table
.entrypoints
[i
];
2948 radv_create_pthread_cond(pthread_cond_t
*cond
)
2950 pthread_condattr_t condattr
;
2951 if (pthread_condattr_init(&condattr
)) {
2952 return VK_ERROR_INITIALIZATION_FAILED
;
2955 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
)) {
2956 pthread_condattr_destroy(&condattr
);
2957 return VK_ERROR_INITIALIZATION_FAILED
;
2959 if (pthread_cond_init(cond
, &condattr
)) {
2960 pthread_condattr_destroy(&condattr
);
2961 return VK_ERROR_INITIALIZATION_FAILED
;
2963 pthread_condattr_destroy(&condattr
);
2968 check_physical_device_features(VkPhysicalDevice physicalDevice
,
2969 const VkPhysicalDeviceFeatures
*features
)
2971 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2972 VkPhysicalDeviceFeatures supported_features
;
2973 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2974 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2975 VkBool32
*enabled_feature
= (VkBool32
*)features
;
2976 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2977 for (uint32_t i
= 0; i
< num_features
; i
++) {
2978 if (enabled_feature
[i
] && !supported_feature
[i
])
2979 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
2985 static VkResult
radv_device_init_border_color(struct radv_device
*device
)
2987 device
->border_color_data
.bo
=
2988 device
->ws
->buffer_create(device
->ws
,
2989 RADV_BORDER_COLOR_BUFFER_SIZE
,
2992 RADEON_FLAG_CPU_ACCESS
|
2993 RADEON_FLAG_READ_ONLY
|
2994 RADEON_FLAG_NO_INTERPROCESS_SHARING
,
2995 RADV_BO_PRIORITY_SHADER
);
2997 if (device
->border_color_data
.bo
== NULL
)
2998 return vk_error(device
->physical_device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3000 device
->border_color_data
.colors_gpu_ptr
=
3001 device
->ws
->buffer_map(device
->border_color_data
.bo
);
3002 pthread_mutex_init(&device
->border_color_data
.mutex
, NULL
);
3007 static void radv_device_finish_border_color(struct radv_device
*device
)
3009 if (device
->border_color_data
.bo
) {
3010 device
->ws
->buffer_destroy(device
->border_color_data
.bo
);
3012 pthread_mutex_destroy(&device
->border_color_data
.mutex
);
3016 VkResult
radv_CreateDevice(
3017 VkPhysicalDevice physicalDevice
,
3018 const VkDeviceCreateInfo
* pCreateInfo
,
3019 const VkAllocationCallbacks
* pAllocator
,
3022 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
3024 struct radv_device
*device
;
3026 bool keep_shader_info
= false;
3027 bool robust_buffer_access
= false;
3028 bool overallocation_disallowed
= false;
3029 bool custom_border_colors
= false;
3031 /* Check enabled features */
3032 if (pCreateInfo
->pEnabledFeatures
) {
3033 result
= check_physical_device_features(physicalDevice
,
3034 pCreateInfo
->pEnabledFeatures
);
3035 if (result
!= VK_SUCCESS
)
3038 if (pCreateInfo
->pEnabledFeatures
->robustBufferAccess
)
3039 robust_buffer_access
= true;
3042 vk_foreach_struct_const(ext
, pCreateInfo
->pNext
) {
3043 switch (ext
->sType
) {
3044 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2
: {
3045 const VkPhysicalDeviceFeatures2
*features
= (const void *)ext
;
3046 result
= check_physical_device_features(physicalDevice
,
3047 &features
->features
);
3048 if (result
!= VK_SUCCESS
)
3051 if (features
->features
.robustBufferAccess
)
3052 robust_buffer_access
= true;
3055 case VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD
: {
3056 const VkDeviceMemoryOverallocationCreateInfoAMD
*overallocation
= (const void *)ext
;
3057 if (overallocation
->overallocationBehavior
== VK_MEMORY_OVERALLOCATION_BEHAVIOR_DISALLOWED_AMD
)
3058 overallocation_disallowed
= true;
3061 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT
: {
3062 const VkPhysicalDeviceCustomBorderColorFeaturesEXT
*border_color_features
= (const void *)ext
;
3063 custom_border_colors
= border_color_features
->customBorderColors
;
3071 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
3073 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
3075 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3077 vk_device_init(&device
->vk
, pCreateInfo
,
3078 &physical_device
->instance
->alloc
, pAllocator
);
3080 device
->instance
= physical_device
->instance
;
3081 device
->physical_device
= physical_device
;
3083 device
->ws
= physical_device
->ws
;
3085 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
3086 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
3087 int index
= radv_get_device_extension_index(ext_name
);
3088 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
3089 vk_free(&device
->vk
.alloc
, device
);
3090 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
3093 device
->enabled_extensions
.extensions
[index
] = true;
3096 radv_device_init_dispatch(device
);
3098 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
3100 /* With update after bind we can't attach bo's to the command buffer
3101 * from the descriptor set anymore, so we have to use a global BO list.
3103 device
->use_global_bo_list
=
3104 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
3105 device
->enabled_extensions
.EXT_descriptor_indexing
||
3106 device
->enabled_extensions
.EXT_buffer_device_address
||
3107 device
->enabled_extensions
.KHR_buffer_device_address
;
3109 device
->robust_buffer_access
= robust_buffer_access
;
3111 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
3112 list_inithead(&device
->shader_slabs
);
3114 device
->overallocation_disallowed
= overallocation_disallowed
;
3115 mtx_init(&device
->overallocation_mutex
, mtx_plain
);
3117 radv_bo_list_init(&device
->bo_list
);
3119 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
3120 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
3121 uint32_t qfi
= queue_create
->queueFamilyIndex
;
3122 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
3123 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
3125 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
3127 device
->queues
[qfi
] = vk_alloc(&device
->vk
.alloc
,
3128 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
3129 if (!device
->queues
[qfi
]) {
3130 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
3134 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
3136 device
->queue_count
[qfi
] = queue_create
->queueCount
;
3138 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
3139 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
3140 qfi
, q
, queue_create
->flags
,
3142 if (result
!= VK_SUCCESS
)
3147 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
3148 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
3150 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
3151 device
->dfsm_allowed
= device
->pbb_allowed
&&
3152 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
3154 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
3156 /* The maximum number of scratch waves. Scratch space isn't divided
3157 * evenly between CUs. The number is only a function of the number of CUs.
3158 * We can decrease the constant to decrease the scratch buffer size.
3160 * sctx->scratch_waves must be >= the maximum possible size of
3161 * 1 threadgroup, so that the hw doesn't hang from being unable
3164 * The recommended value is 4 per CU at most. Higher numbers don't
3165 * bring much benefit, but they still occupy chip resources (think
3166 * async compute). I've seen ~2% performance difference between 4 and 32.
3168 uint32_t max_threads_per_block
= 2048;
3169 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
3170 max_threads_per_block
/ 64);
3172 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
3174 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3175 /* If the KMD allows it (there is a KMD hw register for it),
3176 * allow launching waves out-of-order.
3178 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
3181 radv_device_init_gs_info(device
);
3183 device
->tess_offchip_block_dw_size
=
3184 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
3186 if (getenv("RADV_TRACE_FILE")) {
3187 const char *filename
= getenv("RADV_TRACE_FILE");
3189 keep_shader_info
= true;
3191 if (!radv_init_trace(device
))
3194 fprintf(stderr
, "*****************************************************************************\n");
3195 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
3196 fprintf(stderr
, "*****************************************************************************\n");
3198 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
3199 radv_dump_enabled_options(device
, stderr
);
3202 int radv_thread_trace
= radv_get_int_debug_option("RADV_THREAD_TRACE", -1);
3203 if (radv_thread_trace
>= 0) {
3204 fprintf(stderr
, "*************************************************\n");
3205 fprintf(stderr
, "* WARNING: Thread trace support is experimental *\n");
3206 fprintf(stderr
, "*************************************************\n");
3208 if (device
->physical_device
->rad_info
.chip_class
< GFX8
) {
3209 fprintf(stderr
, "GPU hardware not supported: refer to "
3210 "the RGP documentation for the list of "
3211 "supported GPUs!\n");
3215 /* Default buffer size set to 1MB per SE. */
3216 device
->thread_trace_buffer_size
=
3217 radv_get_int_debug_option("RADV_THREAD_TRACE_BUFFER_SIZE", 1024 * 1024);
3218 device
->thread_trace_start_frame
= radv_thread_trace
;
3220 if (!radv_thread_trace_init(device
))
3224 /* Temporarily disable secure compile while we create meta shaders, etc */
3225 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
3227 device
->instance
->num_sc_threads
= 0;
3229 device
->keep_shader_info
= keep_shader_info
;
3230 result
= radv_device_init_meta(device
);
3231 if (result
!= VK_SUCCESS
)
3234 radv_device_init_msaa(device
);
3236 /* If the border color extension is enabled, let's create the buffer we need. */
3237 if (custom_border_colors
) {
3238 result
= radv_device_init_border_color(device
);
3239 if (result
!= VK_SUCCESS
)
3243 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
3244 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
3246 case RADV_QUEUE_GENERAL
:
3247 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
3248 radeon_emit(device
->empty_cs
[family
], CC0_UPDATE_LOAD_ENABLES(1));
3249 radeon_emit(device
->empty_cs
[family
], CC1_UPDATE_SHADOW_ENABLES(1));
3251 case RADV_QUEUE_COMPUTE
:
3252 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
3253 radeon_emit(device
->empty_cs
[family
], 0);
3256 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
3259 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
3260 cik_create_gfx_config(device
);
3262 VkPipelineCacheCreateInfo ci
;
3263 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
3266 ci
.pInitialData
= NULL
;
3267 ci
.initialDataSize
= 0;
3269 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
3271 if (result
!= VK_SUCCESS
)
3274 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
3276 result
= radv_create_pthread_cond(&device
->timeline_cond
);
3277 if (result
!= VK_SUCCESS
)
3278 goto fail_mem_cache
;
3280 device
->force_aniso
=
3281 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
3282 if (device
->force_aniso
>= 0) {
3283 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
3284 1 << util_logbase2(device
->force_aniso
));
3287 /* Fork device for secure compile as required */
3288 device
->instance
->num_sc_threads
= sc_threads
;
3289 if (radv_device_use_secure_compile(device
->instance
)) {
3291 result
= fork_secure_compile_idle_device(device
);
3292 if (result
!= VK_SUCCESS
)
3296 *pDevice
= radv_device_to_handle(device
);
3300 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
3302 radv_device_finish_meta(device
);
3304 radv_bo_list_finish(&device
->bo_list
);
3306 radv_thread_trace_finish(device
);
3308 if (device
->trace_bo
)
3309 device
->ws
->buffer_destroy(device
->trace_bo
);
3311 if (device
->gfx_init
)
3312 device
->ws
->buffer_destroy(device
->gfx_init
);
3314 radv_device_finish_border_color(device
);
3316 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3317 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
3318 radv_queue_finish(&device
->queues
[i
][q
]);
3319 if (device
->queue_count
[i
])
3320 vk_free(&device
->vk
.alloc
, device
->queues
[i
]);
3323 vk_free(&device
->vk
.alloc
, device
);
3327 void radv_DestroyDevice(
3329 const VkAllocationCallbacks
* pAllocator
)
3331 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3336 if (device
->trace_bo
)
3337 device
->ws
->buffer_destroy(device
->trace_bo
);
3339 if (device
->gfx_init
)
3340 device
->ws
->buffer_destroy(device
->gfx_init
);
3342 radv_device_finish_border_color(device
);
3344 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3345 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
3346 radv_queue_finish(&device
->queues
[i
][q
]);
3347 if (device
->queue_count
[i
])
3348 vk_free(&device
->vk
.alloc
, device
->queues
[i
]);
3349 if (device
->empty_cs
[i
])
3350 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
3352 radv_device_finish_meta(device
);
3354 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
3355 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
3357 radv_destroy_shader_slabs(device
);
3359 pthread_cond_destroy(&device
->timeline_cond
);
3360 radv_bo_list_finish(&device
->bo_list
);
3362 radv_thread_trace_finish(device
);
3364 if (radv_device_use_secure_compile(device
->instance
)) {
3365 for (unsigned i
= 0; i
< device
->instance
->num_sc_threads
; i
++ ) {
3366 destroy_secure_compile_device(device
, i
);
3370 if (device
->sc_state
) {
3371 free(device
->sc_state
->uid
);
3372 vk_free(&device
->vk
.alloc
, device
->sc_state
->secure_compile_processes
);
3374 vk_free(&device
->vk
.alloc
, device
->sc_state
);
3375 vk_free(&device
->vk
.alloc
, device
);
3378 VkResult
radv_EnumerateInstanceLayerProperties(
3379 uint32_t* pPropertyCount
,
3380 VkLayerProperties
* pProperties
)
3382 if (pProperties
== NULL
) {
3383 *pPropertyCount
= 0;
3387 /* None supported at this time */
3388 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
3391 VkResult
radv_EnumerateDeviceLayerProperties(
3392 VkPhysicalDevice physicalDevice
,
3393 uint32_t* pPropertyCount
,
3394 VkLayerProperties
* pProperties
)
3396 if (pProperties
== NULL
) {
3397 *pPropertyCount
= 0;
3401 /* None supported at this time */
3402 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
3405 void radv_GetDeviceQueue2(
3407 const VkDeviceQueueInfo2
* pQueueInfo
,
3410 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3411 struct radv_queue
*queue
;
3413 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
3414 if (pQueueInfo
->flags
!= queue
->flags
) {
3415 /* From the Vulkan 1.1.70 spec:
3417 * "The queue returned by vkGetDeviceQueue2 must have the same
3418 * flags value from this structure as that used at device
3419 * creation time in a VkDeviceQueueCreateInfo instance. If no
3420 * matching flags were specified at device creation time then
3421 * pQueue will return VK_NULL_HANDLE."
3423 *pQueue
= VK_NULL_HANDLE
;
3427 *pQueue
= radv_queue_to_handle(queue
);
3430 void radv_GetDeviceQueue(
3432 uint32_t queueFamilyIndex
,
3433 uint32_t queueIndex
,
3436 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
3437 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
3438 .queueFamilyIndex
= queueFamilyIndex
,
3439 .queueIndex
= queueIndex
3442 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
3446 fill_geom_tess_rings(struct radv_queue
*queue
,
3448 bool add_sample_positions
,
3449 uint32_t esgs_ring_size
,
3450 struct radeon_winsys_bo
*esgs_ring_bo
,
3451 uint32_t gsvs_ring_size
,
3452 struct radeon_winsys_bo
*gsvs_ring_bo
,
3453 uint32_t tess_factor_ring_size
,
3454 uint32_t tess_offchip_ring_offset
,
3455 uint32_t tess_offchip_ring_size
,
3456 struct radeon_winsys_bo
*tess_rings_bo
)
3458 uint32_t *desc
= &map
[4];
3461 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
3463 /* stride 0, num records - size, add tid, swizzle, elsize4,
3466 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
3467 S_008F04_SWIZZLE_ENABLE(true);
3468 desc
[2] = esgs_ring_size
;
3469 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3470 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3471 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3472 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
3473 S_008F0C_INDEX_STRIDE(3) |
3474 S_008F0C_ADD_TID_ENABLE(1);
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_DISABLED
) |
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
) |
3483 S_008F0C_ELEMENT_SIZE(1);
3486 /* GS entry for ES->GS ring */
3487 /* stride 0, num records - size, elsize0,
3490 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
3491 desc
[6] = esgs_ring_size
;
3492 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3493 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3494 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3495 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3497 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3498 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3499 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3500 S_008F0C_RESOURCE_LEVEL(1);
3502 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3503 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3510 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
3512 /* VS entry for GS->VS ring */
3513 /* stride 0, num records - size, elsize0,
3516 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
3517 desc
[2] = gsvs_ring_size
;
3518 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3519 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3520 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3521 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3523 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3524 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3525 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3526 S_008F0C_RESOURCE_LEVEL(1);
3528 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3529 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3532 /* stride gsvs_itemsize, num records 64
3533 elsize 4, index stride 16 */
3534 /* shader will patch stride and desc[2] */
3536 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
3537 S_008F04_SWIZZLE_ENABLE(1);
3539 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3540 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3541 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3542 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
3543 S_008F0C_INDEX_STRIDE(1) |
3544 S_008F0C_ADD_TID_ENABLE(true);
3546 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3547 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3548 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_DISABLED
) |
3549 S_008F0C_RESOURCE_LEVEL(1);
3551 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3552 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
3553 S_008F0C_ELEMENT_SIZE(1);
3560 if (tess_rings_bo
) {
3561 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
3562 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
3565 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
3566 desc
[2] = tess_factor_ring_size
;
3567 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3568 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3569 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3570 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3572 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3573 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3574 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW
) |
3575 S_008F0C_RESOURCE_LEVEL(1);
3577 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3578 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3581 desc
[4] = tess_offchip_va
;
3582 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
3583 desc
[6] = tess_offchip_ring_size
;
3584 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
3585 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
3586 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
3587 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
3589 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3590 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
3591 S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW
) |
3592 S_008F0C_RESOURCE_LEVEL(1);
3594 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
3595 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
3601 if (add_sample_positions
) {
3602 /* add sample positions after all rings */
3603 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
3605 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
3607 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
3609 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
3614 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
3616 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
3617 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
3618 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
3619 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
3620 unsigned max_offchip_buffers
;
3621 unsigned offchip_granularity
;
3622 unsigned hs_offchip_param
;
3626 * This must be one less than the maximum number due to a hw limitation.
3627 * Various hardware bugs need thGFX7
3630 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
3631 * Gfx7 should limit max_offchip_buffers to 508
3632 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
3634 * Follow AMDVLK here.
3636 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3637 max_offchip_buffers_per_se
= 256;
3638 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
3639 device
->physical_device
->rad_info
.chip_class
== GFX7
||
3640 device
->physical_device
->rad_info
.chip_class
== GFX6
)
3641 --max_offchip_buffers_per_se
;
3643 max_offchip_buffers
= max_offchip_buffers_per_se
*
3644 device
->physical_device
->rad_info
.max_se
;
3646 /* Hawaii has a bug with offchip buffers > 256 that can be worked
3647 * around by setting 4K granularity.
3649 if (device
->tess_offchip_block_dw_size
== 4096) {
3650 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
3651 offchip_granularity
= V_03093C_X_4K_DWORDS
;
3653 assert(device
->tess_offchip_block_dw_size
== 8192);
3654 offchip_granularity
= V_03093C_X_8K_DWORDS
;
3657 switch (device
->physical_device
->rad_info
.chip_class
) {
3659 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
3664 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
3672 *max_offchip_buffers_p
= max_offchip_buffers
;
3673 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3674 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
3675 --max_offchip_buffers
;
3677 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
3678 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
3681 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
3683 return hs_offchip_param
;
3687 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3688 struct radeon_winsys_bo
*esgs_ring_bo
,
3689 uint32_t esgs_ring_size
,
3690 struct radeon_winsys_bo
*gsvs_ring_bo
,
3691 uint32_t gsvs_ring_size
)
3693 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
3697 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
3700 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
3702 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3703 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
3704 radeon_emit(cs
, esgs_ring_size
>> 8);
3705 radeon_emit(cs
, gsvs_ring_size
>> 8);
3707 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
3708 radeon_emit(cs
, esgs_ring_size
>> 8);
3709 radeon_emit(cs
, gsvs_ring_size
>> 8);
3714 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3715 unsigned hs_offchip_param
, unsigned tf_ring_size
,
3716 struct radeon_winsys_bo
*tess_rings_bo
)
3723 tf_va
= radv_buffer_get_va(tess_rings_bo
);
3725 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
3727 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
3728 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
3729 S_030938_SIZE(tf_ring_size
/ 4));
3730 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
3733 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3734 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
3735 S_030984_BASE_HI(tf_va
>> 40));
3736 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3737 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
3738 S_030944_BASE_HI(tf_va
>> 40));
3740 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
3743 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
3744 S_008988_SIZE(tf_ring_size
/ 4));
3745 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
3747 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
3753 radv_emit_graphics_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3754 uint32_t size_per_wave
, uint32_t waves
,
3755 struct radeon_winsys_bo
*scratch_bo
)
3757 if (queue
->queue_family_index
!= RADV_QUEUE_GENERAL
)
3763 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
3765 radeon_set_context_reg(cs
, R_0286E8_SPI_TMPRING_SIZE
,
3766 S_0286E8_WAVES(waves
) |
3767 S_0286E8_WAVESIZE(round_up_u32(size_per_wave
, 1024)));
3771 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
3772 uint32_t size_per_wave
, uint32_t waves
,
3773 struct radeon_winsys_bo
*compute_scratch_bo
)
3775 uint64_t scratch_va
;
3777 if (!compute_scratch_bo
)
3780 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
3782 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
3784 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
3785 radeon_emit(cs
, scratch_va
);
3786 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3787 S_008F04_SWIZZLE_ENABLE(1));
3789 radeon_set_sh_reg(cs
, R_00B860_COMPUTE_TMPRING_SIZE
,
3790 S_00B860_WAVES(waves
) |
3791 S_00B860_WAVESIZE(round_up_u32(size_per_wave
, 1024)));
3795 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
3796 struct radeon_cmdbuf
*cs
,
3797 struct radeon_winsys_bo
*descriptor_bo
)
3804 va
= radv_buffer_get_va(descriptor_bo
);
3806 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
3808 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3809 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3810 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3811 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3812 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3814 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3815 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3818 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3819 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3820 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3821 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3822 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3824 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3825 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3829 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3830 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3831 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
3832 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
3833 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
3834 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
3836 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3837 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3844 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3846 struct radv_device
*device
= queue
->device
;
3848 if (device
->gfx_init
) {
3849 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
3851 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
3852 radeon_emit(cs
, va
);
3853 radeon_emit(cs
, va
>> 32);
3854 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
3856 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
3858 si_emit_graphics(device
, cs
);
3863 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3865 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
3866 si_emit_compute(physical_device
, cs
);
3870 radv_get_preamble_cs(struct radv_queue
*queue
,
3871 uint32_t scratch_size_per_wave
,
3872 uint32_t scratch_waves
,
3873 uint32_t compute_scratch_size_per_wave
,
3874 uint32_t compute_scratch_waves
,
3875 uint32_t esgs_ring_size
,
3876 uint32_t gsvs_ring_size
,
3877 bool needs_tess_rings
,
3880 bool needs_sample_positions
,
3881 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
3882 struct radeon_cmdbuf
**initial_preamble_cs
,
3883 struct radeon_cmdbuf
**continue_preamble_cs
)
3885 struct radeon_winsys_bo
*scratch_bo
= NULL
;
3886 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
3887 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
3888 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
3889 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
3890 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
3891 struct radeon_winsys_bo
*gds_bo
= NULL
;
3892 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
3893 struct radeon_cmdbuf
*dest_cs
[3] = {0};
3894 bool add_tess_rings
= false, add_gds
= false, add_gds_oa
= false, add_sample_positions
= false;
3895 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
3896 unsigned max_offchip_buffers
;
3897 unsigned hs_offchip_param
= 0;
3898 unsigned tess_offchip_ring_offset
;
3899 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3900 if (!queue
->has_tess_rings
) {
3901 if (needs_tess_rings
)
3902 add_tess_rings
= true;
3904 if (!queue
->has_gds
) {
3908 if (!queue
->has_gds_oa
) {
3912 if (!queue
->has_sample_positions
) {
3913 if (needs_sample_positions
)
3914 add_sample_positions
= true;
3916 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
3917 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
3918 &max_offchip_buffers
);
3919 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
3920 tess_offchip_ring_size
= max_offchip_buffers
*
3921 queue
->device
->tess_offchip_block_dw_size
* 4;
3923 scratch_size_per_wave
= MAX2(scratch_size_per_wave
, queue
->scratch_size_per_wave
);
3924 if (scratch_size_per_wave
)
3925 scratch_waves
= MIN2(scratch_waves
, UINT32_MAX
/ scratch_size_per_wave
);
3929 compute_scratch_size_per_wave
= MAX2(compute_scratch_size_per_wave
, queue
->compute_scratch_size_per_wave
);
3930 if (compute_scratch_size_per_wave
)
3931 compute_scratch_waves
= MIN2(compute_scratch_waves
, UINT32_MAX
/ compute_scratch_size_per_wave
);
3933 compute_scratch_waves
= 0;
3935 if (scratch_size_per_wave
<= queue
->scratch_size_per_wave
&&
3936 scratch_waves
<= queue
->scratch_waves
&&
3937 compute_scratch_size_per_wave
<= queue
->compute_scratch_size_per_wave
&&
3938 compute_scratch_waves
<= queue
->compute_scratch_waves
&&
3939 esgs_ring_size
<= queue
->esgs_ring_size
&&
3940 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
3941 !add_tess_rings
&& !add_gds
&& !add_gds_oa
&& !add_sample_positions
&&
3942 queue
->initial_preamble_cs
) {
3943 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
3944 *initial_preamble_cs
= queue
->initial_preamble_cs
;
3945 *continue_preamble_cs
= queue
->continue_preamble_cs
;
3946 if (!scratch_size_per_wave
&& !compute_scratch_size_per_wave
&&
3947 !esgs_ring_size
&& !gsvs_ring_size
&& !needs_tess_rings
&&
3948 !needs_gds
&& !needs_gds_oa
&& !needs_sample_positions
)
3949 *continue_preamble_cs
= NULL
;
3953 uint32_t scratch_size
= scratch_size_per_wave
* scratch_waves
;
3954 uint32_t queue_scratch_size
= queue
->scratch_size_per_wave
* queue
->scratch_waves
;
3955 if (scratch_size
> queue_scratch_size
) {
3956 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3961 RADV_BO_PRIORITY_SCRATCH
);
3965 scratch_bo
= queue
->scratch_bo
;
3967 uint32_t compute_scratch_size
= compute_scratch_size_per_wave
* compute_scratch_waves
;
3968 uint32_t compute_queue_scratch_size
= queue
->compute_scratch_size_per_wave
* queue
->compute_scratch_waves
;
3969 if (compute_scratch_size
> compute_queue_scratch_size
) {
3970 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3971 compute_scratch_size
,
3975 RADV_BO_PRIORITY_SCRATCH
);
3976 if (!compute_scratch_bo
)
3980 compute_scratch_bo
= queue
->compute_scratch_bo
;
3982 if (esgs_ring_size
> queue
->esgs_ring_size
) {
3983 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3988 RADV_BO_PRIORITY_SCRATCH
);
3992 esgs_ring_bo
= queue
->esgs_ring_bo
;
3993 esgs_ring_size
= queue
->esgs_ring_size
;
3996 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
3997 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
4002 RADV_BO_PRIORITY_SCRATCH
);
4006 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
4007 gsvs_ring_size
= queue
->gsvs_ring_size
;
4010 if (add_tess_rings
) {
4011 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
4012 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
4016 RADV_BO_PRIORITY_SCRATCH
);
4020 tess_rings_bo
= queue
->tess_rings_bo
;
4024 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
4026 /* 4 streamout GDS counters.
4027 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
4029 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
4033 RADV_BO_PRIORITY_SCRATCH
);
4037 gds_bo
= queue
->gds_bo
;
4041 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
4043 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
4047 RADV_BO_PRIORITY_SCRATCH
);
4051 gds_oa_bo
= queue
->gds_oa_bo
;
4054 if (scratch_bo
!= queue
->scratch_bo
||
4055 esgs_ring_bo
!= queue
->esgs_ring_bo
||
4056 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
4057 tess_rings_bo
!= queue
->tess_rings_bo
||
4058 add_sample_positions
) {
4060 if (gsvs_ring_bo
|| esgs_ring_bo
||
4061 tess_rings_bo
|| add_sample_positions
) {
4062 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
4063 if (add_sample_positions
)
4064 size
+= 128; /* 64+32+16+8 = 120 bytes */
4066 else if (scratch_bo
)
4067 size
= 8; /* 2 dword */
4069 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
4073 RADEON_FLAG_CPU_ACCESS
|
4074 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
4075 RADEON_FLAG_READ_ONLY
,
4076 RADV_BO_PRIORITY_DESCRIPTOR
);
4080 descriptor_bo
= queue
->descriptor_bo
;
4082 if (descriptor_bo
!= queue
->descriptor_bo
) {
4083 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
4086 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
4087 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
4088 S_008F04_SWIZZLE_ENABLE(1);
4089 map
[0] = scratch_va
;
4093 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
4094 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
4095 esgs_ring_size
, esgs_ring_bo
,
4096 gsvs_ring_size
, gsvs_ring_bo
,
4097 tess_factor_ring_size
,
4098 tess_offchip_ring_offset
,
4099 tess_offchip_ring_size
,
4102 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
4105 for(int i
= 0; i
< 3; ++i
) {
4106 struct radeon_cmdbuf
*cs
= NULL
;
4107 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
4108 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
4115 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
4117 /* Emit initial configuration. */
4118 switch (queue
->queue_family_index
) {
4119 case RADV_QUEUE_GENERAL
:
4120 radv_init_graphics_state(cs
, queue
);
4122 case RADV_QUEUE_COMPUTE
:
4123 radv_init_compute_state(cs
, queue
);
4125 case RADV_QUEUE_TRANSFER
:
4129 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
4130 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
4131 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
4133 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
4134 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
4137 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
4138 gsvs_ring_bo
, gsvs_ring_size
);
4139 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
4140 tess_factor_ring_size
, tess_rings_bo
);
4141 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
4142 radv_emit_compute_scratch(queue
, cs
, compute_scratch_size_per_wave
,
4143 compute_scratch_waves
, compute_scratch_bo
);
4144 radv_emit_graphics_scratch(queue
, cs
, scratch_size_per_wave
,
4145 scratch_waves
, scratch_bo
);
4148 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
4150 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
4152 if (queue
->device
->trace_bo
)
4153 radv_cs_add_buffer(queue
->device
->ws
, cs
, queue
->device
->trace_bo
);
4156 si_cs_emit_cache_flush(cs
,
4157 queue
->device
->physical_device
->rad_info
.chip_class
,
4159 queue
->queue_family_index
== RING_COMPUTE
&&
4160 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
4161 (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
)) |
4162 RADV_CMD_FLAG_INV_ICACHE
|
4163 RADV_CMD_FLAG_INV_SCACHE
|
4164 RADV_CMD_FLAG_INV_VCACHE
|
4165 RADV_CMD_FLAG_INV_L2
|
4166 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
4167 } else if (i
== 1) {
4168 si_cs_emit_cache_flush(cs
,
4169 queue
->device
->physical_device
->rad_info
.chip_class
,
4171 queue
->queue_family_index
== RING_COMPUTE
&&
4172 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
4173 RADV_CMD_FLAG_INV_ICACHE
|
4174 RADV_CMD_FLAG_INV_SCACHE
|
4175 RADV_CMD_FLAG_INV_VCACHE
|
4176 RADV_CMD_FLAG_INV_L2
|
4177 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
4180 if (!queue
->device
->ws
->cs_finalize(cs
))
4184 if (queue
->initial_full_flush_preamble_cs
)
4185 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
4187 if (queue
->initial_preamble_cs
)
4188 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
4190 if (queue
->continue_preamble_cs
)
4191 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
4193 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
4194 queue
->initial_preamble_cs
= dest_cs
[1];
4195 queue
->continue_preamble_cs
= dest_cs
[2];
4197 if (scratch_bo
!= queue
->scratch_bo
) {
4198 if (queue
->scratch_bo
)
4199 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
4200 queue
->scratch_bo
= scratch_bo
;
4202 queue
->scratch_size_per_wave
= scratch_size_per_wave
;
4203 queue
->scratch_waves
= scratch_waves
;
4205 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
4206 if (queue
->compute_scratch_bo
)
4207 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
4208 queue
->compute_scratch_bo
= compute_scratch_bo
;
4210 queue
->compute_scratch_size_per_wave
= compute_scratch_size_per_wave
;
4211 queue
->compute_scratch_waves
= compute_scratch_waves
;
4213 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
4214 if (queue
->esgs_ring_bo
)
4215 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
4216 queue
->esgs_ring_bo
= esgs_ring_bo
;
4217 queue
->esgs_ring_size
= esgs_ring_size
;
4220 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
4221 if (queue
->gsvs_ring_bo
)
4222 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
4223 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
4224 queue
->gsvs_ring_size
= gsvs_ring_size
;
4227 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
4228 queue
->tess_rings_bo
= tess_rings_bo
;
4229 queue
->has_tess_rings
= true;
4232 if (gds_bo
!= queue
->gds_bo
) {
4233 queue
->gds_bo
= gds_bo
;
4234 queue
->has_gds
= true;
4237 if (gds_oa_bo
!= queue
->gds_oa_bo
) {
4238 queue
->gds_oa_bo
= gds_oa_bo
;
4239 queue
->has_gds_oa
= true;
4242 if (descriptor_bo
!= queue
->descriptor_bo
) {
4243 if (queue
->descriptor_bo
)
4244 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
4246 queue
->descriptor_bo
= descriptor_bo
;
4249 if (add_sample_positions
)
4250 queue
->has_sample_positions
= true;
4252 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
4253 *initial_preamble_cs
= queue
->initial_preamble_cs
;
4254 *continue_preamble_cs
= queue
->continue_preamble_cs
;
4255 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
4256 *continue_preamble_cs
= NULL
;
4259 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
4261 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
4262 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
4263 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
4264 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
4265 queue
->device
->ws
->buffer_destroy(scratch_bo
);
4266 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
4267 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
4268 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
4269 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
4270 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
4271 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
4272 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
4273 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
4274 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
4275 queue
->device
->ws
->buffer_destroy(gds_bo
);
4276 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
4277 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
4279 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4282 static VkResult
radv_alloc_sem_counts(struct radv_device
*device
,
4283 struct radv_winsys_sem_counts
*counts
,
4285 struct radv_semaphore_part
**sems
,
4286 const uint64_t *timeline_values
,
4290 int syncobj_idx
= 0, sem_idx
= 0;
4292 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
4295 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4296 switch(sems
[i
]->kind
) {
4297 case RADV_SEMAPHORE_SYNCOBJ
:
4298 counts
->syncobj_count
++;
4300 case RADV_SEMAPHORE_WINSYS
:
4301 counts
->sem_count
++;
4303 case RADV_SEMAPHORE_NONE
:
4305 case RADV_SEMAPHORE_TIMELINE
:
4306 counts
->syncobj_count
++;
4311 if (_fence
!= VK_NULL_HANDLE
) {
4312 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4313 if (fence
->temp_syncobj
|| fence
->syncobj
)
4314 counts
->syncobj_count
++;
4317 if (counts
->syncobj_count
) {
4318 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
4319 if (!counts
->syncobj
)
4320 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4323 if (counts
->sem_count
) {
4324 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
4326 free(counts
->syncobj
);
4327 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4331 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4332 switch(sems
[i
]->kind
) {
4333 case RADV_SEMAPHORE_NONE
:
4334 unreachable("Empty semaphore");
4336 case RADV_SEMAPHORE_SYNCOBJ
:
4337 counts
->syncobj
[syncobj_idx
++] = sems
[i
]->syncobj
;
4339 case RADV_SEMAPHORE_WINSYS
:
4340 counts
->sem
[sem_idx
++] = sems
[i
]->ws_sem
;
4342 case RADV_SEMAPHORE_TIMELINE
: {
4343 pthread_mutex_lock(&sems
[i
]->timeline
.mutex
);
4344 struct radv_timeline_point
*point
= NULL
;
4346 point
= radv_timeline_add_point_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
4348 point
= radv_timeline_find_point_at_least_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
4351 pthread_mutex_unlock(&sems
[i
]->timeline
.mutex
);
4354 counts
->syncobj
[syncobj_idx
++] = point
->syncobj
;
4356 /* Explicitly remove the semaphore so we might not find
4357 * a point later post-submit. */
4365 if (_fence
!= VK_NULL_HANDLE
) {
4366 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4367 if (fence
->temp_syncobj
)
4368 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
4369 else if (fence
->syncobj
)
4370 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
4373 assert(syncobj_idx
<= counts
->syncobj_count
);
4374 counts
->syncobj_count
= syncobj_idx
;
4380 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
4382 free(sem_info
->wait
.syncobj
);
4383 free(sem_info
->wait
.sem
);
4384 free(sem_info
->signal
.syncobj
);
4385 free(sem_info
->signal
.sem
);
4389 static void radv_free_temp_syncobjs(struct radv_device
*device
,
4391 struct radv_semaphore_part
*sems
)
4393 for (uint32_t i
= 0; i
< num_sems
; i
++) {
4394 radv_destroy_semaphore_part(device
, sems
+ i
);
4399 radv_alloc_sem_info(struct radv_device
*device
,
4400 struct radv_winsys_sem_info
*sem_info
,
4402 struct radv_semaphore_part
**wait_sems
,
4403 const uint64_t *wait_values
,
4404 int num_signal_sems
,
4405 struct radv_semaphore_part
**signal_sems
,
4406 const uint64_t *signal_values
,
4410 memset(sem_info
, 0, sizeof(*sem_info
));
4412 ret
= radv_alloc_sem_counts(device
, &sem_info
->wait
, num_wait_sems
, wait_sems
, wait_values
, VK_NULL_HANDLE
, false);
4415 ret
= radv_alloc_sem_counts(device
, &sem_info
->signal
, num_signal_sems
, signal_sems
, signal_values
, fence
, true);
4417 radv_free_sem_info(sem_info
);
4419 /* caller can override these */
4420 sem_info
->cs_emit_wait
= true;
4421 sem_info
->cs_emit_signal
= true;
4426 radv_finalize_timelines(struct radv_device
*device
,
4427 uint32_t num_wait_sems
,
4428 struct radv_semaphore_part
**wait_sems
,
4429 const uint64_t *wait_values
,
4430 uint32_t num_signal_sems
,
4431 struct radv_semaphore_part
**signal_sems
,
4432 const uint64_t *signal_values
,
4433 struct list_head
*processing_list
)
4435 for (uint32_t i
= 0; i
< num_wait_sems
; ++i
) {
4436 if (wait_sems
[i
] && wait_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4437 pthread_mutex_lock(&wait_sems
[i
]->timeline
.mutex
);
4438 struct radv_timeline_point
*point
=
4439 radv_timeline_find_point_at_least_locked(device
, &wait_sems
[i
]->timeline
, wait_values
[i
]);
4440 point
->wait_count
-= 2;
4441 pthread_mutex_unlock(&wait_sems
[i
]->timeline
.mutex
);
4444 for (uint32_t i
= 0; i
< num_signal_sems
; ++i
) {
4445 if (signal_sems
[i
] && signal_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4446 pthread_mutex_lock(&signal_sems
[i
]->timeline
.mutex
);
4447 struct radv_timeline_point
*point
=
4448 radv_timeline_find_point_at_least_locked(device
, &signal_sems
[i
]->timeline
, signal_values
[i
]);
4449 signal_sems
[i
]->timeline
.highest_submitted
=
4450 MAX2(signal_sems
[i
]->timeline
.highest_submitted
, point
->value
);
4451 point
->wait_count
-= 2;
4452 radv_timeline_trigger_waiters_locked(&signal_sems
[i
]->timeline
, processing_list
);
4453 pthread_mutex_unlock(&signal_sems
[i
]->timeline
.mutex
);
4459 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
4460 const VkSparseBufferMemoryBindInfo
*bind
)
4462 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
4464 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
4465 struct radv_device_memory
*mem
= NULL
;
4467 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
4468 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
4470 device
->ws
->buffer_virtual_bind(buffer
->bo
,
4471 bind
->pBinds
[i
].resourceOffset
,
4472 bind
->pBinds
[i
].size
,
4473 mem
? mem
->bo
: NULL
,
4474 bind
->pBinds
[i
].memoryOffset
);
4479 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
4480 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
4482 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
4484 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
4485 struct radv_device_memory
*mem
= NULL
;
4487 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
4488 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
4490 device
->ws
->buffer_virtual_bind(image
->bo
,
4491 bind
->pBinds
[i
].resourceOffset
,
4492 bind
->pBinds
[i
].size
,
4493 mem
? mem
->bo
: NULL
,
4494 bind
->pBinds
[i
].memoryOffset
);
4499 radv_get_preambles(struct radv_queue
*queue
,
4500 const VkCommandBuffer
*cmd_buffers
,
4501 uint32_t cmd_buffer_count
,
4502 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
4503 struct radeon_cmdbuf
**initial_preamble_cs
,
4504 struct radeon_cmdbuf
**continue_preamble_cs
)
4506 uint32_t scratch_size_per_wave
= 0, waves_wanted
= 0;
4507 uint32_t compute_scratch_size_per_wave
= 0, compute_waves_wanted
= 0;
4508 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
4509 bool tess_rings_needed
= false;
4510 bool gds_needed
= false;
4511 bool gds_oa_needed
= false;
4512 bool sample_positions_needed
= false;
4514 for (uint32_t j
= 0; j
< cmd_buffer_count
; j
++) {
4515 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
4518 scratch_size_per_wave
= MAX2(scratch_size_per_wave
, cmd_buffer
->scratch_size_per_wave_needed
);
4519 waves_wanted
= MAX2(waves_wanted
, cmd_buffer
->scratch_waves_wanted
);
4520 compute_scratch_size_per_wave
= MAX2(compute_scratch_size_per_wave
,
4521 cmd_buffer
->compute_scratch_size_per_wave_needed
);
4522 compute_waves_wanted
= MAX2(compute_waves_wanted
,
4523 cmd_buffer
->compute_scratch_waves_wanted
);
4524 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
4525 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
4526 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
4527 gds_needed
|= cmd_buffer
->gds_needed
;
4528 gds_oa_needed
|= cmd_buffer
->gds_oa_needed
;
4529 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
4532 return radv_get_preamble_cs(queue
, scratch_size_per_wave
, waves_wanted
,
4533 compute_scratch_size_per_wave
, compute_waves_wanted
,
4534 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
4535 gds_needed
, gds_oa_needed
, sample_positions_needed
,
4536 initial_full_flush_preamble_cs
,
4537 initial_preamble_cs
, continue_preamble_cs
);
4540 struct radv_deferred_queue_submission
{
4541 struct radv_queue
*queue
;
4542 VkCommandBuffer
*cmd_buffers
;
4543 uint32_t cmd_buffer_count
;
4545 /* Sparse bindings that happen on a queue. */
4546 VkSparseBufferMemoryBindInfo
*buffer_binds
;
4547 uint32_t buffer_bind_count
;
4548 VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
4549 uint32_t image_opaque_bind_count
;
4552 VkShaderStageFlags wait_dst_stage_mask
;
4553 struct radv_semaphore_part
**wait_semaphores
;
4554 uint32_t wait_semaphore_count
;
4555 struct radv_semaphore_part
**signal_semaphores
;
4556 uint32_t signal_semaphore_count
;
4559 uint64_t *wait_values
;
4560 uint64_t *signal_values
;
4562 struct radv_semaphore_part
*temporary_semaphore_parts
;
4563 uint32_t temporary_semaphore_part_count
;
4565 struct list_head queue_pending_list
;
4566 uint32_t submission_wait_count
;
4567 struct radv_timeline_waiter
*wait_nodes
;
4569 struct list_head processing_list
;
4572 struct radv_queue_submission
{
4573 const VkCommandBuffer
*cmd_buffers
;
4574 uint32_t cmd_buffer_count
;
4576 /* Sparse bindings that happen on a queue. */
4577 const VkSparseBufferMemoryBindInfo
*buffer_binds
;
4578 uint32_t buffer_bind_count
;
4579 const VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
4580 uint32_t image_opaque_bind_count
;
4583 VkPipelineStageFlags wait_dst_stage_mask
;
4584 const VkSemaphore
*wait_semaphores
;
4585 uint32_t wait_semaphore_count
;
4586 const VkSemaphore
*signal_semaphores
;
4587 uint32_t signal_semaphore_count
;
4590 const uint64_t *wait_values
;
4591 uint32_t wait_value_count
;
4592 const uint64_t *signal_values
;
4593 uint32_t signal_value_count
;
4597 radv_create_deferred_submission(struct radv_queue
*queue
,
4598 const struct radv_queue_submission
*submission
,
4599 struct radv_deferred_queue_submission
**out
)
4601 struct radv_deferred_queue_submission
*deferred
= NULL
;
4602 size_t size
= sizeof(struct radv_deferred_queue_submission
);
4604 uint32_t temporary_count
= 0;
4605 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4606 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
4607 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
)
4611 size
+= submission
->cmd_buffer_count
* sizeof(VkCommandBuffer
);
4612 size
+= submission
->buffer_bind_count
* sizeof(VkSparseBufferMemoryBindInfo
);
4613 size
+= submission
->image_opaque_bind_count
* sizeof(VkSparseImageOpaqueMemoryBindInfo
);
4614 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_semaphore_part
*);
4615 size
+= temporary_count
* sizeof(struct radv_semaphore_part
);
4616 size
+= submission
->signal_semaphore_count
* sizeof(struct radv_semaphore_part
*);
4617 size
+= submission
->wait_value_count
* sizeof(uint64_t);
4618 size
+= submission
->signal_value_count
* sizeof(uint64_t);
4619 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_timeline_waiter
);
4621 deferred
= calloc(1, size
);
4623 return VK_ERROR_OUT_OF_HOST_MEMORY
;
4625 deferred
->queue
= queue
;
4627 deferred
->cmd_buffers
= (void*)(deferred
+ 1);
4628 deferred
->cmd_buffer_count
= submission
->cmd_buffer_count
;
4629 memcpy(deferred
->cmd_buffers
, submission
->cmd_buffers
,
4630 submission
->cmd_buffer_count
* sizeof(*deferred
->cmd_buffers
));
4632 deferred
->buffer_binds
= (void*)(deferred
->cmd_buffers
+ submission
->cmd_buffer_count
);
4633 deferred
->buffer_bind_count
= submission
->buffer_bind_count
;
4634 memcpy(deferred
->buffer_binds
, submission
->buffer_binds
,
4635 submission
->buffer_bind_count
* sizeof(*deferred
->buffer_binds
));
4637 deferred
->image_opaque_binds
= (void*)(deferred
->buffer_binds
+ submission
->buffer_bind_count
);
4638 deferred
->image_opaque_bind_count
= submission
->image_opaque_bind_count
;
4639 memcpy(deferred
->image_opaque_binds
, submission
->image_opaque_binds
,
4640 submission
->image_opaque_bind_count
* sizeof(*deferred
->image_opaque_binds
));
4642 deferred
->flush_caches
= submission
->flush_caches
;
4643 deferred
->wait_dst_stage_mask
= submission
->wait_dst_stage_mask
;
4645 deferred
->wait_semaphores
= (void*)(deferred
->image_opaque_binds
+ deferred
->image_opaque_bind_count
);
4646 deferred
->wait_semaphore_count
= submission
->wait_semaphore_count
;
4648 deferred
->signal_semaphores
= (void*)(deferred
->wait_semaphores
+ deferred
->wait_semaphore_count
);
4649 deferred
->signal_semaphore_count
= submission
->signal_semaphore_count
;
4651 deferred
->fence
= submission
->fence
;
4653 deferred
->temporary_semaphore_parts
= (void*)(deferred
->signal_semaphores
+ deferred
->signal_semaphore_count
);
4654 deferred
->temporary_semaphore_part_count
= temporary_count
;
4656 uint32_t temporary_idx
= 0;
4657 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4658 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
4659 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
4660 deferred
->wait_semaphores
[i
] = &deferred
->temporary_semaphore_parts
[temporary_idx
];
4661 deferred
->temporary_semaphore_parts
[temporary_idx
] = semaphore
->temporary
;
4662 semaphore
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
4665 deferred
->wait_semaphores
[i
] = &semaphore
->permanent
;
4668 for (uint32_t i
= 0; i
< submission
->signal_semaphore_count
; ++i
) {
4669 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->signal_semaphores
[i
]);
4670 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
4671 deferred
->signal_semaphores
[i
] = &semaphore
->temporary
;
4673 deferred
->signal_semaphores
[i
] = &semaphore
->permanent
;
4677 deferred
->wait_values
= (void*)(deferred
->temporary_semaphore_parts
+ temporary_count
);
4678 memcpy(deferred
->wait_values
, submission
->wait_values
, submission
->wait_value_count
* sizeof(uint64_t));
4679 deferred
->signal_values
= deferred
->wait_values
+ submission
->wait_value_count
;
4680 memcpy(deferred
->signal_values
, submission
->signal_values
, submission
->signal_value_count
* sizeof(uint64_t));
4682 deferred
->wait_nodes
= (void*)(deferred
->signal_values
+ submission
->signal_value_count
);
4683 /* This is worst-case. radv_queue_enqueue_submission will fill in further, but this
4684 * ensure the submission is not accidentally triggered early when adding wait timelines. */
4685 deferred
->submission_wait_count
= 1 + submission
->wait_semaphore_count
;
4692 radv_queue_enqueue_submission(struct radv_deferred_queue_submission
*submission
,
4693 struct list_head
*processing_list
)
4695 uint32_t wait_cnt
= 0;
4696 struct radv_timeline_waiter
*waiter
= submission
->wait_nodes
;
4697 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
4698 if (submission
->wait_semaphores
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
4699 pthread_mutex_lock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
4700 if (submission
->wait_semaphores
[i
]->timeline
.highest_submitted
< submission
->wait_values
[i
]) {
4702 waiter
->value
= submission
->wait_values
[i
];
4703 waiter
->submission
= submission
;
4704 list_addtail(&waiter
->list
, &submission
->wait_semaphores
[i
]->timeline
.waiters
);
4707 pthread_mutex_unlock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
4711 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
4713 bool is_first
= list_is_empty(&submission
->queue
->pending_submissions
);
4714 list_addtail(&submission
->queue_pending_list
, &submission
->queue
->pending_submissions
);
4716 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
4718 /* If there is already a submission in the queue, that will decrement the counter by 1 when
4719 * submitted, but if the queue was empty, we decrement ourselves as there is no previous
4721 uint32_t decrement
= submission
->wait_semaphore_count
- wait_cnt
+ (is_first
? 1 : 0);
4722 if (__atomic_sub_fetch(&submission
->submission_wait_count
, decrement
, __ATOMIC_ACQ_REL
) == 0) {
4723 list_addtail(&submission
->processing_list
, processing_list
);
4728 radv_queue_submission_update_queue(struct radv_deferred_queue_submission
*submission
,
4729 struct list_head
*processing_list
)
4731 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
4732 list_del(&submission
->queue_pending_list
);
4734 /* trigger the next submission in the queue. */
4735 if (!list_is_empty(&submission
->queue
->pending_submissions
)) {
4736 struct radv_deferred_queue_submission
*next_submission
=
4737 list_first_entry(&submission
->queue
->pending_submissions
,
4738 struct radv_deferred_queue_submission
,
4739 queue_pending_list
);
4740 if (p_atomic_dec_zero(&next_submission
->submission_wait_count
)) {
4741 list_addtail(&next_submission
->processing_list
, processing_list
);
4744 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
4746 pthread_cond_broadcast(&submission
->queue
->device
->timeline_cond
);
4750 radv_queue_submit_deferred(struct radv_deferred_queue_submission
*submission
,
4751 struct list_head
*processing_list
)
4753 RADV_FROM_HANDLE(radv_fence
, fence
, submission
->fence
);
4754 struct radv_queue
*queue
= submission
->queue
;
4755 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
4756 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
4757 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
4758 bool do_flush
= submission
->flush_caches
|| submission
->wait_dst_stage_mask
;
4759 bool can_patch
= true;
4761 struct radv_winsys_sem_info sem_info
;
4764 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
;
4765 struct radeon_cmdbuf
*initial_flush_preamble_cs
= NULL
;
4766 struct radeon_cmdbuf
*continue_preamble_cs
= NULL
;
4768 result
= radv_get_preambles(queue
, submission
->cmd_buffers
,
4769 submission
->cmd_buffer_count
,
4770 &initial_preamble_cs
,
4771 &initial_flush_preamble_cs
,
4772 &continue_preamble_cs
);
4773 if (result
!= VK_SUCCESS
)
4776 result
= radv_alloc_sem_info(queue
->device
,
4778 submission
->wait_semaphore_count
,
4779 submission
->wait_semaphores
,
4780 submission
->wait_values
,
4781 submission
->signal_semaphore_count
,
4782 submission
->signal_semaphores
,
4783 submission
->signal_values
,
4785 if (result
!= VK_SUCCESS
)
4788 for (uint32_t i
= 0; i
< submission
->buffer_bind_count
; ++i
) {
4789 radv_sparse_buffer_bind_memory(queue
->device
,
4790 submission
->buffer_binds
+ i
);
4793 for (uint32_t i
= 0; i
< submission
->image_opaque_bind_count
; ++i
) {
4794 radv_sparse_image_opaque_bind_memory(queue
->device
,
4795 submission
->image_opaque_binds
+ i
);
4798 if (!submission
->cmd_buffer_count
) {
4799 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
4800 &queue
->device
->empty_cs
[queue
->queue_family_index
],
4805 radv_loge("failed to submit CS\n");
4811 struct radeon_cmdbuf
**cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
4812 (submission
->cmd_buffer_count
));
4814 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
++) {
4815 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, submission
->cmd_buffers
[j
]);
4816 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
4818 cs_array
[j
] = cmd_buffer
->cs
;
4819 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
4822 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
4825 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
+= advance
) {
4826 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
4827 const struct radv_winsys_bo_list
*bo_list
= NULL
;
4829 advance
= MIN2(max_cs_submission
,
4830 submission
->cmd_buffer_count
- j
);
4832 if (queue
->device
->trace_bo
)
4833 *queue
->device
->trace_id_ptr
= 0;
4835 sem_info
.cs_emit_wait
= j
== 0;
4836 sem_info
.cs_emit_signal
= j
+ advance
== submission
->cmd_buffer_count
;
4838 if (unlikely(queue
->device
->use_global_bo_list
)) {
4839 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
4840 bo_list
= &queue
->device
->bo_list
.list
;
4843 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
4844 advance
, initial_preamble
, continue_preamble_cs
,
4846 can_patch
, base_fence
);
4848 if (unlikely(queue
->device
->use_global_bo_list
))
4849 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
4852 radv_loge("failed to submit CS\n");
4855 if (queue
->device
->trace_bo
) {
4856 radv_check_gpu_hangs(queue
, cs_array
[j
]);
4864 radv_free_temp_syncobjs(queue
->device
,
4865 submission
->temporary_semaphore_part_count
,
4866 submission
->temporary_semaphore_parts
);
4867 radv_finalize_timelines(queue
->device
,
4868 submission
->wait_semaphore_count
,
4869 submission
->wait_semaphores
,
4870 submission
->wait_values
,
4871 submission
->signal_semaphore_count
,
4872 submission
->signal_semaphores
,
4873 submission
->signal_values
,
4875 /* Has to happen after timeline finalization to make sure the
4876 * condition variable is only triggered when timelines and queue have
4878 radv_queue_submission_update_queue(submission
, processing_list
);
4879 radv_free_sem_info(&sem_info
);
4884 radv_free_temp_syncobjs(queue
->device
,
4885 submission
->temporary_semaphore_part_count
,
4886 submission
->temporary_semaphore_parts
);
4888 return VK_ERROR_DEVICE_LOST
;
4892 radv_process_submissions(struct list_head
*processing_list
)
4894 while(!list_is_empty(processing_list
)) {
4895 struct radv_deferred_queue_submission
*submission
=
4896 list_first_entry(processing_list
, struct radv_deferred_queue_submission
, processing_list
);
4897 list_del(&submission
->processing_list
);
4899 VkResult result
= radv_queue_submit_deferred(submission
, processing_list
);
4900 if (result
!= VK_SUCCESS
)
4906 static VkResult
radv_queue_submit(struct radv_queue
*queue
,
4907 const struct radv_queue_submission
*submission
)
4909 struct radv_deferred_queue_submission
*deferred
= NULL
;
4911 VkResult result
= radv_create_deferred_submission(queue
, submission
, &deferred
);
4912 if (result
!= VK_SUCCESS
)
4915 struct list_head processing_list
;
4916 list_inithead(&processing_list
);
4918 radv_queue_enqueue_submission(deferred
, &processing_list
);
4919 return radv_process_submissions(&processing_list
);
4923 radv_queue_internal_submit(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
)
4925 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
4926 struct radv_winsys_sem_info sem_info
;
4930 result
= radv_alloc_sem_info(queue
->device
, &sem_info
, 0, NULL
, 0, 0,
4931 0, NULL
, VK_NULL_HANDLE
);
4932 if (result
!= VK_SUCCESS
)
4935 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, &cs
, 1, NULL
,
4936 NULL
, &sem_info
, NULL
, false, NULL
);
4937 radv_free_sem_info(&sem_info
);
4941 /* Signals fence as soon as all the work currently put on queue is done. */
4942 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
4945 return radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4950 static bool radv_submit_has_effects(const VkSubmitInfo
*info
)
4952 return info
->commandBufferCount
||
4953 info
->waitSemaphoreCount
||
4954 info
->signalSemaphoreCount
;
4957 VkResult
radv_QueueSubmit(
4959 uint32_t submitCount
,
4960 const VkSubmitInfo
* pSubmits
,
4963 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4965 uint32_t fence_idx
= 0;
4966 bool flushed_caches
= false;
4968 if (fence
!= VK_NULL_HANDLE
) {
4969 for (uint32_t i
= 0; i
< submitCount
; ++i
)
4970 if (radv_submit_has_effects(pSubmits
+ i
))
4973 fence_idx
= UINT32_MAX
;
4975 for (uint32_t i
= 0; i
< submitCount
; i
++) {
4976 if (!radv_submit_has_effects(pSubmits
+ i
) && fence_idx
!= i
)
4979 VkPipelineStageFlags wait_dst_stage_mask
= 0;
4980 for (unsigned j
= 0; j
< pSubmits
[i
].waitSemaphoreCount
; ++j
) {
4981 wait_dst_stage_mask
|= pSubmits
[i
].pWaitDstStageMask
[j
];
4984 const VkTimelineSemaphoreSubmitInfo
*timeline_info
=
4985 vk_find_struct_const(pSubmits
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO
);
4987 result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4988 .cmd_buffers
= pSubmits
[i
].pCommandBuffers
,
4989 .cmd_buffer_count
= pSubmits
[i
].commandBufferCount
,
4990 .wait_dst_stage_mask
= wait_dst_stage_mask
,
4991 .flush_caches
= !flushed_caches
,
4992 .wait_semaphores
= pSubmits
[i
].pWaitSemaphores
,
4993 .wait_semaphore_count
= pSubmits
[i
].waitSemaphoreCount
,
4994 .signal_semaphores
= pSubmits
[i
].pSignalSemaphores
,
4995 .signal_semaphore_count
= pSubmits
[i
].signalSemaphoreCount
,
4996 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
4997 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
4998 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
4999 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
5000 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
5002 if (result
!= VK_SUCCESS
)
5005 flushed_caches
= true;
5008 if (fence
!= VK_NULL_HANDLE
&& !submitCount
) {
5009 result
= radv_signal_fence(queue
, fence
);
5010 if (result
!= VK_SUCCESS
)
5017 VkResult
radv_QueueWaitIdle(
5020 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
5022 pthread_mutex_lock(&queue
->pending_mutex
);
5023 while (!list_is_empty(&queue
->pending_submissions
)) {
5024 pthread_cond_wait(&queue
->device
->timeline_cond
, &queue
->pending_mutex
);
5026 pthread_mutex_unlock(&queue
->pending_mutex
);
5028 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
5029 radv_queue_family_to_ring(queue
->queue_family_index
),
5034 VkResult
radv_DeviceWaitIdle(
5037 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5039 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
5040 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
5041 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
5047 VkResult
radv_EnumerateInstanceExtensionProperties(
5048 const char* pLayerName
,
5049 uint32_t* pPropertyCount
,
5050 VkExtensionProperties
* pProperties
)
5052 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
5054 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
5055 if (radv_instance_extensions_supported
.extensions
[i
]) {
5056 vk_outarray_append(&out
, prop
) {
5057 *prop
= radv_instance_extensions
[i
];
5062 return vk_outarray_status(&out
);
5065 VkResult
radv_EnumerateDeviceExtensionProperties(
5066 VkPhysicalDevice physicalDevice
,
5067 const char* pLayerName
,
5068 uint32_t* pPropertyCount
,
5069 VkExtensionProperties
* pProperties
)
5071 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
5072 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
5074 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
5075 if (device
->supported_extensions
.extensions
[i
]) {
5076 vk_outarray_append(&out
, prop
) {
5077 *prop
= radv_device_extensions
[i
];
5082 return vk_outarray_status(&out
);
5085 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
5086 VkInstance _instance
,
5089 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5091 /* The Vulkan 1.0 spec for vkGetInstanceProcAddr has a table of exactly
5092 * when we have to return valid function pointers, NULL, or it's left
5093 * undefined. See the table for exact details.
5098 #define LOOKUP_RADV_ENTRYPOINT(entrypoint) \
5099 if (strcmp(pName, "vk" #entrypoint) == 0) \
5100 return (PFN_vkVoidFunction)radv_##entrypoint
5102 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceExtensionProperties
);
5103 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceLayerProperties
);
5104 LOOKUP_RADV_ENTRYPOINT(EnumerateInstanceVersion
);
5105 LOOKUP_RADV_ENTRYPOINT(CreateInstance
);
5107 /* GetInstanceProcAddr() can also be called with a NULL instance.
5108 * See https://gitlab.khronos.org/vulkan/vulkan/issues/2057
5110 LOOKUP_RADV_ENTRYPOINT(GetInstanceProcAddr
);
5112 #undef LOOKUP_RADV_ENTRYPOINT
5114 if (instance
== NULL
)
5117 int idx
= radv_get_instance_entrypoint_index(pName
);
5119 return instance
->dispatch
.entrypoints
[idx
];
5121 idx
= radv_get_physical_device_entrypoint_index(pName
);
5123 return instance
->physical_device_dispatch
.entrypoints
[idx
];
5125 idx
= radv_get_device_entrypoint_index(pName
);
5127 return instance
->device_dispatch
.entrypoints
[idx
];
5132 /* The loader wants us to expose a second GetInstanceProcAddr function
5133 * to work around certain LD_PRELOAD issues seen in apps.
5136 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
5137 VkInstance instance
,
5141 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
5142 VkInstance instance
,
5145 return radv_GetInstanceProcAddr(instance
, pName
);
5149 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
5150 VkInstance _instance
,
5154 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
5155 VkInstance _instance
,
5158 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5160 if (!pName
|| !instance
)
5163 int idx
= radv_get_physical_device_entrypoint_index(pName
);
5167 return instance
->physical_device_dispatch
.entrypoints
[idx
];
5170 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
5174 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5176 if (!device
|| !pName
)
5179 int idx
= radv_get_device_entrypoint_index(pName
);
5183 return device
->dispatch
.entrypoints
[idx
];
5186 bool radv_get_memory_fd(struct radv_device
*device
,
5187 struct radv_device_memory
*memory
,
5190 struct radeon_bo_metadata metadata
;
5192 if (memory
->image
) {
5193 if (memory
->image
->tiling
!= VK_IMAGE_TILING_LINEAR
)
5194 radv_init_metadata(device
, memory
->image
, &metadata
);
5195 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
5198 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
5203 static void radv_free_memory(struct radv_device
*device
,
5204 const VkAllocationCallbacks
* pAllocator
,
5205 struct radv_device_memory
*mem
)
5210 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
5211 if (mem
->android_hardware_buffer
)
5212 AHardwareBuffer_release(mem
->android_hardware_buffer
);
5216 if (device
->overallocation_disallowed
) {
5217 mtx_lock(&device
->overallocation_mutex
);
5218 device
->allocated_memory_size
[mem
->heap_index
] -= mem
->alloc_size
;
5219 mtx_unlock(&device
->overallocation_mutex
);
5222 radv_bo_list_remove(device
, mem
->bo
);
5223 device
->ws
->buffer_destroy(mem
->bo
);
5227 vk_object_base_finish(&mem
->base
);
5228 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);
5231 static VkResult
radv_alloc_memory(struct radv_device
*device
,
5232 const VkMemoryAllocateInfo
* pAllocateInfo
,
5233 const VkAllocationCallbacks
* pAllocator
,
5234 VkDeviceMemory
* pMem
)
5236 struct radv_device_memory
*mem
;
5238 enum radeon_bo_domain domain
;
5241 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
5243 const VkImportMemoryFdInfoKHR
*import_info
=
5244 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
5245 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
5246 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
5247 const VkExportMemoryAllocateInfo
*export_info
=
5248 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
5249 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahb_import_info
=
5250 vk_find_struct_const(pAllocateInfo
->pNext
,
5251 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
5252 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
5253 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
5255 const struct wsi_memory_allocate_info
*wsi_info
=
5256 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
5258 if (pAllocateInfo
->allocationSize
== 0 && !ahb_import_info
&&
5259 !(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
))) {
5260 /* Apparently, this is allowed */
5261 *pMem
= VK_NULL_HANDLE
;
5265 mem
= vk_zalloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*mem
), 8,
5266 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5268 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5270 vk_object_base_init(&device
->vk
, &mem
->base
,
5271 VK_OBJECT_TYPE_DEVICE_MEMORY
);
5273 if (wsi_info
&& wsi_info
->implicit_sync
)
5274 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
5276 if (dedicate_info
) {
5277 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
5278 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
5284 float priority_float
= 0.5;
5285 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
5286 vk_find_struct_const(pAllocateInfo
->pNext
,
5287 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
5289 priority_float
= priority_ext
->priority
;
5291 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
5292 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
5294 mem
->user_ptr
= NULL
;
5297 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
5298 mem
->android_hardware_buffer
= NULL
;
5301 if (ahb_import_info
) {
5302 result
= radv_import_ahb_memory(device
, mem
, priority
, ahb_import_info
);
5303 if (result
!= VK_SUCCESS
)
5305 } else if(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)) {
5306 result
= radv_create_ahb_memory(device
, mem
, priority
, pAllocateInfo
);
5307 if (result
!= VK_SUCCESS
)
5309 } else if (import_info
) {
5310 assert(import_info
->handleType
==
5311 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5312 import_info
->handleType
==
5313 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5314 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
5317 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
5320 close(import_info
->fd
);
5322 } else if (host_ptr_info
) {
5323 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
5324 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
5325 pAllocateInfo
->allocationSize
,
5328 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
5331 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
5334 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
5335 uint32_t heap_index
;
5337 heap_index
= device
->physical_device
->memory_properties
.memoryTypes
[pAllocateInfo
->memoryTypeIndex
].heapIndex
;
5338 domain
= device
->physical_device
->memory_domains
[pAllocateInfo
->memoryTypeIndex
];
5339 flags
|= device
->physical_device
->memory_flags
[pAllocateInfo
->memoryTypeIndex
];
5341 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
5342 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
5343 if (device
->use_global_bo_list
) {
5344 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
5348 if (device
->overallocation_disallowed
) {
5349 uint64_t total_size
=
5350 device
->physical_device
->memory_properties
.memoryHeaps
[heap_index
].size
;
5352 mtx_lock(&device
->overallocation_mutex
);
5353 if (device
->allocated_memory_size
[heap_index
] + alloc_size
> total_size
) {
5354 mtx_unlock(&device
->overallocation_mutex
);
5355 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
5358 device
->allocated_memory_size
[heap_index
] += alloc_size
;
5359 mtx_unlock(&device
->overallocation_mutex
);
5362 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
5363 domain
, flags
, priority
);
5366 if (device
->overallocation_disallowed
) {
5367 mtx_lock(&device
->overallocation_mutex
);
5368 device
->allocated_memory_size
[heap_index
] -= alloc_size
;
5369 mtx_unlock(&device
->overallocation_mutex
);
5371 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
5375 mem
->heap_index
= heap_index
;
5376 mem
->alloc_size
= alloc_size
;
5380 result
= radv_bo_list_add(device
, mem
->bo
);
5381 if (result
!= VK_SUCCESS
)
5385 *pMem
= radv_device_memory_to_handle(mem
);
5390 radv_free_memory(device
, pAllocator
,mem
);
5395 VkResult
radv_AllocateMemory(
5397 const VkMemoryAllocateInfo
* pAllocateInfo
,
5398 const VkAllocationCallbacks
* pAllocator
,
5399 VkDeviceMemory
* pMem
)
5401 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5402 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
5405 void radv_FreeMemory(
5407 VkDeviceMemory _mem
,
5408 const VkAllocationCallbacks
* pAllocator
)
5410 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5411 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
5413 radv_free_memory(device
, pAllocator
, mem
);
5416 VkResult
radv_MapMemory(
5418 VkDeviceMemory _memory
,
5419 VkDeviceSize offset
,
5421 VkMemoryMapFlags flags
,
5424 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5425 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
5433 *ppData
= mem
->user_ptr
;
5435 *ppData
= device
->ws
->buffer_map(mem
->bo
);
5442 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
5445 void radv_UnmapMemory(
5447 VkDeviceMemory _memory
)
5449 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5450 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
5455 if (mem
->user_ptr
== NULL
)
5456 device
->ws
->buffer_unmap(mem
->bo
);
5459 VkResult
radv_FlushMappedMemoryRanges(
5461 uint32_t memoryRangeCount
,
5462 const VkMappedMemoryRange
* pMemoryRanges
)
5467 VkResult
radv_InvalidateMappedMemoryRanges(
5469 uint32_t memoryRangeCount
,
5470 const VkMappedMemoryRange
* pMemoryRanges
)
5475 void radv_GetBufferMemoryRequirements(
5478 VkMemoryRequirements
* pMemoryRequirements
)
5480 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5481 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
5483 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
5485 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
5486 pMemoryRequirements
->alignment
= 4096;
5488 pMemoryRequirements
->alignment
= 16;
5490 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
5493 void radv_GetBufferMemoryRequirements2(
5495 const VkBufferMemoryRequirementsInfo2
*pInfo
,
5496 VkMemoryRequirements2
*pMemoryRequirements
)
5498 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
5499 &pMemoryRequirements
->memoryRequirements
);
5500 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
5501 switch (ext
->sType
) {
5502 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
5503 VkMemoryDedicatedRequirements
*req
=
5504 (VkMemoryDedicatedRequirements
*) ext
;
5505 req
->requiresDedicatedAllocation
= false;
5506 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
5515 void radv_GetImageMemoryRequirements(
5518 VkMemoryRequirements
* pMemoryRequirements
)
5520 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5521 RADV_FROM_HANDLE(radv_image
, image
, _image
);
5523 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
5525 pMemoryRequirements
->size
= image
->size
;
5526 pMemoryRequirements
->alignment
= image
->alignment
;
5529 void radv_GetImageMemoryRequirements2(
5531 const VkImageMemoryRequirementsInfo2
*pInfo
,
5532 VkMemoryRequirements2
*pMemoryRequirements
)
5534 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
5535 &pMemoryRequirements
->memoryRequirements
);
5537 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
5539 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
5540 switch (ext
->sType
) {
5541 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
5542 VkMemoryDedicatedRequirements
*req
=
5543 (VkMemoryDedicatedRequirements
*) ext
;
5544 req
->requiresDedicatedAllocation
= image
->shareable
&&
5545 image
->tiling
!= VK_IMAGE_TILING_LINEAR
;
5546 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
5555 void radv_GetImageSparseMemoryRequirements(
5558 uint32_t* pSparseMemoryRequirementCount
,
5559 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
5564 void radv_GetImageSparseMemoryRequirements2(
5566 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
5567 uint32_t* pSparseMemoryRequirementCount
,
5568 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
5573 void radv_GetDeviceMemoryCommitment(
5575 VkDeviceMemory memory
,
5576 VkDeviceSize
* pCommittedMemoryInBytes
)
5578 *pCommittedMemoryInBytes
= 0;
5581 VkResult
radv_BindBufferMemory2(VkDevice device
,
5582 uint32_t bindInfoCount
,
5583 const VkBindBufferMemoryInfo
*pBindInfos
)
5585 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5586 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
5587 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
5590 buffer
->bo
= mem
->bo
;
5591 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
5599 VkResult
radv_BindBufferMemory(
5602 VkDeviceMemory memory
,
5603 VkDeviceSize memoryOffset
)
5605 const VkBindBufferMemoryInfo info
= {
5606 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
5609 .memoryOffset
= memoryOffset
5612 return radv_BindBufferMemory2(device
, 1, &info
);
5615 VkResult
radv_BindImageMemory2(VkDevice device
,
5616 uint32_t bindInfoCount
,
5617 const VkBindImageMemoryInfo
*pBindInfos
)
5619 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5620 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
5621 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
5624 image
->bo
= mem
->bo
;
5625 image
->offset
= pBindInfos
[i
].memoryOffset
;
5635 VkResult
radv_BindImageMemory(
5638 VkDeviceMemory memory
,
5639 VkDeviceSize memoryOffset
)
5641 const VkBindImageMemoryInfo info
= {
5642 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
5645 .memoryOffset
= memoryOffset
5648 return radv_BindImageMemory2(device
, 1, &info
);
5651 static bool radv_sparse_bind_has_effects(const VkBindSparseInfo
*info
)
5653 return info
->bufferBindCount
||
5654 info
->imageOpaqueBindCount
||
5655 info
->imageBindCount
||
5656 info
->waitSemaphoreCount
||
5657 info
->signalSemaphoreCount
;
5660 VkResult
radv_QueueBindSparse(
5662 uint32_t bindInfoCount
,
5663 const VkBindSparseInfo
* pBindInfo
,
5666 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
5668 uint32_t fence_idx
= 0;
5670 if (fence
!= VK_NULL_HANDLE
) {
5671 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
)
5672 if (radv_sparse_bind_has_effects(pBindInfo
+ i
))
5675 fence_idx
= UINT32_MAX
;
5677 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
5678 if (i
!= fence_idx
&& !radv_sparse_bind_has_effects(pBindInfo
+ i
))
5681 const VkTimelineSemaphoreSubmitInfo
*timeline_info
=
5682 vk_find_struct_const(pBindInfo
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO
);
5684 VkResult result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
5685 .buffer_binds
= pBindInfo
[i
].pBufferBinds
,
5686 .buffer_bind_count
= pBindInfo
[i
].bufferBindCount
,
5687 .image_opaque_binds
= pBindInfo
[i
].pImageOpaqueBinds
,
5688 .image_opaque_bind_count
= pBindInfo
[i
].imageOpaqueBindCount
,
5689 .wait_semaphores
= pBindInfo
[i
].pWaitSemaphores
,
5690 .wait_semaphore_count
= pBindInfo
[i
].waitSemaphoreCount
,
5691 .signal_semaphores
= pBindInfo
[i
].pSignalSemaphores
,
5692 .signal_semaphore_count
= pBindInfo
[i
].signalSemaphoreCount
,
5693 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
5694 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
5695 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
5696 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
5697 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
5700 if (result
!= VK_SUCCESS
)
5704 if (fence
!= VK_NULL_HANDLE
&& !bindInfoCount
) {
5705 result
= radv_signal_fence(queue
, fence
);
5706 if (result
!= VK_SUCCESS
)
5713 VkResult
radv_CreateFence(
5715 const VkFenceCreateInfo
* pCreateInfo
,
5716 const VkAllocationCallbacks
* pAllocator
,
5719 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5720 const VkExportFenceCreateInfo
*export
=
5721 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
5722 VkExternalFenceHandleTypeFlags handleTypes
=
5723 export
? export
->handleTypes
: 0;
5725 struct radv_fence
*fence
= vk_alloc2(&device
->vk
.alloc
, pAllocator
,
5727 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5730 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5732 vk_object_base_init(&device
->vk
, &fence
->base
, VK_OBJECT_TYPE_FENCE
);
5734 fence
->fence_wsi
= NULL
;
5735 fence
->temp_syncobj
= 0;
5736 if (device
->always_use_syncobj
|| handleTypes
) {
5737 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
5739 vk_free2(&device
->vk
.alloc
, pAllocator
, fence
);
5740 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5742 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
5743 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
5745 fence
->fence
= NULL
;
5747 fence
->fence
= device
->ws
->create_fence();
5748 if (!fence
->fence
) {
5749 vk_free2(&device
->vk
.alloc
, pAllocator
, fence
);
5750 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5753 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
5754 device
->ws
->signal_fence(fence
->fence
);
5757 *pFence
= radv_fence_to_handle(fence
);
5762 void radv_DestroyFence(
5765 const VkAllocationCallbacks
* pAllocator
)
5767 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5768 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5773 if (fence
->temp_syncobj
)
5774 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5776 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
5778 device
->ws
->destroy_fence(fence
->fence
);
5779 if (fence
->fence_wsi
)
5780 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
5782 vk_object_base_finish(&fence
->base
);
5783 vk_free2(&device
->vk
.alloc
, pAllocator
, fence
);
5787 uint64_t radv_get_current_time(void)
5790 clock_gettime(CLOCK_MONOTONIC
, &tv
);
5791 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
5794 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
5796 uint64_t current_time
= radv_get_current_time();
5798 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
5800 return current_time
+ timeout
;
5804 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
5805 uint32_t fenceCount
, const VkFence
*pFences
)
5807 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5808 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5809 if (fence
->fence
== NULL
|| fence
->syncobj
||
5810 fence
->temp_syncobj
|| fence
->fence_wsi
||
5811 (!device
->ws
->is_fence_waitable(fence
->fence
)))
5817 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
5819 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5820 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5821 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
5827 VkResult
radv_WaitForFences(
5829 uint32_t fenceCount
,
5830 const VkFence
* pFences
,
5834 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5835 timeout
= radv_get_absolute_timeout(timeout
);
5837 if (device
->always_use_syncobj
&&
5838 radv_all_fences_syncobj(fenceCount
, pFences
))
5840 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
5842 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5844 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5845 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5846 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
5849 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
5852 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5855 if (!waitAll
&& fenceCount
> 1) {
5856 /* Not doing this by default for waitAll, due to needing to allocate twice. */
5857 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
5858 uint32_t wait_count
= 0;
5859 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
5861 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5863 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5864 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5866 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
5871 fences
[wait_count
++] = fence
->fence
;
5874 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
5875 waitAll
, timeout
- radv_get_current_time());
5878 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5881 while(radv_get_current_time() <= timeout
) {
5882 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5883 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
5890 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
5891 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5892 bool expired
= false;
5894 if (fence
->temp_syncobj
) {
5895 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
5900 if (fence
->syncobj
) {
5901 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
5907 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
5908 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
5909 radv_get_current_time() <= timeout
)
5913 expired
= device
->ws
->fence_wait(device
->ws
,
5920 if (fence
->fence_wsi
) {
5921 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
5922 if (result
!= VK_SUCCESS
)
5930 VkResult
radv_ResetFences(VkDevice _device
,
5931 uint32_t fenceCount
,
5932 const VkFence
*pFences
)
5934 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5936 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
5937 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5939 device
->ws
->reset_fence(fence
->fence
);
5941 /* Per spec, we first restore the permanent payload, and then reset, so
5942 * having a temp syncobj should not skip resetting the permanent syncobj. */
5943 if (fence
->temp_syncobj
) {
5944 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5945 fence
->temp_syncobj
= 0;
5948 if (fence
->syncobj
) {
5949 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
5956 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
5958 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5959 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5961 if (fence
->temp_syncobj
) {
5962 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
5963 return success
? VK_SUCCESS
: VK_NOT_READY
;
5966 if (fence
->syncobj
) {
5967 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
5968 return success
? VK_SUCCESS
: VK_NOT_READY
;
5972 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
5973 return VK_NOT_READY
;
5975 if (fence
->fence_wsi
) {
5976 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
5978 if (result
!= VK_SUCCESS
) {
5979 if (result
== VK_TIMEOUT
)
5980 return VK_NOT_READY
;
5988 // Queue semaphore functions
5991 radv_create_timeline(struct radv_timeline
*timeline
, uint64_t value
)
5993 timeline
->highest_signaled
= value
;
5994 timeline
->highest_submitted
= value
;
5995 list_inithead(&timeline
->points
);
5996 list_inithead(&timeline
->free_points
);
5997 list_inithead(&timeline
->waiters
);
5998 pthread_mutex_init(&timeline
->mutex
, NULL
);
6002 radv_destroy_timeline(struct radv_device
*device
,
6003 struct radv_timeline
*timeline
)
6005 list_for_each_entry_safe(struct radv_timeline_point
, point
,
6006 &timeline
->free_points
, list
) {
6007 list_del(&point
->list
);
6008 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
6011 list_for_each_entry_safe(struct radv_timeline_point
, point
,
6012 &timeline
->points
, list
) {
6013 list_del(&point
->list
);
6014 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
6017 pthread_mutex_destroy(&timeline
->mutex
);
6021 radv_timeline_gc_locked(struct radv_device
*device
,
6022 struct radv_timeline
*timeline
)
6024 list_for_each_entry_safe(struct radv_timeline_point
, point
,
6025 &timeline
->points
, list
) {
6026 if (point
->wait_count
|| point
->value
> timeline
->highest_submitted
)
6029 if (device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, 0)) {
6030 timeline
->highest_signaled
= point
->value
;
6031 list_del(&point
->list
);
6032 list_add(&point
->list
, &timeline
->free_points
);
6037 static struct radv_timeline_point
*
6038 radv_timeline_find_point_at_least_locked(struct radv_device
*device
,
6039 struct radv_timeline
*timeline
,
6042 radv_timeline_gc_locked(device
, timeline
);
6044 if (p
<= timeline
->highest_signaled
)
6047 list_for_each_entry(struct radv_timeline_point
, point
,
6048 &timeline
->points
, list
) {
6049 if (point
->value
>= p
) {
6050 ++point
->wait_count
;
6057 static struct radv_timeline_point
*
6058 radv_timeline_add_point_locked(struct radv_device
*device
,
6059 struct radv_timeline
*timeline
,
6062 radv_timeline_gc_locked(device
, timeline
);
6064 struct radv_timeline_point
*ret
= NULL
;
6065 struct radv_timeline_point
*prev
= NULL
;
6067 if (p
<= timeline
->highest_signaled
)
6070 list_for_each_entry(struct radv_timeline_point
, point
,
6071 &timeline
->points
, list
) {
6072 if (point
->value
== p
) {
6076 if (point
->value
< p
)
6080 if (list_is_empty(&timeline
->free_points
)) {
6081 ret
= malloc(sizeof(struct radv_timeline_point
));
6082 device
->ws
->create_syncobj(device
->ws
, &ret
->syncobj
);
6084 ret
= list_first_entry(&timeline
->free_points
, struct radv_timeline_point
, list
);
6085 list_del(&ret
->list
);
6087 device
->ws
->reset_syncobj(device
->ws
, ret
->syncobj
);
6091 ret
->wait_count
= 1;
6094 list_add(&ret
->list
, &prev
->list
);
6096 list_addtail(&ret
->list
, &timeline
->points
);
6103 radv_timeline_wait_locked(struct radv_device
*device
,
6104 struct radv_timeline
*timeline
,
6106 uint64_t abs_timeout
)
6108 while(timeline
->highest_submitted
< value
) {
6109 struct timespec abstime
;
6110 timespec_from_nsec(&abstime
, abs_timeout
);
6112 pthread_cond_timedwait(&device
->timeline_cond
, &timeline
->mutex
, &abstime
);
6114 if (radv_get_current_time() >= abs_timeout
&& timeline
->highest_submitted
< value
)
6118 struct radv_timeline_point
*point
= radv_timeline_find_point_at_least_locked(device
, timeline
, value
);
6122 pthread_mutex_unlock(&timeline
->mutex
);
6124 bool success
= device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, abs_timeout
);
6126 pthread_mutex_lock(&timeline
->mutex
);
6127 point
->wait_count
--;
6128 return success
? VK_SUCCESS
: VK_TIMEOUT
;
6132 radv_timeline_trigger_waiters_locked(struct radv_timeline
*timeline
,
6133 struct list_head
*processing_list
)
6135 list_for_each_entry_safe(struct radv_timeline_waiter
, waiter
,
6136 &timeline
->waiters
, list
) {
6137 if (waiter
->value
> timeline
->highest_submitted
)
6140 if (p_atomic_dec_zero(&waiter
->submission
->submission_wait_count
)) {
6141 list_addtail(&waiter
->submission
->processing_list
, processing_list
);
6143 list_del(&waiter
->list
);
6148 void radv_destroy_semaphore_part(struct radv_device
*device
,
6149 struct radv_semaphore_part
*part
)
6151 switch(part
->kind
) {
6152 case RADV_SEMAPHORE_NONE
:
6154 case RADV_SEMAPHORE_WINSYS
:
6155 device
->ws
->destroy_sem(part
->ws_sem
);
6157 case RADV_SEMAPHORE_TIMELINE
:
6158 radv_destroy_timeline(device
, &part
->timeline
);
6160 case RADV_SEMAPHORE_SYNCOBJ
:
6161 device
->ws
->destroy_syncobj(device
->ws
, part
->syncobj
);
6164 part
->kind
= RADV_SEMAPHORE_NONE
;
6167 static VkSemaphoreTypeKHR
6168 radv_get_semaphore_type(const void *pNext
, uint64_t *initial_value
)
6170 const VkSemaphoreTypeCreateInfo
*type_info
=
6171 vk_find_struct_const(pNext
, SEMAPHORE_TYPE_CREATE_INFO
);
6174 return VK_SEMAPHORE_TYPE_BINARY
;
6177 *initial_value
= type_info
->initialValue
;
6178 return type_info
->semaphoreType
;
6181 VkResult
radv_CreateSemaphore(
6183 const VkSemaphoreCreateInfo
* pCreateInfo
,
6184 const VkAllocationCallbacks
* pAllocator
,
6185 VkSemaphore
* pSemaphore
)
6187 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6188 const VkExportSemaphoreCreateInfo
*export
=
6189 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
6190 VkExternalSemaphoreHandleTypeFlags handleTypes
=
6191 export
? export
->handleTypes
: 0;
6192 uint64_t initial_value
= 0;
6193 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pCreateInfo
->pNext
, &initial_value
);
6195 struct radv_semaphore
*sem
= vk_alloc2(&device
->vk
.alloc
, pAllocator
,
6197 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6199 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6201 vk_object_base_init(&device
->vk
, &sem
->base
,
6202 VK_OBJECT_TYPE_SEMAPHORE
);
6204 sem
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
6205 sem
->permanent
.kind
= RADV_SEMAPHORE_NONE
;
6207 if (type
== VK_SEMAPHORE_TYPE_TIMELINE
) {
6208 radv_create_timeline(&sem
->permanent
.timeline
, initial_value
);
6209 sem
->permanent
.kind
= RADV_SEMAPHORE_TIMELINE
;
6210 } else if (device
->always_use_syncobj
|| handleTypes
) {
6211 assert (device
->physical_device
->rad_info
.has_syncobj
);
6212 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->permanent
.syncobj
);
6214 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
6215 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6217 sem
->permanent
.kind
= RADV_SEMAPHORE_SYNCOBJ
;
6219 sem
->permanent
.ws_sem
= device
->ws
->create_sem(device
->ws
);
6220 if (!sem
->permanent
.ws_sem
) {
6221 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
6222 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6224 sem
->permanent
.kind
= RADV_SEMAPHORE_WINSYS
;
6227 *pSemaphore
= radv_semaphore_to_handle(sem
);
6231 void radv_DestroySemaphore(
6233 VkSemaphore _semaphore
,
6234 const VkAllocationCallbacks
* pAllocator
)
6236 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6237 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
6241 radv_destroy_semaphore_part(device
, &sem
->temporary
);
6242 radv_destroy_semaphore_part(device
, &sem
->permanent
);
6243 vk_object_base_finish(&sem
->base
);
6244 vk_free2(&device
->vk
.alloc
, pAllocator
, sem
);
6248 radv_GetSemaphoreCounterValue(VkDevice _device
,
6249 VkSemaphore _semaphore
,
6252 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6253 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, _semaphore
);
6255 struct radv_semaphore_part
*part
=
6256 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
6258 switch (part
->kind
) {
6259 case RADV_SEMAPHORE_TIMELINE
: {
6260 pthread_mutex_lock(&part
->timeline
.mutex
);
6261 radv_timeline_gc_locked(device
, &part
->timeline
);
6262 *pValue
= part
->timeline
.highest_signaled
;
6263 pthread_mutex_unlock(&part
->timeline
.mutex
);
6266 case RADV_SEMAPHORE_NONE
:
6267 case RADV_SEMAPHORE_SYNCOBJ
:
6268 case RADV_SEMAPHORE_WINSYS
:
6269 unreachable("Invalid semaphore type");
6271 unreachable("Unhandled semaphore type");
6276 radv_wait_timelines(struct radv_device
*device
,
6277 const VkSemaphoreWaitInfo
* pWaitInfo
,
6278 uint64_t abs_timeout
)
6280 if ((pWaitInfo
->flags
& VK_SEMAPHORE_WAIT_ANY_BIT_KHR
) && pWaitInfo
->semaphoreCount
> 1) {
6282 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
6283 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
6284 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
6285 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], 0);
6286 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
6288 if (result
== VK_SUCCESS
)
6291 if (radv_get_current_time() > abs_timeout
)
6296 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
6297 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
6298 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
6299 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], abs_timeout
);
6300 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
6302 if (result
!= VK_SUCCESS
)
6308 radv_WaitSemaphores(VkDevice _device
,
6309 const VkSemaphoreWaitInfo
* pWaitInfo
,
6312 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6313 uint64_t abs_timeout
= radv_get_absolute_timeout(timeout
);
6314 return radv_wait_timelines(device
, pWaitInfo
, abs_timeout
);
6318 radv_SignalSemaphore(VkDevice _device
,
6319 const VkSemaphoreSignalInfo
* pSignalInfo
)
6321 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6322 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pSignalInfo
->semaphore
);
6324 struct radv_semaphore_part
*part
=
6325 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
6327 switch(part
->kind
) {
6328 case RADV_SEMAPHORE_TIMELINE
: {
6329 pthread_mutex_lock(&part
->timeline
.mutex
);
6330 radv_timeline_gc_locked(device
, &part
->timeline
);
6331 part
->timeline
.highest_submitted
= MAX2(part
->timeline
.highest_submitted
, pSignalInfo
->value
);
6332 part
->timeline
.highest_signaled
= MAX2(part
->timeline
.highest_signaled
, pSignalInfo
->value
);
6334 struct list_head processing_list
;
6335 list_inithead(&processing_list
);
6336 radv_timeline_trigger_waiters_locked(&part
->timeline
, &processing_list
);
6337 pthread_mutex_unlock(&part
->timeline
.mutex
);
6339 return radv_process_submissions(&processing_list
);
6341 case RADV_SEMAPHORE_NONE
:
6342 case RADV_SEMAPHORE_SYNCOBJ
:
6343 case RADV_SEMAPHORE_WINSYS
:
6344 unreachable("Invalid semaphore type");
6351 VkResult
radv_CreateEvent(
6353 const VkEventCreateInfo
* pCreateInfo
,
6354 const VkAllocationCallbacks
* pAllocator
,
6357 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6358 struct radv_event
*event
= vk_alloc2(&device
->vk
.alloc
, pAllocator
,
6360 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6363 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6365 vk_object_base_init(&device
->vk
, &event
->base
, VK_OBJECT_TYPE_EVENT
);
6367 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
6369 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
6370 RADV_BO_PRIORITY_FENCE
);
6372 vk_free2(&device
->vk
.alloc
, pAllocator
, event
);
6373 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6376 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
6378 *pEvent
= radv_event_to_handle(event
);
6383 void radv_DestroyEvent(
6386 const VkAllocationCallbacks
* pAllocator
)
6388 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6389 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6393 device
->ws
->buffer_destroy(event
->bo
);
6394 vk_object_base_finish(&event
->base
);
6395 vk_free2(&device
->vk
.alloc
, pAllocator
, event
);
6398 VkResult
radv_GetEventStatus(
6402 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6404 if (*event
->map
== 1)
6405 return VK_EVENT_SET
;
6406 return VK_EVENT_RESET
;
6409 VkResult
radv_SetEvent(
6413 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6419 VkResult
radv_ResetEvent(
6423 RADV_FROM_HANDLE(radv_event
, event
, _event
);
6429 VkResult
radv_CreateBuffer(
6431 const VkBufferCreateInfo
* pCreateInfo
,
6432 const VkAllocationCallbacks
* pAllocator
,
6435 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6436 struct radv_buffer
*buffer
;
6438 if (pCreateInfo
->size
> RADV_MAX_MEMORY_ALLOCATION_SIZE
)
6439 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
6441 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
6443 buffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*buffer
), 8,
6444 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6446 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6448 vk_object_base_init(&device
->vk
, &buffer
->base
, VK_OBJECT_TYPE_BUFFER
);
6450 buffer
->size
= pCreateInfo
->size
;
6451 buffer
->usage
= pCreateInfo
->usage
;
6454 buffer
->flags
= pCreateInfo
->flags
;
6456 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
6457 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
6459 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
6460 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
6461 align64(buffer
->size
, 4096),
6462 4096, 0, RADEON_FLAG_VIRTUAL
,
6463 RADV_BO_PRIORITY_VIRTUAL
);
6465 vk_free2(&device
->vk
.alloc
, pAllocator
, buffer
);
6466 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6470 *pBuffer
= radv_buffer_to_handle(buffer
);
6475 void radv_DestroyBuffer(
6478 const VkAllocationCallbacks
* pAllocator
)
6480 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6481 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
6486 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
6487 device
->ws
->buffer_destroy(buffer
->bo
);
6489 vk_object_base_finish(&buffer
->base
);
6490 vk_free2(&device
->vk
.alloc
, pAllocator
, buffer
);
6493 VkDeviceAddress
radv_GetBufferDeviceAddress(
6495 const VkBufferDeviceAddressInfo
* pInfo
)
6497 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
6498 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
6502 uint64_t radv_GetBufferOpaqueCaptureAddress(VkDevice device
,
6503 const VkBufferDeviceAddressInfo
* pInfo
)
6508 uint64_t radv_GetDeviceMemoryOpaqueCaptureAddress(VkDevice device
,
6509 const VkDeviceMemoryOpaqueCaptureAddressInfo
* pInfo
)
6514 static inline unsigned
6515 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
6518 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
6520 return plane
->surface
.u
.legacy
.tiling_index
[level
];
6523 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
6525 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
6529 radv_init_dcc_control_reg(struct radv_device
*device
,
6530 struct radv_image_view
*iview
)
6532 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
6533 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
6534 unsigned max_compressed_block_size
;
6535 unsigned independent_128b_blocks
;
6536 unsigned independent_64b_blocks
;
6538 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
6541 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
6542 /* amdvlk: [min-compressed-block-size] should be set to 32 for
6543 * dGPU and 64 for APU because all of our APUs to date use
6544 * DIMMs which have a request granularity size of 64B while all
6545 * other chips have a 32B request size.
6547 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
6550 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6551 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
6552 independent_64b_blocks
= 0;
6553 independent_128b_blocks
= 1;
6555 independent_128b_blocks
= 0;
6557 if (iview
->image
->info
.samples
> 1) {
6558 if (iview
->image
->planes
[0].surface
.bpe
== 1)
6559 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
6560 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
6561 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
6564 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
6565 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
6566 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
6567 /* If this DCC image is potentially going to be used in texture
6568 * fetches, we need some special settings.
6570 independent_64b_blocks
= 1;
6571 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
6573 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
6574 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
6575 * big as possible for better compression state.
6577 independent_64b_blocks
= 0;
6578 max_compressed_block_size
= max_uncompressed_block_size
;
6582 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
6583 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
6584 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
6585 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
6586 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
6590 radv_initialise_color_surface(struct radv_device
*device
,
6591 struct radv_color_buffer_info
*cb
,
6592 struct radv_image_view
*iview
)
6594 const struct vk_format_description
*desc
;
6595 unsigned ntype
, format
, swap
, endian
;
6596 unsigned blend_clamp
= 0, blend_bypass
= 0;
6598 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
6599 const struct radeon_surf
*surf
= &plane
->surface
;
6601 desc
= vk_format_description(iview
->vk_format
);
6603 memset(cb
, 0, sizeof(*cb
));
6605 /* Intensity is implemented as Red, so treat it that way. */
6606 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
6608 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
6610 cb
->cb_color_base
= va
>> 8;
6612 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6613 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6614 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6615 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
6616 S_028EE0_CMASK_PIPE_ALIGNED(1) |
6617 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
6619 struct gfx9_surf_meta_flags meta
= {
6624 if (iview
->image
->dcc_offset
)
6625 meta
= surf
->u
.gfx9
.dcc
;
6627 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6628 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
6629 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
6630 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
6631 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
6634 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
6635 cb
->cb_color_base
|= surf
->tile_swizzle
;
6637 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
6638 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
6640 cb
->cb_color_base
+= level_info
->offset
>> 8;
6641 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
6642 cb
->cb_color_base
|= surf
->tile_swizzle
;
6644 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
6645 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
6646 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
6648 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
6649 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
6650 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
6652 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
6654 if (radv_image_has_fmask(iview
->image
)) {
6655 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
6656 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
6657 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
6658 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
6660 /* This must be set for fast clear to work without FMASK. */
6661 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
6662 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
6663 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
6664 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
6668 /* CMASK variables */
6669 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6670 va
+= iview
->image
->cmask_offset
;
6671 cb
->cb_color_cmask
= va
>> 8;
6673 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6674 va
+= iview
->image
->dcc_offset
;
6676 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
6677 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
6678 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
6680 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
6681 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
6683 cb
->cb_dcc_base
= va
>> 8;
6684 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
6686 /* GFX10 field has the same base shift as the GFX6 field. */
6687 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
6688 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
6689 S_028C6C_SLICE_MAX_GFX10(max_slice
);
6691 if (iview
->image
->info
.samples
> 1) {
6692 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
6694 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
6695 S_028C74_NUM_FRAGMENTS(log_samples
);
6698 if (radv_image_has_fmask(iview
->image
)) {
6699 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
6700 cb
->cb_color_fmask
= va
>> 8;
6701 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
6703 cb
->cb_color_fmask
= cb
->cb_color_base
;
6706 ntype
= radv_translate_color_numformat(iview
->vk_format
,
6708 vk_format_get_first_non_void_channel(iview
->vk_format
));
6709 format
= radv_translate_colorformat(iview
->vk_format
);
6710 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
6711 radv_finishme("Illegal color\n");
6712 swap
= radv_translate_colorswap(iview
->vk_format
, false);
6713 endian
= radv_colorformat_endian_swap(format
);
6715 /* blend clamp should be set for all NORM/SRGB types */
6716 if (ntype
== V_028C70_NUMBER_UNORM
||
6717 ntype
== V_028C70_NUMBER_SNORM
||
6718 ntype
== V_028C70_NUMBER_SRGB
)
6721 /* set blend bypass according to docs if SINT/UINT or
6722 8/24 COLOR variants */
6723 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
6724 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
6725 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
6730 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
6731 (format
== V_028C70_COLOR_8
||
6732 format
== V_028C70_COLOR_8_8
||
6733 format
== V_028C70_COLOR_8_8_8_8
))
6734 ->color_is_int8
= true;
6736 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
6737 S_028C70_COMP_SWAP(swap
) |
6738 S_028C70_BLEND_CLAMP(blend_clamp
) |
6739 S_028C70_BLEND_BYPASS(blend_bypass
) |
6740 S_028C70_SIMPLE_FLOAT(1) |
6741 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
6742 ntype
!= V_028C70_NUMBER_SNORM
&&
6743 ntype
!= V_028C70_NUMBER_SRGB
&&
6744 format
!= V_028C70_COLOR_8_24
&&
6745 format
!= V_028C70_COLOR_24_8
) |
6746 S_028C70_NUMBER_TYPE(ntype
) |
6747 S_028C70_ENDIAN(endian
);
6748 if (radv_image_has_fmask(iview
->image
)) {
6749 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
6750 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
6751 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
6752 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
6755 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
6756 /* Allow the texture block to read FMASK directly
6757 * without decompressing it. This bit must be cleared
6758 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
6759 * otherwise the operation doesn't happen.
6761 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
6763 /* Set CMASK into a tiling format that allows the
6764 * texture block to read it.
6766 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
6770 if (radv_image_has_cmask(iview
->image
) &&
6771 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
6772 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
6774 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
6775 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
6777 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
6779 /* This must be set for fast clear to work without FMASK. */
6780 if (!radv_image_has_fmask(iview
->image
) &&
6781 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
6782 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
6783 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
6786 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6787 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
6789 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
6790 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
6791 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
6792 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
6794 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6795 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
6797 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
6798 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
6799 S_028EE0_RESOURCE_LEVEL(1);
6801 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
6802 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
6803 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
6806 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
6807 S_028C68_MIP0_HEIGHT(height
- 1) |
6808 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
6813 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
6814 struct radv_image_view
*iview
)
6816 unsigned max_zplanes
= 0;
6818 assert(radv_image_is_tc_compat_htile(iview
->image
));
6820 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6821 /* Default value for 32-bit depth surfaces. */
6824 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
6825 iview
->image
->info
.samples
> 1)
6828 max_zplanes
= max_zplanes
+ 1;
6830 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
6831 /* Do not enable Z plane compression for 16-bit depth
6832 * surfaces because isn't supported on GFX8. Only
6833 * 32-bit depth surfaces are supported by the hardware.
6834 * This allows to maintain shader compatibility and to
6835 * reduce the number of depth decompressions.
6839 if (iview
->image
->info
.samples
<= 1)
6841 else if (iview
->image
->info
.samples
<= 4)
6852 radv_initialise_ds_surface(struct radv_device
*device
,
6853 struct radv_ds_buffer_info
*ds
,
6854 struct radv_image_view
*iview
)
6856 unsigned level
= iview
->base_mip
;
6857 unsigned format
, stencil_format
;
6858 uint64_t va
, s_offs
, z_offs
;
6859 bool stencil_only
= false;
6860 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
6861 const struct radeon_surf
*surf
= &plane
->surface
;
6863 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
6865 memset(ds
, 0, sizeof(*ds
));
6866 switch (iview
->image
->vk_format
) {
6867 case VK_FORMAT_D24_UNORM_S8_UINT
:
6868 case VK_FORMAT_X8_D24_UNORM_PACK32
:
6869 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
6870 ds
->offset_scale
= 2.0f
;
6872 case VK_FORMAT_D16_UNORM
:
6873 case VK_FORMAT_D16_UNORM_S8_UINT
:
6874 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
6875 ds
->offset_scale
= 4.0f
;
6877 case VK_FORMAT_D32_SFLOAT
:
6878 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
6879 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
6880 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
6881 ds
->offset_scale
= 1.0f
;
6883 case VK_FORMAT_S8_UINT
:
6884 stencil_only
= true;
6890 format
= radv_translate_dbformat(iview
->image
->vk_format
);
6891 stencil_format
= surf
->has_stencil
?
6892 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
6894 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
6895 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
6896 S_028008_SLICE_MAX(max_slice
);
6897 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6898 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
6899 S_028008_SLICE_MAX_HI(max_slice
>> 11);
6902 ds
->db_htile_data_base
= 0;
6903 ds
->db_htile_surface
= 0;
6905 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
6906 s_offs
= z_offs
= va
;
6908 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
6909 assert(surf
->u
.gfx9
.surf_offset
== 0);
6910 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
6912 ds
->db_z_info
= S_028038_FORMAT(format
) |
6913 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
6914 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
6915 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
6916 S_028038_ZRANGE_PRECISION(1);
6917 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
6918 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
6920 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6921 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
6922 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
6925 ds
->db_depth_view
|= S_028008_MIPID(level
);
6926 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
6927 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
6929 if (radv_htile_enabled(iview
->image
, level
)) {
6930 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
6932 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6933 unsigned max_zplanes
=
6934 radv_calc_decompress_on_z_planes(device
, iview
);
6936 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6938 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6939 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
6940 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
6942 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
6943 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
6947 if (!surf
->has_stencil
)
6948 /* Use all of the htile_buffer for depth if there's no stencil. */
6949 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
6950 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6951 iview
->image
->htile_offset
;
6952 ds
->db_htile_data_base
= va
>> 8;
6953 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
6954 S_028ABC_PIPE_ALIGNED(1);
6956 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6957 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(1);
6961 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
6964 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
6966 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
6967 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
6969 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
6970 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
6971 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
6973 if (iview
->image
->info
.samples
> 1)
6974 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
6976 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
6977 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
6978 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
6979 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
6980 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
6981 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
6982 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
6983 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
6986 tile_mode
= stencil_tile_mode
;
6988 ds
->db_depth_info
|=
6989 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
6990 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
6991 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
6992 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
6993 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
6994 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
6995 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
6996 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
6998 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
6999 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
7000 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
7001 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
7003 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
7006 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
7007 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
7008 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
7010 if (radv_htile_enabled(iview
->image
, level
)) {
7011 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
7013 if (!surf
->has_stencil
&&
7014 !radv_image_is_tc_compat_htile(iview
->image
))
7015 /* Use all of the htile_buffer for depth if there's no stencil. */
7016 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
7018 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
7019 iview
->image
->htile_offset
;
7020 ds
->db_htile_data_base
= va
>> 8;
7021 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
7023 if (radv_image_is_tc_compat_htile(iview
->image
)) {
7024 unsigned max_zplanes
=
7025 radv_calc_decompress_on_z_planes(device
, iview
);
7027 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
7028 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
7033 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
7034 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
7037 VkResult
radv_CreateFramebuffer(
7039 const VkFramebufferCreateInfo
* pCreateInfo
,
7040 const VkAllocationCallbacks
* pAllocator
,
7041 VkFramebuffer
* pFramebuffer
)
7043 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7044 struct radv_framebuffer
*framebuffer
;
7045 const VkFramebufferAttachmentsCreateInfo
*imageless_create_info
=
7046 vk_find_struct_const(pCreateInfo
->pNext
,
7047 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO
);
7049 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
7051 size_t size
= sizeof(*framebuffer
);
7052 if (!imageless_create_info
)
7053 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
7054 framebuffer
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
7055 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
7056 if (framebuffer
== NULL
)
7057 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
7059 vk_object_base_init(&device
->vk
, &framebuffer
->base
,
7060 VK_OBJECT_TYPE_FRAMEBUFFER
);
7062 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
7063 framebuffer
->width
= pCreateInfo
->width
;
7064 framebuffer
->height
= pCreateInfo
->height
;
7065 framebuffer
->layers
= pCreateInfo
->layers
;
7066 if (imageless_create_info
) {
7067 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
7068 const VkFramebufferAttachmentImageInfo
*attachment
=
7069 imageless_create_info
->pAttachmentImageInfos
+ i
;
7070 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
7071 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
7072 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
7075 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
7076 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
7077 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
7078 framebuffer
->attachments
[i
] = iview
;
7079 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
7080 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
7081 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
7085 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
7089 void radv_DestroyFramebuffer(
7092 const VkAllocationCallbacks
* pAllocator
)
7094 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7095 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
7099 vk_object_base_finish(&fb
->base
);
7100 vk_free2(&device
->vk
.alloc
, pAllocator
, fb
);
7103 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
7105 switch (address_mode
) {
7106 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
7107 return V_008F30_SQ_TEX_WRAP
;
7108 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
7109 return V_008F30_SQ_TEX_MIRROR
;
7110 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
7111 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
7112 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
7113 return V_008F30_SQ_TEX_CLAMP_BORDER
;
7114 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
7115 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
7117 unreachable("illegal tex wrap mode");
7123 radv_tex_compare(VkCompareOp op
)
7126 case VK_COMPARE_OP_NEVER
:
7127 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
7128 case VK_COMPARE_OP_LESS
:
7129 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
7130 case VK_COMPARE_OP_EQUAL
:
7131 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
7132 case VK_COMPARE_OP_LESS_OR_EQUAL
:
7133 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
7134 case VK_COMPARE_OP_GREATER
:
7135 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
7136 case VK_COMPARE_OP_NOT_EQUAL
:
7137 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
7138 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
7139 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
7140 case VK_COMPARE_OP_ALWAYS
:
7141 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
7143 unreachable("illegal compare mode");
7149 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
7152 case VK_FILTER_NEAREST
:
7153 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
7154 V_008F38_SQ_TEX_XY_FILTER_POINT
);
7155 case VK_FILTER_LINEAR
:
7156 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
7157 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
7158 case VK_FILTER_CUBIC_IMG
:
7160 fprintf(stderr
, "illegal texture filter");
7166 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
7169 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
7170 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
7171 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
7172 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
7174 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
7179 radv_tex_bordercolor(VkBorderColor bcolor
)
7182 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
7183 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
7184 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
7185 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
7186 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
7187 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
7188 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
7189 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
7190 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
7191 case VK_BORDER_COLOR_FLOAT_CUSTOM_EXT
:
7192 case VK_BORDER_COLOR_INT_CUSTOM_EXT
:
7193 return V_008F3C_SQ_TEX_BORDER_COLOR_REGISTER
;
7201 radv_tex_aniso_filter(unsigned filter
)
7215 radv_tex_filter_mode(VkSamplerReductionMode mode
)
7218 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
7219 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
7220 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
7221 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
7222 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
7223 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
7231 radv_get_max_anisotropy(struct radv_device
*device
,
7232 const VkSamplerCreateInfo
*pCreateInfo
)
7234 if (device
->force_aniso
>= 0)
7235 return device
->force_aniso
;
7237 if (pCreateInfo
->anisotropyEnable
&&
7238 pCreateInfo
->maxAnisotropy
> 1.0f
)
7239 return (uint32_t)pCreateInfo
->maxAnisotropy
;
7244 static inline int S_FIXED(float value
, unsigned frac_bits
)
7246 return value
* (1 << frac_bits
);
7249 static uint32_t radv_register_border_color(struct radv_device
*device
,
7250 VkClearColorValue value
)
7254 pthread_mutex_lock(&device
->border_color_data
.mutex
);
7256 for (slot
= 0; slot
< RADV_BORDER_COLOR_COUNT
; slot
++) {
7257 if (!device
->border_color_data
.used
[slot
]) {
7258 /* Copy to the GPU wrt endian-ness. */
7259 util_memcpy_cpu_to_le32(&device
->border_color_data
.colors_gpu_ptr
[slot
],
7261 sizeof(VkClearColorValue
));
7263 device
->border_color_data
.used
[slot
] = true;
7268 pthread_mutex_unlock(&device
->border_color_data
.mutex
);
7273 static void radv_unregister_border_color(struct radv_device
*device
,
7276 pthread_mutex_lock(&device
->border_color_data
.mutex
);
7278 device
->border_color_data
.used
[slot
] = false;
7280 pthread_mutex_unlock(&device
->border_color_data
.mutex
);
7284 radv_init_sampler(struct radv_device
*device
,
7285 struct radv_sampler
*sampler
,
7286 const VkSamplerCreateInfo
*pCreateInfo
)
7288 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
7289 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
7290 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
7291 device
->physical_device
->rad_info
.chip_class
== GFX9
;
7292 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
7293 unsigned depth_compare_func
= V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
7294 bool trunc_coord
= pCreateInfo
->minFilter
== VK_FILTER_NEAREST
&& pCreateInfo
->magFilter
== VK_FILTER_NEAREST
;
7295 bool uses_border_color
= pCreateInfo
->addressModeU
== VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
||
7296 pCreateInfo
->addressModeV
== VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
||
7297 pCreateInfo
->addressModeW
== VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
;
7298 VkBorderColor border_color
= uses_border_color
? pCreateInfo
->borderColor
: VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
;
7299 uint32_t border_color_ptr
;
7301 const struct VkSamplerReductionModeCreateInfo
*sampler_reduction
=
7302 vk_find_struct_const(pCreateInfo
->pNext
,
7303 SAMPLER_REDUCTION_MODE_CREATE_INFO
);
7304 if (sampler_reduction
)
7305 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
7307 if (pCreateInfo
->compareEnable
)
7308 depth_compare_func
= radv_tex_compare(pCreateInfo
->compareOp
);
7310 sampler
->border_color_slot
= RADV_BORDER_COLOR_COUNT
;
7312 if (border_color
== VK_BORDER_COLOR_FLOAT_CUSTOM_EXT
|| border_color
== VK_BORDER_COLOR_INT_CUSTOM_EXT
) {
7313 const VkSamplerCustomBorderColorCreateInfoEXT
*custom_border_color
=
7314 vk_find_struct_const(pCreateInfo
->pNext
,
7315 SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT
);
7317 assert(custom_border_color
);
7319 sampler
->border_color_slot
=
7320 radv_register_border_color(device
, custom_border_color
->customBorderColor
);
7322 /* Did we fail to find a slot? */
7323 if (sampler
->border_color_slot
== RADV_BORDER_COLOR_COUNT
) {
7324 fprintf(stderr
, "WARNING: no free border color slots, defaulting to TRANS_BLACK.\n");
7325 border_color
= VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
;
7329 /* If we don't have a custom color, set the ptr to 0 */
7330 border_color_ptr
= sampler
->border_color_slot
!= RADV_BORDER_COLOR_COUNT
7331 ? sampler
->border_color_slot
7334 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
7335 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
7336 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
7337 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
7338 S_008F30_DEPTH_COMPARE_FUNC(depth_compare_func
) |
7339 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
7340 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
7341 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
7342 S_008F30_DISABLE_CUBE_WRAP(0) |
7343 S_008F30_COMPAT_MODE(compat_mode
) |
7344 S_008F30_FILTER_MODE(filter_mode
) |
7345 S_008F30_TRUNC_COORD(trunc_coord
));
7346 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
7347 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
7348 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
7349 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
7350 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
7351 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
7352 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
7353 S_008F38_MIP_POINT_PRECLAMP(0));
7354 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(border_color_ptr
) |
7355 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(border_color
)));
7357 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
7358 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
7360 sampler
->state
[2] |=
7361 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
7362 S_008F38_FILTER_PREC_FIX(1) |
7363 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
7367 VkResult
radv_CreateSampler(
7369 const VkSamplerCreateInfo
* pCreateInfo
,
7370 const VkAllocationCallbacks
* pAllocator
,
7371 VkSampler
* pSampler
)
7373 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7374 struct radv_sampler
*sampler
;
7376 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
7377 vk_find_struct_const(pCreateInfo
->pNext
,
7378 SAMPLER_YCBCR_CONVERSION_INFO
);
7380 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
7382 sampler
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*sampler
), 8,
7383 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
7385 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
7387 vk_object_base_init(&device
->vk
, &sampler
->base
,
7388 VK_OBJECT_TYPE_SAMPLER
);
7390 radv_init_sampler(device
, sampler
, pCreateInfo
);
7392 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
7393 *pSampler
= radv_sampler_to_handle(sampler
);
7398 void radv_DestroySampler(
7401 const VkAllocationCallbacks
* pAllocator
)
7403 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7404 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
7409 if (sampler
->border_color_slot
!= RADV_BORDER_COLOR_COUNT
)
7410 radv_unregister_border_color(device
, sampler
->border_color_slot
);
7412 vk_object_base_finish(&sampler
->base
);
7413 vk_free2(&device
->vk
.alloc
, pAllocator
, sampler
);
7416 /* vk_icd.h does not declare this function, so we declare it here to
7417 * suppress Wmissing-prototypes.
7419 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
7420 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
7422 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
7423 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
7425 /* For the full details on loader interface versioning, see
7426 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
7427 * What follows is a condensed summary, to help you navigate the large and
7428 * confusing official doc.
7430 * - Loader interface v0 is incompatible with later versions. We don't
7433 * - In loader interface v1:
7434 * - The first ICD entrypoint called by the loader is
7435 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
7437 * - The ICD must statically expose no other Vulkan symbol unless it is
7438 * linked with -Bsymbolic.
7439 * - Each dispatchable Vulkan handle created by the ICD must be
7440 * a pointer to a struct whose first member is VK_LOADER_DATA. The
7441 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
7442 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
7443 * vkDestroySurfaceKHR(). The ICD must be capable of working with
7444 * such loader-managed surfaces.
7446 * - Loader interface v2 differs from v1 in:
7447 * - The first ICD entrypoint called by the loader is
7448 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
7449 * statically expose this entrypoint.
7451 * - Loader interface v3 differs from v2 in:
7452 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
7453 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
7454 * because the loader no longer does so.
7456 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
7460 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
7461 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
7464 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7465 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
7467 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
7469 /* At the moment, we support only the below handle types. */
7470 assert(pGetFdInfo
->handleType
==
7471 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
7472 pGetFdInfo
->handleType
==
7473 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
7475 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
7477 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
7481 static uint32_t radv_compute_valid_memory_types_attempt(struct radv_physical_device
*dev
,
7482 enum radeon_bo_domain domains
,
7483 enum radeon_bo_flag flags
,
7484 enum radeon_bo_flag ignore_flags
)
7486 /* Don't count GTT/CPU as relevant:
7488 * - We're not fully consistent between the two.
7489 * - Sometimes VRAM gets VRAM|GTT.
7491 const enum radeon_bo_domain relevant_domains
= RADEON_DOMAIN_VRAM
|
7495 for (unsigned i
= 0; i
< dev
->memory_properties
.memoryTypeCount
; ++i
) {
7496 if ((domains
& relevant_domains
) != (dev
->memory_domains
[i
] & relevant_domains
))
7499 if ((flags
& ~ignore_flags
) != (dev
->memory_flags
[i
] & ~ignore_flags
))
7508 static uint32_t radv_compute_valid_memory_types(struct radv_physical_device
*dev
,
7509 enum radeon_bo_domain domains
,
7510 enum radeon_bo_flag flags
)
7512 enum radeon_bo_flag ignore_flags
= ~(RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_GTT_WC
);
7513 uint32_t bits
= radv_compute_valid_memory_types_attempt(dev
, domains
, flags
, ignore_flags
);
7516 ignore_flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
7517 bits
= radv_compute_valid_memory_types_attempt(dev
, domains
, flags
, ignore_flags
);
7522 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
7523 VkExternalMemoryHandleTypeFlagBits handleType
,
7525 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
7527 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7529 switch (handleType
) {
7530 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
: {
7531 enum radeon_bo_domain domains
;
7532 enum radeon_bo_flag flags
;
7533 if (!device
->ws
->buffer_get_flags_from_fd(device
->ws
, fd
, &domains
, &flags
))
7534 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7536 pMemoryFdProperties
->memoryTypeBits
= radv_compute_valid_memory_types(device
->physical_device
, domains
, flags
);
7540 /* The valid usage section for this function says:
7542 * "handleType must not be one of the handle types defined as
7545 * So opaque handle types fall into the default "unsupported" case.
7547 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7551 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
7555 uint32_t syncobj_handle
= 0;
7556 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
7558 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7561 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
7563 *syncobj
= syncobj_handle
;
7569 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
7573 /* If we create a syncobj we do it locally so that if we have an error, we don't
7574 * leave a syncobj in an undetermined state in the fence. */
7575 uint32_t syncobj_handle
= *syncobj
;
7576 if (!syncobj_handle
) {
7577 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
7579 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7584 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
7586 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
7588 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7591 *syncobj
= syncobj_handle
;
7598 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
7599 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
7601 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7602 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
7604 struct radv_semaphore_part
*dst
= NULL
;
7606 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
7607 dst
= &sem
->temporary
;
7609 dst
= &sem
->permanent
;
7612 uint32_t syncobj
= dst
->kind
== RADV_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
7614 switch(pImportSemaphoreFdInfo
->handleType
) {
7615 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7616 result
= radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
7618 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
7619 result
= radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
7622 unreachable("Unhandled semaphore handle type");
7625 if (result
== VK_SUCCESS
) {
7626 dst
->syncobj
= syncobj
;
7627 dst
->kind
= RADV_SEMAPHORE_SYNCOBJ
;
7633 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
7634 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
7637 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7638 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
7640 uint32_t syncobj_handle
;
7642 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
7643 assert(sem
->temporary
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
7644 syncobj_handle
= sem
->temporary
.syncobj
;
7646 assert(sem
->permanent
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
7647 syncobj_handle
= sem
->permanent
.syncobj
;
7650 switch(pGetFdInfo
->handleType
) {
7651 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7652 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
7654 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
7655 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
7657 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
7658 radv_destroy_semaphore_part(device
, &sem
->temporary
);
7660 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
7665 unreachable("Unhandled semaphore handle type");
7669 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7673 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
7674 VkPhysicalDevice physicalDevice
,
7675 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
7676 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
7678 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
7679 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pExternalSemaphoreInfo
->pNext
, NULL
);
7681 if (type
== VK_SEMAPHORE_TYPE_TIMELINE
) {
7682 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
7683 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
7684 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
7686 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
7687 } else if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
7688 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
7689 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
7690 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
7691 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
7692 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
7693 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7694 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
7695 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
7696 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
7697 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
7698 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7700 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
7701 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
7702 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
7706 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
7707 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
7709 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7710 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
7711 uint32_t *syncobj_dst
= NULL
;
7714 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
7715 syncobj_dst
= &fence
->temp_syncobj
;
7717 syncobj_dst
= &fence
->syncobj
;
7720 switch(pImportFenceFdInfo
->handleType
) {
7721 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7722 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
7723 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
7724 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
7726 unreachable("Unhandled fence handle type");
7730 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
7731 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
7734 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7735 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
7737 uint32_t syncobj_handle
;
7739 if (fence
->temp_syncobj
)
7740 syncobj_handle
= fence
->temp_syncobj
;
7742 syncobj_handle
= fence
->syncobj
;
7744 switch(pGetFdInfo
->handleType
) {
7745 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
7746 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
7748 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
7749 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
7751 if (fence
->temp_syncobj
) {
7752 close (fence
->temp_syncobj
);
7753 fence
->temp_syncobj
= 0;
7755 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
7760 unreachable("Unhandled fence handle type");
7764 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
7768 void radv_GetPhysicalDeviceExternalFenceProperties(
7769 VkPhysicalDevice physicalDevice
,
7770 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
7771 VkExternalFenceProperties
*pExternalFenceProperties
)
7773 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
7775 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
7776 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
7777 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
7778 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
7779 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
7780 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
7781 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
7783 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
7784 pExternalFenceProperties
->compatibleHandleTypes
= 0;
7785 pExternalFenceProperties
->externalFenceFeatures
= 0;
7790 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
7791 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
7792 const VkAllocationCallbacks
* pAllocator
,
7793 VkDebugReportCallbackEXT
* pCallback
)
7795 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7796 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
7797 pCreateInfo
, pAllocator
, &instance
->alloc
,
7802 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
7803 VkDebugReportCallbackEXT _callback
,
7804 const VkAllocationCallbacks
* pAllocator
)
7806 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7807 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
7808 _callback
, pAllocator
, &instance
->alloc
);
7812 radv_DebugReportMessageEXT(VkInstance _instance
,
7813 VkDebugReportFlagsEXT flags
,
7814 VkDebugReportObjectTypeEXT objectType
,
7817 int32_t messageCode
,
7818 const char* pLayerPrefix
,
7819 const char* pMessage
)
7821 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
7822 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
7823 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
7827 radv_GetDeviceGroupPeerMemoryFeatures(
7830 uint32_t localDeviceIndex
,
7831 uint32_t remoteDeviceIndex
,
7832 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
7834 assert(localDeviceIndex
== remoteDeviceIndex
);
7836 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
7837 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
7838 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
7839 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
7842 static const VkTimeDomainEXT radv_time_domains
[] = {
7843 VK_TIME_DOMAIN_DEVICE_EXT
,
7844 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
7845 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
7848 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
7849 VkPhysicalDevice physicalDevice
,
7850 uint32_t *pTimeDomainCount
,
7851 VkTimeDomainEXT
*pTimeDomains
)
7854 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
7856 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
7857 vk_outarray_append(&out
, i
) {
7858 *i
= radv_time_domains
[d
];
7862 return vk_outarray_status(&out
);
7866 radv_clock_gettime(clockid_t clock_id
)
7868 struct timespec current
;
7871 ret
= clock_gettime(clock_id
, ¤t
);
7872 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
7873 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
7877 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
7880 VkResult
radv_GetCalibratedTimestampsEXT(
7882 uint32_t timestampCount
,
7883 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
7884 uint64_t *pTimestamps
,
7885 uint64_t *pMaxDeviation
)
7887 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7888 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
7890 uint64_t begin
, end
;
7891 uint64_t max_clock_period
= 0;
7893 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
7895 for (d
= 0; d
< timestampCount
; d
++) {
7896 switch (pTimestampInfos
[d
].timeDomain
) {
7897 case VK_TIME_DOMAIN_DEVICE_EXT
:
7898 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
7900 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
7901 max_clock_period
= MAX2(max_clock_period
, device_period
);
7903 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
7904 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
7905 max_clock_period
= MAX2(max_clock_period
, 1);
7908 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
7909 pTimestamps
[d
] = begin
;
7917 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
7920 * The maximum deviation is the sum of the interval over which we
7921 * perform the sampling and the maximum period of any sampled
7922 * clock. That's because the maximum skew between any two sampled
7923 * clock edges is when the sampled clock with the largest period is
7924 * sampled at the end of that period but right at the beginning of the
7925 * sampling interval and some other clock is sampled right at the
7926 * begining of its sampling period and right at the end of the
7927 * sampling interval. Let's assume the GPU has the longest clock
7928 * period and that the application is sampling GPU and monotonic:
7931 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
7932 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
7936 * GPU -----_____-----_____-----_____-----_____
7939 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
7940 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
7942 * Interval <----------------->
7943 * Deviation <-------------------------->
7947 * m = read(monotonic) 2
7950 * We round the sample interval up by one tick to cover sampling error
7951 * in the interval clock
7954 uint64_t sample_interval
= end
- begin
+ 1;
7956 *pMaxDeviation
= sample_interval
+ max_clock_period
;
7961 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
7962 VkPhysicalDevice physicalDevice
,
7963 VkSampleCountFlagBits samples
,
7964 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
7966 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
7967 VK_SAMPLE_COUNT_4_BIT
|
7968 VK_SAMPLE_COUNT_8_BIT
)) {
7969 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
7971 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };
7975 VkResult
radv_CreatePrivateDataSlotEXT(
7977 const VkPrivateDataSlotCreateInfoEXT
* pCreateInfo
,
7978 const VkAllocationCallbacks
* pAllocator
,
7979 VkPrivateDataSlotEXT
* pPrivateDataSlot
)
7981 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7982 return vk_private_data_slot_create(&device
->vk
, pCreateInfo
, pAllocator
,
7986 void radv_DestroyPrivateDataSlotEXT(
7988 VkPrivateDataSlotEXT privateDataSlot
,
7989 const VkAllocationCallbacks
* pAllocator
)
7991 RADV_FROM_HANDLE(radv_device
, device
, _device
);
7992 vk_private_data_slot_destroy(&device
->vk
, privateDataSlot
, pAllocator
);
7995 VkResult
radv_SetPrivateDataEXT(
7997 VkObjectType objectType
,
7998 uint64_t objectHandle
,
7999 VkPrivateDataSlotEXT privateDataSlot
,
8002 RADV_FROM_HANDLE(radv_device
, device
, _device
);
8003 return vk_object_base_set_private_data(&device
->vk
, objectType
,
8004 objectHandle
, privateDataSlot
,
8008 void radv_GetPrivateDataEXT(
8010 VkObjectType objectType
,
8011 uint64_t objectHandle
,
8012 VkPrivateDataSlotEXT privateDataSlot
,
8015 RADV_FROM_HANDLE(radv_device
, device
, _device
);
8016 vk_object_base_get_private_data(&device
->vk
, objectType
, objectHandle
,
8017 privateDataSlot
, pData
);