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"
47 #include "util/build_id.h"
48 #include "util/debug.h"
49 #include "util/mesa-sha1.h"
50 #include "compiler/glsl_types.h"
51 #include "util/xmlpool.h"
54 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
57 unsigned char sha1
[20];
58 unsigned ptr_size
= sizeof(void*);
60 memset(uuid
, 0, VK_UUID_SIZE
);
61 _mesa_sha1_init(&ctx
);
63 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
64 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
67 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
68 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
69 _mesa_sha1_final(&ctx
, sha1
);
71 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
76 radv_get_driver_uuid(void *uuid
)
78 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
82 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
84 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
88 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
90 const char *chip_string
;
93 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
94 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
95 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
96 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
97 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
98 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
99 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
100 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
101 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
102 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
103 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
104 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
105 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
106 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
107 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
108 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
109 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
110 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
111 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
112 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
113 case CHIP_VEGA20
: chip_string
= "AMD RADV VEGA20"; break;
114 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
115 case CHIP_RAVEN2
: chip_string
= "AMD RADV RAVEN2"; break;
116 default: chip_string
= "AMD RADV unknown"; break;
119 snprintf(name
, name_len
, "%s (LLVM " MESA_LLVM_VERSION_STRING
")", chip_string
);
123 radv_get_visible_vram_size(struct radv_physical_device
*device
)
125 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
129 radv_get_vram_size(struct radv_physical_device
*device
)
131 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
135 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
137 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
138 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
139 uint64_t vram_size
= radv_get_vram_size(device
);
140 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
141 device
->memory_properties
.memoryHeapCount
= 0;
143 vram_index
= device
->memory_properties
.memoryHeapCount
++;
144 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
146 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
149 if (visible_vram_size
) {
150 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
151 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
152 .size
= visible_vram_size
,
153 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
156 if (device
->rad_info
.gart_size
> 0) {
157 gart_index
= device
->memory_properties
.memoryHeapCount
++;
158 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
159 .size
= device
->rad_info
.gart_size
,
160 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
164 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
165 unsigned type_count
= 0;
166 if (vram_index
>= 0) {
167 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
168 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
169 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
170 .heapIndex
= vram_index
,
173 if (gart_index
>= 0) {
174 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
175 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
176 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
177 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
178 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
179 .heapIndex
= gart_index
,
182 if (visible_vram_index
>= 0) {
183 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
184 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
185 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
186 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
187 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
188 .heapIndex
= visible_vram_index
,
191 if (gart_index
>= 0) {
192 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
193 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
194 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
195 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
196 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
197 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
198 .heapIndex
= gart_index
,
201 device
->memory_properties
.memoryTypeCount
= type_count
;
205 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
207 const char *family
= getenv("RADV_FORCE_FAMILY");
213 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
214 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
215 /* Override family and chip_class. */
216 device
->rad_info
.family
= i
;
218 if (i
>= CHIP_VEGA10
)
219 device
->rad_info
.chip_class
= GFX9
;
220 else if (i
>= CHIP_TONGA
)
221 device
->rad_info
.chip_class
= GFX8
;
222 else if (i
>= CHIP_BONAIRE
)
223 device
->rad_info
.chip_class
= GFX7
;
225 device
->rad_info
.chip_class
= GFX6
;
231 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
236 radv_physical_device_init(struct radv_physical_device
*device
,
237 struct radv_instance
*instance
,
238 drmDevicePtr drm_device
)
240 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
242 drmVersionPtr version
;
246 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
248 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
249 radv_logi("Could not open device '%s'", path
);
251 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
254 version
= drmGetVersion(fd
);
258 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
259 radv_logi("Could not get the kernel driver version for device '%s'", path
);
261 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
262 "failed to get version %s: %m", path
);
265 if (strcmp(version
->name
, "amdgpu")) {
266 drmFreeVersion(version
);
269 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
270 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
272 return VK_ERROR_INCOMPATIBLE_DRIVER
;
274 drmFreeVersion(version
);
276 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
277 radv_logi("Found compatible device '%s'.", path
);
279 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
280 device
->instance
= instance
;
282 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
283 instance
->perftest_flags
);
285 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
289 if (instance
->enabled_extensions
.KHR_display
) {
290 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
291 if (master_fd
>= 0) {
292 uint32_t accel_working
= 0;
293 struct drm_amdgpu_info request
= {
294 .return_pointer
= (uintptr_t)&accel_working
,
295 .return_size
= sizeof(accel_working
),
296 .query
= AMDGPU_INFO_ACCEL_WORKING
299 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
306 device
->master_fd
= master_fd
;
307 device
->local_fd
= fd
;
308 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
310 radv_handle_env_var_force_family(device
);
312 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
314 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
315 device
->ws
->destroy(device
->ws
);
316 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
317 "cannot generate UUID");
321 /* These flags affect shader compilation. */
322 uint64_t shader_env_flags
=
323 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
324 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
326 /* The gpu id is already embedded in the uuid so we just pass "radv"
327 * when creating the cache.
329 char buf
[VK_UUID_SIZE
* 2 + 1];
330 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
331 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
333 if (device
->rad_info
.chip_class
< GFX8
||
334 device
->rad_info
.chip_class
> GFX9
)
335 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
337 radv_get_driver_uuid(&device
->driver_uuid
);
338 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
340 if (device
->rad_info
.family
== CHIP_STONEY
||
341 device
->rad_info
.chip_class
>= GFX9
) {
342 device
->has_rbplus
= true;
343 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
344 device
->rad_info
.family
== CHIP_VEGA12
||
345 device
->rad_info
.family
== CHIP_RAVEN
||
346 device
->rad_info
.family
== CHIP_RAVEN2
;
349 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
352 device
->has_clear_state
= device
->rad_info
.chip_class
>= GFX7
;
354 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= GFX8
;
356 /* Vega10/Raven need a special workaround for a hardware bug. */
357 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
358 device
->rad_info
.family
== CHIP_RAVEN
;
360 /* Out-of-order primitive rasterization. */
361 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= GFX8
&&
362 device
->rad_info
.max_se
>= 2;
363 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
364 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
366 device
->dcc_msaa_allowed
=
367 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
369 /* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
370 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
371 (device
->rad_info
.chip_class
>= GFX8
&&
372 device
->rad_info
.me_fw_feature
>= 41);
374 radv_physical_device_init_mem_types(device
);
375 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
377 device
->bus_info
= *drm_device
->businfo
.pci
;
379 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
380 ac_print_gpu_info(&device
->rad_info
);
382 /* The WSI is structured as a layer on top of the driver, so this has
383 * to be the last part of initialization (at least until we get other
386 result
= radv_init_wsi(device
);
387 if (result
!= VK_SUCCESS
) {
388 device
->ws
->destroy(device
->ws
);
389 vk_error(instance
, result
);
403 radv_physical_device_finish(struct radv_physical_device
*device
)
405 radv_finish_wsi(device
);
406 device
->ws
->destroy(device
->ws
);
407 disk_cache_destroy(device
->disk_cache
);
408 close(device
->local_fd
);
409 if (device
->master_fd
!= -1)
410 close(device
->master_fd
);
414 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
415 VkSystemAllocationScope allocationScope
)
421 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
422 size_t align
, VkSystemAllocationScope allocationScope
)
424 return realloc(pOriginal
, size
);
428 default_free_func(void *pUserData
, void *pMemory
)
433 static const VkAllocationCallbacks default_alloc
= {
435 .pfnAllocation
= default_alloc_func
,
436 .pfnReallocation
= default_realloc_func
,
437 .pfnFree
= default_free_func
,
440 static const struct debug_control radv_debug_options
[] = {
441 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
442 {"nodcc", RADV_DEBUG_NO_DCC
},
443 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
444 {"nocache", RADV_DEBUG_NO_CACHE
},
445 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
446 {"nohiz", RADV_DEBUG_NO_HIZ
},
447 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
448 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
449 {"allbos", RADV_DEBUG_ALL_BOS
},
450 {"noibs", RADV_DEBUG_NO_IBS
},
451 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
452 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
453 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
454 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
455 {"nosisched", RADV_DEBUG_NO_SISCHED
},
456 {"preoptir", RADV_DEBUG_PREOPTIR
},
457 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
458 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
459 {"info", RADV_DEBUG_INFO
},
460 {"errors", RADV_DEBUG_ERRORS
},
461 {"startup", RADV_DEBUG_STARTUP
},
462 {"checkir", RADV_DEBUG_CHECKIR
},
463 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
464 {"nobinning", RADV_DEBUG_NOBINNING
},
465 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
470 radv_get_debug_option_name(int id
)
472 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
473 return radv_debug_options
[id
].string
;
476 static const struct debug_control radv_perftest_options
[] = {
477 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
478 {"sisched", RADV_PERFTEST_SISCHED
},
479 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
480 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
481 {"bolist", RADV_PERFTEST_BO_LIST
},
486 radv_get_perftest_option_name(int id
)
488 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
489 return radv_perftest_options
[id
].string
;
493 radv_handle_per_app_options(struct radv_instance
*instance
,
494 const VkApplicationInfo
*info
)
496 const char *name
= info
? info
->pApplicationName
: NULL
;
501 if (!strcmp(name
, "Talos - Linux - 32bit") ||
502 !strcmp(name
, "Talos - Linux - 64bit")) {
503 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
504 /* Force enable LLVM sisched for Talos because it looks
505 * safe and it gives few more FPS.
507 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
509 } else if (!strcmp(name
, "DOOM_VFR")) {
510 /* Work around a Doom VFR game bug */
511 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
512 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
513 /* Workaround for a WaW hazard when LLVM moves/merges
514 * load/store memory operations.
515 * See https://reviews.llvm.org/D61313
517 if (HAVE_LLVM
< 0x900)
518 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
522 static int radv_get_instance_extension_index(const char *name
)
524 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
525 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
531 static const char radv_dri_options_xml
[] =
533 DRI_CONF_SECTION_QUALITY
534 DRI_CONF_ADAPTIVE_SYNC("true")
538 static void radv_init_dri_options(struct radv_instance
*instance
)
540 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
541 driParseConfigFiles(&instance
->dri_options
,
542 &instance
->available_dri_options
,
546 VkResult
radv_CreateInstance(
547 const VkInstanceCreateInfo
* pCreateInfo
,
548 const VkAllocationCallbacks
* pAllocator
,
549 VkInstance
* pInstance
)
551 struct radv_instance
*instance
;
554 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
556 uint32_t client_version
;
557 if (pCreateInfo
->pApplicationInfo
&&
558 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
559 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
561 client_version
= VK_API_VERSION_1_0
;
564 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
565 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
567 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
569 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
572 instance
->alloc
= *pAllocator
;
574 instance
->alloc
= default_alloc
;
576 instance
->apiVersion
= client_version
;
577 instance
->physicalDeviceCount
= -1;
579 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
582 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
583 radv_perftest_options
);
586 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
587 radv_logi("Created an instance");
589 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
590 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
591 int index
= radv_get_instance_extension_index(ext_name
);
593 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
594 vk_free2(&default_alloc
, pAllocator
, instance
);
595 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
598 instance
->enabled_extensions
.extensions
[index
] = true;
601 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
602 if (result
!= VK_SUCCESS
) {
603 vk_free2(&default_alloc
, pAllocator
, instance
);
604 return vk_error(instance
, result
);
608 glsl_type_singleton_init_or_ref();
610 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
612 radv_init_dri_options(instance
);
613 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
615 *pInstance
= radv_instance_to_handle(instance
);
620 void radv_DestroyInstance(
621 VkInstance _instance
,
622 const VkAllocationCallbacks
* pAllocator
)
624 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
629 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
630 radv_physical_device_finish(instance
->physicalDevices
+ i
);
633 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
635 glsl_type_singleton_decref();
638 driDestroyOptionCache(&instance
->dri_options
);
639 driDestroyOptionInfo(&instance
->available_dri_options
);
641 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
643 vk_free(&instance
->alloc
, instance
);
647 radv_enumerate_devices(struct radv_instance
*instance
)
649 /* TODO: Check for more devices ? */
650 drmDevicePtr devices
[8];
651 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
654 instance
->physicalDeviceCount
= 0;
656 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
658 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
659 radv_logi("Found %d drm nodes", max_devices
);
662 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
664 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
665 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
666 devices
[i
]->bustype
== DRM_BUS_PCI
&&
667 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
669 result
= radv_physical_device_init(instance
->physicalDevices
+
670 instance
->physicalDeviceCount
,
673 if (result
== VK_SUCCESS
)
674 ++instance
->physicalDeviceCount
;
675 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
679 drmFreeDevices(devices
, max_devices
);
684 VkResult
radv_EnumeratePhysicalDevices(
685 VkInstance _instance
,
686 uint32_t* pPhysicalDeviceCount
,
687 VkPhysicalDevice
* pPhysicalDevices
)
689 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
692 if (instance
->physicalDeviceCount
< 0) {
693 result
= radv_enumerate_devices(instance
);
694 if (result
!= VK_SUCCESS
&&
695 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
699 if (!pPhysicalDevices
) {
700 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
702 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
703 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
704 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
707 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
711 VkResult
radv_EnumeratePhysicalDeviceGroups(
712 VkInstance _instance
,
713 uint32_t* pPhysicalDeviceGroupCount
,
714 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
716 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
719 if (instance
->physicalDeviceCount
< 0) {
720 result
= radv_enumerate_devices(instance
);
721 if (result
!= VK_SUCCESS
&&
722 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
726 if (!pPhysicalDeviceGroupProperties
) {
727 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
729 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
730 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
731 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
732 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
733 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
736 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
740 void radv_GetPhysicalDeviceFeatures(
741 VkPhysicalDevice physicalDevice
,
742 VkPhysicalDeviceFeatures
* pFeatures
)
744 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
745 memset(pFeatures
, 0, sizeof(*pFeatures
));
747 *pFeatures
= (VkPhysicalDeviceFeatures
) {
748 .robustBufferAccess
= true,
749 .fullDrawIndexUint32
= true,
750 .imageCubeArray
= true,
751 .independentBlend
= true,
752 .geometryShader
= true,
753 .tessellationShader
= true,
754 .sampleRateShading
= true,
755 .dualSrcBlend
= true,
757 .multiDrawIndirect
= true,
758 .drawIndirectFirstInstance
= true,
760 .depthBiasClamp
= true,
761 .fillModeNonSolid
= true,
766 .multiViewport
= true,
767 .samplerAnisotropy
= true,
768 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
769 .textureCompressionASTC_LDR
= false,
770 .textureCompressionBC
= true,
771 .occlusionQueryPrecise
= true,
772 .pipelineStatisticsQuery
= true,
773 .vertexPipelineStoresAndAtomics
= true,
774 .fragmentStoresAndAtomics
= true,
775 .shaderTessellationAndGeometryPointSize
= true,
776 .shaderImageGatherExtended
= true,
777 .shaderStorageImageExtendedFormats
= true,
778 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
779 .shaderUniformBufferArrayDynamicIndexing
= true,
780 .shaderSampledImageArrayDynamicIndexing
= true,
781 .shaderStorageBufferArrayDynamicIndexing
= true,
782 .shaderStorageImageArrayDynamicIndexing
= true,
783 .shaderStorageImageReadWithoutFormat
= true,
784 .shaderStorageImageWriteWithoutFormat
= true,
785 .shaderClipDistance
= true,
786 .shaderCullDistance
= true,
787 .shaderFloat64
= true,
789 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
790 .sparseBinding
= true,
791 .variableMultisampleRate
= true,
792 .inheritedQueries
= true,
796 void radv_GetPhysicalDeviceFeatures2(
797 VkPhysicalDevice physicalDevice
,
798 VkPhysicalDeviceFeatures2
*pFeatures
)
800 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
801 vk_foreach_struct(ext
, pFeatures
->pNext
) {
802 switch (ext
->sType
) {
803 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
804 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
805 features
->variablePointersStorageBuffer
= true;
806 features
->variablePointers
= true;
809 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
810 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
811 features
->multiview
= true;
812 features
->multiviewGeometryShader
= true;
813 features
->multiviewTessellationShader
= true;
816 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
817 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
818 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
819 features
->shaderDrawParameters
= true;
822 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
823 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
824 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
825 features
->protectedMemory
= false;
828 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
829 VkPhysicalDevice16BitStorageFeatures
*features
=
830 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
831 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
832 features
->storageBuffer16BitAccess
= enabled
;
833 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
834 features
->storagePushConstant16
= enabled
;
835 features
->storageInputOutput16
= enabled
&& HAVE_LLVM
>= 0x900;
838 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
839 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
840 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
841 features
->samplerYcbcrConversion
= true;
844 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
845 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
846 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
847 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
848 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
849 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
850 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
851 features
->shaderSampledImageArrayNonUniformIndexing
= true;
852 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
853 features
->shaderStorageImageArrayNonUniformIndexing
= true;
854 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
855 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
856 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
857 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
858 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
859 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
860 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
861 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
862 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
863 features
->descriptorBindingUpdateUnusedWhilePending
= true;
864 features
->descriptorBindingPartiallyBound
= true;
865 features
->descriptorBindingVariableDescriptorCount
= true;
866 features
->runtimeDescriptorArray
= true;
869 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
870 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
871 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
872 features
->conditionalRendering
= true;
873 features
->inheritedConditionalRendering
= false;
876 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
877 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
878 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
879 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
880 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
883 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
884 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
885 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
886 features
->transformFeedback
= true;
887 features
->geometryStreams
= true;
890 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
891 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
892 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
893 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
896 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
897 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
898 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
899 features
->memoryPriority
= VK_TRUE
;
902 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
903 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
904 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
905 features
->bufferDeviceAddress
= true;
906 features
->bufferDeviceAddressCaptureReplay
= false;
907 features
->bufferDeviceAddressMultiDevice
= false;
910 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
911 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
912 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
913 features
->depthClipEnable
= true;
916 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
917 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
918 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
919 features
->hostQueryReset
= true;
922 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
923 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
924 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
925 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
926 features
->storageBuffer8BitAccess
= enabled
;
927 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
928 features
->storagePushConstant8
= enabled
;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
932 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
933 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
934 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& HAVE_LLVM
>= 0x0800;
935 features
->shaderInt8
= true;
938 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
939 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
940 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
941 /* TODO: Enable this once the driver supports 64-bit
942 * compare&swap atomic operations.
944 features
->shaderBufferInt64Atomics
= false;
945 features
->shaderSharedInt64Atomics
= false;
948 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
949 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
950 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
952 features
->inlineUniformBlock
= true;
953 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
957 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
958 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
959 features
->computeDerivativeGroupQuads
= false;
960 features
->computeDerivativeGroupLinear
= true;
963 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
964 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
965 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
966 features
->ycbcrImageArrays
= true;
969 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
970 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
971 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
972 features
->uniformBufferStandardLayout
= true;
979 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
982 void radv_GetPhysicalDeviceProperties(
983 VkPhysicalDevice physicalDevice
,
984 VkPhysicalDeviceProperties
* pProperties
)
986 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
987 VkSampleCountFlags sample_counts
= 0xf;
989 /* make sure that the entire descriptor set is addressable with a signed
990 * 32-bit int. So the sum of all limits scaled by descriptor size has to
991 * be at most 2 GiB. the combined image & samples object count as one of
992 * both. This limit is for the pipeline layout, not for the set layout, but
993 * there is no set limit, so we just set a pipeline limit. I don't think
994 * any app is going to hit this soon. */
995 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
996 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
997 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
998 32 /* sampler, largest when combined with image */ +
999 64 /* sampled image */ +
1000 64 /* storage image */);
1002 VkPhysicalDeviceLimits limits
= {
1003 .maxImageDimension1D
= (1 << 14),
1004 .maxImageDimension2D
= (1 << 14),
1005 .maxImageDimension3D
= (1 << 11),
1006 .maxImageDimensionCube
= (1 << 14),
1007 .maxImageArrayLayers
= (1 << 11),
1008 .maxTexelBufferElements
= 128 * 1024 * 1024,
1009 .maxUniformBufferRange
= UINT32_MAX
,
1010 .maxStorageBufferRange
= UINT32_MAX
,
1011 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1012 .maxMemoryAllocationCount
= UINT32_MAX
,
1013 .maxSamplerAllocationCount
= 64 * 1024,
1014 .bufferImageGranularity
= 64, /* A cache line */
1015 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1016 .maxBoundDescriptorSets
= MAX_SETS
,
1017 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1018 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1019 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1020 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1021 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1022 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1023 .maxPerStageResources
= max_descriptor_set_size
,
1024 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1025 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1026 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1027 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1028 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1029 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1030 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1031 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1032 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1033 .maxVertexInputBindings
= MAX_VBS
,
1034 .maxVertexInputAttributeOffset
= 2047,
1035 .maxVertexInputBindingStride
= 2048,
1036 .maxVertexOutputComponents
= 128,
1037 .maxTessellationGenerationLevel
= 64,
1038 .maxTessellationPatchSize
= 32,
1039 .maxTessellationControlPerVertexInputComponents
= 128,
1040 .maxTessellationControlPerVertexOutputComponents
= 128,
1041 .maxTessellationControlPerPatchOutputComponents
= 120,
1042 .maxTessellationControlTotalOutputComponents
= 4096,
1043 .maxTessellationEvaluationInputComponents
= 128,
1044 .maxTessellationEvaluationOutputComponents
= 128,
1045 .maxGeometryShaderInvocations
= 127,
1046 .maxGeometryInputComponents
= 64,
1047 .maxGeometryOutputComponents
= 128,
1048 .maxGeometryOutputVertices
= 256,
1049 .maxGeometryTotalOutputComponents
= 1024,
1050 .maxFragmentInputComponents
= 128,
1051 .maxFragmentOutputAttachments
= 8,
1052 .maxFragmentDualSrcAttachments
= 1,
1053 .maxFragmentCombinedOutputResources
= 8,
1054 .maxComputeSharedMemorySize
= 32768,
1055 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1056 .maxComputeWorkGroupInvocations
= 2048,
1057 .maxComputeWorkGroupSize
= {
1062 .subPixelPrecisionBits
= 8,
1063 .subTexelPrecisionBits
= 8,
1064 .mipmapPrecisionBits
= 8,
1065 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1066 .maxDrawIndirectCount
= UINT32_MAX
,
1067 .maxSamplerLodBias
= 16,
1068 .maxSamplerAnisotropy
= 16,
1069 .maxViewports
= MAX_VIEWPORTS
,
1070 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1071 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1072 .viewportSubPixelBits
= 8,
1073 .minMemoryMapAlignment
= 4096, /* A page */
1074 .minTexelBufferOffsetAlignment
= 1,
1075 .minUniformBufferOffsetAlignment
= 4,
1076 .minStorageBufferOffsetAlignment
= 4,
1077 .minTexelOffset
= -32,
1078 .maxTexelOffset
= 31,
1079 .minTexelGatherOffset
= -32,
1080 .maxTexelGatherOffset
= 31,
1081 .minInterpolationOffset
= -2,
1082 .maxInterpolationOffset
= 2,
1083 .subPixelInterpolationOffsetBits
= 8,
1084 .maxFramebufferWidth
= (1 << 14),
1085 .maxFramebufferHeight
= (1 << 14),
1086 .maxFramebufferLayers
= (1 << 10),
1087 .framebufferColorSampleCounts
= sample_counts
,
1088 .framebufferDepthSampleCounts
= sample_counts
,
1089 .framebufferStencilSampleCounts
= sample_counts
,
1090 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1091 .maxColorAttachments
= MAX_RTS
,
1092 .sampledImageColorSampleCounts
= sample_counts
,
1093 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1094 .sampledImageDepthSampleCounts
= sample_counts
,
1095 .sampledImageStencilSampleCounts
= sample_counts
,
1096 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1097 .maxSampleMaskWords
= 1,
1098 .timestampComputeAndGraphics
= true,
1099 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1100 .maxClipDistances
= 8,
1101 .maxCullDistances
= 8,
1102 .maxCombinedClipAndCullDistances
= 8,
1103 .discreteQueuePriorities
= 2,
1104 .pointSizeRange
= { 0.0, 8192.0 },
1105 .lineWidthRange
= { 0.0, 7.9921875 },
1106 .pointSizeGranularity
= (1.0 / 8.0),
1107 .lineWidthGranularity
= (1.0 / 128.0),
1108 .strictLines
= false, /* FINISHME */
1109 .standardSampleLocations
= true,
1110 .optimalBufferCopyOffsetAlignment
= 128,
1111 .optimalBufferCopyRowPitchAlignment
= 128,
1112 .nonCoherentAtomSize
= 64,
1115 *pProperties
= (VkPhysicalDeviceProperties
) {
1116 .apiVersion
= radv_physical_device_api_version(pdevice
),
1117 .driverVersion
= vk_get_driver_version(),
1118 .vendorID
= ATI_VENDOR_ID
,
1119 .deviceID
= pdevice
->rad_info
.pci_id
,
1120 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1122 .sparseProperties
= {0},
1125 strcpy(pProperties
->deviceName
, pdevice
->name
);
1126 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1129 void radv_GetPhysicalDeviceProperties2(
1130 VkPhysicalDevice physicalDevice
,
1131 VkPhysicalDeviceProperties2
*pProperties
)
1133 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1134 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1136 vk_foreach_struct(ext
, pProperties
->pNext
) {
1137 switch (ext
->sType
) {
1138 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1139 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1140 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1141 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1144 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1145 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1146 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1147 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1148 properties
->deviceLUIDValid
= false;
1151 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1152 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1153 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1154 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1157 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1158 VkPhysicalDevicePointClippingProperties
*properties
=
1159 (VkPhysicalDevicePointClippingProperties
*)ext
;
1160 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1163 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1164 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1165 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1166 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1169 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1170 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1171 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1172 properties
->minImportedHostPointerAlignment
= 4096;
1175 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1176 VkPhysicalDeviceSubgroupProperties
*properties
=
1177 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1178 properties
->subgroupSize
= 64;
1179 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1180 properties
->supportedOperations
=
1181 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1182 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1183 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1184 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1185 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1186 properties
->supportedOperations
|=
1187 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1188 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1189 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1191 properties
->quadOperationsInAllStages
= true;
1194 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1195 VkPhysicalDeviceMaintenance3Properties
*properties
=
1196 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1197 /* Make sure everything is addressable by a signed 32-bit int, and
1198 * our largest descriptors are 96 bytes. */
1199 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1200 /* Our buffer size fields allow only this much */
1201 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1204 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1205 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1206 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1207 /* GFX6-8 only support single channel min/max filter. */
1208 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1209 properties
->filterMinmaxSingleComponentFormats
= true;
1212 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1213 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1214 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1216 /* Shader engines. */
1217 properties
->shaderEngineCount
=
1218 pdevice
->rad_info
.max_se
;
1219 properties
->shaderArraysPerEngineCount
=
1220 pdevice
->rad_info
.max_sh_per_se
;
1221 properties
->computeUnitsPerShaderArray
=
1222 pdevice
->rad_info
.num_good_cu_per_sh
;
1223 properties
->simdPerComputeUnit
= 4;
1224 properties
->wavefrontsPerSimd
=
1225 pdevice
->rad_info
.family
== CHIP_TONGA
||
1226 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1227 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1228 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1229 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1230 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1231 properties
->wavefrontSize
= 64;
1234 properties
->sgprsPerSimd
=
1235 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1236 properties
->minSgprAllocation
=
1237 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1238 properties
->maxSgprAllocation
=
1239 pdevice
->rad_info
.family
== CHIP_TONGA
||
1240 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1241 properties
->sgprAllocationGranularity
=
1242 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1245 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1246 properties
->minVgprAllocation
= 4;
1247 properties
->maxVgprAllocation
= 256;
1248 properties
->vgprAllocationGranularity
= 4;
1251 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1252 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1253 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1254 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1257 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1258 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1259 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1260 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1261 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1262 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1263 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1264 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1265 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1266 properties
->robustBufferAccessUpdateAfterBind
= false;
1267 properties
->quadDivergentImplicitLod
= false;
1269 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1270 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1271 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1272 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1273 32 /* sampler, largest when combined with image */ +
1274 64 /* sampled image */ +
1275 64 /* storage image */);
1276 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1277 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1278 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1279 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1280 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1281 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1282 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1283 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1284 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1285 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1286 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1287 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1288 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1289 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1290 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1293 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1294 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1295 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1296 properties
->protectedNoFault
= false;
1299 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1300 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1301 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1302 properties
->primitiveOverestimationSize
= 0;
1303 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1304 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1305 properties
->primitiveUnderestimation
= VK_FALSE
;
1306 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1307 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1308 properties
->degenerateLinesRasterized
= VK_FALSE
;
1309 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1310 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1313 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1314 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1315 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1316 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1317 properties
->pciBus
= pdevice
->bus_info
.bus
;
1318 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1319 properties
->pciFunction
= pdevice
->bus_info
.func
;
1322 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1323 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1324 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1326 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1327 memset(driver_props
->driverName
, 0, VK_MAX_DRIVER_NAME_SIZE_KHR
);
1328 strcpy(driver_props
->driverName
, "radv");
1330 memset(driver_props
->driverInfo
, 0, VK_MAX_DRIVER_INFO_SIZE_KHR
);
1331 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1332 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1333 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1335 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1343 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1344 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1345 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1346 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1347 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1348 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1349 properties
->maxTransformFeedbackStreamDataSize
= 512;
1350 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1351 properties
->maxTransformFeedbackBufferDataStride
= 512;
1352 properties
->transformFeedbackQueries
= true;
1353 properties
->transformFeedbackStreamsLinesTriangles
= true;
1354 properties
->transformFeedbackRasterizationStreamSelect
= false;
1355 properties
->transformFeedbackDraw
= true;
1358 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1359 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1360 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1362 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1363 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1364 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1365 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1366 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1369 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1370 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1371 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1372 /* TODO: The ext is currently disabled because the
1373 * driver needs to handle sample locations during
1374 * layout transitions for depth/stencil surfaces and
1377 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1379 properties->sampleLocationSampleCounts = VK_SAMPLE_COUNT_2_BIT |
1380 VK_SAMPLE_COUNT_4_BIT |
1381 VK_SAMPLE_COUNT_8_BIT;
1383 properties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2 , 2 };
1384 properties
->sampleLocationCoordinateRange
[0] = 0.0f
;
1385 properties
->sampleLocationCoordinateRange
[1] = 0.9375f
;
1386 properties
->sampleLocationSubPixelBits
= 4;
1387 properties
->variableSampleLocations
= VK_FALSE
;
1396 static void radv_get_physical_device_queue_family_properties(
1397 struct radv_physical_device
* pdevice
,
1399 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1401 int num_queue_families
= 1;
1403 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1404 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1405 num_queue_families
++;
1407 if (pQueueFamilyProperties
== NULL
) {
1408 *pCount
= num_queue_families
;
1417 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1418 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1419 VK_QUEUE_COMPUTE_BIT
|
1420 VK_QUEUE_TRANSFER_BIT
|
1421 VK_QUEUE_SPARSE_BINDING_BIT
,
1423 .timestampValidBits
= 64,
1424 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1429 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1430 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1431 if (*pCount
> idx
) {
1432 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1433 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1434 VK_QUEUE_TRANSFER_BIT
|
1435 VK_QUEUE_SPARSE_BINDING_BIT
,
1436 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1437 .timestampValidBits
= 64,
1438 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1446 void radv_GetPhysicalDeviceQueueFamilyProperties(
1447 VkPhysicalDevice physicalDevice
,
1449 VkQueueFamilyProperties
* 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,
1458 pQueueFamilyProperties
+ 1,
1459 pQueueFamilyProperties
+ 2,
1461 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1462 assert(*pCount
<= 3);
1465 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1466 VkPhysicalDevice physicalDevice
,
1468 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1470 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1471 if (!pQueueFamilyProperties
) {
1472 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1475 VkQueueFamilyProperties
*properties
[] = {
1476 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1477 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1478 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1480 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1481 assert(*pCount
<= 3);
1484 void radv_GetPhysicalDeviceMemoryProperties(
1485 VkPhysicalDevice physicalDevice
,
1486 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1488 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1490 *pMemoryProperties
= physical_device
->memory_properties
;
1494 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1495 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1497 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1498 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1499 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1500 uint64_t vram_size
= radv_get_vram_size(device
);
1501 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1502 uint64_t heap_budget
, heap_usage
;
1504 /* For all memory heaps, the computation of budget is as follow:
1505 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1507 * The Vulkan spec 1.1.97 says that the budget should include any
1508 * currently allocated device memory.
1510 * Note that the application heap usages are not really accurate (eg.
1511 * in presence of shared buffers).
1514 heap_usage
= device
->ws
->query_value(device
->ws
,
1515 RADEON_ALLOCATED_VRAM
);
1517 heap_budget
= vram_size
-
1518 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1521 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM
] = heap_budget
;
1522 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM
] = heap_usage
;
1525 if (visible_vram_size
) {
1526 heap_usage
= device
->ws
->query_value(device
->ws
,
1527 RADEON_ALLOCATED_VRAM_VIS
);
1529 heap_budget
= visible_vram_size
-
1530 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1533 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_budget
;
1534 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_usage
;
1538 heap_usage
= device
->ws
->query_value(device
->ws
,
1539 RADEON_ALLOCATED_GTT
);
1541 heap_budget
= gtt_size
-
1542 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1545 memoryBudget
->heapBudget
[RADV_MEM_HEAP_GTT
] = heap_budget
;
1546 memoryBudget
->heapUsage
[RADV_MEM_HEAP_GTT
] = heap_usage
;
1549 /* The heapBudget and heapUsage values must be zero for array elements
1550 * greater than or equal to
1551 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1553 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1554 memoryBudget
->heapBudget
[i
] = 0;
1555 memoryBudget
->heapUsage
[i
] = 0;
1559 void radv_GetPhysicalDeviceMemoryProperties2(
1560 VkPhysicalDevice physicalDevice
,
1561 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1563 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1564 &pMemoryProperties
->memoryProperties
);
1566 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1567 vk_find_struct(pMemoryProperties
->pNext
,
1568 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1570 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1573 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1575 VkExternalMemoryHandleTypeFlagBits handleType
,
1576 const void *pHostPointer
,
1577 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1579 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1583 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1584 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1585 uint32_t memoryTypeBits
= 0;
1586 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1587 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1588 memoryTypeBits
= (1 << i
);
1592 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1596 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1600 static enum radeon_ctx_priority
1601 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1603 /* Default to MEDIUM when a specific global priority isn't requested */
1605 return RADEON_CTX_PRIORITY_MEDIUM
;
1607 switch(pObj
->globalPriority
) {
1608 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1609 return RADEON_CTX_PRIORITY_REALTIME
;
1610 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1611 return RADEON_CTX_PRIORITY_HIGH
;
1612 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1613 return RADEON_CTX_PRIORITY_MEDIUM
;
1614 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1615 return RADEON_CTX_PRIORITY_LOW
;
1617 unreachable("Illegal global priority value");
1618 return RADEON_CTX_PRIORITY_INVALID
;
1623 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1624 uint32_t queue_family_index
, int idx
,
1625 VkDeviceQueueCreateFlags flags
,
1626 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1628 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1629 queue
->device
= device
;
1630 queue
->queue_family_index
= queue_family_index
;
1631 queue
->queue_idx
= idx
;
1632 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1633 queue
->flags
= flags
;
1635 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1637 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1643 radv_queue_finish(struct radv_queue
*queue
)
1646 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1648 if (queue
->initial_full_flush_preamble_cs
)
1649 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1650 if (queue
->initial_preamble_cs
)
1651 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1652 if (queue
->continue_preamble_cs
)
1653 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1654 if (queue
->descriptor_bo
)
1655 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1656 if (queue
->scratch_bo
)
1657 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1658 if (queue
->esgs_ring_bo
)
1659 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1660 if (queue
->gsvs_ring_bo
)
1661 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1662 if (queue
->tess_rings_bo
)
1663 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1664 if (queue
->compute_scratch_bo
)
1665 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1669 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1671 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1672 bo_list
->list
.count
= bo_list
->capacity
= 0;
1673 bo_list
->list
.bos
= NULL
;
1677 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1679 free(bo_list
->list
.bos
);
1680 pthread_mutex_destroy(&bo_list
->mutex
);
1683 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1684 struct radeon_winsys_bo
*bo
)
1686 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1691 if (unlikely(!device
->use_global_bo_list
))
1694 pthread_mutex_lock(&bo_list
->mutex
);
1695 if (bo_list
->list
.count
== bo_list
->capacity
) {
1696 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1697 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1700 pthread_mutex_unlock(&bo_list
->mutex
);
1701 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1704 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1705 bo_list
->capacity
= capacity
;
1708 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1709 pthread_mutex_unlock(&bo_list
->mutex
);
1713 static void radv_bo_list_remove(struct radv_device
*device
,
1714 struct radeon_winsys_bo
*bo
)
1716 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1721 if (unlikely(!device
->use_global_bo_list
))
1724 pthread_mutex_lock(&bo_list
->mutex
);
1725 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1726 if (bo_list
->list
.bos
[i
] == bo
) {
1727 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1728 --bo_list
->list
.count
;
1732 pthread_mutex_unlock(&bo_list
->mutex
);
1736 radv_device_init_gs_info(struct radv_device
*device
)
1738 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1739 device
->physical_device
->rad_info
.family
);
1742 static int radv_get_device_extension_index(const char *name
)
1744 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1745 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1752 radv_get_int_debug_option(const char *name
, int default_value
)
1759 result
= default_value
;
1763 result
= strtol(str
, &endptr
, 0);
1764 if (str
== endptr
) {
1765 /* No digits founs. */
1766 result
= default_value
;
1773 VkResult
radv_CreateDevice(
1774 VkPhysicalDevice physicalDevice
,
1775 const VkDeviceCreateInfo
* pCreateInfo
,
1776 const VkAllocationCallbacks
* pAllocator
,
1779 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1781 struct radv_device
*device
;
1783 bool keep_shader_info
= false;
1785 /* Check enabled features */
1786 if (pCreateInfo
->pEnabledFeatures
) {
1787 VkPhysicalDeviceFeatures supported_features
;
1788 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1789 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1790 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1791 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1792 for (uint32_t i
= 0; i
< num_features
; i
++) {
1793 if (enabled_feature
[i
] && !supported_feature
[i
])
1794 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1798 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1800 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1802 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1804 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1805 device
->instance
= physical_device
->instance
;
1806 device
->physical_device
= physical_device
;
1808 device
->ws
= physical_device
->ws
;
1810 device
->alloc
= *pAllocator
;
1812 device
->alloc
= physical_device
->instance
->alloc
;
1814 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1815 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1816 int index
= radv_get_device_extension_index(ext_name
);
1817 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1818 vk_free(&device
->alloc
, device
);
1819 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1822 device
->enabled_extensions
.extensions
[index
] = true;
1825 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1827 /* With update after bind we can't attach bo's to the command buffer
1828 * from the descriptor set anymore, so we have to use a global BO list.
1830 device
->use_global_bo_list
=
1831 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1832 device
->enabled_extensions
.EXT_descriptor_indexing
||
1833 device
->enabled_extensions
.EXT_buffer_device_address
;
1835 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1836 list_inithead(&device
->shader_slabs
);
1838 radv_bo_list_init(&device
->bo_list
);
1840 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1841 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1842 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1843 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1844 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1846 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1848 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1849 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1850 if (!device
->queues
[qfi
]) {
1851 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1855 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1857 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1859 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1860 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1861 qfi
, q
, queue_create
->flags
,
1863 if (result
!= VK_SUCCESS
)
1868 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1869 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1871 /* Disabled and not implemented for now. */
1872 device
->dfsm_allowed
= device
->pbb_allowed
&&
1873 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1874 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
);
1877 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1880 /* The maximum number of scratch waves. Scratch space isn't divided
1881 * evenly between CUs. The number is only a function of the number of CUs.
1882 * We can decrease the constant to decrease the scratch buffer size.
1884 * sctx->scratch_waves must be >= the maximum possible size of
1885 * 1 threadgroup, so that the hw doesn't hang from being unable
1888 * The recommended value is 4 per CU at most. Higher numbers don't
1889 * bring much benefit, but they still occupy chip resources (think
1890 * async compute). I've seen ~2% performance difference between 4 and 32.
1892 uint32_t max_threads_per_block
= 2048;
1893 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1894 max_threads_per_block
/ 64);
1896 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1898 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
1899 /* If the KMD allows it (there is a KMD hw register for it),
1900 * allow launching waves out-of-order.
1902 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1905 radv_device_init_gs_info(device
);
1907 device
->tess_offchip_block_dw_size
=
1908 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1909 device
->has_distributed_tess
=
1910 device
->physical_device
->rad_info
.chip_class
>= GFX8
&&
1911 device
->physical_device
->rad_info
.max_se
>= 2;
1913 if (getenv("RADV_TRACE_FILE")) {
1914 const char *filename
= getenv("RADV_TRACE_FILE");
1916 keep_shader_info
= true;
1918 if (!radv_init_trace(device
))
1921 fprintf(stderr
, "*****************************************************************************\n");
1922 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1923 fprintf(stderr
, "*****************************************************************************\n");
1925 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1926 radv_dump_enabled_options(device
, stderr
);
1929 device
->keep_shader_info
= keep_shader_info
;
1931 result
= radv_device_init_meta(device
);
1932 if (result
!= VK_SUCCESS
)
1935 radv_device_init_msaa(device
);
1937 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1938 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1940 case RADV_QUEUE_GENERAL
:
1941 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1942 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1943 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1945 case RADV_QUEUE_COMPUTE
:
1946 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1947 radeon_emit(device
->empty_cs
[family
], 0);
1950 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1953 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
1954 cik_create_gfx_config(device
);
1956 VkPipelineCacheCreateInfo ci
;
1957 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1960 ci
.pInitialData
= NULL
;
1961 ci
.initialDataSize
= 0;
1963 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1965 if (result
!= VK_SUCCESS
)
1968 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1970 device
->force_aniso
=
1971 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1972 if (device
->force_aniso
>= 0) {
1973 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
1974 1 << util_logbase2(device
->force_aniso
));
1977 *pDevice
= radv_device_to_handle(device
);
1981 radv_device_finish_meta(device
);
1983 radv_bo_list_finish(&device
->bo_list
);
1985 if (device
->trace_bo
)
1986 device
->ws
->buffer_destroy(device
->trace_bo
);
1988 if (device
->gfx_init
)
1989 device
->ws
->buffer_destroy(device
->gfx_init
);
1991 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1992 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1993 radv_queue_finish(&device
->queues
[i
][q
]);
1994 if (device
->queue_count
[i
])
1995 vk_free(&device
->alloc
, device
->queues
[i
]);
1998 vk_free(&device
->alloc
, device
);
2002 void radv_DestroyDevice(
2004 const VkAllocationCallbacks
* pAllocator
)
2006 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2011 if (device
->trace_bo
)
2012 device
->ws
->buffer_destroy(device
->trace_bo
);
2014 if (device
->gfx_init
)
2015 device
->ws
->buffer_destroy(device
->gfx_init
);
2017 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2018 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2019 radv_queue_finish(&device
->queues
[i
][q
]);
2020 if (device
->queue_count
[i
])
2021 vk_free(&device
->alloc
, device
->queues
[i
]);
2022 if (device
->empty_cs
[i
])
2023 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2025 radv_device_finish_meta(device
);
2027 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2028 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2030 radv_destroy_shader_slabs(device
);
2032 radv_bo_list_finish(&device
->bo_list
);
2033 vk_free(&device
->alloc
, device
);
2036 VkResult
radv_EnumerateInstanceLayerProperties(
2037 uint32_t* pPropertyCount
,
2038 VkLayerProperties
* pProperties
)
2040 if (pProperties
== NULL
) {
2041 *pPropertyCount
= 0;
2045 /* None supported at this time */
2046 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2049 VkResult
radv_EnumerateDeviceLayerProperties(
2050 VkPhysicalDevice physicalDevice
,
2051 uint32_t* pPropertyCount
,
2052 VkLayerProperties
* pProperties
)
2054 if (pProperties
== NULL
) {
2055 *pPropertyCount
= 0;
2059 /* None supported at this time */
2060 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2063 void radv_GetDeviceQueue2(
2065 const VkDeviceQueueInfo2
* pQueueInfo
,
2068 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2069 struct radv_queue
*queue
;
2071 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2072 if (pQueueInfo
->flags
!= queue
->flags
) {
2073 /* From the Vulkan 1.1.70 spec:
2075 * "The queue returned by vkGetDeviceQueue2 must have the same
2076 * flags value from this structure as that used at device
2077 * creation time in a VkDeviceQueueCreateInfo instance. If no
2078 * matching flags were specified at device creation time then
2079 * pQueue will return VK_NULL_HANDLE."
2081 *pQueue
= VK_NULL_HANDLE
;
2085 *pQueue
= radv_queue_to_handle(queue
);
2088 void radv_GetDeviceQueue(
2090 uint32_t queueFamilyIndex
,
2091 uint32_t queueIndex
,
2094 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2095 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2096 .queueFamilyIndex
= queueFamilyIndex
,
2097 .queueIndex
= queueIndex
2100 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2104 fill_geom_tess_rings(struct radv_queue
*queue
,
2106 bool add_sample_positions
,
2107 uint32_t esgs_ring_size
,
2108 struct radeon_winsys_bo
*esgs_ring_bo
,
2109 uint32_t gsvs_ring_size
,
2110 struct radeon_winsys_bo
*gsvs_ring_bo
,
2111 uint32_t tess_factor_ring_size
,
2112 uint32_t tess_offchip_ring_offset
,
2113 uint32_t tess_offchip_ring_size
,
2114 struct radeon_winsys_bo
*tess_rings_bo
)
2116 uint32_t *desc
= &map
[4];
2119 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2121 /* stride 0, num records - size, add tid, swizzle, elsize4,
2124 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2125 S_008F04_STRIDE(0) |
2126 S_008F04_SWIZZLE_ENABLE(true);
2127 desc
[2] = esgs_ring_size
;
2128 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2129 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2130 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2131 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2132 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2133 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2134 S_008F0C_ELEMENT_SIZE(1) |
2135 S_008F0C_INDEX_STRIDE(3) |
2136 S_008F0C_ADD_TID_ENABLE(true);
2138 /* GS entry for ES->GS ring */
2139 /* stride 0, num records - size, elsize0,
2142 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
2143 S_008F04_STRIDE(0) |
2144 S_008F04_SWIZZLE_ENABLE(false);
2145 desc
[6] = esgs_ring_size
;
2146 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2147 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2148 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2149 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2150 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2151 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2152 S_008F0C_ELEMENT_SIZE(0) |
2153 S_008F0C_INDEX_STRIDE(0) |
2154 S_008F0C_ADD_TID_ENABLE(false);
2160 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2162 /* VS entry for GS->VS ring */
2163 /* stride 0, num records - size, elsize0,
2166 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2167 S_008F04_STRIDE(0) |
2168 S_008F04_SWIZZLE_ENABLE(false);
2169 desc
[2] = gsvs_ring_size
;
2170 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2171 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2172 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2173 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2174 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2175 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2176 S_008F0C_ELEMENT_SIZE(0) |
2177 S_008F0C_INDEX_STRIDE(0) |
2178 S_008F0C_ADD_TID_ENABLE(false);
2180 /* stride gsvs_itemsize, num records 64
2181 elsize 4, index stride 16 */
2182 /* shader will patch stride and desc[2] */
2184 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2185 S_008F04_STRIDE(0) |
2186 S_008F04_SWIZZLE_ENABLE(true);
2188 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2189 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2190 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2191 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2192 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2193 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2194 S_008F0C_ELEMENT_SIZE(1) |
2195 S_008F0C_INDEX_STRIDE(1) |
2196 S_008F0C_ADD_TID_ENABLE(true);
2201 if (tess_rings_bo
) {
2202 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2203 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2206 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
2207 S_008F04_STRIDE(0) |
2208 S_008F04_SWIZZLE_ENABLE(false);
2209 desc
[2] = tess_factor_ring_size
;
2210 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2211 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2212 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2213 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2214 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2215 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2216 S_008F0C_ELEMENT_SIZE(0) |
2217 S_008F0C_INDEX_STRIDE(0) |
2218 S_008F0C_ADD_TID_ENABLE(false);
2220 desc
[4] = tess_offchip_va
;
2221 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
2222 S_008F04_STRIDE(0) |
2223 S_008F04_SWIZZLE_ENABLE(false);
2224 desc
[6] = tess_offchip_ring_size
;
2225 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2226 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2227 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2228 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2229 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2230 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2231 S_008F0C_ELEMENT_SIZE(0) |
2232 S_008F0C_INDEX_STRIDE(0) |
2233 S_008F0C_ADD_TID_ENABLE(false);
2238 if (add_sample_positions
) {
2239 /* add sample positions after all rings */
2240 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2242 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2244 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2246 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2251 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2253 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2254 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2255 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2256 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2257 unsigned max_offchip_buffers
;
2258 unsigned offchip_granularity
;
2259 unsigned hs_offchip_param
;
2263 * This must be one less than the maximum number due to a hw limitation.
2264 * Various hardware bugs need thGFX7
2267 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2268 * Gfx7 should limit max_offchip_buffers to 508
2269 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2271 * Follow AMDVLK here.
2273 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2274 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2275 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2276 --max_offchip_buffers_per_se
;
2278 max_offchip_buffers
= max_offchip_buffers_per_se
*
2279 device
->physical_device
->rad_info
.max_se
;
2281 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2282 * around by setting 4K granularity.
2284 if (device
->tess_offchip_block_dw_size
== 4096) {
2285 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2286 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2288 assert(device
->tess_offchip_block_dw_size
== 8192);
2289 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2292 switch (device
->physical_device
->rad_info
.chip_class
) {
2294 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2300 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2304 *max_offchip_buffers_p
= max_offchip_buffers
;
2305 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2306 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2307 --max_offchip_buffers
;
2309 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2310 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2313 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2315 return hs_offchip_param
;
2319 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2320 struct radeon_winsys_bo
*esgs_ring_bo
,
2321 uint32_t esgs_ring_size
,
2322 struct radeon_winsys_bo
*gsvs_ring_bo
,
2323 uint32_t gsvs_ring_size
)
2325 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2329 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2332 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2334 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2335 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2336 radeon_emit(cs
, esgs_ring_size
>> 8);
2337 radeon_emit(cs
, gsvs_ring_size
>> 8);
2339 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2340 radeon_emit(cs
, esgs_ring_size
>> 8);
2341 radeon_emit(cs
, gsvs_ring_size
>> 8);
2346 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2347 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2348 struct radeon_winsys_bo
*tess_rings_bo
)
2355 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2357 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2359 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2360 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2361 S_030938_SIZE(tf_ring_size
/ 4));
2362 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2364 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2365 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2366 S_030944_BASE_HI(tf_va
>> 40));
2368 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2371 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2372 S_008988_SIZE(tf_ring_size
/ 4));
2373 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2375 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2381 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2382 struct radeon_winsys_bo
*compute_scratch_bo
)
2384 uint64_t scratch_va
;
2386 if (!compute_scratch_bo
)
2389 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2391 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2393 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2394 radeon_emit(cs
, scratch_va
);
2395 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2396 S_008F04_SWIZZLE_ENABLE(1));
2400 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2401 struct radeon_cmdbuf
*cs
,
2402 struct radeon_winsys_bo
*descriptor_bo
)
2409 va
= radv_buffer_get_va(descriptor_bo
);
2411 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2413 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2414 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2415 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2416 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2417 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2419 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2420 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2424 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2425 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2426 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2427 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2428 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2429 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2431 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2432 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2439 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2441 struct radv_device
*device
= queue
->device
;
2443 if (device
->gfx_init
) {
2444 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2446 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2447 radeon_emit(cs
, va
);
2448 radeon_emit(cs
, va
>> 32);
2449 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2451 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2453 struct radv_physical_device
*physical_device
= device
->physical_device
;
2454 si_emit_graphics(physical_device
, cs
);
2459 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2461 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2462 si_emit_compute(physical_device
, cs
);
2466 radv_get_preamble_cs(struct radv_queue
*queue
,
2467 uint32_t scratch_size
,
2468 uint32_t compute_scratch_size
,
2469 uint32_t esgs_ring_size
,
2470 uint32_t gsvs_ring_size
,
2471 bool needs_tess_rings
,
2472 bool needs_sample_positions
,
2473 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2474 struct radeon_cmdbuf
**initial_preamble_cs
,
2475 struct radeon_cmdbuf
**continue_preamble_cs
)
2477 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2478 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2479 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2480 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2481 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2482 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2483 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2484 bool add_tess_rings
= false, add_sample_positions
= false;
2485 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2486 unsigned max_offchip_buffers
;
2487 unsigned hs_offchip_param
= 0;
2488 unsigned tess_offchip_ring_offset
;
2489 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2490 if (!queue
->has_tess_rings
) {
2491 if (needs_tess_rings
)
2492 add_tess_rings
= true;
2494 if (!queue
->has_sample_positions
) {
2495 if (needs_sample_positions
)
2496 add_sample_positions
= true;
2498 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2499 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2500 &max_offchip_buffers
);
2501 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2502 tess_offchip_ring_size
= max_offchip_buffers
*
2503 queue
->device
->tess_offchip_block_dw_size
* 4;
2505 if (scratch_size
<= queue
->scratch_size
&&
2506 compute_scratch_size
<= queue
->compute_scratch_size
&&
2507 esgs_ring_size
<= queue
->esgs_ring_size
&&
2508 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2509 !add_tess_rings
&& !add_sample_positions
&&
2510 queue
->initial_preamble_cs
) {
2511 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2512 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2513 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2514 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2515 *continue_preamble_cs
= NULL
;
2519 if (scratch_size
> queue
->scratch_size
) {
2520 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2525 RADV_BO_PRIORITY_SCRATCH
);
2529 scratch_bo
= queue
->scratch_bo
;
2531 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2532 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2533 compute_scratch_size
,
2537 RADV_BO_PRIORITY_SCRATCH
);
2538 if (!compute_scratch_bo
)
2542 compute_scratch_bo
= queue
->compute_scratch_bo
;
2544 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2545 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2550 RADV_BO_PRIORITY_SCRATCH
);
2554 esgs_ring_bo
= queue
->esgs_ring_bo
;
2555 esgs_ring_size
= queue
->esgs_ring_size
;
2558 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2559 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2564 RADV_BO_PRIORITY_SCRATCH
);
2568 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2569 gsvs_ring_size
= queue
->gsvs_ring_size
;
2572 if (add_tess_rings
) {
2573 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2574 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2578 RADV_BO_PRIORITY_SCRATCH
);
2582 tess_rings_bo
= queue
->tess_rings_bo
;
2585 if (scratch_bo
!= queue
->scratch_bo
||
2586 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2587 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2588 tess_rings_bo
!= queue
->tess_rings_bo
||
2589 add_sample_positions
) {
2591 if (gsvs_ring_bo
|| esgs_ring_bo
||
2592 tess_rings_bo
|| add_sample_positions
) {
2593 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2594 if (add_sample_positions
)
2595 size
+= 128; /* 64+32+16+8 = 120 bytes */
2597 else if (scratch_bo
)
2598 size
= 8; /* 2 dword */
2600 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2604 RADEON_FLAG_CPU_ACCESS
|
2605 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2606 RADEON_FLAG_READ_ONLY
,
2607 RADV_BO_PRIORITY_DESCRIPTOR
);
2611 descriptor_bo
= queue
->descriptor_bo
;
2613 if (descriptor_bo
!= queue
->descriptor_bo
) {
2614 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2617 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2618 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2619 S_008F04_SWIZZLE_ENABLE(1);
2620 map
[0] = scratch_va
;
2624 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2625 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2626 esgs_ring_size
, esgs_ring_bo
,
2627 gsvs_ring_size
, gsvs_ring_bo
,
2628 tess_factor_ring_size
,
2629 tess_offchip_ring_offset
,
2630 tess_offchip_ring_size
,
2633 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2636 for(int i
= 0; i
< 3; ++i
) {
2637 struct radeon_cmdbuf
*cs
= NULL
;
2638 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2639 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2646 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2648 /* Emit initial configuration. */
2649 switch (queue
->queue_family_index
) {
2650 case RADV_QUEUE_GENERAL
:
2651 radv_init_graphics_state(cs
, queue
);
2653 case RADV_QUEUE_COMPUTE
:
2654 radv_init_compute_state(cs
, queue
);
2656 case RADV_QUEUE_TRANSFER
:
2660 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2661 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2662 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2663 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2664 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2667 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2668 gsvs_ring_bo
, gsvs_ring_size
);
2669 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2670 tess_factor_ring_size
, tess_rings_bo
);
2671 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2672 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2675 si_cs_emit_cache_flush(cs
,
2676 queue
->device
->physical_device
->rad_info
.chip_class
,
2678 queue
->queue_family_index
== RING_COMPUTE
&&
2679 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2680 (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
)) |
2681 RADV_CMD_FLAG_INV_ICACHE
|
2682 RADV_CMD_FLAG_INV_SMEM_L1
|
2683 RADV_CMD_FLAG_INV_VMEM_L1
|
2684 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2685 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2686 } else if (i
== 1) {
2687 si_cs_emit_cache_flush(cs
,
2688 queue
->device
->physical_device
->rad_info
.chip_class
,
2690 queue
->queue_family_index
== RING_COMPUTE
&&
2691 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2692 RADV_CMD_FLAG_INV_ICACHE
|
2693 RADV_CMD_FLAG_INV_SMEM_L1
|
2694 RADV_CMD_FLAG_INV_VMEM_L1
|
2695 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2696 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2699 if (!queue
->device
->ws
->cs_finalize(cs
))
2703 if (queue
->initial_full_flush_preamble_cs
)
2704 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2706 if (queue
->initial_preamble_cs
)
2707 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2709 if (queue
->continue_preamble_cs
)
2710 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2712 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2713 queue
->initial_preamble_cs
= dest_cs
[1];
2714 queue
->continue_preamble_cs
= dest_cs
[2];
2716 if (scratch_bo
!= queue
->scratch_bo
) {
2717 if (queue
->scratch_bo
)
2718 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2719 queue
->scratch_bo
= scratch_bo
;
2720 queue
->scratch_size
= scratch_size
;
2723 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2724 if (queue
->compute_scratch_bo
)
2725 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2726 queue
->compute_scratch_bo
= compute_scratch_bo
;
2727 queue
->compute_scratch_size
= compute_scratch_size
;
2730 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2731 if (queue
->esgs_ring_bo
)
2732 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2733 queue
->esgs_ring_bo
= esgs_ring_bo
;
2734 queue
->esgs_ring_size
= esgs_ring_size
;
2737 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2738 if (queue
->gsvs_ring_bo
)
2739 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2740 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2741 queue
->gsvs_ring_size
= gsvs_ring_size
;
2744 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2745 queue
->tess_rings_bo
= tess_rings_bo
;
2746 queue
->has_tess_rings
= true;
2749 if (descriptor_bo
!= queue
->descriptor_bo
) {
2750 if (queue
->descriptor_bo
)
2751 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2753 queue
->descriptor_bo
= descriptor_bo
;
2756 if (add_sample_positions
)
2757 queue
->has_sample_positions
= true;
2759 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2760 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2761 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2762 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2763 *continue_preamble_cs
= NULL
;
2766 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2768 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2769 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2770 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2771 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2772 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2773 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2774 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2775 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2776 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2777 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2778 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2779 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2780 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2781 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2784 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2785 struct radv_winsys_sem_counts
*counts
,
2787 const VkSemaphore
*sems
,
2791 int syncobj_idx
= 0, sem_idx
= 0;
2793 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2796 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2797 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2799 if (sem
->temp_syncobj
|| sem
->syncobj
)
2800 counts
->syncobj_count
++;
2802 counts
->sem_count
++;
2805 if (_fence
!= VK_NULL_HANDLE
) {
2806 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2807 if (fence
->temp_syncobj
|| fence
->syncobj
)
2808 counts
->syncobj_count
++;
2811 if (counts
->syncobj_count
) {
2812 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2813 if (!counts
->syncobj
)
2814 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2817 if (counts
->sem_count
) {
2818 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2820 free(counts
->syncobj
);
2821 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2825 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2826 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2828 if (sem
->temp_syncobj
) {
2829 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2831 else if (sem
->syncobj
)
2832 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2835 counts
->sem
[sem_idx
++] = sem
->sem
;
2839 if (_fence
!= VK_NULL_HANDLE
) {
2840 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2841 if (fence
->temp_syncobj
)
2842 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2843 else if (fence
->syncobj
)
2844 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2851 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2853 free(sem_info
->wait
.syncobj
);
2854 free(sem_info
->wait
.sem
);
2855 free(sem_info
->signal
.syncobj
);
2856 free(sem_info
->signal
.sem
);
2860 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2862 const VkSemaphore
*sems
)
2864 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2865 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2867 if (sem
->temp_syncobj
) {
2868 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2869 sem
->temp_syncobj
= 0;
2875 radv_alloc_sem_info(struct radv_instance
*instance
,
2876 struct radv_winsys_sem_info
*sem_info
,
2878 const VkSemaphore
*wait_sems
,
2879 int num_signal_sems
,
2880 const VkSemaphore
*signal_sems
,
2884 memset(sem_info
, 0, sizeof(*sem_info
));
2886 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2889 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2891 radv_free_sem_info(sem_info
);
2893 /* caller can override these */
2894 sem_info
->cs_emit_wait
= true;
2895 sem_info
->cs_emit_signal
= true;
2899 /* Signals fence as soon as all the work currently put on queue is done. */
2900 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2901 struct radv_fence
*fence
)
2905 struct radv_winsys_sem_info sem_info
;
2907 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2908 radv_fence_to_handle(fence
));
2909 if (result
!= VK_SUCCESS
)
2912 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2913 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2914 1, NULL
, NULL
, &sem_info
, NULL
,
2915 false, fence
->fence
);
2916 radv_free_sem_info(&sem_info
);
2919 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2924 VkResult
radv_QueueSubmit(
2926 uint32_t submitCount
,
2927 const VkSubmitInfo
* pSubmits
,
2930 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2931 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2932 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2933 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2935 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
2936 uint32_t scratch_size
= 0;
2937 uint32_t compute_scratch_size
= 0;
2938 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2939 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2941 bool fence_emitted
= false;
2942 bool tess_rings_needed
= false;
2943 bool sample_positions_needed
= false;
2945 /* Do this first so failing to allocate scratch buffers can't result in
2946 * partially executed submissions. */
2947 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2948 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2949 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2950 pSubmits
[i
].pCommandBuffers
[j
]);
2952 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2953 compute_scratch_size
= MAX2(compute_scratch_size
,
2954 cmd_buffer
->compute_scratch_size_needed
);
2955 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2956 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2957 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2958 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2962 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2963 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2964 sample_positions_needed
, &initial_flush_preamble_cs
,
2965 &initial_preamble_cs
, &continue_preamble_cs
);
2966 if (result
!= VK_SUCCESS
)
2969 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2970 struct radeon_cmdbuf
**cs_array
;
2971 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2972 bool can_patch
= true;
2974 struct radv_winsys_sem_info sem_info
;
2976 result
= radv_alloc_sem_info(queue
->device
->instance
,
2978 pSubmits
[i
].waitSemaphoreCount
,
2979 pSubmits
[i
].pWaitSemaphores
,
2980 pSubmits
[i
].signalSemaphoreCount
,
2981 pSubmits
[i
].pSignalSemaphores
,
2983 if (result
!= VK_SUCCESS
)
2986 if (!pSubmits
[i
].commandBufferCount
) {
2987 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2988 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2989 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2994 radv_loge("failed to submit CS %d\n", i
);
2997 fence_emitted
= true;
2999 radv_free_sem_info(&sem_info
);
3003 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3004 (pSubmits
[i
].commandBufferCount
));
3006 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3007 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3008 pSubmits
[i
].pCommandBuffers
[j
]);
3009 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3011 cs_array
[j
] = cmd_buffer
->cs
;
3012 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3015 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3018 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3019 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3020 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3022 advance
= MIN2(max_cs_submission
,
3023 pSubmits
[i
].commandBufferCount
- j
);
3025 if (queue
->device
->trace_bo
)
3026 *queue
->device
->trace_id_ptr
= 0;
3028 sem_info
.cs_emit_wait
= j
== 0;
3029 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3031 if (unlikely(queue
->device
->use_global_bo_list
)) {
3032 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3033 bo_list
= &queue
->device
->bo_list
.list
;
3036 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3037 advance
, initial_preamble
, continue_preamble_cs
,
3039 can_patch
, base_fence
);
3041 if (unlikely(queue
->device
->use_global_bo_list
))
3042 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3045 radv_loge("failed to submit CS %d\n", i
);
3048 fence_emitted
= true;
3049 if (queue
->device
->trace_bo
) {
3050 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3054 radv_free_temp_syncobjs(queue
->device
,
3055 pSubmits
[i
].waitSemaphoreCount
,
3056 pSubmits
[i
].pWaitSemaphores
);
3057 radv_free_sem_info(&sem_info
);
3062 if (!fence_emitted
) {
3063 result
= radv_signal_fence(queue
, fence
);
3064 if (result
!= VK_SUCCESS
)
3072 VkResult
radv_QueueWaitIdle(
3075 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3077 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3078 radv_queue_family_to_ring(queue
->queue_family_index
),
3083 VkResult
radv_DeviceWaitIdle(
3086 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3088 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3089 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3090 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3096 VkResult
radv_EnumerateInstanceExtensionProperties(
3097 const char* pLayerName
,
3098 uint32_t* pPropertyCount
,
3099 VkExtensionProperties
* pProperties
)
3101 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3103 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3104 if (radv_supported_instance_extensions
.extensions
[i
]) {
3105 vk_outarray_append(&out
, prop
) {
3106 *prop
= radv_instance_extensions
[i
];
3111 return vk_outarray_status(&out
);
3114 VkResult
radv_EnumerateDeviceExtensionProperties(
3115 VkPhysicalDevice physicalDevice
,
3116 const char* pLayerName
,
3117 uint32_t* pPropertyCount
,
3118 VkExtensionProperties
* pProperties
)
3120 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3121 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3123 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3124 if (device
->supported_extensions
.extensions
[i
]) {
3125 vk_outarray_append(&out
, prop
) {
3126 *prop
= radv_device_extensions
[i
];
3131 return vk_outarray_status(&out
);
3134 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3135 VkInstance _instance
,
3138 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3140 return radv_lookup_entrypoint_checked(pName
,
3141 instance
? instance
->apiVersion
: 0,
3142 instance
? &instance
->enabled_extensions
: NULL
,
3146 /* The loader wants us to expose a second GetInstanceProcAddr function
3147 * to work around certain LD_PRELOAD issues seen in apps.
3150 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3151 VkInstance instance
,
3155 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3156 VkInstance instance
,
3159 return radv_GetInstanceProcAddr(instance
, pName
);
3163 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3164 VkInstance _instance
,
3168 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3169 VkInstance _instance
,
3172 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3174 return radv_lookup_physical_device_entrypoint_checked(pName
,
3175 instance
? instance
->apiVersion
: 0,
3176 instance
? &instance
->enabled_extensions
: NULL
);
3179 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3183 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3185 return radv_lookup_entrypoint_checked(pName
,
3186 device
->instance
->apiVersion
,
3187 &device
->instance
->enabled_extensions
,
3188 &device
->enabled_extensions
);
3191 bool radv_get_memory_fd(struct radv_device
*device
,
3192 struct radv_device_memory
*memory
,
3195 struct radeon_bo_metadata metadata
;
3197 if (memory
->image
) {
3198 radv_init_metadata(device
, memory
->image
, &metadata
);
3199 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3202 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3206 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3207 const VkMemoryAllocateInfo
* pAllocateInfo
,
3208 const VkAllocationCallbacks
* pAllocator
,
3209 VkDeviceMemory
* pMem
)
3211 struct radv_device_memory
*mem
;
3213 enum radeon_bo_domain domain
;
3215 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3217 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3219 if (pAllocateInfo
->allocationSize
== 0) {
3220 /* Apparently, this is allowed */
3221 *pMem
= VK_NULL_HANDLE
;
3225 const VkImportMemoryFdInfoKHR
*import_info
=
3226 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3227 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3228 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3229 const VkExportMemoryAllocateInfo
*export_info
=
3230 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3231 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3232 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3234 const struct wsi_memory_allocate_info
*wsi_info
=
3235 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3237 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3238 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3240 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3242 if (wsi_info
&& wsi_info
->implicit_sync
)
3243 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3245 if (dedicate_info
) {
3246 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3247 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3253 float priority_float
= 0.5;
3254 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3255 vk_find_struct_const(pAllocateInfo
->pNext
,
3256 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3258 priority_float
= priority_ext
->priority
;
3260 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3261 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3263 mem
->user_ptr
= NULL
;
3266 assert(import_info
->handleType
==
3267 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3268 import_info
->handleType
==
3269 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3270 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3271 priority
, NULL
, NULL
);
3273 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3276 close(import_info
->fd
);
3278 } else if (host_ptr_info
) {
3279 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3280 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3281 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3282 pAllocateInfo
->allocationSize
,
3285 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3288 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3291 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3292 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3293 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3294 domain
= RADEON_DOMAIN_GTT
;
3296 domain
= RADEON_DOMAIN_VRAM
;
3298 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3299 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3301 flags
|= RADEON_FLAG_CPU_ACCESS
;
3303 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3304 flags
|= RADEON_FLAG_GTT_WC
;
3306 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3307 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3308 if (device
->use_global_bo_list
) {
3309 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3313 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3314 domain
, flags
, priority
);
3317 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3320 mem
->type_index
= mem_type_index
;
3323 result
= radv_bo_list_add(device
, mem
->bo
);
3324 if (result
!= VK_SUCCESS
)
3327 *pMem
= radv_device_memory_to_handle(mem
);
3332 device
->ws
->buffer_destroy(mem
->bo
);
3334 vk_free2(&device
->alloc
, pAllocator
, mem
);
3339 VkResult
radv_AllocateMemory(
3341 const VkMemoryAllocateInfo
* pAllocateInfo
,
3342 const VkAllocationCallbacks
* pAllocator
,
3343 VkDeviceMemory
* pMem
)
3345 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3346 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3349 void radv_FreeMemory(
3351 VkDeviceMemory _mem
,
3352 const VkAllocationCallbacks
* pAllocator
)
3354 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3355 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3360 radv_bo_list_remove(device
, mem
->bo
);
3361 device
->ws
->buffer_destroy(mem
->bo
);
3364 vk_free2(&device
->alloc
, pAllocator
, mem
);
3367 VkResult
radv_MapMemory(
3369 VkDeviceMemory _memory
,
3370 VkDeviceSize offset
,
3372 VkMemoryMapFlags flags
,
3375 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3376 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3384 *ppData
= mem
->user_ptr
;
3386 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3393 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3396 void radv_UnmapMemory(
3398 VkDeviceMemory _memory
)
3400 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3401 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3406 if (mem
->user_ptr
== NULL
)
3407 device
->ws
->buffer_unmap(mem
->bo
);
3410 VkResult
radv_FlushMappedMemoryRanges(
3412 uint32_t memoryRangeCount
,
3413 const VkMappedMemoryRange
* pMemoryRanges
)
3418 VkResult
radv_InvalidateMappedMemoryRanges(
3420 uint32_t memoryRangeCount
,
3421 const VkMappedMemoryRange
* pMemoryRanges
)
3426 void radv_GetBufferMemoryRequirements(
3429 VkMemoryRequirements
* pMemoryRequirements
)
3431 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3432 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3434 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3436 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3437 pMemoryRequirements
->alignment
= 4096;
3439 pMemoryRequirements
->alignment
= 16;
3441 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3444 void radv_GetBufferMemoryRequirements2(
3446 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3447 VkMemoryRequirements2
*pMemoryRequirements
)
3449 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3450 &pMemoryRequirements
->memoryRequirements
);
3451 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3452 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3453 switch (ext
->sType
) {
3454 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3455 VkMemoryDedicatedRequirements
*req
=
3456 (VkMemoryDedicatedRequirements
*) ext
;
3457 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3458 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3467 void radv_GetImageMemoryRequirements(
3470 VkMemoryRequirements
* pMemoryRequirements
)
3472 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3473 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3475 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3477 pMemoryRequirements
->size
= image
->size
;
3478 pMemoryRequirements
->alignment
= image
->alignment
;
3481 void radv_GetImageMemoryRequirements2(
3483 const VkImageMemoryRequirementsInfo2
*pInfo
,
3484 VkMemoryRequirements2
*pMemoryRequirements
)
3486 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3487 &pMemoryRequirements
->memoryRequirements
);
3489 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3491 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3492 switch (ext
->sType
) {
3493 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3494 VkMemoryDedicatedRequirements
*req
=
3495 (VkMemoryDedicatedRequirements
*) ext
;
3496 req
->requiresDedicatedAllocation
= image
->shareable
;
3497 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3506 void radv_GetImageSparseMemoryRequirements(
3509 uint32_t* pSparseMemoryRequirementCount
,
3510 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3515 void radv_GetImageSparseMemoryRequirements2(
3517 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3518 uint32_t* pSparseMemoryRequirementCount
,
3519 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3524 void radv_GetDeviceMemoryCommitment(
3526 VkDeviceMemory memory
,
3527 VkDeviceSize
* pCommittedMemoryInBytes
)
3529 *pCommittedMemoryInBytes
= 0;
3532 VkResult
radv_BindBufferMemory2(VkDevice device
,
3533 uint32_t bindInfoCount
,
3534 const VkBindBufferMemoryInfo
*pBindInfos
)
3536 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3537 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3538 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3541 buffer
->bo
= mem
->bo
;
3542 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3550 VkResult
radv_BindBufferMemory(
3553 VkDeviceMemory memory
,
3554 VkDeviceSize memoryOffset
)
3556 const VkBindBufferMemoryInfo info
= {
3557 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3560 .memoryOffset
= memoryOffset
3563 return radv_BindBufferMemory2(device
, 1, &info
);
3566 VkResult
radv_BindImageMemory2(VkDevice device
,
3567 uint32_t bindInfoCount
,
3568 const VkBindImageMemoryInfo
*pBindInfos
)
3570 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3571 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3572 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3575 image
->bo
= mem
->bo
;
3576 image
->offset
= pBindInfos
[i
].memoryOffset
;
3586 VkResult
radv_BindImageMemory(
3589 VkDeviceMemory memory
,
3590 VkDeviceSize memoryOffset
)
3592 const VkBindImageMemoryInfo info
= {
3593 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3596 .memoryOffset
= memoryOffset
3599 return radv_BindImageMemory2(device
, 1, &info
);
3604 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3605 const VkSparseBufferMemoryBindInfo
*bind
)
3607 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3609 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3610 struct radv_device_memory
*mem
= NULL
;
3612 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3613 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3615 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3616 bind
->pBinds
[i
].resourceOffset
,
3617 bind
->pBinds
[i
].size
,
3618 mem
? mem
->bo
: NULL
,
3619 bind
->pBinds
[i
].memoryOffset
);
3624 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3625 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3627 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3629 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3630 struct radv_device_memory
*mem
= NULL
;
3632 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3633 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3635 device
->ws
->buffer_virtual_bind(image
->bo
,
3636 bind
->pBinds
[i
].resourceOffset
,
3637 bind
->pBinds
[i
].size
,
3638 mem
? mem
->bo
: NULL
,
3639 bind
->pBinds
[i
].memoryOffset
);
3643 VkResult
radv_QueueBindSparse(
3645 uint32_t bindInfoCount
,
3646 const VkBindSparseInfo
* pBindInfo
,
3649 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3650 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3651 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3652 bool fence_emitted
= false;
3656 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3657 struct radv_winsys_sem_info sem_info
;
3658 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3659 radv_sparse_buffer_bind_memory(queue
->device
,
3660 pBindInfo
[i
].pBufferBinds
+ j
);
3663 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3664 radv_sparse_image_opaque_bind_memory(queue
->device
,
3665 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3669 result
= radv_alloc_sem_info(queue
->device
->instance
,
3671 pBindInfo
[i
].waitSemaphoreCount
,
3672 pBindInfo
[i
].pWaitSemaphores
,
3673 pBindInfo
[i
].signalSemaphoreCount
,
3674 pBindInfo
[i
].pSignalSemaphores
,
3676 if (result
!= VK_SUCCESS
)
3679 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3680 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3681 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3686 radv_loge("failed to submit CS %d\n", i
);
3690 fence_emitted
= true;
3693 radv_free_sem_info(&sem_info
);
3698 if (!fence_emitted
) {
3699 result
= radv_signal_fence(queue
, fence
);
3700 if (result
!= VK_SUCCESS
)
3708 VkResult
radv_CreateFence(
3710 const VkFenceCreateInfo
* pCreateInfo
,
3711 const VkAllocationCallbacks
* pAllocator
,
3714 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3715 const VkExportFenceCreateInfo
*export
=
3716 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3717 VkExternalFenceHandleTypeFlags handleTypes
=
3718 export
? export
->handleTypes
: 0;
3720 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3722 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3725 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3727 fence
->fence_wsi
= NULL
;
3728 fence
->temp_syncobj
= 0;
3729 if (device
->always_use_syncobj
|| handleTypes
) {
3730 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3732 vk_free2(&device
->alloc
, pAllocator
, fence
);
3733 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3735 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3736 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3738 fence
->fence
= NULL
;
3740 fence
->fence
= device
->ws
->create_fence();
3741 if (!fence
->fence
) {
3742 vk_free2(&device
->alloc
, pAllocator
, fence
);
3743 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3746 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3747 device
->ws
->signal_fence(fence
->fence
);
3750 *pFence
= radv_fence_to_handle(fence
);
3755 void radv_DestroyFence(
3758 const VkAllocationCallbacks
* pAllocator
)
3760 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3761 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3766 if (fence
->temp_syncobj
)
3767 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3769 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3771 device
->ws
->destroy_fence(fence
->fence
);
3772 if (fence
->fence_wsi
)
3773 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3774 vk_free2(&device
->alloc
, pAllocator
, fence
);
3778 uint64_t radv_get_current_time(void)
3781 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3782 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3785 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3787 uint64_t current_time
= radv_get_current_time();
3789 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3791 return current_time
+ timeout
;
3795 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
3796 uint32_t fenceCount
, const VkFence
*pFences
)
3798 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3799 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3800 if (fence
->fence
== NULL
|| fence
->syncobj
||
3801 fence
->temp_syncobj
|| fence
->fence_wsi
||
3802 (!device
->ws
->is_fence_waitable(fence
->fence
)))
3808 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3810 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3811 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3812 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3818 VkResult
radv_WaitForFences(
3820 uint32_t fenceCount
,
3821 const VkFence
* pFences
,
3825 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3826 timeout
= radv_get_absolute_timeout(timeout
);
3828 if (device
->always_use_syncobj
&&
3829 radv_all_fences_syncobj(fenceCount
, pFences
))
3831 uint32_t *handles
= malloc(sizeof(uint32_t) * 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
]);
3837 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3840 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3843 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3846 if (!waitAll
&& fenceCount
> 1) {
3847 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3848 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
3849 uint32_t wait_count
= 0;
3850 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3852 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3854 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3855 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3857 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
3862 fences
[wait_count
++] = fence
->fence
;
3865 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3866 waitAll
, timeout
- radv_get_current_time());
3869 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3872 while(radv_get_current_time() <= timeout
) {
3873 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3874 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3881 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3882 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3883 bool expired
= false;
3885 if (fence
->temp_syncobj
) {
3886 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3891 if (fence
->syncobj
) {
3892 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3898 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
3899 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
3900 radv_get_current_time() <= timeout
)
3904 expired
= device
->ws
->fence_wait(device
->ws
,
3911 if (fence
->fence_wsi
) {
3912 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3913 if (result
!= VK_SUCCESS
)
3921 VkResult
radv_ResetFences(VkDevice _device
,
3922 uint32_t fenceCount
,
3923 const VkFence
*pFences
)
3925 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3927 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3928 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3930 device
->ws
->reset_fence(fence
->fence
);
3932 /* Per spec, we first restore the permanent payload, and then reset, so
3933 * having a temp syncobj should not skip resetting the permanent syncobj. */
3934 if (fence
->temp_syncobj
) {
3935 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3936 fence
->temp_syncobj
= 0;
3939 if (fence
->syncobj
) {
3940 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3947 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3949 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3950 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3952 if (fence
->temp_syncobj
) {
3953 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3954 return success
? VK_SUCCESS
: VK_NOT_READY
;
3957 if (fence
->syncobj
) {
3958 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3959 return success
? VK_SUCCESS
: VK_NOT_READY
;
3963 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3964 return VK_NOT_READY
;
3966 if (fence
->fence_wsi
) {
3967 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
3969 if (result
!= VK_SUCCESS
) {
3970 if (result
== VK_TIMEOUT
)
3971 return VK_NOT_READY
;
3979 // Queue semaphore functions
3981 VkResult
radv_CreateSemaphore(
3983 const VkSemaphoreCreateInfo
* pCreateInfo
,
3984 const VkAllocationCallbacks
* pAllocator
,
3985 VkSemaphore
* pSemaphore
)
3987 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3988 const VkExportSemaphoreCreateInfo
*export
=
3989 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
3990 VkExternalSemaphoreHandleTypeFlags handleTypes
=
3991 export
? export
->handleTypes
: 0;
3993 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3995 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3997 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3999 sem
->temp_syncobj
= 0;
4000 /* create a syncobject if we are going to export this semaphore */
4001 if (device
->always_use_syncobj
|| handleTypes
) {
4002 assert (device
->physical_device
->rad_info
.has_syncobj
);
4003 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4005 vk_free2(&device
->alloc
, pAllocator
, sem
);
4006 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4010 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4012 vk_free2(&device
->alloc
, pAllocator
, sem
);
4013 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4018 *pSemaphore
= radv_semaphore_to_handle(sem
);
4022 void radv_DestroySemaphore(
4024 VkSemaphore _semaphore
,
4025 const VkAllocationCallbacks
* pAllocator
)
4027 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4028 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4033 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4035 device
->ws
->destroy_sem(sem
->sem
);
4036 vk_free2(&device
->alloc
, pAllocator
, sem
);
4039 VkResult
radv_CreateEvent(
4041 const VkEventCreateInfo
* pCreateInfo
,
4042 const VkAllocationCallbacks
* pAllocator
,
4045 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4046 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4048 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4051 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4053 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4055 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4056 RADV_BO_PRIORITY_FENCE
);
4058 vk_free2(&device
->alloc
, pAllocator
, event
);
4059 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4062 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4064 *pEvent
= radv_event_to_handle(event
);
4069 void radv_DestroyEvent(
4072 const VkAllocationCallbacks
* pAllocator
)
4074 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4075 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4079 device
->ws
->buffer_destroy(event
->bo
);
4080 vk_free2(&device
->alloc
, pAllocator
, event
);
4083 VkResult
radv_GetEventStatus(
4087 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4089 if (*event
->map
== 1)
4090 return VK_EVENT_SET
;
4091 return VK_EVENT_RESET
;
4094 VkResult
radv_SetEvent(
4098 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4104 VkResult
radv_ResetEvent(
4108 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4114 VkResult
radv_CreateBuffer(
4116 const VkBufferCreateInfo
* pCreateInfo
,
4117 const VkAllocationCallbacks
* pAllocator
,
4120 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4121 struct radv_buffer
*buffer
;
4123 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4125 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4126 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4128 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4130 buffer
->size
= pCreateInfo
->size
;
4131 buffer
->usage
= pCreateInfo
->usage
;
4134 buffer
->flags
= pCreateInfo
->flags
;
4136 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4137 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4139 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4140 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4141 align64(buffer
->size
, 4096),
4142 4096, 0, RADEON_FLAG_VIRTUAL
,
4143 RADV_BO_PRIORITY_VIRTUAL
);
4145 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4146 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4150 *pBuffer
= radv_buffer_to_handle(buffer
);
4155 void radv_DestroyBuffer(
4158 const VkAllocationCallbacks
* pAllocator
)
4160 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4161 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4166 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4167 device
->ws
->buffer_destroy(buffer
->bo
);
4169 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4172 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4174 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4176 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4177 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4181 static inline unsigned
4182 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4185 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4187 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4190 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4192 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4196 radv_init_dcc_control_reg(struct radv_device
*device
,
4197 struct radv_image_view
*iview
)
4199 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4200 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4201 unsigned max_compressed_block_size
;
4202 unsigned independent_64b_blocks
;
4204 if (!radv_image_has_dcc(iview
->image
))
4207 if (iview
->image
->info
.samples
> 1) {
4208 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4209 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4210 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4211 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4214 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4215 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4216 * dGPU and 64 for APU because all of our APUs to date use
4217 * DIMMs which have a request granularity size of 64B while all
4218 * other chips have a 32B request size.
4220 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4223 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4224 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4225 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4226 /* If this DCC image is potentially going to be used in texture
4227 * fetches, we need some special settings.
4229 independent_64b_blocks
= 1;
4230 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4232 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4233 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4234 * big as possible for better compression state.
4236 independent_64b_blocks
= 0;
4237 max_compressed_block_size
= max_uncompressed_block_size
;
4240 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4241 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4242 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4243 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
4247 radv_initialise_color_surface(struct radv_device
*device
,
4248 struct radv_color_buffer_info
*cb
,
4249 struct radv_image_view
*iview
)
4251 const struct vk_format_description
*desc
;
4252 unsigned ntype
, format
, swap
, endian
;
4253 unsigned blend_clamp
= 0, blend_bypass
= 0;
4255 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4256 const struct radeon_surf
*surf
= &plane
->surface
;
4258 desc
= vk_format_description(iview
->vk_format
);
4260 memset(cb
, 0, sizeof(*cb
));
4262 /* Intensity is implemented as Red, so treat it that way. */
4263 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4265 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4267 cb
->cb_color_base
= va
>> 8;
4269 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4270 struct gfx9_surf_meta_flags meta
;
4271 if (iview
->image
->dcc_offset
)
4272 meta
= surf
->u
.gfx9
.dcc
;
4274 meta
= surf
->u
.gfx9
.cmask
;
4276 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4277 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4278 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4279 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4281 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4282 cb
->cb_color_base
|= surf
->tile_swizzle
;
4284 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4286 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4287 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4289 cb
->cb_color_base
+= level_info
->offset
>> 8;
4290 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4291 cb
->cb_color_base
|= surf
->tile_swizzle
;
4293 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4294 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4295 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4297 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4298 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4299 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
4301 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4303 if (radv_image_has_fmask(iview
->image
)) {
4304 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4305 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
4306 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4307 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4309 /* This must be set for fast clear to work without FMASK. */
4310 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4311 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4312 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4313 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4317 /* CMASK variables */
4318 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4319 va
+= iview
->image
->cmask
.offset
;
4320 cb
->cb_color_cmask
= va
>> 8;
4322 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4323 va
+= iview
->image
->dcc_offset
;
4324 cb
->cb_dcc_base
= va
>> 8;
4325 cb
->cb_dcc_base
|= surf
->tile_swizzle
;
4327 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4328 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4329 S_028C6C_SLICE_MAX(max_slice
);
4331 if (iview
->image
->info
.samples
> 1) {
4332 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4334 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4335 S_028C74_NUM_FRAGMENTS(log_samples
);
4338 if (radv_image_has_fmask(iview
->image
)) {
4339 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4340 cb
->cb_color_fmask
= va
>> 8;
4341 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4343 cb
->cb_color_fmask
= cb
->cb_color_base
;
4346 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4348 vk_format_get_first_non_void_channel(iview
->vk_format
));
4349 format
= radv_translate_colorformat(iview
->vk_format
);
4350 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4351 radv_finishme("Illegal color\n");
4352 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4353 endian
= radv_colorformat_endian_swap(format
);
4355 /* blend clamp should be set for all NORM/SRGB types */
4356 if (ntype
== V_028C70_NUMBER_UNORM
||
4357 ntype
== V_028C70_NUMBER_SNORM
||
4358 ntype
== V_028C70_NUMBER_SRGB
)
4361 /* set blend bypass according to docs if SINT/UINT or
4362 8/24 COLOR variants */
4363 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4364 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4365 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4370 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4371 (format
== V_028C70_COLOR_8
||
4372 format
== V_028C70_COLOR_8_8
||
4373 format
== V_028C70_COLOR_8_8_8_8
))
4374 ->color_is_int8
= true;
4376 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4377 S_028C70_COMP_SWAP(swap
) |
4378 S_028C70_BLEND_CLAMP(blend_clamp
) |
4379 S_028C70_BLEND_BYPASS(blend_bypass
) |
4380 S_028C70_SIMPLE_FLOAT(1) |
4381 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4382 ntype
!= V_028C70_NUMBER_SNORM
&&
4383 ntype
!= V_028C70_NUMBER_SRGB
&&
4384 format
!= V_028C70_COLOR_8_24
&&
4385 format
!= V_028C70_COLOR_24_8
) |
4386 S_028C70_NUMBER_TYPE(ntype
) |
4387 S_028C70_ENDIAN(endian
);
4388 if (radv_image_has_fmask(iview
->image
)) {
4389 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4390 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4391 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4392 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4396 if (radv_image_has_cmask(iview
->image
) &&
4397 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4398 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4400 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4401 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4403 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4405 /* This must be set for fast clear to work without FMASK. */
4406 if (!radv_image_has_fmask(iview
->image
) &&
4407 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4408 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4409 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4412 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4413 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4415 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4416 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4417 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4418 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4420 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
4421 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4422 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4423 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4424 S_028C68_MIP0_HEIGHT(height
- 1) |
4425 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4430 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4431 struct radv_image_view
*iview
)
4433 unsigned max_zplanes
= 0;
4435 assert(radv_image_is_tc_compat_htile(iview
->image
));
4437 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4438 /* Default value for 32-bit depth surfaces. */
4441 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4442 iview
->image
->info
.samples
> 1)
4445 max_zplanes
= max_zplanes
+ 1;
4447 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4448 /* Do not enable Z plane compression for 16-bit depth
4449 * surfaces because isn't supported on GFX8. Only
4450 * 32-bit depth surfaces are supported by the hardware.
4451 * This allows to maintain shader compatibility and to
4452 * reduce the number of depth decompressions.
4456 if (iview
->image
->info
.samples
<= 1)
4458 else if (iview
->image
->info
.samples
<= 4)
4469 radv_initialise_ds_surface(struct radv_device
*device
,
4470 struct radv_ds_buffer_info
*ds
,
4471 struct radv_image_view
*iview
)
4473 unsigned level
= iview
->base_mip
;
4474 unsigned format
, stencil_format
;
4475 uint64_t va
, s_offs
, z_offs
;
4476 bool stencil_only
= false;
4477 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4478 const struct radeon_surf
*surf
= &plane
->surface
;
4480 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4482 memset(ds
, 0, sizeof(*ds
));
4483 switch (iview
->image
->vk_format
) {
4484 case VK_FORMAT_D24_UNORM_S8_UINT
:
4485 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4486 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4487 ds
->offset_scale
= 2.0f
;
4489 case VK_FORMAT_D16_UNORM
:
4490 case VK_FORMAT_D16_UNORM_S8_UINT
:
4491 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4492 ds
->offset_scale
= 4.0f
;
4494 case VK_FORMAT_D32_SFLOAT
:
4495 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4496 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4497 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4498 ds
->offset_scale
= 1.0f
;
4500 case VK_FORMAT_S8_UINT
:
4501 stencil_only
= true;
4507 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4508 stencil_format
= surf
->has_stencil
?
4509 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4511 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4512 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4513 S_028008_SLICE_MAX(max_slice
);
4515 ds
->db_htile_data_base
= 0;
4516 ds
->db_htile_surface
= 0;
4518 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4519 s_offs
= z_offs
= va
;
4521 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4522 assert(surf
->u
.gfx9
.surf_offset
== 0);
4523 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4525 ds
->db_z_info
= S_028038_FORMAT(format
) |
4526 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4527 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4528 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4529 S_028038_ZRANGE_PRECISION(1);
4530 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4531 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4533 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4534 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4535 ds
->db_depth_view
|= S_028008_MIPID(level
);
4537 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4538 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4540 if (radv_htile_enabled(iview
->image
, level
)) {
4541 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4543 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4544 unsigned max_zplanes
=
4545 radv_calc_decompress_on_z_planes(device
, iview
);
4547 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4548 S_028038_ITERATE_FLUSH(1);
4549 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4552 if (!surf
->has_stencil
)
4553 /* Use all of the htile_buffer for depth if there's no stencil. */
4554 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4555 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4556 iview
->image
->htile_offset
;
4557 ds
->db_htile_data_base
= va
>> 8;
4558 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4559 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
) |
4560 S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4563 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4566 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4568 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4569 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4571 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4572 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4573 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4575 if (iview
->image
->info
.samples
> 1)
4576 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4578 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4579 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4580 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4581 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4582 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4583 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4584 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4585 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4588 tile_mode
= stencil_tile_mode
;
4590 ds
->db_depth_info
|=
4591 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4592 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4593 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4594 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4595 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4596 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4597 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4598 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4600 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4601 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4602 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4603 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4605 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4608 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4609 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4610 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4612 if (radv_htile_enabled(iview
->image
, level
)) {
4613 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4615 if (!surf
->has_stencil
&&
4616 !radv_image_is_tc_compat_htile(iview
->image
))
4617 /* Use all of the htile_buffer for depth if there's no stencil. */
4618 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4620 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4621 iview
->image
->htile_offset
;
4622 ds
->db_htile_data_base
= va
>> 8;
4623 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4625 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4626 unsigned max_zplanes
=
4627 radv_calc_decompress_on_z_planes(device
, iview
);
4629 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4630 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4635 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4636 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4639 VkResult
radv_CreateFramebuffer(
4641 const VkFramebufferCreateInfo
* pCreateInfo
,
4642 const VkAllocationCallbacks
* pAllocator
,
4643 VkFramebuffer
* pFramebuffer
)
4645 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4646 struct radv_framebuffer
*framebuffer
;
4648 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4650 size_t size
= sizeof(*framebuffer
) +
4651 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4652 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4653 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4654 if (framebuffer
== NULL
)
4655 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4657 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4658 framebuffer
->width
= pCreateInfo
->width
;
4659 framebuffer
->height
= pCreateInfo
->height
;
4660 framebuffer
->layers
= pCreateInfo
->layers
;
4661 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4662 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4663 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4664 framebuffer
->attachments
[i
].attachment
= iview
;
4665 if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4666 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4668 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4670 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4671 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4672 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4675 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4679 void radv_DestroyFramebuffer(
4682 const VkAllocationCallbacks
* pAllocator
)
4684 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4685 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4689 vk_free2(&device
->alloc
, pAllocator
, fb
);
4692 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4694 switch (address_mode
) {
4695 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4696 return V_008F30_SQ_TEX_WRAP
;
4697 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4698 return V_008F30_SQ_TEX_MIRROR
;
4699 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4700 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4701 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4702 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4703 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4704 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4706 unreachable("illegal tex wrap mode");
4712 radv_tex_compare(VkCompareOp op
)
4715 case VK_COMPARE_OP_NEVER
:
4716 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4717 case VK_COMPARE_OP_LESS
:
4718 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4719 case VK_COMPARE_OP_EQUAL
:
4720 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4721 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4722 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4723 case VK_COMPARE_OP_GREATER
:
4724 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4725 case VK_COMPARE_OP_NOT_EQUAL
:
4726 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4727 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4728 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4729 case VK_COMPARE_OP_ALWAYS
:
4730 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4732 unreachable("illegal compare mode");
4738 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4741 case VK_FILTER_NEAREST
:
4742 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4743 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4744 case VK_FILTER_LINEAR
:
4745 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4746 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4747 case VK_FILTER_CUBIC_IMG
:
4749 fprintf(stderr
, "illegal texture filter");
4755 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4758 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4759 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4760 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4761 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4763 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4768 radv_tex_bordercolor(VkBorderColor bcolor
)
4771 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4772 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4773 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4774 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4775 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4776 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4777 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4778 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4779 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4787 radv_tex_aniso_filter(unsigned filter
)
4801 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4804 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4805 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4806 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4807 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
4808 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4809 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
4817 radv_get_max_anisotropy(struct radv_device
*device
,
4818 const VkSamplerCreateInfo
*pCreateInfo
)
4820 if (device
->force_aniso
>= 0)
4821 return device
->force_aniso
;
4823 if (pCreateInfo
->anisotropyEnable
&&
4824 pCreateInfo
->maxAnisotropy
> 1.0f
)
4825 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4831 radv_init_sampler(struct radv_device
*device
,
4832 struct radv_sampler
*sampler
,
4833 const VkSamplerCreateInfo
*pCreateInfo
)
4835 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4836 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4837 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= GFX8
);
4838 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4840 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4841 vk_find_struct_const(pCreateInfo
->pNext
,
4842 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4843 if (sampler_reduction
)
4844 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4846 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4847 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4848 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4849 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4850 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4851 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4852 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4853 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4854 S_008F30_DISABLE_CUBE_WRAP(0) |
4855 S_008F30_COMPAT_MODE(is_vi
) |
4856 S_008F30_FILTER_MODE(filter_mode
));
4857 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4858 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4859 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4860 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4861 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4862 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4863 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4864 S_008F38_MIP_POINT_PRECLAMP(0) |
4865 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
4866 S_008F38_FILTER_PREC_FIX(1) |
4867 S_008F38_ANISO_OVERRIDE(is_vi
));
4868 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4869 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4872 VkResult
radv_CreateSampler(
4874 const VkSamplerCreateInfo
* pCreateInfo
,
4875 const VkAllocationCallbacks
* pAllocator
,
4876 VkSampler
* pSampler
)
4878 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4879 struct radv_sampler
*sampler
;
4881 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
4882 vk_find_struct_const(pCreateInfo
->pNext
,
4883 SAMPLER_YCBCR_CONVERSION_INFO
);
4885 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4887 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4888 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4890 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4892 radv_init_sampler(device
, sampler
, pCreateInfo
);
4894 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
4895 *pSampler
= radv_sampler_to_handle(sampler
);
4900 void radv_DestroySampler(
4903 const VkAllocationCallbacks
* pAllocator
)
4905 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4906 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4910 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4913 /* vk_icd.h does not declare this function, so we declare it here to
4914 * suppress Wmissing-prototypes.
4916 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4917 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4919 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4920 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4922 /* For the full details on loader interface versioning, see
4923 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4924 * What follows is a condensed summary, to help you navigate the large and
4925 * confusing official doc.
4927 * - Loader interface v0 is incompatible with later versions. We don't
4930 * - In loader interface v1:
4931 * - The first ICD entrypoint called by the loader is
4932 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4934 * - The ICD must statically expose no other Vulkan symbol unless it is
4935 * linked with -Bsymbolic.
4936 * - Each dispatchable Vulkan handle created by the ICD must be
4937 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4938 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4939 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4940 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4941 * such loader-managed surfaces.
4943 * - Loader interface v2 differs from v1 in:
4944 * - The first ICD entrypoint called by the loader is
4945 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4946 * statically expose this entrypoint.
4948 * - Loader interface v3 differs from v2 in:
4949 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4950 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4951 * because the loader no longer does so.
4953 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
4957 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4958 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4961 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4962 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4964 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4966 /* At the moment, we support only the below handle types. */
4967 assert(pGetFdInfo
->handleType
==
4968 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
4969 pGetFdInfo
->handleType
==
4970 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4972 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4974 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4978 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4979 VkExternalMemoryHandleTypeFlagBits handleType
,
4981 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4983 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4985 switch (handleType
) {
4986 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4987 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4991 /* The valid usage section for this function says:
4993 * "handleType must not be one of the handle types defined as
4996 * So opaque handle types fall into the default "unsupported" case.
4998 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5002 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5006 uint32_t syncobj_handle
= 0;
5007 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5009 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5012 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5014 *syncobj
= syncobj_handle
;
5020 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5024 /* If we create a syncobj we do it locally so that if we have an error, we don't
5025 * leave a syncobj in an undetermined state in the fence. */
5026 uint32_t syncobj_handle
= *syncobj
;
5027 if (!syncobj_handle
) {
5028 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5030 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5035 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5037 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5039 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5042 *syncobj
= syncobj_handle
;
5049 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5050 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5052 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5053 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5054 uint32_t *syncobj_dst
= NULL
;
5056 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5057 syncobj_dst
= &sem
->temp_syncobj
;
5059 syncobj_dst
= &sem
->syncobj
;
5062 switch(pImportSemaphoreFdInfo
->handleType
) {
5063 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5064 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5065 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5066 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5068 unreachable("Unhandled semaphore handle type");
5072 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5073 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5076 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5077 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5079 uint32_t syncobj_handle
;
5081 if (sem
->temp_syncobj
)
5082 syncobj_handle
= sem
->temp_syncobj
;
5084 syncobj_handle
= sem
->syncobj
;
5086 switch(pGetFdInfo
->handleType
) {
5087 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5088 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5090 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5091 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5093 if (sem
->temp_syncobj
) {
5094 close (sem
->temp_syncobj
);
5095 sem
->temp_syncobj
= 0;
5097 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5102 unreachable("Unhandled semaphore handle type");
5106 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5110 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5111 VkPhysicalDevice physicalDevice
,
5112 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5113 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5115 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5117 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5118 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5119 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5120 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5121 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5122 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5123 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5124 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5125 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5126 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5127 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5128 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5129 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5131 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5132 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5133 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5137 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5138 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5140 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5141 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5142 uint32_t *syncobj_dst
= NULL
;
5145 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5146 syncobj_dst
= &fence
->temp_syncobj
;
5148 syncobj_dst
= &fence
->syncobj
;
5151 switch(pImportFenceFdInfo
->handleType
) {
5152 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5153 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5154 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5155 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5157 unreachable("Unhandled fence handle type");
5161 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5162 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5165 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5166 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5168 uint32_t syncobj_handle
;
5170 if (fence
->temp_syncobj
)
5171 syncobj_handle
= fence
->temp_syncobj
;
5173 syncobj_handle
= fence
->syncobj
;
5175 switch(pGetFdInfo
->handleType
) {
5176 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5177 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5179 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5180 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5182 if (fence
->temp_syncobj
) {
5183 close (fence
->temp_syncobj
);
5184 fence
->temp_syncobj
= 0;
5186 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5191 unreachable("Unhandled fence handle type");
5195 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5199 void radv_GetPhysicalDeviceExternalFenceProperties(
5200 VkPhysicalDevice physicalDevice
,
5201 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5202 VkExternalFenceProperties
*pExternalFenceProperties
)
5204 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5206 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5207 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5208 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5209 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5210 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5211 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5212 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5214 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5215 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5216 pExternalFenceProperties
->externalFenceFeatures
= 0;
5221 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5222 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5223 const VkAllocationCallbacks
* pAllocator
,
5224 VkDebugReportCallbackEXT
* pCallback
)
5226 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5227 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5228 pCreateInfo
, pAllocator
, &instance
->alloc
,
5233 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5234 VkDebugReportCallbackEXT _callback
,
5235 const VkAllocationCallbacks
* pAllocator
)
5237 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5238 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5239 _callback
, pAllocator
, &instance
->alloc
);
5243 radv_DebugReportMessageEXT(VkInstance _instance
,
5244 VkDebugReportFlagsEXT flags
,
5245 VkDebugReportObjectTypeEXT objectType
,
5248 int32_t messageCode
,
5249 const char* pLayerPrefix
,
5250 const char* pMessage
)
5252 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5253 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5254 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5258 radv_GetDeviceGroupPeerMemoryFeatures(
5261 uint32_t localDeviceIndex
,
5262 uint32_t remoteDeviceIndex
,
5263 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5265 assert(localDeviceIndex
== remoteDeviceIndex
);
5267 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5268 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5269 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5270 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5273 static const VkTimeDomainEXT radv_time_domains
[] = {
5274 VK_TIME_DOMAIN_DEVICE_EXT
,
5275 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5276 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5279 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5280 VkPhysicalDevice physicalDevice
,
5281 uint32_t *pTimeDomainCount
,
5282 VkTimeDomainEXT
*pTimeDomains
)
5285 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5287 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5288 vk_outarray_append(&out
, i
) {
5289 *i
= radv_time_domains
[d
];
5293 return vk_outarray_status(&out
);
5297 radv_clock_gettime(clockid_t clock_id
)
5299 struct timespec current
;
5302 ret
= clock_gettime(clock_id
, ¤t
);
5303 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5304 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5308 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5311 VkResult
radv_GetCalibratedTimestampsEXT(
5313 uint32_t timestampCount
,
5314 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5315 uint64_t *pTimestamps
,
5316 uint64_t *pMaxDeviation
)
5318 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5319 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5321 uint64_t begin
, end
;
5322 uint64_t max_clock_period
= 0;
5324 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5326 for (d
= 0; d
< timestampCount
; d
++) {
5327 switch (pTimestampInfos
[d
].timeDomain
) {
5328 case VK_TIME_DOMAIN_DEVICE_EXT
:
5329 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5331 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5332 max_clock_period
= MAX2(max_clock_period
, device_period
);
5334 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5335 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5336 max_clock_period
= MAX2(max_clock_period
, 1);
5339 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5340 pTimestamps
[d
] = begin
;
5348 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5351 * The maximum deviation is the sum of the interval over which we
5352 * perform the sampling and the maximum period of any sampled
5353 * clock. That's because the maximum skew between any two sampled
5354 * clock edges is when the sampled clock with the largest period is
5355 * sampled at the end of that period but right at the beginning of the
5356 * sampling interval and some other clock is sampled right at the
5357 * begining of its sampling period and right at the end of the
5358 * sampling interval. Let's assume the GPU has the longest clock
5359 * period and that the application is sampling GPU and monotonic:
5362 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5363 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5367 * GPU -----_____-----_____-----_____-----_____
5370 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5371 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5373 * Interval <----------------->
5374 * Deviation <-------------------------->
5378 * m = read(monotonic) 2
5381 * We round the sample interval up by one tick to cover sampling error
5382 * in the interval clock
5385 uint64_t sample_interval
= end
- begin
+ 1;
5387 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5392 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5393 VkPhysicalDevice physicalDevice
,
5394 VkSampleCountFlagBits samples
,
5395 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5397 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5398 VK_SAMPLE_COUNT_4_BIT
|
5399 VK_SAMPLE_COUNT_8_BIT
)) {
5400 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5402 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };