2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
48 #include "util/build_id.h"
49 #include "util/debug.h"
50 #include "util/mesa-sha1.h"
53 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
56 unsigned char sha1
[20];
57 unsigned ptr_size
= sizeof(void*);
59 memset(uuid
, 0, VK_UUID_SIZE
);
60 _mesa_sha1_init(&ctx
);
62 if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid
, &ctx
) ||
63 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
66 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
67 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
68 _mesa_sha1_final(&ctx
, sha1
);
70 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
75 radv_get_driver_uuid(void *uuid
)
77 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
81 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
83 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
87 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
89 const char *chip_string
;
90 char llvm_string
[32] = {};
93 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
94 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
95 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
96 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
97 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
98 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
99 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
100 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
101 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
102 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
103 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
104 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
105 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
106 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
107 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
108 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
109 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
110 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
111 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
112 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
113 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
114 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
115 case CHIP_RAVEN2
: chip_string
= "AMD RADV RAVEN2"; break;
116 default: chip_string
= "AMD RADV unknown"; break;
119 snprintf(llvm_string
, sizeof(llvm_string
),
120 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
121 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
122 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
126 radv_get_visible_vram_size(struct radv_physical_device
*device
)
128 return MIN2(device
->rad_info
.vram_size
, device
->rad_info
.vram_vis_size
);
132 radv_get_vram_size(struct radv_physical_device
*device
)
134 return device
->rad_info
.vram_size
- radv_get_visible_vram_size(device
);
138 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
140 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
141 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
142 uint64_t vram_size
= radv_get_vram_size(device
);
143 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
144 device
->memory_properties
.memoryHeapCount
= 0;
146 vram_index
= device
->memory_properties
.memoryHeapCount
++;
147 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
149 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
152 if (visible_vram_size
) {
153 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
154 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
155 .size
= visible_vram_size
,
156 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
159 if (device
->rad_info
.gart_size
> 0) {
160 gart_index
= device
->memory_properties
.memoryHeapCount
++;
161 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
162 .size
= device
->rad_info
.gart_size
,
163 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
167 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
168 unsigned type_count
= 0;
169 if (vram_index
>= 0) {
170 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
171 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
172 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
173 .heapIndex
= vram_index
,
176 if (gart_index
>= 0) {
177 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
178 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
179 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
181 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
182 .heapIndex
= gart_index
,
185 if (visible_vram_index
>= 0) {
186 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
187 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
188 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
189 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
190 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
191 .heapIndex
= visible_vram_index
,
194 if (gart_index
>= 0) {
195 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
196 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
197 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
198 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
199 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
200 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
201 .heapIndex
= gart_index
,
204 device
->memory_properties
.memoryTypeCount
= type_count
;
208 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
210 const char *family
= getenv("RADV_FORCE_FAMILY");
216 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
217 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
218 /* Override family and chip_class. */
219 device
->rad_info
.family
= i
;
221 if (i
>= CHIP_VEGA10
)
222 device
->rad_info
.chip_class
= GFX9
;
223 else if (i
>= CHIP_TONGA
)
224 device
->rad_info
.chip_class
= VI
;
225 else if (i
>= CHIP_BONAIRE
)
226 device
->rad_info
.chip_class
= CIK
;
228 device
->rad_info
.chip_class
= SI
;
234 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
239 radv_physical_device_init(struct radv_physical_device
*device
,
240 struct radv_instance
*instance
,
241 drmDevicePtr drm_device
)
243 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
245 drmVersionPtr version
;
249 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
251 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
252 radv_logi("Could not open device '%s'", path
);
254 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
257 version
= drmGetVersion(fd
);
261 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
262 radv_logi("Could not get the kernel driver version for device '%s'", path
);
264 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
265 "failed to get version %s: %m", path
);
268 if (strcmp(version
->name
, "amdgpu")) {
269 drmFreeVersion(version
);
272 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
273 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
275 return VK_ERROR_INCOMPATIBLE_DRIVER
;
277 drmFreeVersion(version
);
279 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
280 radv_logi("Found compatible device '%s'.", path
);
282 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
283 device
->instance
= instance
;
285 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
286 instance
->perftest_flags
);
288 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
292 if (instance
->enabled_extensions
.KHR_display
) {
293 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
294 if (master_fd
>= 0) {
295 uint32_t accel_working
= 0;
296 struct drm_amdgpu_info request
= {
297 .return_pointer
= (uintptr_t)&accel_working
,
298 .return_size
= sizeof(accel_working
),
299 .query
= AMDGPU_INFO_ACCEL_WORKING
302 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
309 device
->master_fd
= master_fd
;
310 device
->local_fd
= fd
;
311 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
313 radv_handle_env_var_force_family(device
);
315 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
317 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
318 device
->ws
->destroy(device
->ws
);
319 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
320 "cannot generate UUID");
324 /* These flags affect shader compilation. */
325 uint64_t shader_env_flags
=
326 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
327 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
329 /* The gpu id is already embedded in the uuid so we just pass "radv"
330 * when creating the cache.
332 char buf
[VK_UUID_SIZE
* 2 + 1];
333 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
334 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
336 if (device
->rad_info
.chip_class
< VI
||
337 device
->rad_info
.chip_class
> GFX9
)
338 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
340 radv_get_driver_uuid(&device
->device_uuid
);
341 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
343 if (device
->rad_info
.family
== CHIP_STONEY
||
344 device
->rad_info
.chip_class
>= GFX9
) {
345 device
->has_rbplus
= true;
346 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
347 device
->rad_info
.family
== CHIP_VEGA12
||
348 device
->rad_info
.family
== CHIP_RAVEN
||
349 device
->rad_info
.family
== CHIP_RAVEN2
;
352 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
355 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
357 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
359 /* Vega10/Raven need a special workaround for a hardware bug. */
360 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
361 device
->rad_info
.family
== CHIP_RAVEN
;
363 /* Out-of-order primitive rasterization. */
364 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
365 device
->rad_info
.max_se
>= 2;
366 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
367 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
369 device
->dcc_msaa_allowed
=
370 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
372 /* TODO: Figure out how to use LOAD_CONTEXT_REG on SI/CIK. */
373 device
->has_load_ctx_reg_pkt
= device
->rad_info
.chip_class
>= GFX9
||
374 (device
->rad_info
.chip_class
>= VI
&&
375 device
->rad_info
.me_fw_feature
>= 41);
377 radv_physical_device_init_mem_types(device
);
378 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
380 device
->bus_info
= *drm_device
->businfo
.pci
;
382 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
383 ac_print_gpu_info(&device
->rad_info
);
385 /* The WSI is structured as a layer on top of the driver, so this has
386 * to be the last part of initialization (at least until we get other
389 result
= radv_init_wsi(device
);
390 if (result
!= VK_SUCCESS
) {
391 device
->ws
->destroy(device
->ws
);
392 vk_error(instance
, result
);
406 radv_physical_device_finish(struct radv_physical_device
*device
)
408 radv_finish_wsi(device
);
409 device
->ws
->destroy(device
->ws
);
410 disk_cache_destroy(device
->disk_cache
);
411 close(device
->local_fd
);
412 if (device
->master_fd
!= -1)
413 close(device
->master_fd
);
417 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
418 VkSystemAllocationScope allocationScope
)
424 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
425 size_t align
, VkSystemAllocationScope allocationScope
)
427 return realloc(pOriginal
, size
);
431 default_free_func(void *pUserData
, void *pMemory
)
436 static const VkAllocationCallbacks default_alloc
= {
438 .pfnAllocation
= default_alloc_func
,
439 .pfnReallocation
= default_realloc_func
,
440 .pfnFree
= default_free_func
,
443 static const struct debug_control radv_debug_options
[] = {
444 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
445 {"nodcc", RADV_DEBUG_NO_DCC
},
446 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
447 {"nocache", RADV_DEBUG_NO_CACHE
},
448 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
449 {"nohiz", RADV_DEBUG_NO_HIZ
},
450 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
451 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
452 {"allbos", RADV_DEBUG_ALL_BOS
},
453 {"noibs", RADV_DEBUG_NO_IBS
},
454 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
455 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
456 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
457 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
458 {"nosisched", RADV_DEBUG_NO_SISCHED
},
459 {"preoptir", RADV_DEBUG_PREOPTIR
},
460 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
461 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
462 {"info", RADV_DEBUG_INFO
},
463 {"errors", RADV_DEBUG_ERRORS
},
464 {"startup", RADV_DEBUG_STARTUP
},
465 {"checkir", RADV_DEBUG_CHECKIR
},
466 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
467 {"nobinning", RADV_DEBUG_NOBINNING
},
472 radv_get_debug_option_name(int id
)
474 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
475 return radv_debug_options
[id
].string
;
478 static const struct debug_control radv_perftest_options
[] = {
479 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
480 {"sisched", RADV_PERFTEST_SISCHED
},
481 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
482 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
487 radv_get_perftest_option_name(int id
)
489 assert(id
< ARRAY_SIZE(radv_perftest_options
) - 1);
490 return radv_perftest_options
[id
].string
;
494 radv_handle_per_app_options(struct radv_instance
*instance
,
495 const VkApplicationInfo
*info
)
497 const char *name
= info
? info
->pApplicationName
: NULL
;
502 if (!strcmp(name
, "Talos - Linux - 32bit") ||
503 !strcmp(name
, "Talos - Linux - 64bit")) {
504 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
505 /* Force enable LLVM sisched for Talos because it looks
506 * safe and it gives few more FPS.
508 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
510 } else if (!strcmp(name
, "DOOM_VFR")) {
511 /* Work around a Doom VFR game bug */
512 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
516 static int radv_get_instance_extension_index(const char *name
)
518 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
519 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
526 VkResult
radv_CreateInstance(
527 const VkInstanceCreateInfo
* pCreateInfo
,
528 const VkAllocationCallbacks
* pAllocator
,
529 VkInstance
* pInstance
)
531 struct radv_instance
*instance
;
534 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
536 uint32_t client_version
;
537 if (pCreateInfo
->pApplicationInfo
&&
538 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
539 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
541 client_version
= VK_API_VERSION_1_0
;
544 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
545 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
547 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
549 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
552 instance
->alloc
= *pAllocator
;
554 instance
->alloc
= default_alloc
;
556 instance
->apiVersion
= client_version
;
557 instance
->physicalDeviceCount
= -1;
559 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
562 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
563 radv_perftest_options
);
566 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
567 radv_logi("Created an instance");
569 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
570 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
571 int index
= radv_get_instance_extension_index(ext_name
);
573 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
574 vk_free2(&default_alloc
, pAllocator
, instance
);
575 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
578 instance
->enabled_extensions
.extensions
[index
] = true;
581 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
582 if (result
!= VK_SUCCESS
) {
583 vk_free2(&default_alloc
, pAllocator
, instance
);
584 return vk_error(instance
, result
);
589 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
591 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
593 *pInstance
= radv_instance_to_handle(instance
);
598 void radv_DestroyInstance(
599 VkInstance _instance
,
600 const VkAllocationCallbacks
* pAllocator
)
602 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
607 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
608 radv_physical_device_finish(instance
->physicalDevices
+ i
);
611 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
615 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
617 vk_free(&instance
->alloc
, instance
);
621 radv_enumerate_devices(struct radv_instance
*instance
)
623 /* TODO: Check for more devices ? */
624 drmDevicePtr devices
[8];
625 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
628 instance
->physicalDeviceCount
= 0;
630 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
632 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
633 radv_logi("Found %d drm nodes", max_devices
);
636 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
638 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
639 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
640 devices
[i
]->bustype
== DRM_BUS_PCI
&&
641 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
643 result
= radv_physical_device_init(instance
->physicalDevices
+
644 instance
->physicalDeviceCount
,
647 if (result
== VK_SUCCESS
)
648 ++instance
->physicalDeviceCount
;
649 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
653 drmFreeDevices(devices
, max_devices
);
658 VkResult
radv_EnumeratePhysicalDevices(
659 VkInstance _instance
,
660 uint32_t* pPhysicalDeviceCount
,
661 VkPhysicalDevice
* pPhysicalDevices
)
663 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
666 if (instance
->physicalDeviceCount
< 0) {
667 result
= radv_enumerate_devices(instance
);
668 if (result
!= VK_SUCCESS
&&
669 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
673 if (!pPhysicalDevices
) {
674 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
676 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
677 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
678 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
681 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
685 VkResult
radv_EnumeratePhysicalDeviceGroups(
686 VkInstance _instance
,
687 uint32_t* pPhysicalDeviceGroupCount
,
688 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
690 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
693 if (instance
->physicalDeviceCount
< 0) {
694 result
= radv_enumerate_devices(instance
);
695 if (result
!= VK_SUCCESS
&&
696 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
700 if (!pPhysicalDeviceGroupProperties
) {
701 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
703 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
704 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
705 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
706 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
707 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
710 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
714 void radv_GetPhysicalDeviceFeatures(
715 VkPhysicalDevice physicalDevice
,
716 VkPhysicalDeviceFeatures
* pFeatures
)
718 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
719 memset(pFeatures
, 0, sizeof(*pFeatures
));
721 *pFeatures
= (VkPhysicalDeviceFeatures
) {
722 .robustBufferAccess
= true,
723 .fullDrawIndexUint32
= true,
724 .imageCubeArray
= true,
725 .independentBlend
= true,
726 .geometryShader
= true,
727 .tessellationShader
= true,
728 .sampleRateShading
= true,
729 .dualSrcBlend
= true,
731 .multiDrawIndirect
= true,
732 .drawIndirectFirstInstance
= true,
734 .depthBiasClamp
= true,
735 .fillModeNonSolid
= true,
740 .multiViewport
= true,
741 .samplerAnisotropy
= true,
742 .textureCompressionETC2
= radv_device_supports_etc(pdevice
),
743 .textureCompressionASTC_LDR
= false,
744 .textureCompressionBC
= true,
745 .occlusionQueryPrecise
= true,
746 .pipelineStatisticsQuery
= true,
747 .vertexPipelineStoresAndAtomics
= true,
748 .fragmentStoresAndAtomics
= true,
749 .shaderTessellationAndGeometryPointSize
= true,
750 .shaderImageGatherExtended
= true,
751 .shaderStorageImageExtendedFormats
= true,
752 .shaderStorageImageMultisample
= pdevice
->rad_info
.chip_class
>= VI
,
753 .shaderUniformBufferArrayDynamicIndexing
= true,
754 .shaderSampledImageArrayDynamicIndexing
= true,
755 .shaderStorageBufferArrayDynamicIndexing
= true,
756 .shaderStorageImageArrayDynamicIndexing
= true,
757 .shaderStorageImageReadWithoutFormat
= true,
758 .shaderStorageImageWriteWithoutFormat
= true,
759 .shaderClipDistance
= true,
760 .shaderCullDistance
= true,
761 .shaderFloat64
= true,
763 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
,
764 .sparseBinding
= true,
765 .variableMultisampleRate
= true,
766 .inheritedQueries
= true,
770 void radv_GetPhysicalDeviceFeatures2(
771 VkPhysicalDevice physicalDevice
,
772 VkPhysicalDeviceFeatures2
*pFeatures
)
774 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
775 vk_foreach_struct(ext
, pFeatures
->pNext
) {
776 switch (ext
->sType
) {
777 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES
: {
778 VkPhysicalDeviceVariablePointerFeatures
*features
= (void *)ext
;
779 features
->variablePointersStorageBuffer
= true;
780 features
->variablePointers
= true;
783 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES
: {
784 VkPhysicalDeviceMultiviewFeatures
*features
= (VkPhysicalDeviceMultiviewFeatures
*)ext
;
785 features
->multiview
= true;
786 features
->multiviewGeometryShader
= true;
787 features
->multiviewTessellationShader
= true;
790 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
791 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
792 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
793 features
->shaderDrawParameters
= true;
796 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
797 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
798 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
799 features
->protectedMemory
= false;
802 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
803 VkPhysicalDevice16BitStorageFeatures
*features
=
804 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
805 bool enabled
= pdevice
->rad_info
.chip_class
>= VI
;
806 features
->storageBuffer16BitAccess
= enabled
;
807 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
808 features
->storagePushConstant16
= enabled
;
809 features
->storageInputOutput16
= enabled
;
812 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
813 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
814 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
815 features
->samplerYcbcrConversion
= false;
818 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
819 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
820 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
821 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
822 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
823 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
824 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
825 features
->shaderSampledImageArrayNonUniformIndexing
= false;
826 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
827 features
->shaderStorageImageArrayNonUniformIndexing
= false;
828 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
829 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
830 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
831 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
832 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
833 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
834 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
835 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
836 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
837 features
->descriptorBindingUpdateUnusedWhilePending
= true;
838 features
->descriptorBindingPartiallyBound
= true;
839 features
->descriptorBindingVariableDescriptorCount
= true;
840 features
->runtimeDescriptorArray
= true;
843 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
844 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
845 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
846 features
->conditionalRendering
= true;
847 features
->inheritedConditionalRendering
= false;
850 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
851 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
852 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
853 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
854 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
857 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
: {
858 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*features
=
859 (VkPhysicalDeviceTransformFeedbackFeaturesEXT
*)ext
;
860 features
->transformFeedback
= true;
861 features
->geometryStreams
= true;
864 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT
: {
865 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*features
=
866 (VkPhysicalDeviceScalarBlockLayoutFeaturesEXT
*)ext
;
867 features
->scalarBlockLayout
= pdevice
->rad_info
.chip_class
>= CIK
;
870 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT
: {
871 VkPhysicalDeviceMemoryPriorityFeaturesEXT
*features
=
872 (VkPhysicalDeviceMemoryPriorityFeaturesEXT
*)ext
;
873 features
->memoryPriority
= VK_TRUE
;
876 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_ADDRESS_FEATURES_EXT
: {
877 VkPhysicalDeviceBufferAddressFeaturesEXT
*features
=
878 (VkPhysicalDeviceBufferAddressFeaturesEXT
*)ext
;
879 features
->bufferDeviceAddress
= true;
880 features
->bufferDeviceAddressCaptureReplay
= false;
881 features
->bufferDeviceAddressMultiDevice
= false;
888 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
891 void radv_GetPhysicalDeviceProperties(
892 VkPhysicalDevice physicalDevice
,
893 VkPhysicalDeviceProperties
* pProperties
)
895 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
896 VkSampleCountFlags sample_counts
= 0xf;
898 /* make sure that the entire descriptor set is addressable with a signed
899 * 32-bit int. So the sum of all limits scaled by descriptor size has to
900 * be at most 2 GiB. the combined image & samples object count as one of
901 * both. This limit is for the pipeline layout, not for the set layout, but
902 * there is no set limit, so we just set a pipeline limit. I don't think
903 * any app is going to hit this soon. */
904 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
905 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
906 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
907 32 /* sampler, largest when combined with image */ +
908 64 /* sampled image */ +
909 64 /* storage image */);
911 VkPhysicalDeviceLimits limits
= {
912 .maxImageDimension1D
= (1 << 14),
913 .maxImageDimension2D
= (1 << 14),
914 .maxImageDimension3D
= (1 << 11),
915 .maxImageDimensionCube
= (1 << 14),
916 .maxImageArrayLayers
= (1 << 11),
917 .maxTexelBufferElements
= 128 * 1024 * 1024,
918 .maxUniformBufferRange
= UINT32_MAX
,
919 .maxStorageBufferRange
= UINT32_MAX
,
920 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
921 .maxMemoryAllocationCount
= UINT32_MAX
,
922 .maxSamplerAllocationCount
= 64 * 1024,
923 .bufferImageGranularity
= 64, /* A cache line */
924 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
925 .maxBoundDescriptorSets
= MAX_SETS
,
926 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
927 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
928 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
929 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
930 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
931 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
932 .maxPerStageResources
= max_descriptor_set_size
,
933 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
934 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
935 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
936 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
937 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
938 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
939 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
940 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
941 .maxVertexInputAttributes
= MAX_VERTEX_ATTRIBS
,
942 .maxVertexInputBindings
= MAX_VBS
,
943 .maxVertexInputAttributeOffset
= 2047,
944 .maxVertexInputBindingStride
= 2048,
945 .maxVertexOutputComponents
= 128,
946 .maxTessellationGenerationLevel
= 64,
947 .maxTessellationPatchSize
= 32,
948 .maxTessellationControlPerVertexInputComponents
= 128,
949 .maxTessellationControlPerVertexOutputComponents
= 128,
950 .maxTessellationControlPerPatchOutputComponents
= 120,
951 .maxTessellationControlTotalOutputComponents
= 4096,
952 .maxTessellationEvaluationInputComponents
= 128,
953 .maxTessellationEvaluationOutputComponents
= 128,
954 .maxGeometryShaderInvocations
= 127,
955 .maxGeometryInputComponents
= 64,
956 .maxGeometryOutputComponents
= 128,
957 .maxGeometryOutputVertices
= 256,
958 .maxGeometryTotalOutputComponents
= 1024,
959 .maxFragmentInputComponents
= 128,
960 .maxFragmentOutputAttachments
= 8,
961 .maxFragmentDualSrcAttachments
= 1,
962 .maxFragmentCombinedOutputResources
= 8,
963 .maxComputeSharedMemorySize
= 32768,
964 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
965 .maxComputeWorkGroupInvocations
= 2048,
966 .maxComputeWorkGroupSize
= {
971 .subPixelPrecisionBits
= 8,
972 .subTexelPrecisionBits
= 8,
973 .mipmapPrecisionBits
= 8,
974 .maxDrawIndexedIndexValue
= UINT32_MAX
,
975 .maxDrawIndirectCount
= UINT32_MAX
,
976 .maxSamplerLodBias
= 16,
977 .maxSamplerAnisotropy
= 16,
978 .maxViewports
= MAX_VIEWPORTS
,
979 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
980 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
981 .viewportSubPixelBits
= 8,
982 .minMemoryMapAlignment
= 4096, /* A page */
983 .minTexelBufferOffsetAlignment
= 1,
984 .minUniformBufferOffsetAlignment
= 4,
985 .minStorageBufferOffsetAlignment
= 4,
986 .minTexelOffset
= -32,
987 .maxTexelOffset
= 31,
988 .minTexelGatherOffset
= -32,
989 .maxTexelGatherOffset
= 31,
990 .minInterpolationOffset
= -2,
991 .maxInterpolationOffset
= 2,
992 .subPixelInterpolationOffsetBits
= 8,
993 .maxFramebufferWidth
= (1 << 14),
994 .maxFramebufferHeight
= (1 << 14),
995 .maxFramebufferLayers
= (1 << 10),
996 .framebufferColorSampleCounts
= sample_counts
,
997 .framebufferDepthSampleCounts
= sample_counts
,
998 .framebufferStencilSampleCounts
= sample_counts
,
999 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
1000 .maxColorAttachments
= MAX_RTS
,
1001 .sampledImageColorSampleCounts
= sample_counts
,
1002 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
1003 .sampledImageDepthSampleCounts
= sample_counts
,
1004 .sampledImageStencilSampleCounts
= sample_counts
,
1005 .storageImageSampleCounts
= pdevice
->rad_info
.chip_class
>= VI
? sample_counts
: VK_SAMPLE_COUNT_1_BIT
,
1006 .maxSampleMaskWords
= 1,
1007 .timestampComputeAndGraphics
= true,
1008 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
1009 .maxClipDistances
= 8,
1010 .maxCullDistances
= 8,
1011 .maxCombinedClipAndCullDistances
= 8,
1012 .discreteQueuePriorities
= 2,
1013 .pointSizeRange
= { 0.125, 255.875 },
1014 .lineWidthRange
= { 0.0, 7.9921875 },
1015 .pointSizeGranularity
= (1.0 / 8.0),
1016 .lineWidthGranularity
= (1.0 / 128.0),
1017 .strictLines
= false, /* FINISHME */
1018 .standardSampleLocations
= true,
1019 .optimalBufferCopyOffsetAlignment
= 128,
1020 .optimalBufferCopyRowPitchAlignment
= 128,
1021 .nonCoherentAtomSize
= 64,
1024 *pProperties
= (VkPhysicalDeviceProperties
) {
1025 .apiVersion
= radv_physical_device_api_version(pdevice
),
1026 .driverVersion
= vk_get_driver_version(),
1027 .vendorID
= ATI_VENDOR_ID
,
1028 .deviceID
= pdevice
->rad_info
.pci_id
,
1029 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1031 .sparseProperties
= {0},
1034 strcpy(pProperties
->deviceName
, pdevice
->name
);
1035 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1038 void radv_GetPhysicalDeviceProperties2(
1039 VkPhysicalDevice physicalDevice
,
1040 VkPhysicalDeviceProperties2
*pProperties
)
1042 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1043 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1045 vk_foreach_struct(ext
, pProperties
->pNext
) {
1046 switch (ext
->sType
) {
1047 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1048 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1049 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1050 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1053 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
: {
1054 VkPhysicalDeviceIDProperties
*properties
= (VkPhysicalDeviceIDProperties
*)ext
;
1055 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1056 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1057 properties
->deviceLUIDValid
= false;
1060 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES
: {
1061 VkPhysicalDeviceMultiviewProperties
*properties
= (VkPhysicalDeviceMultiviewProperties
*)ext
;
1062 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1063 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1066 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES
: {
1067 VkPhysicalDevicePointClippingProperties
*properties
=
1068 (VkPhysicalDevicePointClippingProperties
*)ext
;
1069 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES
;
1072 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1073 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1074 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1075 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1078 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1079 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1080 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1081 properties
->minImportedHostPointerAlignment
= 4096;
1084 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1085 VkPhysicalDeviceSubgroupProperties
*properties
=
1086 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1087 properties
->subgroupSize
= 64;
1088 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1089 properties
->supportedOperations
=
1090 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1091 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1092 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1093 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1094 if (pdevice
->rad_info
.chip_class
>= VI
) {
1095 properties
->supportedOperations
|=
1096 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1097 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1098 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1100 properties
->quadOperationsInAllStages
= true;
1103 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1104 VkPhysicalDeviceMaintenance3Properties
*properties
=
1105 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1106 /* Make sure everything is addressable by a signed 32-bit int, and
1107 * our largest descriptors are 96 bytes. */
1108 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1109 /* Our buffer size fields allow only this much */
1110 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1113 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1114 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1115 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1116 /* GFX6-8 only support single channel min/max filter. */
1117 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1118 properties
->filterMinmaxSingleComponentFormats
= true;
1121 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1122 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1123 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1125 /* Shader engines. */
1126 properties
->shaderEngineCount
=
1127 pdevice
->rad_info
.max_se
;
1128 properties
->shaderArraysPerEngineCount
=
1129 pdevice
->rad_info
.max_sh_per_se
;
1130 properties
->computeUnitsPerShaderArray
=
1131 pdevice
->rad_info
.num_good_cu_per_sh
;
1132 properties
->simdPerComputeUnit
= 4;
1133 properties
->wavefrontsPerSimd
=
1134 pdevice
->rad_info
.family
== CHIP_TONGA
||
1135 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1136 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1137 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1138 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1139 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1140 properties
->wavefrontSize
= 64;
1143 properties
->sgprsPerSimd
=
1144 ac_get_num_physical_sgprs(pdevice
->rad_info
.chip_class
);
1145 properties
->minSgprAllocation
=
1146 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1147 properties
->maxSgprAllocation
=
1148 pdevice
->rad_info
.family
== CHIP_TONGA
||
1149 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1150 properties
->sgprAllocationGranularity
=
1151 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1154 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1155 properties
->minVgprAllocation
= 4;
1156 properties
->maxVgprAllocation
= 256;
1157 properties
->vgprAllocationGranularity
= 4;
1160 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1161 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1162 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1163 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1166 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1167 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1168 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1169 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1170 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1171 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1172 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1173 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1174 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1175 properties
->robustBufferAccessUpdateAfterBind
= false;
1176 properties
->quadDivergentImplicitLod
= false;
1178 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1179 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1180 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1181 32 /* sampler, largest when combined with image */ +
1182 64 /* sampled image */ +
1183 64 /* storage image */);
1184 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1185 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1186 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1187 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1188 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1189 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1190 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1191 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1192 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1193 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1194 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1195 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1196 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1197 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1198 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1201 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1202 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1203 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1204 properties
->protectedNoFault
= false;
1207 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1208 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1209 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1210 properties
->primitiveOverestimationSize
= 0;
1211 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1212 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1213 properties
->primitiveUnderestimation
= VK_FALSE
;
1214 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1215 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1216 properties
->degenerateLinesRasterized
= VK_FALSE
;
1217 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1218 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1221 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT
: {
1222 VkPhysicalDevicePCIBusInfoPropertiesEXT
*properties
=
1223 (VkPhysicalDevicePCIBusInfoPropertiesEXT
*)ext
;
1224 properties
->pciDomain
= pdevice
->bus_info
.domain
;
1225 properties
->pciBus
= pdevice
->bus_info
.bus
;
1226 properties
->pciDevice
= pdevice
->bus_info
.dev
;
1227 properties
->pciFunction
= pdevice
->bus_info
.func
;
1230 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR
: {
1231 VkPhysicalDeviceDriverPropertiesKHR
*driver_props
=
1232 (VkPhysicalDeviceDriverPropertiesKHR
*) ext
;
1234 driver_props
->driverID
= VK_DRIVER_ID_MESA_RADV_KHR
;
1235 memset(driver_props
->driverName
, 0, VK_MAX_DRIVER_NAME_SIZE_KHR
);
1236 strcpy(driver_props
->driverName
, "radv");
1238 memset(driver_props
->driverInfo
, 0, VK_MAX_DRIVER_INFO_SIZE_KHR
);
1239 snprintf(driver_props
->driverInfo
, VK_MAX_DRIVER_INFO_SIZE_KHR
,
1240 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
1242 (HAVE_LLVM
>> 8) & 0xff, HAVE_LLVM
& 0xff,
1243 MESA_LLVM_VERSION_PATCH
);
1245 driver_props
->conformanceVersion
= (VkConformanceVersionKHR
) {
1253 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT
: {
1254 VkPhysicalDeviceTransformFeedbackPropertiesEXT
*properties
=
1255 (VkPhysicalDeviceTransformFeedbackPropertiesEXT
*)ext
;
1256 properties
->maxTransformFeedbackStreams
= MAX_SO_STREAMS
;
1257 properties
->maxTransformFeedbackBuffers
= MAX_SO_BUFFERS
;
1258 properties
->maxTransformFeedbackBufferSize
= UINT32_MAX
;
1259 properties
->maxTransformFeedbackStreamDataSize
= 512;
1260 properties
->maxTransformFeedbackBufferDataSize
= UINT32_MAX
;
1261 properties
->maxTransformFeedbackBufferDataStride
= 512;
1262 properties
->transformFeedbackQueries
= true;
1263 properties
->transformFeedbackStreamsLinesTriangles
= false;
1264 properties
->transformFeedbackRasterizationStreamSelect
= false;
1265 properties
->transformFeedbackDraw
= true;
1274 static void radv_get_physical_device_queue_family_properties(
1275 struct radv_physical_device
* pdevice
,
1277 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1279 int num_queue_families
= 1;
1281 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1282 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1283 num_queue_families
++;
1285 if (pQueueFamilyProperties
== NULL
) {
1286 *pCount
= num_queue_families
;
1295 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1296 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1297 VK_QUEUE_COMPUTE_BIT
|
1298 VK_QUEUE_TRANSFER_BIT
|
1299 VK_QUEUE_SPARSE_BINDING_BIT
,
1301 .timestampValidBits
= 64,
1302 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1307 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1308 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1309 if (*pCount
> idx
) {
1310 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1311 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1312 VK_QUEUE_TRANSFER_BIT
|
1313 VK_QUEUE_SPARSE_BINDING_BIT
,
1314 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1315 .timestampValidBits
= 64,
1316 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1324 void radv_GetPhysicalDeviceQueueFamilyProperties(
1325 VkPhysicalDevice physicalDevice
,
1327 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1329 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1330 if (!pQueueFamilyProperties
) {
1331 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1334 VkQueueFamilyProperties
*properties
[] = {
1335 pQueueFamilyProperties
+ 0,
1336 pQueueFamilyProperties
+ 1,
1337 pQueueFamilyProperties
+ 2,
1339 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1340 assert(*pCount
<= 3);
1343 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1344 VkPhysicalDevice physicalDevice
,
1346 VkQueueFamilyProperties2
*pQueueFamilyProperties
)
1348 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1349 if (!pQueueFamilyProperties
) {
1350 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1353 VkQueueFamilyProperties
*properties
[] = {
1354 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1355 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1356 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1358 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1359 assert(*pCount
<= 3);
1362 void radv_GetPhysicalDeviceMemoryProperties(
1363 VkPhysicalDevice physicalDevice
,
1364 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1366 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1368 *pMemoryProperties
= physical_device
->memory_properties
;
1372 radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice
,
1373 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memoryBudget
)
1375 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
1376 VkPhysicalDeviceMemoryProperties
*memory_properties
= &device
->memory_properties
;
1377 uint64_t visible_vram_size
= radv_get_visible_vram_size(device
);
1378 uint64_t vram_size
= radv_get_vram_size(device
);
1379 uint64_t gtt_size
= device
->rad_info
.gart_size
;
1380 uint64_t heap_budget
, heap_usage
;
1382 /* For all memory heaps, the computation of budget is as follow:
1383 * heap_budget = heap_size - global_heap_usage + app_heap_usage
1385 * The Vulkan spec 1.1.97 says that the budget should include any
1386 * currently allocated device memory.
1388 * Note that the application heap usages are not really accurate (eg.
1389 * in presence of shared buffers).
1392 heap_usage
= device
->ws
->query_value(device
->ws
,
1393 RADEON_ALLOCATED_VRAM
);
1395 heap_budget
= vram_size
-
1396 device
->ws
->query_value(device
->ws
, RADEON_VRAM_USAGE
) +
1399 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM
] = heap_budget
;
1400 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM
] = heap_usage
;
1403 if (visible_vram_size
) {
1404 heap_usage
= device
->ws
->query_value(device
->ws
,
1405 RADEON_ALLOCATED_VRAM_VIS
);
1407 heap_budget
= visible_vram_size
-
1408 device
->ws
->query_value(device
->ws
, RADEON_VRAM_VIS_USAGE
) +
1411 memoryBudget
->heapBudget
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_budget
;
1412 memoryBudget
->heapUsage
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = heap_usage
;
1416 heap_usage
= device
->ws
->query_value(device
->ws
,
1417 RADEON_ALLOCATED_GTT
);
1419 heap_budget
= gtt_size
-
1420 device
->ws
->query_value(device
->ws
, RADEON_GTT_USAGE
) +
1423 memoryBudget
->heapBudget
[RADV_MEM_HEAP_GTT
] = heap_budget
;
1424 memoryBudget
->heapUsage
[RADV_MEM_HEAP_GTT
] = heap_usage
;
1427 /* The heapBudget and heapUsage values must be zero for array elements
1428 * greater than or equal to
1429 * VkPhysicalDeviceMemoryProperties::memoryHeapCount.
1431 for (uint32_t i
= memory_properties
->memoryHeapCount
; i
< VK_MAX_MEMORY_HEAPS
; i
++) {
1432 memoryBudget
->heapBudget
[i
] = 0;
1433 memoryBudget
->heapUsage
[i
] = 0;
1437 void radv_GetPhysicalDeviceMemoryProperties2(
1438 VkPhysicalDevice physicalDevice
,
1439 VkPhysicalDeviceMemoryProperties2
*pMemoryProperties
)
1441 radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1442 &pMemoryProperties
->memoryProperties
);
1444 VkPhysicalDeviceMemoryBudgetPropertiesEXT
*memory_budget
=
1445 vk_find_struct(pMemoryProperties
->pNext
,
1446 PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT
);
1448 radv_get_memory_budget_properties(physicalDevice
, memory_budget
);
1451 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1453 VkExternalMemoryHandleTypeFlagBits handleType
,
1454 const void *pHostPointer
,
1455 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1457 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1461 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1462 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1463 uint32_t memoryTypeBits
= 0;
1464 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1465 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1466 memoryTypeBits
= (1 << i
);
1470 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1474 return VK_ERROR_INVALID_EXTERNAL_HANDLE
;
1478 static enum radeon_ctx_priority
1479 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1481 /* Default to MEDIUM when a specific global priority isn't requested */
1483 return RADEON_CTX_PRIORITY_MEDIUM
;
1485 switch(pObj
->globalPriority
) {
1486 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1487 return RADEON_CTX_PRIORITY_REALTIME
;
1488 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1489 return RADEON_CTX_PRIORITY_HIGH
;
1490 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1491 return RADEON_CTX_PRIORITY_MEDIUM
;
1492 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1493 return RADEON_CTX_PRIORITY_LOW
;
1495 unreachable("Illegal global priority value");
1496 return RADEON_CTX_PRIORITY_INVALID
;
1501 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1502 uint32_t queue_family_index
, int idx
,
1503 VkDeviceQueueCreateFlags flags
,
1504 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1506 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1507 queue
->device
= device
;
1508 queue
->queue_family_index
= queue_family_index
;
1509 queue
->queue_idx
= idx
;
1510 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1511 queue
->flags
= flags
;
1513 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1515 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1521 radv_queue_finish(struct radv_queue
*queue
)
1524 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1526 if (queue
->initial_full_flush_preamble_cs
)
1527 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1528 if (queue
->initial_preamble_cs
)
1529 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1530 if (queue
->continue_preamble_cs
)
1531 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1532 if (queue
->descriptor_bo
)
1533 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1534 if (queue
->scratch_bo
)
1535 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1536 if (queue
->esgs_ring_bo
)
1537 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1538 if (queue
->gsvs_ring_bo
)
1539 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1540 if (queue
->tess_rings_bo
)
1541 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1542 if (queue
->compute_scratch_bo
)
1543 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1547 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1549 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1550 bo_list
->list
.count
= bo_list
->capacity
= 0;
1551 bo_list
->list
.bos
= NULL
;
1555 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1557 free(bo_list
->list
.bos
);
1558 pthread_mutex_destroy(&bo_list
->mutex
);
1561 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1562 struct radeon_winsys_bo
*bo
)
1564 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1569 if (unlikely(!device
->use_global_bo_list
))
1572 pthread_mutex_lock(&bo_list
->mutex
);
1573 if (bo_list
->list
.count
== bo_list
->capacity
) {
1574 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1575 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1578 pthread_mutex_unlock(&bo_list
->mutex
);
1579 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1582 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1583 bo_list
->capacity
= capacity
;
1586 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1587 pthread_mutex_unlock(&bo_list
->mutex
);
1591 static void radv_bo_list_remove(struct radv_device
*device
,
1592 struct radeon_winsys_bo
*bo
)
1594 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1599 if (unlikely(!device
->use_global_bo_list
))
1602 pthread_mutex_lock(&bo_list
->mutex
);
1603 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1604 if (bo_list
->list
.bos
[i
] == bo
) {
1605 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1606 --bo_list
->list
.count
;
1610 pthread_mutex_unlock(&bo_list
->mutex
);
1614 radv_device_init_gs_info(struct radv_device
*device
)
1616 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1617 device
->physical_device
->rad_info
.family
);
1620 static int radv_get_device_extension_index(const char *name
)
1622 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1623 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1630 radv_get_int_debug_option(const char *name
, int default_value
)
1637 result
= default_value
;
1641 result
= strtol(str
, &endptr
, 0);
1642 if (str
== endptr
) {
1643 /* No digits founs. */
1644 result
= default_value
;
1651 VkResult
radv_CreateDevice(
1652 VkPhysicalDevice physicalDevice
,
1653 const VkDeviceCreateInfo
* pCreateInfo
,
1654 const VkAllocationCallbacks
* pAllocator
,
1657 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1659 struct radv_device
*device
;
1661 bool keep_shader_info
= false;
1663 /* Check enabled features */
1664 if (pCreateInfo
->pEnabledFeatures
) {
1665 VkPhysicalDeviceFeatures supported_features
;
1666 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1667 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1668 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1669 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1670 for (uint32_t i
= 0; i
< num_features
; i
++) {
1671 if (enabled_feature
[i
] && !supported_feature
[i
])
1672 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1676 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1678 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1680 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1682 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1683 device
->instance
= physical_device
->instance
;
1684 device
->physical_device
= physical_device
;
1686 device
->ws
= physical_device
->ws
;
1688 device
->alloc
= *pAllocator
;
1690 device
->alloc
= physical_device
->instance
->alloc
;
1692 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1693 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1694 int index
= radv_get_device_extension_index(ext_name
);
1695 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1696 vk_free(&device
->alloc
, device
);
1697 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1700 device
->enabled_extensions
.extensions
[index
] = true;
1703 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1705 /* With update after bind we can't attach bo's to the command buffer
1706 * from the descriptor set anymore, so we have to use a global BO list.
1708 device
->use_global_bo_list
=
1709 device
->enabled_extensions
.EXT_descriptor_indexing
||
1710 device
->enabled_extensions
.EXT_buffer_device_address
;
1712 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1713 list_inithead(&device
->shader_slabs
);
1715 radv_bo_list_init(&device
->bo_list
);
1717 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1718 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1719 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1720 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1721 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1723 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1725 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1726 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1727 if (!device
->queues
[qfi
]) {
1728 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1732 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1734 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1736 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1737 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1738 qfi
, q
, queue_create
->flags
,
1740 if (result
!= VK_SUCCESS
)
1745 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1746 !(device
->instance
->debug_flags
& RADV_DEBUG_NOBINNING
);
1748 /* Disabled and not implemented for now. */
1749 device
->dfsm_allowed
= device
->pbb_allowed
&&
1750 (device
->physical_device
->rad_info
.family
== CHIP_RAVEN
||
1751 device
->physical_device
->rad_info
.family
== CHIP_RAVEN2
);
1754 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1757 /* The maximum number of scratch waves. Scratch space isn't divided
1758 * evenly between CUs. The number is only a function of the number of CUs.
1759 * We can decrease the constant to decrease the scratch buffer size.
1761 * sctx->scratch_waves must be >= the maximum possible size of
1762 * 1 threadgroup, so that the hw doesn't hang from being unable
1765 * The recommended value is 4 per CU at most. Higher numbers don't
1766 * bring much benefit, but they still occupy chip resources (think
1767 * async compute). I've seen ~2% performance difference between 4 and 32.
1769 uint32_t max_threads_per_block
= 2048;
1770 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1771 max_threads_per_block
/ 64);
1773 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1775 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1776 /* If the KMD allows it (there is a KMD hw register for it),
1777 * allow launching waves out-of-order.
1779 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1782 radv_device_init_gs_info(device
);
1784 device
->tess_offchip_block_dw_size
=
1785 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1786 device
->has_distributed_tess
=
1787 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1788 device
->physical_device
->rad_info
.max_se
>= 2;
1790 if (getenv("RADV_TRACE_FILE")) {
1791 const char *filename
= getenv("RADV_TRACE_FILE");
1793 keep_shader_info
= true;
1795 if (!radv_init_trace(device
))
1798 fprintf(stderr
, "*****************************************************************************\n");
1799 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1800 fprintf(stderr
, "*****************************************************************************\n");
1802 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1803 radv_dump_enabled_options(device
, stderr
);
1806 device
->keep_shader_info
= keep_shader_info
;
1808 result
= radv_device_init_meta(device
);
1809 if (result
!= VK_SUCCESS
)
1812 radv_device_init_msaa(device
);
1814 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1815 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1817 case RADV_QUEUE_GENERAL
:
1818 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1819 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1820 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1822 case RADV_QUEUE_COMPUTE
:
1823 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1824 radeon_emit(device
->empty_cs
[family
], 0);
1827 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1830 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1831 cik_create_gfx_config(device
);
1833 VkPipelineCacheCreateInfo ci
;
1834 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1837 ci
.pInitialData
= NULL
;
1838 ci
.initialDataSize
= 0;
1840 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1842 if (result
!= VK_SUCCESS
)
1845 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1847 device
->force_aniso
=
1848 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1849 if (device
->force_aniso
>= 0) {
1850 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
1851 1 << util_logbase2(device
->force_aniso
));
1854 *pDevice
= radv_device_to_handle(device
);
1858 radv_device_finish_meta(device
);
1860 radv_bo_list_finish(&device
->bo_list
);
1862 if (device
->trace_bo
)
1863 device
->ws
->buffer_destroy(device
->trace_bo
);
1865 if (device
->gfx_init
)
1866 device
->ws
->buffer_destroy(device
->gfx_init
);
1868 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1869 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1870 radv_queue_finish(&device
->queues
[i
][q
]);
1871 if (device
->queue_count
[i
])
1872 vk_free(&device
->alloc
, device
->queues
[i
]);
1875 vk_free(&device
->alloc
, device
);
1879 void radv_DestroyDevice(
1881 const VkAllocationCallbacks
* pAllocator
)
1883 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1888 if (device
->trace_bo
)
1889 device
->ws
->buffer_destroy(device
->trace_bo
);
1891 if (device
->gfx_init
)
1892 device
->ws
->buffer_destroy(device
->gfx_init
);
1894 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1895 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1896 radv_queue_finish(&device
->queues
[i
][q
]);
1897 if (device
->queue_count
[i
])
1898 vk_free(&device
->alloc
, device
->queues
[i
]);
1899 if (device
->empty_cs
[i
])
1900 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1902 radv_device_finish_meta(device
);
1904 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1905 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1907 radv_destroy_shader_slabs(device
);
1909 radv_bo_list_finish(&device
->bo_list
);
1910 vk_free(&device
->alloc
, device
);
1913 VkResult
radv_EnumerateInstanceLayerProperties(
1914 uint32_t* pPropertyCount
,
1915 VkLayerProperties
* pProperties
)
1917 if (pProperties
== NULL
) {
1918 *pPropertyCount
= 0;
1922 /* None supported at this time */
1923 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1926 VkResult
radv_EnumerateDeviceLayerProperties(
1927 VkPhysicalDevice physicalDevice
,
1928 uint32_t* pPropertyCount
,
1929 VkLayerProperties
* pProperties
)
1931 if (pProperties
== NULL
) {
1932 *pPropertyCount
= 0;
1936 /* None supported at this time */
1937 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1940 void radv_GetDeviceQueue2(
1942 const VkDeviceQueueInfo2
* pQueueInfo
,
1945 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1946 struct radv_queue
*queue
;
1948 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1949 if (pQueueInfo
->flags
!= queue
->flags
) {
1950 /* From the Vulkan 1.1.70 spec:
1952 * "The queue returned by vkGetDeviceQueue2 must have the same
1953 * flags value from this structure as that used at device
1954 * creation time in a VkDeviceQueueCreateInfo instance. If no
1955 * matching flags were specified at device creation time then
1956 * pQueue will return VK_NULL_HANDLE."
1958 *pQueue
= VK_NULL_HANDLE
;
1962 *pQueue
= radv_queue_to_handle(queue
);
1965 void radv_GetDeviceQueue(
1967 uint32_t queueFamilyIndex
,
1968 uint32_t queueIndex
,
1971 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1972 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1973 .queueFamilyIndex
= queueFamilyIndex
,
1974 .queueIndex
= queueIndex
1977 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1981 fill_geom_tess_rings(struct radv_queue
*queue
,
1983 bool add_sample_positions
,
1984 uint32_t esgs_ring_size
,
1985 struct radeon_winsys_bo
*esgs_ring_bo
,
1986 uint32_t gsvs_ring_size
,
1987 struct radeon_winsys_bo
*gsvs_ring_bo
,
1988 uint32_t tess_factor_ring_size
,
1989 uint32_t tess_offchip_ring_offset
,
1990 uint32_t tess_offchip_ring_size
,
1991 struct radeon_winsys_bo
*tess_rings_bo
)
1993 uint32_t *desc
= &map
[4];
1996 uint64_t esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1998 /* stride 0, num records - size, add tid, swizzle, elsize4,
2001 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
2002 S_008F04_STRIDE(0) |
2003 S_008F04_SWIZZLE_ENABLE(true);
2004 desc
[2] = esgs_ring_size
;
2005 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2006 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2007 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2008 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2009 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2010 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2011 S_008F0C_ELEMENT_SIZE(1) |
2012 S_008F0C_INDEX_STRIDE(3) |
2013 S_008F0C_ADD_TID_ENABLE(true);
2015 /* GS entry for ES->GS ring */
2016 /* stride 0, num records - size, elsize0,
2019 desc
[5] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
2020 S_008F04_STRIDE(0) |
2021 S_008F04_SWIZZLE_ENABLE(false);
2022 desc
[6] = esgs_ring_size
;
2023 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2024 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2025 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2026 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2027 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2028 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2029 S_008F0C_ELEMENT_SIZE(0) |
2030 S_008F0C_INDEX_STRIDE(0) |
2031 S_008F0C_ADD_TID_ENABLE(false);
2037 uint64_t gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
2039 /* VS entry for GS->VS ring */
2040 /* stride 0, num records - size, elsize0,
2043 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2044 S_008F04_STRIDE(0) |
2045 S_008F04_SWIZZLE_ENABLE(false);
2046 desc
[2] = gsvs_ring_size
;
2047 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2048 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2049 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2050 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2051 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2052 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2053 S_008F0C_ELEMENT_SIZE(0) |
2054 S_008F0C_INDEX_STRIDE(0) |
2055 S_008F0C_ADD_TID_ENABLE(false);
2057 /* stride gsvs_itemsize, num records 64
2058 elsize 4, index stride 16 */
2059 /* shader will patch stride and desc[2] */
2061 desc
[5] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
2062 S_008F04_STRIDE(0) |
2063 S_008F04_SWIZZLE_ENABLE(true);
2065 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2066 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2067 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2068 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2069 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2070 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2071 S_008F0C_ELEMENT_SIZE(1) |
2072 S_008F0C_INDEX_STRIDE(1) |
2073 S_008F0C_ADD_TID_ENABLE(true);
2078 if (tess_rings_bo
) {
2079 uint64_t tess_va
= radv_buffer_get_va(tess_rings_bo
);
2080 uint64_t tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
2083 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
2084 S_008F04_STRIDE(0) |
2085 S_008F04_SWIZZLE_ENABLE(false);
2086 desc
[2] = tess_factor_ring_size
;
2087 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2088 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2089 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2090 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2091 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2092 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2093 S_008F0C_ELEMENT_SIZE(0) |
2094 S_008F0C_INDEX_STRIDE(0) |
2095 S_008F0C_ADD_TID_ENABLE(false);
2097 desc
[4] = tess_offchip_va
;
2098 desc
[5] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
2099 S_008F04_STRIDE(0) |
2100 S_008F04_SWIZZLE_ENABLE(false);
2101 desc
[6] = tess_offchip_ring_size
;
2102 desc
[7] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
2103 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
2104 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
2105 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
2106 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
2107 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
2108 S_008F0C_ELEMENT_SIZE(0) |
2109 S_008F0C_INDEX_STRIDE(0) |
2110 S_008F0C_ADD_TID_ENABLE(false);
2115 if (add_sample_positions
) {
2116 /* add sample positions after all rings */
2117 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
2119 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
2121 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
2123 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
2128 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
2130 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
2131 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
2132 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
2133 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
2134 unsigned max_offchip_buffers
;
2135 unsigned offchip_granularity
;
2136 unsigned hs_offchip_param
;
2140 * This must be one less than the maximum number due to a hw limitation.
2141 * Various hardware bugs in SI, CIK, and GFX9 need this.
2144 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
2145 * Gfx7 should limit max_offchip_buffers to 508
2146 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
2148 * Follow AMDVLK here.
2150 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
2151 device
->physical_device
->rad_info
.chip_class
== CIK
||
2152 device
->physical_device
->rad_info
.chip_class
== SI
)
2153 --max_offchip_buffers_per_se
;
2155 max_offchip_buffers
= max_offchip_buffers_per_se
*
2156 device
->physical_device
->rad_info
.max_se
;
2158 /* Hawaii has a bug with offchip buffers > 256 that can be worked
2159 * around by setting 4K granularity.
2161 if (device
->tess_offchip_block_dw_size
== 4096) {
2162 assert(device
->physical_device
->rad_info
.family
== CHIP_HAWAII
);
2163 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2165 assert(device
->tess_offchip_block_dw_size
== 8192);
2166 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2169 switch (device
->physical_device
->rad_info
.chip_class
) {
2171 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2177 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2181 *max_offchip_buffers_p
= max_offchip_buffers
;
2182 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2183 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
2184 --max_offchip_buffers
;
2186 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2187 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2190 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2192 return hs_offchip_param
;
2196 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2197 struct radeon_winsys_bo
*esgs_ring_bo
,
2198 uint32_t esgs_ring_size
,
2199 struct radeon_winsys_bo
*gsvs_ring_bo
,
2200 uint32_t gsvs_ring_size
)
2202 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2206 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2209 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2211 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2212 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2213 radeon_emit(cs
, esgs_ring_size
>> 8);
2214 radeon_emit(cs
, gsvs_ring_size
>> 8);
2216 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2217 radeon_emit(cs
, esgs_ring_size
>> 8);
2218 radeon_emit(cs
, gsvs_ring_size
>> 8);
2223 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2224 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2225 struct radeon_winsys_bo
*tess_rings_bo
)
2232 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2234 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2236 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2237 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2238 S_030938_SIZE(tf_ring_size
/ 4));
2239 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2241 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2242 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2243 S_030944_BASE_HI(tf_va
>> 40));
2245 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2248 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2249 S_008988_SIZE(tf_ring_size
/ 4));
2250 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2252 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2258 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2259 struct radeon_winsys_bo
*compute_scratch_bo
)
2261 uint64_t scratch_va
;
2263 if (!compute_scratch_bo
)
2266 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2268 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2270 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2271 radeon_emit(cs
, scratch_va
);
2272 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2273 S_008F04_SWIZZLE_ENABLE(1));
2277 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2278 struct radeon_cmdbuf
*cs
,
2279 struct radeon_winsys_bo
*descriptor_bo
)
2286 va
= radv_buffer_get_va(descriptor_bo
);
2288 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2290 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2291 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2292 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2293 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2294 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2296 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2297 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2301 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2302 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2303 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2304 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2305 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2306 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2308 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2309 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2316 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2318 struct radv_device
*device
= queue
->device
;
2320 if (device
->gfx_init
) {
2321 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2323 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2324 radeon_emit(cs
, va
);
2325 radeon_emit(cs
, va
>> 32);
2326 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2328 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2330 struct radv_physical_device
*physical_device
= device
->physical_device
;
2331 si_emit_graphics(physical_device
, cs
);
2336 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2338 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2339 si_emit_compute(physical_device
, cs
);
2343 radv_get_preamble_cs(struct radv_queue
*queue
,
2344 uint32_t scratch_size
,
2345 uint32_t compute_scratch_size
,
2346 uint32_t esgs_ring_size
,
2347 uint32_t gsvs_ring_size
,
2348 bool needs_tess_rings
,
2349 bool needs_sample_positions
,
2350 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2351 struct radeon_cmdbuf
**initial_preamble_cs
,
2352 struct radeon_cmdbuf
**continue_preamble_cs
)
2354 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2355 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2356 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2357 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2358 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2359 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2360 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2361 bool add_tess_rings
= false, add_sample_positions
= false;
2362 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2363 unsigned max_offchip_buffers
;
2364 unsigned hs_offchip_param
= 0;
2365 unsigned tess_offchip_ring_offset
;
2366 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2367 if (!queue
->has_tess_rings
) {
2368 if (needs_tess_rings
)
2369 add_tess_rings
= true;
2371 if (!queue
->has_sample_positions
) {
2372 if (needs_sample_positions
)
2373 add_sample_positions
= true;
2375 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2376 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2377 &max_offchip_buffers
);
2378 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2379 tess_offchip_ring_size
= max_offchip_buffers
*
2380 queue
->device
->tess_offchip_block_dw_size
* 4;
2382 if (scratch_size
<= queue
->scratch_size
&&
2383 compute_scratch_size
<= queue
->compute_scratch_size
&&
2384 esgs_ring_size
<= queue
->esgs_ring_size
&&
2385 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2386 !add_tess_rings
&& !add_sample_positions
&&
2387 queue
->initial_preamble_cs
) {
2388 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2389 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2390 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2391 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2392 *continue_preamble_cs
= NULL
;
2396 if (scratch_size
> queue
->scratch_size
) {
2397 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2402 RADV_BO_PRIORITY_SCRATCH
);
2406 scratch_bo
= queue
->scratch_bo
;
2408 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2409 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2410 compute_scratch_size
,
2414 RADV_BO_PRIORITY_SCRATCH
);
2415 if (!compute_scratch_bo
)
2419 compute_scratch_bo
= queue
->compute_scratch_bo
;
2421 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2422 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2427 RADV_BO_PRIORITY_SCRATCH
);
2431 esgs_ring_bo
= queue
->esgs_ring_bo
;
2432 esgs_ring_size
= queue
->esgs_ring_size
;
2435 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2436 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2441 RADV_BO_PRIORITY_SCRATCH
);
2445 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2446 gsvs_ring_size
= queue
->gsvs_ring_size
;
2449 if (add_tess_rings
) {
2450 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2451 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2455 RADV_BO_PRIORITY_SCRATCH
);
2459 tess_rings_bo
= queue
->tess_rings_bo
;
2462 if (scratch_bo
!= queue
->scratch_bo
||
2463 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2464 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2465 tess_rings_bo
!= queue
->tess_rings_bo
||
2466 add_sample_positions
) {
2468 if (gsvs_ring_bo
|| esgs_ring_bo
||
2469 tess_rings_bo
|| add_sample_positions
) {
2470 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2471 if (add_sample_positions
)
2472 size
+= 128; /* 64+32+16+8 = 120 bytes */
2474 else if (scratch_bo
)
2475 size
= 8; /* 2 dword */
2477 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2481 RADEON_FLAG_CPU_ACCESS
|
2482 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2483 RADEON_FLAG_READ_ONLY
,
2484 RADV_BO_PRIORITY_DESCRIPTOR
);
2488 descriptor_bo
= queue
->descriptor_bo
;
2490 if (descriptor_bo
!= queue
->descriptor_bo
) {
2491 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2494 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2495 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2496 S_008F04_SWIZZLE_ENABLE(1);
2497 map
[0] = scratch_va
;
2501 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
|| add_sample_positions
)
2502 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2503 esgs_ring_size
, esgs_ring_bo
,
2504 gsvs_ring_size
, gsvs_ring_bo
,
2505 tess_factor_ring_size
,
2506 tess_offchip_ring_offset
,
2507 tess_offchip_ring_size
,
2510 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2513 for(int i
= 0; i
< 3; ++i
) {
2514 struct radeon_cmdbuf
*cs
= NULL
;
2515 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2516 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2523 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2525 /* Emit initial configuration. */
2526 switch (queue
->queue_family_index
) {
2527 case RADV_QUEUE_GENERAL
:
2528 radv_init_graphics_state(cs
, queue
);
2530 case RADV_QUEUE_COMPUTE
:
2531 radv_init_compute_state(cs
, queue
);
2533 case RADV_QUEUE_TRANSFER
:
2537 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2538 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2539 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2540 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2541 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2544 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2545 gsvs_ring_bo
, gsvs_ring_size
);
2546 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2547 tess_factor_ring_size
, tess_rings_bo
);
2548 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2549 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2552 si_cs_emit_cache_flush(cs
,
2553 queue
->device
->physical_device
->rad_info
.chip_class
,
2555 queue
->queue_family_index
== RING_COMPUTE
&&
2556 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2557 (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
)) |
2558 RADV_CMD_FLAG_INV_ICACHE
|
2559 RADV_CMD_FLAG_INV_SMEM_L1
|
2560 RADV_CMD_FLAG_INV_VMEM_L1
|
2561 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2562 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2563 } else if (i
== 1) {
2564 si_cs_emit_cache_flush(cs
,
2565 queue
->device
->physical_device
->rad_info
.chip_class
,
2567 queue
->queue_family_index
== RING_COMPUTE
&&
2568 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2569 RADV_CMD_FLAG_INV_ICACHE
|
2570 RADV_CMD_FLAG_INV_SMEM_L1
|
2571 RADV_CMD_FLAG_INV_VMEM_L1
|
2572 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2573 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2576 if (!queue
->device
->ws
->cs_finalize(cs
))
2580 if (queue
->initial_full_flush_preamble_cs
)
2581 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2583 if (queue
->initial_preamble_cs
)
2584 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2586 if (queue
->continue_preamble_cs
)
2587 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2589 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2590 queue
->initial_preamble_cs
= dest_cs
[1];
2591 queue
->continue_preamble_cs
= dest_cs
[2];
2593 if (scratch_bo
!= queue
->scratch_bo
) {
2594 if (queue
->scratch_bo
)
2595 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2596 queue
->scratch_bo
= scratch_bo
;
2597 queue
->scratch_size
= scratch_size
;
2600 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2601 if (queue
->compute_scratch_bo
)
2602 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2603 queue
->compute_scratch_bo
= compute_scratch_bo
;
2604 queue
->compute_scratch_size
= compute_scratch_size
;
2607 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2608 if (queue
->esgs_ring_bo
)
2609 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2610 queue
->esgs_ring_bo
= esgs_ring_bo
;
2611 queue
->esgs_ring_size
= esgs_ring_size
;
2614 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2615 if (queue
->gsvs_ring_bo
)
2616 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2617 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2618 queue
->gsvs_ring_size
= gsvs_ring_size
;
2621 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2622 queue
->tess_rings_bo
= tess_rings_bo
;
2623 queue
->has_tess_rings
= true;
2626 if (descriptor_bo
!= queue
->descriptor_bo
) {
2627 if (queue
->descriptor_bo
)
2628 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2630 queue
->descriptor_bo
= descriptor_bo
;
2633 if (add_sample_positions
)
2634 queue
->has_sample_positions
= true;
2636 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2637 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2638 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2639 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2640 *continue_preamble_cs
= NULL
;
2643 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2645 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2646 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2647 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2648 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2649 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2650 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2651 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2652 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2653 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2654 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2655 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2656 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2657 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2658 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2661 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2662 struct radv_winsys_sem_counts
*counts
,
2664 const VkSemaphore
*sems
,
2668 int syncobj_idx
= 0, sem_idx
= 0;
2670 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2673 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2674 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2676 if (sem
->temp_syncobj
|| sem
->syncobj
)
2677 counts
->syncobj_count
++;
2679 counts
->sem_count
++;
2682 if (_fence
!= VK_NULL_HANDLE
) {
2683 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2684 if (fence
->temp_syncobj
|| fence
->syncobj
)
2685 counts
->syncobj_count
++;
2688 if (counts
->syncobj_count
) {
2689 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2690 if (!counts
->syncobj
)
2691 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2694 if (counts
->sem_count
) {
2695 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2697 free(counts
->syncobj
);
2698 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2702 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2703 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2705 if (sem
->temp_syncobj
) {
2706 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2708 else if (sem
->syncobj
)
2709 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2712 counts
->sem
[sem_idx
++] = sem
->sem
;
2716 if (_fence
!= VK_NULL_HANDLE
) {
2717 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2718 if (fence
->temp_syncobj
)
2719 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2720 else if (fence
->syncobj
)
2721 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2728 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2730 free(sem_info
->wait
.syncobj
);
2731 free(sem_info
->wait
.sem
);
2732 free(sem_info
->signal
.syncobj
);
2733 free(sem_info
->signal
.sem
);
2737 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2739 const VkSemaphore
*sems
)
2741 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2742 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2744 if (sem
->temp_syncobj
) {
2745 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2746 sem
->temp_syncobj
= 0;
2752 radv_alloc_sem_info(struct radv_instance
*instance
,
2753 struct radv_winsys_sem_info
*sem_info
,
2755 const VkSemaphore
*wait_sems
,
2756 int num_signal_sems
,
2757 const VkSemaphore
*signal_sems
,
2761 memset(sem_info
, 0, sizeof(*sem_info
));
2763 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2766 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2768 radv_free_sem_info(sem_info
);
2770 /* caller can override these */
2771 sem_info
->cs_emit_wait
= true;
2772 sem_info
->cs_emit_signal
= true;
2776 /* Signals fence as soon as all the work currently put on queue is done. */
2777 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2778 struct radv_fence
*fence
)
2782 struct radv_winsys_sem_info sem_info
;
2784 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2785 radv_fence_to_handle(fence
));
2786 if (result
!= VK_SUCCESS
)
2789 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2790 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2791 1, NULL
, NULL
, &sem_info
, NULL
,
2792 false, fence
->fence
);
2793 radv_free_sem_info(&sem_info
);
2796 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2801 VkResult
radv_QueueSubmit(
2803 uint32_t submitCount
,
2804 const VkSubmitInfo
* pSubmits
,
2807 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2808 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2809 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2810 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2812 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2813 uint32_t scratch_size
= 0;
2814 uint32_t compute_scratch_size
= 0;
2815 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2816 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2818 bool fence_emitted
= false;
2819 bool tess_rings_needed
= false;
2820 bool sample_positions_needed
= false;
2822 /* Do this first so failing to allocate scratch buffers can't result in
2823 * partially executed submissions. */
2824 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2825 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2826 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2827 pSubmits
[i
].pCommandBuffers
[j
]);
2829 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2830 compute_scratch_size
= MAX2(compute_scratch_size
,
2831 cmd_buffer
->compute_scratch_size_needed
);
2832 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2833 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2834 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2835 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2839 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2840 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2841 sample_positions_needed
, &initial_flush_preamble_cs
,
2842 &initial_preamble_cs
, &continue_preamble_cs
);
2843 if (result
!= VK_SUCCESS
)
2846 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2847 struct radeon_cmdbuf
**cs_array
;
2848 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2849 bool can_patch
= true;
2851 struct radv_winsys_sem_info sem_info
;
2853 result
= radv_alloc_sem_info(queue
->device
->instance
,
2855 pSubmits
[i
].waitSemaphoreCount
,
2856 pSubmits
[i
].pWaitSemaphores
,
2857 pSubmits
[i
].signalSemaphoreCount
,
2858 pSubmits
[i
].pSignalSemaphores
,
2860 if (result
!= VK_SUCCESS
)
2863 if (!pSubmits
[i
].commandBufferCount
) {
2864 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2865 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2866 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2871 radv_loge("failed to submit CS %d\n", i
);
2874 fence_emitted
= true;
2876 radv_free_sem_info(&sem_info
);
2880 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2881 (pSubmits
[i
].commandBufferCount
));
2883 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2884 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2885 pSubmits
[i
].pCommandBuffers
[j
]);
2886 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2888 cs_array
[j
] = cmd_buffer
->cs
;
2889 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2892 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2895 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2896 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2897 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2899 advance
= MIN2(max_cs_submission
,
2900 pSubmits
[i
].commandBufferCount
- j
);
2902 if (queue
->device
->trace_bo
)
2903 *queue
->device
->trace_id_ptr
= 0;
2905 sem_info
.cs_emit_wait
= j
== 0;
2906 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2908 if (unlikely(queue
->device
->use_global_bo_list
)) {
2909 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2910 bo_list
= &queue
->device
->bo_list
.list
;
2913 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2914 advance
, initial_preamble
, continue_preamble_cs
,
2916 can_patch
, base_fence
);
2918 if (unlikely(queue
->device
->use_global_bo_list
))
2919 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2922 radv_loge("failed to submit CS %d\n", i
);
2925 fence_emitted
= true;
2926 if (queue
->device
->trace_bo
) {
2927 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2931 radv_free_temp_syncobjs(queue
->device
,
2932 pSubmits
[i
].waitSemaphoreCount
,
2933 pSubmits
[i
].pWaitSemaphores
);
2934 radv_free_sem_info(&sem_info
);
2939 if (!fence_emitted
) {
2940 result
= radv_signal_fence(queue
, fence
);
2941 if (result
!= VK_SUCCESS
)
2944 fence
->submitted
= true;
2950 VkResult
radv_QueueWaitIdle(
2953 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2955 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2956 radv_queue_family_to_ring(queue
->queue_family_index
),
2961 VkResult
radv_DeviceWaitIdle(
2964 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2966 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2967 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2968 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2974 VkResult
radv_EnumerateInstanceExtensionProperties(
2975 const char* pLayerName
,
2976 uint32_t* pPropertyCount
,
2977 VkExtensionProperties
* pProperties
)
2979 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2981 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2982 if (radv_supported_instance_extensions
.extensions
[i
]) {
2983 vk_outarray_append(&out
, prop
) {
2984 *prop
= radv_instance_extensions
[i
];
2989 return vk_outarray_status(&out
);
2992 VkResult
radv_EnumerateDeviceExtensionProperties(
2993 VkPhysicalDevice physicalDevice
,
2994 const char* pLayerName
,
2995 uint32_t* pPropertyCount
,
2996 VkExtensionProperties
* pProperties
)
2998 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2999 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
3001 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
3002 if (device
->supported_extensions
.extensions
[i
]) {
3003 vk_outarray_append(&out
, prop
) {
3004 *prop
= radv_device_extensions
[i
];
3009 return vk_outarray_status(&out
);
3012 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
3013 VkInstance _instance
,
3016 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
3018 return radv_lookup_entrypoint_checked(pName
,
3019 instance
? instance
->apiVersion
: 0,
3020 instance
? &instance
->enabled_extensions
: NULL
,
3024 /* The loader wants us to expose a second GetInstanceProcAddr function
3025 * to work around certain LD_PRELOAD issues seen in apps.
3028 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3029 VkInstance instance
,
3033 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
3034 VkInstance instance
,
3037 return radv_GetInstanceProcAddr(instance
, pName
);
3040 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
3044 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3046 return radv_lookup_entrypoint_checked(pName
,
3047 device
->instance
->apiVersion
,
3048 &device
->instance
->enabled_extensions
,
3049 &device
->enabled_extensions
);
3052 bool radv_get_memory_fd(struct radv_device
*device
,
3053 struct radv_device_memory
*memory
,
3056 struct radeon_bo_metadata metadata
;
3058 if (memory
->image
) {
3059 radv_init_metadata(device
, memory
->image
, &metadata
);
3060 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
3063 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
3067 static VkResult
radv_alloc_memory(struct radv_device
*device
,
3068 const VkMemoryAllocateInfo
* pAllocateInfo
,
3069 const VkAllocationCallbacks
* pAllocator
,
3070 VkDeviceMemory
* pMem
)
3072 struct radv_device_memory
*mem
;
3074 enum radeon_bo_domain domain
;
3076 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
3078 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
3080 if (pAllocateInfo
->allocationSize
== 0) {
3081 /* Apparently, this is allowed */
3082 *pMem
= VK_NULL_HANDLE
;
3086 const VkImportMemoryFdInfoKHR
*import_info
=
3087 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
3088 const VkMemoryDedicatedAllocateInfo
*dedicate_info
=
3089 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO
);
3090 const VkExportMemoryAllocateInfo
*export_info
=
3091 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO
);
3092 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
3093 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
3095 const struct wsi_memory_allocate_info
*wsi_info
=
3096 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
3098 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
3099 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3101 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3103 if (wsi_info
&& wsi_info
->implicit_sync
)
3104 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
3106 if (dedicate_info
) {
3107 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
3108 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
3114 float priority_float
= 0.5;
3115 const struct VkMemoryPriorityAllocateInfoEXT
*priority_ext
=
3116 vk_find_struct_const(pAllocateInfo
->pNext
,
3117 MEMORY_PRIORITY_ALLOCATE_INFO_EXT
);
3119 priority_float
= priority_ext
->priority
;
3121 unsigned priority
= MIN2(RADV_BO_PRIORITY_APPLICATION_MAX
- 1,
3122 (int)(priority_float
* RADV_BO_PRIORITY_APPLICATION_MAX
));
3124 mem
->user_ptr
= NULL
;
3127 assert(import_info
->handleType
==
3128 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
3129 import_info
->handleType
==
3130 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3131 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
3132 priority
, NULL
, NULL
);
3134 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3137 close(import_info
->fd
);
3139 } else if (host_ptr_info
) {
3140 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
3141 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
3142 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
3143 pAllocateInfo
->allocationSize
,
3146 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE
;
3149 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
3152 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
3153 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
3154 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
3155 domain
= RADEON_DOMAIN_GTT
;
3157 domain
= RADEON_DOMAIN_VRAM
;
3159 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
3160 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
3162 flags
|= RADEON_FLAG_CPU_ACCESS
;
3164 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
3165 flags
|= RADEON_FLAG_GTT_WC
;
3167 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
3168 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3170 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3171 domain
, flags
, priority
);
3174 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3177 mem
->type_index
= mem_type_index
;
3180 result
= radv_bo_list_add(device
, mem
->bo
);
3181 if (result
!= VK_SUCCESS
)
3184 *pMem
= radv_device_memory_to_handle(mem
);
3189 device
->ws
->buffer_destroy(mem
->bo
);
3191 vk_free2(&device
->alloc
, pAllocator
, mem
);
3196 VkResult
radv_AllocateMemory(
3198 const VkMemoryAllocateInfo
* pAllocateInfo
,
3199 const VkAllocationCallbacks
* pAllocator
,
3200 VkDeviceMemory
* pMem
)
3202 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3203 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3206 void radv_FreeMemory(
3208 VkDeviceMemory _mem
,
3209 const VkAllocationCallbacks
* pAllocator
)
3211 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3212 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3217 radv_bo_list_remove(device
, mem
->bo
);
3218 device
->ws
->buffer_destroy(mem
->bo
);
3221 vk_free2(&device
->alloc
, pAllocator
, mem
);
3224 VkResult
radv_MapMemory(
3226 VkDeviceMemory _memory
,
3227 VkDeviceSize offset
,
3229 VkMemoryMapFlags flags
,
3232 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3233 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3241 *ppData
= mem
->user_ptr
;
3243 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3250 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3253 void radv_UnmapMemory(
3255 VkDeviceMemory _memory
)
3257 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3258 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3263 if (mem
->user_ptr
== NULL
)
3264 device
->ws
->buffer_unmap(mem
->bo
);
3267 VkResult
radv_FlushMappedMemoryRanges(
3269 uint32_t memoryRangeCount
,
3270 const VkMappedMemoryRange
* pMemoryRanges
)
3275 VkResult
radv_InvalidateMappedMemoryRanges(
3277 uint32_t memoryRangeCount
,
3278 const VkMappedMemoryRange
* pMemoryRanges
)
3283 void radv_GetBufferMemoryRequirements(
3286 VkMemoryRequirements
* pMemoryRequirements
)
3288 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3289 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3291 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3293 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3294 pMemoryRequirements
->alignment
= 4096;
3296 pMemoryRequirements
->alignment
= 16;
3298 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3301 void radv_GetBufferMemoryRequirements2(
3303 const VkBufferMemoryRequirementsInfo2
*pInfo
,
3304 VkMemoryRequirements2
*pMemoryRequirements
)
3306 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3307 &pMemoryRequirements
->memoryRequirements
);
3308 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3309 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3310 switch (ext
->sType
) {
3311 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3312 VkMemoryDedicatedRequirements
*req
=
3313 (VkMemoryDedicatedRequirements
*) ext
;
3314 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3315 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3324 void radv_GetImageMemoryRequirements(
3327 VkMemoryRequirements
* pMemoryRequirements
)
3329 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3330 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3332 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3334 pMemoryRequirements
->size
= image
->size
;
3335 pMemoryRequirements
->alignment
= image
->alignment
;
3338 void radv_GetImageMemoryRequirements2(
3340 const VkImageMemoryRequirementsInfo2
*pInfo
,
3341 VkMemoryRequirements2
*pMemoryRequirements
)
3343 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3344 &pMemoryRequirements
->memoryRequirements
);
3346 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3348 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3349 switch (ext
->sType
) {
3350 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS
: {
3351 VkMemoryDedicatedRequirements
*req
=
3352 (VkMemoryDedicatedRequirements
*) ext
;
3353 req
->requiresDedicatedAllocation
= image
->shareable
;
3354 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3363 void radv_GetImageSparseMemoryRequirements(
3366 uint32_t* pSparseMemoryRequirementCount
,
3367 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3372 void radv_GetImageSparseMemoryRequirements2(
3374 const VkImageSparseMemoryRequirementsInfo2
*pInfo
,
3375 uint32_t* pSparseMemoryRequirementCount
,
3376 VkSparseImageMemoryRequirements2
*pSparseMemoryRequirements
)
3381 void radv_GetDeviceMemoryCommitment(
3383 VkDeviceMemory memory
,
3384 VkDeviceSize
* pCommittedMemoryInBytes
)
3386 *pCommittedMemoryInBytes
= 0;
3389 VkResult
radv_BindBufferMemory2(VkDevice device
,
3390 uint32_t bindInfoCount
,
3391 const VkBindBufferMemoryInfo
*pBindInfos
)
3393 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3394 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3395 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3398 buffer
->bo
= mem
->bo
;
3399 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3407 VkResult
radv_BindBufferMemory(
3410 VkDeviceMemory memory
,
3411 VkDeviceSize memoryOffset
)
3413 const VkBindBufferMemoryInfo info
= {
3414 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3417 .memoryOffset
= memoryOffset
3420 return radv_BindBufferMemory2(device
, 1, &info
);
3423 VkResult
radv_BindImageMemory2(VkDevice device
,
3424 uint32_t bindInfoCount
,
3425 const VkBindImageMemoryInfo
*pBindInfos
)
3427 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3428 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3429 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3432 image
->bo
= mem
->bo
;
3433 image
->offset
= pBindInfos
[i
].memoryOffset
;
3443 VkResult
radv_BindImageMemory(
3446 VkDeviceMemory memory
,
3447 VkDeviceSize memoryOffset
)
3449 const VkBindImageMemoryInfo info
= {
3450 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO
,
3453 .memoryOffset
= memoryOffset
3456 return radv_BindImageMemory2(device
, 1, &info
);
3461 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3462 const VkSparseBufferMemoryBindInfo
*bind
)
3464 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3466 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3467 struct radv_device_memory
*mem
= NULL
;
3469 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3470 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3472 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3473 bind
->pBinds
[i
].resourceOffset
,
3474 bind
->pBinds
[i
].size
,
3475 mem
? mem
->bo
: NULL
,
3476 bind
->pBinds
[i
].memoryOffset
);
3481 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3482 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3484 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3486 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3487 struct radv_device_memory
*mem
= NULL
;
3489 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3490 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3492 device
->ws
->buffer_virtual_bind(image
->bo
,
3493 bind
->pBinds
[i
].resourceOffset
,
3494 bind
->pBinds
[i
].size
,
3495 mem
? mem
->bo
: NULL
,
3496 bind
->pBinds
[i
].memoryOffset
);
3500 VkResult
radv_QueueBindSparse(
3502 uint32_t bindInfoCount
,
3503 const VkBindSparseInfo
* pBindInfo
,
3506 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3507 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3508 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3509 bool fence_emitted
= false;
3513 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3514 struct radv_winsys_sem_info sem_info
;
3515 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3516 radv_sparse_buffer_bind_memory(queue
->device
,
3517 pBindInfo
[i
].pBufferBinds
+ j
);
3520 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3521 radv_sparse_image_opaque_bind_memory(queue
->device
,
3522 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3526 result
= radv_alloc_sem_info(queue
->device
->instance
,
3528 pBindInfo
[i
].waitSemaphoreCount
,
3529 pBindInfo
[i
].pWaitSemaphores
,
3530 pBindInfo
[i
].signalSemaphoreCount
,
3531 pBindInfo
[i
].pSignalSemaphores
,
3533 if (result
!= VK_SUCCESS
)
3536 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3537 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3538 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3543 radv_loge("failed to submit CS %d\n", i
);
3547 fence_emitted
= true;
3549 fence
->submitted
= true;
3552 radv_free_sem_info(&sem_info
);
3557 if (!fence_emitted
) {
3558 result
= radv_signal_fence(queue
, fence
);
3559 if (result
!= VK_SUCCESS
)
3562 fence
->submitted
= true;
3568 VkResult
radv_CreateFence(
3570 const VkFenceCreateInfo
* pCreateInfo
,
3571 const VkAllocationCallbacks
* pAllocator
,
3574 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3575 const VkExportFenceCreateInfo
*export
=
3576 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO
);
3577 VkExternalFenceHandleTypeFlags handleTypes
=
3578 export
? export
->handleTypes
: 0;
3580 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3582 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3585 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3587 fence
->fence_wsi
= NULL
;
3588 fence
->submitted
= false;
3589 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3590 fence
->temp_syncobj
= 0;
3591 if (device
->always_use_syncobj
|| handleTypes
) {
3592 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3594 vk_free2(&device
->alloc
, pAllocator
, fence
);
3595 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3597 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3598 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3600 fence
->fence
= NULL
;
3602 fence
->fence
= device
->ws
->create_fence();
3603 if (!fence
->fence
) {
3604 vk_free2(&device
->alloc
, pAllocator
, fence
);
3605 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3610 *pFence
= radv_fence_to_handle(fence
);
3615 void radv_DestroyFence(
3618 const VkAllocationCallbacks
* pAllocator
)
3620 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3621 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3626 if (fence
->temp_syncobj
)
3627 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3629 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3631 device
->ws
->destroy_fence(fence
->fence
);
3632 if (fence
->fence_wsi
)
3633 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3634 vk_free2(&device
->alloc
, pAllocator
, fence
);
3638 static uint64_t radv_get_current_time()
3641 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3642 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3645 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3647 uint64_t current_time
= radv_get_current_time();
3649 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3651 return current_time
+ timeout
;
3655 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3657 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3658 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3659 if (fence
->fence
== NULL
|| fence
->syncobj
||
3660 fence
->temp_syncobj
||
3661 (!fence
->signalled
&& !fence
->submitted
))
3667 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3669 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3670 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3671 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3677 VkResult
radv_WaitForFences(
3679 uint32_t fenceCount
,
3680 const VkFence
* pFences
,
3684 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3685 timeout
= radv_get_absolute_timeout(timeout
);
3687 if (device
->always_use_syncobj
&&
3688 radv_all_fences_syncobj(fenceCount
, pFences
))
3690 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3692 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3694 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3695 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3696 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3699 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3702 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3705 if (!waitAll
&& fenceCount
> 1) {
3706 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3707 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3708 uint32_t wait_count
= 0;
3709 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3711 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3713 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3714 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3716 if (fence
->signalled
) {
3721 fences
[wait_count
++] = fence
->fence
;
3724 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3725 waitAll
, timeout
- radv_get_current_time());
3728 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3731 while(radv_get_current_time() <= timeout
) {
3732 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3733 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3740 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3741 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3742 bool expired
= false;
3744 if (fence
->temp_syncobj
) {
3745 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3750 if (fence
->syncobj
) {
3751 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3756 if (fence
->signalled
)
3760 if (!fence
->submitted
) {
3761 while(radv_get_current_time() <= timeout
&&
3765 if (!fence
->submitted
)
3768 /* Recheck as it may have been set by
3769 * submitting operations. */
3771 if (fence
->signalled
)
3775 expired
= device
->ws
->fence_wait(device
->ws
,
3782 if (fence
->fence_wsi
) {
3783 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3784 if (result
!= VK_SUCCESS
)
3788 fence
->signalled
= true;
3794 VkResult
radv_ResetFences(VkDevice _device
,
3795 uint32_t fenceCount
,
3796 const VkFence
*pFences
)
3798 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3800 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3801 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3802 fence
->submitted
= fence
->signalled
= false;
3804 /* Per spec, we first restore the permanent payload, and then reset, so
3805 * having a temp syncobj should not skip resetting the permanent syncobj. */
3806 if (fence
->temp_syncobj
) {
3807 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3808 fence
->temp_syncobj
= 0;
3811 if (fence
->syncobj
) {
3812 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3819 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3821 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3822 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3824 if (fence
->temp_syncobj
) {
3825 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3826 return success
? VK_SUCCESS
: VK_NOT_READY
;
3829 if (fence
->syncobj
) {
3830 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3831 return success
? VK_SUCCESS
: VK_NOT_READY
;
3834 if (fence
->signalled
)
3836 if (!fence
->submitted
)
3837 return VK_NOT_READY
;
3839 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3840 return VK_NOT_READY
;
3842 if (fence
->fence_wsi
) {
3843 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
3845 if (result
!= VK_SUCCESS
) {
3846 if (result
== VK_TIMEOUT
)
3847 return VK_NOT_READY
;
3855 // Queue semaphore functions
3857 VkResult
radv_CreateSemaphore(
3859 const VkSemaphoreCreateInfo
* pCreateInfo
,
3860 const VkAllocationCallbacks
* pAllocator
,
3861 VkSemaphore
* pSemaphore
)
3863 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3864 const VkExportSemaphoreCreateInfo
*export
=
3865 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO
);
3866 VkExternalSemaphoreHandleTypeFlags handleTypes
=
3867 export
? export
->handleTypes
: 0;
3869 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3871 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3873 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3875 sem
->temp_syncobj
= 0;
3876 /* create a syncobject if we are going to export this semaphore */
3877 if (device
->always_use_syncobj
|| handleTypes
) {
3878 assert (device
->physical_device
->rad_info
.has_syncobj
);
3879 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3881 vk_free2(&device
->alloc
, pAllocator
, sem
);
3882 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3886 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3888 vk_free2(&device
->alloc
, pAllocator
, sem
);
3889 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3894 *pSemaphore
= radv_semaphore_to_handle(sem
);
3898 void radv_DestroySemaphore(
3900 VkSemaphore _semaphore
,
3901 const VkAllocationCallbacks
* pAllocator
)
3903 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3904 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3909 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3911 device
->ws
->destroy_sem(sem
->sem
);
3912 vk_free2(&device
->alloc
, pAllocator
, sem
);
3915 VkResult
radv_CreateEvent(
3917 const VkEventCreateInfo
* pCreateInfo
,
3918 const VkAllocationCallbacks
* pAllocator
,
3921 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3922 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3924 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3927 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3929 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3931 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
,
3932 RADV_BO_PRIORITY_FENCE
);
3934 vk_free2(&device
->alloc
, pAllocator
, event
);
3935 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3938 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3940 *pEvent
= radv_event_to_handle(event
);
3945 void radv_DestroyEvent(
3948 const VkAllocationCallbacks
* pAllocator
)
3950 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3951 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3955 device
->ws
->buffer_destroy(event
->bo
);
3956 vk_free2(&device
->alloc
, pAllocator
, event
);
3959 VkResult
radv_GetEventStatus(
3963 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3965 if (*event
->map
== 1)
3966 return VK_EVENT_SET
;
3967 return VK_EVENT_RESET
;
3970 VkResult
radv_SetEvent(
3974 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3980 VkResult
radv_ResetEvent(
3984 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3990 VkResult
radv_CreateBuffer(
3992 const VkBufferCreateInfo
* pCreateInfo
,
3993 const VkAllocationCallbacks
* pAllocator
,
3996 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3997 struct radv_buffer
*buffer
;
3999 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
4001 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
4002 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4004 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4006 buffer
->size
= pCreateInfo
->size
;
4007 buffer
->usage
= pCreateInfo
->usage
;
4010 buffer
->flags
= pCreateInfo
->flags
;
4012 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
4013 EXTERNAL_MEMORY_BUFFER_CREATE_INFO
) != NULL
;
4015 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
4016 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
4017 align64(buffer
->size
, 4096),
4018 4096, 0, RADEON_FLAG_VIRTUAL
,
4019 RADV_BO_PRIORITY_VIRTUAL
);
4021 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4022 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4026 *pBuffer
= radv_buffer_to_handle(buffer
);
4031 void radv_DestroyBuffer(
4034 const VkAllocationCallbacks
* pAllocator
)
4036 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4037 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
4042 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
4043 device
->ws
->buffer_destroy(buffer
->bo
);
4045 vk_free2(&device
->alloc
, pAllocator
, buffer
);
4048 VkDeviceAddress
radv_GetBufferDeviceAddressEXT(
4050 const VkBufferDeviceAddressInfoEXT
* pInfo
)
4052 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
4053 return radv_buffer_get_va(buffer
->bo
) + buffer
->offset
;
4057 static inline unsigned
4058 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
4061 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4063 return image
->surface
.u
.legacy
.tiling_index
[level
];
4066 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
4068 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
4072 radv_init_dcc_control_reg(struct radv_device
*device
,
4073 struct radv_image_view
*iview
)
4075 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
4076 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
4077 unsigned max_compressed_block_size
;
4078 unsigned independent_64b_blocks
;
4080 if (!radv_image_has_dcc(iview
->image
))
4083 if (iview
->image
->info
.samples
> 1) {
4084 if (iview
->image
->surface
.bpe
== 1)
4085 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4086 else if (iview
->image
->surface
.bpe
== 2)
4087 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
4090 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
4091 /* amdvlk: [min-compressed-block-size] should be set to 32 for
4092 * dGPU and 64 for APU because all of our APUs to date use
4093 * DIMMs which have a request granularity size of 64B while all
4094 * other chips have a 32B request size.
4096 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
4099 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
4100 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
4101 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
4102 /* If this DCC image is potentially going to be used in texture
4103 * fetches, we need some special settings.
4105 independent_64b_blocks
= 1;
4106 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
4108 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
4109 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
4110 * big as possible for better compression state.
4112 independent_64b_blocks
= 0;
4113 max_compressed_block_size
= max_uncompressed_block_size
;
4116 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
4117 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
4118 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
4119 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
4123 radv_initialise_color_surface(struct radv_device
*device
,
4124 struct radv_color_buffer_info
*cb
,
4125 struct radv_image_view
*iview
)
4127 const struct vk_format_description
*desc
;
4128 unsigned ntype
, format
, swap
, endian
;
4129 unsigned blend_clamp
= 0, blend_bypass
= 0;
4131 const struct radeon_surf
*surf
= &iview
->image
->surface
;
4133 desc
= vk_format_description(iview
->vk_format
);
4135 memset(cb
, 0, sizeof(*cb
));
4137 /* Intensity is implemented as Red, so treat it that way. */
4138 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
4140 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4142 cb
->cb_color_base
= va
>> 8;
4144 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4145 struct gfx9_surf_meta_flags meta
;
4146 if (iview
->image
->dcc_offset
)
4147 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
4149 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
4151 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
4152 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
4153 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
4154 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
4156 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
4157 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
4159 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
4160 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
4162 cb
->cb_color_base
+= level_info
->offset
>> 8;
4163 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
4164 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
4166 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
4167 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
4168 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
4170 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
4171 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
4172 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
4174 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
4176 if (radv_image_has_fmask(iview
->image
)) {
4177 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4178 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
4179 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4180 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4182 /* This must be set for fast clear to work without FMASK. */
4183 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4184 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4185 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4186 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4190 /* CMASK variables */
4191 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4192 va
+= iview
->image
->cmask
.offset
;
4193 cb
->cb_color_cmask
= va
>> 8;
4195 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4196 va
+= iview
->image
->dcc_offset
;
4197 cb
->cb_dcc_base
= va
>> 8;
4198 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
4200 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4201 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4202 S_028C6C_SLICE_MAX(max_slice
);
4204 if (iview
->image
->info
.samples
> 1) {
4205 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4207 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4208 S_028C74_NUM_FRAGMENTS(log_samples
);
4211 if (radv_image_has_fmask(iview
->image
)) {
4212 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4213 cb
->cb_color_fmask
= va
>> 8;
4214 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4216 cb
->cb_color_fmask
= cb
->cb_color_base
;
4219 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4221 vk_format_get_first_non_void_channel(iview
->vk_format
));
4222 format
= radv_translate_colorformat(iview
->vk_format
);
4223 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4224 radv_finishme("Illegal color\n");
4225 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4226 endian
= radv_colorformat_endian_swap(format
);
4228 /* blend clamp should be set for all NORM/SRGB types */
4229 if (ntype
== V_028C70_NUMBER_UNORM
||
4230 ntype
== V_028C70_NUMBER_SNORM
||
4231 ntype
== V_028C70_NUMBER_SRGB
)
4234 /* set blend bypass according to docs if SINT/UINT or
4235 8/24 COLOR variants */
4236 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4237 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4238 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4243 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4244 (format
== V_028C70_COLOR_8
||
4245 format
== V_028C70_COLOR_8_8
||
4246 format
== V_028C70_COLOR_8_8_8_8
))
4247 ->color_is_int8
= true;
4249 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4250 S_028C70_COMP_SWAP(swap
) |
4251 S_028C70_BLEND_CLAMP(blend_clamp
) |
4252 S_028C70_BLEND_BYPASS(blend_bypass
) |
4253 S_028C70_SIMPLE_FLOAT(1) |
4254 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4255 ntype
!= V_028C70_NUMBER_SNORM
&&
4256 ntype
!= V_028C70_NUMBER_SRGB
&&
4257 format
!= V_028C70_COLOR_8_24
&&
4258 format
!= V_028C70_COLOR_24_8
) |
4259 S_028C70_NUMBER_TYPE(ntype
) |
4260 S_028C70_ENDIAN(endian
);
4261 if (radv_image_has_fmask(iview
->image
)) {
4262 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4263 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
4264 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4265 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4269 if (radv_image_has_cmask(iview
->image
) &&
4270 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4271 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4273 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4274 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4276 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4278 /* This must be set for fast clear to work without FMASK. */
4279 if (!radv_image_has_fmask(iview
->image
) &&
4280 device
->physical_device
->rad_info
.chip_class
== SI
) {
4281 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
4282 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4285 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4286 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4287 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4289 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
4290 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4291 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
4292 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
4293 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
4294 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4299 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4300 struct radv_image_view
*iview
)
4302 unsigned max_zplanes
= 0;
4304 assert(radv_image_is_tc_compat_htile(iview
->image
));
4306 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4307 /* Default value for 32-bit depth surfaces. */
4310 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4311 iview
->image
->info
.samples
> 1)
4314 max_zplanes
= max_zplanes
+ 1;
4316 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4317 /* Do not enable Z plane compression for 16-bit depth
4318 * surfaces because isn't supported on GFX8. Only
4319 * 32-bit depth surfaces are supported by the hardware.
4320 * This allows to maintain shader compatibility and to
4321 * reduce the number of depth decompressions.
4325 if (iview
->image
->info
.samples
<= 1)
4327 else if (iview
->image
->info
.samples
<= 4)
4338 radv_initialise_ds_surface(struct radv_device
*device
,
4339 struct radv_ds_buffer_info
*ds
,
4340 struct radv_image_view
*iview
)
4342 unsigned level
= iview
->base_mip
;
4343 unsigned format
, stencil_format
;
4344 uint64_t va
, s_offs
, z_offs
;
4345 bool stencil_only
= false;
4346 memset(ds
, 0, sizeof(*ds
));
4347 switch (iview
->image
->vk_format
) {
4348 case VK_FORMAT_D24_UNORM_S8_UINT
:
4349 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4350 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4351 ds
->offset_scale
= 2.0f
;
4353 case VK_FORMAT_D16_UNORM
:
4354 case VK_FORMAT_D16_UNORM_S8_UINT
:
4355 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4356 ds
->offset_scale
= 4.0f
;
4358 case VK_FORMAT_D32_SFLOAT
:
4359 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4360 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4361 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4362 ds
->offset_scale
= 1.0f
;
4364 case VK_FORMAT_S8_UINT
:
4365 stencil_only
= true;
4371 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4372 stencil_format
= iview
->image
->surface
.has_stencil
?
4373 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4375 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4376 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4377 S_028008_SLICE_MAX(max_slice
);
4379 ds
->db_htile_data_base
= 0;
4380 ds
->db_htile_surface
= 0;
4382 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4383 s_offs
= z_offs
= va
;
4385 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4386 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
4387 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
4389 ds
->db_z_info
= S_028038_FORMAT(format
) |
4390 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4391 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
4392 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4393 S_028038_ZRANGE_PRECISION(1);
4394 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4395 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
4397 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
4398 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
4399 ds
->db_depth_view
|= S_028008_MIPID(level
);
4401 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4402 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4404 if (radv_htile_enabled(iview
->image
, level
)) {
4405 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4407 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4408 unsigned max_zplanes
=
4409 radv_calc_decompress_on_z_planes(device
, iview
);
4411 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4412 S_028038_ITERATE_FLUSH(1);
4413 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4416 if (!iview
->image
->surface
.has_stencil
)
4417 /* Use all of the htile_buffer for depth if there's no stencil. */
4418 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4419 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4420 iview
->image
->htile_offset
;
4421 ds
->db_htile_data_base
= va
>> 8;
4422 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4423 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4424 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4427 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4430 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4432 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4433 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4435 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4436 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4437 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4439 if (iview
->image
->info
.samples
> 1)
4440 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4442 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4443 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4444 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4445 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4446 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4447 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4448 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4449 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4452 tile_mode
= stencil_tile_mode
;
4454 ds
->db_depth_info
|=
4455 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4456 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4457 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4458 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4459 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4460 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4461 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4462 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4464 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4465 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4466 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4467 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4469 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4472 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4473 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4474 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4476 if (radv_htile_enabled(iview
->image
, level
)) {
4477 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4479 if (!iview
->image
->surface
.has_stencil
&&
4480 !radv_image_is_tc_compat_htile(iview
->image
))
4481 /* Use all of the htile_buffer for depth if there's no stencil. */
4482 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4484 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4485 iview
->image
->htile_offset
;
4486 ds
->db_htile_data_base
= va
>> 8;
4487 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4489 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4490 unsigned max_zplanes
=
4491 radv_calc_decompress_on_z_planes(device
, iview
);
4493 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4494 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4499 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4500 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4503 VkResult
radv_CreateFramebuffer(
4505 const VkFramebufferCreateInfo
* pCreateInfo
,
4506 const VkAllocationCallbacks
* pAllocator
,
4507 VkFramebuffer
* pFramebuffer
)
4509 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4510 struct radv_framebuffer
*framebuffer
;
4512 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4514 size_t size
= sizeof(*framebuffer
) +
4515 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4516 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4517 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4518 if (framebuffer
== NULL
)
4519 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4521 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4522 framebuffer
->width
= pCreateInfo
->width
;
4523 framebuffer
->height
= pCreateInfo
->height
;
4524 framebuffer
->layers
= pCreateInfo
->layers
;
4525 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4526 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4527 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4528 framebuffer
->attachments
[i
].attachment
= iview
;
4529 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4530 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4531 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4532 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4534 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4535 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4536 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4539 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4543 void radv_DestroyFramebuffer(
4546 const VkAllocationCallbacks
* pAllocator
)
4548 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4549 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4553 vk_free2(&device
->alloc
, pAllocator
, fb
);
4556 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4558 switch (address_mode
) {
4559 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4560 return V_008F30_SQ_TEX_WRAP
;
4561 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4562 return V_008F30_SQ_TEX_MIRROR
;
4563 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4564 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4565 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4566 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4567 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4568 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4570 unreachable("illegal tex wrap mode");
4576 radv_tex_compare(VkCompareOp op
)
4579 case VK_COMPARE_OP_NEVER
:
4580 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4581 case VK_COMPARE_OP_LESS
:
4582 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4583 case VK_COMPARE_OP_EQUAL
:
4584 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4585 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4586 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4587 case VK_COMPARE_OP_GREATER
:
4588 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4589 case VK_COMPARE_OP_NOT_EQUAL
:
4590 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4591 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4592 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4593 case VK_COMPARE_OP_ALWAYS
:
4594 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4596 unreachable("illegal compare mode");
4602 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4605 case VK_FILTER_NEAREST
:
4606 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4607 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4608 case VK_FILTER_LINEAR
:
4609 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4610 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4611 case VK_FILTER_CUBIC_IMG
:
4613 fprintf(stderr
, "illegal texture filter");
4619 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4622 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4623 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4624 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4625 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4627 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4632 radv_tex_bordercolor(VkBorderColor bcolor
)
4635 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4636 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4637 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4638 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4639 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4640 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4641 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4642 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4643 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4651 radv_tex_aniso_filter(unsigned filter
)
4665 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4668 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4669 return V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4670 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4671 return V_008F30_SQ_IMG_FILTER_MODE_MIN
;
4672 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4673 return V_008F30_SQ_IMG_FILTER_MODE_MAX
;
4681 radv_get_max_anisotropy(struct radv_device
*device
,
4682 const VkSamplerCreateInfo
*pCreateInfo
)
4684 if (device
->force_aniso
>= 0)
4685 return device
->force_aniso
;
4687 if (pCreateInfo
->anisotropyEnable
&&
4688 pCreateInfo
->maxAnisotropy
> 1.0f
)
4689 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4695 radv_init_sampler(struct radv_device
*device
,
4696 struct radv_sampler
*sampler
,
4697 const VkSamplerCreateInfo
*pCreateInfo
)
4699 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4700 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4701 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4702 unsigned filter_mode
= V_008F30_SQ_IMG_FILTER_MODE_BLEND
;
4704 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4705 vk_find_struct_const(pCreateInfo
->pNext
,
4706 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4707 if (sampler_reduction
)
4708 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4710 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4711 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4712 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4713 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4714 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4715 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4716 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4717 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4718 S_008F30_DISABLE_CUBE_WRAP(0) |
4719 S_008F30_COMPAT_MODE(is_vi
) |
4720 S_008F30_FILTER_MODE(filter_mode
));
4721 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4722 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4723 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4724 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4725 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4726 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4727 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4728 S_008F38_MIP_POINT_PRECLAMP(0) |
4729 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4730 S_008F38_FILTER_PREC_FIX(1) |
4731 S_008F38_ANISO_OVERRIDE(is_vi
));
4732 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4733 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4736 VkResult
radv_CreateSampler(
4738 const VkSamplerCreateInfo
* pCreateInfo
,
4739 const VkAllocationCallbacks
* pAllocator
,
4740 VkSampler
* pSampler
)
4742 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4743 struct radv_sampler
*sampler
;
4745 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4747 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4748 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4750 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4752 radv_init_sampler(device
, sampler
, pCreateInfo
);
4753 *pSampler
= radv_sampler_to_handle(sampler
);
4758 void radv_DestroySampler(
4761 const VkAllocationCallbacks
* pAllocator
)
4763 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4764 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4768 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4771 /* vk_icd.h does not declare this function, so we declare it here to
4772 * suppress Wmissing-prototypes.
4774 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4775 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4777 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4778 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4780 /* For the full details on loader interface versioning, see
4781 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4782 * What follows is a condensed summary, to help you navigate the large and
4783 * confusing official doc.
4785 * - Loader interface v0 is incompatible with later versions. We don't
4788 * - In loader interface v1:
4789 * - The first ICD entrypoint called by the loader is
4790 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4792 * - The ICD must statically expose no other Vulkan symbol unless it is
4793 * linked with -Bsymbolic.
4794 * - Each dispatchable Vulkan handle created by the ICD must be
4795 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4796 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4797 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4798 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4799 * such loader-managed surfaces.
4801 * - Loader interface v2 differs from v1 in:
4802 * - The first ICD entrypoint called by the loader is
4803 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4804 * statically expose this entrypoint.
4806 * - Loader interface v3 differs from v2 in:
4807 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4808 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4809 * because the loader no longer does so.
4811 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4815 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4816 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4819 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4820 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4822 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4824 /* At the moment, we support only the below handle types. */
4825 assert(pGetFdInfo
->handleType
==
4826 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
||
4827 pGetFdInfo
->handleType
==
4828 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4830 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4832 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4836 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4837 VkExternalMemoryHandleTypeFlagBits handleType
,
4839 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4841 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4843 switch (handleType
) {
4844 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4845 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4849 /* The valid usage section for this function says:
4851 * "handleType must not be one of the handle types defined as
4854 * So opaque handle types fall into the default "unsupported" case.
4856 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4860 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4864 uint32_t syncobj_handle
= 0;
4865 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4867 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4870 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4872 *syncobj
= syncobj_handle
;
4878 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4882 /* If we create a syncobj we do it locally so that if we have an error, we don't
4883 * leave a syncobj in an undetermined state in the fence. */
4884 uint32_t syncobj_handle
= *syncobj
;
4885 if (!syncobj_handle
) {
4886 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4888 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4893 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4895 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4897 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4900 *syncobj
= syncobj_handle
;
4907 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4908 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4910 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4911 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4912 uint32_t *syncobj_dst
= NULL
;
4914 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT
) {
4915 syncobj_dst
= &sem
->temp_syncobj
;
4917 syncobj_dst
= &sem
->syncobj
;
4920 switch(pImportSemaphoreFdInfo
->handleType
) {
4921 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
4922 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4923 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
4924 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4926 unreachable("Unhandled semaphore handle type");
4930 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4931 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4934 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4935 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4937 uint32_t syncobj_handle
;
4939 if (sem
->temp_syncobj
)
4940 syncobj_handle
= sem
->temp_syncobj
;
4942 syncobj_handle
= sem
->syncobj
;
4944 switch(pGetFdInfo
->handleType
) {
4945 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
:
4946 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4948 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
:
4949 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4951 if (sem
->temp_syncobj
) {
4952 close (sem
->temp_syncobj
);
4953 sem
->temp_syncobj
= 0;
4955 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4960 unreachable("Unhandled semaphore handle type");
4964 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
4968 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4969 VkPhysicalDevice physicalDevice
,
4970 const VkPhysicalDeviceExternalSemaphoreInfo
*pExternalSemaphoreInfo
,
4971 VkExternalSemaphoreProperties
*pExternalSemaphoreProperties
)
4973 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4975 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4976 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4977 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
||
4978 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
)) {
4979 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
4980 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
;
4981 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
4982 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
4983 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
) {
4984 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
4985 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT
;
4986 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT
|
4987 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
4989 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4990 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4991 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4995 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4996 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4998 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4999 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
5000 uint32_t *syncobj_dst
= NULL
;
5003 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT
) {
5004 syncobj_dst
= &fence
->temp_syncobj
;
5006 syncobj_dst
= &fence
->syncobj
;
5009 switch(pImportFenceFdInfo
->handleType
) {
5010 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5011 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5012 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5013 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
5015 unreachable("Unhandled fence handle type");
5019 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
5020 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
5023 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5024 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
5026 uint32_t syncobj_handle
;
5028 if (fence
->temp_syncobj
)
5029 syncobj_handle
= fence
->temp_syncobj
;
5031 syncobj_handle
= fence
->syncobj
;
5033 switch(pGetFdInfo
->handleType
) {
5034 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
:
5035 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
5037 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
:
5038 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
5040 if (fence
->temp_syncobj
) {
5041 close (fence
->temp_syncobj
);
5042 fence
->temp_syncobj
= 0;
5044 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
5049 unreachable("Unhandled fence handle type");
5053 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5057 void radv_GetPhysicalDeviceExternalFenceProperties(
5058 VkPhysicalDevice physicalDevice
,
5059 const VkPhysicalDeviceExternalFenceInfo
*pExternalFenceInfo
,
5060 VkExternalFenceProperties
*pExternalFenceProperties
)
5062 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
5064 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
5065 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
||
5066 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
)) {
5067 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5068 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
;
5069 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT
|
5070 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT
;
5072 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
5073 pExternalFenceProperties
->compatibleHandleTypes
= 0;
5074 pExternalFenceProperties
->externalFenceFeatures
= 0;
5079 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
5080 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
5081 const VkAllocationCallbacks
* pAllocator
,
5082 VkDebugReportCallbackEXT
* pCallback
)
5084 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5085 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
5086 pCreateInfo
, pAllocator
, &instance
->alloc
,
5091 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
5092 VkDebugReportCallbackEXT _callback
,
5093 const VkAllocationCallbacks
* pAllocator
)
5095 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5096 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
5097 _callback
, pAllocator
, &instance
->alloc
);
5101 radv_DebugReportMessageEXT(VkInstance _instance
,
5102 VkDebugReportFlagsEXT flags
,
5103 VkDebugReportObjectTypeEXT objectType
,
5106 int32_t messageCode
,
5107 const char* pLayerPrefix
,
5108 const char* pMessage
)
5110 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
5111 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
5112 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
5116 radv_GetDeviceGroupPeerMemoryFeatures(
5119 uint32_t localDeviceIndex
,
5120 uint32_t remoteDeviceIndex
,
5121 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
5123 assert(localDeviceIndex
== remoteDeviceIndex
);
5125 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
5126 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
5127 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
5128 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;
5131 static const VkTimeDomainEXT radv_time_domains
[] = {
5132 VK_TIME_DOMAIN_DEVICE_EXT
,
5133 VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
,
5134 VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
,
5137 VkResult
radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
5138 VkPhysicalDevice physicalDevice
,
5139 uint32_t *pTimeDomainCount
,
5140 VkTimeDomainEXT
*pTimeDomains
)
5143 VK_OUTARRAY_MAKE(out
, pTimeDomains
, pTimeDomainCount
);
5145 for (d
= 0; d
< ARRAY_SIZE(radv_time_domains
); d
++) {
5146 vk_outarray_append(&out
, i
) {
5147 *i
= radv_time_domains
[d
];
5151 return vk_outarray_status(&out
);
5155 radv_clock_gettime(clockid_t clock_id
)
5157 struct timespec current
;
5160 ret
= clock_gettime(clock_id
, ¤t
);
5161 if (ret
< 0 && clock_id
== CLOCK_MONOTONIC_RAW
)
5162 ret
= clock_gettime(CLOCK_MONOTONIC
, ¤t
);
5166 return (uint64_t) current
.tv_sec
* 1000000000ULL + current
.tv_nsec
;
5169 VkResult
radv_GetCalibratedTimestampsEXT(
5171 uint32_t timestampCount
,
5172 const VkCalibratedTimestampInfoEXT
*pTimestampInfos
,
5173 uint64_t *pTimestamps
,
5174 uint64_t *pMaxDeviation
)
5176 RADV_FROM_HANDLE(radv_device
, device
, _device
);
5177 uint32_t clock_crystal_freq
= device
->physical_device
->rad_info
.clock_crystal_freq
;
5179 uint64_t begin
, end
;
5180 uint64_t max_clock_period
= 0;
5182 begin
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5184 for (d
= 0; d
< timestampCount
; d
++) {
5185 switch (pTimestampInfos
[d
].timeDomain
) {
5186 case VK_TIME_DOMAIN_DEVICE_EXT
:
5187 pTimestamps
[d
] = device
->ws
->query_value(device
->ws
,
5189 uint64_t device_period
= DIV_ROUND_UP(1000000, clock_crystal_freq
);
5190 max_clock_period
= MAX2(max_clock_period
, device_period
);
5192 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
:
5193 pTimestamps
[d
] = radv_clock_gettime(CLOCK_MONOTONIC
);
5194 max_clock_period
= MAX2(max_clock_period
, 1);
5197 case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
:
5198 pTimestamps
[d
] = begin
;
5206 end
= radv_clock_gettime(CLOCK_MONOTONIC_RAW
);
5209 * The maximum deviation is the sum of the interval over which we
5210 * perform the sampling and the maximum period of any sampled
5211 * clock. That's because the maximum skew between any two sampled
5212 * clock edges is when the sampled clock with the largest period is
5213 * sampled at the end of that period but right at the beginning of the
5214 * sampling interval and some other clock is sampled right at the
5215 * begining of its sampling period and right at the end of the
5216 * sampling interval. Let's assume the GPU has the longest clock
5217 * period and that the application is sampling GPU and monotonic:
5220 * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
5221 * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5225 * GPU -----_____-----_____-----_____-----_____
5228 * x y z 0 1 2 3 4 5 6 7 8 9 a b c
5229 * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
5231 * Interval <----------------->
5232 * Deviation <-------------------------->
5236 * m = read(monotonic) 2
5239 * We round the sample interval up by one tick to cover sampling error
5240 * in the interval clock
5243 uint64_t sample_interval
= end
- begin
+ 1;
5245 *pMaxDeviation
= sample_interval
+ max_clock_period
;