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
30 #include <linux/audit.h>
31 #include <linux/bpf.h>
32 #include <linux/filter.h>
33 #include <linux/seccomp.h>
34 #include <linux/unistd.h>
39 #include <sys/prctl.h>
43 #include <llvm/Config/llvm-config.h>
45 #include "radv_debug.h"
46 #include "radv_private.h"
47 #include "radv_shader.h"
49 #include "util/disk_cache.h"
53 #include <amdgpu_drm.h>
54 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
55 #include "ac_llvm_util.h"
56 #include "vk_format.h"
59 #include "util/build_id.h"
60 #include "util/debug.h"
61 #include "util/mesa-sha1.h"
62 #include "util/timespec.h"
63 #include "util/u_atomic.h"
64 #include "compiler/glsl_types.h"
65 #include "util/xmlpool.h"
67 static struct radv_timeline_point
*
68 radv_timeline_find_point_at_least_locked(struct radv_device
*device
,
69 struct radv_timeline
*timeline
,
72 static struct radv_timeline_point
*
73 radv_timeline_add_point_locked(struct radv_device
*device
,
74 struct radv_timeline
*timeline
,
78 radv_timeline_trigger_waiters_locked(struct radv_timeline
*timeline
,
79 struct list_head
*processing_list
);
82 void radv_destroy_semaphore_part(struct radv_device
*device
,
83 struct radv_semaphore_part
*part
);
86 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
89 unsigned char sha1
[20];
90 unsigned ptr_size
= sizeof(void*);
92 memset(uuid
, 0, VK_UUID_SIZE
);
93 _mesa_sha1_init(&ctx
);
95 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
96 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
99 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
100 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
101 _mesa_sha1_final(&ctx
, sha1
);
103 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
108 radv_get_driver_uuid(void *uuid
)
110 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
114 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
116 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
120 radv_get_visible_vram_size(struct radv_physical_device
*device
)
122 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
126 radv_get_vram_size(struct radv_physical_device
*device
)
128 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
132 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
134 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
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
,
146 if (visible_vram_size
) {
147 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
148 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
149 .size
= visible_vram_size
,
150 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
153 if (device
->rad_info
.gart_size
> 0) {
154 gart_index
= device
->memory_properties
.memoryHeapCount
++;
155 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
156 .size
= device
->rad_info
.gart_size
,
157 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
161 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
162 unsigned type_count
= 0;
163 if (vram_index
>= 0) {
164 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
165 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
166 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
167 .heapIndex
= vram_index
,
170 if (gart_index
>= 0 && device
->rad_info
.has_dedicated_vram
) {
171 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
172 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
173 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
174 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
175 .heapIndex
= gart_index
,
178 if (visible_vram_index
>= 0) {
179 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
180 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
181 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
182 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
183 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
184 .heapIndex
= visible_vram_index
,
187 if (gart_index
>= 0 && !device
->rad_info
.has_dedicated_vram
) {
188 /* Put GTT after visible VRAM for GPUs without dedicated VRAM
189 * as they have identical property flags, and according to the
190 * spec, for types with identical flags, the one with greater
191 * performance must be given a lower index. */
192 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
193 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
194 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
195 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
196 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
197 .heapIndex
= gart_index
,
200 if (gart_index
>= 0) {
201 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
202 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
203 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
204 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
205 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
206 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
207 .heapIndex
= gart_index
,
210 device
->memory_properties
.memoryTypeCount
= type_count
;
214 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
216 const char *family
= getenv("RADV_FORCE_FAMILY");
222 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
223 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
224 /* Override family and chip_class. */
225 device
->rad_info
.family
= i
;
227 if (i
>= CHIP_NAVI10
)
228 device
->rad_info
.chip_class
= GFX10
;
229 else if (i
>= CHIP_VEGA10
)
230 device
->rad_info
.chip_class
= GFX9
;
231 else if (i
>= CHIP_TONGA
)
232 device
->rad_info
.chip_class
= GFX8
;
233 else if (i
>= CHIP_BONAIRE
)
234 device
->rad_info
.chip_class
= GFX7
;
236 device
->rad_info
.chip_class
= GFX6
;
242 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
247 radv_physical_device_init(struct radv_physical_device
*device
,
248 struct radv_instance
*instance
,
249 drmDevicePtr drm_device
)
251 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
253 drmVersionPtr version
;
257 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
259 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
260 radv_logi("Could not open device '%s'", path
);
262 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
265 version
= drmGetVersion(fd
);
269 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
270 radv_logi("Could not get the kernel driver version for device '%s'", path
);
272 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
273 "failed to get version %s: %m", path
);
276 if (strcmp(version
->name
, "amdgpu")) {
277 drmFreeVersion(version
);
280 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
281 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
283 return VK_ERROR_INCOMPATIBLE_DRIVER
;
285 drmFreeVersion(version
);
287 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
288 radv_logi("Found compatible device '%s'.", path
);
290 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
291 device
->instance
= instance
;
293 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
294 instance
->perftest_flags
);
296 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
300 if (instance
->enabled_extensions
.KHR_display
) {
301 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
302 if (master_fd
>= 0) {
303 uint32_t accel_working
= 0;
304 struct drm_amdgpu_info request
= {
305 .return_pointer
= (uintptr_t)&accel_working
,
306 .return_size
= sizeof(accel_working
),
307 .query
= AMDGPU_INFO_ACCEL_WORKING
310 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
317 device
->master_fd
= master_fd
;
318 device
->local_fd
= fd
;
319 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
321 radv_handle_env_var_force_family(device
);
323 device
->use_aco
= instance
->perftest_flags
& RADV_PERFTEST_ACO
;
324 if (device
->rad_info
.chip_class
< GFX8
&& device
->use_aco
) {
325 fprintf(stderr
, "WARNING: disabling ACO on unsupported GPUs.\n");
326 device
->use_aco
= false;
329 snprintf(device
->name
, sizeof(device
->name
),
330 "AMD RADV%s %s (LLVM " MESA_LLVM_VERSION_STRING
")", device
->use_aco
? "/ACO" : "",
331 device
->rad_info
.name
);
333 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
334 device
->ws
->destroy(device
->ws
);
335 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
336 "cannot generate UUID");
340 /* These flags affect shader compilation. */
341 uint64_t shader_env_flags
=
342 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
343 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0) |
344 (device
->use_aco
? 0x4 : 0);
346 /* The gpu id is already embedded in the uuid so we just pass "radv"
347 * when creating the cache.
349 char buf
[VK_UUID_SIZE
* 2 + 1];
350 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
351 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
353 if (device
->rad_info
.chip_class
< GFX8
||
354 device
->rad_info
.chip_class
> GFX9
)
355 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
357 radv_get_driver_uuid(&device
->driver_uuid
);
358 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
360 device
->out_of_order_rast_allowed
= device
->rad_info
.has_out_of_order_rast
&&
361 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
363 device
->dcc_msaa_allowed
=
364 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
366 device
->use_shader_ballot
= device
->rad_info
.chip_class
>= GFX8
&&
367 (device
->use_aco
|| device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
);
369 device
->use_ngg
= device
->rad_info
.chip_class
>= GFX10
&&
370 device
->rad_info
.family
!= CHIP_NAVI14
&&
371 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_NGG
);
372 if (device
->use_aco
&& device
->use_ngg
) {
373 fprintf(stderr
, "WARNING: disabling NGG because ACO is used.\n");
374 device
->use_ngg
= false;
377 device
->use_ngg_streamout
= false;
379 /* Determine the number of threads per wave for all stages. */
380 device
->cs_wave_size
= 64;
381 device
->ps_wave_size
= 64;
382 device
->ge_wave_size
= 64;
384 if (device
->rad_info
.chip_class
>= GFX10
) {
385 if (device
->instance
->perftest_flags
& RADV_PERFTEST_CS_WAVE_32
)
386 device
->cs_wave_size
= 32;
388 /* For pixel shaders, wave64 is recommanded. */
389 if (device
->instance
->perftest_flags
& RADV_PERFTEST_PS_WAVE_32
)
390 device
->ps_wave_size
= 32;
392 if (device
->instance
->perftest_flags
& RADV_PERFTEST_GE_WAVE_32
)
393 device
->ge_wave_size
= 32;
396 radv_physical_device_init_mem_types(device
);
397 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
399 device
->bus_info
= *drm_device
->businfo
.pci
;
401 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
402 ac_print_gpu_info(&device
->rad_info
);
404 /* The WSI is structured as a layer on top of the driver, so this has
405 * to be the last part of initialization (at least until we get other
408 result
= radv_init_wsi(device
);
409 if (result
!= VK_SUCCESS
) {
410 device
->ws
->destroy(device
->ws
);
411 vk_error(instance
, result
);
425 radv_physical_device_finish(struct radv_physical_device
*device
)
427 radv_finish_wsi(device
);
428 device
->ws
->destroy(device
->ws
);
429 disk_cache_destroy(device
->disk_cache
);
430 close(device
->local_fd
);
431 if (device
->master_fd
!= -1)
432 close(device
->master_fd
);
436 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
437 VkSystemAllocationScope allocationScope
)
443 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
444 size_t align
, VkSystemAllocationScope allocationScope
)
446 return realloc(pOriginal
, size
);
450 default_free_func(void *pUserData
, void *pMemory
)
455 static const VkAllocationCallbacks default_alloc
= {
457 .pfnAllocation
= default_alloc_func
,
458 .pfnReallocation
= default_realloc_func
,
459 .pfnFree
= default_free_func
,
462 static const struct debug_control radv_debug_options
[] = {
463 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
464 {"nodcc", RADV_DEBUG_NO_DCC
},
465 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
466 {"nocache", RADV_DEBUG_NO_CACHE
},
467 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
468 {"nohiz", RADV_DEBUG_NO_HIZ
},
469 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
470 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
471 {"allbos", RADV_DEBUG_ALL_BOS
},
472 {"noibs", RADV_DEBUG_NO_IBS
},
473 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
474 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
475 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
476 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
477 {"nosisched", RADV_DEBUG_NO_SISCHED
},
478 {"preoptir", RADV_DEBUG_PREOPTIR
},
479 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
480 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
481 {"info", RADV_DEBUG_INFO
},
482 {"errors", RADV_DEBUG_ERRORS
},
483 {"startup", RADV_DEBUG_STARTUP
},
484 {"checkir", RADV_DEBUG_CHECKIR
},
485 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
486 {"nobinning", RADV_DEBUG_NOBINNING
},
487 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
488 {"nongg", RADV_DEBUG_NO_NGG
},
489 {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT
},
490 {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS
},
491 {"metashaders", RADV_DEBUG_DUMP_META_SHADERS
},
492 {"nomemorycache", RADV_DEBUG_NO_MEMORY_CACHE
},
497 radv_get_debug_option_name(int id
)
499 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
500 return radv_debug_options
[id
].string
;
503 static const struct debug_control radv_perftest_options
[] = {
504 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
505 {"sisched", RADV_PERFTEST_SISCHED
},
506 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
507 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
508 {"bolist", RADV_PERFTEST_BO_LIST
},
509 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
510 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
511 {"cswave32", RADV_PERFTEST_CS_WAVE_32
},
512 {"pswave32", RADV_PERFTEST_PS_WAVE_32
},
513 {"gewave32", RADV_PERFTEST_GE_WAVE_32
},
514 {"dfsm", RADV_PERFTEST_DFSM
},
515 {"aco", RADV_PERFTEST_ACO
},
520 radv_get_perftest_option_name(int id
)
522 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
523 return radv_perftest_options
[id
].string
;
527 radv_handle_per_app_options(struct radv_instance
*instance
,
528 const VkApplicationInfo
*info
)
530 const char *name
= info
? info
->pApplicationName
: NULL
;
535 if (!strcmp(name
, "Talos - Linux - 32bit") ||
536 !strcmp(name
, "Talos - Linux - 64bit")) {
537 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
538 /* Force enable LLVM sisched for Talos because it looks
539 * safe and it gives few more FPS.
541 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
543 } else if (!strcmp(name
, "DOOM_VFR")) {
544 /* Work around a Doom VFR game bug */
545 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
546 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
547 /* Workaround for a WaW hazard when LLVM moves/merges
548 * load/store memory operations.
549 * See https://reviews.llvm.org/D61313
551 if (LLVM_VERSION_MAJOR
< 9)
552 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
553 } else if (!strcmp(name
, "Wolfenstein: Youngblood")) {
554 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SHADER_BALLOT
)) {
555 /* Force enable VK_AMD_shader_ballot because it looks
556 * safe and it gives a nice boost (+20% on Vega 56 at
559 instance
->perftest_flags
|= RADV_PERFTEST_SHADER_BALLOT
;
561 } else if (!strcmp(name
, "Fledge")) {
563 * Zero VRAM for "The Surge 2"
565 * This avoid a hang when when rendering any level. Likely
566 * uninitialized data in an indirect draw.
568 instance
->debug_flags
|= RADV_DEBUG_ZERO_VRAM
;
572 static int radv_get_instance_extension_index(const char *name
)
574 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
575 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
581 static const char radv_dri_options_xml
[] =
583 DRI_CONF_SECTION_PERFORMANCE
584 DRI_CONF_ADAPTIVE_SYNC("true")
585 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
586 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
590 static void radv_init_dri_options(struct radv_instance
*instance
)
592 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
593 driParseConfigFiles(&instance
->dri_options
,
594 &instance
->available_dri_options
,
596 instance
->engineName
,
597 instance
->engineVersion
);
600 VkResult
radv_CreateInstance(
601 const VkInstanceCreateInfo
* pCreateInfo
,
602 const VkAllocationCallbacks
* pAllocator
,
603 VkInstance
* pInstance
)
605 struct radv_instance
*instance
;
608 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
610 uint32_t client_version
;
611 if (pCreateInfo
->pApplicationInfo
&&
612 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
613 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
615 client_version
= VK_API_VERSION_1_0
;
618 const char *engine_name
= NULL
;
619 uint32_t engine_version
= 0;
620 if (pCreateInfo
->pApplicationInfo
) {
621 engine_name
= pCreateInfo
->pApplicationInfo
->pEngineName
;
622 engine_version
= pCreateInfo
->pApplicationInfo
->engineVersion
;
625 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
626 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
628 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
630 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
633 instance
->alloc
= *pAllocator
;
635 instance
->alloc
= default_alloc
;
637 instance
->apiVersion
= client_version
;
638 instance
->physicalDeviceCount
= -1;
640 /* Get secure compile thread count. NOTE: We cap this at 32 */
641 #define MAX_SC_PROCS 32
642 char *num_sc_threads
= getenv("RADV_SECURE_COMPILE_THREADS");
644 instance
->num_sc_threads
= MIN2(strtoul(num_sc_threads
, NULL
, 10), MAX_SC_PROCS
);
646 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
649 /* Disable memory cache when secure compile is set */
650 if (radv_device_use_secure_compile(instance
))
651 instance
->debug_flags
|= RADV_DEBUG_NO_MEMORY_CACHE
;
653 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
654 radv_perftest_options
);
656 if (instance
->perftest_flags
& RADV_PERFTEST_ACO
)
657 fprintf(stderr
, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
659 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
660 radv_logi("Created an instance");
662 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
663 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
664 int index
= radv_get_instance_extension_index(ext_name
);
666 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
667 vk_free2(&default_alloc
, pAllocator
, instance
);
668 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
671 instance
->enabled_extensions
.extensions
[index
] = true;
674 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
675 if (result
!= VK_SUCCESS
) {
676 vk_free2(&default_alloc
, pAllocator
, instance
);
677 return vk_error(instance
, result
);
680 instance
->engineName
= vk_strdup(&instance
->alloc
, engine_name
,
681 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
682 instance
->engineVersion
= engine_version
;
684 glsl_type_singleton_init_or_ref();
686 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
688 radv_init_dri_options(instance
);
689 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
691 *pInstance
= radv_instance_to_handle(instance
);
696 void radv_DestroyInstance(
697 VkInstance _instance
,
698 const VkAllocationCallbacks
* pAllocator
)
700 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
705 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
706 radv_physical_device_finish(instance
->physicalDevices
+ i
);
709 vk_free(&instance
->alloc
, instance
->engineName
);
711 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
713 glsl_type_singleton_decref();
715 driDestroyOptionCache(&instance
->dri_options
);
716 driDestroyOptionInfo(&instance
->available_dri_options
);
718 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
720 vk_free(&instance
->alloc
, instance
);
724 radv_enumerate_devices(struct radv_instance
*instance
)
726 /* TODO: Check for more devices ? */
727 drmDevicePtr devices
[8];
728 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
731 instance
->physicalDeviceCount
= 0;
733 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
735 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
736 radv_logi("Found %d drm nodes", max_devices
);
739 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
741 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
742 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
743 devices
[i
]->bustype
== DRM_BUS_PCI
&&
744 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
746 result
= radv_physical_device_init(instance
->physicalDevices
+
747 instance
->physicalDeviceCount
,
750 if (result
== VK_SUCCESS
)
751 ++instance
->physicalDeviceCount
;
752 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
756 drmFreeDevices(devices
, max_devices
);
761 VkResult
radv_EnumeratePhysicalDevices(
762 VkInstance _instance
,
763 uint32_t* pPhysicalDeviceCount
,
764 VkPhysicalDevice
* pPhysicalDevices
)
766 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
769 if (instance
->physicalDeviceCount
< 0) {
770 result
= radv_enumerate_devices(instance
);
771 if (result
!= VK_SUCCESS
&&
772 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
776 if (!pPhysicalDevices
) {
777 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
779 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
780 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
781 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
784 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
788 VkResult
radv_EnumeratePhysicalDeviceGroups(
789 VkInstance _instance
,
790 uint32_t* pPhysicalDeviceGroupCount
,
791 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
793 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
796 if (instance
->physicalDeviceCount
< 0) {
797 result
= radv_enumerate_devices(instance
);
798 if (result
!= VK_SUCCESS
&&
799 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
803 if (!pPhysicalDeviceGroupProperties
) {
804 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
806 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
807 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
808 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
809 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
810 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
813 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
817 void radv_GetPhysicalDeviceFeatures(
818 VkPhysicalDevice physicalDevice
,
819 VkPhysicalDeviceFeatures
* pFeatures
)
821 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
822 memset(pFeatures
, 0, sizeof(*pFeatures
));
824 *pFeatures
= (VkPhysicalDeviceFeatures
) {
825 .robustBufferAccess
= true,
826 .fullDrawIndexUint32
= true,
827 .imageCubeArray
= true,
828 .independentBlend
= true,
829 .geometryShader
= true,
830 .tessellationShader
= true,
831 .sampleRateShading
= true,
832 .dualSrcBlend
= true,
834 .multiDrawIndirect
= true,
835 .drawIndirectFirstInstance
= true,
837 .depthBiasClamp
= true,
838 .fillModeNonSolid
= true,
843 .multiViewport
= true,
844 .samplerAnisotropy
= true,
845 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
846 .textureCompressionASTC_LDR
= false,
847 .textureCompressionBC
= true,
848 .occlusionQueryPrecise
= true,
849 .pipelineStatisticsQuery
= true,
850 .vertexPipelineStoresAndAtomics
= true,
851 .fragmentStoresAndAtomics
= true,
852 .shaderTessellationAndGeometryPointSize
= true,
853 .shaderImageGatherExtended
= true,
854 .shaderStorageImageExtendedFormats
= true,
855 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
856 .shaderUniformBufferArrayDynamicIndexing
= true,
857 .shaderSampledImageArrayDynamicIndexing
= true,
858 .shaderStorageBufferArrayDynamicIndexing
= true,
859 .shaderStorageImageArrayDynamicIndexing
= true,
860 .shaderStorageImageReadWithoutFormat
= true,
861 .shaderStorageImageWriteWithoutFormat
= true,
862 .shaderClipDistance
= true,
863 .shaderCullDistance
= true,
864 .shaderFloat64
= true,
866 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
&& !pdevice
->use_aco
,
867 .sparseBinding
= true,
868 .variableMultisampleRate
= true,
869 .inheritedQueries
= true,
873 void radv_GetPhysicalDeviceFeatures2(
874 VkPhysicalDevice physicalDevice
,
875 VkPhysicalDeviceFeatures2
*pFeatures
)
877 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
878 vk_foreach_struct(ext
, pFeatures
->pNext
) {
879 switch (ext
->sType
) {
880 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
881 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
882 features
->variablePointersStorageBuffer
= true;
883 features
->variablePointers
= true;
886 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
887 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
888 features
->multiview
= true;
889 features
->multiviewGeometryShader
= true;
890 features
->multiviewTessellationShader
= true;
893 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
894 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
895 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
896 features
->shaderDrawParameters
= true;
899 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
900 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
901 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
902 features
->protectedMemory
= false;
905 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
906 VkPhysicalDevice16BitStorageFeatures
*features
=
907 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
908 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
909 features
->storageBuffer16BitAccess
= enabled
;
910 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
911 features
->storagePushConstant16
= enabled
;
912 features
->storageInputOutput16
= enabled
&& LLVM_VERSION_MAJOR
>= 9;
915 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
916 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
917 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
918 features
->samplerYcbcrConversion
= true;
921 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
922 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
923 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
924 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
925 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
926 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
927 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
928 features
->shaderSampledImageArrayNonUniformIndexing
= true;
929 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
930 features
->shaderStorageImageArrayNonUniformIndexing
= true;
931 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
932 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
933 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
934 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
935 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
936 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
937 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
938 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
939 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
940 features
->descriptorBindingUpdateUnusedWhilePending
= true;
941 features
->descriptorBindingPartiallyBound
= true;
942 features
->descriptorBindingVariableDescriptorCount
= true;
943 features
->runtimeDescriptorArray
= true;
946 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
947 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
948 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
949 features
->conditionalRendering
= true;
950 features
->inheritedConditionalRendering
= false;
953 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
954 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
955 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
956 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
957 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
960 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
961 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
962 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
963 features
->transformFeedback
= true;
964 features
->geometryStreams
= !pdevice
->use_ngg_streamout
;
967 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
968 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
969 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
970 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
973 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
974 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
975 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
976 features
->memoryPriority
= VK_TRUE
;
979 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
980 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
981 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
982 features
->bufferDeviceAddress
= true;
983 features
->bufferDeviceAddressCaptureReplay
= false;
984 features
->bufferDeviceAddressMultiDevice
= false;
987 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
988 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
989 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
990 features
->depthClipEnable
= true;
993 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
994 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
995 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
996 features
->hostQueryReset
= true;
999 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
1000 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
1001 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
1002 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
1003 features
->storageBuffer8BitAccess
= enabled
;
1004 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
1005 features
->storagePushConstant8
= enabled
;
1008 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR
: {
1009 VkPhysicalDeviceShaderFloat16Int8FeaturesKHR
*features
=
1010 (VkPhysicalDeviceShaderFloat16Int8FeaturesKHR
*)ext
;
1011 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& !pdevice
->use_aco
;
1012 features
->shaderInt8
= !pdevice
->use_aco
;
1015 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
1016 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
1017 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
1018 features
->shaderBufferInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1019 features
->shaderSharedInt64Atomics
= LLVM_VERSION_MAJOR
>= 9;
1022 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT
: {
1023 VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*features
=
1024 (VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT
*)ext
;
1025 features
->shaderDemoteToHelperInvocation
= pdevice
->use_aco
;
1028 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
1029 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
1030 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
1032 features
->inlineUniformBlock
= true;
1033 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
1036 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
1037 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
1038 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
1039 features
->computeDerivativeGroupQuads
= false;
1040 features
->computeDerivativeGroupLinear
= true;
1043 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
1044 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
1045 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
1046 features
->ycbcrImageArrays
= true;
1049 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
1050 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
1051 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
1052 features
->uniformBufferStandardLayout
= true;
1055 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT
: {
1056 VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*features
=
1057 (VkPhysicalDeviceIndexTypeUint8FeaturesEXT
*)ext
;
1058 features
->indexTypeUint8
= pdevice
->rad_info
.chip_class
>= GFX8
;
1061 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR
: {
1062 VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*features
=
1063 (VkPhysicalDeviceImagelessFramebufferFeaturesKHR
*)ext
;
1064 features
->imagelessFramebuffer
= true;
1067 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR
: {
1068 VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*features
=
1069 (VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR
*)ext
;
1070 features
->pipelineExecutableInfo
= true;
1073 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
: {
1074 VkPhysicalDeviceShaderClockFeaturesKHR
*features
=
1075 (VkPhysicalDeviceShaderClockFeaturesKHR
*)ext
;
1076 features
->shaderSubgroupClock
= true;
1077 features
->shaderDeviceClock
= false;
1080 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT
: {
1081 VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*features
=
1082 (VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT
*)ext
;
1083 features
->texelBufferAlignment
= true;
1086 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR
: {
1087 VkPhysicalDeviceTimelineSemaphoreFeaturesKHR
*features
=
1088 (VkPhysicalDeviceTimelineSemaphoreFeaturesKHR
*) ext
;
1089 features
->timelineSemaphore
= true;
1096 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
1099 void radv_GetPhysicalDeviceProperties(
1100 VkPhysicalDevice physicalDevice
,
1101 VkPhysicalDeviceProperties
* pProperties
)
1103 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1104 VkSampleCountFlags sample_counts
= 0xf;
1106 /* make sure that the entire descriptor set is addressable with a signed
1107 * 32-bit int. So the sum of all limits scaled by descriptor size has to
1108 * be at most 2 GiB. the combined image & samples object count as one of
1109 * both. This limit is for the pipeline layout, not for the set layout, but
1110 * there is no set limit, so we just set a pipeline limit. I don't think
1111 * any app is going to hit this soon. */
1112 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1113 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1114 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1115 32 /* sampler, largest when combined with image */ +
1116 64 /* sampled image */ +
1117 64 /* storage image */);
1119 VkPhysicalDeviceLimits limits
= {
1120 .maxImageDimension1D
= (1 << 14),
1121 .maxImageDimension2D
= (1 << 14),
1122 .maxImageDimension3D
= (1 << 11),
1123 .maxImageDimensionCube
= (1 << 14),
1124 .maxImageArrayLayers
= (1 << 11),
1125 .maxTexelBufferElements
= 128 * 1024 * 1024,
1126 .maxUniformBufferRange
= UINT32_MAX
,
1127 .maxStorageBufferRange
= UINT32_MAX
,
1128 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1129 .maxMemoryAllocationCount
= UINT32_MAX
,
1130 .maxSamplerAllocationCount
= 64 * 1024,
1131 .bufferImageGranularity
= 64, /* A cache line */
1132 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1133 .maxBoundDescriptorSets
= MAX_SETS
,
1134 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1135 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1136 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1137 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1138 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1139 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1140 .maxPerStageResources
= max_descriptor_set_size
,
1141 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1142 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1143 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1144 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1145 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1146 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1147 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1148 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1149 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1150 .maxVertexInputBindings
= MAX_VBS
,
1151 .maxVertexInputAttributeOffset
= 2047,
1152 .maxVertexInputBindingStride
= 2048,
1153 .maxVertexOutputComponents
= 128,
1154 .maxTessellationGenerationLevel
= 64,
1155 .maxTessellationPatchSize
= 32,
1156 .maxTessellationControlPerVertexInputComponents
= 128,
1157 .maxTessellationControlPerVertexOutputComponents
= 128,
1158 .maxTessellationControlPerPatchOutputComponents
= 120,
1159 .maxTessellationControlTotalOutputComponents
= 4096,
1160 .maxTessellationEvaluationInputComponents
= 128,
1161 .maxTessellationEvaluationOutputComponents
= 128,
1162 .maxGeometryShaderInvocations
= 127,
1163 .maxGeometryInputComponents
= 64,
1164 .maxGeometryOutputComponents
= 128,
1165 .maxGeometryOutputVertices
= 256,
1166 .maxGeometryTotalOutputComponents
= 1024,
1167 .maxFragmentInputComponents
= 128,
1168 .maxFragmentOutputAttachments
= 8,
1169 .maxFragmentDualSrcAttachments
= 1,
1170 .maxFragmentCombinedOutputResources
= 8,
1171 .maxComputeSharedMemorySize
= 32768,
1172 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1173 .maxComputeWorkGroupInvocations
= 2048,
1174 .maxComputeWorkGroupSize
= {
1179 .subPixelPrecisionBits
= 8,
1180 .subTexelPrecisionBits
= 8,
1181 .mipmapPrecisionBits
= 8,
1182 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1183 .maxDrawIndirectCount
= UINT32_MAX
,
1184 .maxSamplerLodBias
= 16,
1185 .maxSamplerAnisotropy
= 16,
1186 .maxViewports
= MAX_VIEWPORTS
,
1187 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1188 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1189 .viewportSubPixelBits
= 8,
1190 .minMemoryMapAlignment
= 4096, /* A page */
1191 .minTexelBufferOffsetAlignment
= 4,
1192 .minUniformBufferOffsetAlignment
= 4,
1193 .minStorageBufferOffsetAlignment
= 4,
1194 .minTexelOffset
= -32,
1195 .maxTexelOffset
= 31,
1196 .minTexelGatherOffset
= -32,
1197 .maxTexelGatherOffset
= 31,
1198 .minInterpolationOffset
= -2,
1199 .maxInterpolationOffset
= 2,
1200 .subPixelInterpolationOffsetBits
= 8,
1201 .maxFramebufferWidth
= (1 << 14),
1202 .maxFramebufferHeight
= (1 << 14),
1203 .maxFramebufferLayers
= (1 << 10),
1204 .framebufferColorSampleCounts
= sample_counts
,
1205 .framebufferDepthSampleCounts
= sample_counts
,
1206 .framebufferStencilSampleCounts
= sample_counts
,
1207 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1208 .maxColorAttachments
= MAX_RTS
,
1209 .sampledImageColorSampleCounts
= sample_counts
,
1210 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1211 .sampledImageDepthSampleCounts
= sample_counts
,
1212 .sampledImageStencilSampleCounts
= sample_counts
,
1213 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1214 .maxSampleMaskWords
= 1,
1215 .timestampComputeAndGraphics
= true,
1216 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1217 .maxClipDistances
= 8,
1218 .maxCullDistances
= 8,
1219 .maxCombinedClipAndCullDistances
= 8,
1220 .discreteQueuePriorities
= 2,
1221 .pointSizeRange
= { 0.0, 8192.0 },
1222 .lineWidthRange
= { 0.0, 7.9921875 },
1223 .pointSizeGranularity
= (1.0 / 8.0),
1224 .lineWidthGranularity
= (1.0 / 128.0),
1225 .strictLines
= false, /* FINISHME */
1226 .standardSampleLocations
= true,
1227 .optimalBufferCopyOffsetAlignment
= 128,
1228 .optimalBufferCopyRowPitchAlignment
= 128,
1229 .nonCoherentAtomSize
= 64,
1232 *pProperties
= (VkPhysicalDeviceProperties
) {
1233 .apiVersion
= radv_physical_device_api_version(pdevice
),
1234 .driverVersion
= vk_get_driver_version(),
1235 .vendorID
= ATI_VENDOR_ID
,
1236 .deviceID
= pdevice
->rad_info
.pci_id
,
1237 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1239 .sparseProperties
= {0},
1242 strcpy(pProperties
->deviceName
, pdevice
->name
);
1243 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1246 void radv_GetPhysicalDeviceProperties2(
1247 VkPhysicalDevice physicalDevice
,
1248 VkPhysicalDeviceProperties2
*pProperties
)
1250 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1251 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1253 vk_foreach_struct(ext
, pProperties
->pNext
) {
1254 switch (ext
->sType
) {
1255 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1256 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1257 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1258 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1261 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1262 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1263 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1264 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1265 properties
->deviceLUIDValid
= false;
1268 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1269 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1270 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1271 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1274 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1275 VkPhysicalDevicePointClippingProperties
*properties
=
1276 (VkPhysicalDevicePointClippingProperties
*)ext
;
1277 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1280 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1281 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1282 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1283 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1286 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1287 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1288 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1289 properties
->minImportedHostPointerAlignment
= 4096;
1292 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1293 VkPhysicalDeviceSubgroupProperties
*properties
=
1294 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1295 properties
->subgroupSize
= 64;
1296 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1297 properties
->supportedOperations
=
1298 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1299 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1300 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1301 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1302 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1303 properties
->supportedOperations
|=
1304 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1305 VK_SUBGROUP_FEATURE_CLUSTERED_BIT
|
1306 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1307 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1309 properties
->quadOperationsInAllStages
= true;
1312 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1313 VkPhysicalDeviceMaintenance3Properties
*properties
=
1314 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1315 /* Make sure everything is addressable by a signed 32-bit int, and
1316 * our largest descriptors are 96 bytes. */
1317 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1318 /* Our buffer size fields allow only this much */
1319 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1322 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1323 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1324 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1325 /* GFX6-8 only support single channel min/max filter. */
1326 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1327 properties
->filterMinmaxSingleComponentFormats
= true;
1330 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1331 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1332 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1334 /* Shader engines. */
1335 properties
->shaderEngineCount
=
1336 pdevice
->rad_info
.max_se
;
1337 properties
->shaderArraysPerEngineCount
=
1338 pdevice
->rad_info
.max_sh_per_se
;
1339 properties
->computeUnitsPerShaderArray
=
1340 pdevice
->rad_info
.num_good_cu_per_sh
;
1341 properties
->simdPerComputeUnit
= 4;
1342 properties
->wavefrontsPerSimd
=
1343 pdevice
->rad_info
.family
== CHIP_TONGA
||
1344 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1345 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1346 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1347 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1348 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1349 properties
->wavefrontSize
= 64;
1352 properties
->sgprsPerSimd
=
1353 pdevice
->rad_info
.num_physical_sgprs_per_simd
;
1354 properties
->minSgprAllocation
=
1355 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1356 properties
->maxSgprAllocation
=
1357 pdevice
->rad_info
.family
== CHIP_TONGA
||
1358 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1359 properties
->sgprAllocationGranularity
=
1360 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1363 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1364 properties
->minVgprAllocation
= 4;
1365 properties
->maxVgprAllocation
= 256;
1366 properties
->vgprAllocationGranularity
= 4;
1369 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD
: {
1370 VkPhysicalDeviceShaderCoreProperties2AMD
*properties
=
1371 (VkPhysicalDeviceShaderCoreProperties2AMD
*)ext
;
1373 properties
->shaderCoreFeatures
= 0;
1374 properties
->activeComputeUnitCount
=
1375 pdevice
->rad_info
.num_good_compute_units
;
1378 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1379 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1380 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1381 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1384 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1385 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1386 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1387 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1388 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1389 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1390 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1391 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1392 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1393 properties
->robustBufferAccessUpdateAfterBind
= false;
1394 properties
->quadDivergentImplicitLod
= false;
1396 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1397 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1398 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1399 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1400 32 /* sampler, largest when combined with image */ +
1401 64 /* sampled image */ +
1402 64 /* storage image */);
1403 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1404 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1405 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1406 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1407 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1408 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1409 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1410 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1411 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1412 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1413 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1414 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1415 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1416 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1417 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1420 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1421 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1422 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1423 properties
->protectedNoFault
= false;
1426 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1427 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1428 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1429 properties
->primitiveOverestimationSize
= 0;
1430 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1431 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1432 properties
->primitiveUnderestimation
= VK_FALSE
;
1433 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1434 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1435 properties
->degenerateLinesRasterized
= VK_FALSE
;
1436 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1437 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1440 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1441 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1442 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1443 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1444 properties
->pciBus
= pdevice
->bus_info
.bus
;
1445 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1446 properties
->pciFunction
= pdevice
->bus_info
.func
;
1449 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1450 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1451 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1453 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1454 snprintf(driver_props
->driverName
, VK_MAX_DRIVER_NAME_SIZE_KHR
, "radv");
1455 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1456 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1457 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1459 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1467 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1468 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1469 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1470 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1471 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1472 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1473 properties
->maxTransformFeedbackStreamDataSize
= 512;
1474 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1475 properties
->maxTransformFeedbackBufferDataStride
= 512;
1476 properties
->transformFeedbackQueries
= !pdevice
->use_ngg_streamout
;
1477 properties
->transformFeedbackStreamsLinesTriangles
= !pdevice
->use_ngg_streamout
;
1478 properties
->transformFeedbackRasterizationStreamSelect
= false;
1479 properties
->transformFeedbackDraw
= true;
1482 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1483 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1484 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1486 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1487 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1488 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1489 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1490 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1493 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1494 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1495 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1496 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1497 VK_SAMPLE_COUNT_4_BIT
|
1498 VK_SAMPLE_COUNT_8_BIT
;
1499 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1500 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1501 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1502 properties
->sampleLocationSubPixelBits
= 4;
1503 properties
->variableSampleLocations
= VK_FALSE
;
1506 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1507 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1508 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1510 /* We support all of the depth resolve modes */
1511 properties
->supportedDepthResolveModes
=
1512 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1513 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1514 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1515 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1517 /* Average doesn't make sense for stencil so we don't support that */
1518 properties
->supportedStencilResolveModes
=
1519 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1520 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1521 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1523 properties
->independentResolveNone
= VK_TRUE
;
1524 properties
->independentResolve
= VK_TRUE
;
1527 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT
: {
1528 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*properties
=
1529 (VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT
*)ext
;
1530 properties
->storageTexelBufferOffsetAlignmentBytes
= 4;
1531 properties
->storageTexelBufferOffsetSingleTexelAlignment
= true;
1532 properties
->uniformTexelBufferOffsetAlignmentBytes
= 4;
1533 properties
->uniformTexelBufferOffsetSingleTexelAlignment
= true;
1536 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR
: {
1537 VkPhysicalDeviceFloatControlsPropertiesKHR
*properties
=
1538 (VkPhysicalDeviceFloatControlsPropertiesKHR
*)ext
;
1540 /* On AMD hardware, denormals and rounding modes for
1541 * fp16/fp64 are controlled by the same config
1544 properties
->denormBehaviorIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1545 properties
->roundingModeIndependence
= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR
;
1547 /* Do not allow both preserving and flushing denorms
1548 * because different shaders in the same pipeline can
1549 * have different settings and this won't work for
1550 * merged shaders. To make it work, this requires LLVM
1551 * support for changing the register. The same logic
1552 * applies for the rounding modes because they are
1553 * configured with the same config register.
1555 properties
->shaderDenormFlushToZeroFloat32
= true;
1556 properties
->shaderDenormPreserveFloat32
= false;
1557 properties
->shaderRoundingModeRTEFloat32
= true;
1558 properties
->shaderRoundingModeRTZFloat32
= false;
1559 properties
->shaderSignedZeroInfNanPreserveFloat32
= true;
1561 properties
->shaderDenormFlushToZeroFloat16
= false;
1562 properties
->shaderDenormPreserveFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
1563 properties
->shaderRoundingModeRTEFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
1564 properties
->shaderRoundingModeRTZFloat16
= false;
1565 properties
->shaderSignedZeroInfNanPreserveFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
;
1567 properties
->shaderDenormFlushToZeroFloat64
= false;
1568 properties
->shaderDenormPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1569 properties
->shaderRoundingModeRTEFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1570 properties
->shaderRoundingModeRTZFloat64
= false;
1571 properties
->shaderSignedZeroInfNanPreserveFloat64
= pdevice
->rad_info
.chip_class
>= GFX8
;
1574 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES_KHR
: {
1575 VkPhysicalDeviceTimelineSemaphorePropertiesKHR
*props
=
1576 (VkPhysicalDeviceTimelineSemaphorePropertiesKHR
*) ext
;
1577 props
->maxTimelineSemaphoreValueDifference
= UINT64_MAX
;
1586 static void radv_get_physical_device_queue_family_properties(
1587 struct radv_physical_device
* pdevice
,
1589 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1591 int num_queue_families
= 1;
1593 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1594 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1595 num_queue_families
++;
1597 if (pQueueFamilyProperties
== NULL
) {
1598 *pCount
= num_queue_families
;
1607 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1608 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1609 VK_QUEUE_COMPUTE_BIT
|
1610 VK_QUEUE_TRANSFER_BIT
|
1611 VK_QUEUE_SPARSE_BINDING_BIT
,
1613 .timestampValidBits
= 64,
1614 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1619 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1620 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1621 if (*pCount
> idx
) {
1622 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1623 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1624 VK_QUEUE_TRANSFER_BIT
|
1625 VK_QUEUE_SPARSE_BINDING_BIT
,
1626 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1627 .timestampValidBits
= 64,
1628 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1636 void radv_GetPhysicalDeviceQueueFamilyProperties(
1637 VkPhysicalDevice physicalDevice
,
1639 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1641 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1642 if (!pQueueFamilyProperties
) {
1643 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1646 VkQueueFamilyProperties
*properties
[] = {
1647 pQueueFamilyProperties
+ 0,
1648 pQueueFamilyProperties
+ 1,
1649 pQueueFamilyProperties
+ 2,
1651 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1652 assert(*pCount
<= 3);
1655 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1656 VkPhysicalDevice physicalDevice
,
1658 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1660 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1661 if (!pQueueFamilyProperties
) {
1662 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1665 VkQueueFamilyProperties
*properties
[] = {
1666 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1667 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1668 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1670 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1671 assert(*pCount
<= 3);
1674 void radv_GetPhysicalDeviceMemoryProperties(
1675 VkPhysicalDevice physicalDevice
,
1676 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1678 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1680 *pMemoryProperties
= physical_device
->memory_properties
;
1684 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1685 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1687 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1688 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1689 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1690 uint64_t vram_size
= radv_get_vram_size(device
);
1691 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1692 uint64_t heap_budget
, heap_usage
;
1694 /* For all memory heaps, the computation of budget is as follow:
1695 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1697 * The Vulkan spec 1.1.97 says that the budget should include any
1698 * currently allocated device memory.
1700 * Note that the application heap usages are not really accurate (eg.
1701 * in presence of shared buffers).
1703 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1704 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1706 switch (device
->mem_type_indices
[i
]) {
1707 case RADV_MEM_TYPE_VRAM
:
1708 heap_usage
= device
->ws
->query_value(device
->ws
,
1709 RADEON_ALLOCATED_VRAM
);
1711 heap_budget
= vram_size
-
1712 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1715 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1716 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1718 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1719 heap_usage
= device
->ws
->query_value(device
->ws
,
1720 RADEON_ALLOCATED_VRAM_VIS
);
1722 heap_budget
= visible_vram_size
-
1723 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1726 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1727 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1729 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1730 heap_usage
= device
->ws
->query_value(device
->ws
,
1731 RADEON_ALLOCATED_GTT
);
1733 heap_budget
= gtt_size
-
1734 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1737 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1738 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1745 /* The heapBudget and heapUsage values must be zero for array elements
1746 * greater than or equal to
1747 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1749 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1750 memoryBudget
->heapBudget
[i
] = 0;
1751 memoryBudget
->heapUsage
[i
] = 0;
1755 void radv_GetPhysicalDeviceMemoryProperties2(
1756 VkPhysicalDevice physicalDevice
,
1757 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1759 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1760 &pMemoryProperties
->memoryProperties
);
1762 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1763 vk_find_struct(pMemoryProperties
->pNext
,
1764 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1766 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1769 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1771 VkExternalMemoryHandleTypeFlagBits handleType
,
1772 const void *pHostPointer
,
1773 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1775 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1779 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1780 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1781 uint32_t memoryTypeBits
= 0;
1782 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1783 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1784 memoryTypeBits
= (1 << i
);
1788 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1792 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1796 static enum radeon_ctx_priority
1797 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1799 /* Default to MEDIUM when a specific global priority isn't requested */
1801 return RADEON_CTX_PRIORITY_MEDIUM
;
1803 switch(pObj
->globalPriority
) {
1804 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1805 return RADEON_CTX_PRIORITY_REALTIME
;
1806 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1807 return RADEON_CTX_PRIORITY_HIGH
;
1808 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1809 return RADEON_CTX_PRIORITY_MEDIUM
;
1810 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1811 return RADEON_CTX_PRIORITY_LOW
;
1813 unreachable("Illegal global priority value");
1814 return RADEON_CTX_PRIORITY_INVALID
;
1819 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1820 uint32_t queue_family_index
, int idx
,
1821 VkDeviceQueueCreateFlags flags
,
1822 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1824 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1825 queue
->device
= device
;
1826 queue
->queue_family_index
= queue_family_index
;
1827 queue
->queue_idx
= idx
;
1828 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1829 queue
->flags
= flags
;
1831 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1833 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1835 list_inithead(&queue
->pending_submissions
);
1836 pthread_mutex_init(&queue
->pending_mutex
, NULL
);
1842 radv_queue_finish(struct radv_queue
*queue
)
1844 pthread_mutex_destroy(&queue
->pending_mutex
);
1847 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1849 if (queue
->initial_full_flush_preamble_cs
)
1850 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1851 if (queue
->initial_preamble_cs
)
1852 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1853 if (queue
->continue_preamble_cs
)
1854 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1855 if (queue
->descriptor_bo
)
1856 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1857 if (queue
->scratch_bo
)
1858 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1859 if (queue
->esgs_ring_bo
)
1860 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1861 if (queue
->gsvs_ring_bo
)
1862 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1863 if (queue
->tess_rings_bo
)
1864 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1866 queue
->device
->ws
->buffer_destroy(queue
->gds_bo
);
1867 if (queue
->gds_oa_bo
)
1868 queue
->device
->ws
->buffer_destroy(queue
->gds_oa_bo
);
1869 if (queue
->compute_scratch_bo
)
1870 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1874 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1876 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1877 bo_list
->list
.count
= bo_list
->capacity
= 0;
1878 bo_list
->list
.bos
= NULL
;
1882 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1884 free(bo_list
->list
.bos
);
1885 pthread_mutex_destroy(&bo_list
->mutex
);
1888 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1889 struct radeon_winsys_bo
*bo
)
1891 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1896 if (unlikely(!device
->use_global_bo_list
))
1899 pthread_mutex_lock(&bo_list
->mutex
);
1900 if (bo_list
->list
.count
== bo_list
->capacity
) {
1901 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1902 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1905 pthread_mutex_unlock(&bo_list
->mutex
);
1906 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1909 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1910 bo_list
->capacity
= capacity
;
1913 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1914 pthread_mutex_unlock(&bo_list
->mutex
);
1918 static void radv_bo_list_remove(struct radv_device
*device
,
1919 struct radeon_winsys_bo
*bo
)
1921 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1926 if (unlikely(!device
->use_global_bo_list
))
1929 pthread_mutex_lock(&bo_list
->mutex
);
1930 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1931 if (bo_list
->list
.bos
[i
] == bo
) {
1932 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1933 --bo_list
->list
.count
;
1937 pthread_mutex_unlock(&bo_list
->mutex
);
1941 radv_device_init_gs_info(struct radv_device
*device
)
1943 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1944 device
->physical_device
->rad_info
.family
);
1947 static int radv_get_device_extension_index(const char *name
)
1949 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1950 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1957 radv_get_int_debug_option(const char *name
, int default_value
)
1964 result
= default_value
;
1968 result
= strtol(str
, &endptr
, 0);
1969 if (str
== endptr
) {
1970 /* No digits founs. */
1971 result
= default_value
;
1978 static int install_seccomp_filter() {
1980 struct sock_filter filter
[] = {
1981 /* Check arch is 64bit x86 */
1982 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, arch
))),
1983 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, AUDIT_ARCH_X86_64
, 0, 12),
1985 /* Futex is required for mutex locks */
1986 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
1987 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_select
, 11, 0),
1989 /* Allow system exit calls for the forked process */
1990 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
1991 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_exit_group
, 9, 0),
1993 /* Allow system read calls */
1994 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
1995 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_read
, 7, 0),
1997 /* Allow system write calls */
1998 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
1999 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_write
, 5, 0),
2001 /* Allow system brk calls (we need this for malloc) */
2002 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2003 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_brk
, 3, 0),
2005 /* Futex is required for mutex locks */
2006 BPF_STMT(BPF_LD
+ BPF_W
+ BPF_ABS
, (offsetof(struct seccomp_data
, nr
))),
2007 BPF_JUMP(BPF_JMP
+ BPF_JEQ
+ BPF_K
, __NR_futex
, 1, 0),
2009 /* Return error if we hit a system call not on the whitelist */
2010 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ERRNO
| (EPERM
& SECCOMP_RET_DATA
)),
2012 /* Allow whitelisted system calls */
2013 BPF_STMT(BPF_RET
+ BPF_K
, SECCOMP_RET_ALLOW
),
2016 struct sock_fprog prog
= {
2017 .len
= (unsigned short)(sizeof(filter
) / sizeof(filter
[0])),
2021 if (prctl(PR_SET_NO_NEW_PRIVS
, 1, 0, 0, 0))
2024 if (prctl(PR_SET_SECCOMP
, SECCOMP_MODE_FILTER
, &prog
))
2030 /* Helper function with timeout support for reading from the pipe between
2031 * processes used for secure compile.
2033 bool radv_sc_read(int fd
, void *buf
, size_t size
, bool timeout
)
2042 /* We can't rely on the value of tv after calling select() so
2043 * we must reset it on each iteration of the loop.
2048 int rval
= select(fd
+ 1, &fds
, NULL
, NULL
, timeout
? &tv
: NULL
);
2054 ssize_t bytes_read
= read(fd
, buf
, size
);
2063 /* select timeout */
2069 static void run_secure_compile_device(struct radv_device
*device
, unsigned process
,
2070 int *fd_secure_input
, int *fd_secure_output
)
2072 enum radv_secure_compile_type sc_type
;
2073 if (install_seccomp_filter() == -1) {
2074 sc_type
= RADV_SC_TYPE_INIT_FAILURE
;
2076 sc_type
= RADV_SC_TYPE_INIT_SUCCESS
;
2077 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
[0];
2078 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
[1];
2081 write(fd_secure_output
[1], &sc_type
, sizeof(sc_type
));
2083 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
)
2084 goto secure_compile_exit
;
2087 radv_sc_read(fd_secure_input
[0], &sc_type
, sizeof(sc_type
), false);
2089 if (sc_type
== RADV_SC_TYPE_COMPILE_PIPELINE
) {
2090 struct radv_pipeline
*pipeline
;
2091 bool sc_read
= true;
2093 pipeline
= vk_zalloc2(&device
->alloc
, NULL
, sizeof(*pipeline
), 8,
2094 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2096 pipeline
->device
= device
;
2098 /* Read pipeline layout */
2099 struct radv_pipeline_layout layout
;
2100 sc_read
= radv_sc_read(fd_secure_input
[0], &layout
, sizeof(struct radv_pipeline_layout
), true);
2101 sc_read
&= radv_sc_read(fd_secure_input
[0], &layout
.num_sets
, sizeof(uint32_t), true);
2103 goto secure_compile_exit
;
2105 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++) {
2106 uint32_t layout_size
;
2107 sc_read
&= radv_sc_read(fd_secure_input
[0], &layout_size
, sizeof(uint32_t), true);
2109 goto secure_compile_exit
;
2111 layout
.set
[set
].layout
= malloc(layout_size
);
2112 layout
.set
[set
].layout
->layout_size
= layout_size
;
2113 sc_read
&= radv_sc_read(fd_secure_input
[0], layout
.set
[set
].layout
,
2114 layout
.set
[set
].layout
->layout_size
, true);
2117 pipeline
->layout
= &layout
;
2119 /* Read pipeline key */
2120 struct radv_pipeline_key key
;
2121 sc_read
&= radv_sc_read(fd_secure_input
[0], &key
, sizeof(struct radv_pipeline_key
), true);
2123 /* Read pipeline create flags */
2124 VkPipelineCreateFlags flags
;
2125 sc_read
&= radv_sc_read(fd_secure_input
[0], &flags
, sizeof(VkPipelineCreateFlags
), true);
2127 /* Read stage and shader information */
2128 uint32_t num_stages
;
2129 const VkPipelineShaderStageCreateInfo
*pStages
[MESA_SHADER_STAGES
] = { 0, };
2130 sc_read
&= radv_sc_read(fd_secure_input
[0], &num_stages
, sizeof(uint32_t), true);
2132 goto secure_compile_exit
;
2134 for (uint32_t i
= 0; i
< num_stages
; i
++) {
2137 gl_shader_stage stage
;
2138 sc_read
&= radv_sc_read(fd_secure_input
[0], &stage
, sizeof(gl_shader_stage
), true);
2140 VkPipelineShaderStageCreateInfo
*pStage
= calloc(1, sizeof(VkPipelineShaderStageCreateInfo
));
2142 /* Read entry point name */
2144 sc_read
&= radv_sc_read(fd_secure_input
[0], &name_size
, sizeof(size_t), true);
2146 goto secure_compile_exit
;
2148 char *ep_name
= malloc(name_size
);
2149 sc_read
&= radv_sc_read(fd_secure_input
[0], ep_name
, name_size
, true);
2150 pStage
->pName
= ep_name
;
2152 /* Read shader module */
2154 sc_read
&= radv_sc_read(fd_secure_input
[0], &module_size
, sizeof(size_t), true);
2156 goto secure_compile_exit
;
2158 struct radv_shader_module
*module
= malloc(module_size
);
2159 sc_read
&= radv_sc_read(fd_secure_input
[0], module
, module_size
, true);
2160 pStage
->module
= radv_shader_module_to_handle(module
);
2162 /* Read specialization info */
2164 sc_read
&= radv_sc_read(fd_secure_input
[0], &has_spec_info
, sizeof(bool), true);
2166 goto secure_compile_exit
;
2168 if (has_spec_info
) {
2169 VkSpecializationInfo
*specInfo
= malloc(sizeof(VkSpecializationInfo
));
2170 pStage
->pSpecializationInfo
= specInfo
;
2172 sc_read
&= radv_sc_read(fd_secure_input
[0], &specInfo
->dataSize
, sizeof(size_t), true);
2174 goto secure_compile_exit
;
2176 void *si_data
= malloc(specInfo
->dataSize
);
2177 sc_read
&= radv_sc_read(fd_secure_input
[0], si_data
, specInfo
->dataSize
, true);
2178 specInfo
->pData
= si_data
;
2180 sc_read
&= radv_sc_read(fd_secure_input
[0], &specInfo
->mapEntryCount
, sizeof(uint32_t), true);
2182 goto secure_compile_exit
;
2184 VkSpecializationMapEntry
*mapEntries
= malloc(sizeof(VkSpecializationMapEntry
) * specInfo
->mapEntryCount
);
2185 for (uint32_t j
= 0; j
< specInfo
->mapEntryCount
; j
++) {
2186 sc_read
&= radv_sc_read(fd_secure_input
[0], &mapEntries
[j
], sizeof(VkSpecializationMapEntry
), true);
2188 goto secure_compile_exit
;
2191 specInfo
->pMapEntries
= mapEntries
;
2194 pStages
[stage
] = pStage
;
2197 /* Compile the shaders */
2198 VkPipelineCreationFeedbackEXT
*stage_feedbacks
[MESA_SHADER_STAGES
] = { 0 };
2199 radv_create_shaders(pipeline
, device
, NULL
, &key
, pStages
, flags
, NULL
, stage_feedbacks
);
2201 /* free memory allocated above */
2202 for (uint32_t set
= 0; set
< layout
.num_sets
; set
++)
2203 free(layout
.set
[set
].layout
);
2205 for (uint32_t i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
2209 free((void *) pStages
[i
]->pName
);
2210 free(radv_shader_module_from_handle(pStages
[i
]->module
));
2211 if (pStages
[i
]->pSpecializationInfo
) {
2212 free((void *) pStages
[i
]->pSpecializationInfo
->pData
);
2213 free((void *) pStages
[i
]->pSpecializationInfo
->pMapEntries
);
2214 free((void *) pStages
[i
]->pSpecializationInfo
);
2216 free((void *) pStages
[i
]);
2219 vk_free(&device
->alloc
, pipeline
);
2221 sc_type
= RADV_SC_TYPE_COMPILE_PIPELINE_FINISHED
;
2222 write(fd_secure_output
[1], &sc_type
, sizeof(sc_type
));
2224 } else if (sc_type
== RADV_SC_TYPE_DESTROY_DEVICE
) {
2225 goto secure_compile_exit
;
2229 secure_compile_exit
:
2230 close(fd_secure_input
[1]);
2231 close(fd_secure_input
[0]);
2232 close(fd_secure_output
[1]);
2233 close(fd_secure_output
[0]);
2237 static void destroy_secure_compile_device(struct radv_device
*device
, unsigned process
)
2239 int fd_secure_input
= device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
;
2241 enum radv_secure_compile_type sc_type
= RADV_SC_TYPE_DESTROY_DEVICE
;
2242 write(fd_secure_input
, &sc_type
, sizeof(sc_type
));
2244 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
);
2245 close(device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
);
2248 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2251 static VkResult
fork_secure_compile_device(struct radv_device
*device
)
2253 device
->sc_state
= vk_zalloc(&device
->alloc
,
2254 sizeof(struct radv_secure_compile_state
),
2255 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2257 mtx_init(&device
->sc_state
->secure_compile_mutex
, mtx_plain
);
2259 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
2260 int fd_secure_input
[MAX_SC_PROCS
][2];
2261 int fd_secure_output
[MAX_SC_PROCS
][2];
2263 /* create pipe descriptors (used to communicate between processes) */
2264 for (unsigned i
= 0; i
< sc_threads
; i
++) {
2265 if (pipe(fd_secure_input
[i
]) == -1 ||
2266 pipe(fd_secure_output
[i
]) == -1) {
2267 return VK_ERROR_INITIALIZATION_FAILED
;
2271 device
->sc_state
->secure_compile_processes
= vk_zalloc(&device
->alloc
,
2272 sizeof(struct radv_secure_compile_process
) * sc_threads
, 8,
2273 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2275 for (unsigned process
= 0; process
< sc_threads
; process
++) {
2276 if ((device
->sc_state
->secure_compile_processes
[process
].sc_pid
= fork()) == 0) {
2277 device
->sc_state
->secure_compile_thread_counter
= process
;
2278 run_secure_compile_device(device
, process
, fd_secure_input
[process
], fd_secure_output
[process
]);
2280 if (device
->sc_state
->secure_compile_processes
[process
].sc_pid
== -1)
2281 return VK_ERROR_INITIALIZATION_FAILED
;
2283 /* Read the init result returned from the secure process */
2284 enum radv_secure_compile_type sc_type
;
2285 bool sc_read
= radv_sc_read(fd_secure_output
[process
][0], &sc_type
, sizeof(sc_type
), true);
2287 if (sc_type
== RADV_SC_TYPE_INIT_FAILURE
|| !sc_read
) {
2288 close(fd_secure_input
[process
][0]);
2289 close(fd_secure_input
[process
][1]);
2290 close(fd_secure_output
[process
][1]);
2291 close(fd_secure_output
[process
][0]);
2293 waitpid(device
->sc_state
->secure_compile_processes
[process
].sc_pid
, &status
, 0);
2295 /* Destroy any forks that were created sucessfully */
2296 for (unsigned i
= 0; i
< process
; i
++) {
2297 destroy_secure_compile_device(device
, i
);
2300 return VK_ERROR_INITIALIZATION_FAILED
;
2302 assert(sc_type
== RADV_SC_TYPE_INIT_SUCCESS
);
2303 device
->sc_state
->secure_compile_processes
[process
].fd_secure_input
= fd_secure_input
[process
][1];
2304 device
->sc_state
->secure_compile_processes
[process
].fd_secure_output
= fd_secure_output
[process
][0];
2312 radv_create_pthread_cond(pthread_cond_t
*cond
)
2314 pthread_condattr_t condattr
;
2315 if (pthread_condattr_init(&condattr
)) {
2316 return VK_ERROR_INITIALIZATION_FAILED
;
2319 if (pthread_condattr_setclock(&condattr
, CLOCK_MONOTONIC
)) {
2320 pthread_condattr_destroy(&condattr
);
2321 return VK_ERROR_INITIALIZATION_FAILED
;
2323 if (pthread_cond_init(cond
, &condattr
)) {
2324 pthread_condattr_destroy(&condattr
);
2325 return VK_ERROR_INITIALIZATION_FAILED
;
2327 pthread_condattr_destroy(&condattr
);
2331 VkResult
radv_CreateDevice(
2332 VkPhysicalDevice physicalDevice
,
2333 const VkDeviceCreateInfo
* pCreateInfo
,
2334 const VkAllocationCallbacks
* pAllocator
,
2337 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
2339 struct radv_device
*device
;
2341 bool keep_shader_info
= false;
2343 /* Check enabled features */
2344 if (pCreateInfo
->pEnabledFeatures
) {
2345 VkPhysicalDeviceFeatures supported_features
;
2346 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
2347 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
2348 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
2349 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
2350 for (uint32_t i
= 0; i
< num_features
; i
++) {
2351 if (enabled_feature
[i
] && !supported_feature
[i
])
2352 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
2356 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
2358 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2360 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2362 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
2363 device
->instance
= physical_device
->instance
;
2364 device
->physical_device
= physical_device
;
2366 device
->ws
= physical_device
->ws
;
2368 device
->alloc
= *pAllocator
;
2370 device
->alloc
= physical_device
->instance
->alloc
;
2372 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
2373 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
2374 int index
= radv_get_device_extension_index(ext_name
);
2375 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
2376 vk_free(&device
->alloc
, device
);
2377 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
2380 device
->enabled_extensions
.extensions
[index
] = true;
2383 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
2385 /* With update after bind we can't attach bo's to the command buffer
2386 * from the descriptor set anymore, so we have to use a global BO list.
2388 device
->use_global_bo_list
=
2389 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
2390 device
->enabled_extensions
.EXT_descriptor_indexing
||
2391 device
->enabled_extensions
.EXT_buffer_device_address
;
2393 device
->robust_buffer_access
= pCreateInfo
->pEnabledFeatures
&&
2394 pCreateInfo
->pEnabledFeatures
->robustBufferAccess
;
2396 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
2397 list_inithead(&device
->shader_slabs
);
2399 radv_bo_list_init(&device
->bo_list
);
2401 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
2402 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
2403 uint32_t qfi
= queue_create
->queueFamilyIndex
;
2404 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
2405 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
2407 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
2409 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
2410 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
2411 if (!device
->queues
[qfi
]) {
2412 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
2416 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
2418 device
->queue_count
[qfi
] = queue_create
->queueCount
;
2420 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
2421 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
2422 qfi
, q
, queue_create
->flags
,
2424 if (result
!= VK_SUCCESS
)
2429 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
2430 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
2432 /* Disable DFSM by default. As of 2019-09-15 Talos on Low is still 3% slower on Raven. */
2433 device
->dfsm_allowed
= device
->pbb_allowed
&&
2434 (device
->instance
->perftest_flags
& RADV_PERFTEST_DFSM
);
2436 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
2438 /* The maximum number of scratch waves. Scratch space isn't divided
2439 * evenly between CUs. The number is only a function of the number of CUs.
2440 * We can decrease the constant to decrease the scratch buffer size.
2442 * sctx->scratch_waves must be >= the maximum possible size of
2443 * 1 threadgroup, so that the hw doesn't hang from being unable
2446 * The recommended value is 4 per CU at most. Higher numbers don't
2447 * bring much benefit, but they still occupy chip resources (think
2448 * async compute). I've seen ~2% performance difference between 4 and 32.
2450 uint32_t max_threads_per_block
= 2048;
2451 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
2452 max_threads_per_block
/ 64);
2454 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
2455 S_00B800_CS_W32_EN(device
->physical_device
->cs_wave_size
== 32);
2457 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2458 /* If the KMD allows it (there is a KMD hw register for it),
2459 * allow launching waves out-of-order.
2461 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
2464 radv_device_init_gs_info(device
);
2466 device
->tess_offchip_block_dw_size
=
2467 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
2469 if (getenv("RADV_TRACE_FILE")) {
2470 const char *filename
= getenv("RADV_TRACE_FILE");
2472 keep_shader_info
= true;
2474 if (!radv_init_trace(device
))
2477 fprintf(stderr
, "*****************************************************************************\n");
2478 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
2479 fprintf(stderr
, "*****************************************************************************\n");
2481 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
2482 radv_dump_enabled_options(device
, stderr
);
2485 /* Temporarily disable secure compile while we create meta shaders, etc */
2486 uint8_t sc_threads
= device
->instance
->num_sc_threads
;
2488 device
->instance
->num_sc_threads
= 0;
2490 device
->keep_shader_info
= keep_shader_info
;
2491 result
= radv_device_init_meta(device
);
2492 if (result
!= VK_SUCCESS
)
2495 radv_device_init_msaa(device
);
2497 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
2498 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
2500 case RADV_QUEUE_GENERAL
:
2501 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2502 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
2503 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
2505 case RADV_QUEUE_COMPUTE
:
2506 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
2507 radeon_emit(device
->empty_cs
[family
], 0);
2510 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
2513 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
2514 cik_create_gfx_config(device
);
2516 VkPipelineCacheCreateInfo ci
;
2517 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
2520 ci
.pInitialData
= NULL
;
2521 ci
.initialDataSize
= 0;
2523 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
2525 if (result
!= VK_SUCCESS
)
2528 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
2530 result
= radv_create_pthread_cond(&device
->timeline_cond
);
2531 if (result
!= VK_SUCCESS
)
2532 goto fail_mem_cache
;
2534 device
->force_aniso
=
2535 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
2536 if (device
->force_aniso
>= 0) {
2537 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2538 1 << util_logbase2(device
->force_aniso
));
2541 /* Fork device for secure compile as required */
2542 device
->instance
->num_sc_threads
= sc_threads
;
2543 if (radv_device_use_secure_compile(device
->instance
)) {
2544 result
= fork_secure_compile_device(device
);
2545 if (result
!= VK_SUCCESS
)
2549 *pDevice
= radv_device_to_handle(device
);
2553 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2555 radv_device_finish_meta(device
);
2557 radv_bo_list_finish(&device
->bo_list
);
2559 if (device
->trace_bo
)
2560 device
->ws
->buffer_destroy(device
->trace_bo
);
2562 if (device
->gfx_init
)
2563 device
->ws
->buffer_destroy(device
->gfx_init
);
2565 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2566 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2567 radv_queue_finish(&device
->queues
[i
][q
]);
2568 if (device
->queue_count
[i
])
2569 vk_free(&device
->alloc
, device
->queues
[i
]);
2572 vk_free(&device
->alloc
, device
);
2576 void radv_DestroyDevice(
2578 const VkAllocationCallbacks
* pAllocator
)
2580 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2585 if (device
->trace_bo
)
2586 device
->ws
->buffer_destroy(device
->trace_bo
);
2588 if (device
->gfx_init
)
2589 device
->ws
->buffer_destroy(device
->gfx_init
);
2591 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2592 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2593 radv_queue_finish(&device
->queues
[i
][q
]);
2594 if (device
->queue_count
[i
])
2595 vk_free(&device
->alloc
, device
->queues
[i
]);
2596 if (device
->empty_cs
[i
])
2597 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2599 radv_device_finish_meta(device
);
2601 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2602 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2604 radv_destroy_shader_slabs(device
);
2606 pthread_cond_destroy(&device
->timeline_cond
);
2607 radv_bo_list_finish(&device
->bo_list
);
2609 if (radv_device_use_secure_compile(device
->instance
)) {
2610 for (unsigned i
= 0; i
< device
->instance
->num_sc_threads
; i
++ ) {
2611 destroy_secure_compile_device(device
, i
);
2615 if (device
->sc_state
)
2616 vk_free(&device
->alloc
, device
->sc_state
->secure_compile_processes
);
2617 vk_free(&device
->alloc
, device
->sc_state
);
2618 vk_free(&device
->alloc
, device
);
2621 VkResult
radv_EnumerateInstanceLayerProperties(
2622 uint32_t* pPropertyCount
,
2623 VkLayerProperties
* pProperties
)
2625 if (pProperties
== NULL
) {
2626 *pPropertyCount
= 0;
2630 /* None supported at this time */
2631 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2634 VkResult
radv_EnumerateDeviceLayerProperties(
2635 VkPhysicalDevice physicalDevice
,
2636 uint32_t* pPropertyCount
,
2637 VkLayerProperties
* pProperties
)
2639 if (pProperties
== NULL
) {
2640 *pPropertyCount
= 0;
2644 /* None supported at this time */
2645 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2648 void radv_GetDeviceQueue2(
2650 const VkDeviceQueueInfo2
* pQueueInfo
,
2653 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2654 struct radv_queue
*queue
;
2656 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2657 if (pQueueInfo
->flags
!= queue
->flags
) {
2658 /* From the Vulkan 1.1.70 spec:
2660 * "The queue returned by vkGetDeviceQueue2 must have the same
2661 * flags value from this structure as that used at device
2662 * creation time in a VkDeviceQueueCreateInfo instance. If no
2663 * matching flags were specified at device creation time then
2664 * pQueue will return VK_NULL_HANDLE."
2666 *pQueue
= VK_NULL_HANDLE
;
2670 *pQueue
= radv_queue_to_handle(queue
);
2673 void radv_GetDeviceQueue(
2675 uint32_t queueFamilyIndex
,
2676 uint32_t queueIndex
,
2679 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2680 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2681 .queueFamilyIndex
= queueFamilyIndex
,
2682 .queueIndex
= queueIndex
2685 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2689 fill_geom_tess_rings(struct radv_queue
*queue
,
2691 bool add_sample_positions
,
2692 uint32_t esgs_ring_size
,
2693 struct radeon_winsys_bo
*esgs_ring_bo
,
2694 uint32_t gsvs_ring_size
,
2695 struct radeon_winsys_bo
*gsvs_ring_bo
,
2696 uint32_t tess_factor_ring_size
,
2697 uint32_t tess_offchip_ring_offset
,
2698 uint32_t tess_offchip_ring_size
,
2699 struct radeon_winsys_bo
*tess_rings_bo
)
2701 uint32_t *desc
= &map
[4];
2704 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2706 /* stride 0, num records - size, add tid, swizzle, elsize4,
2709 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2710 S_008F04_SWIZZLE_ENABLE(true);
2711 desc
[2] = esgs_ring_size
;
2712 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2713 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2714 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2715 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2716 S_008F0C_INDEX_STRIDE(3) |
2717 S_008F0C_ADD_TID_ENABLE(1);
2719 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2720 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2721 S_008F0C_OOB_SELECT(2) |
2722 S_008F0C_RESOURCE_LEVEL(1);
2724 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2725 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2726 S_008F0C_ELEMENT_SIZE(1);
2729 /* GS entry for ES->GS ring */
2730 /* stride 0, num records - size, elsize0,
2733 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32);
2734 desc
[6] = esgs_ring_size
;
2735 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2736 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2737 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2738 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2740 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2741 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2742 S_008F0C_OOB_SELECT(2) |
2743 S_008F0C_RESOURCE_LEVEL(1);
2745 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2746 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2753 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2755 /* VS entry for GS->VS ring */
2756 /* stride 0, num records - size, elsize0,
2759 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32);
2760 desc
[2] = gsvs_ring_size
;
2761 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2762 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2763 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2764 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2766 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2767 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2768 S_008F0C_OOB_SELECT(2) |
2769 S_008F0C_RESOURCE_LEVEL(1);
2771 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2772 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2775 /* stride gsvs_itemsize, num records 64
2776 elsize 4, index stride 16 */
2777 /* shader will patch stride and desc[2] */
2779 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32) |
2780 S_008F04_SWIZZLE_ENABLE(1);
2782 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2783 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2784 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2785 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2786 S_008F0C_INDEX_STRIDE(1) |
2787 S_008F0C_ADD_TID_ENABLE(true);
2789 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2790 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2791 S_008F0C_OOB_SELECT(2) |
2792 S_008F0C_RESOURCE_LEVEL(1);
2794 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2795 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2796 S_008F0C_ELEMENT_SIZE(1);
2803 if (tess_rings_bo
) {
2804 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2805 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2808 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32);
2809 desc
[2] = tess_factor_ring_size
;
2810 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2811 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2812 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2813 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2815 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2816 desc
[3] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2817 S_008F0C_OOB_SELECT(3) |
2818 S_008F0C_RESOURCE_LEVEL(1);
2820 desc
[3] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2821 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2824 desc
[4] = tess_offchip_va
;
2825 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32);
2826 desc
[6] = tess_offchip_ring_size
;
2827 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2828 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2829 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2830 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
);
2832 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2833 desc
[7] |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT
) |
2834 S_008F0C_OOB_SELECT(3) |
2835 S_008F0C_RESOURCE_LEVEL(1);
2837 desc
[7] |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2838 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
2844 if (add_sample_positions
) {
2845 /* add sample positions after all rings */
2846 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2848 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2850 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2852 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2857 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2859 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2860 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2861 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2862 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2863 unsigned max_offchip_buffers
;
2864 unsigned offchip_granularity
;
2865 unsigned hs_offchip_param
;
2869 * This must be one less than the maximum number due to a hw limitation.
2870 * Various hardware bugs need thGFX7
2873 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2874 * Gfx7 should limit max_offchip_buffers to 508
2875 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2877 * Follow AMDVLK here.
2879 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2880 max_offchip_buffers_per_se
= 256;
2881 } else if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2882 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2883 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2884 --max_offchip_buffers_per_se
;
2886 max_offchip_buffers
= max_offchip_buffers_per_se
*
2887 device
->physical_device
->rad_info
.max_se
;
2889 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2890 * around by setting 4K granularity.
2892 if (device
->tess_offchip_block_dw_size
== 4096) {
2893 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2894 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2896 assert(device
->tess_offchip_block_dw_size
== 8192);
2897 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2900 switch (device
->physical_device
->rad_info
.chip_class
) {
2902 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2907 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2915 *max_offchip_buffers_p
= max_offchip_buffers
;
2916 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2917 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2918 --max_offchip_buffers
;
2920 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2921 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2924 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2926 return hs_offchip_param
;
2930 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2931 struct radeon_winsys_bo
*esgs_ring_bo
,
2932 uint32_t esgs_ring_size
,
2933 struct radeon_winsys_bo
*gsvs_ring_bo
,
2934 uint32_t gsvs_ring_size
)
2936 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2940 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2943 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2945 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2946 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2947 radeon_emit(cs
, esgs_ring_size
>> 8);
2948 radeon_emit(cs
, gsvs_ring_size
>> 8);
2950 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2951 radeon_emit(cs
, esgs_ring_size
>> 8);
2952 radeon_emit(cs
, gsvs_ring_size
>> 8);
2957 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2958 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2959 struct radeon_winsys_bo
*tess_rings_bo
)
2966 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2968 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2970 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2971 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2972 S_030938_SIZE(tf_ring_size
/ 4));
2973 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2976 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2977 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2978 S_030984_BASE_HI(tf_va
>> 40));
2979 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2980 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2981 S_030944_BASE_HI(tf_va
>> 40));
2983 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2986 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2987 S_008988_SIZE(tf_ring_size
/ 4));
2988 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2990 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2996 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2997 struct radeon_winsys_bo
*compute_scratch_bo
)
2999 uint64_t scratch_va
;
3001 if (!compute_scratch_bo
)
3004 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
3006 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
3008 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
3009 radeon_emit(cs
, scratch_va
);
3010 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3011 S_008F04_SWIZZLE_ENABLE(1));
3015 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
3016 struct radeon_cmdbuf
*cs
,
3017 struct radeon_winsys_bo
*descriptor_bo
)
3024 va
= radv_buffer_get_va(descriptor_bo
);
3026 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
3028 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
3029 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3030 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3031 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3032 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3034 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3035 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3038 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
3039 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3040 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3041 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
3042 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
3044 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3045 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3049 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
3050 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
3051 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
3052 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
3053 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
3054 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
3056 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
3057 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
3064 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3066 struct radv_device
*device
= queue
->device
;
3068 if (device
->gfx_init
) {
3069 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
3071 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
3072 radeon_emit(cs
, va
);
3073 radeon_emit(cs
, va
>> 32);
3074 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
3076 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
3078 struct radv_physical_device
*physical_device
= device
->physical_device
;
3079 si_emit_graphics(physical_device
, cs
);
3084 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
3086 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
3087 si_emit_compute(physical_device
, cs
);
3091 radv_get_preamble_cs(struct radv_queue
*queue
,
3092 uint32_t scratch_size
,
3093 uint32_t compute_scratch_size
,
3094 uint32_t esgs_ring_size
,
3095 uint32_t gsvs_ring_size
,
3096 bool needs_tess_rings
,
3098 bool needs_sample_positions
,
3099 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
3100 struct radeon_cmdbuf
**initial_preamble_cs
,
3101 struct radeon_cmdbuf
**continue_preamble_cs
)
3103 struct radeon_winsys_bo
*scratch_bo
= NULL
;
3104 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
3105 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
3106 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
3107 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
3108 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
3109 struct radeon_winsys_bo
*gds_bo
= NULL
;
3110 struct radeon_winsys_bo
*gds_oa_bo
= NULL
;
3111 struct radeon_cmdbuf
*dest_cs
[3] = {0};
3112 bool add_tess_rings
= false, add_gds
= false, add_sample_positions
= false;
3113 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
3114 unsigned max_offchip_buffers
;
3115 unsigned hs_offchip_param
= 0;
3116 unsigned tess_offchip_ring_offset
;
3117 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3118 if (!queue
->has_tess_rings
) {
3119 if (needs_tess_rings
)
3120 add_tess_rings
= true;
3122 if (!queue
->has_gds
) {
3126 if (!queue
->has_sample_positions
) {
3127 if (needs_sample_positions
)
3128 add_sample_positions
= true;
3130 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
3131 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
3132 &max_offchip_buffers
);
3133 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
3134 tess_offchip_ring_size
= max_offchip_buffers
*
3135 queue
->device
->tess_offchip_block_dw_size
* 4;
3137 if (scratch_size
<= queue
->scratch_size
&&
3138 compute_scratch_size
<= queue
->compute_scratch_size
&&
3139 esgs_ring_size
<= queue
->esgs_ring_size
&&
3140 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
3141 !add_tess_rings
&& !add_gds
&& !add_sample_positions
&&
3142 queue
->initial_preamble_cs
) {
3143 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
3144 *initial_preamble_cs
= queue
->initial_preamble_cs
;
3145 *continue_preamble_cs
= queue
->continue_preamble_cs
;
3146 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
&&
3147 !needs_tess_rings
&& !needs_gds
&& !needs_sample_positions
)
3148 *continue_preamble_cs
= NULL
;
3152 if (scratch_size
> queue
->scratch_size
) {
3153 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3158 RADV_BO_PRIORITY_SCRATCH
);
3162 scratch_bo
= queue
->scratch_bo
;
3164 if (compute_scratch_size
> queue
->compute_scratch_size
) {
3165 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3166 compute_scratch_size
,
3170 RADV_BO_PRIORITY_SCRATCH
);
3171 if (!compute_scratch_bo
)
3175 compute_scratch_bo
= queue
->compute_scratch_bo
;
3177 if (esgs_ring_size
> queue
->esgs_ring_size
) {
3178 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3183 RADV_BO_PRIORITY_SCRATCH
);
3187 esgs_ring_bo
= queue
->esgs_ring_bo
;
3188 esgs_ring_size
= queue
->esgs_ring_size
;
3191 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
3192 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3197 RADV_BO_PRIORITY_SCRATCH
);
3201 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
3202 gsvs_ring_size
= queue
->gsvs_ring_size
;
3205 if (add_tess_rings
) {
3206 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3207 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
3211 RADV_BO_PRIORITY_SCRATCH
);
3215 tess_rings_bo
= queue
->tess_rings_bo
;
3219 assert(queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
);
3221 /* 4 streamout GDS counters.
3222 * We need 256B (64 dw) of GDS, otherwise streamout hangs.
3224 gds_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3228 RADV_BO_PRIORITY_SCRATCH
);
3232 gds_oa_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3236 RADV_BO_PRIORITY_SCRATCH
);
3240 gds_bo
= queue
->gds_bo
;
3241 gds_oa_bo
= queue
->gds_oa_bo
;
3244 if (scratch_bo
!= queue
->scratch_bo
||
3245 esgs_ring_bo
!= queue
->esgs_ring_bo
||
3246 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
3247 tess_rings_bo
!= queue
->tess_rings_bo
||
3248 add_sample_positions
) {
3250 if (gsvs_ring_bo
|| esgs_ring_bo
||
3251 tess_rings_bo
|| add_sample_positions
) {
3252 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
3253 if (add_sample_positions
)
3254 size
+= 128; /* 64+32+16+8 = 120 bytes */
3256 else if (scratch_bo
)
3257 size
= 8; /* 2 dword */
3259 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
3263 RADEON_FLAG_CPU_ACCESS
|
3264 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
3265 RADEON_FLAG_READ_ONLY
,
3266 RADV_BO_PRIORITY_DESCRIPTOR
);
3270 descriptor_bo
= queue
->descriptor_bo
;
3272 if (descriptor_bo
!= queue
->descriptor_bo
) {
3273 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
3276 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
3277 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
3278 S_008F04_SWIZZLE_ENABLE(1);
3279 map
[0] = scratch_va
;
3283 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
3284 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
3285 esgs_ring_size
, esgs_ring_bo
,
3286 gsvs_ring_size
, gsvs_ring_bo
,
3287 tess_factor_ring_size
,
3288 tess_offchip_ring_offset
,
3289 tess_offchip_ring_size
,
3292 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
3295 for(int i
= 0; i
< 3; ++i
) {
3296 struct radeon_cmdbuf
*cs
= NULL
;
3297 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
3298 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
3305 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
3307 /* Emit initial configuration. */
3308 switch (queue
->queue_family_index
) {
3309 case RADV_QUEUE_GENERAL
:
3310 radv_init_graphics_state(cs
, queue
);
3312 case RADV_QUEUE_COMPUTE
:
3313 radv_init_compute_state(cs
, queue
);
3315 case RADV_QUEUE_TRANSFER
:
3319 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
3320 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
3321 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
3323 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
3324 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
3327 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
3328 gsvs_ring_bo
, gsvs_ring_size
);
3329 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
3330 tess_factor_ring_size
, tess_rings_bo
);
3331 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
3332 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
3335 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_bo
);
3337 radv_cs_add_buffer(queue
->device
->ws
, cs
, gds_oa_bo
);
3340 si_cs_emit_cache_flush(cs
,
3341 queue
->device
->physical_device
->rad_info
.chip_class
,
3343 queue
->queue_family_index
== RING_COMPUTE
&&
3344 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
3345 (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
)) |
3346 RADV_CMD_FLAG_INV_ICACHE
|
3347 RADV_CMD_FLAG_INV_SCACHE
|
3348 RADV_CMD_FLAG_INV_VCACHE
|
3349 RADV_CMD_FLAG_INV_L2
|
3350 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
3351 } else if (i
== 1) {
3352 si_cs_emit_cache_flush(cs
,
3353 queue
->device
->physical_device
->rad_info
.chip_class
,
3355 queue
->queue_family_index
== RING_COMPUTE
&&
3356 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
3357 RADV_CMD_FLAG_INV_ICACHE
|
3358 RADV_CMD_FLAG_INV_SCACHE
|
3359 RADV_CMD_FLAG_INV_VCACHE
|
3360 RADV_CMD_FLAG_INV_L2
|
3361 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
3364 if (!queue
->device
->ws
->cs_finalize(cs
))
3368 if (queue
->initial_full_flush_preamble_cs
)
3369 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
3371 if (queue
->initial_preamble_cs
)
3372 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
3374 if (queue
->continue_preamble_cs
)
3375 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
3377 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
3378 queue
->initial_preamble_cs
= dest_cs
[1];
3379 queue
->continue_preamble_cs
= dest_cs
[2];
3381 if (scratch_bo
!= queue
->scratch_bo
) {
3382 if (queue
->scratch_bo
)
3383 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
3384 queue
->scratch_bo
= scratch_bo
;
3385 queue
->scratch_size
= scratch_size
;
3388 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
3389 if (queue
->compute_scratch_bo
)
3390 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
3391 queue
->compute_scratch_bo
= compute_scratch_bo
;
3392 queue
->compute_scratch_size
= compute_scratch_size
;
3395 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
3396 if (queue
->esgs_ring_bo
)
3397 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
3398 queue
->esgs_ring_bo
= esgs_ring_bo
;
3399 queue
->esgs_ring_size
= esgs_ring_size
;
3402 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
3403 if (queue
->gsvs_ring_bo
)
3404 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
3405 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
3406 queue
->gsvs_ring_size
= gsvs_ring_size
;
3409 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
3410 queue
->tess_rings_bo
= tess_rings_bo
;
3411 queue
->has_tess_rings
= true;
3414 if (gds_bo
!= queue
->gds_bo
) {
3415 queue
->gds_bo
= gds_bo
;
3416 queue
->has_gds
= true;
3419 if (gds_oa_bo
!= queue
->gds_oa_bo
)
3420 queue
->gds_oa_bo
= gds_oa_bo
;
3422 if (descriptor_bo
!= queue
->descriptor_bo
) {
3423 if (queue
->descriptor_bo
)
3424 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
3426 queue
->descriptor_bo
= descriptor_bo
;
3429 if (add_sample_positions
)
3430 queue
->has_sample_positions
= true;
3432 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
3433 *initial_preamble_cs
= queue
->initial_preamble_cs
;
3434 *continue_preamble_cs
= queue
->continue_preamble_cs
;
3435 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
3436 *continue_preamble_cs
= NULL
;
3439 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
3441 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
3442 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
3443 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
3444 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
3445 queue
->device
->ws
->buffer_destroy(scratch_bo
);
3446 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
3447 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
3448 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
3449 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
3450 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
3451 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
3452 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
3453 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
3454 if (gds_bo
&& gds_bo
!= queue
->gds_bo
)
3455 queue
->device
->ws
->buffer_destroy(gds_bo
);
3456 if (gds_oa_bo
&& gds_oa_bo
!= queue
->gds_oa_bo
)
3457 queue
->device
->ws
->buffer_destroy(gds_oa_bo
);
3459 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3462 static VkResult
radv_alloc_sem_counts(struct radv_device
*device
,
3463 struct radv_winsys_sem_counts
*counts
,
3465 struct radv_semaphore_part
**sems
,
3466 const uint64_t *timeline_values
,
3470 int syncobj_idx
= 0, sem_idx
= 0;
3472 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
3475 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3476 switch(sems
[i
]->kind
) {
3477 case RADV_SEMAPHORE_SYNCOBJ
:
3478 counts
->syncobj_count
++;
3480 case RADV_SEMAPHORE_WINSYS
:
3481 counts
->sem_count
++;
3483 case RADV_SEMAPHORE_NONE
:
3485 case RADV_SEMAPHORE_TIMELINE
:
3486 counts
->syncobj_count
++;
3491 if (_fence
!= VK_NULL_HANDLE
) {
3492 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3493 if (fence
->temp_syncobj
|| fence
->syncobj
)
3494 counts
->syncobj_count
++;
3497 if (counts
->syncobj_count
) {
3498 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
3499 if (!counts
->syncobj
)
3500 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3503 if (counts
->sem_count
) {
3504 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
3506 free(counts
->syncobj
);
3507 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3511 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3512 switch(sems
[i
]->kind
) {
3513 case RADV_SEMAPHORE_NONE
:
3514 unreachable("Empty semaphore");
3516 case RADV_SEMAPHORE_SYNCOBJ
:
3517 counts
->syncobj
[syncobj_idx
++] = sems
[i
]->syncobj
;
3519 case RADV_SEMAPHORE_WINSYS
:
3520 counts
->sem
[sem_idx
++] = sems
[i
]->ws_sem
;
3522 case RADV_SEMAPHORE_TIMELINE
: {
3523 pthread_mutex_lock(&sems
[i
]->timeline
.mutex
);
3524 struct radv_timeline_point
*point
= NULL
;
3526 point
= radv_timeline_add_point_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
3528 point
= radv_timeline_find_point_at_least_locked(device
, &sems
[i
]->timeline
, timeline_values
[i
]);
3531 pthread_mutex_unlock(&sems
[i
]->timeline
.mutex
);
3534 counts
->syncobj
[syncobj_idx
++] = point
->syncobj
;
3536 /* Explicitly remove the semaphore so we might not find
3537 * a point later post-submit. */
3545 if (_fence
!= VK_NULL_HANDLE
) {
3546 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3547 if (fence
->temp_syncobj
)
3548 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
3549 else if (fence
->syncobj
)
3550 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
3553 assert(syncobj_idx
<= counts
->syncobj_count
);
3554 counts
->syncobj_count
= syncobj_idx
;
3560 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
3562 free(sem_info
->wait
.syncobj
);
3563 free(sem_info
->wait
.sem
);
3564 free(sem_info
->signal
.syncobj
);
3565 free(sem_info
->signal
.sem
);
3569 static void radv_free_temp_syncobjs(struct radv_device
*device
,
3571 struct radv_semaphore_part
*sems
)
3573 for (uint32_t i
= 0; i
< num_sems
; i
++) {
3574 radv_destroy_semaphore_part(device
, sems
+ i
);
3579 radv_alloc_sem_info(struct radv_device
*device
,
3580 struct radv_winsys_sem_info
*sem_info
,
3582 struct radv_semaphore_part
**wait_sems
,
3583 const uint64_t *wait_values
,
3584 int num_signal_sems
,
3585 struct radv_semaphore_part
**signal_sems
,
3586 const uint64_t *signal_values
,
3590 memset(sem_info
, 0, sizeof(*sem_info
));
3592 ret
= radv_alloc_sem_counts(device
, &sem_info
->wait
, num_wait_sems
, wait_sems
, wait_values
, VK_NULL_HANDLE
, false);
3595 ret
= radv_alloc_sem_counts(device
, &sem_info
->signal
, num_signal_sems
, signal_sems
, signal_values
, fence
, true);
3597 radv_free_sem_info(sem_info
);
3599 /* caller can override these */
3600 sem_info
->cs_emit_wait
= true;
3601 sem_info
->cs_emit_signal
= true;
3606 radv_finalize_timelines(struct radv_device
*device
,
3607 uint32_t num_wait_sems
,
3608 struct radv_semaphore_part
**wait_sems
,
3609 const uint64_t *wait_values
,
3610 uint32_t num_signal_sems
,
3611 struct radv_semaphore_part
**signal_sems
,
3612 const uint64_t *signal_values
,
3613 struct list_head
*processing_list
)
3615 for (uint32_t i
= 0; i
< num_wait_sems
; ++i
) {
3616 if (wait_sems
[i
] && wait_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
3617 pthread_mutex_lock(&wait_sems
[i
]->timeline
.mutex
);
3618 struct radv_timeline_point
*point
=
3619 radv_timeline_find_point_at_least_locked(device
, &wait_sems
[i
]->timeline
, wait_values
[i
]);
3621 --point
->wait_count
;
3622 pthread_mutex_unlock(&wait_sems
[i
]->timeline
.mutex
);
3625 for (uint32_t i
= 0; i
< num_signal_sems
; ++i
) {
3626 if (signal_sems
[i
] && signal_sems
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
3627 pthread_mutex_lock(&signal_sems
[i
]->timeline
.mutex
);
3628 struct radv_timeline_point
*point
=
3629 radv_timeline_find_point_at_least_locked(device
, &signal_sems
[i
]->timeline
, signal_values
[i
]);
3631 signal_sems
[i
]->timeline
.highest_submitted
=
3632 MAX2(signal_sems
[i
]->timeline
.highest_submitted
, point
->value
);
3633 point
->wait_count
--;
3635 radv_timeline_trigger_waiters_locked(&signal_sems
[i
]->timeline
, processing_list
);
3636 pthread_mutex_unlock(&signal_sems
[i
]->timeline
.mutex
);
3642 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3643 const VkSparseBufferMemoryBindInfo
*bind
)
3645 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3647 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3648 struct radv_device_memory
*mem
= NULL
;
3650 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3651 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3653 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3654 bind
->pBinds
[i
].resourceOffset
,
3655 bind
->pBinds
[i
].size
,
3656 mem
? mem
->bo
: NULL
,
3657 bind
->pBinds
[i
].memoryOffset
);
3662 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3663 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3665 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3667 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3668 struct radv_device_memory
*mem
= NULL
;
3670 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3671 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3673 device
->ws
->buffer_virtual_bind(image
->bo
,
3674 bind
->pBinds
[i
].resourceOffset
,
3675 bind
->pBinds
[i
].size
,
3676 mem
? mem
->bo
: NULL
,
3677 bind
->pBinds
[i
].memoryOffset
);
3682 radv_get_preambles(struct radv_queue
*queue
,
3683 const VkCommandBuffer
*cmd_buffers
,
3684 uint32_t cmd_buffer_count
,
3685 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
3686 struct radeon_cmdbuf
**initial_preamble_cs
,
3687 struct radeon_cmdbuf
**continue_preamble_cs
)
3689 uint32_t scratch_size
= 0;
3690 uint32_t compute_scratch_size
= 0;
3691 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
3692 bool tess_rings_needed
= false;
3693 bool gds_needed
= false;
3694 bool sample_positions_needed
= false;
3696 for (uint32_t j
= 0; j
< cmd_buffer_count
; j
++) {
3697 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3700 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
3701 compute_scratch_size
= MAX2(compute_scratch_size
,
3702 cmd_buffer
->compute_scratch_size_needed
);
3703 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
3704 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
3705 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
3706 gds_needed
|= cmd_buffer
->gds_needed
;
3707 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3710 return radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3711 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3712 gds_needed
, sample_positions_needed
,
3713 initial_full_flush_preamble_cs
,
3714 initial_preamble_cs
, continue_preamble_cs
);
3717 struct radv_deferred_queue_submission
{
3718 struct radv_queue
*queue
;
3719 VkCommandBuffer
*cmd_buffers
;
3720 uint32_t cmd_buffer_count
;
3722 /* Sparse bindings that happen on a queue. */
3723 VkSparseBufferMemoryBindInfo
*buffer_binds
;
3724 uint32_t buffer_bind_count
;
3725 VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
3726 uint32_t image_opaque_bind_count
;
3729 VkShaderStageFlags wait_dst_stage_mask
;
3730 struct radv_semaphore_part
**wait_semaphores
;
3731 uint32_t wait_semaphore_count
;
3732 struct radv_semaphore_part
**signal_semaphores
;
3733 uint32_t signal_semaphore_count
;
3736 uint64_t *wait_values
;
3737 uint64_t *signal_values
;
3739 struct radv_semaphore_part
*temporary_semaphore_parts
;
3740 uint32_t temporary_semaphore_part_count
;
3742 struct list_head queue_pending_list
;
3743 uint32_t submission_wait_count
;
3744 struct radv_timeline_waiter
*wait_nodes
;
3746 struct list_head processing_list
;
3749 struct radv_queue_submission
{
3750 const VkCommandBuffer
*cmd_buffers
;
3751 uint32_t cmd_buffer_count
;
3753 /* Sparse bindings that happen on a queue. */
3754 const VkSparseBufferMemoryBindInfo
*buffer_binds
;
3755 uint32_t buffer_bind_count
;
3756 const VkSparseImageOpaqueMemoryBindInfo
*image_opaque_binds
;
3757 uint32_t image_opaque_bind_count
;
3760 VkPipelineStageFlags wait_dst_stage_mask
;
3761 const VkSemaphore
*wait_semaphores
;
3762 uint32_t wait_semaphore_count
;
3763 const VkSemaphore
*signal_semaphores
;
3764 uint32_t signal_semaphore_count
;
3767 const uint64_t *wait_values
;
3768 uint32_t wait_value_count
;
3769 const uint64_t *signal_values
;
3770 uint32_t signal_value_count
;
3774 radv_create_deferred_submission(struct radv_queue
*queue
,
3775 const struct radv_queue_submission
*submission
,
3776 struct radv_deferred_queue_submission
**out
)
3778 struct radv_deferred_queue_submission
*deferred
= NULL
;
3779 size_t size
= sizeof(struct radv_deferred_queue_submission
);
3781 uint32_t temporary_count
= 0;
3782 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
3783 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
3784 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
)
3788 size
+= submission
->cmd_buffer_count
* sizeof(VkCommandBuffer
);
3789 size
+= submission
->buffer_bind_count
* sizeof(VkSparseBufferMemoryBindInfo
);
3790 size
+= submission
->image_opaque_bind_count
* sizeof(VkSparseImageOpaqueMemoryBindInfo
);
3791 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_semaphore_part
*);
3792 size
+= temporary_count
* sizeof(struct radv_semaphore_part
);
3793 size
+= submission
->signal_semaphore_count
* sizeof(struct radv_semaphore_part
*);
3794 size
+= submission
->wait_value_count
* sizeof(uint64_t);
3795 size
+= submission
->signal_value_count
* sizeof(uint64_t);
3796 size
+= submission
->wait_semaphore_count
* sizeof(struct radv_timeline_waiter
);
3798 deferred
= calloc(1, size
);
3800 return VK_ERROR_OUT_OF_HOST_MEMORY
;
3802 deferred
->queue
= queue
;
3804 deferred
->cmd_buffers
= (void*)(deferred
+ 1);
3805 deferred
->cmd_buffer_count
= submission
->cmd_buffer_count
;
3806 memcpy(deferred
->cmd_buffers
, submission
->cmd_buffers
,
3807 submission
->cmd_buffer_count
* sizeof(*deferred
->cmd_buffers
));
3809 deferred
->buffer_binds
= (void*)(deferred
->cmd_buffers
+ submission
->cmd_buffer_count
);
3810 deferred
->buffer_bind_count
= submission
->buffer_bind_count
;
3811 memcpy(deferred
->buffer_binds
, submission
->buffer_binds
,
3812 submission
->buffer_bind_count
* sizeof(*deferred
->buffer_binds
));
3814 deferred
->image_opaque_binds
= (void*)(deferred
->buffer_binds
+ submission
->buffer_bind_count
);
3815 deferred
->image_opaque_bind_count
= submission
->image_opaque_bind_count
;
3816 memcpy(deferred
->image_opaque_binds
, submission
->image_opaque_binds
,
3817 submission
->image_opaque_bind_count
* sizeof(*deferred
->image_opaque_binds
));
3819 deferred
->flush_caches
= submission
->flush_caches
;
3820 deferred
->wait_dst_stage_mask
= submission
->wait_dst_stage_mask
;
3822 deferred
->wait_semaphores
= (void*)(deferred
->image_opaque_binds
+ deferred
->image_opaque_bind_count
);
3823 deferred
->wait_semaphore_count
= submission
->wait_semaphore_count
;
3825 deferred
->signal_semaphores
= (void*)(deferred
->wait_semaphores
+ deferred
->wait_semaphore_count
);
3826 deferred
->signal_semaphore_count
= submission
->signal_semaphore_count
;
3828 deferred
->fence
= submission
->fence
;
3830 deferred
->temporary_semaphore_parts
= (void*)(deferred
->signal_semaphores
+ deferred
->signal_semaphore_count
);
3831 deferred
->temporary_semaphore_part_count
= temporary_count
;
3833 uint32_t temporary_idx
= 0;
3834 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
3835 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->wait_semaphores
[i
]);
3836 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
3837 deferred
->wait_semaphores
[i
] = &deferred
->temporary_semaphore_parts
[temporary_idx
];
3838 deferred
->temporary_semaphore_parts
[temporary_idx
] = semaphore
->temporary
;
3839 semaphore
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
3842 deferred
->wait_semaphores
[i
] = &semaphore
->permanent
;
3845 for (uint32_t i
= 0; i
< submission
->signal_semaphore_count
; ++i
) {
3846 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, submission
->signal_semaphores
[i
]);
3847 if (semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
3848 deferred
->signal_semaphores
[i
] = &semaphore
->temporary
;
3850 deferred
->signal_semaphores
[i
] = &semaphore
->permanent
;
3854 deferred
->wait_values
= (void*)(deferred
->temporary_semaphore_parts
+ temporary_count
);
3855 memcpy(deferred
->wait_values
, submission
->wait_values
, submission
->wait_value_count
* sizeof(uint64_t));
3856 deferred
->signal_values
= deferred
->wait_values
+ submission
->wait_value_count
;
3857 memcpy(deferred
->signal_values
, submission
->signal_values
, submission
->signal_value_count
* sizeof(uint64_t));
3859 deferred
->wait_nodes
= (void*)(deferred
->signal_values
+ submission
->signal_value_count
);
3860 /* This is worst-case. radv_queue_enqueue_submission will fill in further, but this
3861 * ensure the submission is not accidentally triggered early when adding wait timelines. */
3862 deferred
->submission_wait_count
= 1 + submission
->wait_semaphore_count
;
3869 radv_queue_enqueue_submission(struct radv_deferred_queue_submission
*submission
,
3870 struct list_head
*processing_list
)
3872 uint32_t wait_cnt
= 0;
3873 struct radv_timeline_waiter
*waiter
= submission
->wait_nodes
;
3874 for (uint32_t i
= 0; i
< submission
->wait_semaphore_count
; ++i
) {
3875 if (submission
->wait_semaphores
[i
]->kind
== RADV_SEMAPHORE_TIMELINE
) {
3876 pthread_mutex_lock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
3877 if (submission
->wait_semaphores
[i
]->timeline
.highest_submitted
< submission
->wait_values
[i
]) {
3879 waiter
->value
= submission
->wait_values
[i
];
3880 waiter
->submission
= submission
;
3881 list_addtail(&waiter
->list
, &submission
->wait_semaphores
[i
]->timeline
.waiters
);
3884 pthread_mutex_unlock(&submission
->wait_semaphores
[i
]->timeline
.mutex
);
3888 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
3890 bool is_first
= list_is_empty(&submission
->queue
->pending_submissions
);
3891 list_addtail(&submission
->queue_pending_list
, &submission
->queue
->pending_submissions
);
3893 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
3895 /* If there is already a submission in the queue, that will decrement the counter by 1 when
3896 * submitted, but if the queue was empty, we decrement ourselves as there is no previous
3898 uint32_t decrement
= submission
->wait_semaphore_count
- wait_cnt
+ (is_first
? 1 : 0);
3899 if (__atomic_sub_fetch(&submission
->submission_wait_count
, decrement
, __ATOMIC_ACQ_REL
) == 0) {
3900 list_addtail(&submission
->processing_list
, processing_list
);
3905 radv_queue_submission_update_queue(struct radv_deferred_queue_submission
*submission
,
3906 struct list_head
*processing_list
)
3908 pthread_mutex_lock(&submission
->queue
->pending_mutex
);
3909 list_del(&submission
->queue_pending_list
);
3911 /* trigger the next submission in the queue. */
3912 if (!list_is_empty(&submission
->queue
->pending_submissions
)) {
3913 struct radv_deferred_queue_submission
*next_submission
=
3914 list_first_entry(&submission
->queue
->pending_submissions
,
3915 struct radv_deferred_queue_submission
,
3916 queue_pending_list
);
3917 if (p_atomic_dec_zero(&next_submission
->submission_wait_count
)) {
3918 list_addtail(&next_submission
->processing_list
, processing_list
);
3921 pthread_mutex_unlock(&submission
->queue
->pending_mutex
);
3923 pthread_cond_broadcast(&submission
->queue
->device
->timeline_cond
);
3927 radv_queue_submit_deferred(struct radv_deferred_queue_submission
*submission
,
3928 struct list_head
*processing_list
)
3930 RADV_FROM_HANDLE(radv_fence
, fence
, submission
->fence
);
3931 struct radv_queue
*queue
= submission
->queue
;
3932 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
3933 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
3934 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3935 bool do_flush
= submission
->flush_caches
|| submission
->wait_dst_stage_mask
;
3936 bool can_patch
= true;
3938 struct radv_winsys_sem_info sem_info
;
3941 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
;
3942 struct radeon_cmdbuf
*initial_flush_preamble_cs
= NULL
;
3943 struct radeon_cmdbuf
*continue_preamble_cs
= NULL
;
3945 result
= radv_get_preambles(queue
, submission
->cmd_buffers
,
3946 submission
->cmd_buffer_count
,
3947 &initial_preamble_cs
,
3948 &initial_flush_preamble_cs
,
3949 &continue_preamble_cs
);
3950 if (result
!= VK_SUCCESS
)
3953 result
= radv_alloc_sem_info(queue
->device
,
3955 submission
->wait_semaphore_count
,
3956 submission
->wait_semaphores
,
3957 submission
->wait_values
,
3958 submission
->signal_semaphore_count
,
3959 submission
->signal_semaphores
,
3960 submission
->signal_values
,
3962 if (result
!= VK_SUCCESS
)
3965 for (uint32_t i
= 0; i
< submission
->buffer_bind_count
; ++i
) {
3966 radv_sparse_buffer_bind_memory(queue
->device
,
3967 submission
->buffer_binds
+ i
);
3970 for (uint32_t i
= 0; i
< submission
->image_opaque_bind_count
; ++i
) {
3971 radv_sparse_image_opaque_bind_memory(queue
->device
,
3972 submission
->image_opaque_binds
+ i
);
3975 if (!submission
->cmd_buffer_count
) {
3976 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3977 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3982 radv_loge("failed to submit CS\n");
3988 struct radeon_cmdbuf
**cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3989 (submission
->cmd_buffer_count
));
3991 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
++) {
3992 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
, submission
->cmd_buffers
[j
]);
3993 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3995 cs_array
[j
] = cmd_buffer
->cs
;
3996 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3999 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
4002 for (uint32_t j
= 0; j
< submission
->cmd_buffer_count
; j
+= advance
) {
4003 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
4004 const struct radv_winsys_bo_list
*bo_list
= NULL
;
4006 advance
= MIN2(max_cs_submission
,
4007 submission
->cmd_buffer_count
- j
);
4009 if (queue
->device
->trace_bo
)
4010 *queue
->device
->trace_id_ptr
= 0;
4012 sem_info
.cs_emit_wait
= j
== 0;
4013 sem_info
.cs_emit_signal
= j
+ advance
== submission
->cmd_buffer_count
;
4015 if (unlikely(queue
->device
->use_global_bo_list
)) {
4016 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
4017 bo_list
= &queue
->device
->bo_list
.list
;
4020 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
4021 advance
, initial_preamble
, continue_preamble_cs
,
4023 can_patch
, base_fence
);
4025 if (unlikely(queue
->device
->use_global_bo_list
))
4026 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
4029 radv_loge("failed to submit CS\n");
4032 if (queue
->device
->trace_bo
) {
4033 radv_check_gpu_hangs(queue
, cs_array
[j
]);
4041 radv_free_temp_syncobjs(queue
->device
,
4042 submission
->temporary_semaphore_part_count
,
4043 submission
->temporary_semaphore_parts
);
4044 radv_finalize_timelines(queue
->device
,
4045 submission
->wait_semaphore_count
,
4046 submission
->wait_semaphores
,
4047 submission
->wait_values
,
4048 submission
->signal_semaphore_count
,
4049 submission
->signal_semaphores
,
4050 submission
->signal_values
,
4052 /* Has to happen after timeline finalization to make sure the
4053 * condition variable is only triggered when timelines and queue have
4055 radv_queue_submission_update_queue(submission
, processing_list
);
4056 radv_free_sem_info(&sem_info
);
4061 radv_free_temp_syncobjs(queue
->device
,
4062 submission
->temporary_semaphore_part_count
,
4063 submission
->temporary_semaphore_parts
);
4065 return VK_ERROR_DEVICE_LOST
;
4069 radv_process_submissions(struct list_head
*processing_list
)
4071 while(!list_is_empty(processing_list
)) {
4072 struct radv_deferred_queue_submission
*submission
=
4073 list_first_entry(processing_list
, struct radv_deferred_queue_submission
, processing_list
);
4074 list_del(&submission
->processing_list
);
4076 VkResult result
= radv_queue_submit_deferred(submission
, processing_list
);
4077 if (result
!= VK_SUCCESS
)
4083 static VkResult
radv_queue_submit(struct radv_queue
*queue
,
4084 const struct radv_queue_submission
*submission
)
4086 struct radv_deferred_queue_submission
*deferred
= NULL
;
4088 VkResult result
= radv_create_deferred_submission(queue
, submission
, &deferred
);
4089 if (result
!= VK_SUCCESS
)
4092 struct list_head processing_list
;
4093 list_inithead(&processing_list
);
4095 radv_queue_enqueue_submission(deferred
, &processing_list
);
4096 return radv_process_submissions(&processing_list
);
4099 /* Signals fence as soon as all the work currently put on queue is done. */
4100 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
4103 return radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4108 static bool radv_submit_has_effects(const VkSubmitInfo
*info
)
4110 return info
->commandBufferCount
||
4111 info
->waitSemaphoreCount
||
4112 info
->signalSemaphoreCount
;
4115 VkResult
radv_QueueSubmit(
4117 uint32_t submitCount
,
4118 const VkSubmitInfo
* pSubmits
,
4121 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4123 uint32_t fence_idx
= 0;
4124 bool flushed_caches
= false;
4126 if (fence
!= VK_NULL_HANDLE
) {
4127 for (uint32_t i
= 0; i
< submitCount
; ++i
)
4128 if (radv_submit_has_effects(pSubmits
+ i
))
4131 fence_idx
= UINT32_MAX
;
4133 for (uint32_t i
= 0; i
< submitCount
; i
++) {
4134 if (!radv_submit_has_effects(pSubmits
+ i
) && fence_idx
!= i
)
4137 VkPipelineStageFlags wait_dst_stage_mask
= 0;
4138 for (unsigned j
= 0; j
< pSubmits
[i
].waitSemaphoreCount
; ++j
) {
4139 wait_dst_stage_mask
|= pSubmits
[i
].pWaitDstStageMask
[j
];
4142 const VkTimelineSemaphoreSubmitInfoKHR
*timeline_info
=
4143 vk_find_struct_const(pSubmits
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR
);
4145 result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4146 .cmd_buffers
= pSubmits
[i
].pCommandBuffers
,
4147 .cmd_buffer_count
= pSubmits
[i
].commandBufferCount
,
4148 .wait_dst_stage_mask
= wait_dst_stage_mask
,
4149 .flush_caches
= !flushed_caches
,
4150 .wait_semaphores
= pSubmits
[i
].pWaitSemaphores
,
4151 .wait_semaphore_count
= pSubmits
[i
].waitSemaphoreCount
,
4152 .signal_semaphores
= pSubmits
[i
].pSignalSemaphores
,
4153 .signal_semaphore_count
= pSubmits
[i
].signalSemaphoreCount
,
4154 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
4155 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
4156 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
4157 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
4158 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
4160 if (result
!= VK_SUCCESS
)
4163 flushed_caches
= true;
4166 if (fence
!= VK_NULL_HANDLE
&& !submitCount
) {
4167 result
= radv_signal_fence(queue
, fence
);
4168 if (result
!= VK_SUCCESS
)
4175 VkResult
radv_QueueWaitIdle(
4178 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4180 pthread_mutex_lock(&queue
->pending_mutex
);
4181 while (!list_is_empty(&queue
->pending_submissions
)) {
4182 pthread_cond_wait(&queue
->device
->timeline_cond
, &queue
->pending_mutex
);
4184 pthread_mutex_unlock(&queue
->pending_mutex
);
4186 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
4187 radv_queue_family_to_ring(queue
->queue_family_index
),
4192 VkResult
radv_DeviceWaitIdle(
4195 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4197 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
4198 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
4199 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
4205 VkResult
radv_EnumerateInstanceExtensionProperties(
4206 const char* pLayerName
,
4207 uint32_t* pPropertyCount
,
4208 VkExtensionProperties
* pProperties
)
4210 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
4212 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
4213 if (radv_supported_instance_extensions
.extensions
[i
]) {
4214 vk_outarray_append(&out
, prop
) {
4215 *prop
= radv_instance_extensions
[i
];
4220 return vk_outarray_status(&out
);
4223 VkResult
radv_EnumerateDeviceExtensionProperties(
4224 VkPhysicalDevice physicalDevice
,
4225 const char* pLayerName
,
4226 uint32_t* pPropertyCount
,
4227 VkExtensionProperties
* pProperties
)
4229 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
4230 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
4232 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
4233 if (device
->supported_extensions
.extensions
[i
]) {
4234 vk_outarray_append(&out
, prop
) {
4235 *prop
= radv_device_extensions
[i
];
4240 return vk_outarray_status(&out
);
4243 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
4244 VkInstance _instance
,
4247 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4248 bool unchecked
= instance
? instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
4251 return radv_lookup_entrypoint_unchecked(pName
);
4253 return radv_lookup_entrypoint_checked(pName
,
4254 instance
? instance
->apiVersion
: 0,
4255 instance
? &instance
->enabled_extensions
: NULL
,
4260 /* The loader wants us to expose a second GetInstanceProcAddr function
4261 * to work around certain LD_PRELOAD issues seen in apps.
4264 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
4265 VkInstance instance
,
4269 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
4270 VkInstance instance
,
4273 return radv_GetInstanceProcAddr(instance
, pName
);
4277 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
4278 VkInstance _instance
,
4282 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
4283 VkInstance _instance
,
4286 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4288 return radv_lookup_physical_device_entrypoint_checked(pName
,
4289 instance
? instance
->apiVersion
: 0,
4290 instance
? &instance
->enabled_extensions
: NULL
);
4293 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
4297 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4298 bool unchecked
= device
? device
->instance
->debug_flags
& RADV_DEBUG_ALL_ENTRYPOINTS
: false;
4301 return radv_lookup_entrypoint_unchecked(pName
);
4303 return radv_lookup_entrypoint_checked(pName
,
4304 device
->instance
->apiVersion
,
4305 &device
->instance
->enabled_extensions
,
4306 &device
->enabled_extensions
);
4310 bool radv_get_memory_fd(struct radv_device
*device
,
4311 struct radv_device_memory
*memory
,
4314 struct radeon_bo_metadata metadata
;
4316 if (memory
->image
) {
4317 radv_init_metadata(device
, memory
->image
, &metadata
);
4318 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
4321 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
4326 static void radv_free_memory(struct radv_device
*device
,
4327 const VkAllocationCallbacks
* pAllocator
,
4328 struct radv_device_memory
*mem
)
4333 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
4334 if (mem
->android_hardware_buffer
)
4335 AHardwareBuffer_release(mem
->android_hardware_buffer
);
4339 radv_bo_list_remove(device
, mem
->bo
);
4340 device
->ws
->buffer_destroy(mem
->bo
);
4344 vk_free2(&device
->alloc
, pAllocator
, mem
);
4347 static VkResult
radv_alloc_memory(struct radv_device
*device
,
4348 const VkMemoryAllocateInfo
* pAllocateInfo
,
4349 const VkAllocationCallbacks
* pAllocator
,
4350 VkDeviceMemory
* pMem
)
4352 struct radv_device_memory
*mem
;
4354 enum radeon_bo_domain domain
;
4356 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
4358 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
4360 const VkImportMemoryFdInfoKHR
*import_info
=
4361 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
4362 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
4363 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
4364 const VkExportMemoryAllocateInfo
*export_info
=
4365 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
4366 const struct VkImportAndroidHardwareBufferInfoANDROID
*ahb_import_info
=
4367 vk_find_struct_const(pAllocateInfo
->pNext
,
4368 IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID
);
4369 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
4370 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
4372 const struct wsi_memory_allocate_info
*wsi_info
=
4373 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
4375 if (pAllocateInfo
->allocationSize
== 0 && !ahb_import_info
&&
4376 !(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
))) {
4377 /* Apparently, this is allowed */
4378 *pMem
= VK_NULL_HANDLE
;
4382 mem
= vk_zalloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
4383 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4385 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4387 if (wsi_info
&& wsi_info
->implicit_sync
)
4388 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
4390 if (dedicate_info
) {
4391 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
4392 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
4398 float priority_float
= 0.5;
4399 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
4400 vk_find_struct_const(pAllocateInfo
->pNext
,
4401 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
4403 priority_float
= priority_ext
->priority
;
4405 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
4406 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
4408 mem
->user_ptr
= NULL
;
4411 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
4412 mem
->android_hardware_buffer
= NULL
;
4415 if (ahb_import_info
) {
4416 result
= radv_import_ahb_memory(device
, mem
, priority
, ahb_import_info
);
4417 if (result
!= VK_SUCCESS
)
4419 } else if(export_info
&& (export_info
->handleTypes
& VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
)) {
4420 result
= radv_create_ahb_memory(device
, mem
, priority
, pAllocateInfo
);
4421 if (result
!= VK_SUCCESS
)
4423 } else if (import_info
) {
4424 assert(import_info
->handleType
==
4425 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
4426 import_info
->handleType
==
4427 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4428 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
4431 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
4434 close(import_info
->fd
);
4436 } else if (host_ptr_info
) {
4437 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
4438 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
4439 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
4440 pAllocateInfo
->allocationSize
,
4443 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
4446 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
4449 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
4450 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
4451 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
4452 domain
= RADEON_DOMAIN_GTT
;
4454 domain
= RADEON_DOMAIN_VRAM
;
4456 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
4457 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
4459 flags
|= RADEON_FLAG_CPU_ACCESS
;
4461 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
4462 flags
|= RADEON_FLAG_GTT_WC
;
4464 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
4465 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
4466 if (device
->use_global_bo_list
) {
4467 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
4471 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
4472 domain
, flags
, priority
);
4475 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
4478 mem
->type_index
= mem_type_index
;
4481 result
= radv_bo_list_add(device
, mem
->bo
);
4482 if (result
!= VK_SUCCESS
)
4485 *pMem
= radv_device_memory_to_handle(mem
);
4490 radv_free_memory(device
, pAllocator
,mem
);
4491 vk_free2(&device
->alloc
, pAllocator
, mem
);
4496 VkResult
radv_AllocateMemory(
4498 const VkMemoryAllocateInfo
* pAllocateInfo
,
4499 const VkAllocationCallbacks
* pAllocator
,
4500 VkDeviceMemory
* pMem
)
4502 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4503 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
4506 void radv_FreeMemory(
4508 VkDeviceMemory _mem
,
4509 const VkAllocationCallbacks
* pAllocator
)
4511 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4512 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
4514 radv_free_memory(device
, pAllocator
, mem
);
4517 VkResult
radv_MapMemory(
4519 VkDeviceMemory _memory
,
4520 VkDeviceSize offset
,
4522 VkMemoryMapFlags flags
,
4525 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4526 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
4534 *ppData
= mem
->user_ptr
;
4536 *ppData
= device
->ws
->buffer_map(mem
->bo
);
4543 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
4546 void radv_UnmapMemory(
4548 VkDeviceMemory _memory
)
4550 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4551 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
4556 if (mem
->user_ptr
== NULL
)
4557 device
->ws
->buffer_unmap(mem
->bo
);
4560 VkResult
radv_FlushMappedMemoryRanges(
4562 uint32_t memoryRangeCount
,
4563 const VkMappedMemoryRange
* pMemoryRanges
)
4568 VkResult
radv_InvalidateMappedMemoryRanges(
4570 uint32_t memoryRangeCount
,
4571 const VkMappedMemoryRange
* pMemoryRanges
)
4576 void radv_GetBufferMemoryRequirements(
4579 VkMemoryRequirements
* pMemoryRequirements
)
4581 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4582 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4584 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
4586 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4587 pMemoryRequirements
->alignment
= 4096;
4589 pMemoryRequirements
->alignment
= 16;
4591 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
4594 void radv_GetBufferMemoryRequirements2(
4596 const VkBufferMemoryRequirementsInfo2
*pInfo
,
4597 VkMemoryRequirements2
*pMemoryRequirements
)
4599 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
4600 &pMemoryRequirements
->memoryRequirements
);
4601 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4602 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
4603 switch (ext
->sType
) {
4604 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
4605 VkMemoryDedicatedRequirements
*req
=
4606 (VkMemoryDedicatedRequirements
*) ext
;
4607 req
->requiresDedicatedAllocation
= buffer
->shareable
;
4608 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
4617 void radv_GetImageMemoryRequirements(
4620 VkMemoryRequirements
* pMemoryRequirements
)
4622 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4623 RADV_FROM_HANDLE(radv_image
, image
, _image
);
4625 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
4627 pMemoryRequirements
->size
= image
->size
;
4628 pMemoryRequirements
->alignment
= image
->alignment
;
4631 void radv_GetImageMemoryRequirements2(
4633 const VkImageMemoryRequirementsInfo2
*pInfo
,
4634 VkMemoryRequirements2
*pMemoryRequirements
)
4636 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
4637 &pMemoryRequirements
->memoryRequirements
);
4639 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
4641 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
4642 switch (ext
->sType
) {
4643 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
4644 VkMemoryDedicatedRequirements
*req
=
4645 (VkMemoryDedicatedRequirements
*) ext
;
4646 req
->requiresDedicatedAllocation
= image
->shareable
;
4647 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
4656 void radv_GetImageSparseMemoryRequirements(
4659 uint32_t* pSparseMemoryRequirementCount
,
4660 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
4665 void radv_GetImageSparseMemoryRequirements2(
4667 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
4668 uint32_t* pSparseMemoryRequirementCount
,
4669 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
4674 void radv_GetDeviceMemoryCommitment(
4676 VkDeviceMemory memory
,
4677 VkDeviceSize
* pCommittedMemoryInBytes
)
4679 *pCommittedMemoryInBytes
= 0;
4682 VkResult
radv_BindBufferMemory2(VkDevice device
,
4683 uint32_t bindInfoCount
,
4684 const VkBindBufferMemoryInfo
*pBindInfos
)
4686 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
4687 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
4688 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
4691 buffer
->bo
= mem
->bo
;
4692 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
4700 VkResult
radv_BindBufferMemory(
4703 VkDeviceMemory memory
,
4704 VkDeviceSize memoryOffset
)
4706 const VkBindBufferMemoryInfo info
= {
4707 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
4710 .memoryOffset
= memoryOffset
4713 return radv_BindBufferMemory2(device
, 1, &info
);
4716 VkResult
radv_BindImageMemory2(VkDevice device
,
4717 uint32_t bindInfoCount
,
4718 const VkBindImageMemoryInfo
*pBindInfos
)
4720 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
4721 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
4722 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
4725 image
->bo
= mem
->bo
;
4726 image
->offset
= pBindInfos
[i
].memoryOffset
;
4736 VkResult
radv_BindImageMemory(
4739 VkDeviceMemory memory
,
4740 VkDeviceSize memoryOffset
)
4742 const VkBindImageMemoryInfo info
= {
4743 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
4746 .memoryOffset
= memoryOffset
4749 return radv_BindImageMemory2(device
, 1, &info
);
4752 static bool radv_sparse_bind_has_effects(const VkBindSparseInfo
*info
)
4754 return info
->bufferBindCount
||
4755 info
->imageOpaqueBindCount
||
4756 info
->imageBindCount
||
4757 info
->waitSemaphoreCount
||
4758 info
->signalSemaphoreCount
;
4761 VkResult
radv_QueueBindSparse(
4763 uint32_t bindInfoCount
,
4764 const VkBindSparseInfo
* pBindInfo
,
4767 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
4769 uint32_t fence_idx
= 0;
4771 if (fence
!= VK_NULL_HANDLE
) {
4772 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
)
4773 if (radv_sparse_bind_has_effects(pBindInfo
+ i
))
4776 fence_idx
= UINT32_MAX
;
4778 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
4779 if (i
!= fence_idx
&& !radv_sparse_bind_has_effects(pBindInfo
+ i
))
4782 const VkTimelineSemaphoreSubmitInfoKHR
*timeline_info
=
4783 vk_find_struct_const(pBindInfo
[i
].pNext
, TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR
);
4785 VkResult result
= radv_queue_submit(queue
, &(struct radv_queue_submission
) {
4786 .buffer_binds
= pBindInfo
[i
].pBufferBinds
,
4787 .buffer_bind_count
= pBindInfo
[i
].bufferBindCount
,
4788 .image_opaque_binds
= pBindInfo
[i
].pImageOpaqueBinds
,
4789 .image_opaque_bind_count
= pBindInfo
[i
].imageOpaqueBindCount
,
4790 .wait_semaphores
= pBindInfo
[i
].pWaitSemaphores
,
4791 .wait_semaphore_count
= pBindInfo
[i
].waitSemaphoreCount
,
4792 .signal_semaphores
= pBindInfo
[i
].pSignalSemaphores
,
4793 .signal_semaphore_count
= pBindInfo
[i
].signalSemaphoreCount
,
4794 .fence
= i
== fence_idx
? fence
: VK_NULL_HANDLE
,
4795 .wait_values
= timeline_info
? timeline_info
->pWaitSemaphoreValues
: NULL
,
4796 .wait_value_count
= timeline_info
&& timeline_info
->pWaitSemaphoreValues
? timeline_info
->waitSemaphoreValueCount
: 0,
4797 .signal_values
= timeline_info
? timeline_info
->pSignalSemaphoreValues
: NULL
,
4798 .signal_value_count
= timeline_info
&& timeline_info
->pSignalSemaphoreValues
? timeline_info
->signalSemaphoreValueCount
: 0,
4801 if (result
!= VK_SUCCESS
)
4805 if (fence
!= VK_NULL_HANDLE
&& !bindInfoCount
) {
4806 result
= radv_signal_fence(queue
, fence
);
4807 if (result
!= VK_SUCCESS
)
4814 VkResult
radv_CreateFence(
4816 const VkFenceCreateInfo
* pCreateInfo
,
4817 const VkAllocationCallbacks
* pAllocator
,
4820 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4821 const VkExportFenceCreateInfo
*export
=
4822 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
4823 VkExternalFenceHandleTypeFlags handleTypes
=
4824 export
? export
->handleTypes
: 0;
4826 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
4828 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4831 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4833 fence
->fence_wsi
= NULL
;
4834 fence
->temp_syncobj
= 0;
4835 if (device
->always_use_syncobj
|| handleTypes
) {
4836 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
4838 vk_free2(&device
->alloc
, pAllocator
, fence
);
4839 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4841 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
4842 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
4844 fence
->fence
= NULL
;
4846 fence
->fence
= device
->ws
->create_fence();
4847 if (!fence
->fence
) {
4848 vk_free2(&device
->alloc
, pAllocator
, fence
);
4849 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4852 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
4853 device
->ws
->signal_fence(fence
->fence
);
4856 *pFence
= radv_fence_to_handle(fence
);
4861 void radv_DestroyFence(
4864 const VkAllocationCallbacks
* pAllocator
)
4866 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4867 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
4872 if (fence
->temp_syncobj
)
4873 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
4875 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
4877 device
->ws
->destroy_fence(fence
->fence
);
4878 if (fence
->fence_wsi
)
4879 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
4880 vk_free2(&device
->alloc
, pAllocator
, fence
);
4884 uint64_t radv_get_current_time(void)
4887 clock_gettime(CLOCK_MONOTONIC
, &tv
);
4888 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
4891 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
4893 uint64_t current_time
= radv_get_current_time();
4895 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
4897 return current_time
+ timeout
;
4901 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
4902 uint32_t fenceCount
, const VkFence
*pFences
)
4904 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4905 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4906 if (fence
->fence
== NULL
|| fence
->syncobj
||
4907 fence
->temp_syncobj
|| fence
->fence_wsi
||
4908 (!device
->ws
->is_fence_waitable(fence
->fence
)))
4914 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
4916 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4917 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4918 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
4924 VkResult
radv_WaitForFences(
4926 uint32_t fenceCount
,
4927 const VkFence
* pFences
,
4931 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4932 timeout
= radv_get_absolute_timeout(timeout
);
4934 if (device
->always_use_syncobj
&&
4935 radv_all_fences_syncobj(fenceCount
, pFences
))
4937 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
4939 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4941 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4942 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4943 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
4946 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
4949 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4952 if (!waitAll
&& fenceCount
> 1) {
4953 /* Not doing this by default for waitAll, due to needing to allocate twice. */
4954 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
4955 uint32_t wait_count
= 0;
4956 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
4958 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4960 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4961 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4963 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
4968 fences
[wait_count
++] = fence
->fence
;
4971 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
4972 waitAll
, timeout
- radv_get_current_time());
4975 return success
? VK_SUCCESS
: VK_TIMEOUT
;
4978 while(radv_get_current_time() <= timeout
) {
4979 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4980 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
4987 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
4988 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
4989 bool expired
= false;
4991 if (fence
->temp_syncobj
) {
4992 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
4997 if (fence
->syncobj
) {
4998 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
5004 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
5005 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
5006 radv_get_current_time() <= timeout
)
5010 expired
= device
->ws
->fence_wait(device
->ws
,
5017 if (fence
->fence_wsi
) {
5018 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
5019 if (result
!= VK_SUCCESS
)
5027 VkResult
radv_ResetFences(VkDevice _device
,
5028 uint32_t fenceCount
,
5029 const VkFence
*pFences
)
5031 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5033 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
5034 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
5036 device
->ws
->reset_fence(fence
->fence
);
5038 /* Per spec, we first restore the permanent payload, and then reset, so
5039 * having a temp syncobj should not skip resetting the permanent syncobj. */
5040 if (fence
->temp_syncobj
) {
5041 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
5042 fence
->temp_syncobj
= 0;
5045 if (fence
->syncobj
) {
5046 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
5053 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
5055 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5056 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
5058 if (fence
->temp_syncobj
) {
5059 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
5060 return success
? VK_SUCCESS
: VK_NOT_READY
;
5063 if (fence
->syncobj
) {
5064 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
5065 return success
? VK_SUCCESS
: VK_NOT_READY
;
5069 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
5070 return VK_NOT_READY
;
5072 if (fence
->fence_wsi
) {
5073 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
5075 if (result
!= VK_SUCCESS
) {
5076 if (result
== VK_TIMEOUT
)
5077 return VK_NOT_READY
;
5085 // Queue semaphore functions
5088 radv_create_timeline(struct radv_timeline
*timeline
, uint64_t value
)
5090 timeline
->highest_signaled
= value
;
5091 timeline
->highest_submitted
= value
;
5092 list_inithead(&timeline
->points
);
5093 list_inithead(&timeline
->free_points
);
5094 list_inithead(&timeline
->waiters
);
5095 pthread_mutex_init(&timeline
->mutex
, NULL
);
5099 radv_destroy_timeline(struct radv_device
*device
,
5100 struct radv_timeline
*timeline
)
5102 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5103 &timeline
->free_points
, list
) {
5104 list_del(&point
->list
);
5105 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
5108 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5109 &timeline
->points
, list
) {
5110 list_del(&point
->list
);
5111 device
->ws
->destroy_syncobj(device
->ws
, point
->syncobj
);
5114 pthread_mutex_destroy(&timeline
->mutex
);
5118 radv_timeline_gc_locked(struct radv_device
*device
,
5119 struct radv_timeline
*timeline
)
5121 list_for_each_entry_safe(struct radv_timeline_point
, point
,
5122 &timeline
->points
, list
) {
5123 if (point
->wait_count
|| point
->value
> timeline
->highest_submitted
)
5126 if (device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, 0)) {
5127 timeline
->highest_signaled
= point
->value
;
5128 list_del(&point
->list
);
5129 list_add(&point
->list
, &timeline
->free_points
);
5134 static struct radv_timeline_point
*
5135 radv_timeline_find_point_at_least_locked(struct radv_device
*device
,
5136 struct radv_timeline
*timeline
,
5139 radv_timeline_gc_locked(device
, timeline
);
5141 if (p
<= timeline
->highest_signaled
)
5144 list_for_each_entry(struct radv_timeline_point
, point
,
5145 &timeline
->points
, list
) {
5146 if (point
->value
>= p
) {
5147 ++point
->wait_count
;
5154 static struct radv_timeline_point
*
5155 radv_timeline_add_point_locked(struct radv_device
*device
,
5156 struct radv_timeline
*timeline
,
5159 radv_timeline_gc_locked(device
, timeline
);
5161 struct radv_timeline_point
*ret
= NULL
;
5162 struct radv_timeline_point
*prev
= NULL
;
5164 if (p
<= timeline
->highest_signaled
)
5167 list_for_each_entry(struct radv_timeline_point
, point
,
5168 &timeline
->points
, list
) {
5169 if (point
->value
== p
) {
5173 if (point
->value
< p
)
5177 if (list_is_empty(&timeline
->free_points
)) {
5178 ret
= malloc(sizeof(struct radv_timeline_point
));
5179 device
->ws
->create_syncobj(device
->ws
, &ret
->syncobj
);
5181 ret
= list_first_entry(&timeline
->free_points
, struct radv_timeline_point
, list
);
5182 list_del(&ret
->list
);
5184 device
->ws
->reset_syncobj(device
->ws
, ret
->syncobj
);
5188 ret
->wait_count
= 1;
5191 list_add(&ret
->list
, &prev
->list
);
5193 list_addtail(&ret
->list
, &timeline
->points
);
5200 radv_timeline_wait_locked(struct radv_device
*device
,
5201 struct radv_timeline
*timeline
,
5203 uint64_t abs_timeout
)
5205 while(timeline
->highest_submitted
< value
) {
5206 struct timespec abstime
;
5207 timespec_from_nsec(&abstime
, abs_timeout
);
5209 pthread_cond_timedwait(&device
->timeline_cond
, &timeline
->mutex
, &abstime
);
5211 if (radv_get_current_time() >= abs_timeout
&& timeline
->highest_submitted
< value
)
5215 struct radv_timeline_point
*point
= radv_timeline_find_point_at_least_locked(device
, timeline
, value
);
5219 point
->wait_count
++;
5221 pthread_mutex_unlock(&timeline
->mutex
);
5223 bool success
= device
->ws
->wait_syncobj(device
->ws
, &point
->syncobj
, 1, true, abs_timeout
);
5225 pthread_mutex_lock(&timeline
->mutex
);
5226 point
->wait_count
--;
5227 return success
? VK_SUCCESS
: VK_TIMEOUT
;
5231 radv_timeline_trigger_waiters_locked(struct radv_timeline
*timeline
,
5232 struct list_head
*processing_list
)
5234 list_for_each_entry_safe(struct radv_timeline_waiter
, waiter
,
5235 &timeline
->waiters
, list
) {
5236 if (waiter
->value
> timeline
->highest_submitted
)
5239 if (p_atomic_dec_zero(&waiter
->submission
->submission_wait_count
)) {
5240 list_addtail(&waiter
->submission
->processing_list
, processing_list
);
5242 list_del(&waiter
->list
);
5247 void radv_destroy_semaphore_part(struct radv_device
*device
,
5248 struct radv_semaphore_part
*part
)
5250 switch(part
->kind
) {
5251 case RADV_SEMAPHORE_NONE
:
5253 case RADV_SEMAPHORE_WINSYS
:
5254 device
->ws
->destroy_sem(part
->ws_sem
);
5256 case RADV_SEMAPHORE_TIMELINE
:
5257 radv_destroy_timeline(device
, &part
->timeline
);
5259 case RADV_SEMAPHORE_SYNCOBJ
:
5260 device
->ws
->destroy_syncobj(device
->ws
, part
->syncobj
);
5263 part
->kind
= RADV_SEMAPHORE_NONE
;
5266 static VkSemaphoreTypeKHR
5267 radv_get_semaphore_type(const void *pNext
, uint64_t *initial_value
)
5269 const VkSemaphoreTypeCreateInfoKHR
*type_info
=
5270 vk_find_struct_const(pNext
, SEMAPHORE_TYPE_CREATE_INFO_KHR
);
5273 return VK_SEMAPHORE_TYPE_BINARY_KHR
;
5276 *initial_value
= type_info
->initialValue
;
5277 return type_info
->semaphoreType
;
5280 VkResult
radv_CreateSemaphore(
5282 const VkSemaphoreCreateInfo
* pCreateInfo
,
5283 const VkAllocationCallbacks
* pAllocator
,
5284 VkSemaphore
* pSemaphore
)
5286 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5287 const VkExportSemaphoreCreateInfo
*export
=
5288 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
5289 VkExternalSemaphoreHandleTypeFlags handleTypes
=
5290 export
? export
->handleTypes
: 0;
5291 uint64_t initial_value
= 0;
5292 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pCreateInfo
->pNext
, &initial_value
);
5294 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
5296 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5298 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5300 sem
->temporary
.kind
= RADV_SEMAPHORE_NONE
;
5301 sem
->permanent
.kind
= RADV_SEMAPHORE_NONE
;
5303 if (type
== VK_SEMAPHORE_TYPE_TIMELINE_KHR
) {
5304 radv_create_timeline(&sem
->permanent
.timeline
, initial_value
);
5305 sem
->permanent
.kind
= RADV_SEMAPHORE_TIMELINE
;
5306 } else if (device
->always_use_syncobj
|| handleTypes
) {
5307 assert (device
->physical_device
->rad_info
.has_syncobj
);
5308 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->permanent
.syncobj
);
5310 vk_free2(&device
->alloc
, pAllocator
, sem
);
5311 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5313 sem
->permanent
.kind
= RADV_SEMAPHORE_SYNCOBJ
;
5315 sem
->permanent
.ws_sem
= device
->ws
->create_sem(device
->ws
);
5316 if (!sem
->permanent
.ws_sem
) {
5317 vk_free2(&device
->alloc
, pAllocator
, sem
);
5318 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5320 sem
->permanent
.kind
= RADV_SEMAPHORE_WINSYS
;
5323 *pSemaphore
= radv_semaphore_to_handle(sem
);
5327 void radv_DestroySemaphore(
5329 VkSemaphore _semaphore
,
5330 const VkAllocationCallbacks
* pAllocator
)
5332 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5333 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
5337 radv_destroy_semaphore_part(device
, &sem
->temporary
);
5338 radv_destroy_semaphore_part(device
, &sem
->permanent
);
5339 vk_free2(&device
->alloc
, pAllocator
, sem
);
5343 radv_GetSemaphoreCounterValueKHR(VkDevice _device
,
5344 VkSemaphore _semaphore
,
5347 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5348 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, _semaphore
);
5350 struct radv_semaphore_part
*part
=
5351 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
5353 switch (part
->kind
) {
5354 case RADV_SEMAPHORE_TIMELINE
: {
5355 pthread_mutex_lock(&part
->timeline
.mutex
);
5356 radv_timeline_gc_locked(device
, &part
->timeline
);
5357 *pValue
= part
->timeline
.highest_signaled
;
5358 pthread_mutex_unlock(&part
->timeline
.mutex
);
5361 case RADV_SEMAPHORE_NONE
:
5362 case RADV_SEMAPHORE_SYNCOBJ
:
5363 case RADV_SEMAPHORE_WINSYS
:
5364 unreachable("Invalid semaphore type");
5366 unreachable("Unhandled semaphore type");
5371 radv_wait_timelines(struct radv_device
*device
,
5372 const VkSemaphoreWaitInfoKHR
* pWaitInfo
,
5373 uint64_t abs_timeout
)
5375 if ((pWaitInfo
->flags
& VK_SEMAPHORE_WAIT_ANY_BIT_KHR
) && pWaitInfo
->semaphoreCount
> 1) {
5377 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
5378 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
5379 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
5380 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], 0);
5381 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
5383 if (result
== VK_SUCCESS
)
5386 if (radv_get_current_time() > abs_timeout
)
5391 for(uint32_t i
= 0; i
< pWaitInfo
->semaphoreCount
; ++i
) {
5392 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pWaitInfo
->pSemaphores
[i
]);
5393 pthread_mutex_lock(&semaphore
->permanent
.timeline
.mutex
);
5394 VkResult result
= radv_timeline_wait_locked(device
, &semaphore
->permanent
.timeline
, pWaitInfo
->pValues
[i
], abs_timeout
);
5395 pthread_mutex_unlock(&semaphore
->permanent
.timeline
.mutex
);
5397 if (result
!= VK_SUCCESS
)
5403 radv_WaitSemaphoresKHR(VkDevice _device
,
5404 const VkSemaphoreWaitInfoKHR
* pWaitInfo
,
5407 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5408 uint64_t abs_timeout
= radv_get_absolute_timeout(timeout
);
5409 return radv_wait_timelines(device
, pWaitInfo
, abs_timeout
);
5413 radv_SignalSemaphoreKHR(VkDevice _device
,
5414 const VkSemaphoreSignalInfoKHR
* pSignalInfo
)
5416 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5417 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pSignalInfo
->semaphore
);
5419 struct radv_semaphore_part
*part
=
5420 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
? &semaphore
->temporary
: &semaphore
->permanent
;
5422 switch(part
->kind
) {
5423 case RADV_SEMAPHORE_TIMELINE
: {
5424 pthread_mutex_lock(&part
->timeline
.mutex
);
5425 radv_timeline_gc_locked(device
, &part
->timeline
);
5426 part
->timeline
.highest_submitted
= MAX2(part
->timeline
.highest_submitted
, pSignalInfo
->value
);
5427 part
->timeline
.highest_signaled
= MAX2(part
->timeline
.highest_signaled
, pSignalInfo
->value
);
5429 struct list_head processing_list
;
5430 list_inithead(&processing_list
);
5431 radv_timeline_trigger_waiters_locked(&part
->timeline
, &processing_list
);
5432 pthread_mutex_unlock(&part
->timeline
.mutex
);
5434 return radv_process_submissions(&processing_list
);
5436 case RADV_SEMAPHORE_NONE
:
5437 case RADV_SEMAPHORE_SYNCOBJ
:
5438 case RADV_SEMAPHORE_WINSYS
:
5439 unreachable("Invalid semaphore type");
5446 VkResult
radv_CreateEvent(
5448 const VkEventCreateInfo
* pCreateInfo
,
5449 const VkAllocationCallbacks
* pAllocator
,
5452 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5453 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
5455 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5458 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5460 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
5462 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
5463 RADV_BO_PRIORITY_FENCE
);
5465 vk_free2(&device
->alloc
, pAllocator
, event
);
5466 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5469 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
5471 *pEvent
= radv_event_to_handle(event
);
5476 void radv_DestroyEvent(
5479 const VkAllocationCallbacks
* pAllocator
)
5481 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5482 RADV_FROM_HANDLE(radv_event
, event
, _event
);
5486 device
->ws
->buffer_destroy(event
->bo
);
5487 vk_free2(&device
->alloc
, pAllocator
, event
);
5490 VkResult
radv_GetEventStatus(
5494 RADV_FROM_HANDLE(radv_event
, event
, _event
);
5496 if (*event
->map
== 1)
5497 return VK_EVENT_SET
;
5498 return VK_EVENT_RESET
;
5501 VkResult
radv_SetEvent(
5505 RADV_FROM_HANDLE(radv_event
, event
, _event
);
5511 VkResult
radv_ResetEvent(
5515 RADV_FROM_HANDLE(radv_event
, event
, _event
);
5521 VkResult
radv_CreateBuffer(
5523 const VkBufferCreateInfo
* pCreateInfo
,
5524 const VkAllocationCallbacks
* pAllocator
,
5527 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5528 struct radv_buffer
*buffer
;
5530 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
5532 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
5533 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
5535 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
5537 buffer
->size
= pCreateInfo
->size
;
5538 buffer
->usage
= pCreateInfo
->usage
;
5541 buffer
->flags
= pCreateInfo
->flags
;
5543 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
5544 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
5546 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
5547 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
5548 align64(buffer
->size
, 4096),
5549 4096, 0, RADEON_FLAG_VIRTUAL
,
5550 RADV_BO_PRIORITY_VIRTUAL
);
5552 vk_free2(&device
->alloc
, pAllocator
, buffer
);
5553 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5557 *pBuffer
= radv_buffer_to_handle(buffer
);
5562 void radv_DestroyBuffer(
5565 const VkAllocationCallbacks
* pAllocator
)
5567 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5568 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
5573 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
5574 device
->ws
->buffer_destroy(buffer
->bo
);
5576 vk_free2(&device
->alloc
, pAllocator
, buffer
);
5579 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
5581 const VkBufferDeviceAddressInfoEXT
* pInfo
)
5583 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
5584 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
5588 static inline unsigned
5589 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
5592 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
5594 return plane
->surface
.u
.legacy
.tiling_index
[level
];
5597 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
5599 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
5603 radv_init_dcc_control_reg(struct radv_device
*device
,
5604 struct radv_image_view
*iview
)
5606 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
5607 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
5608 unsigned max_compressed_block_size
;
5609 unsigned independent_128b_blocks
;
5610 unsigned independent_64b_blocks
;
5612 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
5615 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
5616 /* amdvlk: [min-compressed-block-size] should be set to 32 for
5617 * dGPU and 64 for APU because all of our APUs to date use
5618 * DIMMs which have a request granularity size of 64B while all
5619 * other chips have a 32B request size.
5621 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
5624 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5625 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
5626 independent_64b_blocks
= 0;
5627 independent_128b_blocks
= 1;
5629 independent_128b_blocks
= 0;
5631 if (iview
->image
->info
.samples
> 1) {
5632 if (iview
->image
->planes
[0].surface
.bpe
== 1)
5633 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
5634 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
5635 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
5638 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
5639 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
5640 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
5641 /* If this DCC image is potentially going to be used in texture
5642 * fetches, we need some special settings.
5644 independent_64b_blocks
= 1;
5645 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
5647 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
5648 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
5649 * big as possible for better compression state.
5651 independent_64b_blocks
= 0;
5652 max_compressed_block_size
= max_uncompressed_block_size
;
5656 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
5657 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
5658 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
5659 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
5660 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
5664 radv_initialise_color_surface(struct radv_device
*device
,
5665 struct radv_color_buffer_info
*cb
,
5666 struct radv_image_view
*iview
)
5668 const struct vk_format_description
*desc
;
5669 unsigned ntype
, format
, swap
, endian
;
5670 unsigned blend_clamp
= 0, blend_bypass
= 0;
5672 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
5673 const struct radeon_surf
*surf
= &plane
->surface
;
5675 desc
= vk_format_description(iview
->vk_format
);
5677 memset(cb
, 0, sizeof(*cb
));
5679 /* Intensity is implemented as Red, so treat it that way. */
5680 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
5682 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
5684 cb
->cb_color_base
= va
>> 8;
5686 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
5687 struct gfx9_surf_meta_flags meta
;
5688 if (iview
->image
->dcc_offset
)
5689 meta
= surf
->u
.gfx9
.dcc
;
5691 meta
= surf
->u
.gfx9
.cmask
;
5693 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5694 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
5695 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
5696 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
5697 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
5699 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
5700 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
5701 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
5702 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
5703 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
5706 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
5707 cb
->cb_color_base
|= surf
->tile_swizzle
;
5709 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
5710 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
5712 cb
->cb_color_base
+= level_info
->offset
>> 8;
5713 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
5714 cb
->cb_color_base
|= surf
->tile_swizzle
;
5716 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
5717 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
5718 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
5720 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
5721 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
5722 cb
->cb_color_cmask_slice
= surf
->u
.legacy
.cmask_slice_tile_max
;
5724 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
5726 if (radv_image_has_fmask(iview
->image
)) {
5727 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
5728 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(surf
->u
.legacy
.fmask
.pitch_in_pixels
/ 8 - 1);
5729 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(surf
->u
.legacy
.fmask
.tiling_index
);
5730 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(surf
->u
.legacy
.fmask
.slice_tile_max
);
5732 /* This must be set for fast clear to work without FMASK. */
5733 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
5734 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
5735 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
5736 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
5740 /* CMASK variables */
5741 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
5742 va
+= iview
->image
->cmask_offset
;
5743 cb
->cb_color_cmask
= va
>> 8;
5745 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
5746 va
+= iview
->image
->dcc_offset
;
5748 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
5749 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
5750 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
5752 unsigned dcc_tile_swizzle
= surf
->tile_swizzle
;
5753 dcc_tile_swizzle
&= (surf
->dcc_alignment
- 1) >> 8;
5755 cb
->cb_dcc_base
= va
>> 8;
5756 cb
->cb_dcc_base
|= dcc_tile_swizzle
;
5758 /* GFX10 field has the same base shift as the GFX6 field. */
5759 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
5760 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
5761 S_028C6C_SLICE_MAX_GFX10(max_slice
);
5763 if (iview
->image
->info
.samples
> 1) {
5764 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
5766 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
5767 S_028C74_NUM_FRAGMENTS(log_samples
);
5770 if (radv_image_has_fmask(iview
->image
)) {
5771 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask_offset
;
5772 cb
->cb_color_fmask
= va
>> 8;
5773 cb
->cb_color_fmask
|= surf
->fmask_tile_swizzle
;
5775 cb
->cb_color_fmask
= cb
->cb_color_base
;
5778 ntype
= radv_translate_color_numformat(iview
->vk_format
,
5780 vk_format_get_first_non_void_channel(iview
->vk_format
));
5781 format
= radv_translate_colorformat(iview
->vk_format
);
5782 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
5783 radv_finishme("Illegal color\n");
5784 swap
= radv_translate_colorswap(iview
->vk_format
, false);
5785 endian
= radv_colorformat_endian_swap(format
);
5787 /* blend clamp should be set for all NORM/SRGB types */
5788 if (ntype
== V_028C70_NUMBER_UNORM
||
5789 ntype
== V_028C70_NUMBER_SNORM
||
5790 ntype
== V_028C70_NUMBER_SRGB
)
5793 /* set blend bypass according to docs if SINT/UINT or
5794 8/24 COLOR variants */
5795 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
5796 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
5797 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
5802 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
5803 (format
== V_028C70_COLOR_8
||
5804 format
== V_028C70_COLOR_8_8
||
5805 format
== V_028C70_COLOR_8_8_8_8
))
5806 ->color_is_int8
= true;
5808 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
5809 S_028C70_COMP_SWAP(swap
) |
5810 S_028C70_BLEND_CLAMP(blend_clamp
) |
5811 S_028C70_BLEND_BYPASS(blend_bypass
) |
5812 S_028C70_SIMPLE_FLOAT(1) |
5813 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
5814 ntype
!= V_028C70_NUMBER_SNORM
&&
5815 ntype
!= V_028C70_NUMBER_SRGB
&&
5816 format
!= V_028C70_COLOR_8_24
&&
5817 format
!= V_028C70_COLOR_24_8
) |
5818 S_028C70_NUMBER_TYPE(ntype
) |
5819 S_028C70_ENDIAN(endian
);
5820 if (radv_image_has_fmask(iview
->image
)) {
5821 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
5822 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
5823 unsigned fmask_bankh
= util_logbase2(surf
->u
.legacy
.fmask
.bankh
);
5824 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
5827 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
5828 /* Allow the texture block to read FMASK directly
5829 * without decompressing it. This bit must be cleared
5830 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
5831 * otherwise the operation doesn't happen.
5833 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
5835 /* Set CMASK into a tiling format that allows the
5836 * texture block to read it.
5838 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
5842 if (radv_image_has_cmask(iview
->image
) &&
5843 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
5844 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
5846 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
5847 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
5849 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
5851 /* This must be set for fast clear to work without FMASK. */
5852 if (!radv_image_has_fmask(iview
->image
) &&
5853 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
5854 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
5855 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
5858 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
5859 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
5861 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
5862 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
5863 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
5864 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
5866 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5867 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
5869 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
5870 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
5871 S_028EE0_RESOURCE_LEVEL(1);
5873 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
5874 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
5875 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
5878 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
5879 S_028C68_MIP0_HEIGHT(height
- 1) |
5880 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
5885 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
5886 struct radv_image_view
*iview
)
5888 unsigned max_zplanes
= 0;
5890 assert(radv_image_is_tc_compat_htile(iview
->image
));
5892 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
5893 /* Default value for 32-bit depth surfaces. */
5896 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
5897 iview
->image
->info
.samples
> 1)
5900 max_zplanes
= max_zplanes
+ 1;
5902 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
5903 /* Do not enable Z plane compression for 16-bit depth
5904 * surfaces because isn't supported on GFX8. Only
5905 * 32-bit depth surfaces are supported by the hardware.
5906 * This allows to maintain shader compatibility and to
5907 * reduce the number of depth decompressions.
5911 if (iview
->image
->info
.samples
<= 1)
5913 else if (iview
->image
->info
.samples
<= 4)
5924 radv_initialise_ds_surface(struct radv_device
*device
,
5925 struct radv_ds_buffer_info
*ds
,
5926 struct radv_image_view
*iview
)
5928 unsigned level
= iview
->base_mip
;
5929 unsigned format
, stencil_format
;
5930 uint64_t va
, s_offs
, z_offs
;
5931 bool stencil_only
= false;
5932 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
5933 const struct radeon_surf
*surf
= &plane
->surface
;
5935 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
5937 memset(ds
, 0, sizeof(*ds
));
5938 switch (iview
->image
->vk_format
) {
5939 case VK_FORMAT_D24_UNORM_S8_UINT
:
5940 case VK_FORMAT_X8_D24_UNORM_PACK32
:
5941 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
5942 ds
->offset_scale
= 2.0f
;
5944 case VK_FORMAT_D16_UNORM
:
5945 case VK_FORMAT_D16_UNORM_S8_UINT
:
5946 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
5947 ds
->offset_scale
= 4.0f
;
5949 case VK_FORMAT_D32_SFLOAT
:
5950 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
5951 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
5952 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
5953 ds
->offset_scale
= 1.0f
;
5955 case VK_FORMAT_S8_UINT
:
5956 stencil_only
= true;
5962 format
= radv_translate_dbformat(iview
->image
->vk_format
);
5963 stencil_format
= surf
->has_stencil
?
5964 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
5966 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
5967 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
5968 S_028008_SLICE_MAX(max_slice
);
5969 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
5970 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
5971 S_028008_SLICE_MAX_HI(max_slice
>> 11);
5974 ds
->db_htile_data_base
= 0;
5975 ds
->db_htile_surface
= 0;
5977 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
5978 s_offs
= z_offs
= va
;
5980 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
5981 assert(surf
->u
.gfx9
.surf_offset
== 0);
5982 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
5984 ds
->db_z_info
= S_028038_FORMAT(format
) |
5985 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
5986 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
5987 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
5988 S_028038_ZRANGE_PRECISION(1);
5989 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
5990 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
5992 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
5993 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
5994 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
5997 ds
->db_depth_view
|= S_028008_MIPID(level
);
5998 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
5999 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
6001 if (radv_htile_enabled(iview
->image
, level
)) {
6002 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
6004 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6005 unsigned max_zplanes
=
6006 radv_calc_decompress_on_z_planes(device
, iview
);
6008 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6010 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6011 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
6012 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
6014 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
6015 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
6019 if (!surf
->has_stencil
)
6020 /* Use all of the htile_buffer for depth if there's no stencil. */
6021 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
6022 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6023 iview
->image
->htile_offset
;
6024 ds
->db_htile_data_base
= va
>> 8;
6025 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
6026 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
6028 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
6029 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
6033 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
6036 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
6038 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
6039 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
6041 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
6042 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
6043 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
6045 if (iview
->image
->info
.samples
> 1)
6046 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
6048 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
6049 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
6050 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
6051 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
6052 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
6053 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
6054 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
6055 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
6058 tile_mode
= stencil_tile_mode
;
6060 ds
->db_depth_info
|=
6061 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
6062 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
6063 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
6064 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
6065 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
6066 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
6067 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
6068 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
6070 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
6071 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
6072 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
6073 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
6075 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
6078 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
6079 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
6080 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
6082 if (radv_htile_enabled(iview
->image
, level
)) {
6083 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
6085 if (!surf
->has_stencil
&&
6086 !radv_image_is_tc_compat_htile(iview
->image
))
6087 /* Use all of the htile_buffer for depth if there's no stencil. */
6088 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
6090 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
6091 iview
->image
->htile_offset
;
6092 ds
->db_htile_data_base
= va
>> 8;
6093 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
6095 if (radv_image_is_tc_compat_htile(iview
->image
)) {
6096 unsigned max_zplanes
=
6097 radv_calc_decompress_on_z_planes(device
, iview
);
6099 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
6100 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
6105 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
6106 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
6109 VkResult
radv_CreateFramebuffer(
6111 const VkFramebufferCreateInfo
* pCreateInfo
,
6112 const VkAllocationCallbacks
* pAllocator
,
6113 VkFramebuffer
* pFramebuffer
)
6115 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6116 struct radv_framebuffer
*framebuffer
;
6117 const VkFramebufferAttachmentsCreateInfoKHR
*imageless_create_info
=
6118 vk_find_struct_const(pCreateInfo
->pNext
,
6119 FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR
);
6121 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
6123 size_t size
= sizeof(*framebuffer
);
6124 if (!imageless_create_info
)
6125 size
+= sizeof(struct radv_image_view
*) * pCreateInfo
->attachmentCount
;
6126 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
6127 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6128 if (framebuffer
== NULL
)
6129 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6131 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
6132 framebuffer
->width
= pCreateInfo
->width
;
6133 framebuffer
->height
= pCreateInfo
->height
;
6134 framebuffer
->layers
= pCreateInfo
->layers
;
6135 if (imageless_create_info
) {
6136 for (unsigned i
= 0; i
< imageless_create_info
->attachmentImageInfoCount
; ++i
) {
6137 const VkFramebufferAttachmentImageInfoKHR
*attachment
=
6138 imageless_create_info
->pAttachmentImageInfos
+ i
;
6139 framebuffer
->width
= MIN2(framebuffer
->width
, attachment
->width
);
6140 framebuffer
->height
= MIN2(framebuffer
->height
, attachment
->height
);
6141 framebuffer
->layers
= MIN2(framebuffer
->layers
, attachment
->layerCount
);
6144 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
6145 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
6146 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
6147 framebuffer
->attachments
[i
] = iview
;
6148 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
6149 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
6150 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
6154 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
6158 void radv_DestroyFramebuffer(
6161 const VkAllocationCallbacks
* pAllocator
)
6163 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6164 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
6168 vk_free2(&device
->alloc
, pAllocator
, fb
);
6171 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
6173 switch (address_mode
) {
6174 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
6175 return V_008F30_SQ_TEX_WRAP
;
6176 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
6177 return V_008F30_SQ_TEX_MIRROR
;
6178 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
6179 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
6180 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
6181 return V_008F30_SQ_TEX_CLAMP_BORDER
;
6182 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
6183 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
6185 unreachable("illegal tex wrap mode");
6191 radv_tex_compare(VkCompareOp op
)
6194 case VK_COMPARE_OP_NEVER
:
6195 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
6196 case VK_COMPARE_OP_LESS
:
6197 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
6198 case VK_COMPARE_OP_EQUAL
:
6199 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
6200 case VK_COMPARE_OP_LESS_OR_EQUAL
:
6201 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
6202 case VK_COMPARE_OP_GREATER
:
6203 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
6204 case VK_COMPARE_OP_NOT_EQUAL
:
6205 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
6206 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
6207 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
6208 case VK_COMPARE_OP_ALWAYS
:
6209 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
6211 unreachable("illegal compare mode");
6217 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
6220 case VK_FILTER_NEAREST
:
6221 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
6222 V_008F38_SQ_TEX_XY_FILTER_POINT
);
6223 case VK_FILTER_LINEAR
:
6224 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
6225 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
6226 case VK_FILTER_CUBIC_IMG
:
6228 fprintf(stderr
, "illegal texture filter");
6234 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
6237 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
6238 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
6239 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
6240 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
6242 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
6247 radv_tex_bordercolor(VkBorderColor bcolor
)
6250 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
6251 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
6252 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
6253 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
6254 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
6255 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
6256 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
6257 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
6258 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
6266 radv_tex_aniso_filter(unsigned filter
)
6280 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
6283 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
6284 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
6285 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
6286 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
6287 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
6288 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
6296 radv_get_max_anisotropy(struct radv_device
*device
,
6297 const VkSamplerCreateInfo
*pCreateInfo
)
6299 if (device
->force_aniso
>= 0)
6300 return device
->force_aniso
;
6302 if (pCreateInfo
->anisotropyEnable
&&
6303 pCreateInfo
->maxAnisotropy
> 1.0f
)
6304 return (uint32_t)pCreateInfo
->maxAnisotropy
;
6310 radv_init_sampler(struct radv_device
*device
,
6311 struct radv_sampler
*sampler
,
6312 const VkSamplerCreateInfo
*pCreateInfo
)
6314 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
6315 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
6316 bool compat_mode
= device
->physical_device
->rad_info
.chip_class
== GFX8
||
6317 device
->physical_device
->rad_info
.chip_class
== GFX9
;
6318 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
6320 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
6321 vk_find_struct_const(pCreateInfo
->pNext
,
6322 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
6323 if (sampler_reduction
)
6324 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
6326 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
6327 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
6328 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
6329 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
6330 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
6331 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
6332 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
6333 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
6334 S_008F30_DISABLE_CUBE_WRAP(0) |
6335 S_008F30_COMPAT_MODE(compat_mode
) |
6336 S_008F30_FILTER_MODE(filter_mode
));
6337 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
6338 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
6339 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
6340 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
6341 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
6342 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
6343 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
6344 S_008F38_MIP_POINT_PRECLAMP(0));
6345 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
6346 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
6348 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
6349 sampler
->state
[2] |= S_008F38_ANISO_OVERRIDE_GFX10(1);
6351 sampler
->state
[2] |=
6352 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
6353 S_008F38_FILTER_PREC_FIX(1) |
6354 S_008F38_ANISO_OVERRIDE_GFX6(device
->physical_device
->rad_info
.chip_class
>= GFX8
);
6358 VkResult
radv_CreateSampler(
6360 const VkSamplerCreateInfo
* pCreateInfo
,
6361 const VkAllocationCallbacks
* pAllocator
,
6362 VkSampler
* pSampler
)
6364 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6365 struct radv_sampler
*sampler
;
6367 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
6368 vk_find_struct_const(pCreateInfo
->pNext
,
6369 SAMPLER_YCBCR_CONVERSION_INFO
);
6371 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
6373 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
6374 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
6376 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
6378 radv_init_sampler(device
, sampler
, pCreateInfo
);
6380 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
6381 *pSampler
= radv_sampler_to_handle(sampler
);
6386 void radv_DestroySampler(
6389 const VkAllocationCallbacks
* pAllocator
)
6391 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6392 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
6396 vk_free2(&device
->alloc
, pAllocator
, sampler
);
6399 /* vk_icd.h does not declare this function, so we declare it here to
6400 * suppress Wmissing-prototypes.
6402 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
6403 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
6405 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
6406 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
6408 /* For the full details on loader interface versioning, see
6409 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
6410 * What follows is a condensed summary, to help you navigate the large and
6411 * confusing official doc.
6413 * - Loader interface v0 is incompatible with later versions. We don't
6416 * - In loader interface v1:
6417 * - The first ICD entrypoint called by the loader is
6418 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
6420 * - The ICD must statically expose no other Vulkan symbol unless it is
6421 * linked with -Bsymbolic.
6422 * - Each dispatchable Vulkan handle created by the ICD must be
6423 * a pointer to a struct whose first member is VK_LOADER_DATA. The
6424 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
6425 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
6426 * vkDestroySurfaceKHR(). The ICD must be capable of working with
6427 * such loader-managed surfaces.
6429 * - Loader interface v2 differs from v1 in:
6430 * - The first ICD entrypoint called by the loader is
6431 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
6432 * statically expose this entrypoint.
6434 * - Loader interface v3 differs from v2 in:
6435 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
6436 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
6437 * because the loader no longer does so.
6439 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
6443 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
6444 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
6447 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6448 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
6450 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
6452 /* At the moment, we support only the below handle types. */
6453 assert(pGetFdInfo
->handleType
==
6454 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
6455 pGetFdInfo
->handleType
==
6456 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
6458 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
6460 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
6464 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
6465 VkExternalMemoryHandleTypeFlagBits handleType
,
6467 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
6469 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6471 switch (handleType
) {
6472 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
6473 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
6477 /* The valid usage section for this function says:
6479 * "handleType must not be one of the handle types defined as
6482 * So opaque handle types fall into the default "unsupported" case.
6484 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
6488 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
6492 uint32_t syncobj_handle
= 0;
6493 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
6495 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
6498 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
6500 *syncobj
= syncobj_handle
;
6506 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
6510 /* If we create a syncobj we do it locally so that if we have an error, we don't
6511 * leave a syncobj in an undetermined state in the fence. */
6512 uint32_t syncobj_handle
= *syncobj
;
6513 if (!syncobj_handle
) {
6514 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
6516 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
6521 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
6523 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
6525 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
6528 *syncobj
= syncobj_handle
;
6535 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
6536 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
6538 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6539 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
6541 struct radv_semaphore_part
*dst
= NULL
;
6543 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
6544 dst
= &sem
->temporary
;
6546 dst
= &sem
->permanent
;
6549 uint32_t syncobj
= dst
->kind
== RADV_SEMAPHORE_SYNCOBJ
? dst
->syncobj
: 0;
6551 switch(pImportSemaphoreFdInfo
->handleType
) {
6552 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
6553 result
= radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
6555 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
6556 result
= radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, &syncobj
);
6559 unreachable("Unhandled semaphore handle type");
6562 if (result
== VK_SUCCESS
) {
6563 dst
->syncobj
= syncobj
;
6564 dst
->kind
= RADV_SEMAPHORE_SYNCOBJ
;
6570 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
6571 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
6574 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6575 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
6577 uint32_t syncobj_handle
;
6579 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
6580 assert(sem
->temporary
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
6581 syncobj_handle
= sem
->temporary
.syncobj
;
6583 assert(sem
->permanent
.kind
== RADV_SEMAPHORE_SYNCOBJ
);
6584 syncobj_handle
= sem
->permanent
.syncobj
;
6587 switch(pGetFdInfo
->handleType
) {
6588 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
6589 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
6591 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
6592 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
6594 if (sem
->temporary
.kind
!= RADV_SEMAPHORE_NONE
) {
6595 radv_destroy_semaphore_part(device
, &sem
->temporary
);
6597 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
6602 unreachable("Unhandled semaphore handle type");
6606 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
6610 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
6611 VkPhysicalDevice physicalDevice
,
6612 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
6613 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
6615 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
6616 VkSemaphoreTypeKHR type
= radv_get_semaphore_type(pExternalSemaphoreInfo
->pNext
, NULL
);
6618 if (type
== VK_SEMAPHORE_TYPE_TIMELINE_KHR
) {
6619 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
6620 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
6621 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
6623 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
6624 } else if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
6625 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
6626 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
6627 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
6628 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
6629 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
6630 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
6631 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
6632 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
6633 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
6634 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
6635 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
6637 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
6638 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
6639 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
6643 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
6644 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
6646 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6647 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
6648 uint32_t *syncobj_dst
= NULL
;
6651 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
6652 syncobj_dst
= &fence
->temp_syncobj
;
6654 syncobj_dst
= &fence
->syncobj
;
6657 switch(pImportFenceFdInfo
->handleType
) {
6658 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
6659 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
6660 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
6661 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
6663 unreachable("Unhandled fence handle type");
6667 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
6668 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
6671 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6672 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
6674 uint32_t syncobj_handle
;
6676 if (fence
->temp_syncobj
)
6677 syncobj_handle
= fence
->temp_syncobj
;
6679 syncobj_handle
= fence
->syncobj
;
6681 switch(pGetFdInfo
->handleType
) {
6682 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
6683 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
6685 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
6686 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
6688 if (fence
->temp_syncobj
) {
6689 close (fence
->temp_syncobj
);
6690 fence
->temp_syncobj
= 0;
6692 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
6697 unreachable("Unhandled fence handle type");
6701 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
6705 void radv_GetPhysicalDeviceExternalFenceProperties(
6706 VkPhysicalDevice physicalDevice
,
6707 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
6708 VkExternalFenceProperties
*pExternalFenceProperties
)
6710 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
6712 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
6713 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
6714 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
6715 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
6716 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
6717 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
6718 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
6720 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
6721 pExternalFenceProperties
->compatibleHandleTypes
= 0;
6722 pExternalFenceProperties
->externalFenceFeatures
= 0;
6727 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
6728 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
6729 const VkAllocationCallbacks
* pAllocator
,
6730 VkDebugReportCallbackEXT
* pCallback
)
6732 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
6733 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
6734 pCreateInfo
, pAllocator
, &instance
->alloc
,
6739 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
6740 VkDebugReportCallbackEXT _callback
,
6741 const VkAllocationCallbacks
* pAllocator
)
6743 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
6744 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
6745 _callback
, pAllocator
, &instance
->alloc
);
6749 radv_DebugReportMessageEXT(VkInstance _instance
,
6750 VkDebugReportFlagsEXT flags
,
6751 VkDebugReportObjectTypeEXT objectType
,
6754 int32_t messageCode
,
6755 const char* pLayerPrefix
,
6756 const char* pMessage
)
6758 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
6759 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
6760 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
6764 radv_GetDeviceGroupPeerMemoryFeatures(
6767 uint32_t localDeviceIndex
,
6768 uint32_t remoteDeviceIndex
,
6769 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
6771 assert(localDeviceIndex
== remoteDeviceIndex
);
6773 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
6774 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
6775 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
6776 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
6779 static const VkTimeDomainEXT radv_time_domains
[] = {
6780 VK_TIME_DOMAIN_DEVICE_EXT
,
6781 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
6782 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
6785 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
6786 VkPhysicalDevice physicalDevice
,
6787 uint32_t *pTimeDomainCount
,
6788 VkTimeDomainEXT
*pTimeDomains
)
6791 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
6793 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
6794 vk_outarray_append(&out
, i
) {
6795 *i
= radv_time_domains
[d
];
6799 return vk_outarray_status(&out
);
6803 radv_clock_gettime(clockid_t clock_id
)
6805 struct timespec current
;
6808 ret
= clock_gettime(clock_id
, ¤t
);
6809 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
6810 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
6814 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
6817 VkResult
radv_GetCalibratedTimestampsEXT(
6819 uint32_t timestampCount
,
6820 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
6821 uint64_t *pTimestamps
,
6822 uint64_t *pMaxDeviation
)
6824 RADV_FROM_HANDLE(radv_device
, device
, _device
);
6825 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
6827 uint64_t begin
, end
;
6828 uint64_t max_clock_period
= 0;
6830 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
6832 for (d
= 0; d
< timestampCount
; d
++) {
6833 switch (pTimestampInfos
[d
].timeDomain
) {
6834 case VK_TIME_DOMAIN_DEVICE_EXT
:
6835 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
6837 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
6838 max_clock_period
= MAX2(max_clock_period
, device_period
);
6840 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
6841 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
6842 max_clock_period
= MAX2(max_clock_period
, 1);
6845 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
6846 pTimestamps
[d
] = begin
;
6854 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
6857 * The maximum deviation is the sum of the interval over which we
6858 * perform the sampling and the maximum period of any sampled
6859 * clock. That's because the maximum skew between any two sampled
6860 * clock edges is when the sampled clock with the largest period is
6861 * sampled at the end of that period but right at the beginning of the
6862 * sampling interval and some other clock is sampled right at the
6863 * begining of its sampling period and right at the end of the
6864 * sampling interval. Let's assume the GPU has the longest clock
6865 * period and that the application is sampling GPU and monotonic:
6868 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
6869 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
6873 * GPU -----_____-----_____-----_____-----_____
6876 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
6877 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
6879 * Interval <----------------->
6880 * Deviation <-------------------------->
6884 * m = read(monotonic) 2
6887 * We round the sample interval up by one tick to cover sampling error
6888 * in the interval clock
6891 uint64_t sample_interval
= end
- begin
+ 1;
6893 *pMaxDeviation
= sample_interval
+ max_clock_period
;
6898 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
6899 VkPhysicalDevice physicalDevice
,
6900 VkSampleCountFlagBits samples
,
6901 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
6903 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
6904 VK_SAMPLE_COUNT_4_BIT
|
6905 VK_SAMPLE_COUNT_8_BIT
)) {
6906 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
6908 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };