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 "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/build_id.h"
49 #include "util/debug.h"
50 #include "util/mesa-sha1.h"
53 radv_get_build_id(void *ptr
, struct mesa_sha1
*ctx
)
57 #ifdef HAVE_DL_ITERATE_PHDR
58 const struct build_id_note
*note
= NULL
;
59 if ((note
= build_id_find_nhdr_for_addr(ptr
))) {
60 _mesa_sha1_update(ctx
, build_id_data(note
), build_id_length(note
));
63 if (disk_cache_get_function_timestamp(ptr
, ×tamp
)) {
64 _mesa_sha1_update(ctx
, ×tamp
, sizeof(timestamp
));
71 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
74 unsigned char sha1
[20];
75 unsigned ptr_size
= sizeof(void*);
77 memset(uuid
, 0, VK_UUID_SIZE
);
78 _mesa_sha1_init(&ctx
);
80 if (!radv_get_build_id(radv_device_get_cache_uuid
, &ctx
) ||
81 !radv_get_build_id(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
84 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
85 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
86 _mesa_sha1_final(&ctx
, sha1
);
88 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
93 radv_get_driver_uuid(void *uuid
)
95 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
99 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
101 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
105 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
107 const char *chip_string
;
108 char llvm_string
[32] = {};
111 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
112 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
113 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
114 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
115 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
116 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
117 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
118 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
119 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
120 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
121 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
122 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
123 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
124 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
125 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
126 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
127 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
128 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
129 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
130 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
131 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
132 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
133 default: chip_string
= "AMD RADV unknown"; break;
136 snprintf(llvm_string
, sizeof(llvm_string
),
137 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
138 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
139 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
143 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
145 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
146 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
147 device
->rad_info
.vram_vis_size
);
149 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
150 device
->memory_properties
.memoryHeapCount
= 0;
151 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
152 vram_index
= device
->memory_properties
.memoryHeapCount
++;
153 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
154 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
155 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
158 if (visible_vram_size
) {
159 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
160 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
161 .size
= visible_vram_size
,
162 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
165 if (device
->rad_info
.gart_size
> 0) {
166 gart_index
= device
->memory_properties
.memoryHeapCount
++;
167 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
168 .size
= device
->rad_info
.gart_size
,
169 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
173 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
174 unsigned type_count
= 0;
175 if (vram_index
>= 0) {
176 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
177 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
178 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
179 .heapIndex
= vram_index
,
182 if (gart_index
>= 0) {
183 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
184 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
185 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
186 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
187 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
188 .heapIndex
= gart_index
,
191 if (visible_vram_index
>= 0) {
192 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
193 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
194 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
195 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
196 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
197 .heapIndex
= visible_vram_index
,
200 if (gart_index
>= 0) {
201 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
202 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
203 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
204 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
205 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
206 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
207 .heapIndex
= gart_index
,
210 device
->memory_properties
.memoryTypeCount
= type_count
;
214 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
216 const char *family
= getenv("RADV_FORCE_FAMILY");
222 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
223 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
224 /* Override family and chip_class. */
225 device
->rad_info
.family
= i
;
227 if (i
>= CHIP_VEGA10
)
228 device
->rad_info
.chip_class
= GFX9
;
229 else if (i
>= CHIP_TONGA
)
230 device
->rad_info
.chip_class
= VI
;
231 else if (i
>= CHIP_BONAIRE
)
232 device
->rad_info
.chip_class
= CIK
;
234 device
->rad_info
.chip_class
= SI
;
240 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
245 radv_physical_device_init(struct radv_physical_device
*device
,
246 struct radv_instance
*instance
,
247 drmDevicePtr drm_device
)
249 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
251 drmVersionPtr version
;
255 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
257 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
258 radv_logi("Could not open device '%s'", path
);
260 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
263 version
= drmGetVersion(fd
);
267 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
268 radv_logi("Could not get the kernel driver version for device '%s'", path
);
270 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
271 "failed to get version %s: %m", path
);
274 if (strcmp(version
->name
, "amdgpu")) {
275 drmFreeVersion(version
);
278 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
279 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
281 return VK_ERROR_INCOMPATIBLE_DRIVER
;
283 drmFreeVersion(version
);
285 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
286 radv_logi("Found compatible device '%s'.", path
);
288 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
289 device
->instance
= instance
;
290 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
291 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
293 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
294 instance
->perftest_flags
);
296 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
300 if (instance
->enabled_extensions
.KHR_display
) {
301 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
302 if (master_fd
>= 0) {
303 uint32_t accel_working
= 0;
304 struct drm_amdgpu_info request
= {
305 .return_pointer
= (uintptr_t)&accel_working
,
306 .return_size
= sizeof(accel_working
),
307 .query
= AMDGPU_INFO_ACCEL_WORKING
310 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
317 device
->master_fd
= master_fd
;
318 device
->local_fd
= fd
;
319 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
321 radv_handle_env_var_force_family(device
);
323 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
325 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
326 device
->ws
->destroy(device
->ws
);
327 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
328 "cannot generate UUID");
332 /* These flags affect shader compilation. */
333 uint64_t shader_env_flags
=
334 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
335 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
337 /* The gpu id is already embedded in the uuid so we just pass "radv"
338 * when creating the cache.
340 char buf
[VK_UUID_SIZE
* 2 + 1];
341 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
342 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
344 if (device
->rad_info
.chip_class
< VI
||
345 device
->rad_info
.chip_class
> GFX9
)
346 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
348 radv_get_driver_uuid(&device
->device_uuid
);
349 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
351 if (device
->rad_info
.family
== CHIP_STONEY
||
352 device
->rad_info
.chip_class
>= GFX9
) {
353 device
->has_rbplus
= true;
354 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
355 device
->rad_info
.family
== CHIP_VEGA12
||
356 device
->rad_info
.family
== CHIP_RAVEN
;
359 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
362 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
364 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
366 /* Vega10/Raven need a special workaround for a hardware bug. */
367 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
368 device
->rad_info
.family
== CHIP_RAVEN
;
370 /* Out-of-order primitive rasterization. */
371 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
372 device
->rad_info
.max_se
>= 2;
373 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
374 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
376 device
->dcc_msaa_allowed
=
377 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
379 radv_physical_device_init_mem_types(device
);
380 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
382 device
->bus_info
= *drm_device
->businfo
.pci
;
384 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
385 ac_print_gpu_info(&device
->rad_info
);
387 /* The WSI is structured as a layer on top of the driver, so this has
388 * to be the last part of initialization (at least until we get other
391 result
= radv_init_wsi(device
);
392 if (result
!= VK_SUCCESS
) {
393 device
->ws
->destroy(device
->ws
);
394 vk_error(instance
, result
);
408 radv_physical_device_finish(struct radv_physical_device
*device
)
410 radv_finish_wsi(device
);
411 device
->ws
->destroy(device
->ws
);
412 disk_cache_destroy(device
->disk_cache
);
413 close(device
->local_fd
);
414 if (device
->master_fd
!= -1)
415 close(device
->master_fd
);
419 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
420 VkSystemAllocationScope allocationScope
)
426 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
427 size_t align
, VkSystemAllocationScope allocationScope
)
429 return realloc(pOriginal
, size
);
433 default_free_func(void *pUserData
, void *pMemory
)
438 static const VkAllocationCallbacks default_alloc
= {
440 .pfnAllocation
= default_alloc_func
,
441 .pfnReallocation
= default_realloc_func
,
442 .pfnFree
= default_free_func
,
445 static const struct debug_control radv_debug_options
[] = {
446 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
447 {"nodcc", RADV_DEBUG_NO_DCC
},
448 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
449 {"nocache", RADV_DEBUG_NO_CACHE
},
450 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
451 {"nohiz", RADV_DEBUG_NO_HIZ
},
452 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
453 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
454 {"allbos", RADV_DEBUG_ALL_BOS
},
455 {"noibs", RADV_DEBUG_NO_IBS
},
456 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
457 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
458 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
459 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
460 {"nosisched", RADV_DEBUG_NO_SISCHED
},
461 {"preoptir", RADV_DEBUG_PREOPTIR
},
462 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
463 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
464 {"info", RADV_DEBUG_INFO
},
465 {"errors", RADV_DEBUG_ERRORS
},
466 {"startup", RADV_DEBUG_STARTUP
},
467 {"checkir", RADV_DEBUG_CHECKIR
},
468 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
473 radv_get_debug_option_name(int id
)
475 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
476 return radv_debug_options
[id
].string
;
479 static const struct debug_control radv_perftest_options
[] = {
480 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
481 {"sisched", RADV_PERFTEST_SISCHED
},
482 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
483 {"binning", RADV_PERFTEST_BINNING
},
484 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
489 radv_get_perftest_option_name(int id
)
491 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
492 return radv_perftest_options
[id
].string
;
496 radv_handle_per_app_options(struct radv_instance
*instance
,
497 const VkApplicationInfo
*info
)
499 const char *name
= info
? info
->pApplicationName
: NULL
;
504 if (!strcmp(name
, "Talos - Linux - 32bit") ||
505 !strcmp(name
, "Talos - Linux - 64bit")) {
506 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
507 /* Force enable LLVM sisched for Talos because it looks
508 * safe and it gives few more FPS.
510 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
512 } else if (!strcmp(name
, "DOOM_VFR")) {
513 /* Work around a Doom VFR game bug */
514 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
518 static int radv_get_instance_extension_index(const char *name
)
520 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
521 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
528 VkResult
radv_CreateInstance(
529 const VkInstanceCreateInfo
* pCreateInfo
,
530 const VkAllocationCallbacks
* pAllocator
,
531 VkInstance
* pInstance
)
533 struct radv_instance
*instance
;
536 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
538 uint32_t client_version
;
539 if (pCreateInfo
->pApplicationInfo
&&
540 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
541 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
543 radv_EnumerateInstanceVersion(&client_version
);
546 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
547 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
549 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
551 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
554 instance
->alloc
= *pAllocator
;
556 instance
->alloc
= default_alloc
;
558 instance
->apiVersion
= client_version
;
559 instance
->physicalDeviceCount
= -1;
561 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
564 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
565 radv_perftest_options
);
568 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
569 radv_logi("Created an instance");
571 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
572 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
573 int index
= radv_get_instance_extension_index(ext_name
);
575 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
576 vk_free2(&default_alloc
, pAllocator
, instance
);
577 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
580 instance
->enabled_extensions
.extensions
[index
] = true;
583 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
584 if (result
!= VK_SUCCESS
) {
585 vk_free2(&default_alloc
, pAllocator
, instance
);
586 return vk_error(instance
, result
);
591 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
593 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
595 *pInstance
= radv_instance_to_handle(instance
);
600 void radv_DestroyInstance(
601 VkInstance _instance
,
602 const VkAllocationCallbacks
* pAllocator
)
604 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
609 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
610 radv_physical_device_finish(instance
->physicalDevices
+ i
);
613 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
617 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
619 vk_free(&instance
->alloc
, instance
);
623 radv_enumerate_devices(struct radv_instance
*instance
)
625 /* TODO: Check for more devices ? */
626 drmDevicePtr devices
[8];
627 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
630 instance
->physicalDeviceCount
= 0;
632 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
634 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
635 radv_logi("Found %d drm nodes", max_devices
);
638 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
640 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
641 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
642 devices
[i
]->bustype
== DRM_BUS_PCI
&&
643 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
645 result
= radv_physical_device_init(instance
->physicalDevices
+
646 instance
->physicalDeviceCount
,
649 if (result
== VK_SUCCESS
)
650 ++instance
->physicalDeviceCount
;
651 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
655 drmFreeDevices(devices
, max_devices
);
660 VkResult
radv_EnumeratePhysicalDevices(
661 VkInstance _instance
,
662 uint32_t* pPhysicalDeviceCount
,
663 VkPhysicalDevice
* pPhysicalDevices
)
665 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
668 if (instance
->physicalDeviceCount
< 0) {
669 result
= radv_enumerate_devices(instance
);
670 if (result
!= VK_SUCCESS
&&
671 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
675 if (!pPhysicalDevices
) {
676 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
678 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
679 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
680 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
683 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
687 VkResult
radv_EnumeratePhysicalDeviceGroups(
688 VkInstance _instance
,
689 uint32_t* pPhysicalDeviceGroupCount
,
690 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
692 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
695 if (instance
->physicalDeviceCount
< 0) {
696 result
= radv_enumerate_devices(instance
);
697 if (result
!= VK_SUCCESS
&&
698 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
702 if (!pPhysicalDeviceGroupProperties
) {
703 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
705 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
706 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
707 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
708 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
709 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
712 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
716 void radv_GetPhysicalDeviceFeatures(
717 VkPhysicalDevice physicalDevice
,
718 VkPhysicalDeviceFeatures
* pFeatures
)
720 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
721 memset(pFeatures
, 0, sizeof(*pFeatures
));
723 *pFeatures
= (VkPhysicalDeviceFeatures
) {
724 .robustBufferAccess
= true,
725 .fullDrawIndexUint32
= true,
726 .imageCubeArray
= true,
727 .independentBlend
= true,
728 .geometryShader
= true,
729 .tessellationShader
= true,
730 .sampleRateShading
= true,
731 .dualSrcBlend
= true,
733 .multiDrawIndirect
= true,
734 .drawIndirectFirstInstance
= true,
736 .depthBiasClamp
= true,
737 .fillModeNonSolid
= true,
742 .multiViewport
= true,
743 .samplerAnisotropy
= true,
744 .textureCompressionETC2
= pdevice
->rad_info
.chip_class
>= GFX9
||
745 pdevice
->rad_info
.family
== CHIP_STONEY
,
746 .textureCompressionASTC_LDR
= false,
747 .textureCompressionBC
= true,
748 .occlusionQueryPrecise
= true,
749 .pipelineStatisticsQuery
= true,
750 .vertexPipelineStoresAndAtomics
= true,
751 .fragmentStoresAndAtomics
= true,
752 .shaderTessellationAndGeometryPointSize
= true,
753 .shaderImageGatherExtended
= true,
754 .shaderStorageImageExtendedFormats
= true,
755 .shaderStorageImageMultisample
= false,
756 .shaderUniformBufferArrayDynamicIndexing
= true,
757 .shaderSampledImageArrayDynamicIndexing
= true,
758 .shaderStorageBufferArrayDynamicIndexing
= true,
759 .shaderStorageImageArrayDynamicIndexing
= true,
760 .shaderStorageImageReadWithoutFormat
= true,
761 .shaderStorageImageWriteWithoutFormat
= true,
762 .shaderClipDistance
= true,
763 .shaderCullDistance
= true,
764 .shaderFloat64
= true,
766 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
&& HAVE_LLVM
>= 0x700,
767 .sparseBinding
= true,
768 .variableMultisampleRate
= true,
769 .inheritedQueries
= true,
773 void radv_GetPhysicalDeviceFeatures2(
774 VkPhysicalDevice physicalDevice
,
775 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
777 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
778 vk_foreach_struct(ext
, pFeatures
->pNext
) {
779 switch (ext
->sType
) {
780 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
781 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
782 features
->variablePointersStorageBuffer
= true;
783 features
->variablePointers
= false;
786 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
787 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
788 features
->multiview
= true;
789 features
->multiviewGeometryShader
= true;
790 features
->multiviewTessellationShader
= true;
793 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
794 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
795 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
796 features
->shaderDrawParameters
= true;
799 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
800 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
801 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
802 features
->protectedMemory
= false;
805 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
806 VkPhysicalDevice16BitStorageFeatures
*features
=
807 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
808 bool enabled
= HAVE_LLVM
>= 0x0700 && pdevice
->rad_info
.chip_class
>= VI
;
809 features
->storageBuffer16BitAccess
= enabled
;
810 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
811 features
->storagePushConstant16
= enabled
;
812 features
->storageInputOutput16
= enabled
;
815 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
816 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
817 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
818 features
->samplerYcbcrConversion
= false;
821 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
822 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
823 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
824 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
825 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
826 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
827 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
828 features
->shaderSampledImageArrayNonUniformIndexing
= false;
829 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
830 features
->shaderStorageImageArrayNonUniformIndexing
= false;
831 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
832 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
833 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
834 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
835 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
836 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
837 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
838 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
839 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
840 features
->descriptorBindingUpdateUnusedWhilePending
= true;
841 features
->descriptorBindingPartiallyBound
= true;
842 features
->descriptorBindingVariableDescriptorCount
= true;
843 features
->runtimeDescriptorArray
= true;
846 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
847 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
848 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
849 features
->conditionalRendering
= true;
850 features
->inheritedConditionalRendering
= false;
853 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
854 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
855 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
856 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
857 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
864 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
867 void radv_GetPhysicalDeviceProperties(
868 VkPhysicalDevice physicalDevice
,
869 VkPhysicalDeviceProperties
* pProperties
)
871 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
872 VkSampleCountFlags sample_counts
= 0xf;
874 /* make sure that the entire descriptor set is addressable with a signed
875 * 32-bit int. So the sum of all limits scaled by descriptor size has to
876 * be at most 2 GiB. the combined image & samples object count as one of
877 * both. This limit is for the pipeline layout, not for the set layout, but
878 * there is no set limit, so we just set a pipeline limit. I don't think
879 * any app is going to hit this soon. */
880 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
881 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
882 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
883 32 /* sampler, largest when combined with image */ +
884 64 /* sampled image */ +
885 64 /* storage image */);
887 VkPhysicalDeviceLimits limits
= {
888 .maxImageDimension1D
= (1 << 14),
889 .maxImageDimension2D
= (1 << 14),
890 .maxImageDimension3D
= (1 << 11),
891 .maxImageDimensionCube
= (1 << 14),
892 .maxImageArrayLayers
= (1 << 11),
893 .maxTexelBufferElements
= 128 * 1024 * 1024,
894 .maxUniformBufferRange
= UINT32_MAX
,
895 .maxStorageBufferRange
= UINT32_MAX
,
896 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
897 .maxMemoryAllocationCount
= UINT32_MAX
,
898 .maxSamplerAllocationCount
= 64 * 1024,
899 .bufferImageGranularity
= 64, /* A cache line */
900 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
901 .maxBoundDescriptorSets
= MAX_SETS
,
902 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
903 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
904 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
905 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
906 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
907 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
908 .maxPerStageResources
= max_descriptor_set_size
,
909 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
910 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
911 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
912 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
913 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
914 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
915 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
916 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
917 .maxVertexInputAttributes
= 32,
918 .maxVertexInputBindings
= 32,
919 .maxVertexInputAttributeOffset
= 2047,
920 .maxVertexInputBindingStride
= 2048,
921 .maxVertexOutputComponents
= 128,
922 .maxTessellationGenerationLevel
= 64,
923 .maxTessellationPatchSize
= 32,
924 .maxTessellationControlPerVertexInputComponents
= 128,
925 .maxTessellationControlPerVertexOutputComponents
= 128,
926 .maxTessellationControlPerPatchOutputComponents
= 120,
927 .maxTessellationControlTotalOutputComponents
= 4096,
928 .maxTessellationEvaluationInputComponents
= 128,
929 .maxTessellationEvaluationOutputComponents
= 128,
930 .maxGeometryShaderInvocations
= 127,
931 .maxGeometryInputComponents
= 64,
932 .maxGeometryOutputComponents
= 128,
933 .maxGeometryOutputVertices
= 256,
934 .maxGeometryTotalOutputComponents
= 1024,
935 .maxFragmentInputComponents
= 128,
936 .maxFragmentOutputAttachments
= 8,
937 .maxFragmentDualSrcAttachments
= 1,
938 .maxFragmentCombinedOutputResources
= 8,
939 .maxComputeSharedMemorySize
= 32768,
940 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
941 .maxComputeWorkGroupInvocations
= 2048,
942 .maxComputeWorkGroupSize
= {
947 .subPixelPrecisionBits
= 4 /* FIXME */,
948 .subTexelPrecisionBits
= 4 /* FIXME */,
949 .mipmapPrecisionBits
= 4 /* FIXME */,
950 .maxDrawIndexedIndexValue
= UINT32_MAX
,
951 .maxDrawIndirectCount
= UINT32_MAX
,
952 .maxSamplerLodBias
= 16,
953 .maxSamplerAnisotropy
= 16,
954 .maxViewports
= MAX_VIEWPORTS
,
955 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
956 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
957 .viewportSubPixelBits
= 8,
958 .minMemoryMapAlignment
= 4096, /* A page */
959 .minTexelBufferOffsetAlignment
= 1,
960 .minUniformBufferOffsetAlignment
= 4,
961 .minStorageBufferOffsetAlignment
= 4,
962 .minTexelOffset
= -32,
963 .maxTexelOffset
= 31,
964 .minTexelGatherOffset
= -32,
965 .maxTexelGatherOffset
= 31,
966 .minInterpolationOffset
= -2,
967 .maxInterpolationOffset
= 2,
968 .subPixelInterpolationOffsetBits
= 8,
969 .maxFramebufferWidth
= (1 << 14),
970 .maxFramebufferHeight
= (1 << 14),
971 .maxFramebufferLayers
= (1 << 10),
972 .framebufferColorSampleCounts
= sample_counts
,
973 .framebufferDepthSampleCounts
= sample_counts
,
974 .framebufferStencilSampleCounts
= sample_counts
,
975 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
976 .maxColorAttachments
= MAX_RTS
,
977 .sampledImageColorSampleCounts
= sample_counts
,
978 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
979 .sampledImageDepthSampleCounts
= sample_counts
,
980 .sampledImageStencilSampleCounts
= sample_counts
,
981 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
982 .maxSampleMaskWords
= 1,
983 .timestampComputeAndGraphics
= true,
984 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
985 .maxClipDistances
= 8,
986 .maxCullDistances
= 8,
987 .maxCombinedClipAndCullDistances
= 8,
988 .discreteQueuePriorities
= 2,
989 .pointSizeRange
= { 0.125, 255.875 },
990 .lineWidthRange
= { 0.0, 7.9921875 },
991 .pointSizeGranularity
= (1.0 / 8.0),
992 .lineWidthGranularity
= (1.0 / 128.0),
993 .strictLines
= false, /* FINISHME */
994 .standardSampleLocations
= true,
995 .optimalBufferCopyOffsetAlignment
= 128,
996 .optimalBufferCopyRowPitchAlignment
= 128,
997 .nonCoherentAtomSize
= 64,
1000 *pProperties
= (VkPhysicalDeviceProperties
) {
1001 .apiVersion
= radv_physical_device_api_version(pdevice
),
1002 .driverVersion
= vk_get_driver_version(),
1003 .vendorID
= ATI_VENDOR_ID
,
1004 .deviceID
= pdevice
->rad_info
.pci_id
,
1005 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1007 .sparseProperties
= {0},
1010 strcpy(pProperties
->deviceName
, pdevice
->name
);
1011 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1014 void radv_GetPhysicalDeviceProperties2(
1015 VkPhysicalDevice physicalDevice
,
1016 VkPhysicalDeviceProperties2KHR
*pProperties
)
1018 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1019 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1021 vk_foreach_struct(ext
, pProperties
->pNext
) {
1022 switch (ext
->sType
) {
1023 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1024 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1025 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1026 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1029 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
1030 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
1031 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1032 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1033 properties
->deviceLUIDValid
= false;
1036 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
1037 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
1038 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1039 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1042 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
1043 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
1044 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
1045 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
1048 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1049 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1050 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1051 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1054 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1055 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1056 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1057 properties
->minImportedHostPointerAlignment
= 4096;
1060 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1061 VkPhysicalDeviceSubgroupProperties
*properties
=
1062 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1063 properties
->subgroupSize
= 64;
1064 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1065 /* TODO: Enable VK_SUBGROUP_FEATURE_VOTE_BIT when wwm
1068 properties
->supportedOperations
=
1069 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1070 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1071 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1072 VK_SUBGROUP_FEATURE_QUAD_BIT
;
1073 if (pdevice
->rad_info
.chip_class
>= VI
) {
1074 properties
->supportedOperations
|=
1075 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1076 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1078 properties
->quadOperationsInAllStages
= true;
1081 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1082 VkPhysicalDeviceMaintenance3Properties
*properties
=
1083 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1084 /* Make sure everything is addressable by a signed 32-bit int, and
1085 * our largest descriptors are 96 bytes. */
1086 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1087 /* Our buffer size fields allow only this much */
1088 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1091 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1092 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1093 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1094 /* GFX6-8 only support single channel min/max filter. */
1095 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1096 properties
->filterMinmaxSingleComponentFormats
= true;
1099 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1100 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1101 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1103 /* Shader engines. */
1104 properties
->shaderEngineCount
=
1105 pdevice
->rad_info
.max_se
;
1106 properties
->shaderArraysPerEngineCount
=
1107 pdevice
->rad_info
.max_sh_per_se
;
1108 properties
->computeUnitsPerShaderArray
=
1109 pdevice
->rad_info
.num_good_compute_units
/
1110 (pdevice
->rad_info
.max_se
*
1111 pdevice
->rad_info
.max_sh_per_se
);
1112 properties
->simdPerComputeUnit
= 4;
1113 properties
->wavefrontsPerSimd
=
1114 pdevice
->rad_info
.family
== CHIP_TONGA
||
1115 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1116 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1117 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1118 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1119 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1120 properties
->wavefrontSize
= 64;
1123 properties
->sgprsPerSimd
=
1124 radv_get_num_physical_sgprs(pdevice
);
1125 properties
->minSgprAllocation
=
1126 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1127 properties
->maxSgprAllocation
=
1128 pdevice
->rad_info
.family
== CHIP_TONGA
||
1129 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1130 properties
->sgprAllocationGranularity
=
1131 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1134 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1135 properties
->minVgprAllocation
= 4;
1136 properties
->maxVgprAllocation
= 256;
1137 properties
->vgprAllocationGranularity
= 4;
1140 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1141 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1142 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1143 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1146 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1147 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1148 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1149 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1150 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1151 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1152 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1153 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1154 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1155 properties
->robustBufferAccessUpdateAfterBind
= false;
1156 properties
->quadDivergentImplicitLod
= false;
1158 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1159 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1160 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1161 32 /* sampler, largest when combined with image */ +
1162 64 /* sampled image */ +
1163 64 /* storage image */);
1164 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1165 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1166 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1167 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1168 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1169 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1170 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1171 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1172 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1173 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1174 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1175 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1176 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1177 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1178 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1181 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1182 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1183 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1184 properties
->protectedNoFault
= false;
1187 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1188 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1189 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1190 properties
->primitiveOverestimationSize
= 0;
1191 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1192 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1193 properties
->primitiveUnderestimation
= VK_FALSE
;
1194 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1195 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1196 properties
->degenerateLinesRasterized
= VK_FALSE
;
1197 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1198 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1201 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1202 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1203 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1204 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1205 properties
->pciBus
= pdevice
->bus_info
.bus
;
1206 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1207 properties
->pciFunction
= pdevice
->bus_info
.func
;
1216 static void radv_get_physical_device_queue_family_properties(
1217 struct radv_physical_device
* pdevice
,
1219 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1221 int num_queue_families
= 1;
1223 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1224 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1225 num_queue_families
++;
1227 if (pQueueFamilyProperties
== NULL
) {
1228 *pCount
= num_queue_families
;
1237 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1238 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1239 VK_QUEUE_COMPUTE_BIT
|
1240 VK_QUEUE_TRANSFER_BIT
|
1241 VK_QUEUE_SPARSE_BINDING_BIT
,
1243 .timestampValidBits
= 64,
1244 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1249 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1250 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1251 if (*pCount
> idx
) {
1252 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1253 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1254 VK_QUEUE_TRANSFER_BIT
|
1255 VK_QUEUE_SPARSE_BINDING_BIT
,
1256 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1257 .timestampValidBits
= 64,
1258 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1266 void radv_GetPhysicalDeviceQueueFamilyProperties(
1267 VkPhysicalDevice physicalDevice
,
1269 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1271 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1272 if (!pQueueFamilyProperties
) {
1273 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1276 VkQueueFamilyProperties
*properties
[] = {
1277 pQueueFamilyProperties
+ 0,
1278 pQueueFamilyProperties
+ 1,
1279 pQueueFamilyProperties
+ 2,
1281 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1282 assert(*pCount
<= 3);
1285 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1286 VkPhysicalDevice physicalDevice
,
1288 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1290 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1291 if (!pQueueFamilyProperties
) {
1292 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1295 VkQueueFamilyProperties
*properties
[] = {
1296 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1297 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1298 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1300 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1301 assert(*pCount
<= 3);
1304 void radv_GetPhysicalDeviceMemoryProperties(
1305 VkPhysicalDevice physicalDevice
,
1306 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1308 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1310 *pMemoryProperties
= physical_device
->memory_properties
;
1313 void radv_GetPhysicalDeviceMemoryProperties2(
1314 VkPhysicalDevice physicalDevice
,
1315 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1317 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1318 &pMemoryProperties
->memoryProperties
);
1321 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1323 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1324 const void *pHostPointer
,
1325 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1327 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1331 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1332 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1333 uint32_t memoryTypeBits
= 0;
1334 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1335 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1336 memoryTypeBits
= (1 << i
);
1340 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1344 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1348 static enum radeon_ctx_priority
1349 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1351 /* Default to MEDIUM when a specific global priority isn't requested */
1353 return RADEON_CTX_PRIORITY_MEDIUM
;
1355 switch(pObj
->globalPriority
) {
1356 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1357 return RADEON_CTX_PRIORITY_REALTIME
;
1358 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1359 return RADEON_CTX_PRIORITY_HIGH
;
1360 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1361 return RADEON_CTX_PRIORITY_MEDIUM
;
1362 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1363 return RADEON_CTX_PRIORITY_LOW
;
1365 unreachable("Illegal global priority value");
1366 return RADEON_CTX_PRIORITY_INVALID
;
1371 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1372 uint32_t queue_family_index
, int idx
,
1373 VkDeviceQueueCreateFlags flags
,
1374 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1376 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1377 queue
->device
= device
;
1378 queue
->queue_family_index
= queue_family_index
;
1379 queue
->queue_idx
= idx
;
1380 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1381 queue
->flags
= flags
;
1383 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1385 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1391 radv_queue_finish(struct radv_queue
*queue
)
1394 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1396 if (queue
->initial_full_flush_preamble_cs
)
1397 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1398 if (queue
->initial_preamble_cs
)
1399 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1400 if (queue
->continue_preamble_cs
)
1401 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1402 if (queue
->descriptor_bo
)
1403 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1404 if (queue
->scratch_bo
)
1405 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1406 if (queue
->esgs_ring_bo
)
1407 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1408 if (queue
->gsvs_ring_bo
)
1409 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1410 if (queue
->tess_rings_bo
)
1411 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1412 if (queue
->compute_scratch_bo
)
1413 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1417 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1419 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1420 bo_list
->list
.count
= bo_list
->capacity
= 0;
1421 bo_list
->list
.bos
= NULL
;
1425 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1427 free(bo_list
->list
.bos
);
1428 pthread_mutex_destroy(&bo_list
->mutex
);
1431 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1432 struct radeon_winsys_bo
*bo
)
1434 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1436 if (unlikely(!device
->use_global_bo_list
))
1439 pthread_mutex_lock(&bo_list
->mutex
);
1440 if (bo_list
->list
.count
== bo_list
->capacity
) {
1441 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1442 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1445 pthread_mutex_unlock(&bo_list
->mutex
);
1446 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1449 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1450 bo_list
->capacity
= capacity
;
1453 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1454 pthread_mutex_unlock(&bo_list
->mutex
);
1458 static void radv_bo_list_remove(struct radv_device
*device
,
1459 struct radeon_winsys_bo
*bo
)
1461 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1463 if (unlikely(!device
->use_global_bo_list
))
1466 pthread_mutex_lock(&bo_list
->mutex
);
1467 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1468 if (bo_list
->list
.bos
[i
] == bo
) {
1469 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1470 --bo_list
->list
.count
;
1474 pthread_mutex_unlock(&bo_list
->mutex
);
1478 radv_device_init_gs_info(struct radv_device
*device
)
1480 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1481 device
->physical_device
->rad_info
.family
);
1484 static int radv_get_device_extension_index(const char *name
)
1486 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1487 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1494 radv_get_int_debug_option(const char *name
, int default_value
)
1501 result
= default_value
;
1505 result
= strtol(str
, &endptr
, 0);
1506 if (str
== endptr
) {
1507 /* No digits founs. */
1508 result
= default_value
;
1515 VkResult
radv_CreateDevice(
1516 VkPhysicalDevice physicalDevice
,
1517 const VkDeviceCreateInfo
* pCreateInfo
,
1518 const VkAllocationCallbacks
* pAllocator
,
1521 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1523 struct radv_device
*device
;
1525 bool keep_shader_info
= false;
1527 /* Check enabled features */
1528 if (pCreateInfo
->pEnabledFeatures
) {
1529 VkPhysicalDeviceFeatures supported_features
;
1530 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1531 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1532 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1533 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1534 for (uint32_t i
= 0; i
< num_features
; i
++) {
1535 if (enabled_feature
[i
] && !supported_feature
[i
])
1536 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1540 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1542 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1544 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1546 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1547 device
->instance
= physical_device
->instance
;
1548 device
->physical_device
= physical_device
;
1550 device
->ws
= physical_device
->ws
;
1552 device
->alloc
= *pAllocator
;
1554 device
->alloc
= physical_device
->instance
->alloc
;
1556 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1557 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1558 int index
= radv_get_device_extension_index(ext_name
);
1559 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1560 vk_free(&device
->alloc
, device
);
1561 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1564 device
->enabled_extensions
.extensions
[index
] = true;
1567 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1569 /* With update after bind we can't attach bo's to the command buffer
1570 * from the descriptor set anymore, so we have to use a global BO list.
1572 device
->use_global_bo_list
=
1573 device
->enabled_extensions
.EXT_descriptor_indexing
;
1575 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1576 list_inithead(&device
->shader_slabs
);
1578 radv_bo_list_init(&device
->bo_list
);
1580 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1581 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1582 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1583 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1584 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1586 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1588 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1589 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1590 if (!device
->queues
[qfi
]) {
1591 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1595 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1597 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1599 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1600 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1601 qfi
, q
, queue_create
->flags
,
1603 if (result
!= VK_SUCCESS
)
1608 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1609 ((device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
) ||
1610 device
->physical_device
->rad_info
.family
== CHIP_RAVEN
);
1612 /* Disabled and not implemented for now. */
1613 device
->dfsm_allowed
= device
->pbb_allowed
&&
1614 device
->physical_device
->rad_info
.family
== CHIP_RAVEN
;
1617 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1620 /* The maximum number of scratch waves. Scratch space isn't divided
1621 * evenly between CUs. The number is only a function of the number of CUs.
1622 * We can decrease the constant to decrease the scratch buffer size.
1624 * sctx->scratch_waves must be >= the maximum possible size of
1625 * 1 threadgroup, so that the hw doesn't hang from being unable
1628 * The recommended value is 4 per CU at most. Higher numbers don't
1629 * bring much benefit, but they still occupy chip resources (think
1630 * async compute). I've seen ~2% performance difference between 4 and 32.
1632 uint32_t max_threads_per_block
= 2048;
1633 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1634 max_threads_per_block
/ 64);
1636 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1638 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1639 /* If the KMD allows it (there is a KMD hw register for it),
1640 * allow launching waves out-of-order.
1642 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1645 radv_device_init_gs_info(device
);
1647 device
->tess_offchip_block_dw_size
=
1648 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1649 device
->has_distributed_tess
=
1650 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1651 device
->physical_device
->rad_info
.max_se
>= 2;
1653 if (getenv("RADV_TRACE_FILE")) {
1654 const char *filename
= getenv("RADV_TRACE_FILE");
1656 keep_shader_info
= true;
1658 if (!radv_init_trace(device
))
1661 fprintf(stderr
, "*****************************************************************************\n");
1662 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1663 fprintf(stderr
, "*****************************************************************************\n");
1665 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1666 radv_dump_enabled_options(device
, stderr
);
1669 device
->keep_shader_info
= keep_shader_info
;
1671 result
= radv_device_init_meta(device
);
1672 if (result
!= VK_SUCCESS
)
1675 radv_device_init_msaa(device
);
1677 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1678 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1680 case RADV_QUEUE_GENERAL
:
1681 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1682 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1683 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1685 case RADV_QUEUE_COMPUTE
:
1686 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1687 radeon_emit(device
->empty_cs
[family
], 0);
1690 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1693 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1694 cik_create_gfx_config(device
);
1696 VkPipelineCacheCreateInfo ci
;
1697 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1700 ci
.pInitialData
= NULL
;
1701 ci
.initialDataSize
= 0;
1703 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1705 if (result
!= VK_SUCCESS
)
1708 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1710 device
->force_aniso
=
1711 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1712 if (device
->force_aniso
>= 0) {
1713 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
1714 1 << util_logbase2(device
->force_aniso
));
1717 *pDevice
= radv_device_to_handle(device
);
1721 radv_device_finish_meta(device
);
1723 radv_bo_list_finish(&device
->bo_list
);
1725 if (device
->trace_bo
)
1726 device
->ws
->buffer_destroy(device
->trace_bo
);
1728 if (device
->gfx_init
)
1729 device
->ws
->buffer_destroy(device
->gfx_init
);
1731 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1732 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1733 radv_queue_finish(&device
->queues
[i
][q
]);
1734 if (device
->queue_count
[i
])
1735 vk_free(&device
->alloc
, device
->queues
[i
]);
1738 vk_free(&device
->alloc
, device
);
1742 void radv_DestroyDevice(
1744 const VkAllocationCallbacks
* pAllocator
)
1746 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1751 if (device
->trace_bo
)
1752 device
->ws
->buffer_destroy(device
->trace_bo
);
1754 if (device
->gfx_init
)
1755 device
->ws
->buffer_destroy(device
->gfx_init
);
1757 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1758 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1759 radv_queue_finish(&device
->queues
[i
][q
]);
1760 if (device
->queue_count
[i
])
1761 vk_free(&device
->alloc
, device
->queues
[i
]);
1762 if (device
->empty_cs
[i
])
1763 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1765 radv_device_finish_meta(device
);
1767 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1768 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1770 radv_destroy_shader_slabs(device
);
1772 radv_bo_list_finish(&device
->bo_list
);
1773 vk_free(&device
->alloc
, device
);
1776 VkResult
radv_EnumerateInstanceLayerProperties(
1777 uint32_t* pPropertyCount
,
1778 VkLayerProperties
* pProperties
)
1780 if (pProperties
== NULL
) {
1781 *pPropertyCount
= 0;
1785 /* None supported at this time */
1786 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1789 VkResult
radv_EnumerateDeviceLayerProperties(
1790 VkPhysicalDevice physicalDevice
,
1791 uint32_t* pPropertyCount
,
1792 VkLayerProperties
* pProperties
)
1794 if (pProperties
== NULL
) {
1795 *pPropertyCount
= 0;
1799 /* None supported at this time */
1800 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1803 void radv_GetDeviceQueue2(
1805 const VkDeviceQueueInfo2
* pQueueInfo
,
1808 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1809 struct radv_queue
*queue
;
1811 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1812 if (pQueueInfo
->flags
!= queue
->flags
) {
1813 /* From the Vulkan 1.1.70 spec:
1815 * "The queue returned by vkGetDeviceQueue2 must have the same
1816 * flags value from this structure as that used at device
1817 * creation time in a VkDeviceQueueCreateInfo instance. If no
1818 * matching flags were specified at device creation time then
1819 * pQueue will return VK_NULL_HANDLE."
1821 *pQueue
= VK_NULL_HANDLE
;
1825 *pQueue
= radv_queue_to_handle(queue
);
1828 void radv_GetDeviceQueue(
1830 uint32_t queueFamilyIndex
,
1831 uint32_t queueIndex
,
1834 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1835 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1836 .queueFamilyIndex
= queueFamilyIndex
,
1837 .queueIndex
= queueIndex
1840 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1844 fill_geom_tess_rings(struct radv_queue
*queue
,
1846 bool add_sample_positions
,
1847 uint32_t esgs_ring_size
,
1848 struct radeon_winsys_bo
*esgs_ring_bo
,
1849 uint32_t gsvs_ring_size
,
1850 struct radeon_winsys_bo
*gsvs_ring_bo
,
1851 uint32_t tess_factor_ring_size
,
1852 uint32_t tess_offchip_ring_offset
,
1853 uint32_t tess_offchip_ring_size
,
1854 struct radeon_winsys_bo
*tess_rings_bo
)
1856 uint64_t esgs_va
= 0, gsvs_va
= 0;
1857 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1858 uint32_t *desc
= &map
[4];
1861 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1863 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1864 if (tess_rings_bo
) {
1865 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1866 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1869 /* stride 0, num records - size, add tid, swizzle, elsize4,
1872 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1873 S_008F04_STRIDE(0) |
1874 S_008F04_SWIZZLE_ENABLE(true);
1875 desc
[2] = esgs_ring_size
;
1876 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1877 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1878 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1879 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1880 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1881 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1882 S_008F0C_ELEMENT_SIZE(1) |
1883 S_008F0C_INDEX_STRIDE(3) |
1884 S_008F0C_ADD_TID_ENABLE(true);
1887 /* GS entry for ES->GS ring */
1888 /* stride 0, num records - size, elsize0,
1891 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1892 S_008F04_STRIDE(0) |
1893 S_008F04_SWIZZLE_ENABLE(false);
1894 desc
[2] = esgs_ring_size
;
1895 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1896 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1897 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1898 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1899 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1900 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1901 S_008F0C_ELEMENT_SIZE(0) |
1902 S_008F0C_INDEX_STRIDE(0) |
1903 S_008F0C_ADD_TID_ENABLE(false);
1906 /* VS entry for GS->VS ring */
1907 /* stride 0, num records - size, elsize0,
1910 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1911 S_008F04_STRIDE(0) |
1912 S_008F04_SWIZZLE_ENABLE(false);
1913 desc
[2] = gsvs_ring_size
;
1914 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1915 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1916 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1917 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1918 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1919 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1920 S_008F0C_ELEMENT_SIZE(0) |
1921 S_008F0C_INDEX_STRIDE(0) |
1922 S_008F0C_ADD_TID_ENABLE(false);
1925 /* stride gsvs_itemsize, num records 64
1926 elsize 4, index stride 16 */
1927 /* shader will patch stride and desc[2] */
1929 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1930 S_008F04_STRIDE(0) |
1931 S_008F04_SWIZZLE_ENABLE(true);
1933 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1934 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1935 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1936 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1937 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1938 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1939 S_008F0C_ELEMENT_SIZE(1) |
1940 S_008F0C_INDEX_STRIDE(1) |
1941 S_008F0C_ADD_TID_ENABLE(true);
1945 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1946 S_008F04_STRIDE(0) |
1947 S_008F04_SWIZZLE_ENABLE(false);
1948 desc
[2] = tess_factor_ring_size
;
1949 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1950 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1951 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1952 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1953 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1954 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1955 S_008F0C_ELEMENT_SIZE(0) |
1956 S_008F0C_INDEX_STRIDE(0) |
1957 S_008F0C_ADD_TID_ENABLE(false);
1960 desc
[0] = tess_offchip_va
;
1961 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1962 S_008F04_STRIDE(0) |
1963 S_008F04_SWIZZLE_ENABLE(false);
1964 desc
[2] = tess_offchip_ring_size
;
1965 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1966 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1967 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1968 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1969 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1970 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1971 S_008F0C_ELEMENT_SIZE(0) |
1972 S_008F0C_INDEX_STRIDE(0) |
1973 S_008F0C_ADD_TID_ENABLE(false);
1976 /* add sample positions after all rings */
1977 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1979 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1981 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1983 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1985 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1989 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1991 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1992 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1993 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1994 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1995 unsigned max_offchip_buffers
;
1996 unsigned offchip_granularity
;
1997 unsigned hs_offchip_param
;
2001 * This must be one less than the maximum number due to a hw limitation.
2002 * Various hardware bugs in SI, CIK, and GFX9 need this.
2005 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2006 * Gfx7 should limit max_offchip_buffers to 508
2007 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2009 * Follow AMDVLK here.
2011 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2012 device
->physical_device
->rad_info
.chip_class
== CIK
||
2013 device
->physical_device
->rad_info
.chip_class
== SI
)
2014 --max_offchip_buffers_per_se
;
2016 max_offchip_buffers
= max_offchip_buffers_per_se
*
2017 device
->physical_device
->rad_info
.max_se
;
2019 switch (device
->tess_offchip_block_dw_size
) {
2024 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2027 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2031 switch (device
->physical_device
->rad_info
.chip_class
) {
2033 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2039 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2043 *max_offchip_buffers_p
= max_offchip_buffers
;
2044 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2045 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
2046 --max_offchip_buffers
;
2048 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2049 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2052 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2054 return hs_offchip_param
;
2058 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2059 struct radeon_winsys_bo
*esgs_ring_bo
,
2060 uint32_t esgs_ring_size
,
2061 struct radeon_winsys_bo
*gsvs_ring_bo
,
2062 uint32_t gsvs_ring_size
)
2064 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2068 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2071 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2073 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2074 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2075 radeon_emit(cs
, esgs_ring_size
>> 8);
2076 radeon_emit(cs
, gsvs_ring_size
>> 8);
2078 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2079 radeon_emit(cs
, esgs_ring_size
>> 8);
2080 radeon_emit(cs
, gsvs_ring_size
>> 8);
2085 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2086 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2087 struct radeon_winsys_bo
*tess_rings_bo
)
2094 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2096 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2098 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2099 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2100 S_030938_SIZE(tf_ring_size
/ 4));
2101 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2103 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2104 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2105 S_030944_BASE_HI(tf_va
>> 40));
2107 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2110 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2111 S_008988_SIZE(tf_ring_size
/ 4));
2112 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2114 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2120 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2121 struct radeon_winsys_bo
*compute_scratch_bo
)
2123 uint64_t scratch_va
;
2125 if (!compute_scratch_bo
)
2128 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2130 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2132 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2133 radeon_emit(cs
, scratch_va
);
2134 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2135 S_008F04_SWIZZLE_ENABLE(1));
2139 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2140 struct radeon_cmdbuf
*cs
,
2141 struct radeon_winsys_bo
*descriptor_bo
)
2148 va
= radv_buffer_get_va(descriptor_bo
);
2150 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2152 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2153 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2154 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2155 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2156 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2158 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2159 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2163 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2164 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2165 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2166 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2167 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2168 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2170 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2171 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2178 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2180 struct radv_device
*device
= queue
->device
;
2182 if (device
->gfx_init
) {
2183 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2185 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2186 radeon_emit(cs
, va
);
2187 radeon_emit(cs
, va
>> 32);
2188 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2190 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2192 struct radv_physical_device
*physical_device
= device
->physical_device
;
2193 si_emit_graphics(physical_device
, cs
);
2198 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2200 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2201 si_emit_compute(physical_device
, cs
);
2205 radv_get_preamble_cs(struct radv_queue
*queue
,
2206 uint32_t scratch_size
,
2207 uint32_t compute_scratch_size
,
2208 uint32_t esgs_ring_size
,
2209 uint32_t gsvs_ring_size
,
2210 bool needs_tess_rings
,
2211 bool needs_sample_positions
,
2212 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2213 struct radeon_cmdbuf
**initial_preamble_cs
,
2214 struct radeon_cmdbuf
**continue_preamble_cs
)
2216 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2217 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2218 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2219 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2220 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2221 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2222 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2223 bool add_tess_rings
= false, add_sample_positions
= false;
2224 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2225 unsigned max_offchip_buffers
;
2226 unsigned hs_offchip_param
= 0;
2227 unsigned tess_offchip_ring_offset
;
2228 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2229 if (!queue
->has_tess_rings
) {
2230 if (needs_tess_rings
)
2231 add_tess_rings
= true;
2233 if (!queue
->has_sample_positions
) {
2234 if (needs_sample_positions
)
2235 add_sample_positions
= true;
2237 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2238 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2239 &max_offchip_buffers
);
2240 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2241 tess_offchip_ring_size
= max_offchip_buffers
*
2242 queue
->device
->tess_offchip_block_dw_size
* 4;
2244 if (scratch_size
<= queue
->scratch_size
&&
2245 compute_scratch_size
<= queue
->compute_scratch_size
&&
2246 esgs_ring_size
<= queue
->esgs_ring_size
&&
2247 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2248 !add_tess_rings
&& !add_sample_positions
&&
2249 queue
->initial_preamble_cs
) {
2250 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2251 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2252 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2253 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2254 *continue_preamble_cs
= NULL
;
2258 if (scratch_size
> queue
->scratch_size
) {
2259 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2267 scratch_bo
= queue
->scratch_bo
;
2269 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2270 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2271 compute_scratch_size
,
2275 if (!compute_scratch_bo
)
2279 compute_scratch_bo
= queue
->compute_scratch_bo
;
2281 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2282 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2290 esgs_ring_bo
= queue
->esgs_ring_bo
;
2291 esgs_ring_size
= queue
->esgs_ring_size
;
2294 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2295 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2303 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2304 gsvs_ring_size
= queue
->gsvs_ring_size
;
2307 if (add_tess_rings
) {
2308 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2309 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2316 tess_rings_bo
= queue
->tess_rings_bo
;
2319 if (scratch_bo
!= queue
->scratch_bo
||
2320 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2321 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2322 tess_rings_bo
!= queue
->tess_rings_bo
||
2323 add_sample_positions
) {
2325 if (gsvs_ring_bo
|| esgs_ring_bo
||
2326 tess_rings_bo
|| add_sample_positions
) {
2327 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2328 if (add_sample_positions
)
2329 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2331 else if (scratch_bo
)
2332 size
= 8; /* 2 dword */
2334 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2338 RADEON_FLAG_CPU_ACCESS
|
2339 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2340 RADEON_FLAG_READ_ONLY
);
2344 descriptor_bo
= queue
->descriptor_bo
;
2346 for(int i
= 0; i
< 3; ++i
) {
2347 struct radeon_cmdbuf
*cs
= NULL
;
2348 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2349 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2356 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2358 /* Emit initial configuration. */
2359 switch (queue
->queue_family_index
) {
2360 case RADV_QUEUE_GENERAL
:
2361 radv_init_graphics_state(cs
, queue
);
2363 case RADV_QUEUE_COMPUTE
:
2364 radv_init_compute_state(cs
, queue
);
2366 case RADV_QUEUE_TRANSFER
:
2370 if (descriptor_bo
!= queue
->descriptor_bo
) {
2371 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2374 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2375 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2376 S_008F04_SWIZZLE_ENABLE(1);
2377 map
[0] = scratch_va
;
2381 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2382 add_sample_positions
)
2383 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2384 esgs_ring_size
, esgs_ring_bo
,
2385 gsvs_ring_size
, gsvs_ring_bo
,
2386 tess_factor_ring_size
,
2387 tess_offchip_ring_offset
,
2388 tess_offchip_ring_size
,
2391 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2394 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2395 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2396 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2397 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2398 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2401 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2402 gsvs_ring_bo
, gsvs_ring_size
);
2403 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2404 tess_factor_ring_size
, tess_rings_bo
);
2405 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2406 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2409 si_cs_emit_cache_flush(cs
,
2410 queue
->device
->physical_device
->rad_info
.chip_class
,
2412 queue
->queue_family_index
== RING_COMPUTE
&&
2413 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2414 (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
)) |
2415 RADV_CMD_FLAG_INV_ICACHE
|
2416 RADV_CMD_FLAG_INV_SMEM_L1
|
2417 RADV_CMD_FLAG_INV_VMEM_L1
|
2418 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2419 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2420 } else if (i
== 1) {
2421 si_cs_emit_cache_flush(cs
,
2422 queue
->device
->physical_device
->rad_info
.chip_class
,
2424 queue
->queue_family_index
== RING_COMPUTE
&&
2425 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2426 RADV_CMD_FLAG_INV_ICACHE
|
2427 RADV_CMD_FLAG_INV_SMEM_L1
|
2428 RADV_CMD_FLAG_INV_VMEM_L1
|
2429 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2430 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2433 if (!queue
->device
->ws
->cs_finalize(cs
))
2437 if (queue
->initial_full_flush_preamble_cs
)
2438 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2440 if (queue
->initial_preamble_cs
)
2441 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2443 if (queue
->continue_preamble_cs
)
2444 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2446 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2447 queue
->initial_preamble_cs
= dest_cs
[1];
2448 queue
->continue_preamble_cs
= dest_cs
[2];
2450 if (scratch_bo
!= queue
->scratch_bo
) {
2451 if (queue
->scratch_bo
)
2452 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2453 queue
->scratch_bo
= scratch_bo
;
2454 queue
->scratch_size
= scratch_size
;
2457 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2458 if (queue
->compute_scratch_bo
)
2459 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2460 queue
->compute_scratch_bo
= compute_scratch_bo
;
2461 queue
->compute_scratch_size
= compute_scratch_size
;
2464 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2465 if (queue
->esgs_ring_bo
)
2466 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2467 queue
->esgs_ring_bo
= esgs_ring_bo
;
2468 queue
->esgs_ring_size
= esgs_ring_size
;
2471 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2472 if (queue
->gsvs_ring_bo
)
2473 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2474 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2475 queue
->gsvs_ring_size
= gsvs_ring_size
;
2478 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2479 queue
->tess_rings_bo
= tess_rings_bo
;
2480 queue
->has_tess_rings
= true;
2483 if (descriptor_bo
!= queue
->descriptor_bo
) {
2484 if (queue
->descriptor_bo
)
2485 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2487 queue
->descriptor_bo
= descriptor_bo
;
2490 if (add_sample_positions
)
2491 queue
->has_sample_positions
= true;
2493 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2494 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2495 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2496 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2497 *continue_preamble_cs
= NULL
;
2500 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2502 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2503 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2504 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2505 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2506 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2507 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2508 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2509 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2510 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2511 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2512 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2513 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2514 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2515 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2518 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2519 struct radv_winsys_sem_counts
*counts
,
2521 const VkSemaphore
*sems
,
2525 int syncobj_idx
= 0, sem_idx
= 0;
2527 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2530 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2531 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2533 if (sem
->temp_syncobj
|| sem
->syncobj
)
2534 counts
->syncobj_count
++;
2536 counts
->sem_count
++;
2539 if (_fence
!= VK_NULL_HANDLE
) {
2540 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2541 if (fence
->temp_syncobj
|| fence
->syncobj
)
2542 counts
->syncobj_count
++;
2545 if (counts
->syncobj_count
) {
2546 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2547 if (!counts
->syncobj
)
2548 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2551 if (counts
->sem_count
) {
2552 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2554 free(counts
->syncobj
);
2555 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2559 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2560 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2562 if (sem
->temp_syncobj
) {
2563 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2565 else if (sem
->syncobj
)
2566 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2569 counts
->sem
[sem_idx
++] = sem
->sem
;
2573 if (_fence
!= VK_NULL_HANDLE
) {
2574 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2575 if (fence
->temp_syncobj
)
2576 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2577 else if (fence
->syncobj
)
2578 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2585 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2587 free(sem_info
->wait
.syncobj
);
2588 free(sem_info
->wait
.sem
);
2589 free(sem_info
->signal
.syncobj
);
2590 free(sem_info
->signal
.sem
);
2594 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2596 const VkSemaphore
*sems
)
2598 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2599 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2601 if (sem
->temp_syncobj
) {
2602 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2603 sem
->temp_syncobj
= 0;
2609 radv_alloc_sem_info(struct radv_instance
*instance
,
2610 struct radv_winsys_sem_info
*sem_info
,
2612 const VkSemaphore
*wait_sems
,
2613 int num_signal_sems
,
2614 const VkSemaphore
*signal_sems
,
2618 memset(sem_info
, 0, sizeof(*sem_info
));
2620 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2623 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2625 radv_free_sem_info(sem_info
);
2627 /* caller can override these */
2628 sem_info
->cs_emit_wait
= true;
2629 sem_info
->cs_emit_signal
= true;
2633 /* Signals fence as soon as all the work currently put on queue is done. */
2634 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2635 struct radv_fence
*fence
)
2639 struct radv_winsys_sem_info sem_info
;
2641 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2642 radv_fence_to_handle(fence
));
2643 if (result
!= VK_SUCCESS
)
2646 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2647 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2648 1, NULL
, NULL
, &sem_info
, NULL
,
2649 false, fence
->fence
);
2650 radv_free_sem_info(&sem_info
);
2653 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2658 VkResult
radv_QueueSubmit(
2660 uint32_t submitCount
,
2661 const VkSubmitInfo
* pSubmits
,
2664 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2665 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2666 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2667 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2669 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2670 uint32_t scratch_size
= 0;
2671 uint32_t compute_scratch_size
= 0;
2672 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2673 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2675 bool fence_emitted
= false;
2676 bool tess_rings_needed
= false;
2677 bool sample_positions_needed
= false;
2679 /* Do this first so failing to allocate scratch buffers can't result in
2680 * partially executed submissions. */
2681 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2682 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2683 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2684 pSubmits
[i
].pCommandBuffers
[j
]);
2686 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2687 compute_scratch_size
= MAX2(compute_scratch_size
,
2688 cmd_buffer
->compute_scratch_size_needed
);
2689 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2690 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2691 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2692 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2696 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2697 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2698 sample_positions_needed
, &initial_flush_preamble_cs
,
2699 &initial_preamble_cs
, &continue_preamble_cs
);
2700 if (result
!= VK_SUCCESS
)
2703 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2704 struct radeon_cmdbuf
**cs_array
;
2705 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2706 bool can_patch
= true;
2708 struct radv_winsys_sem_info sem_info
;
2710 result
= radv_alloc_sem_info(queue
->device
->instance
,
2712 pSubmits
[i
].waitSemaphoreCount
,
2713 pSubmits
[i
].pWaitSemaphores
,
2714 pSubmits
[i
].signalSemaphoreCount
,
2715 pSubmits
[i
].pSignalSemaphores
,
2717 if (result
!= VK_SUCCESS
)
2720 if (!pSubmits
[i
].commandBufferCount
) {
2721 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2722 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2723 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2728 radv_loge("failed to submit CS %d\n", i
);
2731 fence_emitted
= true;
2733 radv_free_sem_info(&sem_info
);
2737 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2738 (pSubmits
[i
].commandBufferCount
));
2740 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2741 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2742 pSubmits
[i
].pCommandBuffers
[j
]);
2743 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2745 cs_array
[j
] = cmd_buffer
->cs
;
2746 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2749 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2752 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2753 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2754 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2756 advance
= MIN2(max_cs_submission
,
2757 pSubmits
[i
].commandBufferCount
- j
);
2759 if (queue
->device
->trace_bo
)
2760 *queue
->device
->trace_id_ptr
= 0;
2762 sem_info
.cs_emit_wait
= j
== 0;
2763 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2765 if (unlikely(queue
->device
->use_global_bo_list
)) {
2766 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2767 bo_list
= &queue
->device
->bo_list
.list
;
2770 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2771 advance
, initial_preamble
, continue_preamble_cs
,
2773 can_patch
, base_fence
);
2775 if (unlikely(queue
->device
->use_global_bo_list
))
2776 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2779 radv_loge("failed to submit CS %d\n", i
);
2782 fence_emitted
= true;
2783 if (queue
->device
->trace_bo
) {
2784 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2788 radv_free_temp_syncobjs(queue
->device
,
2789 pSubmits
[i
].waitSemaphoreCount
,
2790 pSubmits
[i
].pWaitSemaphores
);
2791 radv_free_sem_info(&sem_info
);
2796 if (!fence_emitted
) {
2797 result
= radv_signal_fence(queue
, fence
);
2798 if (result
!= VK_SUCCESS
)
2801 fence
->submitted
= true;
2807 VkResult
radv_QueueWaitIdle(
2810 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2812 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2813 radv_queue_family_to_ring(queue
->queue_family_index
),
2818 VkResult
radv_DeviceWaitIdle(
2821 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2823 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2824 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2825 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2831 VkResult
radv_EnumerateInstanceExtensionProperties(
2832 const char* pLayerName
,
2833 uint32_t* pPropertyCount
,
2834 VkExtensionProperties
* pProperties
)
2836 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2838 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2839 if (radv_supported_instance_extensions
.extensions
[i
]) {
2840 vk_outarray_append(&out
, prop
) {
2841 *prop
= radv_instance_extensions
[i
];
2846 return vk_outarray_status(&out
);
2849 VkResult
radv_EnumerateDeviceExtensionProperties(
2850 VkPhysicalDevice physicalDevice
,
2851 const char* pLayerName
,
2852 uint32_t* pPropertyCount
,
2853 VkExtensionProperties
* pProperties
)
2855 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2856 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2858 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2859 if (device
->supported_extensions
.extensions
[i
]) {
2860 vk_outarray_append(&out
, prop
) {
2861 *prop
= radv_device_extensions
[i
];
2866 return vk_outarray_status(&out
);
2869 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2870 VkInstance _instance
,
2873 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2875 return radv_lookup_entrypoint_checked(pName
,
2876 instance
? instance
->apiVersion
: 0,
2877 instance
? &instance
->enabled_extensions
: NULL
,
2881 /* The loader wants us to expose a second GetInstanceProcAddr function
2882 * to work around certain LD_PRELOAD issues seen in apps.
2885 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2886 VkInstance instance
,
2890 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2891 VkInstance instance
,
2894 return radv_GetInstanceProcAddr(instance
, pName
);
2897 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2901 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2903 return radv_lookup_entrypoint_checked(pName
,
2904 device
->instance
->apiVersion
,
2905 &device
->instance
->enabled_extensions
,
2906 &device
->enabled_extensions
);
2909 bool radv_get_memory_fd(struct radv_device
*device
,
2910 struct radv_device_memory
*memory
,
2913 struct radeon_bo_metadata metadata
;
2915 if (memory
->image
) {
2916 radv_init_metadata(device
, memory
->image
, &metadata
);
2917 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2920 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2924 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2925 const VkMemoryAllocateInfo
* pAllocateInfo
,
2926 const VkAllocationCallbacks
* pAllocator
,
2927 VkDeviceMemory
* pMem
)
2929 struct radv_device_memory
*mem
;
2931 enum radeon_bo_domain domain
;
2933 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2935 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2937 if (pAllocateInfo
->allocationSize
== 0) {
2938 /* Apparently, this is allowed */
2939 *pMem
= VK_NULL_HANDLE
;
2943 const VkImportMemoryFdInfoKHR
*import_info
=
2944 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2945 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2946 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2947 const VkExportMemoryAllocateInfoKHR
*export_info
=
2948 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2949 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2950 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2952 const struct wsi_memory_allocate_info
*wsi_info
=
2953 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2955 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2956 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2958 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2960 if (wsi_info
&& wsi_info
->implicit_sync
)
2961 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2963 if (dedicate_info
) {
2964 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2965 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2971 mem
->user_ptr
= NULL
;
2974 assert(import_info
->handleType
==
2975 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2976 import_info
->handleType
==
2977 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2978 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2981 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2984 close(import_info
->fd
);
2986 } else if (host_ptr_info
) {
2987 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2988 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2989 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2990 pAllocateInfo
->allocationSize
);
2992 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2995 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2998 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2999 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3000 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3001 domain
= RADEON_DOMAIN_GTT
;
3003 domain
= RADEON_DOMAIN_VRAM
;
3005 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3006 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3008 flags
|= RADEON_FLAG_CPU_ACCESS
;
3010 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3011 flags
|= RADEON_FLAG_GTT_WC
;
3013 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
3014 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3016 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3020 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3023 mem
->type_index
= mem_type_index
;
3026 result
= radv_bo_list_add(device
, mem
->bo
);
3027 if (result
!= VK_SUCCESS
)
3030 *pMem
= radv_device_memory_to_handle(mem
);
3035 device
->ws
->buffer_destroy(mem
->bo
);
3037 vk_free2(&device
->alloc
, pAllocator
, mem
);
3042 VkResult
radv_AllocateMemory(
3044 const VkMemoryAllocateInfo
* pAllocateInfo
,
3045 const VkAllocationCallbacks
* pAllocator
,
3046 VkDeviceMemory
* pMem
)
3048 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3049 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3052 void radv_FreeMemory(
3054 VkDeviceMemory _mem
,
3055 const VkAllocationCallbacks
* pAllocator
)
3057 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3058 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3063 radv_bo_list_remove(device
, mem
->bo
);
3064 device
->ws
->buffer_destroy(mem
->bo
);
3067 vk_free2(&device
->alloc
, pAllocator
, mem
);
3070 VkResult
radv_MapMemory(
3072 VkDeviceMemory _memory
,
3073 VkDeviceSize offset
,
3075 VkMemoryMapFlags flags
,
3078 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3079 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3087 *ppData
= mem
->user_ptr
;
3089 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3096 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3099 void radv_UnmapMemory(
3101 VkDeviceMemory _memory
)
3103 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3104 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3109 if (mem
->user_ptr
== NULL
)
3110 device
->ws
->buffer_unmap(mem
->bo
);
3113 VkResult
radv_FlushMappedMemoryRanges(
3115 uint32_t memoryRangeCount
,
3116 const VkMappedMemoryRange
* pMemoryRanges
)
3121 VkResult
radv_InvalidateMappedMemoryRanges(
3123 uint32_t memoryRangeCount
,
3124 const VkMappedMemoryRange
* pMemoryRanges
)
3129 void radv_GetBufferMemoryRequirements(
3132 VkMemoryRequirements
* pMemoryRequirements
)
3134 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3135 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3137 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3139 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3140 pMemoryRequirements
->alignment
= 4096;
3142 pMemoryRequirements
->alignment
= 16;
3144 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3147 void radv_GetBufferMemoryRequirements2(
3149 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
3150 VkMemoryRequirements2KHR
* pMemoryRequirements
)
3152 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3153 &pMemoryRequirements
->memoryRequirements
);
3154 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3155 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3156 switch (ext
->sType
) {
3157 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
3158 VkMemoryDedicatedRequirementsKHR
*req
=
3159 (VkMemoryDedicatedRequirementsKHR
*) ext
;
3160 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3161 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3170 void radv_GetImageMemoryRequirements(
3173 VkMemoryRequirements
* pMemoryRequirements
)
3175 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3176 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3178 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3180 pMemoryRequirements
->size
= image
->size
;
3181 pMemoryRequirements
->alignment
= image
->alignment
;
3184 void radv_GetImageMemoryRequirements2(
3186 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
3187 VkMemoryRequirements2KHR
* pMemoryRequirements
)
3189 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3190 &pMemoryRequirements
->memoryRequirements
);
3192 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3194 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3195 switch (ext
->sType
) {
3196 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
3197 VkMemoryDedicatedRequirementsKHR
*req
=
3198 (VkMemoryDedicatedRequirementsKHR
*) ext
;
3199 req
->requiresDedicatedAllocation
= image
->shareable
;
3200 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3209 void radv_GetImageSparseMemoryRequirements(
3212 uint32_t* pSparseMemoryRequirementCount
,
3213 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3218 void radv_GetImageSparseMemoryRequirements2(
3220 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
3221 uint32_t* pSparseMemoryRequirementCount
,
3222 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
3227 void radv_GetDeviceMemoryCommitment(
3229 VkDeviceMemory memory
,
3230 VkDeviceSize
* pCommittedMemoryInBytes
)
3232 *pCommittedMemoryInBytes
= 0;
3235 VkResult
radv_BindBufferMemory2(VkDevice device
,
3236 uint32_t bindInfoCount
,
3237 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
3239 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3240 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3241 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3244 buffer
->bo
= mem
->bo
;
3245 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3253 VkResult
radv_BindBufferMemory(
3256 VkDeviceMemory memory
,
3257 VkDeviceSize memoryOffset
)
3259 const VkBindBufferMemoryInfoKHR info
= {
3260 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3263 .memoryOffset
= memoryOffset
3266 return radv_BindBufferMemory2(device
, 1, &info
);
3269 VkResult
radv_BindImageMemory2(VkDevice device
,
3270 uint32_t bindInfoCount
,
3271 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3273 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3274 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3275 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3278 image
->bo
= mem
->bo
;
3279 image
->offset
= pBindInfos
[i
].memoryOffset
;
3289 VkResult
radv_BindImageMemory(
3292 VkDeviceMemory memory
,
3293 VkDeviceSize memoryOffset
)
3295 const VkBindImageMemoryInfoKHR info
= {
3296 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3299 .memoryOffset
= memoryOffset
3302 return radv_BindImageMemory2(device
, 1, &info
);
3307 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3308 const VkSparseBufferMemoryBindInfo
*bind
)
3310 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3312 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3313 struct radv_device_memory
*mem
= NULL
;
3315 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3316 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3318 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3319 bind
->pBinds
[i
].resourceOffset
,
3320 bind
->pBinds
[i
].size
,
3321 mem
? mem
->bo
: NULL
,
3322 bind
->pBinds
[i
].memoryOffset
);
3327 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3328 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3330 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3332 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3333 struct radv_device_memory
*mem
= NULL
;
3335 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3336 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3338 device
->ws
->buffer_virtual_bind(image
->bo
,
3339 bind
->pBinds
[i
].resourceOffset
,
3340 bind
->pBinds
[i
].size
,
3341 mem
? mem
->bo
: NULL
,
3342 bind
->pBinds
[i
].memoryOffset
);
3346 VkResult
radv_QueueBindSparse(
3348 uint32_t bindInfoCount
,
3349 const VkBindSparseInfo
* pBindInfo
,
3352 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3353 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3354 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3355 bool fence_emitted
= false;
3359 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3360 struct radv_winsys_sem_info sem_info
;
3361 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3362 radv_sparse_buffer_bind_memory(queue
->device
,
3363 pBindInfo
[i
].pBufferBinds
+ j
);
3366 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3367 radv_sparse_image_opaque_bind_memory(queue
->device
,
3368 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3372 result
= radv_alloc_sem_info(queue
->device
->instance
,
3374 pBindInfo
[i
].waitSemaphoreCount
,
3375 pBindInfo
[i
].pWaitSemaphores
,
3376 pBindInfo
[i
].signalSemaphoreCount
,
3377 pBindInfo
[i
].pSignalSemaphores
,
3379 if (result
!= VK_SUCCESS
)
3382 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3383 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3384 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3389 radv_loge("failed to submit CS %d\n", i
);
3393 fence_emitted
= true;
3395 fence
->submitted
= true;
3398 radv_free_sem_info(&sem_info
);
3403 if (!fence_emitted
) {
3404 result
= radv_signal_fence(queue
, fence
);
3405 if (result
!= VK_SUCCESS
)
3408 fence
->submitted
= true;
3414 VkResult
radv_CreateFence(
3416 const VkFenceCreateInfo
* pCreateInfo
,
3417 const VkAllocationCallbacks
* pAllocator
,
3420 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3421 const VkExportFenceCreateInfoKHR
*export
=
3422 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3423 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3424 export
? export
->handleTypes
: 0;
3426 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3428 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3431 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3433 fence
->fence_wsi
= NULL
;
3434 fence
->submitted
= false;
3435 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3436 fence
->temp_syncobj
= 0;
3437 if (device
->always_use_syncobj
|| handleTypes
) {
3438 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3440 vk_free2(&device
->alloc
, pAllocator
, fence
);
3441 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3443 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3444 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3446 fence
->fence
= NULL
;
3448 fence
->fence
= device
->ws
->create_fence();
3449 if (!fence
->fence
) {
3450 vk_free2(&device
->alloc
, pAllocator
, fence
);
3451 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3456 *pFence
= radv_fence_to_handle(fence
);
3461 void radv_DestroyFence(
3464 const VkAllocationCallbacks
* pAllocator
)
3466 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3467 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3472 if (fence
->temp_syncobj
)
3473 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3475 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3477 device
->ws
->destroy_fence(fence
->fence
);
3478 if (fence
->fence_wsi
)
3479 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3480 vk_free2(&device
->alloc
, pAllocator
, fence
);
3484 static uint64_t radv_get_current_time()
3487 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3488 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3491 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3493 uint64_t current_time
= radv_get_current_time();
3495 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3497 return current_time
+ timeout
;
3501 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3503 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3504 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3505 if (fence
->fence
== NULL
|| fence
->syncobj
||
3506 fence
->temp_syncobj
||
3507 (!fence
->signalled
&& !fence
->submitted
))
3513 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3515 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3516 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3517 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3523 VkResult
radv_WaitForFences(
3525 uint32_t fenceCount
,
3526 const VkFence
* pFences
,
3530 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3531 timeout
= radv_get_absolute_timeout(timeout
);
3533 if (device
->always_use_syncobj
&&
3534 radv_all_fences_syncobj(fenceCount
, pFences
))
3536 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3538 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3540 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3541 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3542 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3545 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3548 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3551 if (!waitAll
&& fenceCount
> 1) {
3552 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3553 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3554 uint32_t wait_count
= 0;
3555 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3557 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3559 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3560 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3562 if (fence
->signalled
) {
3567 fences
[wait_count
++] = fence
->fence
;
3570 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3571 waitAll
, timeout
- radv_get_current_time());
3574 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3577 while(radv_get_current_time() <= timeout
) {
3578 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3579 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3586 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3587 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3588 bool expired
= false;
3590 if (fence
->temp_syncobj
) {
3591 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3596 if (fence
->syncobj
) {
3597 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3602 if (fence
->signalled
)
3606 if (!fence
->submitted
) {
3607 while(radv_get_current_time() <= timeout
&&
3611 if (!fence
->submitted
)
3614 /* Recheck as it may have been set by
3615 * submitting operations. */
3617 if (fence
->signalled
)
3621 expired
= device
->ws
->fence_wait(device
->ws
,
3628 if (fence
->fence_wsi
) {
3629 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3630 if (result
!= VK_SUCCESS
)
3634 fence
->signalled
= true;
3640 VkResult
radv_ResetFences(VkDevice _device
,
3641 uint32_t fenceCount
,
3642 const VkFence
*pFences
)
3644 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3646 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3647 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3648 fence
->submitted
= fence
->signalled
= false;
3650 /* Per spec, we first restore the permanent payload, and then reset, so
3651 * having a temp syncobj should not skip resetting the permanent syncobj. */
3652 if (fence
->temp_syncobj
) {
3653 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3654 fence
->temp_syncobj
= 0;
3657 if (fence
->syncobj
) {
3658 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3665 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3667 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3668 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3670 if (fence
->temp_syncobj
) {
3671 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3672 return success
? VK_SUCCESS
: VK_NOT_READY
;
3675 if (fence
->syncobj
) {
3676 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3677 return success
? VK_SUCCESS
: VK_NOT_READY
;
3680 if (fence
->signalled
)
3682 if (!fence
->submitted
)
3683 return VK_NOT_READY
;
3685 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3686 return VK_NOT_READY
;
3688 if (fence
->fence_wsi
) {
3689 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
3691 if (result
!= VK_SUCCESS
) {
3692 if (result
== VK_TIMEOUT
)
3693 return VK_NOT_READY
;
3701 // Queue semaphore functions
3703 VkResult
radv_CreateSemaphore(
3705 const VkSemaphoreCreateInfo
* pCreateInfo
,
3706 const VkAllocationCallbacks
* pAllocator
,
3707 VkSemaphore
* pSemaphore
)
3709 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3710 const VkExportSemaphoreCreateInfoKHR
*export
=
3711 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3712 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3713 export
? export
->handleTypes
: 0;
3715 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3717 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3719 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3721 sem
->temp_syncobj
= 0;
3722 /* create a syncobject if we are going to export this semaphore */
3723 if (device
->always_use_syncobj
|| handleTypes
) {
3724 assert (device
->physical_device
->rad_info
.has_syncobj
);
3725 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3727 vk_free2(&device
->alloc
, pAllocator
, sem
);
3728 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3732 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3734 vk_free2(&device
->alloc
, pAllocator
, sem
);
3735 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3740 *pSemaphore
= radv_semaphore_to_handle(sem
);
3744 void radv_DestroySemaphore(
3746 VkSemaphore _semaphore
,
3747 const VkAllocationCallbacks
* pAllocator
)
3749 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3750 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3755 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3757 device
->ws
->destroy_sem(sem
->sem
);
3758 vk_free2(&device
->alloc
, pAllocator
, sem
);
3761 VkResult
radv_CreateEvent(
3763 const VkEventCreateInfo
* pCreateInfo
,
3764 const VkAllocationCallbacks
* pAllocator
,
3767 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3768 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3770 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3773 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3775 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3777 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3779 vk_free2(&device
->alloc
, pAllocator
, event
);
3780 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3783 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3785 *pEvent
= radv_event_to_handle(event
);
3790 void radv_DestroyEvent(
3793 const VkAllocationCallbacks
* pAllocator
)
3795 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3796 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3800 device
->ws
->buffer_destroy(event
->bo
);
3801 vk_free2(&device
->alloc
, pAllocator
, event
);
3804 VkResult
radv_GetEventStatus(
3808 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3810 if (*event
->map
== 1)
3811 return VK_EVENT_SET
;
3812 return VK_EVENT_RESET
;
3815 VkResult
radv_SetEvent(
3819 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3825 VkResult
radv_ResetEvent(
3829 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3835 VkResult
radv_CreateBuffer(
3837 const VkBufferCreateInfo
* pCreateInfo
,
3838 const VkAllocationCallbacks
* pAllocator
,
3841 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3842 struct radv_buffer
*buffer
;
3844 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3846 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3847 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3849 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3851 buffer
->size
= pCreateInfo
->size
;
3852 buffer
->usage
= pCreateInfo
->usage
;
3855 buffer
->flags
= pCreateInfo
->flags
;
3857 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3858 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3860 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3861 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3862 align64(buffer
->size
, 4096),
3863 4096, 0, RADEON_FLAG_VIRTUAL
);
3865 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3866 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3870 *pBuffer
= radv_buffer_to_handle(buffer
);
3875 void radv_DestroyBuffer(
3878 const VkAllocationCallbacks
* pAllocator
)
3880 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3881 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3886 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3887 device
->ws
->buffer_destroy(buffer
->bo
);
3889 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3892 static inline unsigned
3893 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3896 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3898 return image
->surface
.u
.legacy
.tiling_index
[level
];
3901 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3903 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3907 radv_init_dcc_control_reg(struct radv_device
*device
,
3908 struct radv_image_view
*iview
)
3910 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3911 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3912 unsigned max_compressed_block_size
;
3913 unsigned independent_64b_blocks
;
3915 if (!radv_image_has_dcc(iview
->image
))
3918 if (iview
->image
->info
.samples
> 1) {
3919 if (iview
->image
->surface
.bpe
== 1)
3920 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3921 else if (iview
->image
->surface
.bpe
== 2)
3922 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3925 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3926 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3927 * dGPU and 64 for APU because all of our APUs to date use
3928 * DIMMs which have a request granularity size of 64B while all
3929 * other chips have a 32B request size.
3931 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3934 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3935 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3936 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3937 /* If this DCC image is potentially going to be used in texture
3938 * fetches, we need some special settings.
3940 independent_64b_blocks
= 1;
3941 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3943 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3944 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3945 * big as possible for better compression state.
3947 independent_64b_blocks
= 0;
3948 max_compressed_block_size
= max_uncompressed_block_size
;
3951 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3952 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3953 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3954 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3958 radv_initialise_color_surface(struct radv_device
*device
,
3959 struct radv_color_buffer_info
*cb
,
3960 struct radv_image_view
*iview
)
3962 const struct vk_format_description
*desc
;
3963 unsigned ntype
, format
, swap
, endian
;
3964 unsigned blend_clamp
= 0, blend_bypass
= 0;
3966 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3968 desc
= vk_format_description(iview
->vk_format
);
3970 memset(cb
, 0, sizeof(*cb
));
3972 /* Intensity is implemented as Red, so treat it that way. */
3973 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3975 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3977 cb
->cb_color_base
= va
>> 8;
3979 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3980 struct gfx9_surf_meta_flags meta
;
3981 if (iview
->image
->dcc_offset
)
3982 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3984 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3986 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3987 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3988 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3989 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3991 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3992 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3994 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3995 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3997 cb
->cb_color_base
+= level_info
->offset
>> 8;
3998 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3999 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
4001 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4002 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4003 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
4005 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4006 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4007 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
4009 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4011 if (radv_image_has_fmask(iview
->image
)) {
4012 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4013 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
4014 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4015 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4017 /* This must be set for fast clear to work without FMASK. */
4018 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4019 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4020 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4021 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4025 /* CMASK variables */
4026 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4027 va
+= iview
->image
->cmask
.offset
;
4028 cb
->cb_color_cmask
= va
>> 8;
4030 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4031 va
+= iview
->image
->dcc_offset
;
4032 cb
->cb_dcc_base
= va
>> 8;
4033 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
4035 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4036 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4037 S_028C6C_SLICE_MAX(max_slice
);
4039 if (iview
->image
->info
.samples
> 1) {
4040 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4042 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4043 S_028C74_NUM_FRAGMENTS(log_samples
);
4046 if (radv_image_has_fmask(iview
->image
)) {
4047 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4048 cb
->cb_color_fmask
= va
>> 8;
4049 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4051 cb
->cb_color_fmask
= cb
->cb_color_base
;
4054 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4056 vk_format_get_first_non_void_channel(iview
->vk_format
));
4057 format
= radv_translate_colorformat(iview
->vk_format
);
4058 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4059 radv_finishme("Illegal color\n");
4060 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4061 endian
= radv_colorformat_endian_swap(format
);
4063 /* blend clamp should be set for all NORM/SRGB types */
4064 if (ntype
== V_028C70_NUMBER_UNORM
||
4065 ntype
== V_028C70_NUMBER_SNORM
||
4066 ntype
== V_028C70_NUMBER_SRGB
)
4069 /* set blend bypass according to docs if SINT/UINT or
4070 8/24 COLOR variants */
4071 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4072 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4073 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4078 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4079 (format
== V_028C70_COLOR_8
||
4080 format
== V_028C70_COLOR_8_8
||
4081 format
== V_028C70_COLOR_8_8_8_8
))
4082 ->color_is_int8
= true;
4084 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4085 S_028C70_COMP_SWAP(swap
) |
4086 S_028C70_BLEND_CLAMP(blend_clamp
) |
4087 S_028C70_BLEND_BYPASS(blend_bypass
) |
4088 S_028C70_SIMPLE_FLOAT(1) |
4089 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4090 ntype
!= V_028C70_NUMBER_SNORM
&&
4091 ntype
!= V_028C70_NUMBER_SRGB
&&
4092 format
!= V_028C70_COLOR_8_24
&&
4093 format
!= V_028C70_COLOR_24_8
) |
4094 S_028C70_NUMBER_TYPE(ntype
) |
4095 S_028C70_ENDIAN(endian
);
4096 if (radv_image_has_fmask(iview
->image
)) {
4097 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4098 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
4099 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4100 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4104 if (radv_image_has_cmask(iview
->image
) &&
4105 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4106 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4108 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4109 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4111 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4113 /* This must be set for fast clear to work without FMASK. */
4114 if (!radv_image_has_fmask(iview
->image
) &&
4115 device
->physical_device
->rad_info
.chip_class
== SI
) {
4116 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
4117 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4120 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4121 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4122 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4124 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
4125 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4126 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
4127 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
4128 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
4129 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4134 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4135 struct radv_image_view
*iview
)
4137 unsigned max_zplanes
= 0;
4139 assert(radv_image_is_tc_compat_htile(iview
->image
));
4141 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4142 /* Default value for 32-bit depth surfaces. */
4145 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4146 iview
->image
->info
.samples
> 1)
4149 max_zplanes
= max_zplanes
+ 1;
4151 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4152 /* Do not enable Z plane compression for 16-bit depth
4153 * surfaces because isn't supported on GFX8. Only
4154 * 32-bit depth surfaces are supported by the hardware.
4155 * This allows to maintain shader compatibility and to
4156 * reduce the number of depth decompressions.
4160 if (iview
->image
->info
.samples
<= 1)
4162 else if (iview
->image
->info
.samples
<= 4)
4173 radv_initialise_ds_surface(struct radv_device
*device
,
4174 struct radv_ds_buffer_info
*ds
,
4175 struct radv_image_view
*iview
)
4177 unsigned level
= iview
->base_mip
;
4178 unsigned format
, stencil_format
;
4179 uint64_t va
, s_offs
, z_offs
;
4180 bool stencil_only
= false;
4181 memset(ds
, 0, sizeof(*ds
));
4182 switch (iview
->image
->vk_format
) {
4183 case VK_FORMAT_D24_UNORM_S8_UINT
:
4184 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4185 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4186 ds
->offset_scale
= 2.0f
;
4188 case VK_FORMAT_D16_UNORM
:
4189 case VK_FORMAT_D16_UNORM_S8_UINT
:
4190 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4191 ds
->offset_scale
= 4.0f
;
4193 case VK_FORMAT_D32_SFLOAT
:
4194 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4195 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4196 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4197 ds
->offset_scale
= 1.0f
;
4199 case VK_FORMAT_S8_UINT
:
4200 stencil_only
= true;
4206 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4207 stencil_format
= iview
->image
->surface
.has_stencil
?
4208 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4210 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4211 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4212 S_028008_SLICE_MAX(max_slice
);
4214 ds
->db_htile_data_base
= 0;
4215 ds
->db_htile_surface
= 0;
4217 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4218 s_offs
= z_offs
= va
;
4220 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4221 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
4222 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
4224 ds
->db_z_info
= S_028038_FORMAT(format
) |
4225 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4226 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
4227 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4228 S_028038_ZRANGE_PRECISION(1);
4229 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4230 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
4232 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
4233 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
4234 ds
->db_depth_view
|= S_028008_MIPID(level
);
4236 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4237 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4239 if (radv_htile_enabled(iview
->image
, level
)) {
4240 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4242 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4243 unsigned max_zplanes
=
4244 radv_calc_decompress_on_z_planes(device
, iview
);
4246 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4247 S_028038_ITERATE_FLUSH(1);
4248 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4251 if (!iview
->image
->surface
.has_stencil
)
4252 /* Use all of the htile_buffer for depth if there's no stencil. */
4253 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4254 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4255 iview
->image
->htile_offset
;
4256 ds
->db_htile_data_base
= va
>> 8;
4257 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4258 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4259 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4262 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4265 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4267 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4268 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4270 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4271 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4272 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4274 if (iview
->image
->info
.samples
> 1)
4275 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4277 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4278 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4279 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4280 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4281 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4282 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4283 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4284 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4287 tile_mode
= stencil_tile_mode
;
4289 ds
->db_depth_info
|=
4290 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4291 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4292 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4293 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4294 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4295 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4296 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4297 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4299 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4300 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4301 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4302 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4304 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4307 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4308 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4309 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4311 if (radv_htile_enabled(iview
->image
, level
)) {
4312 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4314 if (!iview
->image
->surface
.has_stencil
&&
4315 !radv_image_is_tc_compat_htile(iview
->image
))
4316 /* Use all of the htile_buffer for depth if there's no stencil. */
4317 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4319 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4320 iview
->image
->htile_offset
;
4321 ds
->db_htile_data_base
= va
>> 8;
4322 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4324 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4325 unsigned max_zplanes
=
4326 radv_calc_decompress_on_z_planes(device
, iview
);
4328 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4329 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4334 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4335 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4338 VkResult
radv_CreateFramebuffer(
4340 const VkFramebufferCreateInfo
* pCreateInfo
,
4341 const VkAllocationCallbacks
* pAllocator
,
4342 VkFramebuffer
* pFramebuffer
)
4344 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4345 struct radv_framebuffer
*framebuffer
;
4347 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4349 size_t size
= sizeof(*framebuffer
) +
4350 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4351 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4352 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4353 if (framebuffer
== NULL
)
4354 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4356 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4357 framebuffer
->width
= pCreateInfo
->width
;
4358 framebuffer
->height
= pCreateInfo
->height
;
4359 framebuffer
->layers
= pCreateInfo
->layers
;
4360 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4361 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4362 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4363 framebuffer
->attachments
[i
].attachment
= iview
;
4364 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4365 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4366 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4367 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4369 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4370 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4371 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4374 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4378 void radv_DestroyFramebuffer(
4381 const VkAllocationCallbacks
* pAllocator
)
4383 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4384 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4388 vk_free2(&device
->alloc
, pAllocator
, fb
);
4391 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4393 switch (address_mode
) {
4394 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4395 return V_008F30_SQ_TEX_WRAP
;
4396 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4397 return V_008F30_SQ_TEX_MIRROR
;
4398 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4399 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4400 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4401 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4402 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4403 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4405 unreachable("illegal tex wrap mode");
4411 radv_tex_compare(VkCompareOp op
)
4414 case VK_COMPARE_OP_NEVER
:
4415 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4416 case VK_COMPARE_OP_LESS
:
4417 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4418 case VK_COMPARE_OP_EQUAL
:
4419 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4420 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4421 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4422 case VK_COMPARE_OP_GREATER
:
4423 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4424 case VK_COMPARE_OP_NOT_EQUAL
:
4425 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4426 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4427 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4428 case VK_COMPARE_OP_ALWAYS
:
4429 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4431 unreachable("illegal compare mode");
4437 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4440 case VK_FILTER_NEAREST
:
4441 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4442 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4443 case VK_FILTER_LINEAR
:
4444 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4445 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4446 case VK_FILTER_CUBIC_IMG
:
4448 fprintf(stderr
, "illegal texture filter");
4454 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4457 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4458 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4459 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4460 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4462 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4467 radv_tex_bordercolor(VkBorderColor bcolor
)
4470 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4471 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4472 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4473 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4474 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4475 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4476 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4477 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4478 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4486 radv_tex_aniso_filter(unsigned filter
)
4500 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4503 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4504 return SQ_IMG_FILTER_MODE_BLEND
;
4505 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4506 return SQ_IMG_FILTER_MODE_MIN
;
4507 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4508 return SQ_IMG_FILTER_MODE_MAX
;
4516 radv_get_max_anisotropy(struct radv_device
*device
,
4517 const VkSamplerCreateInfo
*pCreateInfo
)
4519 if (device
->force_aniso
>= 0)
4520 return device
->force_aniso
;
4522 if (pCreateInfo
->anisotropyEnable
&&
4523 pCreateInfo
->maxAnisotropy
> 1.0f
)
4524 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4530 radv_init_sampler(struct radv_device
*device
,
4531 struct radv_sampler
*sampler
,
4532 const VkSamplerCreateInfo
*pCreateInfo
)
4534 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4535 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4536 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4537 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4539 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4540 vk_find_struct_const(pCreateInfo
->pNext
,
4541 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4542 if (sampler_reduction
)
4543 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4545 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4546 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4547 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4548 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4549 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4550 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4551 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4552 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4553 S_008F30_DISABLE_CUBE_WRAP(0) |
4554 S_008F30_COMPAT_MODE(is_vi
) |
4555 S_008F30_FILTER_MODE(filter_mode
));
4556 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4557 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4558 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4559 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4560 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4561 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4562 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4563 S_008F38_MIP_POINT_PRECLAMP(0) |
4564 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4565 S_008F38_FILTER_PREC_FIX(1) |
4566 S_008F38_ANISO_OVERRIDE(is_vi
));
4567 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4568 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4571 VkResult
radv_CreateSampler(
4573 const VkSamplerCreateInfo
* pCreateInfo
,
4574 const VkAllocationCallbacks
* pAllocator
,
4575 VkSampler
* pSampler
)
4577 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4578 struct radv_sampler
*sampler
;
4580 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4582 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4583 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4585 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4587 radv_init_sampler(device
, sampler
, pCreateInfo
);
4588 *pSampler
= radv_sampler_to_handle(sampler
);
4593 void radv_DestroySampler(
4596 const VkAllocationCallbacks
* pAllocator
)
4598 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4599 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4603 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4606 /* vk_icd.h does not declare this function, so we declare it here to
4607 * suppress Wmissing-prototypes.
4609 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4610 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4612 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4613 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4615 /* For the full details on loader interface versioning, see
4616 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4617 * What follows is a condensed summary, to help you navigate the large and
4618 * confusing official doc.
4620 * - Loader interface v0 is incompatible with later versions. We don't
4623 * - In loader interface v1:
4624 * - The first ICD entrypoint called by the loader is
4625 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4627 * - The ICD must statically expose no other Vulkan symbol unless it is
4628 * linked with -Bsymbolic.
4629 * - Each dispatchable Vulkan handle created by the ICD must be
4630 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4631 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4632 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4633 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4634 * such loader-managed surfaces.
4636 * - Loader interface v2 differs from v1 in:
4637 * - The first ICD entrypoint called by the loader is
4638 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4639 * statically expose this entrypoint.
4641 * - Loader interface v3 differs from v2 in:
4642 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4643 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4644 * because the loader no longer does so.
4646 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4650 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4651 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4654 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4655 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4657 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4659 /* At the moment, we support only the below handle types. */
4660 assert(pGetFdInfo
->handleType
==
4661 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4662 pGetFdInfo
->handleType
==
4663 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4665 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4667 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4671 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4672 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4674 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4676 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4678 switch (handleType
) {
4679 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4680 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4684 /* The valid usage section for this function says:
4686 * "handleType must not be one of the handle types defined as
4689 * So opaque handle types fall into the default "unsupported" case.
4691 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4695 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4699 uint32_t syncobj_handle
= 0;
4700 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4702 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4705 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4707 *syncobj
= syncobj_handle
;
4713 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4717 /* If we create a syncobj we do it locally so that if we have an error, we don't
4718 * leave a syncobj in an undetermined state in the fence. */
4719 uint32_t syncobj_handle
= *syncobj
;
4720 if (!syncobj_handle
) {
4721 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4723 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4728 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4730 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4732 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4735 *syncobj
= syncobj_handle
;
4742 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4743 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4745 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4746 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4747 uint32_t *syncobj_dst
= NULL
;
4749 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4750 syncobj_dst
= &sem
->temp_syncobj
;
4752 syncobj_dst
= &sem
->syncobj
;
4755 switch(pImportSemaphoreFdInfo
->handleType
) {
4756 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4757 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4758 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4759 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4761 unreachable("Unhandled semaphore handle type");
4765 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4766 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4769 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4770 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4772 uint32_t syncobj_handle
;
4774 if (sem
->temp_syncobj
)
4775 syncobj_handle
= sem
->temp_syncobj
;
4777 syncobj_handle
= sem
->syncobj
;
4779 switch(pGetFdInfo
->handleType
) {
4780 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4781 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4783 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4784 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4786 if (sem
->temp_syncobj
) {
4787 close (sem
->temp_syncobj
);
4788 sem
->temp_syncobj
= 0;
4790 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4795 unreachable("Unhandled semaphore handle type");
4799 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4803 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4804 VkPhysicalDevice physicalDevice
,
4805 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4806 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4808 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4810 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4811 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4812 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4813 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4814 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4815 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4816 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4817 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4818 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4819 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4820 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4821 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4822 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4824 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4825 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4826 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4830 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4831 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4833 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4834 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4835 uint32_t *syncobj_dst
= NULL
;
4838 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4839 syncobj_dst
= &fence
->temp_syncobj
;
4841 syncobj_dst
= &fence
->syncobj
;
4844 switch(pImportFenceFdInfo
->handleType
) {
4845 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4846 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4847 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4848 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4850 unreachable("Unhandled fence handle type");
4854 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4855 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4858 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4859 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4861 uint32_t syncobj_handle
;
4863 if (fence
->temp_syncobj
)
4864 syncobj_handle
= fence
->temp_syncobj
;
4866 syncobj_handle
= fence
->syncobj
;
4868 switch(pGetFdInfo
->handleType
) {
4869 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4870 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4872 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4873 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4875 if (fence
->temp_syncobj
) {
4876 close (fence
->temp_syncobj
);
4877 fence
->temp_syncobj
= 0;
4879 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4884 unreachable("Unhandled fence handle type");
4888 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4892 void radv_GetPhysicalDeviceExternalFenceProperties(
4893 VkPhysicalDevice physicalDevice
,
4894 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4895 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4897 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4899 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4900 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4901 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4902 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4903 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4904 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4905 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4907 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4908 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4909 pExternalFenceProperties
->externalFenceFeatures
= 0;
4914 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4915 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4916 const VkAllocationCallbacks
* pAllocator
,
4917 VkDebugReportCallbackEXT
* pCallback
)
4919 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4920 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4921 pCreateInfo
, pAllocator
, &instance
->alloc
,
4926 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4927 VkDebugReportCallbackEXT _callback
,
4928 const VkAllocationCallbacks
* pAllocator
)
4930 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4931 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4932 _callback
, pAllocator
, &instance
->alloc
);
4936 radv_DebugReportMessageEXT(VkInstance _instance
,
4937 VkDebugReportFlagsEXT flags
,
4938 VkDebugReportObjectTypeEXT objectType
,
4941 int32_t messageCode
,
4942 const char* pLayerPrefix
,
4943 const char* pMessage
)
4945 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4946 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4947 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4951 radv_GetDeviceGroupPeerMemoryFeatures(
4954 uint32_t localDeviceIndex
,
4955 uint32_t remoteDeviceIndex
,
4956 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4958 assert(localDeviceIndex
== remoteDeviceIndex
);
4960 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4961 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4962 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4963 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
4966 static const VkTimeDomainEXT radv_time_domains
[] = {
4967 VK_TIME_DOMAIN_DEVICE_EXT
,
4968 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
4969 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
4972 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
4973 VkPhysicalDevice physicalDevice
,
4974 uint32_t *pTimeDomainCount
,
4975 VkTimeDomainEXT
*pTimeDomains
)
4978 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
4980 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
4981 vk_outarray_append(&out
, i
) {
4982 *i
= radv_time_domains
[d
];
4986 return vk_outarray_status(&out
);
4990 radv_clock_gettime(clockid_t clock_id
)
4992 struct timespec current
;
4995 ret
= clock_gettime(clock_id
, ¤t
);
4996 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
4997 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5001 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5004 VkResult
radv_GetCalibratedTimestampsEXT(
5006 uint32_t timestampCount
,
5007 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5008 uint64_t *pTimestamps
,
5009 uint64_t *pMaxDeviation
)
5011 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5012 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5014 uint64_t begin
, end
;
5015 uint64_t max_clock_period
= 0;
5017 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5019 for (d
= 0; d
< timestampCount
; d
++) {
5020 switch (pTimestampInfos
[d
].timeDomain
) {
5021 case VK_TIME_DOMAIN_DEVICE_EXT
:
5022 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5024 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5025 max_clock_period
= MAX2(max_clock_period
, device_period
);
5027 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5028 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5029 max_clock_period
= MAX2(max_clock_period
, 1);
5032 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5033 pTimestamps
[d
] = begin
;
5041 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5044 * The maximum deviation is the sum of the interval over which we
5045 * perform the sampling and the maximum period of any sampled
5046 * clock. That's because the maximum skew between any two sampled
5047 * clock edges is when the sampled clock with the largest period is
5048 * sampled at the end of that period but right at the beginning of the
5049 * sampling interval and some other clock is sampled right at the
5050 * begining of its sampling period and right at the end of the
5051 * sampling interval. Let's assume the GPU has the longest clock
5052 * period and that the application is sampling GPU and monotonic:
5055 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5056 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5060 * GPU -----_____-----_____-----_____-----_____
5063 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5064 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5066 * Interval <----------------->
5067 * Deviation <-------------------------->
5071 * m = read(monotonic) 2
5074 * We round the sample interval up by one tick to cover sampling error
5075 * in the interval clock
5078 uint64_t sample_interval
= end
- begin
+ 1;
5080 *pMaxDeviation
= sample_interval
+ max_clock_period
;