2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
53 uint32_t mesa_timestamp
, llvm_timestamp
;
55 memset(uuid
, 0, VK_UUID_SIZE
);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
60 memcpy(uuid
, &mesa_timestamp
, 4);
61 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
62 memcpy((char*)uuid
+ 8, &f
, 2);
63 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
68 radv_get_driver_uuid(void *uuid
)
70 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
74 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
76 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
80 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
82 const char *chip_string
;
83 char llvm_string
[32] = {};
86 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
87 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
88 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
89 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
90 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
91 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
92 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
93 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
94 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
95 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
96 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
97 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
98 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
99 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
100 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
101 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
102 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
103 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
104 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
105 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
106 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
107 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
108 default: chip_string
= "AMD RADV unknown"; break;
111 snprintf(llvm_string
, sizeof(llvm_string
),
112 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
113 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
114 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
118 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
120 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
121 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
122 device
->rad_info
.vram_vis_size
);
124 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
125 device
->memory_properties
.memoryHeapCount
= 0;
126 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
127 vram_index
= device
->memory_properties
.memoryHeapCount
++;
128 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
129 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
130 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
133 if (visible_vram_size
) {
134 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
135 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
136 .size
= visible_vram_size
,
137 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
140 if (device
->rad_info
.gart_size
> 0) {
141 gart_index
= device
->memory_properties
.memoryHeapCount
++;
142 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
143 .size
= device
->rad_info
.gart_size
,
144 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
148 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
149 unsigned type_count
= 0;
150 if (vram_index
>= 0) {
151 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
152 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
153 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
154 .heapIndex
= vram_index
,
157 if (gart_index
>= 0) {
158 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
159 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
160 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
161 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
162 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
163 .heapIndex
= gart_index
,
166 if (visible_vram_index
>= 0) {
167 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
168 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
169 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
170 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
171 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
172 .heapIndex
= visible_vram_index
,
175 if (gart_index
>= 0) {
176 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
177 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
178 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
179 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
180 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
181 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
182 .heapIndex
= gart_index
,
185 device
->memory_properties
.memoryTypeCount
= type_count
;
189 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
191 const char *family
= getenv("RADV_FORCE_FAMILY");
197 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
198 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
199 /* Override family and chip_class. */
200 device
->rad_info
.family
= i
;
202 if (i
>= CHIP_VEGA10
)
203 device
->rad_info
.chip_class
= GFX9
;
204 else if (i
>= CHIP_TONGA
)
205 device
->rad_info
.chip_class
= VI
;
206 else if (i
>= CHIP_BONAIRE
)
207 device
->rad_info
.chip_class
= CIK
;
209 device
->rad_info
.chip_class
= SI
;
215 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
220 radv_physical_device_init(struct radv_physical_device
*device
,
221 struct radv_instance
*instance
,
222 drmDevicePtr drm_device
)
224 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
226 drmVersionPtr version
;
230 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
232 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
233 radv_logi("Could not open device '%s'", path
);
235 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
238 version
= drmGetVersion(fd
);
242 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
243 radv_logi("Could not get the kernel driver version for device '%s'", path
);
245 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
246 "failed to get version %s: %m", path
);
249 if (strcmp(version
->name
, "amdgpu")) {
250 drmFreeVersion(version
);
255 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
256 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
258 return VK_ERROR_INCOMPATIBLE_DRIVER
;
260 drmFreeVersion(version
);
262 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
263 radv_logi("Found compatible device '%s'.", path
);
265 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
266 device
->instance
= instance
;
267 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
268 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
270 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
271 instance
->perftest_flags
);
273 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
277 if (instance
->enabled_extensions
.KHR_display
) {
278 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
279 if (master_fd
>= 0) {
280 uint32_t accel_working
= 0;
281 struct drm_amdgpu_info request
= {
282 .return_pointer
= (uintptr_t)&accel_working
,
283 .return_size
= sizeof(accel_working
),
284 .query
= AMDGPU_INFO_ACCEL_WORKING
287 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
294 device
->master_fd
= master_fd
;
295 device
->local_fd
= fd
;
296 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
298 radv_handle_env_var_force_family(device
);
300 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
302 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
303 device
->ws
->destroy(device
->ws
);
304 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
305 "cannot generate UUID");
309 /* These flags affect shader compilation. */
310 uint64_t shader_env_flags
=
311 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
312 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
314 /* The gpu id is already embedded in the uuid so we just pass "radv"
315 * when creating the cache.
317 char buf
[VK_UUID_SIZE
* 2 + 1];
318 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
319 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
321 if (device
->rad_info
.chip_class
< VI
||
322 device
->rad_info
.chip_class
> GFX9
)
323 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
325 radv_get_driver_uuid(&device
->device_uuid
);
326 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
328 if (device
->rad_info
.family
== CHIP_STONEY
||
329 device
->rad_info
.chip_class
>= GFX9
) {
330 device
->has_rbplus
= true;
331 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
332 device
->rad_info
.family
== CHIP_VEGA12
||
333 device
->rad_info
.family
== CHIP_RAVEN
;
336 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
339 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
341 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
343 /* Vega10/Raven need a special workaround for a hardware bug. */
344 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
345 device
->rad_info
.family
== CHIP_RAVEN
;
347 /* Out-of-order primitive rasterization. */
348 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
349 device
->rad_info
.max_se
>= 2;
350 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
351 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
353 device
->dcc_msaa_allowed
=
354 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
356 radv_physical_device_init_mem_types(device
);
357 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
359 result
= radv_init_wsi(device
);
360 if (result
!= VK_SUCCESS
) {
361 device
->ws
->destroy(device
->ws
);
362 vk_error(instance
, result
);
366 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
367 ac_print_gpu_info(&device
->rad_info
);
379 radv_physical_device_finish(struct radv_physical_device
*device
)
381 radv_finish_wsi(device
);
382 device
->ws
->destroy(device
->ws
);
383 disk_cache_destroy(device
->disk_cache
);
384 close(device
->local_fd
);
385 if (device
->master_fd
!= -1)
386 close(device
->master_fd
);
390 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
391 VkSystemAllocationScope allocationScope
)
397 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
398 size_t align
, VkSystemAllocationScope allocationScope
)
400 return realloc(pOriginal
, size
);
404 default_free_func(void *pUserData
, void *pMemory
)
409 static const VkAllocationCallbacks default_alloc
= {
411 .pfnAllocation
= default_alloc_func
,
412 .pfnReallocation
= default_realloc_func
,
413 .pfnFree
= default_free_func
,
416 static const struct debug_control radv_debug_options
[] = {
417 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
418 {"nodcc", RADV_DEBUG_NO_DCC
},
419 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
420 {"nocache", RADV_DEBUG_NO_CACHE
},
421 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
422 {"nohiz", RADV_DEBUG_NO_HIZ
},
423 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
424 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
425 {"allbos", RADV_DEBUG_ALL_BOS
},
426 {"noibs", RADV_DEBUG_NO_IBS
},
427 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
428 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
429 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
430 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
431 {"nosisched", RADV_DEBUG_NO_SISCHED
},
432 {"preoptir", RADV_DEBUG_PREOPTIR
},
433 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
434 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
435 {"info", RADV_DEBUG_INFO
},
436 {"errors", RADV_DEBUG_ERRORS
},
437 {"startup", RADV_DEBUG_STARTUP
},
438 {"checkir", RADV_DEBUG_CHECKIR
},
443 radv_get_debug_option_name(int id
)
445 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
446 return radv_debug_options
[id
].string
;
449 static const struct debug_control radv_perftest_options
[] = {
450 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
451 {"sisched", RADV_PERFTEST_SISCHED
},
452 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
453 {"binning", RADV_PERFTEST_BINNING
},
454 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
459 radv_get_perftest_option_name(int id
)
461 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
462 return radv_perftest_options
[id
].string
;
466 radv_handle_per_app_options(struct radv_instance
*instance
,
467 const VkApplicationInfo
*info
)
469 const char *name
= info
? info
->pApplicationName
: NULL
;
474 if (!strcmp(name
, "Talos - Linux - 32bit") ||
475 !strcmp(name
, "Talos - Linux - 64bit")) {
476 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
477 /* Force enable LLVM sisched for Talos because it looks
478 * safe and it gives few more FPS.
480 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
485 static int radv_get_instance_extension_index(const char *name
)
487 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
488 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
495 VkResult
radv_CreateInstance(
496 const VkInstanceCreateInfo
* pCreateInfo
,
497 const VkAllocationCallbacks
* pAllocator
,
498 VkInstance
* pInstance
)
500 struct radv_instance
*instance
;
503 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
505 uint32_t client_version
;
506 if (pCreateInfo
->pApplicationInfo
&&
507 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
508 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
510 radv_EnumerateInstanceVersion(&client_version
);
513 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
514 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
516 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
518 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
521 instance
->alloc
= *pAllocator
;
523 instance
->alloc
= default_alloc
;
525 instance
->apiVersion
= client_version
;
526 instance
->physicalDeviceCount
= -1;
528 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
531 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
532 radv_perftest_options
);
535 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
536 radv_logi("Created an instance");
538 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
539 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
540 int index
= radv_get_instance_extension_index(ext_name
);
542 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
543 vk_free2(&default_alloc
, pAllocator
, instance
);
544 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
547 instance
->enabled_extensions
.extensions
[index
] = true;
550 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
551 if (result
!= VK_SUCCESS
) {
552 vk_free2(&default_alloc
, pAllocator
, instance
);
553 return vk_error(instance
, result
);
558 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
560 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
562 *pInstance
= radv_instance_to_handle(instance
);
567 void radv_DestroyInstance(
568 VkInstance _instance
,
569 const VkAllocationCallbacks
* pAllocator
)
571 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
576 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
577 radv_physical_device_finish(instance
->physicalDevices
+ i
);
580 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
584 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
586 vk_free(&instance
->alloc
, instance
);
590 radv_enumerate_devices(struct radv_instance
*instance
)
592 /* TODO: Check for more devices ? */
593 drmDevicePtr devices
[8];
594 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
597 instance
->physicalDeviceCount
= 0;
599 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
601 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
602 radv_logi("Found %d drm nodes", max_devices
);
605 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
607 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
608 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
609 devices
[i
]->bustype
== DRM_BUS_PCI
&&
610 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
612 result
= radv_physical_device_init(instance
->physicalDevices
+
613 instance
->physicalDeviceCount
,
616 if (result
== VK_SUCCESS
)
617 ++instance
->physicalDeviceCount
;
618 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
622 drmFreeDevices(devices
, max_devices
);
627 VkResult
radv_EnumeratePhysicalDevices(
628 VkInstance _instance
,
629 uint32_t* pPhysicalDeviceCount
,
630 VkPhysicalDevice
* pPhysicalDevices
)
632 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
635 if (instance
->physicalDeviceCount
< 0) {
636 result
= radv_enumerate_devices(instance
);
637 if (result
!= VK_SUCCESS
&&
638 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
642 if (!pPhysicalDevices
) {
643 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
645 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
646 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
647 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
650 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
654 VkResult
radv_EnumeratePhysicalDeviceGroups(
655 VkInstance _instance
,
656 uint32_t* pPhysicalDeviceGroupCount
,
657 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
659 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
662 if (instance
->physicalDeviceCount
< 0) {
663 result
= radv_enumerate_devices(instance
);
664 if (result
!= VK_SUCCESS
&&
665 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
669 if (!pPhysicalDeviceGroupProperties
) {
670 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
672 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
673 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
674 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
675 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
676 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
679 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
683 void radv_GetPhysicalDeviceFeatures(
684 VkPhysicalDevice physicalDevice
,
685 VkPhysicalDeviceFeatures
* pFeatures
)
687 memset(pFeatures
, 0, sizeof(*pFeatures
));
689 *pFeatures
= (VkPhysicalDeviceFeatures
) {
690 .robustBufferAccess
= true,
691 .fullDrawIndexUint32
= true,
692 .imageCubeArray
= true,
693 .independentBlend
= true,
694 .geometryShader
= true,
695 .tessellationShader
= true,
696 .sampleRateShading
= true,
697 .dualSrcBlend
= true,
699 .multiDrawIndirect
= true,
700 .drawIndirectFirstInstance
= true,
702 .depthBiasClamp
= true,
703 .fillModeNonSolid
= true,
708 .multiViewport
= true,
709 .samplerAnisotropy
= true,
710 .textureCompressionETC2
= false,
711 .textureCompressionASTC_LDR
= false,
712 .textureCompressionBC
= true,
713 .occlusionQueryPrecise
= true,
714 .pipelineStatisticsQuery
= true,
715 .vertexPipelineStoresAndAtomics
= true,
716 .fragmentStoresAndAtomics
= true,
717 .shaderTessellationAndGeometryPointSize
= true,
718 .shaderImageGatherExtended
= true,
719 .shaderStorageImageExtendedFormats
= true,
720 .shaderStorageImageMultisample
= false,
721 .shaderUniformBufferArrayDynamicIndexing
= true,
722 .shaderSampledImageArrayDynamicIndexing
= true,
723 .shaderStorageBufferArrayDynamicIndexing
= true,
724 .shaderStorageImageArrayDynamicIndexing
= true,
725 .shaderStorageImageReadWithoutFormat
= true,
726 .shaderStorageImageWriteWithoutFormat
= true,
727 .shaderClipDistance
= true,
728 .shaderCullDistance
= true,
729 .shaderFloat64
= true,
731 .shaderInt16
= false,
732 .sparseBinding
= true,
733 .variableMultisampleRate
= true,
734 .inheritedQueries
= true,
738 void radv_GetPhysicalDeviceFeatures2(
739 VkPhysicalDevice physicalDevice
,
740 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
742 vk_foreach_struct(ext
, pFeatures
->pNext
) {
743 switch (ext
->sType
) {
744 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
745 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
746 features
->variablePointersStorageBuffer
= true;
747 features
->variablePointers
= false;
750 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
751 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
752 features
->multiview
= true;
753 features
->multiviewGeometryShader
= true;
754 features
->multiviewTessellationShader
= true;
757 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
758 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
759 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
760 features
->shaderDrawParameters
= true;
763 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
764 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
765 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
766 features
->protectedMemory
= false;
769 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
770 VkPhysicalDevice16BitStorageFeatures
*features
=
771 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
772 features
->storageBuffer16BitAccess
= false;
773 features
->uniformAndStorageBuffer16BitAccess
= false;
774 features
->storagePushConstant16
= false;
775 features
->storageInputOutput16
= false;
778 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
779 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
780 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
781 features
->samplerYcbcrConversion
= false;
784 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
785 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
786 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
787 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
788 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
789 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
790 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
791 features
->shaderSampledImageArrayNonUniformIndexing
= false;
792 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
793 features
->shaderStorageImageArrayNonUniformIndexing
= false;
794 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
795 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
796 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
797 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
798 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
799 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
800 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
801 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
802 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
803 features
->descriptorBindingUpdateUnusedWhilePending
= true;
804 features
->descriptorBindingPartiallyBound
= true;
805 features
->descriptorBindingVariableDescriptorCount
= true;
806 features
->runtimeDescriptorArray
= true;
813 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
816 void radv_GetPhysicalDeviceProperties(
817 VkPhysicalDevice physicalDevice
,
818 VkPhysicalDeviceProperties
* pProperties
)
820 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
821 VkSampleCountFlags sample_counts
= 0xf;
823 /* make sure that the entire descriptor set is addressable with a signed
824 * 32-bit int. So the sum of all limits scaled by descriptor size has to
825 * be at most 2 GiB. the combined image & samples object count as one of
826 * both. This limit is for the pipeline layout, not for the set layout, but
827 * there is no set limit, so we just set a pipeline limit. I don't think
828 * any app is going to hit this soon. */
829 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
830 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
831 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
832 32 /* sampler, largest when combined with image */ +
833 64 /* sampled image */ +
834 64 /* storage image */);
836 VkPhysicalDeviceLimits limits
= {
837 .maxImageDimension1D
= (1 << 14),
838 .maxImageDimension2D
= (1 << 14),
839 .maxImageDimension3D
= (1 << 11),
840 .maxImageDimensionCube
= (1 << 14),
841 .maxImageArrayLayers
= (1 << 11),
842 .maxTexelBufferElements
= 128 * 1024 * 1024,
843 .maxUniformBufferRange
= UINT32_MAX
,
844 .maxStorageBufferRange
= UINT32_MAX
,
845 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
846 .maxMemoryAllocationCount
= UINT32_MAX
,
847 .maxSamplerAllocationCount
= 64 * 1024,
848 .bufferImageGranularity
= 64, /* A cache line */
849 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
850 .maxBoundDescriptorSets
= MAX_SETS
,
851 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
852 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
853 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
854 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
855 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
856 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
857 .maxPerStageResources
= max_descriptor_set_size
,
858 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
859 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
860 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
861 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
862 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
863 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
864 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
865 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
866 .maxVertexInputAttributes
= 32,
867 .maxVertexInputBindings
= 32,
868 .maxVertexInputAttributeOffset
= 2047,
869 .maxVertexInputBindingStride
= 2048,
870 .maxVertexOutputComponents
= 128,
871 .maxTessellationGenerationLevel
= 64,
872 .maxTessellationPatchSize
= 32,
873 .maxTessellationControlPerVertexInputComponents
= 128,
874 .maxTessellationControlPerVertexOutputComponents
= 128,
875 .maxTessellationControlPerPatchOutputComponents
= 120,
876 .maxTessellationControlTotalOutputComponents
= 4096,
877 .maxTessellationEvaluationInputComponents
= 128,
878 .maxTessellationEvaluationOutputComponents
= 128,
879 .maxGeometryShaderInvocations
= 127,
880 .maxGeometryInputComponents
= 64,
881 .maxGeometryOutputComponents
= 128,
882 .maxGeometryOutputVertices
= 256,
883 .maxGeometryTotalOutputComponents
= 1024,
884 .maxFragmentInputComponents
= 128,
885 .maxFragmentOutputAttachments
= 8,
886 .maxFragmentDualSrcAttachments
= 1,
887 .maxFragmentCombinedOutputResources
= 8,
888 .maxComputeSharedMemorySize
= 32768,
889 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
890 .maxComputeWorkGroupInvocations
= 2048,
891 .maxComputeWorkGroupSize
= {
896 .subPixelPrecisionBits
= 4 /* FIXME */,
897 .subTexelPrecisionBits
= 4 /* FIXME */,
898 .mipmapPrecisionBits
= 4 /* FIXME */,
899 .maxDrawIndexedIndexValue
= UINT32_MAX
,
900 .maxDrawIndirectCount
= UINT32_MAX
,
901 .maxSamplerLodBias
= 16,
902 .maxSamplerAnisotropy
= 16,
903 .maxViewports
= MAX_VIEWPORTS
,
904 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
905 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
906 .viewportSubPixelBits
= 8,
907 .minMemoryMapAlignment
= 4096, /* A page */
908 .minTexelBufferOffsetAlignment
= 1,
909 .minUniformBufferOffsetAlignment
= 4,
910 .minStorageBufferOffsetAlignment
= 4,
911 .minTexelOffset
= -32,
912 .maxTexelOffset
= 31,
913 .minTexelGatherOffset
= -32,
914 .maxTexelGatherOffset
= 31,
915 .minInterpolationOffset
= -2,
916 .maxInterpolationOffset
= 2,
917 .subPixelInterpolationOffsetBits
= 8,
918 .maxFramebufferWidth
= (1 << 14),
919 .maxFramebufferHeight
= (1 << 14),
920 .maxFramebufferLayers
= (1 << 10),
921 .framebufferColorSampleCounts
= sample_counts
,
922 .framebufferDepthSampleCounts
= sample_counts
,
923 .framebufferStencilSampleCounts
= sample_counts
,
924 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
925 .maxColorAttachments
= MAX_RTS
,
926 .sampledImageColorSampleCounts
= sample_counts
,
927 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
928 .sampledImageDepthSampleCounts
= sample_counts
,
929 .sampledImageStencilSampleCounts
= sample_counts
,
930 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
931 .maxSampleMaskWords
= 1,
932 .timestampComputeAndGraphics
= true,
933 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
934 .maxClipDistances
= 8,
935 .maxCullDistances
= 8,
936 .maxCombinedClipAndCullDistances
= 8,
937 .discreteQueuePriorities
= 1,
938 .pointSizeRange
= { 0.125, 255.875 },
939 .lineWidthRange
= { 0.0, 7.9921875 },
940 .pointSizeGranularity
= (1.0 / 8.0),
941 .lineWidthGranularity
= (1.0 / 128.0),
942 .strictLines
= false, /* FINISHME */
943 .standardSampleLocations
= true,
944 .optimalBufferCopyOffsetAlignment
= 128,
945 .optimalBufferCopyRowPitchAlignment
= 128,
946 .nonCoherentAtomSize
= 64,
949 *pProperties
= (VkPhysicalDeviceProperties
) {
950 .apiVersion
= radv_physical_device_api_version(pdevice
),
951 .driverVersion
= vk_get_driver_version(),
952 .vendorID
= ATI_VENDOR_ID
,
953 .deviceID
= pdevice
->rad_info
.pci_id
,
954 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
956 .sparseProperties
= {0},
959 strcpy(pProperties
->deviceName
, pdevice
->name
);
960 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
963 void radv_GetPhysicalDeviceProperties2(
964 VkPhysicalDevice physicalDevice
,
965 VkPhysicalDeviceProperties2KHR
*pProperties
)
967 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
968 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
970 vk_foreach_struct(ext
, pProperties
->pNext
) {
971 switch (ext
->sType
) {
972 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
973 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
974 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
975 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
978 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
979 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
980 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
981 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
982 properties
->deviceLUIDValid
= false;
985 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
986 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
987 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
988 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
991 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
992 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
993 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
994 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
997 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
998 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
999 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1000 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1003 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1004 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1005 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1006 properties
->minImportedHostPointerAlignment
= 4096;
1009 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1010 VkPhysicalDeviceSubgroupProperties
*properties
=
1011 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1012 properties
->subgroupSize
= 64;
1013 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1014 properties
->supportedOperations
=
1015 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1016 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1017 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1018 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1019 if (pdevice
->rad_info
.chip_class
>= VI
) {
1020 properties
->supportedOperations
|=
1021 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1022 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1024 properties
->quadOperationsInAllStages
= true;
1027 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1028 VkPhysicalDeviceMaintenance3Properties
*properties
=
1029 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1030 /* Make sure everything is addressable by a signed 32-bit int, and
1031 * our largest descriptors are 96 bytes. */
1032 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1033 /* Our buffer size fields allow only this much */
1034 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1037 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1038 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1039 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1040 /* GFX6-8 only support single channel min/max filter. */
1041 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1042 properties
->filterMinmaxSingleComponentFormats
= true;
1045 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1046 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1047 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1049 /* Shader engines. */
1050 properties
->shaderEngineCount
=
1051 pdevice
->rad_info
.max_se
;
1052 properties
->shaderArraysPerEngineCount
=
1053 pdevice
->rad_info
.max_sh_per_se
;
1054 properties
->computeUnitsPerShaderArray
=
1055 pdevice
->rad_info
.num_good_compute_units
/
1056 (pdevice
->rad_info
.max_se
*
1057 pdevice
->rad_info
.max_sh_per_se
);
1058 properties
->simdPerComputeUnit
= 4;
1059 properties
->wavefrontsPerSimd
=
1060 pdevice
->rad_info
.family
== CHIP_TONGA
||
1061 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1062 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1063 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1064 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1065 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1066 properties
->wavefrontSize
= 64;
1069 properties
->sgprsPerSimd
=
1070 radv_get_num_physical_sgprs(pdevice
);
1071 properties
->minSgprAllocation
=
1072 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1073 properties
->maxSgprAllocation
=
1074 pdevice
->rad_info
.family
== CHIP_TONGA
||
1075 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1076 properties
->sgprAllocationGranularity
=
1077 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1080 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1081 properties
->minVgprAllocation
= 4;
1082 properties
->maxVgprAllocation
= 256;
1083 properties
->vgprAllocationGranularity
= 4;
1086 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1087 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1088 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1089 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1092 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1093 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1094 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1095 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1096 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1097 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1098 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1099 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1100 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1101 properties
->robustBufferAccessUpdateAfterBind
= false;
1102 properties
->quadDivergentImplicitLod
= false;
1104 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1105 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1106 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1107 32 /* sampler, largest when combined with image */ +
1108 64 /* sampled image */ +
1109 64 /* storage image */);
1110 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1111 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1112 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1113 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1114 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1115 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1116 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1117 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1118 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1119 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1120 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1121 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1122 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1123 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1124 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1133 static void radv_get_physical_device_queue_family_properties(
1134 struct radv_physical_device
* pdevice
,
1136 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1138 int num_queue_families
= 1;
1140 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1141 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1142 num_queue_families
++;
1144 if (pQueueFamilyProperties
== NULL
) {
1145 *pCount
= num_queue_families
;
1154 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1155 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1156 VK_QUEUE_COMPUTE_BIT
|
1157 VK_QUEUE_TRANSFER_BIT
|
1158 VK_QUEUE_SPARSE_BINDING_BIT
,
1160 .timestampValidBits
= 64,
1161 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1166 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1167 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1168 if (*pCount
> idx
) {
1169 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1170 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1171 VK_QUEUE_TRANSFER_BIT
|
1172 VK_QUEUE_SPARSE_BINDING_BIT
,
1173 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1174 .timestampValidBits
= 64,
1175 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1183 void radv_GetPhysicalDeviceQueueFamilyProperties(
1184 VkPhysicalDevice physicalDevice
,
1186 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1188 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1189 if (!pQueueFamilyProperties
) {
1190 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1193 VkQueueFamilyProperties
*properties
[] = {
1194 pQueueFamilyProperties
+ 0,
1195 pQueueFamilyProperties
+ 1,
1196 pQueueFamilyProperties
+ 2,
1198 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1199 assert(*pCount
<= 3);
1202 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1203 VkPhysicalDevice physicalDevice
,
1205 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1207 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1208 if (!pQueueFamilyProperties
) {
1209 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1212 VkQueueFamilyProperties
*properties
[] = {
1213 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1214 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1215 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1217 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1218 assert(*pCount
<= 3);
1221 void radv_GetPhysicalDeviceMemoryProperties(
1222 VkPhysicalDevice physicalDevice
,
1223 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1225 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1227 *pMemoryProperties
= physical_device
->memory_properties
;
1230 void radv_GetPhysicalDeviceMemoryProperties2(
1231 VkPhysicalDevice physicalDevice
,
1232 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1234 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1235 &pMemoryProperties
->memoryProperties
);
1238 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1240 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1241 const void *pHostPointer
,
1242 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1244 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1248 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1249 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1250 uint32_t memoryTypeBits
= 0;
1251 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1252 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1253 memoryTypeBits
= (1 << i
);
1257 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1261 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1265 static enum radeon_ctx_priority
1266 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1268 /* Default to MEDIUM when a specific global priority isn't requested */
1270 return RADEON_CTX_PRIORITY_MEDIUM
;
1272 switch(pObj
->globalPriority
) {
1273 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1274 return RADEON_CTX_PRIORITY_REALTIME
;
1275 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1276 return RADEON_CTX_PRIORITY_HIGH
;
1277 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1278 return RADEON_CTX_PRIORITY_MEDIUM
;
1279 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1280 return RADEON_CTX_PRIORITY_LOW
;
1282 unreachable("Illegal global priority value");
1283 return RADEON_CTX_PRIORITY_INVALID
;
1288 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1289 uint32_t queue_family_index
, int idx
,
1290 VkDeviceQueueCreateFlags flags
,
1291 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1293 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1294 queue
->device
= device
;
1295 queue
->queue_family_index
= queue_family_index
;
1296 queue
->queue_idx
= idx
;
1297 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1298 queue
->flags
= flags
;
1300 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1302 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1308 radv_queue_finish(struct radv_queue
*queue
)
1311 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1313 if (queue
->initial_full_flush_preamble_cs
)
1314 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1315 if (queue
->initial_preamble_cs
)
1316 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1317 if (queue
->continue_preamble_cs
)
1318 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1319 if (queue
->descriptor_bo
)
1320 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1321 if (queue
->scratch_bo
)
1322 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1323 if (queue
->esgs_ring_bo
)
1324 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1325 if (queue
->gsvs_ring_bo
)
1326 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1327 if (queue
->tess_rings_bo
)
1328 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1329 if (queue
->compute_scratch_bo
)
1330 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1334 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1336 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1337 bo_list
->list
.count
= bo_list
->capacity
= 0;
1338 bo_list
->list
.bos
= NULL
;
1342 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1344 free(bo_list
->list
.bos
);
1345 pthread_mutex_destroy(&bo_list
->mutex
);
1348 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1349 struct radeon_winsys_bo
*bo
)
1351 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1353 if (unlikely(!device
->use_global_bo_list
))
1356 pthread_mutex_lock(&bo_list
->mutex
);
1357 if (bo_list
->list
.count
== bo_list
->capacity
) {
1358 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1359 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1362 pthread_mutex_unlock(&bo_list
->mutex
);
1363 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1366 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1367 bo_list
->capacity
= capacity
;
1370 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1371 pthread_mutex_unlock(&bo_list
->mutex
);
1375 static void radv_bo_list_remove(struct radv_device
*device
,
1376 struct radeon_winsys_bo
*bo
)
1378 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1380 if (unlikely(!device
->use_global_bo_list
))
1383 pthread_mutex_lock(&bo_list
->mutex
);
1384 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1385 if (bo_list
->list
.bos
[i
] == bo
) {
1386 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1387 --bo_list
->list
.count
;
1391 pthread_mutex_unlock(&bo_list
->mutex
);
1395 radv_device_init_gs_info(struct radv_device
*device
)
1397 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1398 device
->physical_device
->rad_info
.family
);
1401 static int radv_get_device_extension_index(const char *name
)
1403 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1404 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1410 VkResult
radv_CreateDevice(
1411 VkPhysicalDevice physicalDevice
,
1412 const VkDeviceCreateInfo
* pCreateInfo
,
1413 const VkAllocationCallbacks
* pAllocator
,
1416 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1418 struct radv_device
*device
;
1420 bool keep_shader_info
= false;
1422 /* Check enabled features */
1423 if (pCreateInfo
->pEnabledFeatures
) {
1424 VkPhysicalDeviceFeatures supported_features
;
1425 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1426 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1427 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1428 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1429 for (uint32_t i
= 0; i
< num_features
; i
++) {
1430 if (enabled_feature
[i
] && !supported_feature
[i
])
1431 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1435 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1437 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1439 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1441 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1442 device
->instance
= physical_device
->instance
;
1443 device
->physical_device
= physical_device
;
1445 device
->ws
= physical_device
->ws
;
1447 device
->alloc
= *pAllocator
;
1449 device
->alloc
= physical_device
->instance
->alloc
;
1451 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1452 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1453 int index
= radv_get_device_extension_index(ext_name
);
1454 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1455 vk_free(&device
->alloc
, device
);
1456 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1459 device
->enabled_extensions
.extensions
[index
] = true;
1462 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1464 /* With update after bind we can't attach bo's to the command buffer
1465 * from the descriptor set anymore, so we have to use a global BO list.
1467 device
->use_global_bo_list
=
1468 device
->enabled_extensions
.EXT_descriptor_indexing
;
1470 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1471 list_inithead(&device
->shader_slabs
);
1473 radv_bo_list_init(&device
->bo_list
);
1475 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1476 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1477 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1478 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1479 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1481 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1483 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1484 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1485 if (!device
->queues
[qfi
]) {
1486 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1490 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1492 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1494 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1495 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1496 qfi
, q
, queue_create
->flags
,
1498 if (result
!= VK_SUCCESS
)
1503 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1504 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1506 /* Disabled and not implemented for now. */
1507 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1510 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1513 /* The maximum number of scratch waves. Scratch space isn't divided
1514 * evenly between CUs. The number is only a function of the number of CUs.
1515 * We can decrease the constant to decrease the scratch buffer size.
1517 * sctx->scratch_waves must be >= the maximum possible size of
1518 * 1 threadgroup, so that the hw doesn't hang from being unable
1521 * The recommended value is 4 per CU at most. Higher numbers don't
1522 * bring much benefit, but they still occupy chip resources (think
1523 * async compute). I've seen ~2% performance difference between 4 and 32.
1525 uint32_t max_threads_per_block
= 2048;
1526 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1527 max_threads_per_block
/ 64);
1529 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1531 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1532 /* If the KMD allows it (there is a KMD hw register for it),
1533 * allow launching waves out-of-order.
1535 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1538 radv_device_init_gs_info(device
);
1540 device
->tess_offchip_block_dw_size
=
1541 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1542 device
->has_distributed_tess
=
1543 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1544 device
->physical_device
->rad_info
.max_se
>= 2;
1546 if (getenv("RADV_TRACE_FILE")) {
1547 const char *filename
= getenv("RADV_TRACE_FILE");
1549 keep_shader_info
= true;
1551 if (!radv_init_trace(device
))
1554 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1555 radv_dump_enabled_options(device
, stderr
);
1558 device
->keep_shader_info
= keep_shader_info
;
1560 result
= radv_device_init_meta(device
);
1561 if (result
!= VK_SUCCESS
)
1564 radv_device_init_msaa(device
);
1566 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1567 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1569 case RADV_QUEUE_GENERAL
:
1570 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1571 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1572 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1574 case RADV_QUEUE_COMPUTE
:
1575 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1576 radeon_emit(device
->empty_cs
[family
], 0);
1579 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1582 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1583 cik_create_gfx_config(device
);
1585 VkPipelineCacheCreateInfo ci
;
1586 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1589 ci
.pInitialData
= NULL
;
1590 ci
.initialDataSize
= 0;
1592 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1594 if (result
!= VK_SUCCESS
)
1597 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1599 *pDevice
= radv_device_to_handle(device
);
1603 radv_device_finish_meta(device
);
1605 radv_bo_list_finish(&device
->bo_list
);
1607 if (device
->trace_bo
)
1608 device
->ws
->buffer_destroy(device
->trace_bo
);
1610 if (device
->gfx_init
)
1611 device
->ws
->buffer_destroy(device
->gfx_init
);
1613 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1614 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1615 radv_queue_finish(&device
->queues
[i
][q
]);
1616 if (device
->queue_count
[i
])
1617 vk_free(&device
->alloc
, device
->queues
[i
]);
1620 vk_free(&device
->alloc
, device
);
1624 void radv_DestroyDevice(
1626 const VkAllocationCallbacks
* pAllocator
)
1628 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1633 if (device
->trace_bo
)
1634 device
->ws
->buffer_destroy(device
->trace_bo
);
1636 if (device
->gfx_init
)
1637 device
->ws
->buffer_destroy(device
->gfx_init
);
1639 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1640 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1641 radv_queue_finish(&device
->queues
[i
][q
]);
1642 if (device
->queue_count
[i
])
1643 vk_free(&device
->alloc
, device
->queues
[i
]);
1644 if (device
->empty_cs
[i
])
1645 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1647 radv_device_finish_meta(device
);
1649 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1650 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1652 radv_destroy_shader_slabs(device
);
1654 radv_bo_list_finish(&device
->bo_list
);
1655 vk_free(&device
->alloc
, device
);
1658 VkResult
radv_EnumerateInstanceLayerProperties(
1659 uint32_t* pPropertyCount
,
1660 VkLayerProperties
* pProperties
)
1662 if (pProperties
== NULL
) {
1663 *pPropertyCount
= 0;
1667 /* None supported at this time */
1668 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1671 VkResult
radv_EnumerateDeviceLayerProperties(
1672 VkPhysicalDevice physicalDevice
,
1673 uint32_t* pPropertyCount
,
1674 VkLayerProperties
* pProperties
)
1676 if (pProperties
== NULL
) {
1677 *pPropertyCount
= 0;
1681 /* None supported at this time */
1682 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1685 void radv_GetDeviceQueue2(
1687 const VkDeviceQueueInfo2
* pQueueInfo
,
1690 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1691 struct radv_queue
*queue
;
1693 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1694 if (pQueueInfo
->flags
!= queue
->flags
) {
1695 /* From the Vulkan 1.1.70 spec:
1697 * "The queue returned by vkGetDeviceQueue2 must have the same
1698 * flags value from this structure as that used at device
1699 * creation time in a VkDeviceQueueCreateInfo instance. If no
1700 * matching flags were specified at device creation time then
1701 * pQueue will return VK_NULL_HANDLE."
1703 *pQueue
= VK_NULL_HANDLE
;
1707 *pQueue
= radv_queue_to_handle(queue
);
1710 void radv_GetDeviceQueue(
1712 uint32_t queueFamilyIndex
,
1713 uint32_t queueIndex
,
1716 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1717 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1718 .queueFamilyIndex
= queueFamilyIndex
,
1719 .queueIndex
= queueIndex
1722 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1726 fill_geom_tess_rings(struct radv_queue
*queue
,
1728 bool add_sample_positions
,
1729 uint32_t esgs_ring_size
,
1730 struct radeon_winsys_bo
*esgs_ring_bo
,
1731 uint32_t gsvs_ring_size
,
1732 struct radeon_winsys_bo
*gsvs_ring_bo
,
1733 uint32_t tess_factor_ring_size
,
1734 uint32_t tess_offchip_ring_offset
,
1735 uint32_t tess_offchip_ring_size
,
1736 struct radeon_winsys_bo
*tess_rings_bo
)
1738 uint64_t esgs_va
= 0, gsvs_va
= 0;
1739 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1740 uint32_t *desc
= &map
[4];
1743 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1745 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1746 if (tess_rings_bo
) {
1747 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1748 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1751 /* stride 0, num records - size, add tid, swizzle, elsize4,
1754 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1755 S_008F04_STRIDE(0) |
1756 S_008F04_SWIZZLE_ENABLE(true);
1757 desc
[2] = esgs_ring_size
;
1758 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1759 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1760 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1761 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1762 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1763 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1764 S_008F0C_ELEMENT_SIZE(1) |
1765 S_008F0C_INDEX_STRIDE(3) |
1766 S_008F0C_ADD_TID_ENABLE(true);
1769 /* GS entry for ES->GS ring */
1770 /* stride 0, num records - size, elsize0,
1773 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1774 S_008F04_STRIDE(0) |
1775 S_008F04_SWIZZLE_ENABLE(false);
1776 desc
[2] = esgs_ring_size
;
1777 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1778 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1779 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1780 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1781 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1782 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1783 S_008F0C_ELEMENT_SIZE(0) |
1784 S_008F0C_INDEX_STRIDE(0) |
1785 S_008F0C_ADD_TID_ENABLE(false);
1788 /* VS entry for GS->VS ring */
1789 /* stride 0, num records - size, elsize0,
1792 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1793 S_008F04_STRIDE(0) |
1794 S_008F04_SWIZZLE_ENABLE(false);
1795 desc
[2] = gsvs_ring_size
;
1796 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1797 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1798 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1799 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1800 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1801 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1802 S_008F0C_ELEMENT_SIZE(0) |
1803 S_008F0C_INDEX_STRIDE(0) |
1804 S_008F0C_ADD_TID_ENABLE(false);
1807 /* stride gsvs_itemsize, num records 64
1808 elsize 4, index stride 16 */
1809 /* shader will patch stride and desc[2] */
1811 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1812 S_008F04_STRIDE(0) |
1813 S_008F04_SWIZZLE_ENABLE(true);
1815 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1816 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1817 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1818 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1819 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1820 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1821 S_008F0C_ELEMENT_SIZE(1) |
1822 S_008F0C_INDEX_STRIDE(1) |
1823 S_008F0C_ADD_TID_ENABLE(true);
1827 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1828 S_008F04_STRIDE(0) |
1829 S_008F04_SWIZZLE_ENABLE(false);
1830 desc
[2] = tess_factor_ring_size
;
1831 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1832 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1833 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1834 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1835 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1836 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1837 S_008F0C_ELEMENT_SIZE(0) |
1838 S_008F0C_INDEX_STRIDE(0) |
1839 S_008F0C_ADD_TID_ENABLE(false);
1842 desc
[0] = tess_offchip_va
;
1843 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1844 S_008F04_STRIDE(0) |
1845 S_008F04_SWIZZLE_ENABLE(false);
1846 desc
[2] = tess_offchip_ring_size
;
1847 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1848 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1849 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1850 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1851 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1852 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1853 S_008F0C_ELEMENT_SIZE(0) |
1854 S_008F0C_INDEX_STRIDE(0) |
1855 S_008F0C_ADD_TID_ENABLE(false);
1858 /* add sample positions after all rings */
1859 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1861 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1863 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1865 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1867 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1871 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1873 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1874 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1875 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1876 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1877 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1878 device
->physical_device
->rad_info
.max_se
;
1879 unsigned offchip_granularity
;
1880 unsigned hs_offchip_param
;
1881 switch (device
->tess_offchip_block_dw_size
) {
1886 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1889 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1893 switch (device
->physical_device
->rad_info
.chip_class
) {
1895 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1901 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1905 *max_offchip_buffers_p
= max_offchip_buffers
;
1906 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1907 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1908 --max_offchip_buffers
;
1910 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1911 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1914 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1916 return hs_offchip_param
;
1920 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
1921 struct radeon_winsys_bo
*esgs_ring_bo
,
1922 uint32_t esgs_ring_size
,
1923 struct radeon_winsys_bo
*gsvs_ring_bo
,
1924 uint32_t gsvs_ring_size
)
1926 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
1930 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1933 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1935 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1936 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1937 radeon_emit(cs
, esgs_ring_size
>> 8);
1938 radeon_emit(cs
, gsvs_ring_size
>> 8);
1940 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1941 radeon_emit(cs
, esgs_ring_size
>> 8);
1942 radeon_emit(cs
, gsvs_ring_size
>> 8);
1947 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
1948 unsigned hs_offchip_param
, unsigned tf_ring_size
,
1949 struct radeon_winsys_bo
*tess_rings_bo
)
1956 tf_va
= radv_buffer_get_va(tess_rings_bo
);
1958 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1960 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1961 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1962 S_030938_SIZE(tf_ring_size
/ 4));
1963 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1965 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1966 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1967 S_030944_BASE_HI(tf_va
>> 40));
1969 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
1972 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1973 S_008988_SIZE(tf_ring_size
/ 4));
1974 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1976 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1982 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
1983 struct radeon_winsys_bo
*compute_scratch_bo
)
1985 uint64_t scratch_va
;
1987 if (!compute_scratch_bo
)
1990 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1992 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1994 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1995 radeon_emit(cs
, scratch_va
);
1996 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1997 S_008F04_SWIZZLE_ENABLE(1));
2001 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2002 struct radeon_cmdbuf
*cs
,
2003 struct radeon_winsys_bo
*descriptor_bo
)
2010 va
= radv_buffer_get_va(descriptor_bo
);
2012 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
2014 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2015 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2016 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2017 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2018 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2020 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2021 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2025 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2026 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2027 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2028 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2029 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2030 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2032 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2033 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2040 radv_get_preamble_cs(struct radv_queue
*queue
,
2041 uint32_t scratch_size
,
2042 uint32_t compute_scratch_size
,
2043 uint32_t esgs_ring_size
,
2044 uint32_t gsvs_ring_size
,
2045 bool needs_tess_rings
,
2046 bool needs_sample_positions
,
2047 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2048 struct radeon_cmdbuf
**initial_preamble_cs
,
2049 struct radeon_cmdbuf
**continue_preamble_cs
)
2051 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2052 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2053 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2054 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2055 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2056 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2057 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2058 bool add_tess_rings
= false, add_sample_positions
= false;
2059 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2060 unsigned max_offchip_buffers
;
2061 unsigned hs_offchip_param
= 0;
2062 unsigned tess_offchip_ring_offset
;
2063 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2064 if (!queue
->has_tess_rings
) {
2065 if (needs_tess_rings
)
2066 add_tess_rings
= true;
2068 if (!queue
->has_sample_positions
) {
2069 if (needs_sample_positions
)
2070 add_sample_positions
= true;
2072 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2073 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2074 &max_offchip_buffers
);
2075 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2076 tess_offchip_ring_size
= max_offchip_buffers
*
2077 queue
->device
->tess_offchip_block_dw_size
* 4;
2079 if (scratch_size
<= queue
->scratch_size
&&
2080 compute_scratch_size
<= queue
->compute_scratch_size
&&
2081 esgs_ring_size
<= queue
->esgs_ring_size
&&
2082 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2083 !add_tess_rings
&& !add_sample_positions
&&
2084 queue
->initial_preamble_cs
) {
2085 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2086 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2087 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2088 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2089 *continue_preamble_cs
= NULL
;
2093 if (scratch_size
> queue
->scratch_size
) {
2094 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2102 scratch_bo
= queue
->scratch_bo
;
2104 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2105 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2106 compute_scratch_size
,
2110 if (!compute_scratch_bo
)
2114 compute_scratch_bo
= queue
->compute_scratch_bo
;
2116 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2117 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2125 esgs_ring_bo
= queue
->esgs_ring_bo
;
2126 esgs_ring_size
= queue
->esgs_ring_size
;
2129 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2130 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2138 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2139 gsvs_ring_size
= queue
->gsvs_ring_size
;
2142 if (add_tess_rings
) {
2143 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2144 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2151 tess_rings_bo
= queue
->tess_rings_bo
;
2154 if (scratch_bo
!= queue
->scratch_bo
||
2155 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2156 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2157 tess_rings_bo
!= queue
->tess_rings_bo
||
2158 add_sample_positions
) {
2160 if (gsvs_ring_bo
|| esgs_ring_bo
||
2161 tess_rings_bo
|| add_sample_positions
) {
2162 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2163 if (add_sample_positions
)
2164 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2166 else if (scratch_bo
)
2167 size
= 8; /* 2 dword */
2169 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2173 RADEON_FLAG_CPU_ACCESS
|
2174 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2175 RADEON_FLAG_READ_ONLY
);
2179 descriptor_bo
= queue
->descriptor_bo
;
2181 for(int i
= 0; i
< 3; ++i
) {
2182 struct radeon_cmdbuf
*cs
= NULL
;
2183 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2184 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2191 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2193 if (descriptor_bo
!= queue
->descriptor_bo
) {
2194 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2197 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2198 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2199 S_008F04_SWIZZLE_ENABLE(1);
2200 map
[0] = scratch_va
;
2204 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2205 add_sample_positions
)
2206 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2207 esgs_ring_size
, esgs_ring_bo
,
2208 gsvs_ring_size
, gsvs_ring_bo
,
2209 tess_factor_ring_size
,
2210 tess_offchip_ring_offset
,
2211 tess_offchip_ring_size
,
2214 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2217 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2218 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2219 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2220 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2221 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2224 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2225 gsvs_ring_bo
, gsvs_ring_size
);
2226 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2227 tess_factor_ring_size
, tess_rings_bo
);
2228 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2229 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2232 si_cs_emit_cache_flush(cs
,
2233 queue
->device
->physical_device
->rad_info
.chip_class
,
2235 queue
->queue_family_index
== RING_COMPUTE
&&
2236 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2237 (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
)) |
2238 RADV_CMD_FLAG_INV_ICACHE
|
2239 RADV_CMD_FLAG_INV_SMEM_L1
|
2240 RADV_CMD_FLAG_INV_VMEM_L1
|
2241 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2242 } else if (i
== 1) {
2243 si_cs_emit_cache_flush(cs
,
2244 queue
->device
->physical_device
->rad_info
.chip_class
,
2246 queue
->queue_family_index
== RING_COMPUTE
&&
2247 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2248 RADV_CMD_FLAG_INV_ICACHE
|
2249 RADV_CMD_FLAG_INV_SMEM_L1
|
2250 RADV_CMD_FLAG_INV_VMEM_L1
|
2251 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2254 if (!queue
->device
->ws
->cs_finalize(cs
))
2258 if (queue
->initial_full_flush_preamble_cs
)
2259 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2261 if (queue
->initial_preamble_cs
)
2262 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2264 if (queue
->continue_preamble_cs
)
2265 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2267 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2268 queue
->initial_preamble_cs
= dest_cs
[1];
2269 queue
->continue_preamble_cs
= dest_cs
[2];
2271 if (scratch_bo
!= queue
->scratch_bo
) {
2272 if (queue
->scratch_bo
)
2273 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2274 queue
->scratch_bo
= scratch_bo
;
2275 queue
->scratch_size
= scratch_size
;
2278 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2279 if (queue
->compute_scratch_bo
)
2280 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2281 queue
->compute_scratch_bo
= compute_scratch_bo
;
2282 queue
->compute_scratch_size
= compute_scratch_size
;
2285 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2286 if (queue
->esgs_ring_bo
)
2287 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2288 queue
->esgs_ring_bo
= esgs_ring_bo
;
2289 queue
->esgs_ring_size
= esgs_ring_size
;
2292 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2293 if (queue
->gsvs_ring_bo
)
2294 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2295 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2296 queue
->gsvs_ring_size
= gsvs_ring_size
;
2299 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2300 queue
->tess_rings_bo
= tess_rings_bo
;
2301 queue
->has_tess_rings
= true;
2304 if (descriptor_bo
!= queue
->descriptor_bo
) {
2305 if (queue
->descriptor_bo
)
2306 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2308 queue
->descriptor_bo
= descriptor_bo
;
2311 if (add_sample_positions
)
2312 queue
->has_sample_positions
= true;
2314 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2315 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2316 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2317 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2318 *continue_preamble_cs
= NULL
;
2321 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2323 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2324 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2325 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2326 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2327 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2328 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2329 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2330 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2331 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2332 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2333 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2334 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2335 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2336 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2339 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2340 struct radv_winsys_sem_counts
*counts
,
2342 const VkSemaphore
*sems
,
2346 int syncobj_idx
= 0, sem_idx
= 0;
2348 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2351 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2352 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2354 if (sem
->temp_syncobj
|| sem
->syncobj
)
2355 counts
->syncobj_count
++;
2357 counts
->sem_count
++;
2360 if (_fence
!= VK_NULL_HANDLE
) {
2361 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2362 if (fence
->temp_syncobj
|| fence
->syncobj
)
2363 counts
->syncobj_count
++;
2366 if (counts
->syncobj_count
) {
2367 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2368 if (!counts
->syncobj
)
2369 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2372 if (counts
->sem_count
) {
2373 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2375 free(counts
->syncobj
);
2376 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2380 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2381 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2383 if (sem
->temp_syncobj
) {
2384 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2386 else if (sem
->syncobj
)
2387 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2390 counts
->sem
[sem_idx
++] = sem
->sem
;
2394 if (_fence
!= VK_NULL_HANDLE
) {
2395 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2396 if (fence
->temp_syncobj
)
2397 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2398 else if (fence
->syncobj
)
2399 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2406 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2408 free(sem_info
->wait
.syncobj
);
2409 free(sem_info
->wait
.sem
);
2410 free(sem_info
->signal
.syncobj
);
2411 free(sem_info
->signal
.sem
);
2415 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2417 const VkSemaphore
*sems
)
2419 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2420 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2422 if (sem
->temp_syncobj
) {
2423 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2424 sem
->temp_syncobj
= 0;
2430 radv_alloc_sem_info(struct radv_instance
*instance
,
2431 struct radv_winsys_sem_info
*sem_info
,
2433 const VkSemaphore
*wait_sems
,
2434 int num_signal_sems
,
2435 const VkSemaphore
*signal_sems
,
2439 memset(sem_info
, 0, sizeof(*sem_info
));
2441 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2444 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2446 radv_free_sem_info(sem_info
);
2448 /* caller can override these */
2449 sem_info
->cs_emit_wait
= true;
2450 sem_info
->cs_emit_signal
= true;
2454 /* Signals fence as soon as all the work currently put on queue is done. */
2455 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2456 struct radv_fence
*fence
)
2460 struct radv_winsys_sem_info sem_info
;
2462 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2463 radv_fence_to_handle(fence
));
2464 if (result
!= VK_SUCCESS
)
2467 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2468 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2469 1, NULL
, NULL
, &sem_info
, NULL
,
2470 false, fence
->fence
);
2471 radv_free_sem_info(&sem_info
);
2474 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2479 VkResult
radv_QueueSubmit(
2481 uint32_t submitCount
,
2482 const VkSubmitInfo
* pSubmits
,
2485 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2486 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2487 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2488 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2490 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2491 uint32_t scratch_size
= 0;
2492 uint32_t compute_scratch_size
= 0;
2493 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2494 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2496 bool fence_emitted
= false;
2497 bool tess_rings_needed
= false;
2498 bool sample_positions_needed
= false;
2500 /* Do this first so failing to allocate scratch buffers can't result in
2501 * partially executed submissions. */
2502 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2503 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2504 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2505 pSubmits
[i
].pCommandBuffers
[j
]);
2507 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2508 compute_scratch_size
= MAX2(compute_scratch_size
,
2509 cmd_buffer
->compute_scratch_size_needed
);
2510 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2511 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2512 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2513 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2517 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2518 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2519 sample_positions_needed
, &initial_flush_preamble_cs
,
2520 &initial_preamble_cs
, &continue_preamble_cs
);
2521 if (result
!= VK_SUCCESS
)
2524 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2525 struct radeon_cmdbuf
**cs_array
;
2526 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2527 bool can_patch
= true;
2529 struct radv_winsys_sem_info sem_info
;
2531 result
= radv_alloc_sem_info(queue
->device
->instance
,
2533 pSubmits
[i
].waitSemaphoreCount
,
2534 pSubmits
[i
].pWaitSemaphores
,
2535 pSubmits
[i
].signalSemaphoreCount
,
2536 pSubmits
[i
].pSignalSemaphores
,
2538 if (result
!= VK_SUCCESS
)
2541 if (!pSubmits
[i
].commandBufferCount
) {
2542 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2543 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2544 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2549 radv_loge("failed to submit CS %d\n", i
);
2552 fence_emitted
= true;
2554 radv_free_sem_info(&sem_info
);
2558 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2559 (pSubmits
[i
].commandBufferCount
));
2561 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2562 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2563 pSubmits
[i
].pCommandBuffers
[j
]);
2564 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2566 cs_array
[j
] = cmd_buffer
->cs
;
2567 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2570 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2573 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2574 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2575 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2577 advance
= MIN2(max_cs_submission
,
2578 pSubmits
[i
].commandBufferCount
- j
);
2580 if (queue
->device
->trace_bo
)
2581 *queue
->device
->trace_id_ptr
= 0;
2583 sem_info
.cs_emit_wait
= j
== 0;
2584 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2586 if (unlikely(queue
->device
->use_global_bo_list
)) {
2587 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2588 bo_list
= &queue
->device
->bo_list
.list
;
2591 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2592 advance
, initial_preamble
, continue_preamble_cs
,
2594 can_patch
, base_fence
);
2596 if (unlikely(queue
->device
->use_global_bo_list
))
2597 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2600 radv_loge("failed to submit CS %d\n", i
);
2603 fence_emitted
= true;
2604 if (queue
->device
->trace_bo
) {
2605 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2609 radv_free_temp_syncobjs(queue
->device
,
2610 pSubmits
[i
].waitSemaphoreCount
,
2611 pSubmits
[i
].pWaitSemaphores
);
2612 radv_free_sem_info(&sem_info
);
2617 if (!fence_emitted
) {
2618 radv_signal_fence(queue
, fence
);
2620 fence
->submitted
= true;
2626 VkResult
radv_QueueWaitIdle(
2629 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2631 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2632 radv_queue_family_to_ring(queue
->queue_family_index
),
2637 VkResult
radv_DeviceWaitIdle(
2640 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2642 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2643 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2644 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2650 VkResult
radv_EnumerateInstanceExtensionProperties(
2651 const char* pLayerName
,
2652 uint32_t* pPropertyCount
,
2653 VkExtensionProperties
* pProperties
)
2655 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2657 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2658 if (radv_supported_instance_extensions
.extensions
[i
]) {
2659 vk_outarray_append(&out
, prop
) {
2660 *prop
= radv_instance_extensions
[i
];
2665 return vk_outarray_status(&out
);
2668 VkResult
radv_EnumerateDeviceExtensionProperties(
2669 VkPhysicalDevice physicalDevice
,
2670 const char* pLayerName
,
2671 uint32_t* pPropertyCount
,
2672 VkExtensionProperties
* pProperties
)
2674 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2675 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2677 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2678 if (device
->supported_extensions
.extensions
[i
]) {
2679 vk_outarray_append(&out
, prop
) {
2680 *prop
= radv_device_extensions
[i
];
2685 return vk_outarray_status(&out
);
2688 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2689 VkInstance _instance
,
2692 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2694 return radv_lookup_entrypoint_checked(pName
,
2695 instance
? instance
->apiVersion
: 0,
2696 instance
? &instance
->enabled_extensions
: NULL
,
2700 /* The loader wants us to expose a second GetInstanceProcAddr function
2701 * to work around certain LD_PRELOAD issues seen in apps.
2704 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2705 VkInstance instance
,
2709 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2710 VkInstance instance
,
2713 return radv_GetInstanceProcAddr(instance
, pName
);
2716 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2720 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2722 return radv_lookup_entrypoint_checked(pName
,
2723 device
->instance
->apiVersion
,
2724 &device
->instance
->enabled_extensions
,
2725 &device
->enabled_extensions
);
2728 bool radv_get_memory_fd(struct radv_device
*device
,
2729 struct radv_device_memory
*memory
,
2732 struct radeon_bo_metadata metadata
;
2734 if (memory
->image
) {
2735 radv_init_metadata(device
, memory
->image
, &metadata
);
2736 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2739 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2743 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2744 const VkMemoryAllocateInfo
* pAllocateInfo
,
2745 const VkAllocationCallbacks
* pAllocator
,
2746 VkDeviceMemory
* pMem
)
2748 struct radv_device_memory
*mem
;
2750 enum radeon_bo_domain domain
;
2752 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2754 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2756 if (pAllocateInfo
->allocationSize
== 0) {
2757 /* Apparently, this is allowed */
2758 *pMem
= VK_NULL_HANDLE
;
2762 const VkImportMemoryFdInfoKHR
*import_info
=
2763 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2764 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2765 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2766 const VkExportMemoryAllocateInfoKHR
*export_info
=
2767 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2768 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2769 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2771 const struct wsi_memory_allocate_info
*wsi_info
=
2772 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2774 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2775 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2777 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2779 if (wsi_info
&& wsi_info
->implicit_sync
)
2780 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2782 if (dedicate_info
) {
2783 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2784 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2790 mem
->user_ptr
= NULL
;
2793 assert(import_info
->handleType
==
2794 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2795 import_info
->handleType
==
2796 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2797 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2800 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2803 close(import_info
->fd
);
2805 } else if (host_ptr_info
) {
2806 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2807 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2808 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2809 pAllocateInfo
->allocationSize
);
2811 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2814 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2817 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2818 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2819 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2820 domain
= RADEON_DOMAIN_GTT
;
2822 domain
= RADEON_DOMAIN_VRAM
;
2824 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2825 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2827 flags
|= RADEON_FLAG_CPU_ACCESS
;
2829 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2830 flags
|= RADEON_FLAG_GTT_WC
;
2832 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2833 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2835 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2839 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2842 mem
->type_index
= mem_type_index
;
2845 result
= radv_bo_list_add(device
, mem
->bo
);
2846 if (result
!= VK_SUCCESS
)
2849 *pMem
= radv_device_memory_to_handle(mem
);
2854 device
->ws
->buffer_destroy(mem
->bo
);
2856 vk_free2(&device
->alloc
, pAllocator
, mem
);
2861 VkResult
radv_AllocateMemory(
2863 const VkMemoryAllocateInfo
* pAllocateInfo
,
2864 const VkAllocationCallbacks
* pAllocator
,
2865 VkDeviceMemory
* pMem
)
2867 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2868 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2871 void radv_FreeMemory(
2873 VkDeviceMemory _mem
,
2874 const VkAllocationCallbacks
* pAllocator
)
2876 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2877 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2882 radv_bo_list_remove(device
, mem
->bo
);
2883 device
->ws
->buffer_destroy(mem
->bo
);
2886 vk_free2(&device
->alloc
, pAllocator
, mem
);
2889 VkResult
radv_MapMemory(
2891 VkDeviceMemory _memory
,
2892 VkDeviceSize offset
,
2894 VkMemoryMapFlags flags
,
2897 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2898 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2906 *ppData
= mem
->user_ptr
;
2908 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2915 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
2918 void radv_UnmapMemory(
2920 VkDeviceMemory _memory
)
2922 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2923 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2928 if (mem
->user_ptr
== NULL
)
2929 device
->ws
->buffer_unmap(mem
->bo
);
2932 VkResult
radv_FlushMappedMemoryRanges(
2934 uint32_t memoryRangeCount
,
2935 const VkMappedMemoryRange
* pMemoryRanges
)
2940 VkResult
radv_InvalidateMappedMemoryRanges(
2942 uint32_t memoryRangeCount
,
2943 const VkMappedMemoryRange
* pMemoryRanges
)
2948 void radv_GetBufferMemoryRequirements(
2951 VkMemoryRequirements
* pMemoryRequirements
)
2953 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2954 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2956 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2958 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2959 pMemoryRequirements
->alignment
= 4096;
2961 pMemoryRequirements
->alignment
= 16;
2963 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2966 void radv_GetBufferMemoryRequirements2(
2968 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2969 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2971 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2972 &pMemoryRequirements
->memoryRequirements
);
2973 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2974 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2975 switch (ext
->sType
) {
2976 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2977 VkMemoryDedicatedRequirementsKHR
*req
=
2978 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2979 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2980 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2989 void radv_GetImageMemoryRequirements(
2992 VkMemoryRequirements
* pMemoryRequirements
)
2994 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2995 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2997 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2999 pMemoryRequirements
->size
= image
->size
;
3000 pMemoryRequirements
->alignment
= image
->alignment
;
3003 void radv_GetImageMemoryRequirements2(
3005 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
3006 VkMemoryRequirements2KHR
* pMemoryRequirements
)
3008 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3009 &pMemoryRequirements
->memoryRequirements
);
3011 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3013 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3014 switch (ext
->sType
) {
3015 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
3016 VkMemoryDedicatedRequirementsKHR
*req
=
3017 (VkMemoryDedicatedRequirementsKHR
*) ext
;
3018 req
->requiresDedicatedAllocation
= image
->shareable
;
3019 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3028 void radv_GetImageSparseMemoryRequirements(
3031 uint32_t* pSparseMemoryRequirementCount
,
3032 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3037 void radv_GetImageSparseMemoryRequirements2(
3039 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
3040 uint32_t* pSparseMemoryRequirementCount
,
3041 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
3046 void radv_GetDeviceMemoryCommitment(
3048 VkDeviceMemory memory
,
3049 VkDeviceSize
* pCommittedMemoryInBytes
)
3051 *pCommittedMemoryInBytes
= 0;
3054 VkResult
radv_BindBufferMemory2(VkDevice device
,
3055 uint32_t bindInfoCount
,
3056 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
3058 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3059 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3060 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3063 buffer
->bo
= mem
->bo
;
3064 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3072 VkResult
radv_BindBufferMemory(
3075 VkDeviceMemory memory
,
3076 VkDeviceSize memoryOffset
)
3078 const VkBindBufferMemoryInfoKHR info
= {
3079 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3082 .memoryOffset
= memoryOffset
3085 return radv_BindBufferMemory2(device
, 1, &info
);
3088 VkResult
radv_BindImageMemory2(VkDevice device
,
3089 uint32_t bindInfoCount
,
3090 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3092 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3093 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3094 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3097 image
->bo
= mem
->bo
;
3098 image
->offset
= pBindInfos
[i
].memoryOffset
;
3108 VkResult
radv_BindImageMemory(
3111 VkDeviceMemory memory
,
3112 VkDeviceSize memoryOffset
)
3114 const VkBindImageMemoryInfoKHR info
= {
3115 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3118 .memoryOffset
= memoryOffset
3121 return radv_BindImageMemory2(device
, 1, &info
);
3126 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3127 const VkSparseBufferMemoryBindInfo
*bind
)
3129 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3131 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3132 struct radv_device_memory
*mem
= NULL
;
3134 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3135 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3137 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3138 bind
->pBinds
[i
].resourceOffset
,
3139 bind
->pBinds
[i
].size
,
3140 mem
? mem
->bo
: NULL
,
3141 bind
->pBinds
[i
].memoryOffset
);
3146 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3147 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3149 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3151 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3152 struct radv_device_memory
*mem
= NULL
;
3154 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3155 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3157 device
->ws
->buffer_virtual_bind(image
->bo
,
3158 bind
->pBinds
[i
].resourceOffset
,
3159 bind
->pBinds
[i
].size
,
3160 mem
? mem
->bo
: NULL
,
3161 bind
->pBinds
[i
].memoryOffset
);
3165 VkResult
radv_QueueBindSparse(
3167 uint32_t bindInfoCount
,
3168 const VkBindSparseInfo
* pBindInfo
,
3171 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3172 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3173 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3174 bool fence_emitted
= false;
3176 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3177 struct radv_winsys_sem_info sem_info
;
3178 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3179 radv_sparse_buffer_bind_memory(queue
->device
,
3180 pBindInfo
[i
].pBufferBinds
+ j
);
3183 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3184 radv_sparse_image_opaque_bind_memory(queue
->device
,
3185 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3189 result
= radv_alloc_sem_info(queue
->device
->instance
,
3191 pBindInfo
[i
].waitSemaphoreCount
,
3192 pBindInfo
[i
].pWaitSemaphores
,
3193 pBindInfo
[i
].signalSemaphoreCount
,
3194 pBindInfo
[i
].pSignalSemaphores
,
3196 if (result
!= VK_SUCCESS
)
3199 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3200 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3201 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3205 fence_emitted
= true;
3207 fence
->submitted
= true;
3210 radv_free_sem_info(&sem_info
);
3215 if (!fence_emitted
) {
3216 radv_signal_fence(queue
, fence
);
3218 fence
->submitted
= true;
3224 VkResult
radv_CreateFence(
3226 const VkFenceCreateInfo
* pCreateInfo
,
3227 const VkAllocationCallbacks
* pAllocator
,
3230 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3231 const VkExportFenceCreateInfoKHR
*export
=
3232 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3233 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3234 export
? export
->handleTypes
: 0;
3236 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3238 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3241 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3243 fence
->submitted
= false;
3244 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3245 fence
->temp_syncobj
= 0;
3246 if (device
->always_use_syncobj
|| handleTypes
) {
3247 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3249 vk_free2(&device
->alloc
, pAllocator
, fence
);
3250 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3252 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3253 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3255 fence
->fence
= NULL
;
3257 fence
->fence
= device
->ws
->create_fence();
3258 if (!fence
->fence
) {
3259 vk_free2(&device
->alloc
, pAllocator
, fence
);
3260 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3265 *pFence
= radv_fence_to_handle(fence
);
3270 void radv_DestroyFence(
3273 const VkAllocationCallbacks
* pAllocator
)
3275 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3276 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3281 if (fence
->temp_syncobj
)
3282 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3284 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3286 device
->ws
->destroy_fence(fence
->fence
);
3287 vk_free2(&device
->alloc
, pAllocator
, fence
);
3291 static uint64_t radv_get_current_time()
3294 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3295 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3298 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3300 uint64_t current_time
= radv_get_current_time();
3302 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3304 return current_time
+ timeout
;
3308 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3310 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3311 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3312 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3318 VkResult
radv_WaitForFences(
3320 uint32_t fenceCount
,
3321 const VkFence
* pFences
,
3325 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3326 timeout
= radv_get_absolute_timeout(timeout
);
3328 if (device
->always_use_syncobj
) {
3329 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3331 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3333 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3334 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3335 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3338 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3341 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3344 if (!waitAll
&& fenceCount
> 1) {
3345 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3346 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3347 uint32_t wait_count
= 0;
3348 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3350 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3352 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3353 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3355 if (fence
->signalled
) {
3360 fences
[wait_count
++] = fence
->fence
;
3363 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3364 waitAll
, timeout
- radv_get_current_time());
3367 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3370 while(radv_get_current_time() <= timeout
) {
3371 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3372 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3379 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3380 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3381 bool expired
= false;
3383 if (fence
->temp_syncobj
) {
3384 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3389 if (fence
->syncobj
) {
3390 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3395 if (fence
->signalled
)
3398 if (!fence
->submitted
) {
3399 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3402 if (!fence
->submitted
)
3405 /* Recheck as it may have been set by submitting operations. */
3406 if (fence
->signalled
)
3410 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3414 fence
->signalled
= true;
3420 VkResult
radv_ResetFences(VkDevice _device
,
3421 uint32_t fenceCount
,
3422 const VkFence
*pFences
)
3424 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3426 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3427 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3428 fence
->submitted
= fence
->signalled
= false;
3430 /* Per spec, we first restore the permanent payload, and then reset, so
3431 * having a temp syncobj should not skip resetting the permanent syncobj. */
3432 if (fence
->temp_syncobj
) {
3433 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3434 fence
->temp_syncobj
= 0;
3437 if (fence
->syncobj
) {
3438 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3445 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3447 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3448 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3450 if (fence
->temp_syncobj
) {
3451 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3452 return success
? VK_SUCCESS
: VK_NOT_READY
;
3455 if (fence
->syncobj
) {
3456 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3457 return success
? VK_SUCCESS
: VK_NOT_READY
;
3460 if (fence
->signalled
)
3462 if (!fence
->submitted
)
3463 return VK_NOT_READY
;
3464 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3465 return VK_NOT_READY
;
3471 // Queue semaphore functions
3473 VkResult
radv_CreateSemaphore(
3475 const VkSemaphoreCreateInfo
* pCreateInfo
,
3476 const VkAllocationCallbacks
* pAllocator
,
3477 VkSemaphore
* pSemaphore
)
3479 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3480 const VkExportSemaphoreCreateInfoKHR
*export
=
3481 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3482 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3483 export
? export
->handleTypes
: 0;
3485 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3487 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3489 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3491 sem
->temp_syncobj
= 0;
3492 /* create a syncobject if we are going to export this semaphore */
3493 if (device
->always_use_syncobj
|| handleTypes
) {
3494 assert (device
->physical_device
->rad_info
.has_syncobj
);
3495 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3497 vk_free2(&device
->alloc
, pAllocator
, sem
);
3498 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3502 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3504 vk_free2(&device
->alloc
, pAllocator
, sem
);
3505 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3510 *pSemaphore
= radv_semaphore_to_handle(sem
);
3514 void radv_DestroySemaphore(
3516 VkSemaphore _semaphore
,
3517 const VkAllocationCallbacks
* pAllocator
)
3519 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3520 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3525 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3527 device
->ws
->destroy_sem(sem
->sem
);
3528 vk_free2(&device
->alloc
, pAllocator
, sem
);
3531 VkResult
radv_CreateEvent(
3533 const VkEventCreateInfo
* pCreateInfo
,
3534 const VkAllocationCallbacks
* pAllocator
,
3537 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3538 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3540 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3543 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3545 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3547 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3549 vk_free2(&device
->alloc
, pAllocator
, event
);
3550 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3553 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3555 *pEvent
= radv_event_to_handle(event
);
3560 void radv_DestroyEvent(
3563 const VkAllocationCallbacks
* pAllocator
)
3565 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3566 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3570 device
->ws
->buffer_destroy(event
->bo
);
3571 vk_free2(&device
->alloc
, pAllocator
, event
);
3574 VkResult
radv_GetEventStatus(
3578 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3580 if (*event
->map
== 1)
3581 return VK_EVENT_SET
;
3582 return VK_EVENT_RESET
;
3585 VkResult
radv_SetEvent(
3589 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3595 VkResult
radv_ResetEvent(
3599 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3605 VkResult
radv_CreateBuffer(
3607 const VkBufferCreateInfo
* pCreateInfo
,
3608 const VkAllocationCallbacks
* pAllocator
,
3611 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3612 struct radv_buffer
*buffer
;
3614 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3616 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3617 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3619 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3621 buffer
->size
= pCreateInfo
->size
;
3622 buffer
->usage
= pCreateInfo
->usage
;
3625 buffer
->flags
= pCreateInfo
->flags
;
3627 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3628 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3630 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3631 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3632 align64(buffer
->size
, 4096),
3633 4096, 0, RADEON_FLAG_VIRTUAL
);
3635 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3636 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3640 *pBuffer
= radv_buffer_to_handle(buffer
);
3645 void radv_DestroyBuffer(
3648 const VkAllocationCallbacks
* pAllocator
)
3650 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3651 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3656 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3657 device
->ws
->buffer_destroy(buffer
->bo
);
3659 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3662 static inline unsigned
3663 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3666 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3668 return image
->surface
.u
.legacy
.tiling_index
[level
];
3671 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3673 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3677 radv_init_dcc_control_reg(struct radv_device
*device
,
3678 struct radv_image_view
*iview
)
3680 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3681 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3682 unsigned max_compressed_block_size
;
3683 unsigned independent_64b_blocks
;
3685 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3688 if (iview
->image
->info
.samples
> 1) {
3689 if (iview
->image
->surface
.bpe
== 1)
3690 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3691 else if (iview
->image
->surface
.bpe
== 2)
3692 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3695 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3696 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3697 * dGPU and 64 for APU because all of our APUs to date use
3698 * DIMMs which have a request granularity size of 64B while all
3699 * other chips have a 32B request size.
3701 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3704 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3705 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3706 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3707 /* If this DCC image is potentially going to be used in texture
3708 * fetches, we need some special settings.
3710 independent_64b_blocks
= 1;
3711 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3713 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3714 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3715 * big as possible for better compression state.
3717 independent_64b_blocks
= 0;
3718 max_compressed_block_size
= max_uncompressed_block_size
;
3721 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3722 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3723 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3724 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3728 radv_initialise_color_surface(struct radv_device
*device
,
3729 struct radv_color_buffer_info
*cb
,
3730 struct radv_image_view
*iview
)
3732 const struct vk_format_description
*desc
;
3733 unsigned ntype
, format
, swap
, endian
;
3734 unsigned blend_clamp
= 0, blend_bypass
= 0;
3736 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3738 desc
= vk_format_description(iview
->vk_format
);
3740 memset(cb
, 0, sizeof(*cb
));
3742 /* Intensity is implemented as Red, so treat it that way. */
3743 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3745 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3747 cb
->cb_color_base
= va
>> 8;
3749 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3750 struct gfx9_surf_meta_flags meta
;
3751 if (iview
->image
->dcc_offset
)
3752 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3754 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3756 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3757 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3758 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3759 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3761 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3762 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3764 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3765 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3767 cb
->cb_color_base
+= level_info
->offset
>> 8;
3768 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3769 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3771 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3772 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3773 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3775 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3776 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3777 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3779 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3781 if (radv_image_has_fmask(iview
->image
)) {
3782 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3783 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3784 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3785 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3787 /* This must be set for fast clear to work without FMASK. */
3788 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3789 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3790 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3791 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3795 /* CMASK variables */
3796 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3797 va
+= iview
->image
->cmask
.offset
;
3798 cb
->cb_color_cmask
= va
>> 8;
3800 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3801 va
+= iview
->image
->dcc_offset
;
3802 cb
->cb_dcc_base
= va
>> 8;
3803 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3805 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3806 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3807 S_028C6C_SLICE_MAX(max_slice
);
3809 if (iview
->image
->info
.samples
> 1) {
3810 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3812 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3813 S_028C74_NUM_FRAGMENTS(log_samples
);
3816 if (radv_image_has_fmask(iview
->image
)) {
3817 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3818 cb
->cb_color_fmask
= va
>> 8;
3819 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3821 cb
->cb_color_fmask
= cb
->cb_color_base
;
3824 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3826 vk_format_get_first_non_void_channel(iview
->vk_format
));
3827 format
= radv_translate_colorformat(iview
->vk_format
);
3828 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3829 radv_finishme("Illegal color\n");
3830 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3831 endian
= radv_colorformat_endian_swap(format
);
3833 /* blend clamp should be set for all NORM/SRGB types */
3834 if (ntype
== V_028C70_NUMBER_UNORM
||
3835 ntype
== V_028C70_NUMBER_SNORM
||
3836 ntype
== V_028C70_NUMBER_SRGB
)
3839 /* set blend bypass according to docs if SINT/UINT or
3840 8/24 COLOR variants */
3841 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3842 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3843 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3848 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3849 (format
== V_028C70_COLOR_8
||
3850 format
== V_028C70_COLOR_8_8
||
3851 format
== V_028C70_COLOR_8_8_8_8
))
3852 ->color_is_int8
= true;
3854 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3855 S_028C70_COMP_SWAP(swap
) |
3856 S_028C70_BLEND_CLAMP(blend_clamp
) |
3857 S_028C70_BLEND_BYPASS(blend_bypass
) |
3858 S_028C70_SIMPLE_FLOAT(1) |
3859 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3860 ntype
!= V_028C70_NUMBER_SNORM
&&
3861 ntype
!= V_028C70_NUMBER_SRGB
&&
3862 format
!= V_028C70_COLOR_8_24
&&
3863 format
!= V_028C70_COLOR_24_8
) |
3864 S_028C70_NUMBER_TYPE(ntype
) |
3865 S_028C70_ENDIAN(endian
);
3866 if (radv_image_has_fmask(iview
->image
)) {
3867 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3868 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3869 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3870 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3874 if (radv_image_has_cmask(iview
->image
) &&
3875 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3876 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3878 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3879 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3881 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3883 /* This must be set for fast clear to work without FMASK. */
3884 if (!radv_image_has_fmask(iview
->image
) &&
3885 device
->physical_device
->rad_info
.chip_class
== SI
) {
3886 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3887 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3890 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3891 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3892 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3894 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3895 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3896 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3897 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3898 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3899 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3904 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3905 struct radv_image_view
*iview
)
3907 unsigned max_zplanes
= 0;
3909 assert(radv_image_is_tc_compat_htile(iview
->image
));
3911 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3912 /* Default value for 32-bit depth surfaces. */
3915 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3916 iview
->image
->info
.samples
> 1)
3919 max_zplanes
= max_zplanes
+ 1;
3921 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3922 /* Do not enable Z plane compression for 16-bit depth
3923 * surfaces because isn't supported on GFX8. Only
3924 * 32-bit depth surfaces are supported by the hardware.
3925 * This allows to maintain shader compatibility and to
3926 * reduce the number of depth decompressions.
3930 if (iview
->image
->info
.samples
<= 1)
3932 else if (iview
->image
->info
.samples
<= 4)
3943 radv_initialise_ds_surface(struct radv_device
*device
,
3944 struct radv_ds_buffer_info
*ds
,
3945 struct radv_image_view
*iview
)
3947 unsigned level
= iview
->base_mip
;
3948 unsigned format
, stencil_format
;
3949 uint64_t va
, s_offs
, z_offs
;
3950 bool stencil_only
= false;
3951 memset(ds
, 0, sizeof(*ds
));
3952 switch (iview
->image
->vk_format
) {
3953 case VK_FORMAT_D24_UNORM_S8_UINT
:
3954 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3955 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3956 ds
->offset_scale
= 2.0f
;
3958 case VK_FORMAT_D16_UNORM
:
3959 case VK_FORMAT_D16_UNORM_S8_UINT
:
3960 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3961 ds
->offset_scale
= 4.0f
;
3963 case VK_FORMAT_D32_SFLOAT
:
3964 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3965 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3966 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3967 ds
->offset_scale
= 1.0f
;
3969 case VK_FORMAT_S8_UINT
:
3970 stencil_only
= true;
3976 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3977 stencil_format
= iview
->image
->surface
.has_stencil
?
3978 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3980 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3981 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3982 S_028008_SLICE_MAX(max_slice
);
3984 ds
->db_htile_data_base
= 0;
3985 ds
->db_htile_surface
= 0;
3987 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3988 s_offs
= z_offs
= va
;
3990 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3991 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3992 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3994 ds
->db_z_info
= S_028038_FORMAT(format
) |
3995 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3996 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3997 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
3998 S_028038_ZRANGE_PRECISION(1);
3999 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4000 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
4002 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
4003 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
4004 ds
->db_depth_view
|= S_028008_MIPID(level
);
4006 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4007 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4009 if (radv_htile_enabled(iview
->image
, level
)) {
4010 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4012 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4013 unsigned max_zplanes
=
4014 radv_calc_decompress_on_z_planes(device
, iview
);
4016 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4017 S_028038_ITERATE_FLUSH(1);
4018 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4021 if (!iview
->image
->surface
.has_stencil
)
4022 /* Use all of the htile_buffer for depth if there's no stencil. */
4023 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4024 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4025 iview
->image
->htile_offset
;
4026 ds
->db_htile_data_base
= va
>> 8;
4027 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4028 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4029 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4032 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4035 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4037 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4038 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4040 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4041 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4042 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4044 if (iview
->image
->info
.samples
> 1)
4045 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4047 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4048 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4049 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4050 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4051 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4052 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4053 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4054 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4057 tile_mode
= stencil_tile_mode
;
4059 ds
->db_depth_info
|=
4060 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4061 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4062 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4063 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4064 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4065 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4066 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4067 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4069 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4070 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4071 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4072 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4074 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4077 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4078 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4079 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4081 if (radv_htile_enabled(iview
->image
, level
)) {
4082 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4084 if (!iview
->image
->surface
.has_stencil
&&
4085 !radv_image_is_tc_compat_htile(iview
->image
))
4086 /* Use all of the htile_buffer for depth if there's no stencil. */
4087 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4089 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4090 iview
->image
->htile_offset
;
4091 ds
->db_htile_data_base
= va
>> 8;
4092 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4094 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4095 unsigned max_zplanes
=
4096 radv_calc_decompress_on_z_planes(device
, iview
);
4098 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4099 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4104 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4105 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4108 VkResult
radv_CreateFramebuffer(
4110 const VkFramebufferCreateInfo
* pCreateInfo
,
4111 const VkAllocationCallbacks
* pAllocator
,
4112 VkFramebuffer
* pFramebuffer
)
4114 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4115 struct radv_framebuffer
*framebuffer
;
4117 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4119 size_t size
= sizeof(*framebuffer
) +
4120 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4121 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4122 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4123 if (framebuffer
== NULL
)
4124 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4126 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4127 framebuffer
->width
= pCreateInfo
->width
;
4128 framebuffer
->height
= pCreateInfo
->height
;
4129 framebuffer
->layers
= pCreateInfo
->layers
;
4130 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4131 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4132 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4133 framebuffer
->attachments
[i
].attachment
= iview
;
4134 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4135 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4136 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4137 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4139 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4140 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4141 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4144 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4148 void radv_DestroyFramebuffer(
4151 const VkAllocationCallbacks
* pAllocator
)
4153 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4154 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4158 vk_free2(&device
->alloc
, pAllocator
, fb
);
4161 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4163 switch (address_mode
) {
4164 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4165 return V_008F30_SQ_TEX_WRAP
;
4166 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4167 return V_008F30_SQ_TEX_MIRROR
;
4168 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4169 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4170 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4171 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4172 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4173 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4175 unreachable("illegal tex wrap mode");
4181 radv_tex_compare(VkCompareOp op
)
4184 case VK_COMPARE_OP_NEVER
:
4185 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4186 case VK_COMPARE_OP_LESS
:
4187 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4188 case VK_COMPARE_OP_EQUAL
:
4189 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4190 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4191 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4192 case VK_COMPARE_OP_GREATER
:
4193 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4194 case VK_COMPARE_OP_NOT_EQUAL
:
4195 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4196 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4197 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4198 case VK_COMPARE_OP_ALWAYS
:
4199 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4201 unreachable("illegal compare mode");
4207 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4210 case VK_FILTER_NEAREST
:
4211 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4212 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4213 case VK_FILTER_LINEAR
:
4214 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4215 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4216 case VK_FILTER_CUBIC_IMG
:
4218 fprintf(stderr
, "illegal texture filter");
4224 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4227 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4228 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4229 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4230 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4232 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4237 radv_tex_bordercolor(VkBorderColor bcolor
)
4240 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4241 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4242 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4243 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4244 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4245 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4246 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4247 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4248 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4256 radv_tex_aniso_filter(unsigned filter
)
4270 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4273 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4274 return SQ_IMG_FILTER_MODE_BLEND
;
4275 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4276 return SQ_IMG_FILTER_MODE_MIN
;
4277 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4278 return SQ_IMG_FILTER_MODE_MAX
;
4286 radv_init_sampler(struct radv_device
*device
,
4287 struct radv_sampler
*sampler
,
4288 const VkSamplerCreateInfo
*pCreateInfo
)
4290 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4291 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4292 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4293 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4294 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4296 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4297 vk_find_struct_const(pCreateInfo
->pNext
,
4298 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4299 if (sampler_reduction
)
4300 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4302 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4303 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4304 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4305 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4306 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4307 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4308 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4309 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4310 S_008F30_DISABLE_CUBE_WRAP(0) |
4311 S_008F30_COMPAT_MODE(is_vi
) |
4312 S_008F30_FILTER_MODE(filter_mode
));
4313 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4314 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4315 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4316 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4317 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4318 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4319 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4320 S_008F38_MIP_POINT_PRECLAMP(0) |
4321 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4322 S_008F38_FILTER_PREC_FIX(1) |
4323 S_008F38_ANISO_OVERRIDE(is_vi
));
4324 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4325 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4328 VkResult
radv_CreateSampler(
4330 const VkSamplerCreateInfo
* pCreateInfo
,
4331 const VkAllocationCallbacks
* pAllocator
,
4332 VkSampler
* pSampler
)
4334 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4335 struct radv_sampler
*sampler
;
4337 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4339 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4340 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4342 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4344 radv_init_sampler(device
, sampler
, pCreateInfo
);
4345 *pSampler
= radv_sampler_to_handle(sampler
);
4350 void radv_DestroySampler(
4353 const VkAllocationCallbacks
* pAllocator
)
4355 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4356 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4360 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4363 /* vk_icd.h does not declare this function, so we declare it here to
4364 * suppress Wmissing-prototypes.
4366 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4367 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4369 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4370 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4372 /* For the full details on loader interface versioning, see
4373 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4374 * What follows is a condensed summary, to help you navigate the large and
4375 * confusing official doc.
4377 * - Loader interface v0 is incompatible with later versions. We don't
4380 * - In loader interface v1:
4381 * - The first ICD entrypoint called by the loader is
4382 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4384 * - The ICD must statically expose no other Vulkan symbol unless it is
4385 * linked with -Bsymbolic.
4386 * - Each dispatchable Vulkan handle created by the ICD must be
4387 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4388 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4389 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4390 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4391 * such loader-managed surfaces.
4393 * - Loader interface v2 differs from v1 in:
4394 * - The first ICD entrypoint called by the loader is
4395 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4396 * statically expose this entrypoint.
4398 * - Loader interface v3 differs from v2 in:
4399 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4400 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4401 * because the loader no longer does so.
4403 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4407 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4408 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4411 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4412 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4414 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4416 /* At the moment, we support only the below handle types. */
4417 assert(pGetFdInfo
->handleType
==
4418 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4419 pGetFdInfo
->handleType
==
4420 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4422 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4424 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4428 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4429 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4431 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4433 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4435 switch (handleType
) {
4436 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4437 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4441 /* The valid usage section for this function says:
4443 * "handleType must not be one of the handle types defined as
4446 * So opaque handle types fall into the default "unsupported" case.
4448 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4452 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4456 uint32_t syncobj_handle
= 0;
4457 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4459 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4462 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4464 *syncobj
= syncobj_handle
;
4470 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4474 /* If we create a syncobj we do it locally so that if we have an error, we don't
4475 * leave a syncobj in an undetermined state in the fence. */
4476 uint32_t syncobj_handle
= *syncobj
;
4477 if (!syncobj_handle
) {
4478 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4480 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4485 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4487 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4489 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4492 *syncobj
= syncobj_handle
;
4499 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4500 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4502 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4503 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4504 uint32_t *syncobj_dst
= NULL
;
4506 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4507 syncobj_dst
= &sem
->temp_syncobj
;
4509 syncobj_dst
= &sem
->syncobj
;
4512 switch(pImportSemaphoreFdInfo
->handleType
) {
4513 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4514 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4515 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4516 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4518 unreachable("Unhandled semaphore handle type");
4522 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4523 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4526 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4527 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4529 uint32_t syncobj_handle
;
4531 if (sem
->temp_syncobj
)
4532 syncobj_handle
= sem
->temp_syncobj
;
4534 syncobj_handle
= sem
->syncobj
;
4536 switch(pGetFdInfo
->handleType
) {
4537 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4538 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4540 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4541 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4543 if (sem
->temp_syncobj
) {
4544 close (sem
->temp_syncobj
);
4545 sem
->temp_syncobj
= 0;
4547 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4552 unreachable("Unhandled semaphore handle type");
4556 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4560 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4561 VkPhysicalDevice physicalDevice
,
4562 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4563 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4565 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4567 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4568 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4569 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4570 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4571 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4572 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4573 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4574 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4575 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4576 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4577 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4578 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4579 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4581 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4582 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4583 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4587 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4588 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4590 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4591 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4592 uint32_t *syncobj_dst
= NULL
;
4595 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4596 syncobj_dst
= &fence
->temp_syncobj
;
4598 syncobj_dst
= &fence
->syncobj
;
4601 switch(pImportFenceFdInfo
->handleType
) {
4602 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4603 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4604 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4605 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4607 unreachable("Unhandled fence handle type");
4611 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4612 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4615 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4616 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4618 uint32_t syncobj_handle
;
4620 if (fence
->temp_syncobj
)
4621 syncobj_handle
= fence
->temp_syncobj
;
4623 syncobj_handle
= fence
->syncobj
;
4625 switch(pGetFdInfo
->handleType
) {
4626 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4627 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4629 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4630 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4632 if (fence
->temp_syncobj
) {
4633 close (fence
->temp_syncobj
);
4634 fence
->temp_syncobj
= 0;
4636 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4641 unreachable("Unhandled fence handle type");
4645 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4649 void radv_GetPhysicalDeviceExternalFenceProperties(
4650 VkPhysicalDevice physicalDevice
,
4651 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4652 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4654 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4656 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4657 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4658 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4659 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4660 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4661 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4662 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4664 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4665 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4666 pExternalFenceProperties
->externalFenceFeatures
= 0;
4671 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4672 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4673 const VkAllocationCallbacks
* pAllocator
,
4674 VkDebugReportCallbackEXT
* pCallback
)
4676 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4677 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4678 pCreateInfo
, pAllocator
, &instance
->alloc
,
4683 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4684 VkDebugReportCallbackEXT _callback
,
4685 const VkAllocationCallbacks
* pAllocator
)
4687 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4688 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4689 _callback
, pAllocator
, &instance
->alloc
);
4693 radv_DebugReportMessageEXT(VkInstance _instance
,
4694 VkDebugReportFlagsEXT flags
,
4695 VkDebugReportObjectTypeEXT objectType
,
4698 int32_t messageCode
,
4699 const char* pLayerPrefix
,
4700 const char* pMessage
)
4702 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4703 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4704 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4708 radv_GetDeviceGroupPeerMemoryFeatures(
4711 uint32_t localDeviceIndex
,
4712 uint32_t remoteDeviceIndex
,
4713 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4715 assert(localDeviceIndex
== remoteDeviceIndex
);
4717 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4718 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4719 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4720 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;