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_NAVI10
)
219 device
->rad_info
.chip_class
= GFX10
;
220 else if (i
>= CHIP_VEGA10
)
221 device
->rad_info
.chip_class
= GFX9
;
222 else if (i
>= CHIP_TONGA
)
223 device
->rad_info
.chip_class
= GFX8
;
224 else if (i
>= CHIP_BONAIRE
)
225 device
->rad_info
.chip_class
= GFX7
;
227 device
->rad_info
.chip_class
= GFX6
;
233 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
238 radv_physical_device_init(struct radv_physical_device
*device
,
239 struct radv_instance
*instance
,
240 drmDevicePtr drm_device
)
242 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
244 drmVersionPtr version
;
248 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
250 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
251 radv_logi("Could not open device '%s'", path
);
253 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
256 version
= drmGetVersion(fd
);
260 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
261 radv_logi("Could not get the kernel driver version for device '%s'", path
);
263 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
264 "failed to get version %s: %m", path
);
267 if (strcmp(version
->name
, "amdgpu")) {
268 drmFreeVersion(version
);
271 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
272 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
274 return VK_ERROR_INCOMPATIBLE_DRIVER
;
276 drmFreeVersion(version
);
278 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
279 radv_logi("Found compatible device '%s'.", path
);
281 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
282 device
->instance
= instance
;
284 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
285 instance
->perftest_flags
);
287 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
291 if (instance
->enabled_extensions
.KHR_display
) {
292 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
293 if (master_fd
>= 0) {
294 uint32_t accel_working
= 0;
295 struct drm_amdgpu_info request
= {
296 .return_pointer
= (uintptr_t)&accel_working
,
297 .return_size
= sizeof(accel_working
),
298 .query
= AMDGPU_INFO_ACCEL_WORKING
301 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
308 device
->master_fd
= master_fd
;
309 device
->local_fd
= fd
;
310 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
312 radv_handle_env_var_force_family(device
);
314 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
316 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
317 device
->ws
->destroy(device
->ws
);
318 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
319 "cannot generate UUID");
323 /* These flags affect shader compilation. */
324 uint64_t shader_env_flags
=
325 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
326 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
328 /* The gpu id is already embedded in the uuid so we just pass "radv"
329 * when creating the cache.
331 char buf
[VK_UUID_SIZE
* 2 + 1];
332 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
333 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
335 if (device
->rad_info
.chip_class
< GFX8
||
336 device
->rad_info
.chip_class
> GFX9
)
337 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
339 radv_get_driver_uuid(&device
->driver_uuid
);
340 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
342 if (device
->rad_info
.family
== CHIP_STONEY
||
343 device
->rad_info
.chip_class
>= GFX9
) {
344 device
->has_rbplus
= true;
345 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
346 device
->rad_info
.family
== CHIP_VEGA12
||
347 device
->rad_info
.family
== CHIP_RAVEN
||
348 device
->rad_info
.family
== CHIP_RAVEN2
;
351 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
354 device
->has_clear_state
= device
->rad_info
.chip_class
>= GFX7
;
356 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= GFX8
;
358 /* Vega10/Raven need a special workaround for a hardware bug. */
359 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
360 device
->rad_info
.family
== CHIP_RAVEN
;
362 /* Out-of-order primitive rasterization. */
363 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= GFX8
&&
364 device
->rad_info
.max_se
>= 2;
365 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
366 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
368 device
->dcc_msaa_allowed
=
369 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
371 /* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
372 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
373 (device
->rad_info
.chip_class
>= GFX8
&&
374 device
->rad_info
.me_fw_feature
>= 41);
376 device
->has_dcc_constant_encode
= device
->rad_info
.family
== CHIP_RAVEN2
;
378 device
->use_shader_ballot
= device
->instance
->perftest_flags
& RADV_PERFTEST_SHADER_BALLOT
;
380 radv_physical_device_init_mem_types(device
);
381 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
383 device
->bus_info
= *drm_device
->businfo
.pci
;
385 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
386 ac_print_gpu_info(&device
->rad_info
);
388 /* The WSI is structured as a layer on top of the driver, so this has
389 * to be the last part of initialization (at least until we get other
392 result
= radv_init_wsi(device
);
393 if (result
!= VK_SUCCESS
) {
394 device
->ws
->destroy(device
->ws
);
395 vk_error(instance
, result
);
409 radv_physical_device_finish(struct radv_physical_device
*device
)
411 radv_finish_wsi(device
);
412 device
->ws
->destroy(device
->ws
);
413 disk_cache_destroy(device
->disk_cache
);
414 close(device
->local_fd
);
415 if (device
->master_fd
!= -1)
416 close(device
->master_fd
);
420 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
421 VkSystemAllocationScope allocationScope
)
427 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
428 size_t align
, VkSystemAllocationScope allocationScope
)
430 return realloc(pOriginal
, size
);
434 default_free_func(void *pUserData
, void *pMemory
)
439 static const VkAllocationCallbacks default_alloc
= {
441 .pfnAllocation
= default_alloc_func
,
442 .pfnReallocation
= default_realloc_func
,
443 .pfnFree
= default_free_func
,
446 static const struct debug_control radv_debug_options
[] = {
447 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
448 {"nodcc", RADV_DEBUG_NO_DCC
},
449 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
450 {"nocache", RADV_DEBUG_NO_CACHE
},
451 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
452 {"nohiz", RADV_DEBUG_NO_HIZ
},
453 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
454 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
455 {"allbos", RADV_DEBUG_ALL_BOS
},
456 {"noibs", RADV_DEBUG_NO_IBS
},
457 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
458 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
459 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
460 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
461 {"nosisched", RADV_DEBUG_NO_SISCHED
},
462 {"preoptir", RADV_DEBUG_PREOPTIR
},
463 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
464 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
465 {"info", RADV_DEBUG_INFO
},
466 {"errors", RADV_DEBUG_ERRORS
},
467 {"startup", RADV_DEBUG_STARTUP
},
468 {"checkir", RADV_DEBUG_CHECKIR
},
469 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
470 {"nobinning", RADV_DEBUG_NOBINNING
},
471 {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT
},
476 radv_get_debug_option_name(int id
)
478 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
479 return radv_debug_options
[id
].string
;
482 static const struct debug_control radv_perftest_options
[] = {
483 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
484 {"sisched", RADV_PERFTEST_SISCHED
},
485 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
486 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
487 {"bolist", RADV_PERFTEST_BO_LIST
},
488 {"shader_ballot", RADV_PERFTEST_SHADER_BALLOT
},
489 {"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK
},
494 radv_get_perftest_option_name(int id
)
496 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
497 return radv_perftest_options
[id
].string
;
501 radv_handle_per_app_options(struct radv_instance
*instance
,
502 const VkApplicationInfo
*info
)
504 const char *name
= info
? info
->pApplicationName
: NULL
;
509 if (!strcmp(name
, "Talos - Linux - 32bit") ||
510 !strcmp(name
, "Talos - Linux - 64bit")) {
511 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
512 /* Force enable LLVM sisched for Talos because it looks
513 * safe and it gives few more FPS.
515 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
517 } else if (!strcmp(name
, "DOOM_VFR")) {
518 /* Work around a Doom VFR game bug */
519 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
520 } else if (!strcmp(name
, "MonsterHunterWorld.exe")) {
521 /* Workaround for a WaW hazard when LLVM moves/merges
522 * load/store memory operations.
523 * See https://reviews.llvm.org/D61313
525 if (HAVE_LLVM
< 0x900)
526 instance
->debug_flags
|= RADV_DEBUG_NO_LOAD_STORE_OPT
;
530 static int radv_get_instance_extension_index(const char *name
)
532 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
533 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
539 static const char radv_dri_options_xml
[] =
541 DRI_CONF_SECTION_QUALITY
542 DRI_CONF_ADAPTIVE_SYNC("true")
546 static void radv_init_dri_options(struct radv_instance
*instance
)
548 driParseOptionInfo(&instance
->available_dri_options
, radv_dri_options_xml
);
549 driParseConfigFiles(&instance
->dri_options
,
550 &instance
->available_dri_options
,
554 VkResult
radv_CreateInstance(
555 const VkInstanceCreateInfo
* pCreateInfo
,
556 const VkAllocationCallbacks
* pAllocator
,
557 VkInstance
* pInstance
)
559 struct radv_instance
*instance
;
562 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
564 uint32_t client_version
;
565 if (pCreateInfo
->pApplicationInfo
&&
566 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
567 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
569 client_version
= VK_API_VERSION_1_0
;
572 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
573 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
575 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
577 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
580 instance
->alloc
= *pAllocator
;
582 instance
->alloc
= default_alloc
;
584 instance
->apiVersion
= client_version
;
585 instance
->physicalDeviceCount
= -1;
587 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
590 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
591 radv_perftest_options
);
594 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
595 radv_logi("Created an instance");
597 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
598 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
599 int index
= radv_get_instance_extension_index(ext_name
);
601 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
602 vk_free2(&default_alloc
, pAllocator
, instance
);
603 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
606 instance
->enabled_extensions
.extensions
[index
] = true;
609 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
610 if (result
!= VK_SUCCESS
) {
611 vk_free2(&default_alloc
, pAllocator
, instance
);
612 return vk_error(instance
, result
);
616 glsl_type_singleton_init_or_ref();
618 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
620 radv_init_dri_options(instance
);
621 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
623 *pInstance
= radv_instance_to_handle(instance
);
628 void radv_DestroyInstance(
629 VkInstance _instance
,
630 const VkAllocationCallbacks
* pAllocator
)
632 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
637 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
638 radv_physical_device_finish(instance
->physicalDevices
+ i
);
641 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
643 glsl_type_singleton_decref();
646 driDestroyOptionCache(&instance
->dri_options
);
647 driDestroyOptionInfo(&instance
->available_dri_options
);
649 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
651 vk_free(&instance
->alloc
, instance
);
655 radv_enumerate_devices(struct radv_instance
*instance
)
657 /* TODO: Check for more devices ? */
658 drmDevicePtr devices
[8];
659 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
662 instance
->physicalDeviceCount
= 0;
664 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
666 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
667 radv_logi("Found %d drm nodes", max_devices
);
670 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
672 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
673 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
674 devices
[i
]->bustype
== DRM_BUS_PCI
&&
675 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
677 result
= radv_physical_device_init(instance
->physicalDevices
+
678 instance
->physicalDeviceCount
,
681 if (result
== VK_SUCCESS
)
682 ++instance
->physicalDeviceCount
;
683 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
687 drmFreeDevices(devices
, max_devices
);
692 VkResult
radv_EnumeratePhysicalDevices(
693 VkInstance _instance
,
694 uint32_t* pPhysicalDeviceCount
,
695 VkPhysicalDevice
* pPhysicalDevices
)
697 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
700 if (instance
->physicalDeviceCount
< 0) {
701 result
= radv_enumerate_devices(instance
);
702 if (result
!= VK_SUCCESS
&&
703 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
707 if (!pPhysicalDevices
) {
708 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
710 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
711 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
712 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
715 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
719 VkResult
radv_EnumeratePhysicalDeviceGroups(
720 VkInstance _instance
,
721 uint32_t* pPhysicalDeviceGroupCount
,
722 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
724 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
727 if (instance
->physicalDeviceCount
< 0) {
728 result
= radv_enumerate_devices(instance
);
729 if (result
!= VK_SUCCESS
&&
730 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
734 if (!pPhysicalDeviceGroupProperties
) {
735 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
737 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
738 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
739 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
740 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
741 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
744 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
748 void radv_GetPhysicalDeviceFeatures(
749 VkPhysicalDevice physicalDevice
,
750 VkPhysicalDeviceFeatures
* pFeatures
)
752 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
753 memset(pFeatures
, 0, sizeof(*pFeatures
));
755 *pFeatures
= (VkPhysicalDeviceFeatures
) {
756 .robustBufferAccess
= true,
757 .fullDrawIndexUint32
= true,
758 .imageCubeArray
= true,
759 .independentBlend
= true,
760 .geometryShader
= true,
761 .tessellationShader
= true,
762 .sampleRateShading
= true,
763 .dualSrcBlend
= true,
765 .multiDrawIndirect
= true,
766 .drawIndirectFirstInstance
= true,
768 .depthBiasClamp
= true,
769 .fillModeNonSolid
= true,
774 .multiViewport
= true,
775 .samplerAnisotropy
= true,
776 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
777 .textureCompressionASTC_LDR
= false,
778 .textureCompressionBC
= true,
779 .occlusionQueryPrecise
= true,
780 .pipelineStatisticsQuery
= true,
781 .vertexPipelineStoresAndAtomics
= true,
782 .fragmentStoresAndAtomics
= true,
783 .shaderTessellationAndGeometryPointSize
= true,
784 .shaderImageGatherExtended
= true,
785 .shaderStorageImageExtendedFormats
= true,
786 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= GFX8
,
787 .shaderUniformBufferArrayDynamicIndexing
= true,
788 .shaderSampledImageArrayDynamicIndexing
= true,
789 .shaderStorageBufferArrayDynamicIndexing
= true,
790 .shaderStorageImageArrayDynamicIndexing
= true,
791 .shaderStorageImageReadWithoutFormat
= true,
792 .shaderStorageImageWriteWithoutFormat
= true,
793 .shaderClipDistance
= true,
794 .shaderCullDistance
= true,
795 .shaderFloat64
= true,
797 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
798 .sparseBinding
= true,
799 .variableMultisampleRate
= true,
800 .inheritedQueries
= true,
804 void radv_GetPhysicalDeviceFeatures2(
805 VkPhysicalDevice physicalDevice
,
806 VkPhysicalDeviceFeatures2
*pFeatures
)
808 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
809 vk_foreach_struct(ext
, pFeatures
->pNext
) {
810 switch (ext
->sType
) {
811 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES
: {
812 VkPhysicalDeviceVariablePointersFeatures
*features
= (void *)ext
;
813 features
->variablePointersStorageBuffer
= true;
814 features
->variablePointers
= true;
817 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
818 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
819 features
->multiview
= true;
820 features
->multiviewGeometryShader
= true;
821 features
->multiviewTessellationShader
= true;
824 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES
: {
825 VkPhysicalDeviceShaderDrawParametersFeatures
*features
=
826 (VkPhysicalDeviceShaderDrawParametersFeatures
*)ext
;
827 features
->shaderDrawParameters
= true;
830 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
831 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
832 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
833 features
->protectedMemory
= false;
836 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
837 VkPhysicalDevice16BitStorageFeatures
*features
=
838 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
839 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
840 features
->storageBuffer16BitAccess
= enabled
;
841 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
842 features
->storagePushConstant16
= enabled
;
843 features
->storageInputOutput16
= enabled
&& HAVE_LLVM
>= 0x900;
846 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
847 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
848 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
849 features
->samplerYcbcrConversion
= true;
852 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
853 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
854 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
855 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
856 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
857 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
858 features
->shaderUniformBufferArrayNonUniformIndexing
= true;
859 features
->shaderSampledImageArrayNonUniformIndexing
= true;
860 features
->shaderStorageBufferArrayNonUniformIndexing
= true;
861 features
->shaderStorageImageArrayNonUniformIndexing
= true;
862 features
->shaderInputAttachmentArrayNonUniformIndexing
= true;
863 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= true;
864 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= true;
865 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
866 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
867 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
868 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
869 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
870 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
871 features
->descriptorBindingUpdateUnusedWhilePending
= true;
872 features
->descriptorBindingPartiallyBound
= true;
873 features
->descriptorBindingVariableDescriptorCount
= true;
874 features
->runtimeDescriptorArray
= true;
877 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
878 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
879 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
880 features
->conditionalRendering
= true;
881 features
->inheritedConditionalRendering
= false;
884 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
885 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
886 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
887 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
888 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
891 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
892 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
893 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
894 features
->transformFeedback
= true;
895 features
->geometryStreams
= true;
898 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
899 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
900 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
901 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= GFX7
;
904 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
905 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
906 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
907 features
->memoryPriority
= VK_TRUE
;
910 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT
: {
911 VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*features
=
912 (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT
*)ext
;
913 features
->bufferDeviceAddress
= true;
914 features
->bufferDeviceAddressCaptureReplay
= false;
915 features
->bufferDeviceAddressMultiDevice
= false;
918 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT
: {
919 VkPhysicalDeviceDepthClipEnableFeaturesEXT
*features
=
920 (VkPhysicalDeviceDepthClipEnableFeaturesEXT
*)ext
;
921 features
->depthClipEnable
= true;
924 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT
: {
925 VkPhysicalDeviceHostQueryResetFeaturesEXT
*features
=
926 (VkPhysicalDeviceHostQueryResetFeaturesEXT
*)ext
;
927 features
->hostQueryReset
= true;
930 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR
: {
931 VkPhysicalDevice8BitStorageFeaturesKHR
*features
=
932 (VkPhysicalDevice8BitStorageFeaturesKHR
*)ext
;
933 bool enabled
= pdevice
->rad_info
.chip_class
>= GFX8
;
934 features
->storageBuffer8BitAccess
= enabled
;
935 features
->uniformAndStorageBuffer8BitAccess
= enabled
;
936 features
->storagePushConstant8
= enabled
;
939 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR
: {
940 VkPhysicalDeviceFloat16Int8FeaturesKHR
*features
=
941 (VkPhysicalDeviceFloat16Int8FeaturesKHR
*)ext
;
942 features
->shaderFloat16
= pdevice
->rad_info
.chip_class
>= GFX8
&& HAVE_LLVM
>= 0x0800;
943 features
->shaderInt8
= true;
946 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR
: {
947 VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*features
=
948 (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR
*)ext
;
949 /* TODO: Enable this once the driver supports 64-bit
950 * compare&swap atomic operations.
952 features
->shaderBufferInt64Atomics
= false;
953 features
->shaderSharedInt64Atomics
= false;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
: {
957 VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*features
=
958 (VkPhysicalDeviceInlineUniformBlockFeaturesEXT
*)ext
;
960 features
->inlineUniformBlock
= true;
961 features
->descriptorBindingInlineUniformBlockUpdateAfterBind
= true;
964 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
: {
965 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*features
=
966 (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV
*)ext
;
967 features
->computeDerivativeGroupQuads
= false;
968 features
->computeDerivativeGroupLinear
= true;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT
: {
972 VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*features
=
973 (VkPhysicalDeviceYcbcrImageArraysFeaturesEXT
*)ext
;
974 features
->ycbcrImageArrays
= true;
977 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR
: {
978 VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*features
=
979 (VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR
*)ext
;
980 features
->uniformBufferStandardLayout
= true;
987 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
990 void radv_GetPhysicalDeviceProperties(
991 VkPhysicalDevice physicalDevice
,
992 VkPhysicalDeviceProperties
* pProperties
)
994 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
995 VkSampleCountFlags sample_counts
= 0xf;
997 /* make sure that the entire descriptor set is addressable with a signed
998 * 32-bit int. So the sum of all limits scaled by descriptor size has to
999 * be at most 2 GiB. the combined image & samples object count as one of
1000 * both. This limit is for the pipeline layout, not for the set layout, but
1001 * there is no set limit, so we just set a pipeline limit. I don't think
1002 * any app is going to hit this soon. */
1003 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1004 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1005 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1006 32 /* sampler, largest when combined with image */ +
1007 64 /* sampled image */ +
1008 64 /* storage image */);
1010 VkPhysicalDeviceLimits limits
= {
1011 .maxImageDimension1D
= (1 << 14),
1012 .maxImageDimension2D
= (1 << 14),
1013 .maxImageDimension3D
= (1 << 11),
1014 .maxImageDimensionCube
= (1 << 14),
1015 .maxImageArrayLayers
= (1 << 11),
1016 .maxTexelBufferElements
= 128 * 1024 * 1024,
1017 .maxUniformBufferRange
= UINT32_MAX
,
1018 .maxStorageBufferRange
= UINT32_MAX
,
1019 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
1020 .maxMemoryAllocationCount
= UINT32_MAX
,
1021 .maxSamplerAllocationCount
= 64 * 1024,
1022 .bufferImageGranularity
= 64, /* A cache line */
1023 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
1024 .maxBoundDescriptorSets
= MAX_SETS
,
1025 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
1026 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
1027 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
1028 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
1029 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
1030 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
1031 .maxPerStageResources
= max_descriptor_set_size
,
1032 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
1033 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
1034 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
1035 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
1036 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
1037 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
1038 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
1039 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
1040 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
1041 .maxVertexInputBindings
= MAX_VBS
,
1042 .maxVertexInputAttributeOffset
= 2047,
1043 .maxVertexInputBindingStride
= 2048,
1044 .maxVertexOutputComponents
= 128,
1045 .maxTessellationGenerationLevel
= 64,
1046 .maxTessellationPatchSize
= 32,
1047 .maxTessellationControlPerVertexInputComponents
= 128,
1048 .maxTessellationControlPerVertexOutputComponents
= 128,
1049 .maxTessellationControlPerPatchOutputComponents
= 120,
1050 .maxTessellationControlTotalOutputComponents
= 4096,
1051 .maxTessellationEvaluationInputComponents
= 128,
1052 .maxTessellationEvaluationOutputComponents
= 128,
1053 .maxGeometryShaderInvocations
= 127,
1054 .maxGeometryInputComponents
= 64,
1055 .maxGeometryOutputComponents
= 128,
1056 .maxGeometryOutputVertices
= 256,
1057 .maxGeometryTotalOutputComponents
= 1024,
1058 .maxFragmentInputComponents
= 128,
1059 .maxFragmentOutputAttachments
= 8,
1060 .maxFragmentDualSrcAttachments
= 1,
1061 .maxFragmentCombinedOutputResources
= 8,
1062 .maxComputeSharedMemorySize
= 32768,
1063 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
1064 .maxComputeWorkGroupInvocations
= 2048,
1065 .maxComputeWorkGroupSize
= {
1070 .subPixelPrecisionBits
= 8,
1071 .subTexelPrecisionBits
= 8,
1072 .mipmapPrecisionBits
= 8,
1073 .maxDrawIndexedIndexValue
= UINT32_MAX
,
1074 .maxDrawIndirectCount
= UINT32_MAX
,
1075 .maxSamplerLodBias
= 16,
1076 .maxSamplerAnisotropy
= 16,
1077 .maxViewports
= MAX_VIEWPORTS
,
1078 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
1079 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
1080 .viewportSubPixelBits
= 8,
1081 .minMemoryMapAlignment
= 4096, /* A page */
1082 .minTexelBufferOffsetAlignment
= 1,
1083 .minUniformBufferOffsetAlignment
= 4,
1084 .minStorageBufferOffsetAlignment
= 4,
1085 .minTexelOffset
= -32,
1086 .maxTexelOffset
= 31,
1087 .minTexelGatherOffset
= -32,
1088 .maxTexelGatherOffset
= 31,
1089 .minInterpolationOffset
= -2,
1090 .maxInterpolationOffset
= 2,
1091 .subPixelInterpolationOffsetBits
= 8,
1092 .maxFramebufferWidth
= (1 << 14),
1093 .maxFramebufferHeight
= (1 << 14),
1094 .maxFramebufferLayers
= (1 << 10),
1095 .framebufferColorSampleCounts
= sample_counts
,
1096 .framebufferDepthSampleCounts
= sample_counts
,
1097 .framebufferStencilSampleCounts
= sample_counts
,
1098 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1099 .maxColorAttachments
= MAX_RTS
,
1100 .sampledImageColorSampleCounts
= sample_counts
,
1101 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1102 .sampledImageDepthSampleCounts
= sample_counts
,
1103 .sampledImageStencilSampleCounts
= sample_counts
,
1104 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= GFX8
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1105 .maxSampleMaskWords
= 1,
1106 .timestampComputeAndGraphics
= true,
1107 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1108 .maxClipDistances
= 8,
1109 .maxCullDistances
= 8,
1110 .maxCombinedClipAndCullDistances
= 8,
1111 .discreteQueuePriorities
= 2,
1112 .pointSizeRange
= { 0.0, 8192.0 },
1113 .lineWidthRange
= { 0.0, 7.9921875 },
1114 .pointSizeGranularity
= (1.0 / 8.0),
1115 .lineWidthGranularity
= (1.0 / 128.0),
1116 .strictLines
= false, /* FINISHME */
1117 .standardSampleLocations
= true,
1118 .optimalBufferCopyOffsetAlignment
= 128,
1119 .optimalBufferCopyRowPitchAlignment
= 128,
1120 .nonCoherentAtomSize
= 64,
1123 *pProperties
= (VkPhysicalDeviceProperties
) {
1124 .apiVersion
= radv_physical_device_api_version(pdevice
),
1125 .driverVersion
= vk_get_driver_version(),
1126 .vendorID
= ATI_VENDOR_ID
,
1127 .deviceID
= pdevice
->rad_info
.pci_id
,
1128 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1130 .sparseProperties
= {0},
1133 strcpy(pProperties
->deviceName
, pdevice
->name
);
1134 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1137 void radv_GetPhysicalDeviceProperties2(
1138 VkPhysicalDevice physicalDevice
,
1139 VkPhysicalDeviceProperties2
*pProperties
)
1141 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1142 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1144 vk_foreach_struct(ext
, pProperties
->pNext
) {
1145 switch (ext
->sType
) {
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1147 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1148 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1149 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1152 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1153 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1154 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1155 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1156 properties
->deviceLUIDValid
= false;
1159 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1160 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1161 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1162 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1165 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1166 VkPhysicalDevicePointClippingProperties
*properties
=
1167 (VkPhysicalDevicePointClippingProperties
*)ext
;
1168 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1171 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1172 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1173 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1174 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1177 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1178 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1179 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1180 properties
->minImportedHostPointerAlignment
= 4096;
1183 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1184 VkPhysicalDeviceSubgroupProperties
*properties
=
1185 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1186 properties
->subgroupSize
= 64;
1187 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1188 properties
->supportedOperations
=
1189 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1190 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1191 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1192 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1193 if (pdevice
->rad_info
.chip_class
>= GFX8
) {
1194 properties
->supportedOperations
|=
1195 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1196 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1197 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1199 properties
->quadOperationsInAllStages
= true;
1202 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1203 VkPhysicalDeviceMaintenance3Properties
*properties
=
1204 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1205 /* Make sure everything is addressable by a signed 32-bit int, and
1206 * our largest descriptors are 96 bytes. */
1207 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1208 /* Our buffer size fields allow only this much */
1209 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1212 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1213 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1214 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1215 /* GFX6-8 only support single channel min/max filter. */
1216 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1217 properties
->filterMinmaxSingleComponentFormats
= true;
1220 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1221 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1222 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1224 /* Shader engines. */
1225 properties
->shaderEngineCount
=
1226 pdevice
->rad_info
.max_se
;
1227 properties
->shaderArraysPerEngineCount
=
1228 pdevice
->rad_info
.max_sh_per_se
;
1229 properties
->computeUnitsPerShaderArray
=
1230 pdevice
->rad_info
.num_good_cu_per_sh
;
1231 properties
->simdPerComputeUnit
= 4;
1232 properties
->wavefrontsPerSimd
=
1233 pdevice
->rad_info
.family
== CHIP_TONGA
||
1234 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1235 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1236 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1237 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1238 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1239 properties
->wavefrontSize
= 64;
1242 properties
->sgprsPerSimd
=
1243 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1244 properties
->minSgprAllocation
=
1245 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1246 properties
->maxSgprAllocation
=
1247 pdevice
->rad_info
.family
== CHIP_TONGA
||
1248 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1249 properties
->sgprAllocationGranularity
=
1250 pdevice
->rad_info
.chip_class
>= GFX8
? 16 : 8;
1253 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1254 properties
->minVgprAllocation
= 4;
1255 properties
->maxVgprAllocation
= 256;
1256 properties
->vgprAllocationGranularity
= 4;
1259 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1260 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1261 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1262 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1265 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1266 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1267 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1268 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1269 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1270 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1271 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1272 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1273 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1274 properties
->robustBufferAccessUpdateAfterBind
= false;
1275 properties
->quadDivergentImplicitLod
= false;
1277 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
-
1278 MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_INLINE_UNIFORM_BLOCK_COUNT
) /
1279 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1280 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1281 32 /* sampler, largest when combined with image */ +
1282 64 /* sampled image */ +
1283 64 /* storage image */);
1284 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1285 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1286 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1287 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1288 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1289 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1290 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1291 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1292 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1293 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1294 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1295 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1296 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1297 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1298 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1301 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1302 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1303 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1304 properties
->protectedNoFault
= false;
1307 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1308 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1309 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1310 properties
->primitiveOverestimationSize
= 0;
1311 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1312 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1313 properties
->primitiveUnderestimation
= VK_FALSE
;
1314 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1315 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1316 properties
->degenerateLinesRasterized
= VK_FALSE
;
1317 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1318 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1321 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1322 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1323 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1324 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1325 properties
->pciBus
= pdevice
->bus_info
.bus
;
1326 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1327 properties
->pciFunction
= pdevice
->bus_info
.func
;
1330 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1331 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1332 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1334 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1335 memset(driver_props
->driverName
, 0, VK_MAX_DRIVER_NAME_SIZE_KHR
);
1336 strcpy(driver_props
->driverName
, "radv");
1338 memset(driver_props
->driverInfo
, 0, VK_MAX_DRIVER_INFO_SIZE_KHR
);
1339 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1340 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1341 " (LLVM " MESA_LLVM_VERSION_STRING
")");
1343 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1351 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1352 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1353 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1354 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1355 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1356 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1357 properties
->maxTransformFeedbackStreamDataSize
= 512;
1358 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1359 properties
->maxTransformFeedbackBufferDataStride
= 512;
1360 properties
->transformFeedbackQueries
= true;
1361 properties
->transformFeedbackStreamsLinesTriangles
= true;
1362 properties
->transformFeedbackRasterizationStreamSelect
= false;
1363 properties
->transformFeedbackDraw
= true;
1366 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT
: {
1367 VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*props
=
1368 (VkPhysicalDeviceInlineUniformBlockPropertiesEXT
*)ext
;
1370 props
->maxInlineUniformBlockSize
= MAX_INLINE_UNIFORM_BLOCK_SIZE
;
1371 props
->maxPerStageDescriptorInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1372 props
->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_SIZE
* MAX_SETS
;
1373 props
->maxDescriptorSetInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1374 props
->maxDescriptorSetUpdateAfterBindInlineUniformBlocks
= MAX_INLINE_UNIFORM_BLOCK_COUNT
;
1377 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT
: {
1378 VkPhysicalDeviceSampleLocationsPropertiesEXT
*properties
=
1379 (VkPhysicalDeviceSampleLocationsPropertiesEXT
*)ext
;
1380 properties
->sampleLocationSampleCounts
= VK_SAMPLE_COUNT_2_BIT
|
1381 VK_SAMPLE_COUNT_4_BIT
|
1382 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
;
1390 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR
: {
1391 VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*properties
=
1392 (VkPhysicalDeviceDepthStencilResolvePropertiesKHR
*)ext
;
1394 /* We support all of the depth resolve modes */
1395 properties
->supportedDepthResolveModes
=
1396 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1397 VK_RESOLVE_MODE_AVERAGE_BIT_KHR
|
1398 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1399 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1401 /* Average doesn't make sense for stencil so we don't support that */
1402 properties
->supportedStencilResolveModes
=
1403 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR
|
1404 VK_RESOLVE_MODE_MIN_BIT_KHR
|
1405 VK_RESOLVE_MODE_MAX_BIT_KHR
;
1407 properties
->independentResolveNone
= VK_TRUE
;
1408 properties
->independentResolve
= VK_TRUE
;
1417 static void radv_get_physical_device_queue_family_properties(
1418 struct radv_physical_device
* pdevice
,
1420 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1422 int num_queue_families
= 1;
1424 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1425 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1426 num_queue_families
++;
1428 if (pQueueFamilyProperties
== NULL
) {
1429 *pCount
= num_queue_families
;
1438 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1439 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1440 VK_QUEUE_COMPUTE_BIT
|
1441 VK_QUEUE_TRANSFER_BIT
|
1442 VK_QUEUE_SPARSE_BINDING_BIT
,
1444 .timestampValidBits
= 64,
1445 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1450 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1451 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1452 if (*pCount
> idx
) {
1453 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1454 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1455 VK_QUEUE_TRANSFER_BIT
|
1456 VK_QUEUE_SPARSE_BINDING_BIT
,
1457 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1458 .timestampValidBits
= 64,
1459 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1467 void radv_GetPhysicalDeviceQueueFamilyProperties(
1468 VkPhysicalDevice physicalDevice
,
1470 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1472 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1473 if (!pQueueFamilyProperties
) {
1474 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1477 VkQueueFamilyProperties
*properties
[] = {
1478 pQueueFamilyProperties
+ 0,
1479 pQueueFamilyProperties
+ 1,
1480 pQueueFamilyProperties
+ 2,
1482 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1483 assert(*pCount
<= 3);
1486 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1487 VkPhysicalDevice physicalDevice
,
1489 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1491 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1492 if (!pQueueFamilyProperties
) {
1493 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1496 VkQueueFamilyProperties
*properties
[] = {
1497 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1498 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1499 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1501 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1502 assert(*pCount
<= 3);
1505 void radv_GetPhysicalDeviceMemoryProperties(
1506 VkPhysicalDevice physicalDevice
,
1507 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1509 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1511 *pMemoryProperties
= physical_device
->memory_properties
;
1515 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1516 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1518 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1519 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1520 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1521 uint64_t vram_size
= radv_get_vram_size(device
);
1522 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1523 uint64_t heap_budget
, heap_usage
;
1525 /* For all memory heaps, the computation of budget is as follow:
1526 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1528 * The Vulkan spec 1.1.97 says that the budget should include any
1529 * currently allocated device memory.
1531 * Note that the application heap usages are not really accurate (eg.
1532 * in presence of shared buffers).
1534 for (int i
= 0; i
< device
->memory_properties
.memoryTypeCount
; i
++) {
1535 uint32_t heap_index
= device
->memory_properties
.memoryTypes
[i
].heapIndex
;
1537 switch (device
->mem_type_indices
[i
]) {
1538 case RADV_MEM_TYPE_VRAM
:
1539 heap_usage
= device
->ws
->query_value(device
->ws
,
1540 RADEON_ALLOCATED_VRAM
);
1542 heap_budget
= vram_size
-
1543 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1546 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1547 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1549 case RADV_MEM_TYPE_VRAM_CPU_ACCESS
:
1550 heap_usage
= device
->ws
->query_value(device
->ws
,
1551 RADEON_ALLOCATED_VRAM_VIS
);
1553 heap_budget
= visible_vram_size
-
1554 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1557 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1558 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1560 case RADV_MEM_TYPE_GTT_WRITE_COMBINE
:
1561 heap_usage
= device
->ws
->query_value(device
->ws
,
1562 RADEON_ALLOCATED_GTT
);
1564 heap_budget
= gtt_size
-
1565 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1568 memoryBudget
->heapBudget
[heap_index
] = heap_budget
;
1569 memoryBudget
->heapUsage
[heap_index
] = heap_usage
;
1576 /* The heapBudget and heapUsage values must be zero for array elements
1577 * greater than or equal to
1578 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1580 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1581 memoryBudget
->heapBudget
[i
] = 0;
1582 memoryBudget
->heapUsage
[i
] = 0;
1586 void radv_GetPhysicalDeviceMemoryProperties2(
1587 VkPhysicalDevice physicalDevice
,
1588 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1590 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1591 &pMemoryProperties
->memoryProperties
);
1593 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1594 vk_find_struct(pMemoryProperties
->pNext
,
1595 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1597 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1600 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1602 VkExternalMemoryHandleTypeFlagBits handleType
,
1603 const void *pHostPointer
,
1604 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1606 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1610 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1611 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1612 uint32_t memoryTypeBits
= 0;
1613 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1614 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1615 memoryTypeBits
= (1 << i
);
1619 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1623 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1627 static enum radeon_ctx_priority
1628 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1630 /* Default to MEDIUM when a specific global priority isn't requested */
1632 return RADEON_CTX_PRIORITY_MEDIUM
;
1634 switch(pObj
->globalPriority
) {
1635 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1636 return RADEON_CTX_PRIORITY_REALTIME
;
1637 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1638 return RADEON_CTX_PRIORITY_HIGH
;
1639 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1640 return RADEON_CTX_PRIORITY_MEDIUM
;
1641 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1642 return RADEON_CTX_PRIORITY_LOW
;
1644 unreachable("Illegal global priority value");
1645 return RADEON_CTX_PRIORITY_INVALID
;
1650 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1651 uint32_t queue_family_index
, int idx
,
1652 VkDeviceQueueCreateFlags flags
,
1653 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1655 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1656 queue
->device
= device
;
1657 queue
->queue_family_index
= queue_family_index
;
1658 queue
->queue_idx
= idx
;
1659 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1660 queue
->flags
= flags
;
1662 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1664 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1670 radv_queue_finish(struct radv_queue
*queue
)
1673 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1675 if (queue
->initial_full_flush_preamble_cs
)
1676 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1677 if (queue
->initial_preamble_cs
)
1678 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1679 if (queue
->continue_preamble_cs
)
1680 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1681 if (queue
->descriptor_bo
)
1682 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1683 if (queue
->scratch_bo
)
1684 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1685 if (queue
->esgs_ring_bo
)
1686 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1687 if (queue
->gsvs_ring_bo
)
1688 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1689 if (queue
->tess_rings_bo
)
1690 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1691 if (queue
->compute_scratch_bo
)
1692 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1696 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1698 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1699 bo_list
->list
.count
= bo_list
->capacity
= 0;
1700 bo_list
->list
.bos
= NULL
;
1704 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1706 free(bo_list
->list
.bos
);
1707 pthread_mutex_destroy(&bo_list
->mutex
);
1710 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1711 struct radeon_winsys_bo
*bo
)
1713 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1718 if (unlikely(!device
->use_global_bo_list
))
1721 pthread_mutex_lock(&bo_list
->mutex
);
1722 if (bo_list
->list
.count
== bo_list
->capacity
) {
1723 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1724 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1727 pthread_mutex_unlock(&bo_list
->mutex
);
1728 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1731 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1732 bo_list
->capacity
= capacity
;
1735 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1736 pthread_mutex_unlock(&bo_list
->mutex
);
1740 static void radv_bo_list_remove(struct radv_device
*device
,
1741 struct radeon_winsys_bo
*bo
)
1743 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1748 if (unlikely(!device
->use_global_bo_list
))
1751 pthread_mutex_lock(&bo_list
->mutex
);
1752 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1753 if (bo_list
->list
.bos
[i
] == bo
) {
1754 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1755 --bo_list
->list
.count
;
1759 pthread_mutex_unlock(&bo_list
->mutex
);
1763 radv_device_init_gs_info(struct radv_device
*device
)
1765 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1766 device
->physical_device
->rad_info
.family
);
1769 static int radv_get_device_extension_index(const char *name
)
1771 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1772 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1779 radv_get_int_debug_option(const char *name
, int default_value
)
1786 result
= default_value
;
1790 result
= strtol(str
, &endptr
, 0);
1791 if (str
== endptr
) {
1792 /* No digits founs. */
1793 result
= default_value
;
1800 VkResult
radv_CreateDevice(
1801 VkPhysicalDevice physicalDevice
,
1802 const VkDeviceCreateInfo
* pCreateInfo
,
1803 const VkAllocationCallbacks
* pAllocator
,
1806 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1808 struct radv_device
*device
;
1810 bool keep_shader_info
= false;
1812 /* Check enabled features */
1813 if (pCreateInfo
->pEnabledFeatures
) {
1814 VkPhysicalDeviceFeatures supported_features
;
1815 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1816 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1817 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1818 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1819 for (uint32_t i
= 0; i
< num_features
; i
++) {
1820 if (enabled_feature
[i
] && !supported_feature
[i
])
1821 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1825 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1827 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1829 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1831 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1832 device
->instance
= physical_device
->instance
;
1833 device
->physical_device
= physical_device
;
1835 device
->ws
= physical_device
->ws
;
1837 device
->alloc
= *pAllocator
;
1839 device
->alloc
= physical_device
->instance
->alloc
;
1841 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1842 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1843 int index
= radv_get_device_extension_index(ext_name
);
1844 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1845 vk_free(&device
->alloc
, device
);
1846 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1849 device
->enabled_extensions
.extensions
[index
] = true;
1852 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1854 /* With update after bind we can't attach bo's to the command buffer
1855 * from the descriptor set anymore, so we have to use a global BO list.
1857 device
->use_global_bo_list
=
1858 (device
->instance
->perftest_flags
& RADV_PERFTEST_BO_LIST
) ||
1859 device
->enabled_extensions
.EXT_descriptor_indexing
||
1860 device
->enabled_extensions
.EXT_buffer_device_address
;
1862 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1863 list_inithead(&device
->shader_slabs
);
1865 radv_bo_list_init(&device
->bo_list
);
1867 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1868 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1869 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1870 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1871 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1873 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1875 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1876 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1877 if (!device
->queues
[qfi
]) {
1878 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1882 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1884 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1886 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1887 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1888 qfi
, q
, queue_create
->flags
,
1890 if (result
!= VK_SUCCESS
)
1895 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1896 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1898 /* Disabled and not implemented for now. */
1899 device
->dfsm_allowed
= device
->pbb_allowed
&&
1900 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1901 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
);
1904 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1907 /* The maximum number of scratch waves. Scratch space isn't divided
1908 * evenly between CUs. The number is only a function of the number of CUs.
1909 * We can decrease the constant to decrease the scratch buffer size.
1911 * sctx->scratch_waves must be >= the maximum possible size of
1912 * 1 threadgroup, so that the hw doesn't hang from being unable
1915 * The recommended value is 4 per CU at most. Higher numbers don't
1916 * bring much benefit, but they still occupy chip resources (think
1917 * async compute). I've seen ~2% performance difference between 4 and 32.
1919 uint32_t max_threads_per_block
= 2048;
1920 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1921 max_threads_per_block
/ 64);
1923 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1925 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
1926 /* If the KMD allows it (there is a KMD hw register for it),
1927 * allow launching waves out-of-order.
1929 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1932 radv_device_init_gs_info(device
);
1934 device
->tess_offchip_block_dw_size
=
1935 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1936 device
->has_distributed_tess
=
1937 device
->physical_device
->rad_info
.chip_class
>= GFX8
&&
1938 device
->physical_device
->rad_info
.max_se
>= 2;
1940 if (getenv("RADV_TRACE_FILE")) {
1941 const char *filename
= getenv("RADV_TRACE_FILE");
1943 keep_shader_info
= true;
1945 if (!radv_init_trace(device
))
1948 fprintf(stderr
, "*****************************************************************************\n");
1949 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1950 fprintf(stderr
, "*****************************************************************************\n");
1952 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1953 radv_dump_enabled_options(device
, stderr
);
1956 device
->keep_shader_info
= keep_shader_info
;
1958 result
= radv_device_init_meta(device
);
1959 if (result
!= VK_SUCCESS
)
1962 radv_device_init_msaa(device
);
1964 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1965 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1967 case RADV_QUEUE_GENERAL
:
1968 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1969 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1970 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1972 case RADV_QUEUE_COMPUTE
:
1973 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1974 radeon_emit(device
->empty_cs
[family
], 0);
1977 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1980 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
1981 cik_create_gfx_config(device
);
1983 VkPipelineCacheCreateInfo ci
;
1984 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1987 ci
.pInitialData
= NULL
;
1988 ci
.initialDataSize
= 0;
1990 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1992 if (result
!= VK_SUCCESS
)
1995 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1997 device
->force_aniso
=
1998 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1999 if (device
->force_aniso
>= 0) {
2000 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
2001 1 << util_logbase2(device
->force_aniso
));
2004 *pDevice
= radv_device_to_handle(device
);
2008 radv_device_finish_meta(device
);
2010 radv_bo_list_finish(&device
->bo_list
);
2012 if (device
->trace_bo
)
2013 device
->ws
->buffer_destroy(device
->trace_bo
);
2015 if (device
->gfx_init
)
2016 device
->ws
->buffer_destroy(device
->gfx_init
);
2018 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2019 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2020 radv_queue_finish(&device
->queues
[i
][q
]);
2021 if (device
->queue_count
[i
])
2022 vk_free(&device
->alloc
, device
->queues
[i
]);
2025 vk_free(&device
->alloc
, device
);
2029 void radv_DestroyDevice(
2031 const VkAllocationCallbacks
* pAllocator
)
2033 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2038 if (device
->trace_bo
)
2039 device
->ws
->buffer_destroy(device
->trace_bo
);
2041 if (device
->gfx_init
)
2042 device
->ws
->buffer_destroy(device
->gfx_init
);
2044 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2045 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
2046 radv_queue_finish(&device
->queues
[i
][q
]);
2047 if (device
->queue_count
[i
])
2048 vk_free(&device
->alloc
, device
->queues
[i
]);
2049 if (device
->empty_cs
[i
])
2050 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
2052 radv_device_finish_meta(device
);
2054 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
2055 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
2057 radv_destroy_shader_slabs(device
);
2059 radv_bo_list_finish(&device
->bo_list
);
2060 vk_free(&device
->alloc
, device
);
2063 VkResult
radv_EnumerateInstanceLayerProperties(
2064 uint32_t* pPropertyCount
,
2065 VkLayerProperties
* pProperties
)
2067 if (pProperties
== NULL
) {
2068 *pPropertyCount
= 0;
2072 /* None supported at this time */
2073 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2076 VkResult
radv_EnumerateDeviceLayerProperties(
2077 VkPhysicalDevice physicalDevice
,
2078 uint32_t* pPropertyCount
,
2079 VkLayerProperties
* pProperties
)
2081 if (pProperties
== NULL
) {
2082 *pPropertyCount
= 0;
2086 /* None supported at this time */
2087 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
2090 void radv_GetDeviceQueue2(
2092 const VkDeviceQueueInfo2
* pQueueInfo
,
2095 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2096 struct radv_queue
*queue
;
2098 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
2099 if (pQueueInfo
->flags
!= queue
->flags
) {
2100 /* From the Vulkan 1.1.70 spec:
2102 * "The queue returned by vkGetDeviceQueue2 must have the same
2103 * flags value from this structure as that used at device
2104 * creation time in a VkDeviceQueueCreateInfo instance. If no
2105 * matching flags were specified at device creation time then
2106 * pQueue will return VK_NULL_HANDLE."
2108 *pQueue
= VK_NULL_HANDLE
;
2112 *pQueue
= radv_queue_to_handle(queue
);
2115 void radv_GetDeviceQueue(
2117 uint32_t queueFamilyIndex
,
2118 uint32_t queueIndex
,
2121 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
2122 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
2123 .queueFamilyIndex
= queueFamilyIndex
,
2124 .queueIndex
= queueIndex
2127 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
2131 fill_geom_tess_rings(struct radv_queue
*queue
,
2133 bool add_sample_positions
,
2134 uint32_t esgs_ring_size
,
2135 struct radeon_winsys_bo
*esgs_ring_bo
,
2136 uint32_t gsvs_ring_size
,
2137 struct radeon_winsys_bo
*gsvs_ring_bo
,
2138 uint32_t tess_factor_ring_size
,
2139 uint32_t tess_offchip_ring_offset
,
2140 uint32_t tess_offchip_ring_size
,
2141 struct radeon_winsys_bo
*tess_rings_bo
)
2143 uint32_t *desc
= &map
[4];
2146 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
2148 /* stride 0, num records - size, add tid, swizzle, elsize4,
2151 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2152 S_008F04_STRIDE(0) |
2153 S_008F04_SWIZZLE_ENABLE(true);
2154 desc
[2] = esgs_ring_size
;
2155 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2156 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2157 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2158 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2159 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2160 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2161 S_008F0C_ELEMENT_SIZE(1) |
2162 S_008F0C_INDEX_STRIDE(3) |
2163 S_008F0C_ADD_TID_ENABLE(true);
2165 /* GS entry for ES->GS ring */
2166 /* stride 0, num records - size, elsize0,
2169 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
2170 S_008F04_STRIDE(0) |
2171 S_008F04_SWIZZLE_ENABLE(false);
2172 desc
[6] = esgs_ring_size
;
2173 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2174 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2175 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2176 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2177 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2178 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2179 S_008F0C_ELEMENT_SIZE(0) |
2180 S_008F0C_INDEX_STRIDE(0) |
2181 S_008F0C_ADD_TID_ENABLE(false);
2187 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2189 /* VS entry for GS->VS ring */
2190 /* stride 0, num records - size, elsize0,
2193 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2194 S_008F04_STRIDE(0) |
2195 S_008F04_SWIZZLE_ENABLE(false);
2196 desc
[2] = gsvs_ring_size
;
2197 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2198 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2199 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2200 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2201 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2202 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2203 S_008F0C_ELEMENT_SIZE(0) |
2204 S_008F0C_INDEX_STRIDE(0) |
2205 S_008F0C_ADD_TID_ENABLE(false);
2207 /* stride gsvs_itemsize, num records 64
2208 elsize 4, index stride 16 */
2209 /* shader will patch stride and desc[2] */
2211 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2212 S_008F04_STRIDE(0) |
2213 S_008F04_SWIZZLE_ENABLE(true);
2215 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2216 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2217 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2218 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2219 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2220 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2221 S_008F0C_ELEMENT_SIZE(1) |
2222 S_008F0C_INDEX_STRIDE(1) |
2223 S_008F0C_ADD_TID_ENABLE(true);
2228 if (tess_rings_bo
) {
2229 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2230 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2233 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
2234 S_008F04_STRIDE(0) |
2235 S_008F04_SWIZZLE_ENABLE(false);
2236 desc
[2] = tess_factor_ring_size
;
2237 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2238 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2239 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2240 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2241 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2242 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2243 S_008F0C_ELEMENT_SIZE(0) |
2244 S_008F0C_INDEX_STRIDE(0) |
2245 S_008F0C_ADD_TID_ENABLE(false);
2247 desc
[4] = tess_offchip_va
;
2248 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
2249 S_008F04_STRIDE(0) |
2250 S_008F04_SWIZZLE_ENABLE(false);
2251 desc
[6] = tess_offchip_ring_size
;
2252 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2253 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2254 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2255 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2256 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2257 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2258 S_008F0C_ELEMENT_SIZE(0) |
2259 S_008F0C_INDEX_STRIDE(0) |
2260 S_008F0C_ADD_TID_ENABLE(false);
2265 if (add_sample_positions
) {
2266 /* add sample positions after all rings */
2267 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2269 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2271 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2273 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2278 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2280 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= GFX7
&&
2281 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2282 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2283 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2284 unsigned max_offchip_buffers
;
2285 unsigned offchip_granularity
;
2286 unsigned hs_offchip_param
;
2290 * This must be one less than the maximum number due to a hw limitation.
2291 * Various hardware bugs need thGFX7
2294 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2295 * Gfx7 should limit max_offchip_buffers to 508
2296 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2298 * Follow AMDVLK here.
2300 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2301 device
->physical_device
->rad_info
.chip_class
== GFX7
||
2302 device
->physical_device
->rad_info
.chip_class
== GFX6
)
2303 --max_offchip_buffers_per_se
;
2305 max_offchip_buffers
= max_offchip_buffers_per_se
*
2306 device
->physical_device
->rad_info
.max_se
;
2308 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2309 * around by setting 4K granularity.
2311 if (device
->tess_offchip_block_dw_size
== 4096) {
2312 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2313 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2315 assert(device
->tess_offchip_block_dw_size
== 8192);
2316 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2319 switch (device
->physical_device
->rad_info
.chip_class
) {
2321 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2327 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2331 *max_offchip_buffers_p
= max_offchip_buffers
;
2332 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2333 if (device
->physical_device
->rad_info
.chip_class
>= GFX8
)
2334 --max_offchip_buffers
;
2336 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2337 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2340 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2342 return hs_offchip_param
;
2346 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2347 struct radeon_winsys_bo
*esgs_ring_bo
,
2348 uint32_t esgs_ring_size
,
2349 struct radeon_winsys_bo
*gsvs_ring_bo
,
2350 uint32_t gsvs_ring_size
)
2352 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2356 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2359 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2361 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2362 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2363 radeon_emit(cs
, esgs_ring_size
>> 8);
2364 radeon_emit(cs
, gsvs_ring_size
>> 8);
2366 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2367 radeon_emit(cs
, esgs_ring_size
>> 8);
2368 radeon_emit(cs
, gsvs_ring_size
>> 8);
2373 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2374 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2375 struct radeon_winsys_bo
*tess_rings_bo
)
2382 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2384 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2386 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
2387 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2388 S_030938_SIZE(tf_ring_size
/ 4));
2389 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2392 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2393 radeon_set_uconfig_reg(cs
, R_030984_VGT_TF_MEMORY_BASE_HI_UMD
,
2394 S_030984_BASE_HI(tf_va
>> 40));
2395 } else if (queue
->device
->physical_device
->rad_info
.chip_class
== GFX9
) {
2396 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2397 S_030944_BASE_HI(tf_va
>> 40));
2399 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2402 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2403 S_008988_SIZE(tf_ring_size
/ 4));
2404 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2406 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2412 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2413 struct radeon_winsys_bo
*compute_scratch_bo
)
2415 uint64_t scratch_va
;
2417 if (!compute_scratch_bo
)
2420 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2422 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2424 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2425 radeon_emit(cs
, scratch_va
);
2426 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2427 S_008F04_SWIZZLE_ENABLE(1));
2431 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2432 struct radeon_cmdbuf
*cs
,
2433 struct radeon_winsys_bo
*descriptor_bo
)
2440 va
= radv_buffer_get_va(descriptor_bo
);
2442 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2444 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
2445 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2446 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2447 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2448 R_00B430_SPI_SHADER_USER_DATA_HS_0
};
2450 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2451 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2454 } else if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2455 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2456 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2457 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2458 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2460 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2461 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2465 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2466 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2467 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2468 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2469 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2470 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2472 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2473 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2480 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2482 struct radv_device
*device
= queue
->device
;
2484 if (device
->gfx_init
) {
2485 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2487 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2488 radeon_emit(cs
, va
);
2489 radeon_emit(cs
, va
>> 32);
2490 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2492 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2494 struct radv_physical_device
*physical_device
= device
->physical_device
;
2495 si_emit_graphics(physical_device
, cs
);
2500 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2502 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2503 si_emit_compute(physical_device
, cs
);
2507 radv_get_preamble_cs(struct radv_queue
*queue
,
2508 uint32_t scratch_size
,
2509 uint32_t compute_scratch_size
,
2510 uint32_t esgs_ring_size
,
2511 uint32_t gsvs_ring_size
,
2512 bool needs_tess_rings
,
2513 bool needs_sample_positions
,
2514 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2515 struct radeon_cmdbuf
**initial_preamble_cs
,
2516 struct radeon_cmdbuf
**continue_preamble_cs
)
2518 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2519 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2520 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2521 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2522 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2523 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2524 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2525 bool add_tess_rings
= false, add_sample_positions
= false;
2526 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2527 unsigned max_offchip_buffers
;
2528 unsigned hs_offchip_param
= 0;
2529 unsigned tess_offchip_ring_offset
;
2530 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2531 if (!queue
->has_tess_rings
) {
2532 if (needs_tess_rings
)
2533 add_tess_rings
= true;
2535 if (!queue
->has_sample_positions
) {
2536 if (needs_sample_positions
)
2537 add_sample_positions
= true;
2539 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2540 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2541 &max_offchip_buffers
);
2542 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2543 tess_offchip_ring_size
= max_offchip_buffers
*
2544 queue
->device
->tess_offchip_block_dw_size
* 4;
2546 if (scratch_size
<= queue
->scratch_size
&&
2547 compute_scratch_size
<= queue
->compute_scratch_size
&&
2548 esgs_ring_size
<= queue
->esgs_ring_size
&&
2549 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2550 !add_tess_rings
&& !add_sample_positions
&&
2551 queue
->initial_preamble_cs
) {
2552 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2553 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2554 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2555 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2556 *continue_preamble_cs
= NULL
;
2560 if (scratch_size
> queue
->scratch_size
) {
2561 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2566 RADV_BO_PRIORITY_SCRATCH
);
2570 scratch_bo
= queue
->scratch_bo
;
2572 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2573 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2574 compute_scratch_size
,
2578 RADV_BO_PRIORITY_SCRATCH
);
2579 if (!compute_scratch_bo
)
2583 compute_scratch_bo
= queue
->compute_scratch_bo
;
2585 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2586 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2591 RADV_BO_PRIORITY_SCRATCH
);
2595 esgs_ring_bo
= queue
->esgs_ring_bo
;
2596 esgs_ring_size
= queue
->esgs_ring_size
;
2599 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2600 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2605 RADV_BO_PRIORITY_SCRATCH
);
2609 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2610 gsvs_ring_size
= queue
->gsvs_ring_size
;
2613 if (add_tess_rings
) {
2614 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2615 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2619 RADV_BO_PRIORITY_SCRATCH
);
2623 tess_rings_bo
= queue
->tess_rings_bo
;
2626 if (scratch_bo
!= queue
->scratch_bo
||
2627 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2628 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2629 tess_rings_bo
!= queue
->tess_rings_bo
||
2630 add_sample_positions
) {
2632 if (gsvs_ring_bo
|| esgs_ring_bo
||
2633 tess_rings_bo
|| add_sample_positions
) {
2634 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2635 if (add_sample_positions
)
2636 size
+= 128; /* 64+32+16+8 = 120 bytes */
2638 else if (scratch_bo
)
2639 size
= 8; /* 2 dword */
2641 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2645 RADEON_FLAG_CPU_ACCESS
|
2646 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2647 RADEON_FLAG_READ_ONLY
,
2648 RADV_BO_PRIORITY_DESCRIPTOR
);
2652 descriptor_bo
= queue
->descriptor_bo
;
2654 if (descriptor_bo
!= queue
->descriptor_bo
) {
2655 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2658 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2659 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2660 S_008F04_SWIZZLE_ENABLE(1);
2661 map
[0] = scratch_va
;
2665 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2666 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2667 esgs_ring_size
, esgs_ring_bo
,
2668 gsvs_ring_size
, gsvs_ring_bo
,
2669 tess_factor_ring_size
,
2670 tess_offchip_ring_offset
,
2671 tess_offchip_ring_size
,
2674 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2677 for(int i
= 0; i
< 3; ++i
) {
2678 struct radeon_cmdbuf
*cs
= NULL
;
2679 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2680 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2687 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2689 /* Emit initial configuration. */
2690 switch (queue
->queue_family_index
) {
2691 case RADV_QUEUE_GENERAL
:
2692 radv_init_graphics_state(cs
, queue
);
2694 case RADV_QUEUE_COMPUTE
:
2695 radv_init_compute_state(cs
, queue
);
2697 case RADV_QUEUE_TRANSFER
:
2701 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2702 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2703 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2704 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2705 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2708 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2709 gsvs_ring_bo
, gsvs_ring_size
);
2710 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2711 tess_factor_ring_size
, tess_rings_bo
);
2712 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2713 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2716 si_cs_emit_cache_flush(cs
,
2717 queue
->device
->physical_device
->rad_info
.chip_class
,
2719 queue
->queue_family_index
== RING_COMPUTE
&&
2720 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2721 (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
)) |
2722 RADV_CMD_FLAG_INV_ICACHE
|
2723 RADV_CMD_FLAG_INV_SCACHE
|
2724 RADV_CMD_FLAG_INV_VCACHE
|
2725 RADV_CMD_FLAG_INV_L2
|
2726 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2727 } else if (i
== 1) {
2728 si_cs_emit_cache_flush(cs
,
2729 queue
->device
->physical_device
->rad_info
.chip_class
,
2731 queue
->queue_family_index
== RING_COMPUTE
&&
2732 queue
->device
->physical_device
->rad_info
.chip_class
>= GFX7
,
2733 RADV_CMD_FLAG_INV_ICACHE
|
2734 RADV_CMD_FLAG_INV_SCACHE
|
2735 RADV_CMD_FLAG_INV_VCACHE
|
2736 RADV_CMD_FLAG_INV_L2
|
2737 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2740 if (!queue
->device
->ws
->cs_finalize(cs
))
2744 if (queue
->initial_full_flush_preamble_cs
)
2745 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2747 if (queue
->initial_preamble_cs
)
2748 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2750 if (queue
->continue_preamble_cs
)
2751 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2753 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2754 queue
->initial_preamble_cs
= dest_cs
[1];
2755 queue
->continue_preamble_cs
= dest_cs
[2];
2757 if (scratch_bo
!= queue
->scratch_bo
) {
2758 if (queue
->scratch_bo
)
2759 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2760 queue
->scratch_bo
= scratch_bo
;
2761 queue
->scratch_size
= scratch_size
;
2764 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2765 if (queue
->compute_scratch_bo
)
2766 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2767 queue
->compute_scratch_bo
= compute_scratch_bo
;
2768 queue
->compute_scratch_size
= compute_scratch_size
;
2771 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2772 if (queue
->esgs_ring_bo
)
2773 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2774 queue
->esgs_ring_bo
= esgs_ring_bo
;
2775 queue
->esgs_ring_size
= esgs_ring_size
;
2778 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2779 if (queue
->gsvs_ring_bo
)
2780 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2781 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2782 queue
->gsvs_ring_size
= gsvs_ring_size
;
2785 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2786 queue
->tess_rings_bo
= tess_rings_bo
;
2787 queue
->has_tess_rings
= true;
2790 if (descriptor_bo
!= queue
->descriptor_bo
) {
2791 if (queue
->descriptor_bo
)
2792 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2794 queue
->descriptor_bo
= descriptor_bo
;
2797 if (add_sample_positions
)
2798 queue
->has_sample_positions
= true;
2800 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2801 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2802 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2803 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2804 *continue_preamble_cs
= NULL
;
2807 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2809 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2810 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2811 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2812 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2813 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2814 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2815 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2816 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2817 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2818 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2819 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2820 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2821 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2822 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2825 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2826 struct radv_winsys_sem_counts
*counts
,
2828 const VkSemaphore
*sems
,
2832 int syncobj_idx
= 0, sem_idx
= 0;
2834 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2837 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2838 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2840 if (sem
->temp_syncobj
|| sem
->syncobj
)
2841 counts
->syncobj_count
++;
2843 counts
->sem_count
++;
2846 if (_fence
!= VK_NULL_HANDLE
) {
2847 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2848 if (fence
->temp_syncobj
|| fence
->syncobj
)
2849 counts
->syncobj_count
++;
2852 if (counts
->syncobj_count
) {
2853 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2854 if (!counts
->syncobj
)
2855 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2858 if (counts
->sem_count
) {
2859 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2861 free(counts
->syncobj
);
2862 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2866 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2867 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2869 if (sem
->temp_syncobj
) {
2870 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2872 else if (sem
->syncobj
)
2873 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2876 counts
->sem
[sem_idx
++] = sem
->sem
;
2880 if (_fence
!= VK_NULL_HANDLE
) {
2881 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2882 if (fence
->temp_syncobj
)
2883 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2884 else if (fence
->syncobj
)
2885 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2892 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2894 free(sem_info
->wait
.syncobj
);
2895 free(sem_info
->wait
.sem
);
2896 free(sem_info
->signal
.syncobj
);
2897 free(sem_info
->signal
.sem
);
2901 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2903 const VkSemaphore
*sems
)
2905 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2906 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2908 if (sem
->temp_syncobj
) {
2909 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2910 sem
->temp_syncobj
= 0;
2916 radv_alloc_sem_info(struct radv_instance
*instance
,
2917 struct radv_winsys_sem_info
*sem_info
,
2919 const VkSemaphore
*wait_sems
,
2920 int num_signal_sems
,
2921 const VkSemaphore
*signal_sems
,
2925 memset(sem_info
, 0, sizeof(*sem_info
));
2927 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2930 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2932 radv_free_sem_info(sem_info
);
2934 /* caller can override these */
2935 sem_info
->cs_emit_wait
= true;
2936 sem_info
->cs_emit_signal
= true;
2940 /* Signals fence as soon as all the work currently put on queue is done. */
2941 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2942 struct radv_fence
*fence
)
2946 struct radv_winsys_sem_info sem_info
;
2948 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2949 radv_fence_to_handle(fence
));
2950 if (result
!= VK_SUCCESS
)
2953 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2954 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2955 1, NULL
, NULL
, &sem_info
, NULL
,
2956 false, fence
->fence
);
2957 radv_free_sem_info(&sem_info
);
2960 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2965 VkResult
radv_QueueSubmit(
2967 uint32_t submitCount
,
2968 const VkSubmitInfo
* pSubmits
,
2971 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2972 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2973 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2974 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2976 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : RADV_MAX_IBS_PER_SUBMIT
;
2977 uint32_t scratch_size
= 0;
2978 uint32_t compute_scratch_size
= 0;
2979 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2980 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2982 bool fence_emitted
= false;
2983 bool tess_rings_needed
= false;
2984 bool sample_positions_needed
= false;
2986 /* Do this first so failing to allocate scratch buffers can't result in
2987 * partially executed submissions. */
2988 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2989 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2990 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2991 pSubmits
[i
].pCommandBuffers
[j
]);
2993 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2994 compute_scratch_size
= MAX2(compute_scratch_size
,
2995 cmd_buffer
->compute_scratch_size_needed
);
2996 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2997 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2998 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2999 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
3003 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
3004 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
3005 sample_positions_needed
, &initial_flush_preamble_cs
,
3006 &initial_preamble_cs
, &continue_preamble_cs
);
3007 if (result
!= VK_SUCCESS
)
3010 for (uint32_t i
= 0; i
< submitCount
; i
++) {
3011 struct radeon_cmdbuf
**cs_array
;
3012 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
3013 bool can_patch
= true;
3015 struct radv_winsys_sem_info sem_info
;
3017 result
= radv_alloc_sem_info(queue
->device
->instance
,
3019 pSubmits
[i
].waitSemaphoreCount
,
3020 pSubmits
[i
].pWaitSemaphores
,
3021 pSubmits
[i
].signalSemaphoreCount
,
3022 pSubmits
[i
].pSignalSemaphores
,
3024 if (result
!= VK_SUCCESS
)
3027 if (!pSubmits
[i
].commandBufferCount
) {
3028 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
3029 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
3030 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3035 radv_loge("failed to submit CS %d\n", i
);
3038 fence_emitted
= true;
3040 radv_free_sem_info(&sem_info
);
3044 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
3045 (pSubmits
[i
].commandBufferCount
));
3047 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
3048 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
3049 pSubmits
[i
].pCommandBuffers
[j
]);
3050 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
3052 cs_array
[j
] = cmd_buffer
->cs
;
3053 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
3056 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
3059 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
3060 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
3061 const struct radv_winsys_bo_list
*bo_list
= NULL
;
3063 advance
= MIN2(max_cs_submission
,
3064 pSubmits
[i
].commandBufferCount
- j
);
3066 if (queue
->device
->trace_bo
)
3067 *queue
->device
->trace_id_ptr
= 0;
3069 sem_info
.cs_emit_wait
= j
== 0;
3070 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
3072 if (unlikely(queue
->device
->use_global_bo_list
)) {
3073 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
3074 bo_list
= &queue
->device
->bo_list
.list
;
3077 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
3078 advance
, initial_preamble
, continue_preamble_cs
,
3080 can_patch
, base_fence
);
3082 if (unlikely(queue
->device
->use_global_bo_list
))
3083 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
3086 radv_loge("failed to submit CS %d\n", i
);
3089 fence_emitted
= true;
3090 if (queue
->device
->trace_bo
) {
3091 radv_check_gpu_hangs(queue
, cs_array
[j
]);
3095 radv_free_temp_syncobjs(queue
->device
,
3096 pSubmits
[i
].waitSemaphoreCount
,
3097 pSubmits
[i
].pWaitSemaphores
);
3098 radv_free_sem_info(&sem_info
);
3103 if (!fence_emitted
) {
3104 result
= radv_signal_fence(queue
, fence
);
3105 if (result
!= VK_SUCCESS
)
3113 VkResult
radv_QueueWaitIdle(
3116 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3118 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
3119 radv_queue_family_to_ring(queue
->queue_family_index
),
3124 VkResult
radv_DeviceWaitIdle(
3127 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3129 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
3130 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
3131 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
3137 VkResult
radv_EnumerateInstanceExtensionProperties(
3138 const char* pLayerName
,
3139 uint32_t* pPropertyCount
,
3140 VkExtensionProperties
* pProperties
)
3142 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3144 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
3145 if (radv_supported_instance_extensions
.extensions
[i
]) {
3146 vk_outarray_append(&out
, prop
) {
3147 *prop
= radv_instance_extensions
[i
];
3152 return vk_outarray_status(&out
);
3155 VkResult
radv_EnumerateDeviceExtensionProperties(
3156 VkPhysicalDevice physicalDevice
,
3157 const char* pLayerName
,
3158 uint32_t* pPropertyCount
,
3159 VkExtensionProperties
* pProperties
)
3161 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
3162 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3164 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3165 if (device
->supported_extensions
.extensions
[i
]) {
3166 vk_outarray_append(&out
, prop
) {
3167 *prop
= radv_device_extensions
[i
];
3172 return vk_outarray_status(&out
);
3175 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3176 VkInstance _instance
,
3179 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3181 return radv_lookup_entrypoint_checked(pName
,
3182 instance
? instance
->apiVersion
: 0,
3183 instance
? &instance
->enabled_extensions
: NULL
,
3187 /* The loader wants us to expose a second GetInstanceProcAddr function
3188 * to work around certain LD_PRELOAD issues seen in apps.
3191 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3192 VkInstance instance
,
3196 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3197 VkInstance instance
,
3200 return radv_GetInstanceProcAddr(instance
, pName
);
3204 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3205 VkInstance _instance
,
3209 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetPhysicalDeviceProcAddr(
3210 VkInstance _instance
,
3213 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3215 return radv_lookup_physical_device_entrypoint_checked(pName
,
3216 instance
? instance
->apiVersion
: 0,
3217 instance
? &instance
->enabled_extensions
: NULL
);
3220 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3224 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3226 return radv_lookup_entrypoint_checked(pName
,
3227 device
->instance
->apiVersion
,
3228 &device
->instance
->enabled_extensions
,
3229 &device
->enabled_extensions
);
3232 bool radv_get_memory_fd(struct radv_device
*device
,
3233 struct radv_device_memory
*memory
,
3236 struct radeon_bo_metadata metadata
;
3238 if (memory
->image
) {
3239 radv_init_metadata(device
, memory
->image
, &metadata
);
3240 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3243 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3247 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3248 const VkMemoryAllocateInfo
* pAllocateInfo
,
3249 const VkAllocationCallbacks
* pAllocator
,
3250 VkDeviceMemory
* pMem
)
3252 struct radv_device_memory
*mem
;
3254 enum radeon_bo_domain domain
;
3256 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3258 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3260 if (pAllocateInfo
->allocationSize
== 0) {
3261 /* Apparently, this is allowed */
3262 *pMem
= VK_NULL_HANDLE
;
3266 const VkImportMemoryFdInfoKHR
*import_info
=
3267 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3268 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3269 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3270 const VkExportMemoryAllocateInfo
*export_info
=
3271 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3272 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3273 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3275 const struct wsi_memory_allocate_info
*wsi_info
=
3276 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3278 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3279 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3281 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3283 if (wsi_info
&& wsi_info
->implicit_sync
)
3284 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3286 if (dedicate_info
) {
3287 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3288 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3294 float priority_float
= 0.5;
3295 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3296 vk_find_struct_const(pAllocateInfo
->pNext
,
3297 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3299 priority_float
= priority_ext
->priority
;
3301 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3302 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3304 mem
->user_ptr
= NULL
;
3307 assert(import_info
->handleType
==
3308 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3309 import_info
->handleType
==
3310 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3311 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3312 priority
, NULL
, NULL
);
3314 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3317 close(import_info
->fd
);
3319 } else if (host_ptr_info
) {
3320 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3321 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3322 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3323 pAllocateInfo
->allocationSize
,
3326 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3329 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3332 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3333 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3334 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3335 domain
= RADEON_DOMAIN_GTT
;
3337 domain
= RADEON_DOMAIN_VRAM
;
3339 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3340 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3342 flags
|= RADEON_FLAG_CPU_ACCESS
;
3344 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3345 flags
|= RADEON_FLAG_GTT_WC
;
3347 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
)) {
3348 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3349 if (device
->use_global_bo_list
) {
3350 flags
|= RADEON_FLAG_PREFER_LOCAL_BO
;
3354 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3355 domain
, flags
, priority
);
3358 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3361 mem
->type_index
= mem_type_index
;
3364 result
= radv_bo_list_add(device
, mem
->bo
);
3365 if (result
!= VK_SUCCESS
)
3368 *pMem
= radv_device_memory_to_handle(mem
);
3373 device
->ws
->buffer_destroy(mem
->bo
);
3375 vk_free2(&device
->alloc
, pAllocator
, mem
);
3380 VkResult
radv_AllocateMemory(
3382 const VkMemoryAllocateInfo
* pAllocateInfo
,
3383 const VkAllocationCallbacks
* pAllocator
,
3384 VkDeviceMemory
* pMem
)
3386 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3387 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3390 void radv_FreeMemory(
3392 VkDeviceMemory _mem
,
3393 const VkAllocationCallbacks
* pAllocator
)
3395 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3396 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3401 radv_bo_list_remove(device
, mem
->bo
);
3402 device
->ws
->buffer_destroy(mem
->bo
);
3405 vk_free2(&device
->alloc
, pAllocator
, mem
);
3408 VkResult
radv_MapMemory(
3410 VkDeviceMemory _memory
,
3411 VkDeviceSize offset
,
3413 VkMemoryMapFlags flags
,
3416 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3417 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3425 *ppData
= mem
->user_ptr
;
3427 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3434 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3437 void radv_UnmapMemory(
3439 VkDeviceMemory _memory
)
3441 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3442 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3447 if (mem
->user_ptr
== NULL
)
3448 device
->ws
->buffer_unmap(mem
->bo
);
3451 VkResult
radv_FlushMappedMemoryRanges(
3453 uint32_t memoryRangeCount
,
3454 const VkMappedMemoryRange
* pMemoryRanges
)
3459 VkResult
radv_InvalidateMappedMemoryRanges(
3461 uint32_t memoryRangeCount
,
3462 const VkMappedMemoryRange
* pMemoryRanges
)
3467 void radv_GetBufferMemoryRequirements(
3470 VkMemoryRequirements
* pMemoryRequirements
)
3472 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3473 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3475 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3477 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3478 pMemoryRequirements
->alignment
= 4096;
3480 pMemoryRequirements
->alignment
= 16;
3482 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3485 void radv_GetBufferMemoryRequirements2(
3487 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3488 VkMemoryRequirements2
*pMemoryRequirements
)
3490 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3491 &pMemoryRequirements
->memoryRequirements
);
3492 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3493 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3494 switch (ext
->sType
) {
3495 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3496 VkMemoryDedicatedRequirements
*req
=
3497 (VkMemoryDedicatedRequirements
*) ext
;
3498 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3499 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3508 void radv_GetImageMemoryRequirements(
3511 VkMemoryRequirements
* pMemoryRequirements
)
3513 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3514 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3516 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3518 pMemoryRequirements
->size
= image
->size
;
3519 pMemoryRequirements
->alignment
= image
->alignment
;
3522 void radv_GetImageMemoryRequirements2(
3524 const VkImageMemoryRequirementsInfo2
*pInfo
,
3525 VkMemoryRequirements2
*pMemoryRequirements
)
3527 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3528 &pMemoryRequirements
->memoryRequirements
);
3530 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3532 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3533 switch (ext
->sType
) {
3534 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3535 VkMemoryDedicatedRequirements
*req
=
3536 (VkMemoryDedicatedRequirements
*) ext
;
3537 req
->requiresDedicatedAllocation
= image
->shareable
;
3538 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3547 void radv_GetImageSparseMemoryRequirements(
3550 uint32_t* pSparseMemoryRequirementCount
,
3551 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3556 void radv_GetImageSparseMemoryRequirements2(
3558 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3559 uint32_t* pSparseMemoryRequirementCount
,
3560 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3565 void radv_GetDeviceMemoryCommitment(
3567 VkDeviceMemory memory
,
3568 VkDeviceSize
* pCommittedMemoryInBytes
)
3570 *pCommittedMemoryInBytes
= 0;
3573 VkResult
radv_BindBufferMemory2(VkDevice device
,
3574 uint32_t bindInfoCount
,
3575 const VkBindBufferMemoryInfo
*pBindInfos
)
3577 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3578 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3579 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3582 buffer
->bo
= mem
->bo
;
3583 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3591 VkResult
radv_BindBufferMemory(
3594 VkDeviceMemory memory
,
3595 VkDeviceSize memoryOffset
)
3597 const VkBindBufferMemoryInfo info
= {
3598 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3601 .memoryOffset
= memoryOffset
3604 return radv_BindBufferMemory2(device
, 1, &info
);
3607 VkResult
radv_BindImageMemory2(VkDevice device
,
3608 uint32_t bindInfoCount
,
3609 const VkBindImageMemoryInfo
*pBindInfos
)
3611 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3612 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3613 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3616 image
->bo
= mem
->bo
;
3617 image
->offset
= pBindInfos
[i
].memoryOffset
;
3627 VkResult
radv_BindImageMemory(
3630 VkDeviceMemory memory
,
3631 VkDeviceSize memoryOffset
)
3633 const VkBindImageMemoryInfo info
= {
3634 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3637 .memoryOffset
= memoryOffset
3640 return radv_BindImageMemory2(device
, 1, &info
);
3645 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3646 const VkSparseBufferMemoryBindInfo
*bind
)
3648 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3650 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3651 struct radv_device_memory
*mem
= NULL
;
3653 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3654 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3656 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3657 bind
->pBinds
[i
].resourceOffset
,
3658 bind
->pBinds
[i
].size
,
3659 mem
? mem
->bo
: NULL
,
3660 bind
->pBinds
[i
].memoryOffset
);
3665 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3666 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3668 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3670 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3671 struct radv_device_memory
*mem
= NULL
;
3673 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3674 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3676 device
->ws
->buffer_virtual_bind(image
->bo
,
3677 bind
->pBinds
[i
].resourceOffset
,
3678 bind
->pBinds
[i
].size
,
3679 mem
? mem
->bo
: NULL
,
3680 bind
->pBinds
[i
].memoryOffset
);
3684 VkResult
radv_QueueBindSparse(
3686 uint32_t bindInfoCount
,
3687 const VkBindSparseInfo
* pBindInfo
,
3690 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3691 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3692 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3693 bool fence_emitted
= false;
3697 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3698 struct radv_winsys_sem_info sem_info
;
3699 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3700 radv_sparse_buffer_bind_memory(queue
->device
,
3701 pBindInfo
[i
].pBufferBinds
+ j
);
3704 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3705 radv_sparse_image_opaque_bind_memory(queue
->device
,
3706 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3710 result
= radv_alloc_sem_info(queue
->device
->instance
,
3712 pBindInfo
[i
].waitSemaphoreCount
,
3713 pBindInfo
[i
].pWaitSemaphores
,
3714 pBindInfo
[i
].signalSemaphoreCount
,
3715 pBindInfo
[i
].pSignalSemaphores
,
3717 if (result
!= VK_SUCCESS
)
3720 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3721 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3722 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3727 radv_loge("failed to submit CS %d\n", i
);
3731 fence_emitted
= true;
3734 radv_free_sem_info(&sem_info
);
3739 if (!fence_emitted
) {
3740 result
= radv_signal_fence(queue
, fence
);
3741 if (result
!= VK_SUCCESS
)
3749 VkResult
radv_CreateFence(
3751 const VkFenceCreateInfo
* pCreateInfo
,
3752 const VkAllocationCallbacks
* pAllocator
,
3755 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3756 const VkExportFenceCreateInfo
*export
=
3757 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3758 VkExternalFenceHandleTypeFlags handleTypes
=
3759 export
? export
->handleTypes
: 0;
3761 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3763 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3766 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3768 fence
->fence_wsi
= NULL
;
3769 fence
->temp_syncobj
= 0;
3770 if (device
->always_use_syncobj
|| handleTypes
) {
3771 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3773 vk_free2(&device
->alloc
, pAllocator
, fence
);
3774 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3776 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3777 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3779 fence
->fence
= NULL
;
3781 fence
->fence
= device
->ws
->create_fence();
3782 if (!fence
->fence
) {
3783 vk_free2(&device
->alloc
, pAllocator
, fence
);
3784 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3787 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
)
3788 device
->ws
->signal_fence(fence
->fence
);
3791 *pFence
= radv_fence_to_handle(fence
);
3796 void radv_DestroyFence(
3799 const VkAllocationCallbacks
* pAllocator
)
3801 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3802 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3807 if (fence
->temp_syncobj
)
3808 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3810 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3812 device
->ws
->destroy_fence(fence
->fence
);
3813 if (fence
->fence_wsi
)
3814 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3815 vk_free2(&device
->alloc
, pAllocator
, fence
);
3819 uint64_t radv_get_current_time(void)
3822 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3823 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3826 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3828 uint64_t current_time
= radv_get_current_time();
3830 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3832 return current_time
+ timeout
;
3836 static bool radv_all_fences_plain_and_submitted(struct radv_device
*device
,
3837 uint32_t fenceCount
, const VkFence
*pFences
)
3839 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3840 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3841 if (fence
->fence
== NULL
|| fence
->syncobj
||
3842 fence
->temp_syncobj
|| fence
->fence_wsi
||
3843 (!device
->ws
->is_fence_waitable(fence
->fence
)))
3849 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3851 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3852 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3853 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3859 VkResult
radv_WaitForFences(
3861 uint32_t fenceCount
,
3862 const VkFence
* pFences
,
3866 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3867 timeout
= radv_get_absolute_timeout(timeout
);
3869 if (device
->always_use_syncobj
&&
3870 radv_all_fences_syncobj(fenceCount
, pFences
))
3872 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3874 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3876 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3877 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3878 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3881 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3884 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3887 if (!waitAll
&& fenceCount
> 1) {
3888 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3889 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(device
, fenceCount
, pFences
)) {
3890 uint32_t wait_count
= 0;
3891 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3893 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3895 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3896 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3898 if (device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0)) {
3903 fences
[wait_count
++] = fence
->fence
;
3906 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3907 waitAll
, timeout
- radv_get_current_time());
3910 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3913 while(radv_get_current_time() <= timeout
) {
3914 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3915 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3922 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3923 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3924 bool expired
= false;
3926 if (fence
->temp_syncobj
) {
3927 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3932 if (fence
->syncobj
) {
3933 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3939 if (!device
->ws
->is_fence_waitable(fence
->fence
)) {
3940 while(!device
->ws
->is_fence_waitable(fence
->fence
) &&
3941 radv_get_current_time() <= timeout
)
3945 expired
= device
->ws
->fence_wait(device
->ws
,
3952 if (fence
->fence_wsi
) {
3953 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3954 if (result
!= VK_SUCCESS
)
3962 VkResult
radv_ResetFences(VkDevice _device
,
3963 uint32_t fenceCount
,
3964 const VkFence
*pFences
)
3966 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3968 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3969 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3971 device
->ws
->reset_fence(fence
->fence
);
3973 /* Per spec, we first restore the permanent payload, and then reset, so
3974 * having a temp syncobj should not skip resetting the permanent syncobj. */
3975 if (fence
->temp_syncobj
) {
3976 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3977 fence
->temp_syncobj
= 0;
3980 if (fence
->syncobj
) {
3981 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3988 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3990 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3991 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3993 if (fence
->temp_syncobj
) {
3994 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3995 return success
? VK_SUCCESS
: VK_NOT_READY
;
3998 if (fence
->syncobj
) {
3999 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
4000 return success
? VK_SUCCESS
: VK_NOT_READY
;
4004 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
4005 return VK_NOT_READY
;
4007 if (fence
->fence_wsi
) {
4008 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
4010 if (result
!= VK_SUCCESS
) {
4011 if (result
== VK_TIMEOUT
)
4012 return VK_NOT_READY
;
4020 // Queue semaphore functions
4022 VkResult
radv_CreateSemaphore(
4024 const VkSemaphoreCreateInfo
* pCreateInfo
,
4025 const VkAllocationCallbacks
* pAllocator
,
4026 VkSemaphore
* pSemaphore
)
4028 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4029 const VkExportSemaphoreCreateInfo
*export
=
4030 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
4031 VkExternalSemaphoreHandleTypeFlags handleTypes
=
4032 export
? export
->handleTypes
: 0;
4034 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
4036 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4038 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4040 sem
->temp_syncobj
= 0;
4041 /* create a syncobject if we are going to export this semaphore */
4042 if (device
->always_use_syncobj
|| handleTypes
) {
4043 assert (device
->physical_device
->rad_info
.has_syncobj
);
4044 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
4046 vk_free2(&device
->alloc
, pAllocator
, sem
);
4047 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4051 sem
->sem
= device
->ws
->create_sem(device
->ws
);
4053 vk_free2(&device
->alloc
, pAllocator
, sem
);
4054 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4059 *pSemaphore
= radv_semaphore_to_handle(sem
);
4063 void radv_DestroySemaphore(
4065 VkSemaphore _semaphore
,
4066 const VkAllocationCallbacks
* pAllocator
)
4068 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4069 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
4074 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
4076 device
->ws
->destroy_sem(sem
->sem
);
4077 vk_free2(&device
->alloc
, pAllocator
, sem
);
4080 VkResult
radv_CreateEvent(
4082 const VkEventCreateInfo
* pCreateInfo
,
4083 const VkAllocationCallbacks
* pAllocator
,
4086 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4087 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
4089 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4092 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4094 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
4096 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
4097 RADV_BO_PRIORITY_FENCE
);
4099 vk_free2(&device
->alloc
, pAllocator
, event
);
4100 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4103 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
4105 *pEvent
= radv_event_to_handle(event
);
4110 void radv_DestroyEvent(
4113 const VkAllocationCallbacks
* pAllocator
)
4115 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4116 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4120 device
->ws
->buffer_destroy(event
->bo
);
4121 vk_free2(&device
->alloc
, pAllocator
, event
);
4124 VkResult
radv_GetEventStatus(
4128 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4130 if (*event
->map
== 1)
4131 return VK_EVENT_SET
;
4132 return VK_EVENT_RESET
;
4135 VkResult
radv_SetEvent(
4139 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4145 VkResult
radv_ResetEvent(
4149 RADV_FROM_HANDLE(radv_event
, event
, _event
);
4155 VkResult
radv_CreateBuffer(
4157 const VkBufferCreateInfo
* pCreateInfo
,
4158 const VkAllocationCallbacks
* pAllocator
,
4161 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4162 struct radv_buffer
*buffer
;
4164 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4166 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4167 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4169 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4171 buffer
->size
= pCreateInfo
->size
;
4172 buffer
->usage
= pCreateInfo
->usage
;
4175 buffer
->flags
= pCreateInfo
->flags
;
4177 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4178 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4180 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4181 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4182 align64(buffer
->size
, 4096),
4183 4096, 0, RADEON_FLAG_VIRTUAL
,
4184 RADV_BO_PRIORITY_VIRTUAL
);
4186 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4187 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4191 *pBuffer
= radv_buffer_to_handle(buffer
);
4196 void radv_DestroyBuffer(
4199 const VkAllocationCallbacks
* pAllocator
)
4201 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4202 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4207 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4208 device
->ws
->buffer_destroy(buffer
->bo
);
4210 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4213 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4215 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4217 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4218 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4222 static inline unsigned
4223 si_tile_mode_index(const struct radv_image_plane
*plane
, unsigned level
, bool stencil
)
4226 return plane
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4228 return plane
->surface
.u
.legacy
.tiling_index
[level
];
4231 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4233 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4237 radv_init_dcc_control_reg(struct radv_device
*device
,
4238 struct radv_image_view
*iview
)
4240 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4241 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4242 unsigned max_compressed_block_size
;
4243 unsigned independent_128b_blocks
;
4244 unsigned independent_64b_blocks
;
4246 if (!radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4249 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4250 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4251 * dGPU and 64 for APU because all of our APUs to date use
4252 * DIMMs which have a request granularity size of 64B while all
4253 * other chips have a 32B request size.
4255 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4258 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4259 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4260 independent_64b_blocks
= 0;
4261 independent_128b_blocks
= 1;
4263 independent_128b_blocks
= 0;
4265 if (iview
->image
->info
.samples
> 1) {
4266 if (iview
->image
->planes
[0].surface
.bpe
== 1)
4267 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4268 else if (iview
->image
->planes
[0].surface
.bpe
== 2)
4269 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4272 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4273 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4274 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4275 /* If this DCC image is potentially going to be used in texture
4276 * fetches, we need some special settings.
4278 independent_64b_blocks
= 1;
4279 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4281 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4282 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4283 * big as possible for better compression state.
4285 independent_64b_blocks
= 0;
4286 max_compressed_block_size
= max_uncompressed_block_size
;
4290 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4291 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4292 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4293 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
) |
4294 S_028C78_INDEPENDENT_128B_BLOCKS(independent_128b_blocks
);
4298 radv_initialise_color_surface(struct radv_device
*device
,
4299 struct radv_color_buffer_info
*cb
,
4300 struct radv_image_view
*iview
)
4302 const struct vk_format_description
*desc
;
4303 unsigned ntype
, format
, swap
, endian
;
4304 unsigned blend_clamp
= 0, blend_bypass
= 0;
4306 const struct radv_image_plane
*plane
= &iview
->image
->planes
[iview
->plane_id
];
4307 const struct radeon_surf
*surf
= &plane
->surface
;
4309 desc
= vk_format_description(iview
->vk_format
);
4311 memset(cb
, 0, sizeof(*cb
));
4313 /* Intensity is implemented as Red, so treat it that way. */
4314 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4316 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ plane
->offset
;
4318 cb
->cb_color_base
= va
>> 8;
4320 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4321 struct gfx9_surf_meta_flags meta
;
4322 if (iview
->image
->dcc_offset
)
4323 meta
= surf
->u
.gfx9
.dcc
;
4325 meta
= surf
->u
.gfx9
.cmask
;
4327 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4328 cb
->cb_color_attrib3
|= S_028EE0_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4329 S_028EE0_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4330 S_028EE0_CMASK_PIPE_ALIGNED(surf
->u
.gfx9
.cmask
.pipe_aligned
) |
4331 S_028EE0_DCC_PIPE_ALIGNED(surf
->u
.gfx9
.dcc
.pipe_aligned
);
4333 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4334 S_028C74_FMASK_SW_MODE(surf
->u
.gfx9
.fmask
.swizzle_mode
) |
4335 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4336 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4337 cb
->cb_mrt_epitch
= S_0287A0_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4340 cb
->cb_color_base
+= surf
->u
.gfx9
.surf_offset
>> 8;
4341 cb
->cb_color_base
|= surf
->tile_swizzle
;
4343 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4344 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4346 cb
->cb_color_base
+= level_info
->offset
>> 8;
4347 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4348 cb
->cb_color_base
|= surf
->tile_swizzle
;
4350 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4351 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4352 tile_mode_index
= si_tile_mode_index(plane
, iview
->base_mip
, false);
4354 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4355 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4356 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
4358 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4360 if (radv_image_has_fmask(iview
->image
)) {
4361 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4362 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
4363 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4364 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4366 /* This must be set for fast clear to work without FMASK. */
4367 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
)
4368 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4369 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4370 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4374 /* CMASK variables */
4375 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4376 va
+= iview
->image
->cmask
.offset
;
4377 cb
->cb_color_cmask
= va
>> 8;
4379 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4380 va
+= iview
->image
->dcc_offset
;
4382 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
) &&
4383 device
->physical_device
->rad_info
.chip_class
<= GFX8
)
4384 va
+= plane
->surface
.u
.legacy
.level
[iview
->base_mip
].dcc_offset
;
4386 cb
->cb_dcc_base
= va
>> 8;
4387 cb
->cb_dcc_base
|= surf
->tile_swizzle
;
4389 /* GFX10 field has the same base shift as the GFX6 field. */
4390 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4391 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4392 S_028C6C_SLICE_MAX_GFX10(max_slice
);
4394 if (iview
->image
->info
.samples
> 1) {
4395 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4397 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4398 S_028C74_NUM_FRAGMENTS(log_samples
);
4401 if (radv_image_has_fmask(iview
->image
)) {
4402 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4403 cb
->cb_color_fmask
= va
>> 8;
4404 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4406 cb
->cb_color_fmask
= cb
->cb_color_base
;
4409 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4411 vk_format_get_first_non_void_channel(iview
->vk_format
));
4412 format
= radv_translate_colorformat(iview
->vk_format
);
4413 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4414 radv_finishme("Illegal color\n");
4415 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4416 endian
= radv_colorformat_endian_swap(format
);
4418 /* blend clamp should be set for all NORM/SRGB types */
4419 if (ntype
== V_028C70_NUMBER_UNORM
||
4420 ntype
== V_028C70_NUMBER_SNORM
||
4421 ntype
== V_028C70_NUMBER_SRGB
)
4424 /* set blend bypass according to docs if SINT/UINT or
4425 8/24 COLOR variants */
4426 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4427 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4428 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4433 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4434 (format
== V_028C70_COLOR_8
||
4435 format
== V_028C70_COLOR_8_8
||
4436 format
== V_028C70_COLOR_8_8_8_8
))
4437 ->color_is_int8
= true;
4439 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4440 S_028C70_COMP_SWAP(swap
) |
4441 S_028C70_BLEND_CLAMP(blend_clamp
) |
4442 S_028C70_BLEND_BYPASS(blend_bypass
) |
4443 S_028C70_SIMPLE_FLOAT(1) |
4444 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4445 ntype
!= V_028C70_NUMBER_SNORM
&&
4446 ntype
!= V_028C70_NUMBER_SRGB
&&
4447 format
!= V_028C70_COLOR_8_24
&&
4448 format
!= V_028C70_COLOR_24_8
) |
4449 S_028C70_NUMBER_TYPE(ntype
) |
4450 S_028C70_ENDIAN(endian
);
4451 if (radv_image_has_fmask(iview
->image
)) {
4452 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4453 if (device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4454 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4455 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4458 if (radv_image_is_tc_compat_cmask(iview
->image
)) {
4459 /* Allow the texture block to read FMASK directly
4460 * without decompressing it. This bit must be cleared
4461 * when performing FMASK_DECOMPRESS or DCC_COMPRESS,
4462 * otherwise the operation doesn't happen.
4464 cb
->cb_color_info
|= S_028C70_FMASK_COMPRESS_1FRAG_ONLY(1);
4466 /* Set CMASK into a tiling format that allows the
4467 * texture block to read it.
4469 cb
->cb_color_info
|= S_028C70_CMASK_ADDR_TYPE(2);
4473 if (radv_image_has_cmask(iview
->image
) &&
4474 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4475 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4477 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4478 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4480 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4482 /* This must be set for fast clear to work without FMASK. */
4483 if (!radv_image_has_fmask(iview
->image
) &&
4484 device
->physical_device
->rad_info
.chip_class
== GFX6
) {
4485 unsigned bankh
= util_logbase2(surf
->u
.legacy
.bankh
);
4486 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4489 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4490 const struct vk_format_description
*format_desc
= vk_format_description(iview
->image
->vk_format
);
4492 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4493 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4494 unsigned width
= iview
->extent
.width
/ (iview
->plane_id
? format_desc
->width_divisor
: 1);
4495 unsigned height
= iview
->extent
.height
/ (iview
->plane_id
? format_desc
->height_divisor
: 1);
4497 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4498 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX10(iview
->base_mip
);
4500 cb
->cb_color_attrib3
|= S_028EE0_MIP0_DEPTH(mip0_depth
) |
4501 S_028EE0_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
) |
4502 S_028EE0_RESOURCE_LEVEL(1);
4504 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL_GFX9(iview
->base_mip
);
4505 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4506 S_028C74_RESOURCE_TYPE(surf
->u
.gfx9
.resource_type
);
4509 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(width
- 1) |
4510 S_028C68_MIP0_HEIGHT(height
- 1) |
4511 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4516 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4517 struct radv_image_view
*iview
)
4519 unsigned max_zplanes
= 0;
4521 assert(radv_image_is_tc_compat_htile(iview
->image
));
4523 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4524 /* Default value for 32-bit depth surfaces. */
4527 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4528 iview
->image
->info
.samples
> 1)
4531 max_zplanes
= max_zplanes
+ 1;
4533 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4534 /* Do not enable Z plane compression for 16-bit depth
4535 * surfaces because isn't supported on GFX8. Only
4536 * 32-bit depth surfaces are supported by the hardware.
4537 * This allows to maintain shader compatibility and to
4538 * reduce the number of depth decompressions.
4542 if (iview
->image
->info
.samples
<= 1)
4544 else if (iview
->image
->info
.samples
<= 4)
4555 radv_initialise_ds_surface(struct radv_device
*device
,
4556 struct radv_ds_buffer_info
*ds
,
4557 struct radv_image_view
*iview
)
4559 unsigned level
= iview
->base_mip
;
4560 unsigned format
, stencil_format
;
4561 uint64_t va
, s_offs
, z_offs
;
4562 bool stencil_only
= false;
4563 const struct radv_image_plane
*plane
= &iview
->image
->planes
[0];
4564 const struct radeon_surf
*surf
= &plane
->surface
;
4566 assert(vk_format_get_plane_count(iview
->image
->vk_format
) == 1);
4568 memset(ds
, 0, sizeof(*ds
));
4569 switch (iview
->image
->vk_format
) {
4570 case VK_FORMAT_D24_UNORM_S8_UINT
:
4571 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4572 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4573 ds
->offset_scale
= 2.0f
;
4575 case VK_FORMAT_D16_UNORM
:
4576 case VK_FORMAT_D16_UNORM_S8_UINT
:
4577 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4578 ds
->offset_scale
= 4.0f
;
4580 case VK_FORMAT_D32_SFLOAT
:
4581 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4582 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4583 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4584 ds
->offset_scale
= 1.0f
;
4586 case VK_FORMAT_S8_UINT
:
4587 stencil_only
= true;
4593 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4594 stencil_format
= surf
->has_stencil
?
4595 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4597 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4598 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4599 S_028008_SLICE_MAX(max_slice
);
4600 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4601 ds
->db_depth_view
|= S_028008_SLICE_START_HI(iview
->base_layer
>> 11) |
4602 S_028008_SLICE_MAX_HI(max_slice
>> 11);
4605 ds
->db_htile_data_base
= 0;
4606 ds
->db_htile_surface
= 0;
4608 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4609 s_offs
= z_offs
= va
;
4611 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4612 assert(surf
->u
.gfx9
.surf_offset
== 0);
4613 s_offs
+= surf
->u
.gfx9
.stencil_offset
;
4615 ds
->db_z_info
= S_028038_FORMAT(format
) |
4616 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4617 S_028038_SW_MODE(surf
->u
.gfx9
.surf
.swizzle_mode
) |
4618 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4619 S_028038_ZRANGE_PRECISION(1);
4620 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4621 S_02803C_SW_MODE(surf
->u
.gfx9
.stencil
.swizzle_mode
);
4623 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4624 ds
->db_z_info2
= S_028068_EPITCH(surf
->u
.gfx9
.surf
.epitch
);
4625 ds
->db_stencil_info2
= S_02806C_EPITCH(surf
->u
.gfx9
.stencil
.epitch
);
4628 ds
->db_depth_view
|= S_028008_MIPID(level
);
4629 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4630 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4632 if (radv_htile_enabled(iview
->image
, level
)) {
4633 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4635 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4636 unsigned max_zplanes
=
4637 radv_calc_decompress_on_z_planes(device
, iview
);
4639 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4641 if (device
->physical_device
->rad_info
.chip_class
>= GFX10
) {
4642 ds
->db_z_info
|= S_028040_ITERATE_FLUSH(1);
4643 ds
->db_stencil_info
|= S_028044_ITERATE_FLUSH(1);
4645 ds
->db_z_info
|= S_028038_ITERATE_FLUSH(1);
4646 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4650 if (!surf
->has_stencil
)
4651 /* Use all of the htile_buffer for depth if there's no stencil. */
4652 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4653 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4654 iview
->image
->htile_offset
;
4655 ds
->db_htile_data_base
= va
>> 8;
4656 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4657 S_028ABC_PIPE_ALIGNED(surf
->u
.gfx9
.htile
.pipe_aligned
);
4659 if (device
->physical_device
->rad_info
.chip_class
== GFX9
) {
4660 ds
->db_htile_surface
|= S_028ABC_RB_ALIGNED(surf
->u
.gfx9
.htile
.rb_aligned
);
4664 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[level
];
4667 level_info
= &surf
->u
.legacy
.stencil_level
[level
];
4669 z_offs
+= surf
->u
.legacy
.level
[level
].offset
;
4670 s_offs
+= surf
->u
.legacy
.stencil_level
[level
].offset
;
4672 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4673 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4674 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4676 if (iview
->image
->info
.samples
> 1)
4677 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4679 if (device
->physical_device
->rad_info
.chip_class
>= GFX7
) {
4680 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4681 unsigned tiling_index
= surf
->u
.legacy
.tiling_index
[level
];
4682 unsigned stencil_index
= surf
->u
.legacy
.stencil_tiling_index
[level
];
4683 unsigned macro_index
= surf
->u
.legacy
.macro_tile_index
;
4684 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4685 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4686 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4689 tile_mode
= stencil_tile_mode
;
4691 ds
->db_depth_info
|=
4692 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4693 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4694 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4695 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4696 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4697 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4698 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4699 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4701 unsigned tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, false);
4702 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4703 tile_mode_index
= si_tile_mode_index(&iview
->image
->planes
[0], level
, true);
4704 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4706 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4709 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4710 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4711 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4713 if (radv_htile_enabled(iview
->image
, level
)) {
4714 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4716 if (!surf
->has_stencil
&&
4717 !radv_image_is_tc_compat_htile(iview
->image
))
4718 /* Use all of the htile_buffer for depth if there's no stencil. */
4719 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4721 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4722 iview
->image
->htile_offset
;
4723 ds
->db_htile_data_base
= va
>> 8;
4724 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4726 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4727 unsigned max_zplanes
=
4728 radv_calc_decompress_on_z_planes(device
, iview
);
4730 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4731 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4736 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4737 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4740 VkResult
radv_CreateFramebuffer(
4742 const VkFramebufferCreateInfo
* pCreateInfo
,
4743 const VkAllocationCallbacks
* pAllocator
,
4744 VkFramebuffer
* pFramebuffer
)
4746 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4747 struct radv_framebuffer
*framebuffer
;
4749 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4751 size_t size
= sizeof(*framebuffer
) +
4752 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4753 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4754 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4755 if (framebuffer
== NULL
)
4756 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4758 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4759 framebuffer
->width
= pCreateInfo
->width
;
4760 framebuffer
->height
= pCreateInfo
->height
;
4761 framebuffer
->layers
= pCreateInfo
->layers
;
4762 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4763 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4764 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4765 framebuffer
->attachments
[i
].attachment
= iview
;
4766 if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4767 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4769 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4771 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4772 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4773 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4776 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4780 void radv_DestroyFramebuffer(
4783 const VkAllocationCallbacks
* pAllocator
)
4785 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4786 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4790 vk_free2(&device
->alloc
, pAllocator
, fb
);
4793 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4795 switch (address_mode
) {
4796 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4797 return V_008F30_SQ_TEX_WRAP
;
4798 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4799 return V_008F30_SQ_TEX_MIRROR
;
4800 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4801 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4802 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4803 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4804 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4805 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4807 unreachable("illegal tex wrap mode");
4813 radv_tex_compare(VkCompareOp op
)
4816 case VK_COMPARE_OP_NEVER
:
4817 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4818 case VK_COMPARE_OP_LESS
:
4819 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4820 case VK_COMPARE_OP_EQUAL
:
4821 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4822 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4823 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4824 case VK_COMPARE_OP_GREATER
:
4825 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4826 case VK_COMPARE_OP_NOT_EQUAL
:
4827 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4828 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4829 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4830 case VK_COMPARE_OP_ALWAYS
:
4831 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4833 unreachable("illegal compare mode");
4839 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4842 case VK_FILTER_NEAREST
:
4843 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4844 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4845 case VK_FILTER_LINEAR
:
4846 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4847 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4848 case VK_FILTER_CUBIC_IMG
:
4850 fprintf(stderr
, "illegal texture filter");
4856 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4859 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4860 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4861 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4862 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4864 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4869 radv_tex_bordercolor(VkBorderColor bcolor
)
4872 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4873 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4874 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4875 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4876 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4877 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4878 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4879 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4880 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4888 radv_tex_aniso_filter(unsigned filter
)
4902 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4905 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4906 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4907 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4908 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
4909 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4910 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
4918 radv_get_max_anisotropy(struct radv_device
*device
,
4919 const VkSamplerCreateInfo
*pCreateInfo
)
4921 if (device
->force_aniso
>= 0)
4922 return device
->force_aniso
;
4924 if (pCreateInfo
->anisotropyEnable
&&
4925 pCreateInfo
->maxAnisotropy
> 1.0f
)
4926 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4932 radv_init_sampler(struct radv_device
*device
,
4933 struct radv_sampler
*sampler
,
4934 const VkSamplerCreateInfo
*pCreateInfo
)
4936 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4937 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4938 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= GFX8
);
4939 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4941 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4942 vk_find_struct_const(pCreateInfo
->pNext
,
4943 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4944 if (sampler_reduction
)
4945 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4947 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4948 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4949 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4950 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4951 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4952 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4953 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4954 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4955 S_008F30_DISABLE_CUBE_WRAP(0) |
4956 S_008F30_COMPAT_MODE(is_vi
) |
4957 S_008F30_FILTER_MODE(filter_mode
));
4958 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4959 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4960 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4961 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4962 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4963 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4964 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4965 S_008F38_MIP_POINT_PRECLAMP(0) |
4966 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= GFX8
) |
4967 S_008F38_FILTER_PREC_FIX(1) |
4968 S_008F38_ANISO_OVERRIDE_GFX6(is_vi
));
4969 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4970 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4973 VkResult
radv_CreateSampler(
4975 const VkSamplerCreateInfo
* pCreateInfo
,
4976 const VkAllocationCallbacks
* pAllocator
,
4977 VkSampler
* pSampler
)
4979 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4980 struct radv_sampler
*sampler
;
4982 const struct VkSamplerYcbcrConversionInfo
*ycbcr_conversion
=
4983 vk_find_struct_const(pCreateInfo
->pNext
,
4984 SAMPLER_YCBCR_CONVERSION_INFO
);
4986 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4988 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4989 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4991 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4993 radv_init_sampler(device
, sampler
, pCreateInfo
);
4995 sampler
->ycbcr_sampler
= ycbcr_conversion
? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion
->conversion
): NULL
;
4996 *pSampler
= radv_sampler_to_handle(sampler
);
5001 void radv_DestroySampler(
5004 const VkAllocationCallbacks
* pAllocator
)
5006 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5007 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
5011 vk_free2(&device
->alloc
, pAllocator
, sampler
);
5014 /* vk_icd.h does not declare this function, so we declare it here to
5015 * suppress Wmissing-prototypes.
5017 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5018 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
5020 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
5021 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
5023 /* For the full details on loader interface versioning, see
5024 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
5025 * What follows is a condensed summary, to help you navigate the large and
5026 * confusing official doc.
5028 * - Loader interface v0 is incompatible with later versions. We don't
5031 * - In loader interface v1:
5032 * - The first ICD entrypoint called by the loader is
5033 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
5035 * - The ICD must statically expose no other Vulkan symbol unless it is
5036 * linked with -Bsymbolic.
5037 * - Each dispatchable Vulkan handle created by the ICD must be
5038 * a pointer to a struct whose first member is VK_LOADER_DATA. The
5039 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
5040 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
5041 * vkDestroySurfaceKHR(). The ICD must be capable of working with
5042 * such loader-managed surfaces.
5044 * - Loader interface v2 differs from v1 in:
5045 * - The first ICD entrypoint called by the loader is
5046 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
5047 * statically expose this entrypoint.
5049 * - Loader interface v3 differs from v2 in:
5050 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
5051 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
5052 * because the loader no longer does so.
5054 *pSupportedVersion
= MIN2(*pSupportedVersion
, 4u);
5058 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
5059 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
5062 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5063 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
5065 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
5067 /* At the moment, we support only the below handle types. */
5068 assert(pGetFdInfo
->handleType
==
5069 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
5070 pGetFdInfo
->handleType
==
5071 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
5073 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
5075 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5079 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
5080 VkExternalMemoryHandleTypeFlagBits handleType
,
5082 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
5084 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5086 switch (handleType
) {
5087 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
5088 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
5092 /* The valid usage section for this function says:
5094 * "handleType must not be one of the handle types defined as
5097 * So opaque handle types fall into the default "unsupported" case.
5099 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5103 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
5107 uint32_t syncobj_handle
= 0;
5108 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
5110 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5113 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
5115 *syncobj
= syncobj_handle
;
5121 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
5125 /* If we create a syncobj we do it locally so that if we have an error, we don't
5126 * leave a syncobj in an undetermined state in the fence. */
5127 uint32_t syncobj_handle
= *syncobj
;
5128 if (!syncobj_handle
) {
5129 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
5131 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5136 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
5138 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
5140 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5143 *syncobj
= syncobj_handle
;
5150 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
5151 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
5153 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5154 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
5155 uint32_t *syncobj_dst
= NULL
;
5157 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
5158 syncobj_dst
= &sem
->temp_syncobj
;
5160 syncobj_dst
= &sem
->syncobj
;
5163 switch(pImportSemaphoreFdInfo
->handleType
) {
5164 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5165 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5166 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5167 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
5169 unreachable("Unhandled semaphore handle type");
5173 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
5174 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
5177 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5178 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
5180 uint32_t syncobj_handle
;
5182 if (sem
->temp_syncobj
)
5183 syncobj_handle
= sem
->temp_syncobj
;
5185 syncobj_handle
= sem
->syncobj
;
5187 switch(pGetFdInfo
->handleType
) {
5188 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5189 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5191 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
5192 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5194 if (sem
->temp_syncobj
) {
5195 close (sem
->temp_syncobj
);
5196 sem
->temp_syncobj
= 0;
5198 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5203 unreachable("Unhandled semaphore handle type");
5207 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5211 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
5212 VkPhysicalDevice physicalDevice
,
5213 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
5214 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
5216 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5218 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
5219 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5220 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5221 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5222 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5223 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
5224 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5225 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5226 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
5227 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5228 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
5229 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
5230 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5232 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
5233 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
5234 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
5238 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
5239 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
5241 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5242 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5243 uint32_t *syncobj_dst
= NULL
;
5246 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5247 syncobj_dst
= &fence
->temp_syncobj
;
5249 syncobj_dst
= &fence
->syncobj
;
5252 switch(pImportFenceFdInfo
->handleType
) {
5253 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5254 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5255 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5256 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5258 unreachable("Unhandled fence handle type");
5262 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5263 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5266 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5267 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5269 uint32_t syncobj_handle
;
5271 if (fence
->temp_syncobj
)
5272 syncobj_handle
= fence
->temp_syncobj
;
5274 syncobj_handle
= fence
->syncobj
;
5276 switch(pGetFdInfo
->handleType
) {
5277 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5278 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5280 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5281 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5283 if (fence
->temp_syncobj
) {
5284 close (fence
->temp_syncobj
);
5285 fence
->temp_syncobj
= 0;
5287 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5292 unreachable("Unhandled fence handle type");
5296 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5300 void radv_GetPhysicalDeviceExternalFenceProperties(
5301 VkPhysicalDevice physicalDevice
,
5302 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5303 VkExternalFenceProperties
*pExternalFenceProperties
)
5305 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5307 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5308 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5309 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5310 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5311 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5312 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5313 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5315 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5316 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5317 pExternalFenceProperties
->externalFenceFeatures
= 0;
5322 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5323 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5324 const VkAllocationCallbacks
* pAllocator
,
5325 VkDebugReportCallbackEXT
* pCallback
)
5327 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5328 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5329 pCreateInfo
, pAllocator
, &instance
->alloc
,
5334 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5335 VkDebugReportCallbackEXT _callback
,
5336 const VkAllocationCallbacks
* pAllocator
)
5338 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5339 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5340 _callback
, pAllocator
, &instance
->alloc
);
5344 radv_DebugReportMessageEXT(VkInstance _instance
,
5345 VkDebugReportFlagsEXT flags
,
5346 VkDebugReportObjectTypeEXT objectType
,
5349 int32_t messageCode
,
5350 const char* pLayerPrefix
,
5351 const char* pMessage
)
5353 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5354 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5355 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5359 radv_GetDeviceGroupPeerMemoryFeatures(
5362 uint32_t localDeviceIndex
,
5363 uint32_t remoteDeviceIndex
,
5364 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5366 assert(localDeviceIndex
== remoteDeviceIndex
);
5368 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5369 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5370 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5371 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5374 static const VkTimeDomainEXT radv_time_domains
[] = {
5375 VK_TIME_DOMAIN_DEVICE_EXT
,
5376 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5377 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5380 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5381 VkPhysicalDevice physicalDevice
,
5382 uint32_t *pTimeDomainCount
,
5383 VkTimeDomainEXT
*pTimeDomains
)
5386 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5388 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5389 vk_outarray_append(&out
, i
) {
5390 *i
= radv_time_domains
[d
];
5394 return vk_outarray_status(&out
);
5398 radv_clock_gettime(clockid_t clock_id
)
5400 struct timespec current
;
5403 ret
= clock_gettime(clock_id
, ¤t
);
5404 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5405 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5409 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5412 VkResult
radv_GetCalibratedTimestampsEXT(
5414 uint32_t timestampCount
,
5415 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5416 uint64_t *pTimestamps
,
5417 uint64_t *pMaxDeviation
)
5419 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5420 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5422 uint64_t begin
, end
;
5423 uint64_t max_clock_period
= 0;
5425 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5427 for (d
= 0; d
< timestampCount
; d
++) {
5428 switch (pTimestampInfos
[d
].timeDomain
) {
5429 case VK_TIME_DOMAIN_DEVICE_EXT
:
5430 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5432 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5433 max_clock_period
= MAX2(max_clock_period
, device_period
);
5435 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5436 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5437 max_clock_period
= MAX2(max_clock_period
, 1);
5440 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5441 pTimestamps
[d
] = begin
;
5449 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5452 * The maximum deviation is the sum of the interval over which we
5453 * perform the sampling and the maximum period of any sampled
5454 * clock. That's because the maximum skew between any two sampled
5455 * clock edges is when the sampled clock with the largest period is
5456 * sampled at the end of that period but right at the beginning of the
5457 * sampling interval and some other clock is sampled right at the
5458 * begining of its sampling period and right at the end of the
5459 * sampling interval. Let's assume the GPU has the longest clock
5460 * period and that the application is sampling GPU and monotonic:
5463 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5464 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5468 * GPU -----_____-----_____-----_____-----_____
5471 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5472 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5474 * Interval <----------------->
5475 * Deviation <-------------------------->
5479 * m = read(monotonic) 2
5482 * We round the sample interval up by one tick to cover sampling error
5483 * in the interval clock
5486 uint64_t sample_interval
= end
- begin
+ 1;
5488 *pMaxDeviation
= sample_interval
+ max_clock_period
;
5493 void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
5494 VkPhysicalDevice physicalDevice
,
5495 VkSampleCountFlagBits samples
,
5496 VkMultisamplePropertiesEXT
* pMultisampleProperties
)
5498 if (samples
& (VK_SAMPLE_COUNT_2_BIT
|
5499 VK_SAMPLE_COUNT_4_BIT
|
5500 VK_SAMPLE_COUNT_8_BIT
)) {
5501 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 2, 2 };
5503 pMultisampleProperties
->maxSampleLocationGridSize
= (VkExtent2D
){ 0, 0 };