2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
48 #include "util/build_id.h"
49 #include "util/debug.h"
50 #include "util/mesa-sha1.h"
51 #include "compiler/glsl_types.h"
52 #include "util/xmlpool.h"
55 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
58 unsigned char sha1
[20];
59 unsigned ptr_size
= sizeof(void*);
61 memset(uuid
, 0, VK_UUID_SIZE
);
62 _mesa_sha1_init(&ctx
);
64 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
65 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
68 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
69 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
70 _mesa_sha1_final(&ctx
, sha1
);
72 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
77 radv_get_driver_uuid(void *uuid
)
79 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
83 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
85 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
89 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
91 const char *chip_string
;
94 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
95 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
96 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
97 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
98 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
99 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
100 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
101 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
102 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
103 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
104 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
105 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
106 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
107 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
108 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
109 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
110 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
111 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
112 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
113 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
114 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
115 case CHIP_VEGA20
: chip_string
= "AMD RADV VEGA20"; break;
116 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
117 case CHIP_RAVEN2
: chip_string
= "AMD RADV RAVEN2"; break;
118 default: chip_string
= "AMD RADV unknown"; break;
121 snprintf(name
, name_len
, "%s (LLVM " MESA_LLVM_VERSION_STRING
")", chip_string
);
125 radv_get_visible_vram_size(struct radv_physical_device
*device
)
127 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
131 radv_get_vram_size(struct radv_physical_device
*device
)
133 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
137 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
139 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
140 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
141 uint64_t vram_size
= radv_get_vram_size(device
);
142 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
143 device
->memory_properties
.memoryHeapCount
= 0;
145 vram_index
= device
->memory_properties
.memoryHeapCount
++;
146 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
148 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
151 if (visible_vram_size
) {
152 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
153 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
154 .size
= visible_vram_size
,
155 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
158 if (device
->rad_info
.gart_size
> 0) {
159 gart_index
= device
->memory_properties
.memoryHeapCount
++;
160 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
161 .size
= device
->rad_info
.gart_size
,
162 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
166 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
167 unsigned type_count
= 0;
168 if (vram_index
>= 0) {
169 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
170 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
171 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
172 .heapIndex
= vram_index
,
175 if (gart_index
>= 0) {
176 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
177 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
178 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
179 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
180 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
181 .heapIndex
= gart_index
,
184 if (visible_vram_index
>= 0) {
185 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
186 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
187 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
188 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
189 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
190 .heapIndex
= visible_vram_index
,
193 if (gart_index
>= 0) {
194 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
195 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
196 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
197 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
198 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
199 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
200 .heapIndex
= gart_index
,
203 device
->memory_properties
.memoryTypeCount
= type_count
;
207 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
209 const char *family
= getenv("RADV_FORCE_FAMILY");
215 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
216 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
217 /* Override family and chip_class. */
218 device
->rad_info
.family
= i
;
220 if (i
>= CHIP_VEGA10
)
221 device
->rad_info
.chip_class
= GFX9
;
222 else if (i
>= CHIP_TONGA
)
223 device
->rad_info
.chip_class
= GFX8
;
224 else if (i
>= CHIP_BONAIRE
)
225 device
->rad_info
.chip_class
= GFX7
;
227 device
->rad_info
.chip_class
= GFX6
;
233 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
238 radv_physical_device_init(struct radv_physical_device
*device
,
239 struct radv_instance
*instance
,
240 drmDevicePtr drm_device
)
242 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
244 drmVersionPtr version
;
248 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
250 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
251 radv_logi("Could not open device '%s'", path
);
253 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
256 version
= drmGetVersion(fd
);
260 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
261 radv_logi("Could not get the kernel driver version for device '%s'", path
);
263 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
264 "failed to get version %s: %m", path
);
267 if (strcmp(version
->name
, "amdgpu")) {
268 drmFreeVersion(version
);
271 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
272 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
274 return VK_ERROR_INCOMPATIBLE_DRIVER
;
276 drmFreeVersion(version
);
278 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
279 radv_logi("Found compatible device '%s'.", path
);
281 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
282 device
->instance
= instance
;
284 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
285 instance
->perftest_flags
);
287 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
291 if (instance
->enabled_extensions
.KHR_display
) {
292 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
293 if (master_fd
>= 0) {
294 uint32_t accel_working
= 0;
295 struct drm_amdgpu_info request
= {
296 .return_pointer
= (uintptr_t)&accel_working
,
297 .return_size
= sizeof(accel_working
),
298 .query
= AMDGPU_INFO_ACCEL_WORKING
301 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
308 device
->master_fd
= master_fd
;
309 device
->local_fd
= fd
;
310 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
312 radv_handle_env_var_force_family(device
);
314 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
316 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
317 device
->ws
->destroy(device
->ws
);
318 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
319 "cannot generate UUID");
323 /* These flags affect shader compilation. */
324 uint64_t shader_env_flags
=
325 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
326 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
328 /* The gpu id is already embedded in the uuid so we just pass "radv"
329 * when creating the cache.
331 char buf
[VK_UUID_SIZE
* 2 + 1];
332 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
333 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
335 if (device
->rad_info
.chip_class
< GFX8
||
336 device
->rad_info
.chip_class
> GFX9
)
337 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
339 radv_get_driver_uuid(&device
->driver_uuid
);
340 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
342 if (device
->rad_info
.family
== CHIP_STONEY
||
343 device
->rad_info
.chip_class
>= GFX9
) {
344 device
->has_rbplus
= true;
345 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
346 device
->rad_info
.family
== CHIP_VEGA12
||
347 device
->rad_info
.family
== CHIP_RAVEN
||
348 device
->rad_info
.family
== CHIP_RAVEN2
;
351 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
354 device
->has_clear_state
= device
->rad_info
.chip_class
>= GFX7
;
356 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= GFX8
;
358 /* Vega10/Raven need a special workaround for a hardware bug. */
359 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
360 device
->rad_info
.family
== CHIP_RAVEN
;
362 /* Out-of-order primitive rasterization. */
363 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= GFX8
&&
364 device
->rad_info
.max_se
>= 2;
365 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
366 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
368 device
->dcc_msaa_allowed
=
369 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
371 /* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
372 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
373 (device
->rad_info
.chip_class
>= GFX8
&&
374 device
->rad_info
.me_fw_feature
>= 41);
376 radv_physical_device_init_mem_types(device
);
377 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
379 device
->bus_info
= *drm_device
->businfo
.pci
;
381 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
382 ac_print_gpu_info(&device
->rad_info
);
384 /* The WSI is structured as a layer on top of the driver, so this has
385 * to be the last part of initialization (at least until we get other
388 result
= radv_init_wsi(device
);
389 if (result
!= VK_SUCCESS
) {
390 device
->ws
->destroy(device
->ws
);
391 vk_error(instance
, result
);
405 radv_physical_device_finish(struct radv_physical_device
*device
)
407 radv_finish_wsi(device
);
408 device
->ws
->destroy(device
->ws
);
409 disk_cache_destroy(device
->disk_cache
);
410 close(device
->local_fd
);
411 if (device
->master_fd
!= -1)
412 close(device
->master_fd
);
416 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
417 VkSystemAllocationScope allocationScope
)
423 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
424 size_t align
, VkSystemAllocationScope allocationScope
)
426 return realloc(pOriginal
, size
);
430 default_free_func(void *pUserData
, void *pMemory
)
435 static const VkAllocationCallbacks default_alloc
= {
437 .pfnAllocation
= default_alloc_func
,
438 .pfnReallocation
= default_realloc_func
,
439 .pfnFree
= default_free_func
,
442 static const struct debug_control radv_debug_options
[] = {
443 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
444 {"nodcc", RADV_DEBUG_NO_DCC
},
445 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
446 {"nocache", RADV_DEBUG_NO_CACHE
},
447 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
448 {"nohiz", RADV_DEBUG_NO_HIZ
},
449 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
450 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
451 {"allbos", RADV_DEBUG_ALL_BOS
},
452 {"noibs", RADV_DEBUG_NO_IBS
},
453 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
454 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
455 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
456 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
457 {"nosisched", RADV_DEBUG_NO_SISCHED
},
458 {"preoptir", RADV_DEBUG_PREOPTIR
},
459 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
460 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
461 {"info", RADV_DEBUG_INFO
},
462 {"errors", RADV_DEBUG_ERRORS
},
463 {"startup", RADV_DEBUG_STARTUP
},
464 {"checkir", RADV_DEBUG_CHECKIR
},
465 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
466 {"nobinning", RADV_DEBUG_NOBINNING
},
467 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
472 radv_get_debug_option_name(int id
)
474 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
475 return radv_debug_options
[id
].string
;
478 static const struct debug_control radv_perftest_options
[] = {
479 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
480 {"sisched", RADV_PERFTEST_SISCHED
},
481 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
482 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
483 {"bolist", RADV_PERFTEST_BO_LIST
},
488 radv_get_perftest_option_name(int id
)
490 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
491 return radv_perftest_options
[id
].string
;
495 radv_handle_per_app_options(struct radv_instance
*instance
,
496 const VkApplicationInfo
*info
)
498 const char *name
= info
? info
->pApplicationName
: NULL
;
503 if (!strcmp(name
, "Talos - Linux - 32bit") ||
504 !strcmp(name
, "Talos - Linux - 64bit")) {
505 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
506 /* Force enable LLVM sisched for Talos because it looks
507 * safe and it gives few more FPS.
509 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
511 } else if (!strcmp(name
, "DOOM_VFR")) {
512 /* Work around a Doom VFR game bug */
513 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
514 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
515 /* Workaround for a WaW hazard when LLVM moves/merges
516 * load/store memory operations.
517 * See https://reviews.llvm.org/D61313
519 if (HAVE_LLVM
< 0x900)
520 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
524 static int radv_get_instance_extension_index(const char *name
)
526 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
527 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
533 static const char radv_dri_options_xml
[] =
535 DRI_CONF_SECTION_QUALITY
536 DRI_CONF_ADAPTIVE_SYNC("true")
540 static void radv_init_dri_options(struct radv_instance
*instance
)
542 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
543 driParseConfigFiles(&instance
->dri_options
,
544 &instance
->available_dri_options
,
548 VkResult
radv_CreateInstance(
549 const VkInstanceCreateInfo
* pCreateInfo
,
550 const VkAllocationCallbacks
* pAllocator
,
551 VkInstance
* pInstance
)
553 struct radv_instance
*instance
;
556 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
558 uint32_t client_version
;
559 if (pCreateInfo
->pApplicationInfo
&&
560 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
561 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
563 client_version
= VK_API_VERSION_1_0
;
566 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
567 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
569 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
571 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
574 instance
->alloc
= *pAllocator
;
576 instance
->alloc
= default_alloc
;
578 instance
->apiVersion
= client_version
;
579 instance
->physicalDeviceCount
= -1;
581 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
584 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
585 radv_perftest_options
);
588 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
589 radv_logi("Created an instance");
591 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
592 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
593 int index
= radv_get_instance_extension_index(ext_name
);
595 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
596 vk_free2(&default_alloc
, pAllocator
, instance
);
597 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
600 instance
->enabled_extensions
.extensions
[index
] = true;
603 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
604 if (result
!= VK_SUCCESS
) {
605 vk_free2(&default_alloc
, pAllocator
, instance
);
606 return vk_error(instance
, result
);
610 glsl_type_singleton_init_or_ref();
612 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
614 radv_init_dri_options(instance
);
615 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
617 *pInstance
= radv_instance_to_handle(instance
);
622 void radv_DestroyInstance(
623 VkInstance _instance
,
624 const VkAllocationCallbacks
* pAllocator
)
626 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
631 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
632 radv_physical_device_finish(instance
->physicalDevices
+ i
);
635 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
637 glsl_type_singleton_decref();
640 driDestroyOptionCache(&instance
->dri_options
);
641 driDestroyOptionInfo(&instance
->available_dri_options
);
643 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
645 vk_free(&instance
->alloc
, instance
);
649 radv_enumerate_devices(struct radv_instance
*instance
)
651 /* TODO: Check for more devices ? */
652 drmDevicePtr devices
[8];
653 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
656 instance
->physicalDeviceCount
= 0;
658 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
660 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
661 radv_logi("Found %d drm nodes", max_devices
);
664 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
666 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
667 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
668 devices
[i
]->bustype
== DRM_BUS_PCI
&&
669 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
671 result
= radv_physical_device_init(instance
->physicalDevices
+
672 instance
->physicalDeviceCount
,
675 if (result
== VK_SUCCESS
)
676 ++instance
->physicalDeviceCount
;
677 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
681 drmFreeDevices(devices
, max_devices
);
686 VkResult
radv_EnumeratePhysicalDevices(
687 VkInstance _instance
,
688 uint32_t* pPhysicalDeviceCount
,
689 VkPhysicalDevice
* pPhysicalDevices
)
691 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
694 if (instance
->physicalDeviceCount
< 0) {
695 result
= radv_enumerate_devices(instance
);
696 if (result
!= VK_SUCCESS
&&
697 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
701 if (!pPhysicalDevices
) {
702 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
704 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
705 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
706 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
709 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
713 VkResult
radv_EnumeratePhysicalDeviceGroups(
714 VkInstance _instance
,
715 uint32_t* pPhysicalDeviceGroupCount
,
716 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
718 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
721 if (instance
->physicalDeviceCount
< 0) {
722 result
= radv_enumerate_devices(instance
);
723 if (result
!= VK_SUCCESS
&&
724 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
728 if (!pPhysicalDeviceGroupProperties
) {
729 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
731 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
732 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
733 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
734 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
735 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
738 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
742 void radv_GetPhysicalDeviceFeatures(
743 VkPhysicalDevice physicalDevice
,
744 VkPhysicalDeviceFeatures
* pFeatures
)
746 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
747 memset(pFeatures
, 0, sizeof(*pFeatures
));
749 *pFeatures
= (VkPhysicalDeviceFeatures
) {
750 .robustBufferAccess
= true,
751 .fullDrawIndexUint32
= true,
752 .imageCubeArray
= true,
753 .independentBlend
= true,
754 .geometryShader
= true,
755 .tessellationShader
= true,
756 .sampleRateShading
= true,
757 .dualSrcBlend
= true,
759 .multiDrawIndirect
= true,
760 .drawIndirectFirstInstance
= true,
762 .depthBiasClamp
= true,
763 .fillModeNonSolid
= true,
768 .multiViewport
= true,
769 .samplerAnisotropy
= true,
770 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
771 .textureCompressionASTC_LDR
= false,
772 .textureCompressionBC
= true,
773 .occlusionQueryPrecise
= true,
774 .pipelineStatisticsQuery
= true,
775 .vertexPipelineStoresAndAtomics
= true,
776 .fragmentStoresAndAtomics
= true,
777 .shaderTessellationAndGeometryPointSize
= true,
778 .shaderImageGatherExtended
= true,
779 .shaderStorageImageExtendedFormats
= true,
780 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
781 .shaderUniformBufferArrayDynamicIndexing
= true,
782 .shaderSampledImageArrayDynamicIndexing
= true,
783 .shaderStorageBufferArrayDynamicIndexing
= true,
784 .shaderStorageImageArrayDynamicIndexing
= true,
785 .shaderStorageImageReadWithoutFormat
= true,
786 .shaderStorageImageWriteWithoutFormat
= true,
787 .shaderClipDistance
= true,
788 .shaderCullDistance
= true,
789 .shaderFloat64
= true,
791 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
792 .sparseBinding
= true,
793 .variableMultisampleRate
= true,
794 .inheritedQueries
= true,
798 void radv_GetPhysicalDeviceFeatures2(
799 VkPhysicalDevice physicalDevice
,
800 VkPhysicalDeviceFeatures2
*pFeatures
)
802 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
803 vk_foreach_struct(ext
, pFeatures
->pNext
) {
804 switch (ext
->sType
) {
805 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
806 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
807 features
->variablePointersStorageBuffer
= true;
808 features
->variablePointers
= true;
811 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
812 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
813 features
->multiview
= true;
814 features
->multiviewGeometryShader
= true;
815 features
->multiviewTessellationShader
= true;
818 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
819 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
820 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
821 features
->shaderDrawParameters
= true;
824 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
825 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
826 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
827 features
->protectedMemory
= false;
830 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
831 VkPhysicalDevice16BitStorageFeatures
*features
=
832 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
833 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
834 features
->storageBuffer16BitAccess
= enabled
;
835 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
836 features
->storagePushConstant16
= enabled
;
837 features
->storageInputOutput16
= enabled
&& HAVE_LLVM
>= 0x900;
840 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
841 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
842 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
843 features
->samplerYcbcrConversion
= true;
846 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
847 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
848 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
849 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
850 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
851 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
852 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
853 features
->shaderSampledImageArrayNonUniformIndexing
= true;
854 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
855 features
->shaderStorageImageArrayNonUniformIndexing
= true;
856 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
857 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
858 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
859 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
860 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
861 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
862 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
863 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
864 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
865 features
->descriptorBindingUpdateUnusedWhilePending
= true;
866 features
->descriptorBindingPartiallyBound
= true;
867 features
->descriptorBindingVariableDescriptorCount
= true;
868 features
->runtimeDescriptorArray
= true;
871 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
872 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
873 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
874 features
->conditionalRendering
= true;
875 features
->inheritedConditionalRendering
= false;
878 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
879 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
880 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
881 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
882 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
885 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
886 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
887 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
888 features
->transformFeedback
= true;
889 features
->geometryStreams
= true;
892 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
893 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
894 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
895 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
898 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
899 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
900 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
901 features
->memoryPriority
= VK_TRUE
;
904 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
905 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
906 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
907 features
->bufferDeviceAddress
= true;
908 features
->bufferDeviceAddressCaptureReplay
= false;
909 features
->bufferDeviceAddressMultiDevice
= false;
912 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
913 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
914 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
915 features
->depthClipEnable
= true;
918 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
919 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
920 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
921 features
->hostQueryReset
= true;
924 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
925 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
926 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
927 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
928 features
->storageBuffer8BitAccess
= enabled
;
929 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
930 features
->storagePushConstant8
= enabled
;
933 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
934 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
935 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
936 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& HAVE_LLVM
>= 0x0800;
937 features
->shaderInt8
= true;
940 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
941 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
942 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
943 /* TODO: Enable this once the driver supports 64-bit
944 * compare&swap atomic operations.
946 features
->shaderBufferInt64Atomics
= false;
947 features
->shaderSharedInt64Atomics
= false;
950 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
951 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
952 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
954 features
->inlineUniformBlock
= true;
955 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
958 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
959 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
960 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
961 features
->computeDerivativeGroupQuads
= false;
962 features
->computeDerivativeGroupLinear
= true;
965 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
966 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
967 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
968 features
->ycbcrImageArrays
= true;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
972 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
973 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
974 features
->uniformBufferStandardLayout
= true;
981 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
984 void radv_GetPhysicalDeviceProperties(
985 VkPhysicalDevice physicalDevice
,
986 VkPhysicalDeviceProperties
* pProperties
)
988 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
989 VkSampleCountFlags sample_counts
= 0xf;
991 /* make sure that the entire descriptor set is addressable with a signed
992 * 32-bit int. So the sum of all limits scaled by descriptor size has to
993 * be at most 2 GiB. the combined image & samples object count as one of
994 * both. This limit is for the pipeline layout, not for the set layout, but
995 * there is no set limit, so we just set a pipeline limit. I don't think
996 * any app is going to hit this soon. */
997 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
998 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
999 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1000 32 /* sampler, largest when combined with image */ +
1001 64 /* sampled image */ +
1002 64 /* storage image */);
1004 VkPhysicalDeviceLimits limits
= {
1005 .maxImageDimension1D
= (1 << 14),
1006 .maxImageDimension2D
= (1 << 14),
1007 .maxImageDimension3D
= (1 << 11),
1008 .maxImageDimensionCube
= (1 << 14),
1009 .maxImageArrayLayers
= (1 << 11),
1010 .maxTexelBufferElements
= 128 * 1024 * 1024,
1011 .maxUniformBufferRange
= UINT32_MAX
,
1012 .maxStorageBufferRange
= UINT32_MAX
,
1013 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1014 .maxMemoryAllocationCount
= UINT32_MAX
,
1015 .maxSamplerAllocationCount
= 64 * 1024,
1016 .bufferImageGranularity
= 64, /* A cache line */
1017 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1018 .maxBoundDescriptorSets
= MAX_SETS
,
1019 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1020 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1021 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1022 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1023 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1024 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1025 .maxPerStageResources
= max_descriptor_set_size
,
1026 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1027 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1028 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1029 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1030 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1031 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1032 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1033 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1034 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1035 .maxVertexInputBindings
= MAX_VBS
,
1036 .maxVertexInputAttributeOffset
= 2047,
1037 .maxVertexInputBindingStride
= 2048,
1038 .maxVertexOutputComponents
= 128,
1039 .maxTessellationGenerationLevel
= 64,
1040 .maxTessellationPatchSize
= 32,
1041 .maxTessellationControlPerVertexInputComponents
= 128,
1042 .maxTessellationControlPerVertexOutputComponents
= 128,
1043 .maxTessellationControlPerPatchOutputComponents
= 120,
1044 .maxTessellationControlTotalOutputComponents
= 4096,
1045 .maxTessellationEvaluationInputComponents
= 128,
1046 .maxTessellationEvaluationOutputComponents
= 128,
1047 .maxGeometryShaderInvocations
= 127,
1048 .maxGeometryInputComponents
= 64,
1049 .maxGeometryOutputComponents
= 128,
1050 .maxGeometryOutputVertices
= 256,
1051 .maxGeometryTotalOutputComponents
= 1024,
1052 .maxFragmentInputComponents
= 128,
1053 .maxFragmentOutputAttachments
= 8,
1054 .maxFragmentDualSrcAttachments
= 1,
1055 .maxFragmentCombinedOutputResources
= 8,
1056 .maxComputeSharedMemorySize
= 32768,
1057 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1058 .maxComputeWorkGroupInvocations
= 2048,
1059 .maxComputeWorkGroupSize
= {
1064 .subPixelPrecisionBits
= 8,
1065 .subTexelPrecisionBits
= 8,
1066 .mipmapPrecisionBits
= 8,
1067 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1068 .maxDrawIndirectCount
= UINT32_MAX
,
1069 .maxSamplerLodBias
= 16,
1070 .maxSamplerAnisotropy
= 16,
1071 .maxViewports
= MAX_VIEWPORTS
,
1072 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1073 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1074 .viewportSubPixelBits
= 8,
1075 .minMemoryMapAlignment
= 4096, /* A page */
1076 .minTexelBufferOffsetAlignment
= 1,
1077 .minUniformBufferOffsetAlignment
= 4,
1078 .minStorageBufferOffsetAlignment
= 4,
1079 .minTexelOffset
= -32,
1080 .maxTexelOffset
= 31,
1081 .minTexelGatherOffset
= -32,
1082 .maxTexelGatherOffset
= 31,
1083 .minInterpolationOffset
= -2,
1084 .maxInterpolationOffset
= 2,
1085 .subPixelInterpolationOffsetBits
= 8,
1086 .maxFramebufferWidth
= (1 << 14),
1087 .maxFramebufferHeight
= (1 << 14),
1088 .maxFramebufferLayers
= (1 << 10),
1089 .framebufferColorSampleCounts
= sample_counts
,
1090 .framebufferDepthSampleCounts
= sample_counts
,
1091 .framebufferStencilSampleCounts
= sample_counts
,
1092 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1093 .maxColorAttachments
= MAX_RTS
,
1094 .sampledImageColorSampleCounts
= sample_counts
,
1095 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1096 .sampledImageDepthSampleCounts
= sample_counts
,
1097 .sampledImageStencilSampleCounts
= sample_counts
,
1098 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1099 .maxSampleMaskWords
= 1,
1100 .timestampComputeAndGraphics
= true,
1101 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1102 .maxClipDistances
= 8,
1103 .maxCullDistances
= 8,
1104 .maxCombinedClipAndCullDistances
= 8,
1105 .discreteQueuePriorities
= 2,
1106 .pointSizeRange
= { 0.0, 8192.0 },
1107 .lineWidthRange
= { 0.0, 7.9921875 },
1108 .pointSizeGranularity
= (1.0 / 8.0),
1109 .lineWidthGranularity
= (1.0 / 128.0),
1110 .strictLines
= false, /* FINISHME */
1111 .standardSampleLocations
= true,
1112 .optimalBufferCopyOffsetAlignment
= 128,
1113 .optimalBufferCopyRowPitchAlignment
= 128,
1114 .nonCoherentAtomSize
= 64,
1117 *pProperties
= (VkPhysicalDeviceProperties
) {
1118 .apiVersion
= radv_physical_device_api_version(pdevice
),
1119 .driverVersion
= vk_get_driver_version(),
1120 .vendorID
= ATI_VENDOR_ID
,
1121 .deviceID
= pdevice
->rad_info
.pci_id
,
1122 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1124 .sparseProperties
= {0},
1127 strcpy(pProperties
->deviceName
, pdevice
->name
);
1128 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1131 void radv_GetPhysicalDeviceProperties2(
1132 VkPhysicalDevice physicalDevice
,
1133 VkPhysicalDeviceProperties2
*pProperties
)
1135 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1136 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1138 vk_foreach_struct(ext
, pProperties
->pNext
) {
1139 switch (ext
->sType
) {
1140 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1141 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1142 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1143 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1147 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1148 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1149 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1150 properties
->deviceLUIDValid
= false;
1153 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1154 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1155 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1156 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1159 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1160 VkPhysicalDevicePointClippingProperties
*properties
=
1161 (VkPhysicalDevicePointClippingProperties
*)ext
;
1162 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1165 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1166 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1167 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1168 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1171 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1172 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1173 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1174 properties
->minImportedHostPointerAlignment
= 4096;
1177 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1178 VkPhysicalDeviceSubgroupProperties
*properties
=
1179 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1180 properties
->subgroupSize
= 64;
1181 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1182 properties
->supportedOperations
=
1183 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1184 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1185 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1186 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1187 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1188 properties
->supportedOperations
|=
1189 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1190 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1191 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1193 properties
->quadOperationsInAllStages
= true;
1196 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1197 VkPhysicalDeviceMaintenance3Properties
*properties
=
1198 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1199 /* Make sure everything is addressable by a signed 32-bit int, and
1200 * our largest descriptors are 96 bytes. */
1201 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1202 /* Our buffer size fields allow only this much */
1203 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1206 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1207 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1208 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1209 /* GFX6-8 only support single channel min/max filter. */
1210 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1211 properties
->filterMinmaxSingleComponentFormats
= true;
1214 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1215 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1216 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1218 /* Shader engines. */
1219 properties
->shaderEngineCount
=
1220 pdevice
->rad_info
.max_se
;
1221 properties
->shaderArraysPerEngineCount
=
1222 pdevice
->rad_info
.max_sh_per_se
;
1223 properties
->computeUnitsPerShaderArray
=
1224 pdevice
->rad_info
.num_good_cu_per_sh
;
1225 properties
->simdPerComputeUnit
= 4;
1226 properties
->wavefrontsPerSimd
=
1227 pdevice
->rad_info
.family
== CHIP_TONGA
||
1228 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1229 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1230 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1231 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1232 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1233 properties
->wavefrontSize
= 64;
1236 properties
->sgprsPerSimd
=
1237 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1238 properties
->minSgprAllocation
=
1239 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1240 properties
->maxSgprAllocation
=
1241 pdevice
->rad_info
.family
== CHIP_TONGA
||
1242 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1243 properties
->sgprAllocationGranularity
=
1244 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1247 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1248 properties
->minVgprAllocation
= 4;
1249 properties
->maxVgprAllocation
= 256;
1250 properties
->vgprAllocationGranularity
= 4;
1253 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1254 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1255 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1256 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1259 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1260 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1261 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1262 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1263 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1264 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1265 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1266 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1267 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1268 properties
->robustBufferAccessUpdateAfterBind
= false;
1269 properties
->quadDivergentImplicitLod
= false;
1271 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1272 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1273 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1274 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1275 32 /* sampler, largest when combined with image */ +
1276 64 /* sampled image */ +
1277 64 /* storage image */);
1278 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1279 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1280 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1281 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1282 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1283 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1284 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1285 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1286 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1287 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1288 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1289 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1290 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1291 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1292 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1295 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1296 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1297 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1298 properties
->protectedNoFault
= false;
1301 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1302 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1303 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1304 properties
->primitiveOverestimationSize
= 0;
1305 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1306 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1307 properties
->primitiveUnderestimation
= VK_FALSE
;
1308 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1309 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1310 properties
->degenerateLinesRasterized
= VK_FALSE
;
1311 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1312 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1315 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1316 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1317 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1318 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1319 properties
->pciBus
= pdevice
->bus_info
.bus
;
1320 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1321 properties
->pciFunction
= pdevice
->bus_info
.func
;
1324 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1325 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1326 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1328 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1329 memset(driver_props
->driverName
, 0, VK_MAX_DRIVER_NAME_SIZE_KHR
);
1330 strcpy(driver_props
->driverName
, "radv");
1332 memset(driver_props
->driverInfo
, 0, VK_MAX_DRIVER_INFO_SIZE_KHR
);
1333 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1334 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1335 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1337 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1345 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1346 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1347 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1348 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1349 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1350 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1351 properties
->maxTransformFeedbackStreamDataSize
= 512;
1352 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1353 properties
->maxTransformFeedbackBufferDataStride
= 512;
1354 properties
->transformFeedbackQueries
= true;
1355 properties
->transformFeedbackStreamsLinesTriangles
= false;
1356 properties
->transformFeedbackRasterizationStreamSelect
= false;
1357 properties
->transformFeedbackDraw
= true;
1360 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1361 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1362 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1364 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1365 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1366 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1367 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1368 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1377 static void radv_get_physical_device_queue_family_properties(
1378 struct radv_physical_device
* pdevice
,
1380 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1382 int num_queue_families
= 1;
1384 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1385 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1386 num_queue_families
++;
1388 if (pQueueFamilyProperties
== NULL
) {
1389 *pCount
= num_queue_families
;
1398 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1399 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1400 VK_QUEUE_COMPUTE_BIT
|
1401 VK_QUEUE_TRANSFER_BIT
|
1402 VK_QUEUE_SPARSE_BINDING_BIT
,
1404 .timestampValidBits
= 64,
1405 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1410 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1411 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1412 if (*pCount
> idx
) {
1413 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1414 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1415 VK_QUEUE_TRANSFER_BIT
|
1416 VK_QUEUE_SPARSE_BINDING_BIT
,
1417 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1418 .timestampValidBits
= 64,
1419 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1427 void radv_GetPhysicalDeviceQueueFamilyProperties(
1428 VkPhysicalDevice physicalDevice
,
1430 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1432 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1433 if (!pQueueFamilyProperties
) {
1434 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1437 VkQueueFamilyProperties
*properties
[] = {
1438 pQueueFamilyProperties
+ 0,
1439 pQueueFamilyProperties
+ 1,
1440 pQueueFamilyProperties
+ 2,
1442 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1443 assert(*pCount
<= 3);
1446 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1447 VkPhysicalDevice physicalDevice
,
1449 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1451 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1452 if (!pQueueFamilyProperties
) {
1453 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1456 VkQueueFamilyProperties
*properties
[] = {
1457 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1458 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1459 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1461 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1462 assert(*pCount
<= 3);
1465 void radv_GetPhysicalDeviceMemoryProperties(
1466 VkPhysicalDevice physicalDevice
,
1467 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1469 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1471 *pMemoryProperties
= physical_device
->memory_properties
;
1475 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1476 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1478 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1479 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1480 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1481 uint64_t vram_size
= radv_get_vram_size(device
);
1482 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1483 uint64_t heap_budget
, heap_usage
;
1485 /* For all memory heaps, the computation of budget is as follow:
1486 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1488 * The Vulkan spec 1.1.97 says that the budget should include any
1489 * currently allocated device memory.
1491 * Note that the application heap usages are not really accurate (eg.
1492 * in presence of shared buffers).
1495 heap_usage
= device
->ws
->query_value(device
->ws
,
1496 RADEON_ALLOCATED_VRAM
);
1498 heap_budget
= vram_size
-
1499 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1502 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM
] = heap_budget
;
1503 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM
] = heap_usage
;
1506 if (visible_vram_size
) {
1507 heap_usage
= device
->ws
->query_value(device
->ws
,
1508 RADEON_ALLOCATED_VRAM_VIS
);
1510 heap_budget
= visible_vram_size
-
1511 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1514 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_budget
;
1515 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_usage
;
1519 heap_usage
= device
->ws
->query_value(device
->ws
,
1520 RADEON_ALLOCATED_GTT
);
1522 heap_budget
= gtt_size
-
1523 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1526 memoryBudget
->heapBudget
[RADV_MEM_HEAP_GTT
] = heap_budget
;
1527 memoryBudget
->heapUsage
[RADV_MEM_HEAP_GTT
] = heap_usage
;
1530 /* The heapBudget and heapUsage values must be zero for array elements
1531 * greater than or equal to
1532 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1534 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1535 memoryBudget
->heapBudget
[i
] = 0;
1536 memoryBudget
->heapUsage
[i
] = 0;
1540 void radv_GetPhysicalDeviceMemoryProperties2(
1541 VkPhysicalDevice physicalDevice
,
1542 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1544 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1545 &pMemoryProperties
->memoryProperties
);
1547 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1548 vk_find_struct(pMemoryProperties
->pNext
,
1549 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1551 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1554 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1556 VkExternalMemoryHandleTypeFlagBits handleType
,
1557 const void *pHostPointer
,
1558 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1560 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1564 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1565 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1566 uint32_t memoryTypeBits
= 0;
1567 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1568 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1569 memoryTypeBits
= (1 << i
);
1573 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1577 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1581 static enum radeon_ctx_priority
1582 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1584 /* Default to MEDIUM when a specific global priority isn't requested */
1586 return RADEON_CTX_PRIORITY_MEDIUM
;
1588 switch(pObj
->globalPriority
) {
1589 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1590 return RADEON_CTX_PRIORITY_REALTIME
;
1591 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1592 return RADEON_CTX_PRIORITY_HIGH
;
1593 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1594 return RADEON_CTX_PRIORITY_MEDIUM
;
1595 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1596 return RADEON_CTX_PRIORITY_LOW
;
1598 unreachable("Illegal global priority value");
1599 return RADEON_CTX_PRIORITY_INVALID
;
1604 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1605 uint32_t queue_family_index
, int idx
,
1606 VkDeviceQueueCreateFlags flags
,
1607 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1609 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1610 queue
->device
= device
;
1611 queue
->queue_family_index
= queue_family_index
;
1612 queue
->queue_idx
= idx
;
1613 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1614 queue
->flags
= flags
;
1616 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1618 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1624 radv_queue_finish(struct radv_queue
*queue
)
1627 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1629 if (queue
->initial_full_flush_preamble_cs
)
1630 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1631 if (queue
->initial_preamble_cs
)
1632 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1633 if (queue
->continue_preamble_cs
)
1634 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1635 if (queue
->descriptor_bo
)
1636 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1637 if (queue
->scratch_bo
)
1638 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1639 if (queue
->esgs_ring_bo
)
1640 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1641 if (queue
->gsvs_ring_bo
)
1642 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1643 if (queue
->tess_rings_bo
)
1644 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1645 if (queue
->compute_scratch_bo
)
1646 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1650 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1652 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1653 bo_list
->list
.count
= bo_list
->capacity
= 0;
1654 bo_list
->list
.bos
= NULL
;
1658 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1660 free(bo_list
->list
.bos
);
1661 pthread_mutex_destroy(&bo_list
->mutex
);
1664 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1665 struct radeon_winsys_bo
*bo
)
1667 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1672 if (unlikely(!device
->use_global_bo_list
))
1675 pthread_mutex_lock(&bo_list
->mutex
);
1676 if (bo_list
->list
.count
== bo_list
->capacity
) {
1677 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1678 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1681 pthread_mutex_unlock(&bo_list
->mutex
);
1682 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1685 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1686 bo_list
->capacity
= capacity
;
1689 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1690 pthread_mutex_unlock(&bo_list
->mutex
);
1694 static void radv_bo_list_remove(struct radv_device
*device
,
1695 struct radeon_winsys_bo
*bo
)
1697 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1702 if (unlikely(!device
->use_global_bo_list
))
1705 pthread_mutex_lock(&bo_list
->mutex
);
1706 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1707 if (bo_list
->list
.bos
[i
] == bo
) {
1708 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1709 --bo_list
->list
.count
;
1713 pthread_mutex_unlock(&bo_list
->mutex
);
1717 radv_device_init_gs_info(struct radv_device
*device
)
1719 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1720 device
->physical_device
->rad_info
.family
);
1723 static int radv_get_device_extension_index(const char *name
)
1725 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1726 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1733 radv_get_int_debug_option(const char *name
, int default_value
)
1740 result
= default_value
;
1744 result
= strtol(str
, &endptr
, 0);
1745 if (str
== endptr
) {
1746 /* No digits founs. */
1747 result
= default_value
;
1754 VkResult
radv_CreateDevice(
1755 VkPhysicalDevice physicalDevice
,
1756 const VkDeviceCreateInfo
* pCreateInfo
,
1757 const VkAllocationCallbacks
* pAllocator
,
1760 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1762 struct radv_device
*device
;
1764 bool keep_shader_info
= false;
1766 /* Check enabled features */
1767 if (pCreateInfo
->pEnabledFeatures
) {
1768 VkPhysicalDeviceFeatures supported_features
;
1769 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1770 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1771 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1772 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1773 for (uint32_t i
= 0; i
< num_features
; i
++) {
1774 if (enabled_feature
[i
] && !supported_feature
[i
])
1775 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1779 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1781 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1783 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1785 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1786 device
->instance
= physical_device
->instance
;
1787 device
->physical_device
= physical_device
;
1789 device
->ws
= physical_device
->ws
;
1791 device
->alloc
= *pAllocator
;
1793 device
->alloc
= physical_device
->instance
->alloc
;
1795 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1796 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1797 int index
= radv_get_device_extension_index(ext_name
);
1798 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1799 vk_free(&device
->alloc
, device
);
1800 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1803 device
->enabled_extensions
.extensions
[index
] = true;
1806 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1808 /* With update after bind we can't attach bo's to the command buffer
1809 * from the descriptor set anymore, so we have to use a global BO list.
1811 device
->use_global_bo_list
=
1812 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1813 device
->enabled_extensions
.EXT_descriptor_indexing
||
1814 device
->enabled_extensions
.EXT_buffer_device_address
;
1816 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1817 list_inithead(&device
->shader_slabs
);
1819 radv_bo_list_init(&device
->bo_list
);
1821 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1822 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1823 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1824 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1825 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1827 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1829 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1830 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1831 if (!device
->queues
[qfi
]) {
1832 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1836 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1838 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1840 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1841 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1842 qfi
, q
, queue_create
->flags
,
1844 if (result
!= VK_SUCCESS
)
1849 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1850 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1852 /* Disabled and not implemented for now. */
1853 device
->dfsm_allowed
= device
->pbb_allowed
&&
1854 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1855 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
);
1858 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1861 /* The maximum number of scratch waves. Scratch space isn't divided
1862 * evenly between CUs. The number is only a function of the number of CUs.
1863 * We can decrease the constant to decrease the scratch buffer size.
1865 * sctx->scratch_waves must be >= the maximum possible size of
1866 * 1 threadgroup, so that the hw doesn't hang from being unable
1869 * The recommended value is 4 per CU at most. Higher numbers don't
1870 * bring much benefit, but they still occupy chip resources (think
1871 * async compute). I've seen ~2% performance difference between 4 and 32.
1873 uint32_t max_threads_per_block
= 2048;
1874 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1875 max_threads_per_block
/ 64);
1877 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1879 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
1880 /* If the KMD allows it (there is a KMD hw register for it),
1881 * allow launching waves out-of-order.
1883 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1886 radv_device_init_gs_info(device
);
1888 device
->tess_offchip_block_dw_size
=
1889 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1890 device
->has_distributed_tess
=
1891 device
->physical_device
->rad_info
.chip_class
>= GFX8
&&
1892 device
->physical_device
->rad_info
.max_se
>= 2;
1894 if (getenv("RADV_TRACE_FILE")) {
1895 const char *filename
= getenv("RADV_TRACE_FILE");
1897 keep_shader_info
= true;
1899 if (!radv_init_trace(device
))
1902 fprintf(stderr
, "*****************************************************************************\n");
1903 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1904 fprintf(stderr
, "*****************************************************************************\n");
1906 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1907 radv_dump_enabled_options(device
, stderr
);
1910 device
->keep_shader_info
= keep_shader_info
;
1912 result
= radv_device_init_meta(device
);
1913 if (result
!= VK_SUCCESS
)
1916 radv_device_init_msaa(device
);
1918 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1919 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1921 case RADV_QUEUE_GENERAL
:
1922 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1923 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1924 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1926 case RADV_QUEUE_COMPUTE
:
1927 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1928 radeon_emit(device
->empty_cs
[family
], 0);
1931 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1934 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
1935 cik_create_gfx_config(device
);
1937 VkPipelineCacheCreateInfo ci
;
1938 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1941 ci
.pInitialData
= NULL
;
1942 ci
.initialDataSize
= 0;
1944 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1946 if (result
!= VK_SUCCESS
)
1949 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1951 device
->force_aniso
=
1952 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1953 if (device
->force_aniso
>= 0) {
1954 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
1955 1 << util_logbase2(device
->force_aniso
));
1958 *pDevice
= radv_device_to_handle(device
);
1962 radv_device_finish_meta(device
);
1964 radv_bo_list_finish(&device
->bo_list
);
1966 if (device
->trace_bo
)
1967 device
->ws
->buffer_destroy(device
->trace_bo
);
1969 if (device
->gfx_init
)
1970 device
->ws
->buffer_destroy(device
->gfx_init
);
1972 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1973 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1974 radv_queue_finish(&device
->queues
[i
][q
]);
1975 if (device
->queue_count
[i
])
1976 vk_free(&device
->alloc
, device
->queues
[i
]);
1979 vk_free(&device
->alloc
, device
);
1983 void radv_DestroyDevice(
1985 const VkAllocationCallbacks
* pAllocator
)
1987 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1992 if (device
->trace_bo
)
1993 device
->ws
->buffer_destroy(device
->trace_bo
);
1995 if (device
->gfx_init
)
1996 device
->ws
->buffer_destroy(device
->gfx_init
);
1998 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1999 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2000 radv_queue_finish(&device
->queues
[i
][q
]);
2001 if (device
->queue_count
[i
])
2002 vk_free(&device
->alloc
, device
->queues
[i
]);
2003 if (device
->empty_cs
[i
])
2004 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2006 radv_device_finish_meta(device
);
2008 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2009 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2011 radv_destroy_shader_slabs(device
);
2013 radv_bo_list_finish(&device
->bo_list
);
2014 vk_free(&device
->alloc
, device
);
2017 VkResult
radv_EnumerateInstanceLayerProperties(
2018 uint32_t* pPropertyCount
,
2019 VkLayerProperties
* pProperties
)
2021 if (pProperties
== NULL
) {
2022 *pPropertyCount
= 0;
2026 /* None supported at this time */
2027 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2030 VkResult
radv_EnumerateDeviceLayerProperties(
2031 VkPhysicalDevice physicalDevice
,
2032 uint32_t* pPropertyCount
,
2033 VkLayerProperties
* pProperties
)
2035 if (pProperties
== NULL
) {
2036 *pPropertyCount
= 0;
2040 /* None supported at this time */
2041 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2044 void radv_GetDeviceQueue2(
2046 const VkDeviceQueueInfo2
* pQueueInfo
,
2049 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2050 struct radv_queue
*queue
;
2052 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2053 if (pQueueInfo
->flags
!= queue
->flags
) {
2054 /* From the Vulkan 1.1.70 spec:
2056 * "The queue returned by vkGetDeviceQueue2 must have the same
2057 * flags value from this structure as that used at device
2058 * creation time in a VkDeviceQueueCreateInfo instance. If no
2059 * matching flags were specified at device creation time then
2060 * pQueue will return VK_NULL_HANDLE."
2062 *pQueue
= VK_NULL_HANDLE
;
2066 *pQueue
= radv_queue_to_handle(queue
);
2069 void radv_GetDeviceQueue(
2071 uint32_t queueFamilyIndex
,
2072 uint32_t queueIndex
,
2075 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2076 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2077 .queueFamilyIndex
= queueFamilyIndex
,
2078 .queueIndex
= queueIndex
2081 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2085 fill_geom_tess_rings(struct radv_queue
*queue
,
2087 bool add_sample_positions
,
2088 uint32_t esgs_ring_size
,
2089 struct radeon_winsys_bo
*esgs_ring_bo
,
2090 uint32_t gsvs_ring_size
,
2091 struct radeon_winsys_bo
*gsvs_ring_bo
,
2092 uint32_t tess_factor_ring_size
,
2093 uint32_t tess_offchip_ring_offset
,
2094 uint32_t tess_offchip_ring_size
,
2095 struct radeon_winsys_bo
*tess_rings_bo
)
2097 uint32_t *desc
= &map
[4];
2100 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2102 /* stride 0, num records - size, add tid, swizzle, elsize4,
2105 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2106 S_008F04_STRIDE(0) |
2107 S_008F04_SWIZZLE_ENABLE(true);
2108 desc
[2] = esgs_ring_size
;
2109 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2110 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2111 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2112 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2113 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2114 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2115 S_008F0C_ELEMENT_SIZE(1) |
2116 S_008F0C_INDEX_STRIDE(3) |
2117 S_008F0C_ADD_TID_ENABLE(true);
2119 /* GS entry for ES->GS ring */
2120 /* stride 0, num records - size, elsize0,
2123 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
2124 S_008F04_STRIDE(0) |
2125 S_008F04_SWIZZLE_ENABLE(false);
2126 desc
[6] = esgs_ring_size
;
2127 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2128 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2129 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2130 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2131 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2132 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2133 S_008F0C_ELEMENT_SIZE(0) |
2134 S_008F0C_INDEX_STRIDE(0) |
2135 S_008F0C_ADD_TID_ENABLE(false);
2141 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2143 /* VS entry for GS->VS ring */
2144 /* stride 0, num records - size, elsize0,
2147 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2148 S_008F04_STRIDE(0) |
2149 S_008F04_SWIZZLE_ENABLE(false);
2150 desc
[2] = gsvs_ring_size
;
2151 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2152 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2153 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2154 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2155 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2156 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2157 S_008F0C_ELEMENT_SIZE(0) |
2158 S_008F0C_INDEX_STRIDE(0) |
2159 S_008F0C_ADD_TID_ENABLE(false);
2161 /* stride gsvs_itemsize, num records 64
2162 elsize 4, index stride 16 */
2163 /* shader will patch stride and desc[2] */
2165 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2166 S_008F04_STRIDE(0) |
2167 S_008F04_SWIZZLE_ENABLE(true);
2169 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2170 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2171 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2172 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2173 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2174 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2175 S_008F0C_ELEMENT_SIZE(1) |
2176 S_008F0C_INDEX_STRIDE(1) |
2177 S_008F0C_ADD_TID_ENABLE(true);
2182 if (tess_rings_bo
) {
2183 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2184 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2187 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
2188 S_008F04_STRIDE(0) |
2189 S_008F04_SWIZZLE_ENABLE(false);
2190 desc
[2] = tess_factor_ring_size
;
2191 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2192 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2193 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2194 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2195 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2196 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2197 S_008F0C_ELEMENT_SIZE(0) |
2198 S_008F0C_INDEX_STRIDE(0) |
2199 S_008F0C_ADD_TID_ENABLE(false);
2201 desc
[4] = tess_offchip_va
;
2202 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
2203 S_008F04_STRIDE(0) |
2204 S_008F04_SWIZZLE_ENABLE(false);
2205 desc
[6] = tess_offchip_ring_size
;
2206 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2207 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2208 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2209 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2210 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2211 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2212 S_008F0C_ELEMENT_SIZE(0) |
2213 S_008F0C_INDEX_STRIDE(0) |
2214 S_008F0C_ADD_TID_ENABLE(false);
2219 if (add_sample_positions
) {
2220 /* add sample positions after all rings */
2221 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2223 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2225 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2227 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2232 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2234 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2235 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2236 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2237 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2238 unsigned max_offchip_buffers
;
2239 unsigned offchip_granularity
;
2240 unsigned hs_offchip_param
;
2244 * This must be one less than the maximum number due to a hw limitation.
2245 * Various hardware bugs need thGFX7
2248 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2249 * Gfx7 should limit max_offchip_buffers to 508
2250 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2252 * Follow AMDVLK here.
2254 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2255 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2256 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2257 --max_offchip_buffers_per_se
;
2259 max_offchip_buffers
= max_offchip_buffers_per_se
*
2260 device
->physical_device
->rad_info
.max_se
;
2262 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2263 * around by setting 4K granularity.
2265 if (device
->tess_offchip_block_dw_size
== 4096) {
2266 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2267 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2269 assert(device
->tess_offchip_block_dw_size
== 8192);
2270 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2273 switch (device
->physical_device
->rad_info
.chip_class
) {
2275 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2281 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2285 *max_offchip_buffers_p
= max_offchip_buffers
;
2286 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2287 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2288 --max_offchip_buffers
;
2290 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2291 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2294 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2296 return hs_offchip_param
;
2300 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2301 struct radeon_winsys_bo
*esgs_ring_bo
,
2302 uint32_t esgs_ring_size
,
2303 struct radeon_winsys_bo
*gsvs_ring_bo
,
2304 uint32_t gsvs_ring_size
)
2306 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2310 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2313 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2315 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2316 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2317 radeon_emit(cs
, esgs_ring_size
>> 8);
2318 radeon_emit(cs
, gsvs_ring_size
>> 8);
2320 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2321 radeon_emit(cs
, esgs_ring_size
>> 8);
2322 radeon_emit(cs
, gsvs_ring_size
>> 8);
2327 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2328 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2329 struct radeon_winsys_bo
*tess_rings_bo
)
2336 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2338 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2340 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2341 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2342 S_030938_SIZE(tf_ring_size
/ 4));
2343 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2345 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2346 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2347 S_030944_BASE_HI(tf_va
>> 40));
2349 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2352 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2353 S_008988_SIZE(tf_ring_size
/ 4));
2354 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2356 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2362 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2363 struct radeon_winsys_bo
*compute_scratch_bo
)
2365 uint64_t scratch_va
;
2367 if (!compute_scratch_bo
)
2370 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2372 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2374 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2375 radeon_emit(cs
, scratch_va
);
2376 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2377 S_008F04_SWIZZLE_ENABLE(1));
2381 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2382 struct radeon_cmdbuf
*cs
,
2383 struct radeon_winsys_bo
*descriptor_bo
)
2390 va
= radv_buffer_get_va(descriptor_bo
);
2392 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2394 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2395 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2396 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2397 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2398 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2400 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2401 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2405 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2406 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2407 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2408 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2409 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2410 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2412 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2413 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2420 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2422 struct radv_device
*device
= queue
->device
;
2424 if (device
->gfx_init
) {
2425 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2427 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2428 radeon_emit(cs
, va
);
2429 radeon_emit(cs
, va
>> 32);
2430 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2432 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2434 struct radv_physical_device
*physical_device
= device
->physical_device
;
2435 si_emit_graphics(physical_device
, cs
);
2440 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2442 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2443 si_emit_compute(physical_device
, cs
);
2447 radv_get_preamble_cs(struct radv_queue
*queue
,
2448 uint32_t scratch_size
,
2449 uint32_t compute_scratch_size
,
2450 uint32_t esgs_ring_size
,
2451 uint32_t gsvs_ring_size
,
2452 bool needs_tess_rings
,
2453 bool needs_sample_positions
,
2454 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2455 struct radeon_cmdbuf
**initial_preamble_cs
,
2456 struct radeon_cmdbuf
**continue_preamble_cs
)
2458 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2459 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2460 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2461 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2462 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2463 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2464 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2465 bool add_tess_rings
= false, add_sample_positions
= false;
2466 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2467 unsigned max_offchip_buffers
;
2468 unsigned hs_offchip_param
= 0;
2469 unsigned tess_offchip_ring_offset
;
2470 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2471 if (!queue
->has_tess_rings
) {
2472 if (needs_tess_rings
)
2473 add_tess_rings
= true;
2475 if (!queue
->has_sample_positions
) {
2476 if (needs_sample_positions
)
2477 add_sample_positions
= true;
2479 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2480 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2481 &max_offchip_buffers
);
2482 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2483 tess_offchip_ring_size
= max_offchip_buffers
*
2484 queue
->device
->tess_offchip_block_dw_size
* 4;
2486 if (scratch_size
<= queue
->scratch_size
&&
2487 compute_scratch_size
<= queue
->compute_scratch_size
&&
2488 esgs_ring_size
<= queue
->esgs_ring_size
&&
2489 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2490 !add_tess_rings
&& !add_sample_positions
&&
2491 queue
->initial_preamble_cs
) {
2492 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2493 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2494 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2495 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2496 *continue_preamble_cs
= NULL
;
2500 if (scratch_size
> queue
->scratch_size
) {
2501 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2506 RADV_BO_PRIORITY_SCRATCH
);
2510 scratch_bo
= queue
->scratch_bo
;
2512 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2513 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2514 compute_scratch_size
,
2518 RADV_BO_PRIORITY_SCRATCH
);
2519 if (!compute_scratch_bo
)
2523 compute_scratch_bo
= queue
->compute_scratch_bo
;
2525 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2526 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2531 RADV_BO_PRIORITY_SCRATCH
);
2535 esgs_ring_bo
= queue
->esgs_ring_bo
;
2536 esgs_ring_size
= queue
->esgs_ring_size
;
2539 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2540 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2545 RADV_BO_PRIORITY_SCRATCH
);
2549 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2550 gsvs_ring_size
= queue
->gsvs_ring_size
;
2553 if (add_tess_rings
) {
2554 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2555 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2559 RADV_BO_PRIORITY_SCRATCH
);
2563 tess_rings_bo
= queue
->tess_rings_bo
;
2566 if (scratch_bo
!= queue
->scratch_bo
||
2567 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2568 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2569 tess_rings_bo
!= queue
->tess_rings_bo
||
2570 add_sample_positions
) {
2572 if (gsvs_ring_bo
|| esgs_ring_bo
||
2573 tess_rings_bo
|| add_sample_positions
) {
2574 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2575 if (add_sample_positions
)
2576 size
+= 128; /* 64+32+16+8 = 120 bytes */
2578 else if (scratch_bo
)
2579 size
= 8; /* 2 dword */
2581 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2585 RADEON_FLAG_CPU_ACCESS
|
2586 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2587 RADEON_FLAG_READ_ONLY
,
2588 RADV_BO_PRIORITY_DESCRIPTOR
);
2592 descriptor_bo
= queue
->descriptor_bo
;
2594 if (descriptor_bo
!= queue
->descriptor_bo
) {
2595 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2598 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2599 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2600 S_008F04_SWIZZLE_ENABLE(1);
2601 map
[0] = scratch_va
;
2605 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2606 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2607 esgs_ring_size
, esgs_ring_bo
,
2608 gsvs_ring_size
, gsvs_ring_bo
,
2609 tess_factor_ring_size
,
2610 tess_offchip_ring_offset
,
2611 tess_offchip_ring_size
,
2614 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2617 for(int i
= 0; i
< 3; ++i
) {
2618 struct radeon_cmdbuf
*cs
= NULL
;
2619 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2620 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2627 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2629 /* Emit initial configuration. */
2630 switch (queue
->queue_family_index
) {
2631 case RADV_QUEUE_GENERAL
:
2632 radv_init_graphics_state(cs
, queue
);
2634 case RADV_QUEUE_COMPUTE
:
2635 radv_init_compute_state(cs
, queue
);
2637 case RADV_QUEUE_TRANSFER
:
2641 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2642 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2643 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2644 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2645 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2648 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2649 gsvs_ring_bo
, gsvs_ring_size
);
2650 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2651 tess_factor_ring_size
, tess_rings_bo
);
2652 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2653 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2656 si_cs_emit_cache_flush(cs
,
2657 queue
->device
->physical_device
->rad_info
.chip_class
,
2659 queue
->queue_family_index
== RING_COMPUTE
&&
2660 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2661 (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
)) |
2662 RADV_CMD_FLAG_INV_ICACHE
|
2663 RADV_CMD_FLAG_INV_SMEM_L1
|
2664 RADV_CMD_FLAG_INV_VMEM_L1
|
2665 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2666 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2667 } else if (i
== 1) {
2668 si_cs_emit_cache_flush(cs
,
2669 queue
->device
->physical_device
->rad_info
.chip_class
,
2671 queue
->queue_family_index
== RING_COMPUTE
&&
2672 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2673 RADV_CMD_FLAG_INV_ICACHE
|
2674 RADV_CMD_FLAG_INV_SMEM_L1
|
2675 RADV_CMD_FLAG_INV_VMEM_L1
|
2676 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2677 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2680 if (!queue
->device
->ws
->cs_finalize(cs
))
2684 if (queue
->initial_full_flush_preamble_cs
)
2685 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2687 if (queue
->initial_preamble_cs
)
2688 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2690 if (queue
->continue_preamble_cs
)
2691 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2693 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2694 queue
->initial_preamble_cs
= dest_cs
[1];
2695 queue
->continue_preamble_cs
= dest_cs
[2];
2697 if (scratch_bo
!= queue
->scratch_bo
) {
2698 if (queue
->scratch_bo
)
2699 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2700 queue
->scratch_bo
= scratch_bo
;
2701 queue
->scratch_size
= scratch_size
;
2704 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2705 if (queue
->compute_scratch_bo
)
2706 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2707 queue
->compute_scratch_bo
= compute_scratch_bo
;
2708 queue
->compute_scratch_size
= compute_scratch_size
;
2711 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2712 if (queue
->esgs_ring_bo
)
2713 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2714 queue
->esgs_ring_bo
= esgs_ring_bo
;
2715 queue
->esgs_ring_size
= esgs_ring_size
;
2718 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2719 if (queue
->gsvs_ring_bo
)
2720 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2721 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2722 queue
->gsvs_ring_size
= gsvs_ring_size
;
2725 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2726 queue
->tess_rings_bo
= tess_rings_bo
;
2727 queue
->has_tess_rings
= true;
2730 if (descriptor_bo
!= queue
->descriptor_bo
) {
2731 if (queue
->descriptor_bo
)
2732 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2734 queue
->descriptor_bo
= descriptor_bo
;
2737 if (add_sample_positions
)
2738 queue
->has_sample_positions
= true;
2740 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2741 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2742 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2743 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2744 *continue_preamble_cs
= NULL
;
2747 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2749 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2750 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2751 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2752 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2753 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2754 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2755 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2756 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2757 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2758 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2759 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2760 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2761 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2762 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2765 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2766 struct radv_winsys_sem_counts
*counts
,
2768 const VkSemaphore
*sems
,
2772 int syncobj_idx
= 0, sem_idx
= 0;
2774 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2777 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2778 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2780 if (sem
->temp_syncobj
|| sem
->syncobj
)
2781 counts
->syncobj_count
++;
2783 counts
->sem_count
++;
2786 if (_fence
!= VK_NULL_HANDLE
) {
2787 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2788 if (fence
->temp_syncobj
|| fence
->syncobj
)
2789 counts
->syncobj_count
++;
2792 if (counts
->syncobj_count
) {
2793 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2794 if (!counts
->syncobj
)
2795 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2798 if (counts
->sem_count
) {
2799 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2801 free(counts
->syncobj
);
2802 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2806 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2807 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2809 if (sem
->temp_syncobj
) {
2810 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2812 else if (sem
->syncobj
)
2813 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2816 counts
->sem
[sem_idx
++] = sem
->sem
;
2820 if (_fence
!= VK_NULL_HANDLE
) {
2821 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2822 if (fence
->temp_syncobj
)
2823 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2824 else if (fence
->syncobj
)
2825 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2832 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2834 free(sem_info
->wait
.syncobj
);
2835 free(sem_info
->wait
.sem
);
2836 free(sem_info
->signal
.syncobj
);
2837 free(sem_info
->signal
.sem
);
2841 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2843 const VkSemaphore
*sems
)
2845 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2846 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2848 if (sem
->temp_syncobj
) {
2849 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2850 sem
->temp_syncobj
= 0;
2856 radv_alloc_sem_info(struct radv_instance
*instance
,
2857 struct radv_winsys_sem_info
*sem_info
,
2859 const VkSemaphore
*wait_sems
,
2860 int num_signal_sems
,
2861 const VkSemaphore
*signal_sems
,
2865 memset(sem_info
, 0, sizeof(*sem_info
));
2867 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2870 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2872 radv_free_sem_info(sem_info
);
2874 /* caller can override these */
2875 sem_info
->cs_emit_wait
= true;
2876 sem_info
->cs_emit_signal
= true;
2880 /* Signals fence as soon as all the work currently put on queue is done. */
2881 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2882 struct radv_fence
*fence
)
2886 struct radv_winsys_sem_info sem_info
;
2888 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2889 radv_fence_to_handle(fence
));
2890 if (result
!= VK_SUCCESS
)
2893 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2894 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2895 1, NULL
, NULL
, &sem_info
, NULL
,
2896 false, fence
->fence
);
2897 radv_free_sem_info(&sem_info
);
2900 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2905 VkResult
radv_QueueSubmit(
2907 uint32_t submitCount
,
2908 const VkSubmitInfo
* pSubmits
,
2911 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2912 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2913 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2914 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2916 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
2917 uint32_t scratch_size
= 0;
2918 uint32_t compute_scratch_size
= 0;
2919 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2920 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2922 bool fence_emitted
= false;
2923 bool tess_rings_needed
= false;
2924 bool sample_positions_needed
= false;
2926 /* Do this first so failing to allocate scratch buffers can't result in
2927 * partially executed submissions. */
2928 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2929 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2930 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2931 pSubmits
[i
].pCommandBuffers
[j
]);
2933 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2934 compute_scratch_size
= MAX2(compute_scratch_size
,
2935 cmd_buffer
->compute_scratch_size_needed
);
2936 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2937 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2938 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2939 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2943 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2944 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2945 sample_positions_needed
, &initial_flush_preamble_cs
,
2946 &initial_preamble_cs
, &continue_preamble_cs
);
2947 if (result
!= VK_SUCCESS
)
2950 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2951 struct radeon_cmdbuf
**cs_array
;
2952 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2953 bool can_patch
= true;
2955 struct radv_winsys_sem_info sem_info
;
2957 result
= radv_alloc_sem_info(queue
->device
->instance
,
2959 pSubmits
[i
].waitSemaphoreCount
,
2960 pSubmits
[i
].pWaitSemaphores
,
2961 pSubmits
[i
].signalSemaphoreCount
,
2962 pSubmits
[i
].pSignalSemaphores
,
2964 if (result
!= VK_SUCCESS
)
2967 if (!pSubmits
[i
].commandBufferCount
) {
2968 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2969 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2970 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2975 radv_loge("failed to submit CS %d\n", i
);
2978 fence_emitted
= true;
2980 radv_free_sem_info(&sem_info
);
2984 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2985 (pSubmits
[i
].commandBufferCount
));
2987 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2988 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2989 pSubmits
[i
].pCommandBuffers
[j
]);
2990 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2992 cs_array
[j
] = cmd_buffer
->cs
;
2993 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2996 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2999 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3000 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3001 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3003 advance
= MIN2(max_cs_submission
,
3004 pSubmits
[i
].commandBufferCount
- j
);
3006 if (queue
->device
->trace_bo
)
3007 *queue
->device
->trace_id_ptr
= 0;
3009 sem_info
.cs_emit_wait
= j
== 0;
3010 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3012 if (unlikely(queue
->device
->use_global_bo_list
)) {
3013 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3014 bo_list
= &queue
->device
->bo_list
.list
;
3017 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3018 advance
, initial_preamble
, continue_preamble_cs
,
3020 can_patch
, base_fence
);
3022 if (unlikely(queue
->device
->use_global_bo_list
))
3023 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3026 radv_loge("failed to submit CS %d\n", i
);
3029 fence_emitted
= true;
3030 if (queue
->device
->trace_bo
) {
3031 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3035 radv_free_temp_syncobjs(queue
->device
,
3036 pSubmits
[i
].waitSemaphoreCount
,
3037 pSubmits
[i
].pWaitSemaphores
);
3038 radv_free_sem_info(&sem_info
);
3043 if (!fence_emitted
) {
3044 result
= radv_signal_fence(queue
, fence
);
3045 if (result
!= VK_SUCCESS
)
3053 VkResult
radv_QueueWaitIdle(
3056 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3058 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3059 radv_queue_family_to_ring(queue
->queue_family_index
),
3064 VkResult
radv_DeviceWaitIdle(
3067 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3069 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3070 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3071 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3077 VkResult
radv_EnumerateInstanceExtensionProperties(
3078 const char* pLayerName
,
3079 uint32_t* pPropertyCount
,
3080 VkExtensionProperties
* pProperties
)
3082 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3084 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3085 if (radv_supported_instance_extensions
.extensions
[i
]) {
3086 vk_outarray_append(&out
, prop
) {
3087 *prop
= radv_instance_extensions
[i
];
3092 return vk_outarray_status(&out
);
3095 VkResult
radv_EnumerateDeviceExtensionProperties(
3096 VkPhysicalDevice physicalDevice
,
3097 const char* pLayerName
,
3098 uint32_t* pPropertyCount
,
3099 VkExtensionProperties
* pProperties
)
3101 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3102 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3104 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3105 if (device
->supported_extensions
.extensions
[i
]) {
3106 vk_outarray_append(&out
, prop
) {
3107 *prop
= radv_device_extensions
[i
];
3112 return vk_outarray_status(&out
);
3115 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3116 VkInstance _instance
,
3119 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3121 return radv_lookup_entrypoint_checked(pName
,
3122 instance
? instance
->apiVersion
: 0,
3123 instance
? &instance
->enabled_extensions
: NULL
,
3127 /* The loader wants us to expose a second GetInstanceProcAddr function
3128 * to work around certain LD_PRELOAD issues seen in apps.
3131 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3132 VkInstance instance
,
3136 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3137 VkInstance instance
,
3140 return radv_GetInstanceProcAddr(instance
, pName
);
3144 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3145 VkInstance _instance
,
3149 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3150 VkInstance _instance
,
3153 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3155 return radv_lookup_physical_device_entrypoint_checked(pName
,
3156 instance
? instance
->apiVersion
: 0,
3157 instance
? &instance
->enabled_extensions
: NULL
);
3160 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3164 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3166 return radv_lookup_entrypoint_checked(pName
,
3167 device
->instance
->apiVersion
,
3168 &device
->instance
->enabled_extensions
,
3169 &device
->enabled_extensions
);
3172 bool radv_get_memory_fd(struct radv_device
*device
,
3173 struct radv_device_memory
*memory
,
3176 struct radeon_bo_metadata metadata
;
3178 if (memory
->image
) {
3179 radv_init_metadata(device
, memory
->image
, &metadata
);
3180 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3183 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3187 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3188 const VkMemoryAllocateInfo
* pAllocateInfo
,
3189 const VkAllocationCallbacks
* pAllocator
,
3190 VkDeviceMemory
* pMem
)
3192 struct radv_device_memory
*mem
;
3194 enum radeon_bo_domain domain
;
3196 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3198 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3200 if (pAllocateInfo
->allocationSize
== 0) {
3201 /* Apparently, this is allowed */
3202 *pMem
= VK_NULL_HANDLE
;
3206 const VkImportMemoryFdInfoKHR
*import_info
=
3207 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3208 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3209 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3210 const VkExportMemoryAllocateInfo
*export_info
=
3211 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3212 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3213 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3215 const struct wsi_memory_allocate_info
*wsi_info
=
3216 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3218 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3219 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3221 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3223 if (wsi_info
&& wsi_info
->implicit_sync
)
3224 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3226 if (dedicate_info
) {
3227 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3228 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3234 float priority_float
= 0.5;
3235 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3236 vk_find_struct_const(pAllocateInfo
->pNext
,
3237 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3239 priority_float
= priority_ext
->priority
;
3241 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3242 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3244 mem
->user_ptr
= NULL
;
3247 assert(import_info
->handleType
==
3248 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3249 import_info
->handleType
==
3250 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3251 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3252 priority
, NULL
, NULL
);
3254 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3257 close(import_info
->fd
);
3259 } else if (host_ptr_info
) {
3260 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3261 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3262 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3263 pAllocateInfo
->allocationSize
,
3266 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3269 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3272 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3273 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3274 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3275 domain
= RADEON_DOMAIN_GTT
;
3277 domain
= RADEON_DOMAIN_VRAM
;
3279 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3280 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3282 flags
|= RADEON_FLAG_CPU_ACCESS
;
3284 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3285 flags
|= RADEON_FLAG_GTT_WC
;
3287 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3288 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3289 if (device
->use_global_bo_list
) {
3290 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3294 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3295 domain
, flags
, priority
);
3298 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3301 mem
->type_index
= mem_type_index
;
3304 result
= radv_bo_list_add(device
, mem
->bo
);
3305 if (result
!= VK_SUCCESS
)
3308 *pMem
= radv_device_memory_to_handle(mem
);
3313 device
->ws
->buffer_destroy(mem
->bo
);
3315 vk_free2(&device
->alloc
, pAllocator
, mem
);
3320 VkResult
radv_AllocateMemory(
3322 const VkMemoryAllocateInfo
* pAllocateInfo
,
3323 const VkAllocationCallbacks
* pAllocator
,
3324 VkDeviceMemory
* pMem
)
3326 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3327 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3330 void radv_FreeMemory(
3332 VkDeviceMemory _mem
,
3333 const VkAllocationCallbacks
* pAllocator
)
3335 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3336 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3341 radv_bo_list_remove(device
, mem
->bo
);
3342 device
->ws
->buffer_destroy(mem
->bo
);
3345 vk_free2(&device
->alloc
, pAllocator
, mem
);
3348 VkResult
radv_MapMemory(
3350 VkDeviceMemory _memory
,
3351 VkDeviceSize offset
,
3353 VkMemoryMapFlags flags
,
3356 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3357 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3365 *ppData
= mem
->user_ptr
;
3367 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3374 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3377 void radv_UnmapMemory(
3379 VkDeviceMemory _memory
)
3381 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3382 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3387 if (mem
->user_ptr
== NULL
)
3388 device
->ws
->buffer_unmap(mem
->bo
);
3391 VkResult
radv_FlushMappedMemoryRanges(
3393 uint32_t memoryRangeCount
,
3394 const VkMappedMemoryRange
* pMemoryRanges
)
3399 VkResult
radv_InvalidateMappedMemoryRanges(
3401 uint32_t memoryRangeCount
,
3402 const VkMappedMemoryRange
* pMemoryRanges
)
3407 void radv_GetBufferMemoryRequirements(
3410 VkMemoryRequirements
* pMemoryRequirements
)
3412 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3413 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3415 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3417 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3418 pMemoryRequirements
->alignment
= 4096;
3420 pMemoryRequirements
->alignment
= 16;
3422 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3425 void radv_GetBufferMemoryRequirements2(
3427 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3428 VkMemoryRequirements2
*pMemoryRequirements
)
3430 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3431 &pMemoryRequirements
->memoryRequirements
);
3432 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3433 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3434 switch (ext
->sType
) {
3435 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3436 VkMemoryDedicatedRequirements
*req
=
3437 (VkMemoryDedicatedRequirements
*) ext
;
3438 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3439 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3448 void radv_GetImageMemoryRequirements(
3451 VkMemoryRequirements
* pMemoryRequirements
)
3453 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3454 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3456 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3458 pMemoryRequirements
->size
= image
->size
;
3459 pMemoryRequirements
->alignment
= image
->alignment
;
3462 void radv_GetImageMemoryRequirements2(
3464 const VkImageMemoryRequirementsInfo2
*pInfo
,
3465 VkMemoryRequirements2
*pMemoryRequirements
)
3467 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3468 &pMemoryRequirements
->memoryRequirements
);
3470 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3472 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3473 switch (ext
->sType
) {
3474 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3475 VkMemoryDedicatedRequirements
*req
=
3476 (VkMemoryDedicatedRequirements
*) ext
;
3477 req
->requiresDedicatedAllocation
= image
->shareable
;
3478 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3487 void radv_GetImageSparseMemoryRequirements(
3490 uint32_t* pSparseMemoryRequirementCount
,
3491 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3496 void radv_GetImageSparseMemoryRequirements2(
3498 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3499 uint32_t* pSparseMemoryRequirementCount
,
3500 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3505 void radv_GetDeviceMemoryCommitment(
3507 VkDeviceMemory memory
,
3508 VkDeviceSize
* pCommittedMemoryInBytes
)
3510 *pCommittedMemoryInBytes
= 0;
3513 VkResult
radv_BindBufferMemory2(VkDevice device
,
3514 uint32_t bindInfoCount
,
3515 const VkBindBufferMemoryInfo
*pBindInfos
)
3517 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3518 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3519 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3522 buffer
->bo
= mem
->bo
;
3523 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3531 VkResult
radv_BindBufferMemory(
3534 VkDeviceMemory memory
,
3535 VkDeviceSize memoryOffset
)
3537 const VkBindBufferMemoryInfo info
= {
3538 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3541 .memoryOffset
= memoryOffset
3544 return radv_BindBufferMemory2(device
, 1, &info
);
3547 VkResult
radv_BindImageMemory2(VkDevice device
,
3548 uint32_t bindInfoCount
,
3549 const VkBindImageMemoryInfo
*pBindInfos
)
3551 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3552 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3553 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3556 image
->bo
= mem
->bo
;
3557 image
->offset
= pBindInfos
[i
].memoryOffset
;
3567 VkResult
radv_BindImageMemory(
3570 VkDeviceMemory memory
,
3571 VkDeviceSize memoryOffset
)
3573 const VkBindImageMemoryInfo info
= {
3574 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3577 .memoryOffset
= memoryOffset
3580 return radv_BindImageMemory2(device
, 1, &info
);
3585 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3586 const VkSparseBufferMemoryBindInfo
*bind
)
3588 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3590 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3591 struct radv_device_memory
*mem
= NULL
;
3593 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3594 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3596 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3597 bind
->pBinds
[i
].resourceOffset
,
3598 bind
->pBinds
[i
].size
,
3599 mem
? mem
->bo
: NULL
,
3600 bind
->pBinds
[i
].memoryOffset
);
3605 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3606 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3608 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3610 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3611 struct radv_device_memory
*mem
= NULL
;
3613 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3614 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3616 device
->ws
->buffer_virtual_bind(image
->bo
,
3617 bind
->pBinds
[i
].resourceOffset
,
3618 bind
->pBinds
[i
].size
,
3619 mem
? mem
->bo
: NULL
,
3620 bind
->pBinds
[i
].memoryOffset
);
3624 VkResult
radv_QueueBindSparse(
3626 uint32_t bindInfoCount
,
3627 const VkBindSparseInfo
* pBindInfo
,
3630 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3631 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3632 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3633 bool fence_emitted
= false;
3637 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3638 struct radv_winsys_sem_info sem_info
;
3639 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3640 radv_sparse_buffer_bind_memory(queue
->device
,
3641 pBindInfo
[i
].pBufferBinds
+ j
);
3644 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3645 radv_sparse_image_opaque_bind_memory(queue
->device
,
3646 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3650 result
= radv_alloc_sem_info(queue
->device
->instance
,
3652 pBindInfo
[i
].waitSemaphoreCount
,
3653 pBindInfo
[i
].pWaitSemaphores
,
3654 pBindInfo
[i
].signalSemaphoreCount
,
3655 pBindInfo
[i
].pSignalSemaphores
,
3657 if (result
!= VK_SUCCESS
)
3660 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3661 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3662 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3667 radv_loge("failed to submit CS %d\n", i
);
3671 fence_emitted
= true;
3674 radv_free_sem_info(&sem_info
);
3679 if (!fence_emitted
) {
3680 result
= radv_signal_fence(queue
, fence
);
3681 if (result
!= VK_SUCCESS
)
3689 VkResult
radv_CreateFence(
3691 const VkFenceCreateInfo
* pCreateInfo
,
3692 const VkAllocationCallbacks
* pAllocator
,
3695 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3696 const VkExportFenceCreateInfo
*export
=
3697 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3698 VkExternalFenceHandleTypeFlags handleTypes
=
3699 export
? export
->handleTypes
: 0;
3701 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3703 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3706 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3708 fence
->fence_wsi
= NULL
;
3709 fence
->temp_syncobj
= 0;
3710 if (device
->always_use_syncobj
|| handleTypes
) {
3711 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3713 vk_free2(&device
->alloc
, pAllocator
, fence
);
3714 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3716 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3717 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3719 fence
->fence
= NULL
;
3721 fence
->fence
= device
->ws
->create_fence();
3722 if (!fence
->fence
) {
3723 vk_free2(&device
->alloc
, pAllocator
, fence
);
3724 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3727 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3728 device
->ws
->signal_fence(fence
->fence
);
3731 *pFence
= radv_fence_to_handle(fence
);
3736 void radv_DestroyFence(
3739 const VkAllocationCallbacks
* pAllocator
)
3741 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3742 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3747 if (fence
->temp_syncobj
)
3748 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3750 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3752 device
->ws
->destroy_fence(fence
->fence
);
3753 if (fence
->fence_wsi
)
3754 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3755 vk_free2(&device
->alloc
, pAllocator
, fence
);
3759 uint64_t radv_get_current_time(void)
3762 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3763 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3766 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3768 uint64_t current_time
= radv_get_current_time();
3770 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3772 return current_time
+ timeout
;
3776 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
3777 uint32_t fenceCount
, const VkFence
*pFences
)
3779 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3780 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3781 if (fence
->fence
== NULL
|| fence
->syncobj
||
3782 fence
->temp_syncobj
|| fence
->fence_wsi
||
3783 (!device
->ws
->is_fence_waitable(fence
->fence
)))
3789 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3791 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3792 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3793 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3799 VkResult
radv_WaitForFences(
3801 uint32_t fenceCount
,
3802 const VkFence
* pFences
,
3806 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3807 timeout
= radv_get_absolute_timeout(timeout
);
3809 if (device
->always_use_syncobj
&&
3810 radv_all_fences_syncobj(fenceCount
, pFences
))
3812 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3814 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3816 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3817 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3818 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3821 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3824 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3827 if (!waitAll
&& fenceCount
> 1) {
3828 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3829 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
3830 uint32_t wait_count
= 0;
3831 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3833 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3835 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3836 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3838 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
3843 fences
[wait_count
++] = fence
->fence
;
3846 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3847 waitAll
, timeout
- radv_get_current_time());
3850 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3853 while(radv_get_current_time() <= timeout
) {
3854 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3855 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3862 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3863 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3864 bool expired
= false;
3866 if (fence
->temp_syncobj
) {
3867 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3872 if (fence
->syncobj
) {
3873 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3879 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
3880 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
3881 radv_get_current_time() <= timeout
)
3885 expired
= device
->ws
->fence_wait(device
->ws
,
3892 if (fence
->fence_wsi
) {
3893 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3894 if (result
!= VK_SUCCESS
)
3902 VkResult
radv_ResetFences(VkDevice _device
,
3903 uint32_t fenceCount
,
3904 const VkFence
*pFences
)
3906 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3908 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3909 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3911 device
->ws
->reset_fence(fence
->fence
);
3913 /* Per spec, we first restore the permanent payload, and then reset, so
3914 * having a temp syncobj should not skip resetting the permanent syncobj. */
3915 if (fence
->temp_syncobj
) {
3916 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3917 fence
->temp_syncobj
= 0;
3920 if (fence
->syncobj
) {
3921 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3928 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3930 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3931 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3933 if (fence
->temp_syncobj
) {
3934 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3935 return success
? VK_SUCCESS
: VK_NOT_READY
;
3938 if (fence
->syncobj
) {
3939 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3940 return success
? VK_SUCCESS
: VK_NOT_READY
;
3944 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3945 return VK_NOT_READY
;
3947 if (fence
->fence_wsi
) {
3948 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
3950 if (result
!= VK_SUCCESS
) {
3951 if (result
== VK_TIMEOUT
)
3952 return VK_NOT_READY
;
3960 // Queue semaphore functions
3962 VkResult
radv_CreateSemaphore(
3964 const VkSemaphoreCreateInfo
* pCreateInfo
,
3965 const VkAllocationCallbacks
* pAllocator
,
3966 VkSemaphore
* pSemaphore
)
3968 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3969 const VkExportSemaphoreCreateInfo
*export
=
3970 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
3971 VkExternalSemaphoreHandleTypeFlags handleTypes
=
3972 export
? export
->handleTypes
: 0;
3974 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3976 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3978 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3980 sem
->temp_syncobj
= 0;
3981 /* create a syncobject if we are going to export this semaphore */
3982 if (device
->always_use_syncobj
|| handleTypes
) {
3983 assert (device
->physical_device
->rad_info
.has_syncobj
);
3984 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3986 vk_free2(&device
->alloc
, pAllocator
, sem
);
3987 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3991 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3993 vk_free2(&device
->alloc
, pAllocator
, sem
);
3994 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3999 *pSemaphore
= radv_semaphore_to_handle(sem
);
4003 void radv_DestroySemaphore(
4005 VkSemaphore _semaphore
,
4006 const VkAllocationCallbacks
* pAllocator
)
4008 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4009 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4014 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4016 device
->ws
->destroy_sem(sem
->sem
);
4017 vk_free2(&device
->alloc
, pAllocator
, sem
);
4020 VkResult
radv_CreateEvent(
4022 const VkEventCreateInfo
* pCreateInfo
,
4023 const VkAllocationCallbacks
* pAllocator
,
4026 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4027 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4029 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4032 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4034 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4036 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4037 RADV_BO_PRIORITY_FENCE
);
4039 vk_free2(&device
->alloc
, pAllocator
, event
);
4040 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4043 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4045 *pEvent
= radv_event_to_handle(event
);
4050 void radv_DestroyEvent(
4053 const VkAllocationCallbacks
* pAllocator
)
4055 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4056 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4060 device
->ws
->buffer_destroy(event
->bo
);
4061 vk_free2(&device
->alloc
, pAllocator
, event
);
4064 VkResult
radv_GetEventStatus(
4068 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4070 if (*event
->map
== 1)
4071 return VK_EVENT_SET
;
4072 return VK_EVENT_RESET
;
4075 VkResult
radv_SetEvent(
4079 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4085 VkResult
radv_ResetEvent(
4089 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4095 VkResult
radv_CreateBuffer(
4097 const VkBufferCreateInfo
* pCreateInfo
,
4098 const VkAllocationCallbacks
* pAllocator
,
4101 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4102 struct radv_buffer
*buffer
;
4104 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4106 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4107 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4109 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4111 buffer
->size
= pCreateInfo
->size
;
4112 buffer
->usage
= pCreateInfo
->usage
;
4115 buffer
->flags
= pCreateInfo
->flags
;
4117 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4118 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4120 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4121 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4122 align64(buffer
->size
, 4096),
4123 4096, 0, RADEON_FLAG_VIRTUAL
,
4124 RADV_BO_PRIORITY_VIRTUAL
);
4126 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4127 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4131 *pBuffer
= radv_buffer_to_handle(buffer
);
4136 void radv_DestroyBuffer(
4139 const VkAllocationCallbacks
* pAllocator
)
4141 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4142 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4147 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4148 device
->ws
->buffer_destroy(buffer
->bo
);
4150 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4153 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4155 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4157 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4158 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4162 static inline unsigned
4163 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4166 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4168 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4171 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4173 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4177 radv_init_dcc_control_reg(struct radv_device
*device
,
4178 struct radv_image_view
*iview
)
4180 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4181 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4182 unsigned max_compressed_block_size
;
4183 unsigned independent_64b_blocks
;
4185 if (!radv_image_has_dcc(iview
->image
))
4188 if (iview
->image
->info
.samples
> 1) {
4189 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4190 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4191 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4192 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4195 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4196 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4197 * dGPU and 64 for APU because all of our APUs to date use
4198 * DIMMs which have a request granularity size of 64B while all
4199 * other chips have a 32B request size.
4201 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4204 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4205 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4206 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4207 /* If this DCC image is potentially going to be used in texture
4208 * fetches, we need some special settings.
4210 independent_64b_blocks
= 1;
4211 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4213 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4214 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4215 * big as possible for better compression state.
4217 independent_64b_blocks
= 0;
4218 max_compressed_block_size
= max_uncompressed_block_size
;
4221 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4222 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4223 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4224 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
4228 radv_initialise_color_surface(struct radv_device
*device
,
4229 struct radv_color_buffer_info
*cb
,
4230 struct radv_image_view
*iview
)
4232 const struct vk_format_description
*desc
;
4233 unsigned ntype
, format
, swap
, endian
;
4234 unsigned blend_clamp
= 0, blend_bypass
= 0;
4236 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4237 const struct radeon_surf
*surf
= &plane
->surface
;
4239 desc
= vk_format_description(iview
->vk_format
);
4241 memset(cb
, 0, sizeof(*cb
));
4243 /* Intensity is implemented as Red, so treat it that way. */
4244 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4246 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4248 cb
->cb_color_base
= va
>> 8;
4250 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4251 struct gfx9_surf_meta_flags meta
;
4252 if (iview
->image
->dcc_offset
)
4253 meta
= surf
->u
.gfx9
.dcc
;
4255 meta
= surf
->u
.gfx9
.cmask
;
4257 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4258 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4259 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4260 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4262 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4263 cb
->cb_color_base
|= surf
->tile_swizzle
;
4265 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4267 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4268 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4270 cb
->cb_color_base
+= level_info
->offset
>> 8;
4271 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4272 cb
->cb_color_base
|= surf
->tile_swizzle
;
4274 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4275 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4276 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4278 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4279 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4280 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
4282 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4284 if (radv_image_has_fmask(iview
->image
)) {
4285 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4286 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
4287 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4288 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4290 /* This must be set for fast clear to work without FMASK. */
4291 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4292 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4293 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4294 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4298 /* CMASK variables */
4299 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4300 va
+= iview
->image
->cmask
.offset
;
4301 cb
->cb_color_cmask
= va
>> 8;
4303 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4304 va
+= iview
->image
->dcc_offset
;
4305 cb
->cb_dcc_base
= va
>> 8;
4306 cb
->cb_dcc_base
|= surf
->tile_swizzle
;
4308 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4309 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4310 S_028C6C_SLICE_MAX(max_slice
);
4312 if (iview
->image
->info
.samples
> 1) {
4313 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4315 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4316 S_028C74_NUM_FRAGMENTS(log_samples
);
4319 if (radv_image_has_fmask(iview
->image
)) {
4320 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4321 cb
->cb_color_fmask
= va
>> 8;
4322 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4324 cb
->cb_color_fmask
= cb
->cb_color_base
;
4327 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4329 vk_format_get_first_non_void_channel(iview
->vk_format
));
4330 format
= radv_translate_colorformat(iview
->vk_format
);
4331 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4332 radv_finishme("Illegal color\n");
4333 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4334 endian
= radv_colorformat_endian_swap(format
);
4336 /* blend clamp should be set for all NORM/SRGB types */
4337 if (ntype
== V_028C70_NUMBER_UNORM
||
4338 ntype
== V_028C70_NUMBER_SNORM
||
4339 ntype
== V_028C70_NUMBER_SRGB
)
4342 /* set blend bypass according to docs if SINT/UINT or
4343 8/24 COLOR variants */
4344 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4345 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4346 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4351 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4352 (format
== V_028C70_COLOR_8
||
4353 format
== V_028C70_COLOR_8_8
||
4354 format
== V_028C70_COLOR_8_8_8_8
))
4355 ->color_is_int8
= true;
4357 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4358 S_028C70_COMP_SWAP(swap
) |
4359 S_028C70_BLEND_CLAMP(blend_clamp
) |
4360 S_028C70_BLEND_BYPASS(blend_bypass
) |
4361 S_028C70_SIMPLE_FLOAT(1) |
4362 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4363 ntype
!= V_028C70_NUMBER_SNORM
&&
4364 ntype
!= V_028C70_NUMBER_SRGB
&&
4365 format
!= V_028C70_COLOR_8_24
&&
4366 format
!= V_028C70_COLOR_24_8
) |
4367 S_028C70_NUMBER_TYPE(ntype
) |
4368 S_028C70_ENDIAN(endian
);
4369 if (radv_image_has_fmask(iview
->image
)) {
4370 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4371 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4372 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4373 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4377 if (radv_image_has_cmask(iview
->image
) &&
4378 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4379 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4381 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4382 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4384 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4386 /* This must be set for fast clear to work without FMASK. */
4387 if (!radv_image_has_fmask(iview
->image
) &&
4388 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4389 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4390 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4393 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4394 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4396 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4397 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4398 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4399 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4401 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
4402 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4403 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4404 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4405 S_028C68_MIP0_HEIGHT(height
- 1) |
4406 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4411 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4412 struct radv_image_view
*iview
)
4414 unsigned max_zplanes
= 0;
4416 assert(radv_image_is_tc_compat_htile(iview
->image
));
4418 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4419 /* Default value for 32-bit depth surfaces. */
4422 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4423 iview
->image
->info
.samples
> 1)
4426 max_zplanes
= max_zplanes
+ 1;
4428 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4429 /* Do not enable Z plane compression for 16-bit depth
4430 * surfaces because isn't supported on GFX8. Only
4431 * 32-bit depth surfaces are supported by the hardware.
4432 * This allows to maintain shader compatibility and to
4433 * reduce the number of depth decompressions.
4437 if (iview
->image
->info
.samples
<= 1)
4439 else if (iview
->image
->info
.samples
<= 4)
4450 radv_initialise_ds_surface(struct radv_device
*device
,
4451 struct radv_ds_buffer_info
*ds
,
4452 struct radv_image_view
*iview
)
4454 unsigned level
= iview
->base_mip
;
4455 unsigned format
, stencil_format
;
4456 uint64_t va
, s_offs
, z_offs
;
4457 bool stencil_only
= false;
4458 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4459 const struct radeon_surf
*surf
= &plane
->surface
;
4461 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4463 memset(ds
, 0, sizeof(*ds
));
4464 switch (iview
->image
->vk_format
) {
4465 case VK_FORMAT_D24_UNORM_S8_UINT
:
4466 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4467 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4468 ds
->offset_scale
= 2.0f
;
4470 case VK_FORMAT_D16_UNORM
:
4471 case VK_FORMAT_D16_UNORM_S8_UINT
:
4472 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4473 ds
->offset_scale
= 4.0f
;
4475 case VK_FORMAT_D32_SFLOAT
:
4476 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4477 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4478 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4479 ds
->offset_scale
= 1.0f
;
4481 case VK_FORMAT_S8_UINT
:
4482 stencil_only
= true;
4488 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4489 stencil_format
= surf
->has_stencil
?
4490 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4492 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4493 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4494 S_028008_SLICE_MAX(max_slice
);
4496 ds
->db_htile_data_base
= 0;
4497 ds
->db_htile_surface
= 0;
4499 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4500 s_offs
= z_offs
= va
;
4502 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4503 assert(surf
->u
.gfx9
.surf_offset
== 0);
4504 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4506 ds
->db_z_info
= S_028038_FORMAT(format
) |
4507 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4508 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4509 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4510 S_028038_ZRANGE_PRECISION(1);
4511 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4512 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4514 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4515 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4516 ds
->db_depth_view
|= S_028008_MIPID(level
);
4518 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4519 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4521 if (radv_htile_enabled(iview
->image
, level
)) {
4522 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4524 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4525 unsigned max_zplanes
=
4526 radv_calc_decompress_on_z_planes(device
, iview
);
4528 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4529 S_028038_ITERATE_FLUSH(1);
4530 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4533 if (!surf
->has_stencil
)
4534 /* Use all of the htile_buffer for depth if there's no stencil. */
4535 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4536 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4537 iview
->image
->htile_offset
;
4538 ds
->db_htile_data_base
= va
>> 8;
4539 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4540 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
) |
4541 S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4544 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4547 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4549 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4550 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4552 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4553 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4554 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4556 if (iview
->image
->info
.samples
> 1)
4557 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4559 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4560 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4561 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4562 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4563 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4564 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4565 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4566 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4569 tile_mode
= stencil_tile_mode
;
4571 ds
->db_depth_info
|=
4572 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4573 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4574 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4575 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4576 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4577 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4578 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4579 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4581 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4582 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4583 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4584 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4586 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4589 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4590 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4591 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4593 if (radv_htile_enabled(iview
->image
, level
)) {
4594 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4596 if (!surf
->has_stencil
&&
4597 !radv_image_is_tc_compat_htile(iview
->image
))
4598 /* Use all of the htile_buffer for depth if there's no stencil. */
4599 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4601 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4602 iview
->image
->htile_offset
;
4603 ds
->db_htile_data_base
= va
>> 8;
4604 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4606 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4607 unsigned max_zplanes
=
4608 radv_calc_decompress_on_z_planes(device
, iview
);
4610 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4611 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4616 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4617 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4620 VkResult
radv_CreateFramebuffer(
4622 const VkFramebufferCreateInfo
* pCreateInfo
,
4623 const VkAllocationCallbacks
* pAllocator
,
4624 VkFramebuffer
* pFramebuffer
)
4626 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4627 struct radv_framebuffer
*framebuffer
;
4629 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4631 size_t size
= sizeof(*framebuffer
) +
4632 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4633 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4634 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4635 if (framebuffer
== NULL
)
4636 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4638 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4639 framebuffer
->width
= pCreateInfo
->width
;
4640 framebuffer
->height
= pCreateInfo
->height
;
4641 framebuffer
->layers
= pCreateInfo
->layers
;
4642 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4643 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4644 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4645 framebuffer
->attachments
[i
].attachment
= iview
;
4646 if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4647 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4649 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4651 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4652 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4653 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4656 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4660 void radv_DestroyFramebuffer(
4663 const VkAllocationCallbacks
* pAllocator
)
4665 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4666 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4670 vk_free2(&device
->alloc
, pAllocator
, fb
);
4673 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4675 switch (address_mode
) {
4676 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4677 return V_008F30_SQ_TEX_WRAP
;
4678 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4679 return V_008F30_SQ_TEX_MIRROR
;
4680 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4681 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4682 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4683 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4684 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4685 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4687 unreachable("illegal tex wrap mode");
4693 radv_tex_compare(VkCompareOp op
)
4696 case VK_COMPARE_OP_NEVER
:
4697 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4698 case VK_COMPARE_OP_LESS
:
4699 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4700 case VK_COMPARE_OP_EQUAL
:
4701 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4702 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4703 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4704 case VK_COMPARE_OP_GREATER
:
4705 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4706 case VK_COMPARE_OP_NOT_EQUAL
:
4707 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4708 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4709 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4710 case VK_COMPARE_OP_ALWAYS
:
4711 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4713 unreachable("illegal compare mode");
4719 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4722 case VK_FILTER_NEAREST
:
4723 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4724 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4725 case VK_FILTER_LINEAR
:
4726 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4727 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4728 case VK_FILTER_CUBIC_IMG
:
4730 fprintf(stderr
, "illegal texture filter");
4736 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4739 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4740 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4741 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4742 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4744 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4749 radv_tex_bordercolor(VkBorderColor bcolor
)
4752 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4753 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4754 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4755 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4756 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4757 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4758 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4759 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4760 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4768 radv_tex_aniso_filter(unsigned filter
)
4782 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4785 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4786 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4787 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4788 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
4789 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4790 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
4798 radv_get_max_anisotropy(struct radv_device
*device
,
4799 const VkSamplerCreateInfo
*pCreateInfo
)
4801 if (device
->force_aniso
>= 0)
4802 return device
->force_aniso
;
4804 if (pCreateInfo
->anisotropyEnable
&&
4805 pCreateInfo
->maxAnisotropy
> 1.0f
)
4806 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4812 radv_init_sampler(struct radv_device
*device
,
4813 struct radv_sampler
*sampler
,
4814 const VkSamplerCreateInfo
*pCreateInfo
)
4816 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4817 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4818 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= GFX8
);
4819 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4821 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4822 vk_find_struct_const(pCreateInfo
->pNext
,
4823 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4824 if (sampler_reduction
)
4825 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4827 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4828 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4829 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4830 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4831 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4832 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4833 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4834 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4835 S_008F30_DISABLE_CUBE_WRAP(0) |
4836 S_008F30_COMPAT_MODE(is_vi
) |
4837 S_008F30_FILTER_MODE(filter_mode
));
4838 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4839 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4840 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4841 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4842 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4843 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4844 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4845 S_008F38_MIP_POINT_PRECLAMP(0) |
4846 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
4847 S_008F38_FILTER_PREC_FIX(1) |
4848 S_008F38_ANISO_OVERRIDE(is_vi
));
4849 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4850 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4853 VkResult
radv_CreateSampler(
4855 const VkSamplerCreateInfo
* pCreateInfo
,
4856 const VkAllocationCallbacks
* pAllocator
,
4857 VkSampler
* pSampler
)
4859 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4860 struct radv_sampler
*sampler
;
4862 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
4863 vk_find_struct_const(pCreateInfo
->pNext
,
4864 SAMPLER_YCBCR_CONVERSION_INFO
);
4866 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4868 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4869 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4871 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4873 radv_init_sampler(device
, sampler
, pCreateInfo
);
4875 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
4876 *pSampler
= radv_sampler_to_handle(sampler
);
4881 void radv_DestroySampler(
4884 const VkAllocationCallbacks
* pAllocator
)
4886 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4887 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4891 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4894 /* vk_icd.h does not declare this function, so we declare it here to
4895 * suppress Wmissing-prototypes.
4897 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4898 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4900 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4901 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4903 /* For the full details on loader interface versioning, see
4904 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4905 * What follows is a condensed summary, to help you navigate the large and
4906 * confusing official doc.
4908 * - Loader interface v0 is incompatible with later versions. We don't
4911 * - In loader interface v1:
4912 * - The first ICD entrypoint called by the loader is
4913 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4915 * - The ICD must statically expose no other Vulkan symbol unless it is
4916 * linked with -Bsymbolic.
4917 * - Each dispatchable Vulkan handle created by the ICD must be
4918 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4919 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4920 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4921 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4922 * such loader-managed surfaces.
4924 * - Loader interface v2 differs from v1 in:
4925 * - The first ICD entrypoint called by the loader is
4926 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4927 * statically expose this entrypoint.
4929 * - Loader interface v3 differs from v2 in:
4930 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4931 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4932 * because the loader no longer does so.
4934 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
4938 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4939 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4942 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4943 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4945 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4947 /* At the moment, we support only the below handle types. */
4948 assert(pGetFdInfo
->handleType
==
4949 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
4950 pGetFdInfo
->handleType
==
4951 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4953 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4955 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4959 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4960 VkExternalMemoryHandleTypeFlagBits handleType
,
4962 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4964 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4966 switch (handleType
) {
4967 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4968 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4972 /* The valid usage section for this function says:
4974 * "handleType must not be one of the handle types defined as
4977 * So opaque handle types fall into the default "unsupported" case.
4979 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4983 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4987 uint32_t syncobj_handle
= 0;
4988 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4990 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4993 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4995 *syncobj
= syncobj_handle
;
5001 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5005 /* If we create a syncobj we do it locally so that if we have an error, we don't
5006 * leave a syncobj in an undetermined state in the fence. */
5007 uint32_t syncobj_handle
= *syncobj
;
5008 if (!syncobj_handle
) {
5009 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5011 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5016 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5018 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5020 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5023 *syncobj
= syncobj_handle
;
5030 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5031 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5033 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5034 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5035 uint32_t *syncobj_dst
= NULL
;
5037 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5038 syncobj_dst
= &sem
->temp_syncobj
;
5040 syncobj_dst
= &sem
->syncobj
;
5043 switch(pImportSemaphoreFdInfo
->handleType
) {
5044 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5045 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5046 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5047 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5049 unreachable("Unhandled semaphore handle type");
5053 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5054 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5057 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5058 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5060 uint32_t syncobj_handle
;
5062 if (sem
->temp_syncobj
)
5063 syncobj_handle
= sem
->temp_syncobj
;
5065 syncobj_handle
= sem
->syncobj
;
5067 switch(pGetFdInfo
->handleType
) {
5068 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5069 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5071 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5072 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5074 if (sem
->temp_syncobj
) {
5075 close (sem
->temp_syncobj
);
5076 sem
->temp_syncobj
= 0;
5078 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5083 unreachable("Unhandled semaphore handle type");
5087 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5091 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5092 VkPhysicalDevice physicalDevice
,
5093 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5094 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5096 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5098 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5099 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5100 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5101 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5102 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5103 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5104 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5105 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5106 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5107 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5108 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5109 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5110 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5112 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5113 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5114 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5118 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5119 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5121 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5122 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5123 uint32_t *syncobj_dst
= NULL
;
5126 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5127 syncobj_dst
= &fence
->temp_syncobj
;
5129 syncobj_dst
= &fence
->syncobj
;
5132 switch(pImportFenceFdInfo
->handleType
) {
5133 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5134 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5135 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5136 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5138 unreachable("Unhandled fence handle type");
5142 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5143 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5146 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5147 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5149 uint32_t syncobj_handle
;
5151 if (fence
->temp_syncobj
)
5152 syncobj_handle
= fence
->temp_syncobj
;
5154 syncobj_handle
= fence
->syncobj
;
5156 switch(pGetFdInfo
->handleType
) {
5157 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5158 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5160 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5161 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5163 if (fence
->temp_syncobj
) {
5164 close (fence
->temp_syncobj
);
5165 fence
->temp_syncobj
= 0;
5167 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5172 unreachable("Unhandled fence handle type");
5176 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5180 void radv_GetPhysicalDeviceExternalFenceProperties(
5181 VkPhysicalDevice physicalDevice
,
5182 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5183 VkExternalFenceProperties
*pExternalFenceProperties
)
5185 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5187 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5188 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5189 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5190 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5191 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5192 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5193 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5195 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5196 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5197 pExternalFenceProperties
->externalFenceFeatures
= 0;
5202 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5203 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5204 const VkAllocationCallbacks
* pAllocator
,
5205 VkDebugReportCallbackEXT
* pCallback
)
5207 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5208 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5209 pCreateInfo
, pAllocator
, &instance
->alloc
,
5214 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5215 VkDebugReportCallbackEXT _callback
,
5216 const VkAllocationCallbacks
* pAllocator
)
5218 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5219 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5220 _callback
, pAllocator
, &instance
->alloc
);
5224 radv_DebugReportMessageEXT(VkInstance _instance
,
5225 VkDebugReportFlagsEXT flags
,
5226 VkDebugReportObjectTypeEXT objectType
,
5229 int32_t messageCode
,
5230 const char* pLayerPrefix
,
5231 const char* pMessage
)
5233 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5234 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5235 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5239 radv_GetDeviceGroupPeerMemoryFeatures(
5242 uint32_t localDeviceIndex
,
5243 uint32_t remoteDeviceIndex
,
5244 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5246 assert(localDeviceIndex
== remoteDeviceIndex
);
5248 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5249 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5250 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5251 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5254 static const VkTimeDomainEXT radv_time_domains
[] = {
5255 VK_TIME_DOMAIN_DEVICE_EXT
,
5256 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5257 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5260 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5261 VkPhysicalDevice physicalDevice
,
5262 uint32_t *pTimeDomainCount
,
5263 VkTimeDomainEXT
*pTimeDomains
)
5266 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5268 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5269 vk_outarray_append(&out
, i
) {
5270 *i
= radv_time_domains
[d
];
5274 return vk_outarray_status(&out
);
5278 radv_clock_gettime(clockid_t clock_id
)
5280 struct timespec current
;
5283 ret
= clock_gettime(clock_id
, ¤t
);
5284 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5285 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5289 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5292 VkResult
radv_GetCalibratedTimestampsEXT(
5294 uint32_t timestampCount
,
5295 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5296 uint64_t *pTimestamps
,
5297 uint64_t *pMaxDeviation
)
5299 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5300 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5302 uint64_t begin
, end
;
5303 uint64_t max_clock_period
= 0;
5305 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5307 for (d
= 0; d
< timestampCount
; d
++) {
5308 switch (pTimestampInfos
[d
].timeDomain
) {
5309 case VK_TIME_DOMAIN_DEVICE_EXT
:
5310 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5312 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5313 max_clock_period
= MAX2(max_clock_period
, device_period
);
5315 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5316 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5317 max_clock_period
= MAX2(max_clock_period
, 1);
5320 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5321 pTimestamps
[d
] = begin
;
5329 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5332 * The maximum deviation is the sum of the interval over which we
5333 * perform the sampling and the maximum period of any sampled
5334 * clock. That's because the maximum skew between any two sampled
5335 * clock edges is when the sampled clock with the largest period is
5336 * sampled at the end of that period but right at the beginning of the
5337 * sampling interval and some other clock is sampled right at the
5338 * begining of its sampling period and right at the end of the
5339 * sampling interval. Let's assume the GPU has the longest clock
5340 * period and that the application is sampling GPU and monotonic:
5343 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5344 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5348 * GPU -----_____-----_____-----_____-----_____
5351 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5352 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5354 * Interval <----------------->
5355 * Deviation <-------------------------->
5359 * m = read(monotonic) 2
5362 * We round the sample interval up by one tick to cover sampling error
5363 * in the interval clock
5366 uint64_t sample_interval
= end
- begin
+ 1;
5368 *pMaxDeviation
= sample_interval
+ max_clock_period
;