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;
112 snprintf(llvm_string
, sizeof(llvm_string
),
113 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
114 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
117 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
121 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
123 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
124 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
125 device
->rad_info
.vram_vis_size
);
127 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
128 device
->memory_properties
.memoryHeapCount
= 0;
129 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
130 vram_index
= device
->memory_properties
.memoryHeapCount
++;
131 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
132 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
133 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
136 if (visible_vram_size
) {
137 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
138 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
139 .size
= visible_vram_size
,
140 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
143 if (device
->rad_info
.gart_size
> 0) {
144 gart_index
= device
->memory_properties
.memoryHeapCount
++;
145 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
146 .size
= device
->rad_info
.gart_size
,
147 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
151 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
152 unsigned type_count
= 0;
153 if (vram_index
>= 0) {
154 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
155 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
156 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
157 .heapIndex
= vram_index
,
160 if (gart_index
>= 0) {
161 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
162 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
163 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
164 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
165 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
166 .heapIndex
= gart_index
,
169 if (visible_vram_index
>= 0) {
170 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
171 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
172 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
173 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
174 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
175 .heapIndex
= visible_vram_index
,
178 if (gart_index
>= 0) {
179 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
180 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
181 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
182 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
183 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
184 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
185 .heapIndex
= gart_index
,
188 device
->memory_properties
.memoryTypeCount
= type_count
;
192 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
194 const char *family
= getenv("RADV_FORCE_FAMILY");
200 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
201 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
202 /* Override family and chip_class. */
203 device
->rad_info
.family
= i
;
205 if (i
>= CHIP_VEGA10
)
206 device
->rad_info
.chip_class
= GFX9
;
207 else if (i
>= CHIP_TONGA
)
208 device
->rad_info
.chip_class
= VI
;
209 else if (i
>= CHIP_BONAIRE
)
210 device
->rad_info
.chip_class
= CIK
;
212 device
->rad_info
.chip_class
= SI
;
218 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
223 radv_physical_device_init(struct radv_physical_device
*device
,
224 struct radv_instance
*instance
,
225 drmDevicePtr drm_device
)
227 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
229 drmVersionPtr version
;
232 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
234 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
236 version
= drmGetVersion(fd
);
239 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
240 "failed to get version %s: %m", path
);
243 if (strcmp(version
->name
, "amdgpu")) {
244 drmFreeVersion(version
);
246 return VK_ERROR_INCOMPATIBLE_DRIVER
;
248 drmFreeVersion(version
);
250 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
251 device
->instance
= instance
;
252 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
253 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
255 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
256 instance
->perftest_flags
);
258 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
262 device
->local_fd
= fd
;
263 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
265 radv_handle_env_var_force_family(device
);
267 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
269 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
270 device
->ws
->destroy(device
->ws
);
271 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
272 "cannot generate UUID");
276 /* These flags affect shader compilation. */
277 uint64_t shader_env_flags
=
278 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
279 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
281 /* The gpu id is already embeded in the uuid so we just pass "radv"
282 * when creating the cache.
284 char buf
[VK_UUID_SIZE
* 2 + 1];
285 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
286 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
288 if (device
->rad_info
.chip_class
< VI
||
289 device
->rad_info
.chip_class
> GFX9
)
290 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
292 radv_get_driver_uuid(&device
->device_uuid
);
293 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
295 if (device
->rad_info
.family
== CHIP_STONEY
||
296 device
->rad_info
.chip_class
>= GFX9
) {
297 device
->has_rbplus
= true;
298 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
299 device
->rad_info
.family
== CHIP_VEGA12
||
300 device
->rad_info
.family
== CHIP_RAVEN
;
303 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
306 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
308 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
310 /* Vega10/Raven need a special workaround for a hardware bug. */
311 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
312 device
->rad_info
.family
== CHIP_RAVEN
;
314 /* Out-of-order primitive rasterization. */
315 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
316 device
->rad_info
.max_se
>= 2;
317 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
318 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
320 device
->dcc_msaa_allowed
= device
->rad_info
.chip_class
== VI
&&
321 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
323 radv_physical_device_init_mem_types(device
);
324 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
326 result
= radv_init_wsi(device
);
327 if (result
!= VK_SUCCESS
) {
328 device
->ws
->destroy(device
->ws
);
340 radv_physical_device_finish(struct radv_physical_device
*device
)
342 radv_finish_wsi(device
);
343 device
->ws
->destroy(device
->ws
);
344 disk_cache_destroy(device
->disk_cache
);
345 close(device
->local_fd
);
349 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
350 VkSystemAllocationScope allocationScope
)
356 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
357 size_t align
, VkSystemAllocationScope allocationScope
)
359 return realloc(pOriginal
, size
);
363 default_free_func(void *pUserData
, void *pMemory
)
368 static const VkAllocationCallbacks default_alloc
= {
370 .pfnAllocation
= default_alloc_func
,
371 .pfnReallocation
= default_realloc_func
,
372 .pfnFree
= default_free_func
,
375 static const struct debug_control radv_debug_options
[] = {
376 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
377 {"nodcc", RADV_DEBUG_NO_DCC
},
378 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
379 {"nocache", RADV_DEBUG_NO_CACHE
},
380 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
381 {"nohiz", RADV_DEBUG_NO_HIZ
},
382 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
383 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
384 {"allbos", RADV_DEBUG_ALL_BOS
},
385 {"noibs", RADV_DEBUG_NO_IBS
},
386 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
387 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
388 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
389 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
390 {"nosisched", RADV_DEBUG_NO_SISCHED
},
391 {"preoptir", RADV_DEBUG_PREOPTIR
},
392 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
393 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
398 radv_get_debug_option_name(int id
)
400 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
401 return radv_debug_options
[id
].string
;
404 static const struct debug_control radv_perftest_options
[] = {
405 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
406 {"sisched", RADV_PERFTEST_SISCHED
},
407 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
408 {"binning", RADV_PERFTEST_BINNING
},
409 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
414 radv_get_perftest_option_name(int id
)
416 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
417 return radv_perftest_options
[id
].string
;
421 radv_handle_per_app_options(struct radv_instance
*instance
,
422 const VkApplicationInfo
*info
)
424 const char *name
= info
? info
->pApplicationName
: NULL
;
429 if (!strcmp(name
, "Talos - Linux - 32bit") ||
430 !strcmp(name
, "Talos - Linux - 64bit")) {
431 /* Force enable LLVM sisched for Talos because it looks safe
432 * and it gives few more FPS.
434 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
438 static int radv_get_instance_extension_index(const char *name
)
440 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
441 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
448 VkResult
radv_CreateInstance(
449 const VkInstanceCreateInfo
* pCreateInfo
,
450 const VkAllocationCallbacks
* pAllocator
,
451 VkInstance
* pInstance
)
453 struct radv_instance
*instance
;
456 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
458 uint32_t client_version
;
459 if (pCreateInfo
->pApplicationInfo
&&
460 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
461 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
463 client_version
= VK_MAKE_VERSION(1, 0, 0);
466 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
467 client_version
> VK_MAKE_VERSION(1, 1, 0xfff)) {
468 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
469 "Client requested version %d.%d.%d",
470 VK_VERSION_MAJOR(client_version
),
471 VK_VERSION_MINOR(client_version
),
472 VK_VERSION_PATCH(client_version
));
475 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
476 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
478 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
480 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
483 instance
->alloc
= *pAllocator
;
485 instance
->alloc
= default_alloc
;
487 instance
->apiVersion
= client_version
;
488 instance
->physicalDeviceCount
= -1;
490 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
491 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
492 int index
= radv_get_instance_extension_index(ext_name
);
494 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
495 vk_free2(&default_alloc
, pAllocator
, instance
);
496 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
499 instance
->enabled_extensions
.extensions
[index
] = true;
502 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
503 if (result
!= VK_SUCCESS
) {
504 vk_free2(&default_alloc
, pAllocator
, instance
);
505 return vk_error(result
);
510 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
512 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
515 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
516 radv_perftest_options
);
518 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
520 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
521 /* Disable sisched when the user requests it, this is mostly
522 * useful when the driver force-enable sisched for the given
525 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
528 *pInstance
= radv_instance_to_handle(instance
);
533 void radv_DestroyInstance(
534 VkInstance _instance
,
535 const VkAllocationCallbacks
* pAllocator
)
537 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
542 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
543 radv_physical_device_finish(instance
->physicalDevices
+ i
);
546 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
550 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
552 vk_free(&instance
->alloc
, instance
);
556 radv_enumerate_devices(struct radv_instance
*instance
)
558 /* TODO: Check for more devices ? */
559 drmDevicePtr devices
[8];
560 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
563 instance
->physicalDeviceCount
= 0;
565 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
567 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
569 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
570 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
571 devices
[i
]->bustype
== DRM_BUS_PCI
&&
572 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
574 result
= radv_physical_device_init(instance
->physicalDevices
+
575 instance
->physicalDeviceCount
,
578 if (result
== VK_SUCCESS
)
579 ++instance
->physicalDeviceCount
;
580 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
584 drmFreeDevices(devices
, max_devices
);
589 VkResult
radv_EnumeratePhysicalDevices(
590 VkInstance _instance
,
591 uint32_t* pPhysicalDeviceCount
,
592 VkPhysicalDevice
* pPhysicalDevices
)
594 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
597 if (instance
->physicalDeviceCount
< 0) {
598 result
= radv_enumerate_devices(instance
);
599 if (result
!= VK_SUCCESS
&&
600 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
604 if (!pPhysicalDevices
) {
605 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
607 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
608 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
609 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
612 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
616 VkResult
radv_EnumeratePhysicalDeviceGroups(
617 VkInstance _instance
,
618 uint32_t* pPhysicalDeviceGroupCount
,
619 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
621 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
624 if (instance
->physicalDeviceCount
< 0) {
625 result
= radv_enumerate_devices(instance
);
626 if (result
!= VK_SUCCESS
&&
627 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
631 if (!pPhysicalDeviceGroupProperties
) {
632 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
634 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
635 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
636 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
637 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
638 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
641 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
645 void radv_GetPhysicalDeviceFeatures(
646 VkPhysicalDevice physicalDevice
,
647 VkPhysicalDeviceFeatures
* pFeatures
)
649 memset(pFeatures
, 0, sizeof(*pFeatures
));
651 *pFeatures
= (VkPhysicalDeviceFeatures
) {
652 .robustBufferAccess
= true,
653 .fullDrawIndexUint32
= true,
654 .imageCubeArray
= true,
655 .independentBlend
= true,
656 .geometryShader
= true,
657 .tessellationShader
= true,
658 .sampleRateShading
= true,
659 .dualSrcBlend
= true,
661 .multiDrawIndirect
= true,
662 .drawIndirectFirstInstance
= true,
664 .depthBiasClamp
= true,
665 .fillModeNonSolid
= true,
670 .multiViewport
= true,
671 .samplerAnisotropy
= true,
672 .textureCompressionETC2
= false,
673 .textureCompressionASTC_LDR
= false,
674 .textureCompressionBC
= true,
675 .occlusionQueryPrecise
= true,
676 .pipelineStatisticsQuery
= true,
677 .vertexPipelineStoresAndAtomics
= true,
678 .fragmentStoresAndAtomics
= true,
679 .shaderTessellationAndGeometryPointSize
= true,
680 .shaderImageGatherExtended
= true,
681 .shaderStorageImageExtendedFormats
= true,
682 .shaderStorageImageMultisample
= false,
683 .shaderUniformBufferArrayDynamicIndexing
= true,
684 .shaderSampledImageArrayDynamicIndexing
= true,
685 .shaderStorageBufferArrayDynamicIndexing
= true,
686 .shaderStorageImageArrayDynamicIndexing
= true,
687 .shaderStorageImageReadWithoutFormat
= true,
688 .shaderStorageImageWriteWithoutFormat
= true,
689 .shaderClipDistance
= true,
690 .shaderCullDistance
= true,
691 .shaderFloat64
= true,
693 .shaderInt16
= false,
694 .sparseBinding
= true,
695 .variableMultisampleRate
= true,
696 .inheritedQueries
= true,
700 void radv_GetPhysicalDeviceFeatures2(
701 VkPhysicalDevice physicalDevice
,
702 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
704 vk_foreach_struct(ext
, pFeatures
->pNext
) {
705 switch (ext
->sType
) {
706 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
707 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
708 features
->variablePointersStorageBuffer
= true;
709 features
->variablePointers
= false;
712 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
713 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
714 features
->multiview
= true;
715 features
->multiviewGeometryShader
= true;
716 features
->multiviewTessellationShader
= true;
719 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
720 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
721 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
722 features
->shaderDrawParameters
= true;
725 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
726 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
727 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
728 features
->protectedMemory
= false;
731 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
732 VkPhysicalDevice16BitStorageFeatures
*features
=
733 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
734 features
->storageBuffer16BitAccess
= false;
735 features
->uniformAndStorageBuffer16BitAccess
= false;
736 features
->storagePushConstant16
= false;
737 features
->storageInputOutput16
= false;
740 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
741 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
742 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
743 features
->samplerYcbcrConversion
= false;
746 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
747 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
748 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)features
;
749 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
750 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
751 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
752 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
753 features
->shaderSampledImageArrayNonUniformIndexing
= false;
754 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
755 features
->shaderStorageImageArrayNonUniformIndexing
= false;
756 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
757 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
758 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
759 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
760 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
761 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
762 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
763 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
764 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
765 features
->descriptorBindingUpdateUnusedWhilePending
= true;
766 features
->descriptorBindingPartiallyBound
= true;
767 features
->descriptorBindingVariableDescriptorCount
= true;
768 features
->runtimeDescriptorArray
= true;
775 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
778 void radv_GetPhysicalDeviceProperties(
779 VkPhysicalDevice physicalDevice
,
780 VkPhysicalDeviceProperties
* pProperties
)
782 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
783 VkSampleCountFlags sample_counts
= 0xf;
785 /* make sure that the entire descriptor set is addressable with a signed
786 * 32-bit int. So the sum of all limits scaled by descriptor size has to
787 * be at most 2 GiB. the combined image & samples object count as one of
788 * both. This limit is for the pipeline layout, not for the set layout, but
789 * there is no set limit, so we just set a pipeline limit. I don't think
790 * any app is going to hit this soon. */
791 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
792 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
793 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
794 32 /* sampler, largest when combined with image */ +
795 64 /* sampled image */ +
796 64 /* storage image */);
798 VkPhysicalDeviceLimits limits
= {
799 .maxImageDimension1D
= (1 << 14),
800 .maxImageDimension2D
= (1 << 14),
801 .maxImageDimension3D
= (1 << 11),
802 .maxImageDimensionCube
= (1 << 14),
803 .maxImageArrayLayers
= (1 << 11),
804 .maxTexelBufferElements
= 128 * 1024 * 1024,
805 .maxUniformBufferRange
= UINT32_MAX
,
806 .maxStorageBufferRange
= UINT32_MAX
,
807 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
808 .maxMemoryAllocationCount
= UINT32_MAX
,
809 .maxSamplerAllocationCount
= 64 * 1024,
810 .bufferImageGranularity
= 64, /* A cache line */
811 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
812 .maxBoundDescriptorSets
= MAX_SETS
,
813 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
814 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
815 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
816 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
817 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
818 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
819 .maxPerStageResources
= max_descriptor_set_size
,
820 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
821 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
822 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
823 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
824 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
825 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
826 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
827 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
828 .maxVertexInputAttributes
= 32,
829 .maxVertexInputBindings
= 32,
830 .maxVertexInputAttributeOffset
= 2047,
831 .maxVertexInputBindingStride
= 2048,
832 .maxVertexOutputComponents
= 128,
833 .maxTessellationGenerationLevel
= 64,
834 .maxTessellationPatchSize
= 32,
835 .maxTessellationControlPerVertexInputComponents
= 128,
836 .maxTessellationControlPerVertexOutputComponents
= 128,
837 .maxTessellationControlPerPatchOutputComponents
= 120,
838 .maxTessellationControlTotalOutputComponents
= 4096,
839 .maxTessellationEvaluationInputComponents
= 128,
840 .maxTessellationEvaluationOutputComponents
= 128,
841 .maxGeometryShaderInvocations
= 127,
842 .maxGeometryInputComponents
= 64,
843 .maxGeometryOutputComponents
= 128,
844 .maxGeometryOutputVertices
= 256,
845 .maxGeometryTotalOutputComponents
= 1024,
846 .maxFragmentInputComponents
= 128,
847 .maxFragmentOutputAttachments
= 8,
848 .maxFragmentDualSrcAttachments
= 1,
849 .maxFragmentCombinedOutputResources
= 8,
850 .maxComputeSharedMemorySize
= 32768,
851 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
852 .maxComputeWorkGroupInvocations
= 2048,
853 .maxComputeWorkGroupSize
= {
858 .subPixelPrecisionBits
= 4 /* FIXME */,
859 .subTexelPrecisionBits
= 4 /* FIXME */,
860 .mipmapPrecisionBits
= 4 /* FIXME */,
861 .maxDrawIndexedIndexValue
= UINT32_MAX
,
862 .maxDrawIndirectCount
= UINT32_MAX
,
863 .maxSamplerLodBias
= 16,
864 .maxSamplerAnisotropy
= 16,
865 .maxViewports
= MAX_VIEWPORTS
,
866 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
867 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
868 .viewportSubPixelBits
= 8,
869 .minMemoryMapAlignment
= 4096, /* A page */
870 .minTexelBufferOffsetAlignment
= 1,
871 .minUniformBufferOffsetAlignment
= 4,
872 .minStorageBufferOffsetAlignment
= 4,
873 .minTexelOffset
= -32,
874 .maxTexelOffset
= 31,
875 .minTexelGatherOffset
= -32,
876 .maxTexelGatherOffset
= 31,
877 .minInterpolationOffset
= -2,
878 .maxInterpolationOffset
= 2,
879 .subPixelInterpolationOffsetBits
= 8,
880 .maxFramebufferWidth
= (1 << 14),
881 .maxFramebufferHeight
= (1 << 14),
882 .maxFramebufferLayers
= (1 << 10),
883 .framebufferColorSampleCounts
= sample_counts
,
884 .framebufferDepthSampleCounts
= sample_counts
,
885 .framebufferStencilSampleCounts
= sample_counts
,
886 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
887 .maxColorAttachments
= MAX_RTS
,
888 .sampledImageColorSampleCounts
= sample_counts
,
889 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
890 .sampledImageDepthSampleCounts
= sample_counts
,
891 .sampledImageStencilSampleCounts
= sample_counts
,
892 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
893 .maxSampleMaskWords
= 1,
894 .timestampComputeAndGraphics
= true,
895 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
896 .maxClipDistances
= 8,
897 .maxCullDistances
= 8,
898 .maxCombinedClipAndCullDistances
= 8,
899 .discreteQueuePriorities
= 1,
900 .pointSizeRange
= { 0.125, 255.875 },
901 .lineWidthRange
= { 0.0, 7.9921875 },
902 .pointSizeGranularity
= (1.0 / 8.0),
903 .lineWidthGranularity
= (1.0 / 128.0),
904 .strictLines
= false, /* FINISHME */
905 .standardSampleLocations
= true,
906 .optimalBufferCopyOffsetAlignment
= 128,
907 .optimalBufferCopyRowPitchAlignment
= 128,
908 .nonCoherentAtomSize
= 64,
911 *pProperties
= (VkPhysicalDeviceProperties
) {
912 .apiVersion
= radv_physical_device_api_version(pdevice
),
913 .driverVersion
= vk_get_driver_version(),
914 .vendorID
= ATI_VENDOR_ID
,
915 .deviceID
= pdevice
->rad_info
.pci_id
,
916 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
918 .sparseProperties
= {0},
921 strcpy(pProperties
->deviceName
, pdevice
->name
);
922 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
925 void radv_GetPhysicalDeviceProperties2(
926 VkPhysicalDevice physicalDevice
,
927 VkPhysicalDeviceProperties2KHR
*pProperties
)
929 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
930 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
932 vk_foreach_struct(ext
, pProperties
->pNext
) {
933 switch (ext
->sType
) {
934 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
935 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
936 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
937 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
940 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
941 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
942 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
943 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
944 properties
->deviceLUIDValid
= false;
947 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
948 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
949 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
950 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
953 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
954 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
955 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
956 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
959 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
960 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
961 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
962 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
965 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
966 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
967 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
968 properties
->minImportedHostPointerAlignment
= 4096;
971 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
972 VkPhysicalDeviceSubgroupProperties
*properties
=
973 (VkPhysicalDeviceSubgroupProperties
*)ext
;
974 properties
->subgroupSize
= 64;
975 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
976 properties
->supportedOperations
=
977 VK_SUBGROUP_FEATURE_BASIC_BIT
|
978 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
979 VK_SUBGROUP_FEATURE_QUAD_BIT
|
980 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
981 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
|
982 VK_SUBGROUP_FEATURE_VOTE_BIT
;
983 properties
->quadOperationsInAllStages
= true;
986 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
987 VkPhysicalDeviceMaintenance3Properties
*properties
=
988 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
989 /* Make sure everything is addressable by a signed 32-bit int, and
990 * our largest descriptors are 96 bytes. */
991 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
992 /* Our buffer size fields allow only this much */
993 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
996 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
997 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
998 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
999 /* GFX6-8 only support single channel min/max filter. */
1000 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1001 properties
->filterMinmaxSingleComponentFormats
= true;
1004 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1005 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1006 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1008 /* Shader engines. */
1009 properties
->shaderEngineCount
=
1010 pdevice
->rad_info
.max_se
;
1011 properties
->shaderArraysPerEngineCount
=
1012 pdevice
->rad_info
.max_sh_per_se
;
1013 properties
->computeUnitsPerShaderArray
=
1014 pdevice
->rad_info
.num_good_compute_units
/
1015 (pdevice
->rad_info
.max_se
*
1016 pdevice
->rad_info
.max_sh_per_se
);
1017 properties
->simdPerComputeUnit
= 4;
1018 properties
->wavefrontsPerSimd
=
1019 pdevice
->rad_info
.family
== CHIP_TONGA
||
1020 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1021 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1022 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1023 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1024 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1025 properties
->wavefrontSize
= 64;
1028 properties
->sgprsPerSimd
=
1029 radv_get_num_physical_sgprs(pdevice
);
1030 properties
->minSgprAllocation
=
1031 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1032 properties
->maxSgprAllocation
=
1033 pdevice
->rad_info
.family
== CHIP_TONGA
||
1034 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1035 properties
->sgprAllocationGranularity
=
1036 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1039 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1040 properties
->minVgprAllocation
= 4;
1041 properties
->maxVgprAllocation
= 256;
1042 properties
->vgprAllocationGranularity
= 4;
1045 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1046 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1047 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1048 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1051 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1052 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1053 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1054 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1055 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1056 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1057 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1058 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1059 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1060 properties
->robustBufferAccessUpdateAfterBind
= false;
1061 properties
->quadDivergentImplicitLod
= false;
1063 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1064 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1065 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1066 32 /* sampler, largest when combined with image */ +
1067 64 /* sampled image */ +
1068 64 /* storage image */);
1069 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1070 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1071 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1072 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1073 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1074 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1075 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1076 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1077 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1078 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1079 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1080 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1081 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1082 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1083 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1092 static void radv_get_physical_device_queue_family_properties(
1093 struct radv_physical_device
* pdevice
,
1095 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1097 int num_queue_families
= 1;
1099 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1100 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1101 num_queue_families
++;
1103 if (pQueueFamilyProperties
== NULL
) {
1104 *pCount
= num_queue_families
;
1113 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1114 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1115 VK_QUEUE_COMPUTE_BIT
|
1116 VK_QUEUE_TRANSFER_BIT
|
1117 VK_QUEUE_SPARSE_BINDING_BIT
,
1119 .timestampValidBits
= 64,
1120 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1125 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1126 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1127 if (*pCount
> idx
) {
1128 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1129 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1130 VK_QUEUE_TRANSFER_BIT
|
1131 VK_QUEUE_SPARSE_BINDING_BIT
,
1132 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1133 .timestampValidBits
= 64,
1134 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1142 void radv_GetPhysicalDeviceQueueFamilyProperties(
1143 VkPhysicalDevice physicalDevice
,
1145 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1147 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1148 if (!pQueueFamilyProperties
) {
1149 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1152 VkQueueFamilyProperties
*properties
[] = {
1153 pQueueFamilyProperties
+ 0,
1154 pQueueFamilyProperties
+ 1,
1155 pQueueFamilyProperties
+ 2,
1157 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1158 assert(*pCount
<= 3);
1161 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1162 VkPhysicalDevice physicalDevice
,
1164 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1166 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1167 if (!pQueueFamilyProperties
) {
1168 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1171 VkQueueFamilyProperties
*properties
[] = {
1172 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1173 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1174 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1176 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1177 assert(*pCount
<= 3);
1180 void radv_GetPhysicalDeviceMemoryProperties(
1181 VkPhysicalDevice physicalDevice
,
1182 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1184 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1186 *pMemoryProperties
= physical_device
->memory_properties
;
1189 void radv_GetPhysicalDeviceMemoryProperties2(
1190 VkPhysicalDevice physicalDevice
,
1191 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1193 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1194 &pMemoryProperties
->memoryProperties
);
1197 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1199 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1200 const void *pHostPointer
,
1201 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1203 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1207 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1208 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1209 uint32_t memoryTypeBits
= 0;
1210 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1211 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1212 memoryTypeBits
= (1 << i
);
1216 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1220 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1224 static enum radeon_ctx_priority
1225 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1227 /* Default to MEDIUM when a specific global priority isn't requested */
1229 return RADEON_CTX_PRIORITY_MEDIUM
;
1231 switch(pObj
->globalPriority
) {
1232 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1233 return RADEON_CTX_PRIORITY_REALTIME
;
1234 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1235 return RADEON_CTX_PRIORITY_HIGH
;
1236 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1237 return RADEON_CTX_PRIORITY_MEDIUM
;
1238 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1239 return RADEON_CTX_PRIORITY_LOW
;
1241 unreachable("Illegal global priority value");
1242 return RADEON_CTX_PRIORITY_INVALID
;
1247 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1248 uint32_t queue_family_index
, int idx
,
1249 VkDeviceQueueCreateFlags flags
,
1250 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1252 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1253 queue
->device
= device
;
1254 queue
->queue_family_index
= queue_family_index
;
1255 queue
->queue_idx
= idx
;
1256 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1257 queue
->flags
= flags
;
1259 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1261 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1267 radv_queue_finish(struct radv_queue
*queue
)
1270 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1272 if (queue
->initial_full_flush_preamble_cs
)
1273 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1274 if (queue
->initial_preamble_cs
)
1275 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1276 if (queue
->continue_preamble_cs
)
1277 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1278 if (queue
->descriptor_bo
)
1279 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1280 if (queue
->scratch_bo
)
1281 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1282 if (queue
->esgs_ring_bo
)
1283 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1284 if (queue
->gsvs_ring_bo
)
1285 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1286 if (queue
->tess_rings_bo
)
1287 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1288 if (queue
->compute_scratch_bo
)
1289 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1293 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1295 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1296 bo_list
->list
.count
= bo_list
->capacity
= 0;
1297 bo_list
->list
.bos
= NULL
;
1301 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1303 free(bo_list
->list
.bos
);
1304 pthread_mutex_destroy(&bo_list
->mutex
);
1307 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1308 struct radeon_winsys_bo
*bo
)
1310 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1312 if (unlikely(!device
->use_global_bo_list
))
1315 pthread_mutex_lock(&bo_list
->mutex
);
1316 if (bo_list
->list
.count
== bo_list
->capacity
) {
1317 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1318 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1321 pthread_mutex_unlock(&bo_list
->mutex
);
1322 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1325 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1326 bo_list
->capacity
= capacity
;
1329 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1330 pthread_mutex_unlock(&bo_list
->mutex
);
1334 static void radv_bo_list_remove(struct radv_device
*device
,
1335 struct radeon_winsys_bo
*bo
)
1337 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1339 if (unlikely(!device
->use_global_bo_list
))
1342 pthread_mutex_lock(&bo_list
->mutex
);
1343 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1344 if (bo_list
->list
.bos
[i
] == bo
) {
1345 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1346 --bo_list
->list
.count
;
1350 pthread_mutex_unlock(&bo_list
->mutex
);
1354 radv_device_init_gs_info(struct radv_device
*device
)
1356 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1357 device
->physical_device
->rad_info
.family
);
1360 static int radv_get_device_extension_index(const char *name
)
1362 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1363 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1369 VkResult
radv_CreateDevice(
1370 VkPhysicalDevice physicalDevice
,
1371 const VkDeviceCreateInfo
* pCreateInfo
,
1372 const VkAllocationCallbacks
* pAllocator
,
1375 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1377 struct radv_device
*device
;
1379 bool keep_shader_info
= false;
1381 /* Check enabled features */
1382 if (pCreateInfo
->pEnabledFeatures
) {
1383 VkPhysicalDeviceFeatures supported_features
;
1384 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1385 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1386 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1387 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1388 for (uint32_t i
= 0; i
< num_features
; i
++) {
1389 if (enabled_feature
[i
] && !supported_feature
[i
])
1390 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1394 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1396 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1398 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1400 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1401 device
->instance
= physical_device
->instance
;
1402 device
->physical_device
= physical_device
;
1404 device
->ws
= physical_device
->ws
;
1406 device
->alloc
= *pAllocator
;
1408 device
->alloc
= physical_device
->instance
->alloc
;
1410 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1411 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1412 int index
= radv_get_device_extension_index(ext_name
);
1413 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1414 vk_free(&device
->alloc
, device
);
1415 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1418 device
->enabled_extensions
.extensions
[index
] = true;
1421 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1423 /* With update after bind we can't attach bo's to the command buffer
1424 * from the descriptor set anymore, so we have to use a global BO list.
1426 device
->use_global_bo_list
=
1427 device
->enabled_extensions
.EXT_descriptor_indexing
;
1429 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1430 list_inithead(&device
->shader_slabs
);
1432 radv_bo_list_init(&device
->bo_list
);
1434 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1435 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1436 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1437 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1438 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1440 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1442 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1443 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1444 if (!device
->queues
[qfi
]) {
1445 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1449 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1451 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1453 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1454 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1455 qfi
, q
, queue_create
->flags
,
1457 if (result
!= VK_SUCCESS
)
1462 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1463 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1465 /* Disabled and not implemented for now. */
1466 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1469 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1472 device
->llvm_supports_spill
= true;
1474 /* The maximum number of scratch waves. Scratch space isn't divided
1475 * evenly between CUs. The number is only a function of the number of CUs.
1476 * We can decrease the constant to decrease the scratch buffer size.
1478 * sctx->scratch_waves must be >= the maximum posible size of
1479 * 1 threadgroup, so that the hw doesn't hang from being unable
1482 * The recommended value is 4 per CU at most. Higher numbers don't
1483 * bring much benefit, but they still occupy chip resources (think
1484 * async compute). I've seen ~2% performance difference between 4 and 32.
1486 uint32_t max_threads_per_block
= 2048;
1487 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1488 max_threads_per_block
/ 64);
1490 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1492 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1493 /* If the KMD allows it (there is a KMD hw register for it),
1494 * allow launching waves out-of-order.
1496 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1499 radv_device_init_gs_info(device
);
1501 device
->tess_offchip_block_dw_size
=
1502 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1503 device
->has_distributed_tess
=
1504 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1505 device
->physical_device
->rad_info
.max_se
>= 2;
1507 if (getenv("RADV_TRACE_FILE")) {
1508 const char *filename
= getenv("RADV_TRACE_FILE");
1510 keep_shader_info
= true;
1512 if (!radv_init_trace(device
))
1515 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1516 radv_dump_enabled_options(device
, stderr
);
1519 device
->keep_shader_info
= keep_shader_info
;
1521 result
= radv_device_init_meta(device
);
1522 if (result
!= VK_SUCCESS
)
1525 radv_device_init_msaa(device
);
1527 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1528 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1530 case RADV_QUEUE_GENERAL
:
1531 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1532 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1533 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1535 case RADV_QUEUE_COMPUTE
:
1536 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1537 radeon_emit(device
->empty_cs
[family
], 0);
1540 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1543 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1544 cik_create_gfx_config(device
);
1546 VkPipelineCacheCreateInfo ci
;
1547 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1550 ci
.pInitialData
= NULL
;
1551 ci
.initialDataSize
= 0;
1553 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1555 if (result
!= VK_SUCCESS
)
1558 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1560 *pDevice
= radv_device_to_handle(device
);
1564 radv_device_finish_meta(device
);
1566 radv_bo_list_finish(&device
->bo_list
);
1568 if (device
->trace_bo
)
1569 device
->ws
->buffer_destroy(device
->trace_bo
);
1571 if (device
->gfx_init
)
1572 device
->ws
->buffer_destroy(device
->gfx_init
);
1574 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1575 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1576 radv_queue_finish(&device
->queues
[i
][q
]);
1577 if (device
->queue_count
[i
])
1578 vk_free(&device
->alloc
, device
->queues
[i
]);
1581 vk_free(&device
->alloc
, device
);
1585 void radv_DestroyDevice(
1587 const VkAllocationCallbacks
* pAllocator
)
1589 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1594 if (device
->trace_bo
)
1595 device
->ws
->buffer_destroy(device
->trace_bo
);
1597 if (device
->gfx_init
)
1598 device
->ws
->buffer_destroy(device
->gfx_init
);
1600 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1601 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1602 radv_queue_finish(&device
->queues
[i
][q
]);
1603 if (device
->queue_count
[i
])
1604 vk_free(&device
->alloc
, device
->queues
[i
]);
1605 if (device
->empty_cs
[i
])
1606 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1608 radv_device_finish_meta(device
);
1610 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1611 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1613 radv_destroy_shader_slabs(device
);
1615 radv_bo_list_finish(&device
->bo_list
);
1616 vk_free(&device
->alloc
, device
);
1619 VkResult
radv_EnumerateInstanceLayerProperties(
1620 uint32_t* pPropertyCount
,
1621 VkLayerProperties
* pProperties
)
1623 if (pProperties
== NULL
) {
1624 *pPropertyCount
= 0;
1628 /* None supported at this time */
1629 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1632 VkResult
radv_EnumerateDeviceLayerProperties(
1633 VkPhysicalDevice physicalDevice
,
1634 uint32_t* pPropertyCount
,
1635 VkLayerProperties
* pProperties
)
1637 if (pProperties
== NULL
) {
1638 *pPropertyCount
= 0;
1642 /* None supported at this time */
1643 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1646 void radv_GetDeviceQueue2(
1648 const VkDeviceQueueInfo2
* pQueueInfo
,
1651 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1652 struct radv_queue
*queue
;
1654 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1655 if (pQueueInfo
->flags
!= queue
->flags
) {
1656 /* From the Vulkan 1.1.70 spec:
1658 * "The queue returned by vkGetDeviceQueue2 must have the same
1659 * flags value from this structure as that used at device
1660 * creation time in a VkDeviceQueueCreateInfo instance. If no
1661 * matching flags were specified at device creation time then
1662 * pQueue will return VK_NULL_HANDLE."
1664 *pQueue
= VK_NULL_HANDLE
;
1668 *pQueue
= radv_queue_to_handle(queue
);
1671 void radv_GetDeviceQueue(
1673 uint32_t queueFamilyIndex
,
1674 uint32_t queueIndex
,
1677 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1678 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1679 .queueFamilyIndex
= queueFamilyIndex
,
1680 .queueIndex
= queueIndex
1683 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1687 fill_geom_tess_rings(struct radv_queue
*queue
,
1689 bool add_sample_positions
,
1690 uint32_t esgs_ring_size
,
1691 struct radeon_winsys_bo
*esgs_ring_bo
,
1692 uint32_t gsvs_ring_size
,
1693 struct radeon_winsys_bo
*gsvs_ring_bo
,
1694 uint32_t tess_factor_ring_size
,
1695 uint32_t tess_offchip_ring_offset
,
1696 uint32_t tess_offchip_ring_size
,
1697 struct radeon_winsys_bo
*tess_rings_bo
)
1699 uint64_t esgs_va
= 0, gsvs_va
= 0;
1700 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1701 uint32_t *desc
= &map
[4];
1704 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1706 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1707 if (tess_rings_bo
) {
1708 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1709 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1712 /* stride 0, num records - size, add tid, swizzle, elsize4,
1715 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1716 S_008F04_STRIDE(0) |
1717 S_008F04_SWIZZLE_ENABLE(true);
1718 desc
[2] = esgs_ring_size
;
1719 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1720 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1721 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1722 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1723 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1724 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1725 S_008F0C_ELEMENT_SIZE(1) |
1726 S_008F0C_INDEX_STRIDE(3) |
1727 S_008F0C_ADD_TID_ENABLE(true);
1730 /* GS entry for ES->GS ring */
1731 /* stride 0, num records - size, elsize0,
1734 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1735 S_008F04_STRIDE(0) |
1736 S_008F04_SWIZZLE_ENABLE(false);
1737 desc
[2] = esgs_ring_size
;
1738 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1739 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1740 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1741 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1742 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1743 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1744 S_008F0C_ELEMENT_SIZE(0) |
1745 S_008F0C_INDEX_STRIDE(0) |
1746 S_008F0C_ADD_TID_ENABLE(false);
1749 /* VS entry for GS->VS ring */
1750 /* stride 0, num records - size, elsize0,
1753 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1754 S_008F04_STRIDE(0) |
1755 S_008F04_SWIZZLE_ENABLE(false);
1756 desc
[2] = gsvs_ring_size
;
1757 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1758 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1759 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1760 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1761 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1762 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1763 S_008F0C_ELEMENT_SIZE(0) |
1764 S_008F0C_INDEX_STRIDE(0) |
1765 S_008F0C_ADD_TID_ENABLE(false);
1768 /* stride gsvs_itemsize, num records 64
1769 elsize 4, index stride 16 */
1770 /* shader will patch stride and desc[2] */
1772 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1773 S_008F04_STRIDE(0) |
1774 S_008F04_SWIZZLE_ENABLE(true);
1776 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1777 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1778 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1779 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1780 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1781 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1782 S_008F0C_ELEMENT_SIZE(1) |
1783 S_008F0C_INDEX_STRIDE(1) |
1784 S_008F0C_ADD_TID_ENABLE(true);
1788 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1789 S_008F04_STRIDE(0) |
1790 S_008F04_SWIZZLE_ENABLE(false);
1791 desc
[2] = tess_factor_ring_size
;
1792 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1793 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1794 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1795 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1796 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1797 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1798 S_008F0C_ELEMENT_SIZE(0) |
1799 S_008F0C_INDEX_STRIDE(0) |
1800 S_008F0C_ADD_TID_ENABLE(false);
1803 desc
[0] = tess_offchip_va
;
1804 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1805 S_008F04_STRIDE(0) |
1806 S_008F04_SWIZZLE_ENABLE(false);
1807 desc
[2] = tess_offchip_ring_size
;
1808 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1809 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1810 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1811 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1812 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1813 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1814 S_008F0C_ELEMENT_SIZE(0) |
1815 S_008F0C_INDEX_STRIDE(0) |
1816 S_008F0C_ADD_TID_ENABLE(false);
1819 /* add sample positions after all rings */
1820 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1822 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1824 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1826 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1828 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1832 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1834 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1835 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1836 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1837 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1838 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1839 device
->physical_device
->rad_info
.max_se
;
1840 unsigned offchip_granularity
;
1841 unsigned hs_offchip_param
;
1842 switch (device
->tess_offchip_block_dw_size
) {
1847 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1850 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1854 switch (device
->physical_device
->rad_info
.chip_class
) {
1856 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1862 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1866 *max_offchip_buffers_p
= max_offchip_buffers
;
1867 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1868 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1869 --max_offchip_buffers
;
1871 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1872 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1875 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1877 return hs_offchip_param
;
1881 radv_get_preamble_cs(struct radv_queue
*queue
,
1882 uint32_t scratch_size
,
1883 uint32_t compute_scratch_size
,
1884 uint32_t esgs_ring_size
,
1885 uint32_t gsvs_ring_size
,
1886 bool needs_tess_rings
,
1887 bool needs_sample_positions
,
1888 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1889 struct radeon_winsys_cs
**initial_preamble_cs
,
1890 struct radeon_winsys_cs
**continue_preamble_cs
)
1892 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1893 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1894 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1895 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1896 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1897 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1898 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1899 bool add_tess_rings
= false, add_sample_positions
= false;
1900 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1901 unsigned max_offchip_buffers
;
1902 unsigned hs_offchip_param
= 0;
1903 unsigned tess_offchip_ring_offset
;
1904 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1905 if (!queue
->has_tess_rings
) {
1906 if (needs_tess_rings
)
1907 add_tess_rings
= true;
1909 if (!queue
->has_sample_positions
) {
1910 if (needs_sample_positions
)
1911 add_sample_positions
= true;
1913 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1914 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1915 &max_offchip_buffers
);
1916 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1917 tess_offchip_ring_size
= max_offchip_buffers
*
1918 queue
->device
->tess_offchip_block_dw_size
* 4;
1920 if (scratch_size
<= queue
->scratch_size
&&
1921 compute_scratch_size
<= queue
->compute_scratch_size
&&
1922 esgs_ring_size
<= queue
->esgs_ring_size
&&
1923 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1924 !add_tess_rings
&& !add_sample_positions
&&
1925 queue
->initial_preamble_cs
) {
1926 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1927 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1928 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1929 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1930 *continue_preamble_cs
= NULL
;
1934 if (scratch_size
> queue
->scratch_size
) {
1935 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1943 scratch_bo
= queue
->scratch_bo
;
1945 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1946 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1947 compute_scratch_size
,
1951 if (!compute_scratch_bo
)
1955 compute_scratch_bo
= queue
->compute_scratch_bo
;
1957 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1958 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1966 esgs_ring_bo
= queue
->esgs_ring_bo
;
1967 esgs_ring_size
= queue
->esgs_ring_size
;
1970 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1971 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1979 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1980 gsvs_ring_size
= queue
->gsvs_ring_size
;
1983 if (add_tess_rings
) {
1984 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1985 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
1992 tess_rings_bo
= queue
->tess_rings_bo
;
1995 if (scratch_bo
!= queue
->scratch_bo
||
1996 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1997 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1998 tess_rings_bo
!= queue
->tess_rings_bo
||
1999 add_sample_positions
) {
2001 if (gsvs_ring_bo
|| esgs_ring_bo
||
2002 tess_rings_bo
|| add_sample_positions
) {
2003 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2004 if (add_sample_positions
)
2005 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2007 else if (scratch_bo
)
2008 size
= 8; /* 2 dword */
2010 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2014 RADEON_FLAG_CPU_ACCESS
|
2015 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2016 RADEON_FLAG_READ_ONLY
);
2020 descriptor_bo
= queue
->descriptor_bo
;
2022 for(int i
= 0; i
< 3; ++i
) {
2023 struct radeon_winsys_cs
*cs
= NULL
;
2024 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2025 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2032 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2035 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
2038 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
2041 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
2044 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
2046 if (descriptor_bo
!= queue
->descriptor_bo
) {
2047 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2050 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2051 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2052 S_008F04_SWIZZLE_ENABLE(1);
2053 map
[0] = scratch_va
;
2057 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2058 add_sample_positions
)
2059 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2060 esgs_ring_size
, esgs_ring_bo
,
2061 gsvs_ring_size
, gsvs_ring_bo
,
2062 tess_factor_ring_size
,
2063 tess_offchip_ring_offset
,
2064 tess_offchip_ring_size
,
2067 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2070 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2071 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2072 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2073 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2074 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2077 if (esgs_ring_bo
|| gsvs_ring_bo
) {
2078 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2079 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2080 radeon_emit(cs
, esgs_ring_size
>> 8);
2081 radeon_emit(cs
, gsvs_ring_size
>> 8);
2083 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2084 radeon_emit(cs
, esgs_ring_size
>> 8);
2085 radeon_emit(cs
, gsvs_ring_size
>> 8);
2089 if (tess_rings_bo
) {
2090 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
2091 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2092 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2093 S_030938_SIZE(tess_factor_ring_size
/ 4));
2094 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2096 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2097 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2098 S_030944_BASE_HI(tf_va
>> 40));
2100 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
2102 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2103 S_008988_SIZE(tess_factor_ring_size
/ 4));
2104 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2106 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2111 if (descriptor_bo
) {
2112 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
2113 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2114 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2115 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2116 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2117 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2119 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2120 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2121 radeon_emit(cs
, va
);
2122 radeon_emit(cs
, va
>> 32);
2125 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2126 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2127 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2128 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2129 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2130 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2132 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2133 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2134 radeon_emit(cs
, va
);
2135 radeon_emit(cs
, va
>> 32);
2140 if (compute_scratch_bo
) {
2141 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2142 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2143 S_008F04_SWIZZLE_ENABLE(1);
2145 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2147 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2148 radeon_emit(cs
, scratch_va
);
2149 radeon_emit(cs
, rsrc1
);
2153 si_cs_emit_cache_flush(cs
,
2154 queue
->device
->physical_device
->rad_info
.chip_class
,
2156 queue
->queue_family_index
== RING_COMPUTE
&&
2157 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2158 (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
)) |
2159 RADV_CMD_FLAG_INV_ICACHE
|
2160 RADV_CMD_FLAG_INV_SMEM_L1
|
2161 RADV_CMD_FLAG_INV_VMEM_L1
|
2162 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2163 } else if (i
== 1) {
2164 si_cs_emit_cache_flush(cs
,
2165 queue
->device
->physical_device
->rad_info
.chip_class
,
2167 queue
->queue_family_index
== RING_COMPUTE
&&
2168 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2169 RADV_CMD_FLAG_INV_ICACHE
|
2170 RADV_CMD_FLAG_INV_SMEM_L1
|
2171 RADV_CMD_FLAG_INV_VMEM_L1
|
2172 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2175 if (!queue
->device
->ws
->cs_finalize(cs
))
2179 if (queue
->initial_full_flush_preamble_cs
)
2180 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2182 if (queue
->initial_preamble_cs
)
2183 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2185 if (queue
->continue_preamble_cs
)
2186 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2188 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2189 queue
->initial_preamble_cs
= dest_cs
[1];
2190 queue
->continue_preamble_cs
= dest_cs
[2];
2192 if (scratch_bo
!= queue
->scratch_bo
) {
2193 if (queue
->scratch_bo
)
2194 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2195 queue
->scratch_bo
= scratch_bo
;
2196 queue
->scratch_size
= scratch_size
;
2199 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2200 if (queue
->compute_scratch_bo
)
2201 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2202 queue
->compute_scratch_bo
= compute_scratch_bo
;
2203 queue
->compute_scratch_size
= compute_scratch_size
;
2206 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2207 if (queue
->esgs_ring_bo
)
2208 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2209 queue
->esgs_ring_bo
= esgs_ring_bo
;
2210 queue
->esgs_ring_size
= esgs_ring_size
;
2213 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2214 if (queue
->gsvs_ring_bo
)
2215 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2216 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2217 queue
->gsvs_ring_size
= gsvs_ring_size
;
2220 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2221 queue
->tess_rings_bo
= tess_rings_bo
;
2222 queue
->has_tess_rings
= true;
2225 if (descriptor_bo
!= queue
->descriptor_bo
) {
2226 if (queue
->descriptor_bo
)
2227 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2229 queue
->descriptor_bo
= descriptor_bo
;
2232 if (add_sample_positions
)
2233 queue
->has_sample_positions
= true;
2235 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2236 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2237 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2238 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2239 *continue_preamble_cs
= NULL
;
2242 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2244 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2245 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2246 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2247 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2248 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2249 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2250 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2251 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2252 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2253 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2254 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2255 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2256 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2257 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2260 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2262 const VkSemaphore
*sems
,
2266 int syncobj_idx
= 0, sem_idx
= 0;
2268 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2271 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2272 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2274 if (sem
->temp_syncobj
|| sem
->syncobj
)
2275 counts
->syncobj_count
++;
2277 counts
->sem_count
++;
2280 if (_fence
!= VK_NULL_HANDLE
) {
2281 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2282 if (fence
->temp_syncobj
|| fence
->syncobj
)
2283 counts
->syncobj_count
++;
2286 if (counts
->syncobj_count
) {
2287 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2288 if (!counts
->syncobj
)
2289 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2292 if (counts
->sem_count
) {
2293 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2295 free(counts
->syncobj
);
2296 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2300 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2301 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2303 if (sem
->temp_syncobj
) {
2304 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2306 else if (sem
->syncobj
)
2307 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2310 counts
->sem
[sem_idx
++] = sem
->sem
;
2314 if (_fence
!= VK_NULL_HANDLE
) {
2315 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2316 if (fence
->temp_syncobj
)
2317 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2318 else if (fence
->syncobj
)
2319 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2325 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2327 free(sem_info
->wait
.syncobj
);
2328 free(sem_info
->wait
.sem
);
2329 free(sem_info
->signal
.syncobj
);
2330 free(sem_info
->signal
.sem
);
2334 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2336 const VkSemaphore
*sems
)
2338 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2339 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2341 if (sem
->temp_syncobj
) {
2342 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2343 sem
->temp_syncobj
= 0;
2348 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2350 const VkSemaphore
*wait_sems
,
2351 int num_signal_sems
,
2352 const VkSemaphore
*signal_sems
,
2356 memset(sem_info
, 0, sizeof(*sem_info
));
2358 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2361 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2363 radv_free_sem_info(sem_info
);
2365 /* caller can override these */
2366 sem_info
->cs_emit_wait
= true;
2367 sem_info
->cs_emit_signal
= true;
2371 /* Signals fence as soon as all the work currently put on queue is done. */
2372 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2373 struct radv_fence
*fence
)
2377 struct radv_winsys_sem_info sem_info
;
2379 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2380 radv_fence_to_handle(fence
));
2381 if (result
!= VK_SUCCESS
)
2384 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2385 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2386 1, NULL
, NULL
, &sem_info
, NULL
,
2387 false, fence
->fence
);
2388 radv_free_sem_info(&sem_info
);
2390 /* TODO: find a better error */
2392 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2397 VkResult
radv_QueueSubmit(
2399 uint32_t submitCount
,
2400 const VkSubmitInfo
* pSubmits
,
2403 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2404 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2405 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2406 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2408 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2409 uint32_t scratch_size
= 0;
2410 uint32_t compute_scratch_size
= 0;
2411 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2412 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2414 bool fence_emitted
= false;
2415 bool tess_rings_needed
= false;
2416 bool sample_positions_needed
= false;
2418 /* Do this first so failing to allocate scratch buffers can't result in
2419 * partially executed submissions. */
2420 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2421 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2422 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2423 pSubmits
[i
].pCommandBuffers
[j
]);
2425 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2426 compute_scratch_size
= MAX2(compute_scratch_size
,
2427 cmd_buffer
->compute_scratch_size_needed
);
2428 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2429 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2430 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2431 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2435 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2436 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2437 sample_positions_needed
, &initial_flush_preamble_cs
,
2438 &initial_preamble_cs
, &continue_preamble_cs
);
2439 if (result
!= VK_SUCCESS
)
2442 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2443 struct radeon_winsys_cs
**cs_array
;
2444 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2445 bool can_patch
= true;
2447 struct radv_winsys_sem_info sem_info
;
2449 result
= radv_alloc_sem_info(&sem_info
,
2450 pSubmits
[i
].waitSemaphoreCount
,
2451 pSubmits
[i
].pWaitSemaphores
,
2452 pSubmits
[i
].signalSemaphoreCount
,
2453 pSubmits
[i
].pSignalSemaphores
,
2455 if (result
!= VK_SUCCESS
)
2458 if (!pSubmits
[i
].commandBufferCount
) {
2459 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2460 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2461 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2466 radv_loge("failed to submit CS %d\n", i
);
2469 fence_emitted
= true;
2471 radv_free_sem_info(&sem_info
);
2475 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2476 (pSubmits
[i
].commandBufferCount
));
2478 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2479 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2480 pSubmits
[i
].pCommandBuffers
[j
]);
2481 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2483 cs_array
[j
] = cmd_buffer
->cs
;
2484 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2487 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2490 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2491 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2492 advance
= MIN2(max_cs_submission
,
2493 pSubmits
[i
].commandBufferCount
- j
);
2495 if (queue
->device
->trace_bo
)
2496 *queue
->device
->trace_id_ptr
= 0;
2498 sem_info
.cs_emit_wait
= j
== 0;
2499 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2501 if (unlikely(queue
->device
->use_global_bo_list
))
2502 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2504 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2505 advance
, initial_preamble
, continue_preamble_cs
,
2506 &sem_info
, &queue
->device
->bo_list
.list
,
2507 can_patch
, base_fence
);
2509 if (unlikely(queue
->device
->use_global_bo_list
))
2510 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2513 radv_loge("failed to submit CS %d\n", i
);
2516 fence_emitted
= true;
2517 if (queue
->device
->trace_bo
) {
2518 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2522 radv_free_temp_syncobjs(queue
->device
,
2523 pSubmits
[i
].waitSemaphoreCount
,
2524 pSubmits
[i
].pWaitSemaphores
);
2525 radv_free_sem_info(&sem_info
);
2530 if (!fence_emitted
) {
2531 radv_signal_fence(queue
, fence
);
2533 fence
->submitted
= true;
2539 VkResult
radv_QueueWaitIdle(
2542 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2544 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2545 radv_queue_family_to_ring(queue
->queue_family_index
),
2550 VkResult
radv_DeviceWaitIdle(
2553 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2555 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2556 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2557 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2563 VkResult
radv_EnumerateInstanceExtensionProperties(
2564 const char* pLayerName
,
2565 uint32_t* pPropertyCount
,
2566 VkExtensionProperties
* pProperties
)
2568 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2570 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2571 if (radv_supported_instance_extensions
.extensions
[i
]) {
2572 vk_outarray_append(&out
, prop
) {
2573 *prop
= radv_instance_extensions
[i
];
2578 return vk_outarray_status(&out
);
2581 VkResult
radv_EnumerateDeviceExtensionProperties(
2582 VkPhysicalDevice physicalDevice
,
2583 const char* pLayerName
,
2584 uint32_t* pPropertyCount
,
2585 VkExtensionProperties
* pProperties
)
2587 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2588 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2590 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2591 if (device
->supported_extensions
.extensions
[i
]) {
2592 vk_outarray_append(&out
, prop
) {
2593 *prop
= radv_device_extensions
[i
];
2598 return vk_outarray_status(&out
);
2601 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2602 VkInstance _instance
,
2605 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2607 return radv_lookup_entrypoint_checked(pName
,
2608 instance
? instance
->apiVersion
: 0,
2609 instance
? &instance
->enabled_extensions
: NULL
,
2613 /* The loader wants us to expose a second GetInstanceProcAddr function
2614 * to work around certain LD_PRELOAD issues seen in apps.
2617 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2618 VkInstance instance
,
2622 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2623 VkInstance instance
,
2626 return radv_GetInstanceProcAddr(instance
, pName
);
2629 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2633 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2635 return radv_lookup_entrypoint_checked(pName
,
2636 device
->instance
->apiVersion
,
2637 &device
->instance
->enabled_extensions
,
2638 &device
->enabled_extensions
);
2641 bool radv_get_memory_fd(struct radv_device
*device
,
2642 struct radv_device_memory
*memory
,
2645 struct radeon_bo_metadata metadata
;
2647 if (memory
->image
) {
2648 radv_init_metadata(device
, memory
->image
, &metadata
);
2649 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2652 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2656 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2657 const VkMemoryAllocateInfo
* pAllocateInfo
,
2658 const VkAllocationCallbacks
* pAllocator
,
2659 VkDeviceMemory
* pMem
)
2661 struct radv_device_memory
*mem
;
2663 enum radeon_bo_domain domain
;
2665 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2667 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2669 if (pAllocateInfo
->allocationSize
== 0) {
2670 /* Apparently, this is allowed */
2671 *pMem
= VK_NULL_HANDLE
;
2675 const VkImportMemoryFdInfoKHR
*import_info
=
2676 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2677 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2678 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2679 const VkExportMemoryAllocateInfoKHR
*export_info
=
2680 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2681 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2682 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2684 const struct wsi_memory_allocate_info
*wsi_info
=
2685 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2687 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2688 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2690 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2692 if (wsi_info
&& wsi_info
->implicit_sync
)
2693 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2695 if (dedicate_info
) {
2696 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2697 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2703 mem
->user_ptr
= NULL
;
2706 assert(import_info
->handleType
==
2707 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2708 import_info
->handleType
==
2709 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2710 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2713 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2716 close(import_info
->fd
);
2718 } else if (host_ptr_info
) {
2719 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2720 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2721 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2722 pAllocateInfo
->allocationSize
);
2724 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2727 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2730 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2731 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2732 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2733 domain
= RADEON_DOMAIN_GTT
;
2735 domain
= RADEON_DOMAIN_VRAM
;
2737 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2738 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2740 flags
|= RADEON_FLAG_CPU_ACCESS
;
2742 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2743 flags
|= RADEON_FLAG_GTT_WC
;
2745 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2746 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2748 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2752 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2755 mem
->type_index
= mem_type_index
;
2758 result
= radv_bo_list_add(device
, mem
->bo
);
2759 if (result
!= VK_SUCCESS
)
2762 *pMem
= radv_device_memory_to_handle(mem
);
2767 device
->ws
->buffer_destroy(mem
->bo
);
2769 vk_free2(&device
->alloc
, pAllocator
, mem
);
2774 VkResult
radv_AllocateMemory(
2776 const VkMemoryAllocateInfo
* pAllocateInfo
,
2777 const VkAllocationCallbacks
* pAllocator
,
2778 VkDeviceMemory
* pMem
)
2780 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2781 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2784 void radv_FreeMemory(
2786 VkDeviceMemory _mem
,
2787 const VkAllocationCallbacks
* pAllocator
)
2789 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2790 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2795 radv_bo_list_remove(device
, mem
->bo
);
2796 device
->ws
->buffer_destroy(mem
->bo
);
2799 vk_free2(&device
->alloc
, pAllocator
, mem
);
2802 VkResult
radv_MapMemory(
2804 VkDeviceMemory _memory
,
2805 VkDeviceSize offset
,
2807 VkMemoryMapFlags flags
,
2810 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2811 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2819 *ppData
= mem
->user_ptr
;
2821 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2828 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2831 void radv_UnmapMemory(
2833 VkDeviceMemory _memory
)
2835 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2836 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2841 if (mem
->user_ptr
== NULL
)
2842 device
->ws
->buffer_unmap(mem
->bo
);
2845 VkResult
radv_FlushMappedMemoryRanges(
2847 uint32_t memoryRangeCount
,
2848 const VkMappedMemoryRange
* pMemoryRanges
)
2853 VkResult
radv_InvalidateMappedMemoryRanges(
2855 uint32_t memoryRangeCount
,
2856 const VkMappedMemoryRange
* pMemoryRanges
)
2861 void radv_GetBufferMemoryRequirements(
2864 VkMemoryRequirements
* pMemoryRequirements
)
2866 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2867 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2869 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2871 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2872 pMemoryRequirements
->alignment
= 4096;
2874 pMemoryRequirements
->alignment
= 16;
2876 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2879 void radv_GetBufferMemoryRequirements2(
2881 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2882 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2884 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2885 &pMemoryRequirements
->memoryRequirements
);
2886 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2887 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2888 switch (ext
->sType
) {
2889 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2890 VkMemoryDedicatedRequirementsKHR
*req
=
2891 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2892 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2893 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2902 void radv_GetImageMemoryRequirements(
2905 VkMemoryRequirements
* pMemoryRequirements
)
2907 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2908 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2910 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2912 pMemoryRequirements
->size
= image
->size
;
2913 pMemoryRequirements
->alignment
= image
->alignment
;
2916 void radv_GetImageMemoryRequirements2(
2918 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2919 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2921 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2922 &pMemoryRequirements
->memoryRequirements
);
2924 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2926 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2927 switch (ext
->sType
) {
2928 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2929 VkMemoryDedicatedRequirementsKHR
*req
=
2930 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2931 req
->requiresDedicatedAllocation
= image
->shareable
;
2932 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2941 void radv_GetImageSparseMemoryRequirements(
2944 uint32_t* pSparseMemoryRequirementCount
,
2945 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2950 void radv_GetImageSparseMemoryRequirements2(
2952 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2953 uint32_t* pSparseMemoryRequirementCount
,
2954 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2959 void radv_GetDeviceMemoryCommitment(
2961 VkDeviceMemory memory
,
2962 VkDeviceSize
* pCommittedMemoryInBytes
)
2964 *pCommittedMemoryInBytes
= 0;
2967 VkResult
radv_BindBufferMemory2(VkDevice device
,
2968 uint32_t bindInfoCount
,
2969 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2971 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2972 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2973 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2976 buffer
->bo
= mem
->bo
;
2977 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2985 VkResult
radv_BindBufferMemory(
2988 VkDeviceMemory memory
,
2989 VkDeviceSize memoryOffset
)
2991 const VkBindBufferMemoryInfoKHR info
= {
2992 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2995 .memoryOffset
= memoryOffset
2998 return radv_BindBufferMemory2(device
, 1, &info
);
3001 VkResult
radv_BindImageMemory2(VkDevice device
,
3002 uint32_t bindInfoCount
,
3003 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3005 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3006 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3007 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3010 image
->bo
= mem
->bo
;
3011 image
->offset
= pBindInfos
[i
].memoryOffset
;
3021 VkResult
radv_BindImageMemory(
3024 VkDeviceMemory memory
,
3025 VkDeviceSize memoryOffset
)
3027 const VkBindImageMemoryInfoKHR info
= {
3028 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3031 .memoryOffset
= memoryOffset
3034 return radv_BindImageMemory2(device
, 1, &info
);
3039 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3040 const VkSparseBufferMemoryBindInfo
*bind
)
3042 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3044 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3045 struct radv_device_memory
*mem
= NULL
;
3047 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3048 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3050 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3051 bind
->pBinds
[i
].resourceOffset
,
3052 bind
->pBinds
[i
].size
,
3053 mem
? mem
->bo
: NULL
,
3054 bind
->pBinds
[i
].memoryOffset
);
3059 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3060 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3062 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3064 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3065 struct radv_device_memory
*mem
= NULL
;
3067 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3068 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3070 device
->ws
->buffer_virtual_bind(image
->bo
,
3071 bind
->pBinds
[i
].resourceOffset
,
3072 bind
->pBinds
[i
].size
,
3073 mem
? mem
->bo
: NULL
,
3074 bind
->pBinds
[i
].memoryOffset
);
3078 VkResult
radv_QueueBindSparse(
3080 uint32_t bindInfoCount
,
3081 const VkBindSparseInfo
* pBindInfo
,
3084 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3085 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3086 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3087 bool fence_emitted
= false;
3089 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3090 struct radv_winsys_sem_info sem_info
;
3091 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3092 radv_sparse_buffer_bind_memory(queue
->device
,
3093 pBindInfo
[i
].pBufferBinds
+ j
);
3096 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3097 radv_sparse_image_opaque_bind_memory(queue
->device
,
3098 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3102 result
= radv_alloc_sem_info(&sem_info
,
3103 pBindInfo
[i
].waitSemaphoreCount
,
3104 pBindInfo
[i
].pWaitSemaphores
,
3105 pBindInfo
[i
].signalSemaphoreCount
,
3106 pBindInfo
[i
].pSignalSemaphores
,
3108 if (result
!= VK_SUCCESS
)
3111 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3112 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3113 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3117 fence_emitted
= true;
3119 fence
->submitted
= true;
3122 radv_free_sem_info(&sem_info
);
3127 if (!fence_emitted
) {
3128 radv_signal_fence(queue
, fence
);
3130 fence
->submitted
= true;
3136 VkResult
radv_CreateFence(
3138 const VkFenceCreateInfo
* pCreateInfo
,
3139 const VkAllocationCallbacks
* pAllocator
,
3142 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3143 const VkExportFenceCreateInfoKHR
*export
=
3144 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3145 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3146 export
? export
->handleTypes
: 0;
3148 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3150 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3153 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3155 fence
->submitted
= false;
3156 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3157 fence
->temp_syncobj
= 0;
3158 if (device
->always_use_syncobj
|| handleTypes
) {
3159 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3161 vk_free2(&device
->alloc
, pAllocator
, fence
);
3162 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3164 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3165 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3167 fence
->fence
= NULL
;
3169 fence
->fence
= device
->ws
->create_fence();
3170 if (!fence
->fence
) {
3171 vk_free2(&device
->alloc
, pAllocator
, fence
);
3172 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3177 *pFence
= radv_fence_to_handle(fence
);
3182 void radv_DestroyFence(
3185 const VkAllocationCallbacks
* pAllocator
)
3187 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3188 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3193 if (fence
->temp_syncobj
)
3194 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3196 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3198 device
->ws
->destroy_fence(fence
->fence
);
3199 vk_free2(&device
->alloc
, pAllocator
, fence
);
3203 static uint64_t radv_get_current_time()
3206 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3207 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3210 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3212 uint64_t current_time
= radv_get_current_time();
3214 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3216 return current_time
+ timeout
;
3220 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3222 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3223 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3224 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3230 VkResult
radv_WaitForFences(
3232 uint32_t fenceCount
,
3233 const VkFence
* pFences
,
3237 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3238 timeout
= radv_get_absolute_timeout(timeout
);
3240 if (device
->always_use_syncobj
) {
3241 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3243 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3245 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3246 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3247 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3250 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3253 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3256 if (!waitAll
&& fenceCount
> 1) {
3257 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3258 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3259 uint32_t wait_count
= 0;
3260 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3262 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3264 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3265 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3267 if (fence
->signalled
) {
3272 fences
[wait_count
++] = fence
->fence
;
3275 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3276 waitAll
, timeout
- radv_get_current_time());
3279 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3282 while(radv_get_current_time() <= timeout
) {
3283 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3284 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3291 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3292 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3293 bool expired
= false;
3295 if (fence
->temp_syncobj
) {
3296 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3301 if (fence
->syncobj
) {
3302 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3307 if (fence
->signalled
)
3310 if (!fence
->submitted
) {
3311 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3314 if (!fence
->submitted
)
3317 /* Recheck as it may have been set by submitting operations. */
3318 if (fence
->signalled
)
3322 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3326 fence
->signalled
= true;
3332 VkResult
radv_ResetFences(VkDevice _device
,
3333 uint32_t fenceCount
,
3334 const VkFence
*pFences
)
3336 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3338 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3339 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3340 fence
->submitted
= fence
->signalled
= false;
3342 /* Per spec, we first restore the permanent payload, and then reset, so
3343 * having a temp syncobj should not skip resetting the permanent syncobj. */
3344 if (fence
->temp_syncobj
) {
3345 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3346 fence
->temp_syncobj
= 0;
3349 if (fence
->syncobj
) {
3350 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3357 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3359 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3360 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3362 if (fence
->temp_syncobj
) {
3363 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3364 return success
? VK_SUCCESS
: VK_NOT_READY
;
3367 if (fence
->syncobj
) {
3368 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3369 return success
? VK_SUCCESS
: VK_NOT_READY
;
3372 if (fence
->signalled
)
3374 if (!fence
->submitted
)
3375 return VK_NOT_READY
;
3376 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3377 return VK_NOT_READY
;
3383 // Queue semaphore functions
3385 VkResult
radv_CreateSemaphore(
3387 const VkSemaphoreCreateInfo
* pCreateInfo
,
3388 const VkAllocationCallbacks
* pAllocator
,
3389 VkSemaphore
* pSemaphore
)
3391 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3392 const VkExportSemaphoreCreateInfoKHR
*export
=
3393 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3394 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3395 export
? export
->handleTypes
: 0;
3397 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3399 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3401 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3403 sem
->temp_syncobj
= 0;
3404 /* create a syncobject if we are going to export this semaphore */
3405 if (device
->always_use_syncobj
|| handleTypes
) {
3406 assert (device
->physical_device
->rad_info
.has_syncobj
);
3407 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3409 vk_free2(&device
->alloc
, pAllocator
, sem
);
3410 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3414 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3416 vk_free2(&device
->alloc
, pAllocator
, sem
);
3417 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3422 *pSemaphore
= radv_semaphore_to_handle(sem
);
3426 void radv_DestroySemaphore(
3428 VkSemaphore _semaphore
,
3429 const VkAllocationCallbacks
* pAllocator
)
3431 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3432 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3437 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3439 device
->ws
->destroy_sem(sem
->sem
);
3440 vk_free2(&device
->alloc
, pAllocator
, sem
);
3443 VkResult
radv_CreateEvent(
3445 const VkEventCreateInfo
* pCreateInfo
,
3446 const VkAllocationCallbacks
* pAllocator
,
3449 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3450 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3452 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3455 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3457 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3459 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3461 vk_free2(&device
->alloc
, pAllocator
, event
);
3462 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3465 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3467 *pEvent
= radv_event_to_handle(event
);
3472 void radv_DestroyEvent(
3475 const VkAllocationCallbacks
* pAllocator
)
3477 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3478 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3482 device
->ws
->buffer_destroy(event
->bo
);
3483 vk_free2(&device
->alloc
, pAllocator
, event
);
3486 VkResult
radv_GetEventStatus(
3490 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3492 if (*event
->map
== 1)
3493 return VK_EVENT_SET
;
3494 return VK_EVENT_RESET
;
3497 VkResult
radv_SetEvent(
3501 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3507 VkResult
radv_ResetEvent(
3511 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3517 VkResult
radv_CreateBuffer(
3519 const VkBufferCreateInfo
* pCreateInfo
,
3520 const VkAllocationCallbacks
* pAllocator
,
3523 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3524 struct radv_buffer
*buffer
;
3526 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3528 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3529 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3531 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3533 buffer
->size
= pCreateInfo
->size
;
3534 buffer
->usage
= pCreateInfo
->usage
;
3537 buffer
->flags
= pCreateInfo
->flags
;
3539 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3540 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3542 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3543 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3544 align64(buffer
->size
, 4096),
3545 4096, 0, RADEON_FLAG_VIRTUAL
);
3547 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3548 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3552 *pBuffer
= radv_buffer_to_handle(buffer
);
3557 void radv_DestroyBuffer(
3560 const VkAllocationCallbacks
* pAllocator
)
3562 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3563 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3568 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3569 device
->ws
->buffer_destroy(buffer
->bo
);
3571 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3574 static inline unsigned
3575 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3578 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3580 return image
->surface
.u
.legacy
.tiling_index
[level
];
3583 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3585 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3589 radv_init_dcc_control_reg(struct radv_device
*device
,
3590 struct radv_image_view
*iview
)
3592 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3593 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3594 unsigned max_compressed_block_size
;
3595 unsigned independent_64b_blocks
;
3597 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3600 if (iview
->image
->info
.samples
> 1) {
3601 if (iview
->image
->surface
.bpe
== 1)
3602 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3603 else if (iview
->image
->surface
.bpe
== 2)
3604 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3607 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3608 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3609 * dGPU and 64 for APU because all of our APUs to date use
3610 * DIMMs which have a request granularity size of 64B while all
3611 * other chips have a 32B request size.
3613 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3616 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3617 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3618 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3619 /* If this DCC image is potentially going to be used in texture
3620 * fetches, we need some special settings.
3622 independent_64b_blocks
= 1;
3623 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3625 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3626 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3627 * big as possible for better compression state.
3629 independent_64b_blocks
= 0;
3630 max_compressed_block_size
= max_uncompressed_block_size
;
3633 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3634 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3635 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3636 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3640 radv_initialise_color_surface(struct radv_device
*device
,
3641 struct radv_color_buffer_info
*cb
,
3642 struct radv_image_view
*iview
)
3644 const struct vk_format_description
*desc
;
3645 unsigned ntype
, format
, swap
, endian
;
3646 unsigned blend_clamp
= 0, blend_bypass
= 0;
3648 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3650 desc
= vk_format_description(iview
->vk_format
);
3652 memset(cb
, 0, sizeof(*cb
));
3654 /* Intensity is implemented as Red, so treat it that way. */
3655 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3657 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3659 cb
->cb_color_base
= va
>> 8;
3661 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3662 struct gfx9_surf_meta_flags meta
;
3663 if (iview
->image
->dcc_offset
)
3664 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3666 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3668 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3669 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3670 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3671 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3673 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3674 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3676 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3677 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3679 cb
->cb_color_base
+= level_info
->offset
>> 8;
3680 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3681 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3683 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3684 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3685 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3687 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3688 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3689 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3691 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3693 if (radv_image_has_fmask(iview
->image
)) {
3694 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3695 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3696 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3697 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3699 /* This must be set for fast clear to work without FMASK. */
3700 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3701 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3702 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3703 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3707 /* CMASK variables */
3708 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3709 va
+= iview
->image
->cmask
.offset
;
3710 cb
->cb_color_cmask
= va
>> 8;
3712 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3713 va
+= iview
->image
->dcc_offset
;
3714 cb
->cb_dcc_base
= va
>> 8;
3715 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3717 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3718 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3719 S_028C6C_SLICE_MAX(max_slice
);
3721 if (iview
->image
->info
.samples
> 1) {
3722 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3724 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3725 S_028C74_NUM_FRAGMENTS(log_samples
);
3728 if (radv_image_has_fmask(iview
->image
)) {
3729 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3730 cb
->cb_color_fmask
= va
>> 8;
3731 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3733 cb
->cb_color_fmask
= cb
->cb_color_base
;
3736 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3738 vk_format_get_first_non_void_channel(iview
->vk_format
));
3739 format
= radv_translate_colorformat(iview
->vk_format
);
3740 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3741 radv_finishme("Illegal color\n");
3742 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3743 endian
= radv_colorformat_endian_swap(format
);
3745 /* blend clamp should be set for all NORM/SRGB types */
3746 if (ntype
== V_028C70_NUMBER_UNORM
||
3747 ntype
== V_028C70_NUMBER_SNORM
||
3748 ntype
== V_028C70_NUMBER_SRGB
)
3751 /* set blend bypass according to docs if SINT/UINT or
3752 8/24 COLOR variants */
3753 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3754 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3755 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3760 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3761 (format
== V_028C70_COLOR_8
||
3762 format
== V_028C70_COLOR_8_8
||
3763 format
== V_028C70_COLOR_8_8_8_8
))
3764 ->color_is_int8
= true;
3766 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3767 S_028C70_COMP_SWAP(swap
) |
3768 S_028C70_BLEND_CLAMP(blend_clamp
) |
3769 S_028C70_BLEND_BYPASS(blend_bypass
) |
3770 S_028C70_SIMPLE_FLOAT(1) |
3771 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3772 ntype
!= V_028C70_NUMBER_SNORM
&&
3773 ntype
!= V_028C70_NUMBER_SRGB
&&
3774 format
!= V_028C70_COLOR_8_24
&&
3775 format
!= V_028C70_COLOR_24_8
) |
3776 S_028C70_NUMBER_TYPE(ntype
) |
3777 S_028C70_ENDIAN(endian
);
3778 if (radv_image_has_fmask(iview
->image
)) {
3779 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3780 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3781 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3782 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3786 if (radv_image_has_cmask(iview
->image
) &&
3787 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3788 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3790 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3791 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3793 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3795 /* This must be set for fast clear to work without FMASK. */
3796 if (!radv_image_has_fmask(iview
->image
) &&
3797 device
->physical_device
->rad_info
.chip_class
== SI
) {
3798 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3799 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3802 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3803 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3804 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3806 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3807 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3808 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3809 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3810 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3811 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3816 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3817 struct radv_image_view
*iview
)
3819 unsigned max_zplanes
= 0;
3821 assert(radv_image_is_tc_compat_htile(iview
->image
));
3823 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3824 /* Default value for 32-bit depth surfaces. */
3827 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3828 iview
->image
->info
.samples
> 1)
3831 max_zplanes
= max_zplanes
+ 1;
3833 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3834 /* Do not enable Z plane compression for 16-bit depth
3835 * surfaces because isn't supported on GFX8. Only
3836 * 32-bit depth surfaces are supported by the hardware.
3837 * This allows to maintain shader compatibility and to
3838 * reduce the number of depth decompressions.
3842 if (iview
->image
->info
.samples
<= 1)
3844 else if (iview
->image
->info
.samples
<= 4)
3855 radv_initialise_ds_surface(struct radv_device
*device
,
3856 struct radv_ds_buffer_info
*ds
,
3857 struct radv_image_view
*iview
)
3859 unsigned level
= iview
->base_mip
;
3860 unsigned format
, stencil_format
;
3861 uint64_t va
, s_offs
, z_offs
;
3862 bool stencil_only
= false;
3863 memset(ds
, 0, sizeof(*ds
));
3864 switch (iview
->image
->vk_format
) {
3865 case VK_FORMAT_D24_UNORM_S8_UINT
:
3866 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3867 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3868 ds
->offset_scale
= 2.0f
;
3870 case VK_FORMAT_D16_UNORM
:
3871 case VK_FORMAT_D16_UNORM_S8_UINT
:
3872 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3873 ds
->offset_scale
= 4.0f
;
3875 case VK_FORMAT_D32_SFLOAT
:
3876 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3877 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3878 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3879 ds
->offset_scale
= 1.0f
;
3881 case VK_FORMAT_S8_UINT
:
3882 stencil_only
= true;
3888 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3889 stencil_format
= iview
->image
->surface
.has_stencil
?
3890 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3892 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3893 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3894 S_028008_SLICE_MAX(max_slice
);
3896 ds
->db_htile_data_base
= 0;
3897 ds
->db_htile_surface
= 0;
3899 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3900 s_offs
= z_offs
= va
;
3902 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3903 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3904 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3906 ds
->db_z_info
= S_028038_FORMAT(format
) |
3907 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3908 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3909 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3910 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3911 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3913 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3914 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3915 ds
->db_depth_view
|= S_028008_MIPID(level
);
3917 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3918 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3920 if (radv_htile_enabled(iview
->image
, level
)) {
3921 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3923 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3924 unsigned max_zplanes
=
3925 radv_calc_decompress_on_z_planes(device
, iview
);
3927 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3928 S_028038_ITERATE_FLUSH(1);
3929 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3932 if (!iview
->image
->surface
.has_stencil
)
3933 /* Use all of the htile_buffer for depth if there's no stencil. */
3934 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3935 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3936 iview
->image
->htile_offset
;
3937 ds
->db_htile_data_base
= va
>> 8;
3938 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3939 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3940 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3943 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3946 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3948 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3949 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3951 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3952 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3953 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3955 if (iview
->image
->info
.samples
> 1)
3956 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3958 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3959 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3960 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3961 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3962 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3963 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3964 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3965 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3968 tile_mode
= stencil_tile_mode
;
3970 ds
->db_depth_info
|=
3971 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3972 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3973 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3974 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3975 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3976 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3977 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3978 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3980 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3981 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3982 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3983 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3985 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3988 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3989 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3990 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3992 if (radv_htile_enabled(iview
->image
, level
)) {
3993 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3995 if (!iview
->image
->surface
.has_stencil
&&
3996 !radv_image_is_tc_compat_htile(iview
->image
))
3997 /* Use all of the htile_buffer for depth if there's no stencil. */
3998 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4000 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4001 iview
->image
->htile_offset
;
4002 ds
->db_htile_data_base
= va
>> 8;
4003 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4005 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4006 unsigned max_zplanes
=
4007 radv_calc_decompress_on_z_planes(device
, iview
);
4009 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4010 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4015 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4016 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4019 VkResult
radv_CreateFramebuffer(
4021 const VkFramebufferCreateInfo
* pCreateInfo
,
4022 const VkAllocationCallbacks
* pAllocator
,
4023 VkFramebuffer
* pFramebuffer
)
4025 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4026 struct radv_framebuffer
*framebuffer
;
4028 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4030 size_t size
= sizeof(*framebuffer
) +
4031 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4032 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4033 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4034 if (framebuffer
== NULL
)
4035 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4037 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4038 framebuffer
->width
= pCreateInfo
->width
;
4039 framebuffer
->height
= pCreateInfo
->height
;
4040 framebuffer
->layers
= pCreateInfo
->layers
;
4041 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4042 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4043 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4044 framebuffer
->attachments
[i
].attachment
= iview
;
4045 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4046 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4047 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4048 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4050 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4051 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4052 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4055 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4059 void radv_DestroyFramebuffer(
4062 const VkAllocationCallbacks
* pAllocator
)
4064 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4065 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4069 vk_free2(&device
->alloc
, pAllocator
, fb
);
4072 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4074 switch (address_mode
) {
4075 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4076 return V_008F30_SQ_TEX_WRAP
;
4077 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4078 return V_008F30_SQ_TEX_MIRROR
;
4079 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4080 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4081 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4082 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4083 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4084 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4086 unreachable("illegal tex wrap mode");
4092 radv_tex_compare(VkCompareOp op
)
4095 case VK_COMPARE_OP_NEVER
:
4096 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4097 case VK_COMPARE_OP_LESS
:
4098 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4099 case VK_COMPARE_OP_EQUAL
:
4100 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4101 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4102 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4103 case VK_COMPARE_OP_GREATER
:
4104 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4105 case VK_COMPARE_OP_NOT_EQUAL
:
4106 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4107 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4108 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4109 case VK_COMPARE_OP_ALWAYS
:
4110 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4112 unreachable("illegal compare mode");
4118 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4121 case VK_FILTER_NEAREST
:
4122 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4123 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4124 case VK_FILTER_LINEAR
:
4125 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4126 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4127 case VK_FILTER_CUBIC_IMG
:
4129 fprintf(stderr
, "illegal texture filter");
4135 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4138 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4139 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4140 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4141 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4143 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4148 radv_tex_bordercolor(VkBorderColor bcolor
)
4151 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4152 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4153 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4154 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4155 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4156 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4157 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4158 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4159 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4167 radv_tex_aniso_filter(unsigned filter
)
4181 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4184 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4185 return SQ_IMG_FILTER_MODE_BLEND
;
4186 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4187 return SQ_IMG_FILTER_MODE_MIN
;
4188 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4189 return SQ_IMG_FILTER_MODE_MAX
;
4197 radv_init_sampler(struct radv_device
*device
,
4198 struct radv_sampler
*sampler
,
4199 const VkSamplerCreateInfo
*pCreateInfo
)
4201 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4202 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4203 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4204 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4205 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4207 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4208 vk_find_struct_const(pCreateInfo
->pNext
,
4209 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4210 if (sampler_reduction
)
4211 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4213 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4214 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4215 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4216 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4217 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4218 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4219 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4220 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4221 S_008F30_DISABLE_CUBE_WRAP(0) |
4222 S_008F30_COMPAT_MODE(is_vi
) |
4223 S_008F30_FILTER_MODE(filter_mode
));
4224 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4225 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4226 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4227 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4228 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4229 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4230 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4231 S_008F38_MIP_POINT_PRECLAMP(0) |
4232 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4233 S_008F38_FILTER_PREC_FIX(1) |
4234 S_008F38_ANISO_OVERRIDE(is_vi
));
4235 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4236 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4239 VkResult
radv_CreateSampler(
4241 const VkSamplerCreateInfo
* pCreateInfo
,
4242 const VkAllocationCallbacks
* pAllocator
,
4243 VkSampler
* pSampler
)
4245 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4246 struct radv_sampler
*sampler
;
4248 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4250 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4251 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4253 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4255 radv_init_sampler(device
, sampler
, pCreateInfo
);
4256 *pSampler
= radv_sampler_to_handle(sampler
);
4261 void radv_DestroySampler(
4264 const VkAllocationCallbacks
* pAllocator
)
4266 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4267 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4271 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4274 /* vk_icd.h does not declare this function, so we declare it here to
4275 * suppress Wmissing-prototypes.
4277 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4278 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4280 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4281 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4283 /* For the full details on loader interface versioning, see
4284 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4285 * What follows is a condensed summary, to help you navigate the large and
4286 * confusing official doc.
4288 * - Loader interface v0 is incompatible with later versions. We don't
4291 * - In loader interface v1:
4292 * - The first ICD entrypoint called by the loader is
4293 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4295 * - The ICD must statically expose no other Vulkan symbol unless it is
4296 * linked with -Bsymbolic.
4297 * - Each dispatchable Vulkan handle created by the ICD must be
4298 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4299 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4300 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4301 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4302 * such loader-managed surfaces.
4304 * - Loader interface v2 differs from v1 in:
4305 * - The first ICD entrypoint called by the loader is
4306 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4307 * statically expose this entrypoint.
4309 * - Loader interface v3 differs from v2 in:
4310 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4311 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4312 * because the loader no longer does so.
4314 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4318 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4319 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4322 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4323 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4325 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4327 /* At the moment, we support only the below handle types. */
4328 assert(pGetFdInfo
->handleType
==
4329 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4330 pGetFdInfo
->handleType
==
4331 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4333 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4335 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4339 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4340 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4342 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4344 switch (handleType
) {
4345 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4346 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4350 /* The valid usage section for this function says:
4352 * "handleType must not be one of the handle types defined as
4355 * So opaque handle types fall into the default "unsupported" case.
4357 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4361 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4365 uint32_t syncobj_handle
= 0;
4366 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4368 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4371 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4373 *syncobj
= syncobj_handle
;
4379 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4383 /* If we create a syncobj we do it locally so that if we have an error, we don't
4384 * leave a syncobj in an undetermined state in the fence. */
4385 uint32_t syncobj_handle
= *syncobj
;
4386 if (!syncobj_handle
) {
4387 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4389 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4394 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4396 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4398 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4401 *syncobj
= syncobj_handle
;
4408 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4409 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4411 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4412 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4413 uint32_t *syncobj_dst
= NULL
;
4415 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4416 syncobj_dst
= &sem
->temp_syncobj
;
4418 syncobj_dst
= &sem
->syncobj
;
4421 switch(pImportSemaphoreFdInfo
->handleType
) {
4422 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4423 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4424 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4425 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4427 unreachable("Unhandled semaphore handle type");
4431 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4432 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4435 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4436 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4438 uint32_t syncobj_handle
;
4440 if (sem
->temp_syncobj
)
4441 syncobj_handle
= sem
->temp_syncobj
;
4443 syncobj_handle
= sem
->syncobj
;
4445 switch(pGetFdInfo
->handleType
) {
4446 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4447 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4449 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4450 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4452 if (sem
->temp_syncobj
) {
4453 close (sem
->temp_syncobj
);
4454 sem
->temp_syncobj
= 0;
4456 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4461 unreachable("Unhandled semaphore handle type");
4465 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4469 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4470 VkPhysicalDevice physicalDevice
,
4471 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4472 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4474 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4476 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4477 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4478 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4479 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4480 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4481 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4482 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4483 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4484 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4485 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4486 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4487 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4488 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4490 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4491 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4492 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4496 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4497 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4499 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4500 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4501 uint32_t *syncobj_dst
= NULL
;
4504 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4505 syncobj_dst
= &fence
->temp_syncobj
;
4507 syncobj_dst
= &fence
->syncobj
;
4510 switch(pImportFenceFdInfo
->handleType
) {
4511 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4512 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4513 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4514 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4516 unreachable("Unhandled fence handle type");
4520 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4521 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4524 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4525 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4527 uint32_t syncobj_handle
;
4529 if (fence
->temp_syncobj
)
4530 syncobj_handle
= fence
->temp_syncobj
;
4532 syncobj_handle
= fence
->syncobj
;
4534 switch(pGetFdInfo
->handleType
) {
4535 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4536 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4538 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4539 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4541 if (fence
->temp_syncobj
) {
4542 close (fence
->temp_syncobj
);
4543 fence
->temp_syncobj
= 0;
4545 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4550 unreachable("Unhandled fence handle type");
4554 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4558 void radv_GetPhysicalDeviceExternalFenceProperties(
4559 VkPhysicalDevice physicalDevice
,
4560 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4561 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4563 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4565 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4566 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4567 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4568 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4569 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4570 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4571 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4573 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4574 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4575 pExternalFenceProperties
->externalFenceFeatures
= 0;
4580 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4581 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4582 const VkAllocationCallbacks
* pAllocator
,
4583 VkDebugReportCallbackEXT
* pCallback
)
4585 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4586 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4587 pCreateInfo
, pAllocator
, &instance
->alloc
,
4592 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4593 VkDebugReportCallbackEXT _callback
,
4594 const VkAllocationCallbacks
* pAllocator
)
4596 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4597 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4598 _callback
, pAllocator
, &instance
->alloc
);
4602 radv_DebugReportMessageEXT(VkInstance _instance
,
4603 VkDebugReportFlagsEXT flags
,
4604 VkDebugReportObjectTypeEXT objectType
,
4607 int32_t messageCode
,
4608 const char* pLayerPrefix
,
4609 const char* pMessage
)
4611 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4612 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4613 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4617 radv_GetDeviceGroupPeerMemoryFeatures(
4620 uint32_t localDeviceIndex
,
4621 uint32_t remoteDeviceIndex
,
4622 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4624 assert(localDeviceIndex
== remoteDeviceIndex
);
4626 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4627 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4628 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4629 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;