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
->perftest_flags
& RADV_PERFTEST_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
},
397 radv_get_debug_option_name(int id
)
399 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
400 return radv_debug_options
[id
].string
;
403 static const struct debug_control radv_perftest_options
[] = {
404 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
405 {"sisched", RADV_PERFTEST_SISCHED
},
406 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
407 {"binning", RADV_PERFTEST_BINNING
},
408 {"outoforderrast", RADV_PERFTEST_OUT_OF_ORDER
},
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 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
)
1359 switch (device
->physical_device
->rad_info
.family
) {
1368 device
->gs_table_depth
= 16;
1377 case CHIP_POLARIS10
:
1378 case CHIP_POLARIS11
:
1379 case CHIP_POLARIS12
:
1381 device
->gs_table_depth
= 32;
1384 unreachable("unknown GPU");
1388 static int radv_get_device_extension_index(const char *name
)
1390 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1391 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1397 VkResult
radv_CreateDevice(
1398 VkPhysicalDevice physicalDevice
,
1399 const VkDeviceCreateInfo
* pCreateInfo
,
1400 const VkAllocationCallbacks
* pAllocator
,
1403 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1405 struct radv_device
*device
;
1407 bool keep_shader_info
= false;
1409 /* Check enabled features */
1410 if (pCreateInfo
->pEnabledFeatures
) {
1411 VkPhysicalDeviceFeatures supported_features
;
1412 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1413 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1414 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1415 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1416 for (uint32_t i
= 0; i
< num_features
; i
++) {
1417 if (enabled_feature
[i
] && !supported_feature
[i
])
1418 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1422 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1424 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1426 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1428 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1429 device
->instance
= physical_device
->instance
;
1430 device
->physical_device
= physical_device
;
1432 device
->ws
= physical_device
->ws
;
1434 device
->alloc
= *pAllocator
;
1436 device
->alloc
= physical_device
->instance
->alloc
;
1438 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1439 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1440 int index
= radv_get_device_extension_index(ext_name
);
1441 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1442 vk_free(&device
->alloc
, device
);
1443 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1446 device
->enabled_extensions
.extensions
[index
] = true;
1449 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1451 /* With update after bind we can't attach bo's to the command buffer
1452 * from the descriptor set anymore, so we have to use a global BO list.
1454 device
->use_global_bo_list
=
1455 device
->enabled_extensions
.EXT_descriptor_indexing
;
1457 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1458 list_inithead(&device
->shader_slabs
);
1460 radv_bo_list_init(&device
->bo_list
);
1462 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1463 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1464 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1465 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1466 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1468 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1470 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1471 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1472 if (!device
->queues
[qfi
]) {
1473 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1477 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1479 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1481 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1482 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1483 qfi
, q
, queue_create
->flags
,
1485 if (result
!= VK_SUCCESS
)
1490 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1491 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1493 /* Disabled and not implemented for now. */
1494 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1497 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1500 device
->llvm_supports_spill
= true;
1502 /* The maximum number of scratch waves. Scratch space isn't divided
1503 * evenly between CUs. The number is only a function of the number of CUs.
1504 * We can decrease the constant to decrease the scratch buffer size.
1506 * sctx->scratch_waves must be >= the maximum posible size of
1507 * 1 threadgroup, so that the hw doesn't hang from being unable
1510 * The recommended value is 4 per CU at most. Higher numbers don't
1511 * bring much benefit, but they still occupy chip resources (think
1512 * async compute). I've seen ~2% performance difference between 4 and 32.
1514 uint32_t max_threads_per_block
= 2048;
1515 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1516 max_threads_per_block
/ 64);
1518 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1520 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1521 /* If the KMD allows it (there is a KMD hw register for it),
1522 * allow launching waves out-of-order.
1524 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1527 radv_device_init_gs_info(device
);
1529 device
->tess_offchip_block_dw_size
=
1530 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1531 device
->has_distributed_tess
=
1532 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1533 device
->physical_device
->rad_info
.max_se
>= 2;
1535 if (getenv("RADV_TRACE_FILE")) {
1536 const char *filename
= getenv("RADV_TRACE_FILE");
1538 keep_shader_info
= true;
1540 if (!radv_init_trace(device
))
1543 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1544 radv_dump_enabled_options(device
, stderr
);
1547 device
->keep_shader_info
= keep_shader_info
;
1549 result
= radv_device_init_meta(device
);
1550 if (result
!= VK_SUCCESS
)
1553 radv_device_init_msaa(device
);
1555 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1556 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1558 case RADV_QUEUE_GENERAL
:
1559 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1560 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1561 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1563 case RADV_QUEUE_COMPUTE
:
1564 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1565 radeon_emit(device
->empty_cs
[family
], 0);
1568 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1571 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1572 cik_create_gfx_config(device
);
1574 VkPipelineCacheCreateInfo ci
;
1575 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1578 ci
.pInitialData
= NULL
;
1579 ci
.initialDataSize
= 0;
1581 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1583 if (result
!= VK_SUCCESS
)
1586 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1588 *pDevice
= radv_device_to_handle(device
);
1592 radv_device_finish_meta(device
);
1594 radv_bo_list_finish(&device
->bo_list
);
1596 if (device
->trace_bo
)
1597 device
->ws
->buffer_destroy(device
->trace_bo
);
1599 if (device
->gfx_init
)
1600 device
->ws
->buffer_destroy(device
->gfx_init
);
1602 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1603 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1604 radv_queue_finish(&device
->queues
[i
][q
]);
1605 if (device
->queue_count
[i
])
1606 vk_free(&device
->alloc
, device
->queues
[i
]);
1609 vk_free(&device
->alloc
, device
);
1613 void radv_DestroyDevice(
1615 const VkAllocationCallbacks
* pAllocator
)
1617 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1622 if (device
->trace_bo
)
1623 device
->ws
->buffer_destroy(device
->trace_bo
);
1625 if (device
->gfx_init
)
1626 device
->ws
->buffer_destroy(device
->gfx_init
);
1628 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1629 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1630 radv_queue_finish(&device
->queues
[i
][q
]);
1631 if (device
->queue_count
[i
])
1632 vk_free(&device
->alloc
, device
->queues
[i
]);
1633 if (device
->empty_cs
[i
])
1634 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1636 radv_device_finish_meta(device
);
1638 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1639 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1641 radv_destroy_shader_slabs(device
);
1643 radv_bo_list_finish(&device
->bo_list
);
1644 vk_free(&device
->alloc
, device
);
1647 VkResult
radv_EnumerateInstanceLayerProperties(
1648 uint32_t* pPropertyCount
,
1649 VkLayerProperties
* pProperties
)
1651 if (pProperties
== NULL
) {
1652 *pPropertyCount
= 0;
1656 /* None supported at this time */
1657 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1660 VkResult
radv_EnumerateDeviceLayerProperties(
1661 VkPhysicalDevice physicalDevice
,
1662 uint32_t* pPropertyCount
,
1663 VkLayerProperties
* pProperties
)
1665 if (pProperties
== NULL
) {
1666 *pPropertyCount
= 0;
1670 /* None supported at this time */
1671 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1674 void radv_GetDeviceQueue2(
1676 const VkDeviceQueueInfo2
* pQueueInfo
,
1679 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1680 struct radv_queue
*queue
;
1682 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1683 if (pQueueInfo
->flags
!= queue
->flags
) {
1684 /* From the Vulkan 1.1.70 spec:
1686 * "The queue returned by vkGetDeviceQueue2 must have the same
1687 * flags value from this structure as that used at device
1688 * creation time in a VkDeviceQueueCreateInfo instance. If no
1689 * matching flags were specified at device creation time then
1690 * pQueue will return VK_NULL_HANDLE."
1692 *pQueue
= VK_NULL_HANDLE
;
1696 *pQueue
= radv_queue_to_handle(queue
);
1699 void radv_GetDeviceQueue(
1701 uint32_t queueFamilyIndex
,
1702 uint32_t queueIndex
,
1705 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1706 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1707 .queueFamilyIndex
= queueFamilyIndex
,
1708 .queueIndex
= queueIndex
1711 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1715 fill_geom_tess_rings(struct radv_queue
*queue
,
1717 bool add_sample_positions
,
1718 uint32_t esgs_ring_size
,
1719 struct radeon_winsys_bo
*esgs_ring_bo
,
1720 uint32_t gsvs_ring_size
,
1721 struct radeon_winsys_bo
*gsvs_ring_bo
,
1722 uint32_t tess_factor_ring_size
,
1723 uint32_t tess_offchip_ring_offset
,
1724 uint32_t tess_offchip_ring_size
,
1725 struct radeon_winsys_bo
*tess_rings_bo
)
1727 uint64_t esgs_va
= 0, gsvs_va
= 0;
1728 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1729 uint32_t *desc
= &map
[4];
1732 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1734 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1735 if (tess_rings_bo
) {
1736 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1737 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1740 /* stride 0, num records - size, add tid, swizzle, elsize4,
1743 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1744 S_008F04_STRIDE(0) |
1745 S_008F04_SWIZZLE_ENABLE(true);
1746 desc
[2] = esgs_ring_size
;
1747 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1748 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1749 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1750 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1751 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1752 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1753 S_008F0C_ELEMENT_SIZE(1) |
1754 S_008F0C_INDEX_STRIDE(3) |
1755 S_008F0C_ADD_TID_ENABLE(true);
1758 /* GS entry for ES->GS ring */
1759 /* stride 0, num records - size, elsize0,
1762 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1763 S_008F04_STRIDE(0) |
1764 S_008F04_SWIZZLE_ENABLE(false);
1765 desc
[2] = esgs_ring_size
;
1766 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1767 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1768 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1769 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1770 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1771 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1772 S_008F0C_ELEMENT_SIZE(0) |
1773 S_008F0C_INDEX_STRIDE(0) |
1774 S_008F0C_ADD_TID_ENABLE(false);
1777 /* VS entry for GS->VS ring */
1778 /* stride 0, num records - size, elsize0,
1781 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1782 S_008F04_STRIDE(0) |
1783 S_008F04_SWIZZLE_ENABLE(false);
1784 desc
[2] = gsvs_ring_size
;
1785 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1786 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1787 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1788 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1789 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1790 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1791 S_008F0C_ELEMENT_SIZE(0) |
1792 S_008F0C_INDEX_STRIDE(0) |
1793 S_008F0C_ADD_TID_ENABLE(false);
1796 /* stride gsvs_itemsize, num records 64
1797 elsize 4, index stride 16 */
1798 /* shader will patch stride and desc[2] */
1800 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1801 S_008F04_STRIDE(0) |
1802 S_008F04_SWIZZLE_ENABLE(true);
1804 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1805 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1806 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1807 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1808 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1809 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1810 S_008F0C_ELEMENT_SIZE(1) |
1811 S_008F0C_INDEX_STRIDE(1) |
1812 S_008F0C_ADD_TID_ENABLE(true);
1816 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1817 S_008F04_STRIDE(0) |
1818 S_008F04_SWIZZLE_ENABLE(false);
1819 desc
[2] = tess_factor_ring_size
;
1820 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1821 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1822 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1823 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1824 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1825 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1826 S_008F0C_ELEMENT_SIZE(0) |
1827 S_008F0C_INDEX_STRIDE(0) |
1828 S_008F0C_ADD_TID_ENABLE(false);
1831 desc
[0] = tess_offchip_va
;
1832 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1833 S_008F04_STRIDE(0) |
1834 S_008F04_SWIZZLE_ENABLE(false);
1835 desc
[2] = tess_offchip_ring_size
;
1836 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1837 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1838 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1839 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1840 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1841 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1842 S_008F0C_ELEMENT_SIZE(0) |
1843 S_008F0C_INDEX_STRIDE(0) |
1844 S_008F0C_ADD_TID_ENABLE(false);
1847 /* add sample positions after all rings */
1848 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1850 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1852 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1854 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1856 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1860 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1862 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1863 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1864 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1865 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1866 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1867 device
->physical_device
->rad_info
.max_se
;
1868 unsigned offchip_granularity
;
1869 unsigned hs_offchip_param
;
1870 switch (device
->tess_offchip_block_dw_size
) {
1875 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1878 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1882 switch (device
->physical_device
->rad_info
.chip_class
) {
1884 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1890 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1894 *max_offchip_buffers_p
= max_offchip_buffers
;
1895 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1896 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1897 --max_offchip_buffers
;
1899 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1900 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1903 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1905 return hs_offchip_param
;
1909 radv_get_preamble_cs(struct radv_queue
*queue
,
1910 uint32_t scratch_size
,
1911 uint32_t compute_scratch_size
,
1912 uint32_t esgs_ring_size
,
1913 uint32_t gsvs_ring_size
,
1914 bool needs_tess_rings
,
1915 bool needs_sample_positions
,
1916 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1917 struct radeon_winsys_cs
**initial_preamble_cs
,
1918 struct radeon_winsys_cs
**continue_preamble_cs
)
1920 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1921 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1922 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1923 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1924 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1925 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1926 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1927 bool add_tess_rings
= false, add_sample_positions
= false;
1928 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1929 unsigned max_offchip_buffers
;
1930 unsigned hs_offchip_param
= 0;
1931 unsigned tess_offchip_ring_offset
;
1932 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1933 if (!queue
->has_tess_rings
) {
1934 if (needs_tess_rings
)
1935 add_tess_rings
= true;
1937 if (!queue
->has_sample_positions
) {
1938 if (needs_sample_positions
)
1939 add_sample_positions
= true;
1941 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1942 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1943 &max_offchip_buffers
);
1944 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1945 tess_offchip_ring_size
= max_offchip_buffers
*
1946 queue
->device
->tess_offchip_block_dw_size
* 4;
1948 if (scratch_size
<= queue
->scratch_size
&&
1949 compute_scratch_size
<= queue
->compute_scratch_size
&&
1950 esgs_ring_size
<= queue
->esgs_ring_size
&&
1951 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1952 !add_tess_rings
&& !add_sample_positions
&&
1953 queue
->initial_preamble_cs
) {
1954 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1955 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1956 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1957 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1958 *continue_preamble_cs
= NULL
;
1962 if (scratch_size
> queue
->scratch_size
) {
1963 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1971 scratch_bo
= queue
->scratch_bo
;
1973 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1974 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1975 compute_scratch_size
,
1979 if (!compute_scratch_bo
)
1983 compute_scratch_bo
= queue
->compute_scratch_bo
;
1985 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1986 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1994 esgs_ring_bo
= queue
->esgs_ring_bo
;
1995 esgs_ring_size
= queue
->esgs_ring_size
;
1998 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1999 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2007 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2008 gsvs_ring_size
= queue
->gsvs_ring_size
;
2011 if (add_tess_rings
) {
2012 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2013 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2020 tess_rings_bo
= queue
->tess_rings_bo
;
2023 if (scratch_bo
!= queue
->scratch_bo
||
2024 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2025 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2026 tess_rings_bo
!= queue
->tess_rings_bo
||
2027 add_sample_positions
) {
2029 if (gsvs_ring_bo
|| esgs_ring_bo
||
2030 tess_rings_bo
|| add_sample_positions
) {
2031 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2032 if (add_sample_positions
)
2033 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2035 else if (scratch_bo
)
2036 size
= 8; /* 2 dword */
2038 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2042 RADEON_FLAG_CPU_ACCESS
|
2043 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2044 RADEON_FLAG_READ_ONLY
);
2048 descriptor_bo
= queue
->descriptor_bo
;
2050 for(int i
= 0; i
< 3; ++i
) {
2051 struct radeon_winsys_cs
*cs
= NULL
;
2052 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2053 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2060 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
2063 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
2066 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
2069 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
2072 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
2074 if (descriptor_bo
!= queue
->descriptor_bo
) {
2075 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2078 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2079 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2080 S_008F04_SWIZZLE_ENABLE(1);
2081 map
[0] = scratch_va
;
2085 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2086 add_sample_positions
)
2087 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2088 esgs_ring_size
, esgs_ring_bo
,
2089 gsvs_ring_size
, gsvs_ring_bo
,
2090 tess_factor_ring_size
,
2091 tess_offchip_ring_offset
,
2092 tess_offchip_ring_size
,
2095 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2098 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2099 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2100 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2101 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2102 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2105 if (esgs_ring_bo
|| gsvs_ring_bo
) {
2106 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2107 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2108 radeon_emit(cs
, esgs_ring_size
>> 8);
2109 radeon_emit(cs
, gsvs_ring_size
>> 8);
2111 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2112 radeon_emit(cs
, esgs_ring_size
>> 8);
2113 radeon_emit(cs
, gsvs_ring_size
>> 8);
2117 if (tess_rings_bo
) {
2118 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
2119 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2120 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2121 S_030938_SIZE(tess_factor_ring_size
/ 4));
2122 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2124 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2125 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2126 S_030944_BASE_HI(tf_va
>> 40));
2128 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
2130 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2131 S_008988_SIZE(tess_factor_ring_size
/ 4));
2132 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2134 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2139 if (descriptor_bo
) {
2140 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
2141 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2142 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2143 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2144 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2145 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2147 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2148 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2149 radeon_emit(cs
, va
);
2150 radeon_emit(cs
, va
>> 32);
2153 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2154 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2155 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2156 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2157 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2158 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2160 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2161 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2162 radeon_emit(cs
, va
);
2163 radeon_emit(cs
, va
>> 32);
2168 if (compute_scratch_bo
) {
2169 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2170 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2171 S_008F04_SWIZZLE_ENABLE(1);
2173 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2175 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2176 radeon_emit(cs
, scratch_va
);
2177 radeon_emit(cs
, rsrc1
);
2181 si_cs_emit_cache_flush(cs
,
2182 queue
->device
->physical_device
->rad_info
.chip_class
,
2184 queue
->queue_family_index
== RING_COMPUTE
&&
2185 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2186 (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
)) |
2187 RADV_CMD_FLAG_INV_ICACHE
|
2188 RADV_CMD_FLAG_INV_SMEM_L1
|
2189 RADV_CMD_FLAG_INV_VMEM_L1
|
2190 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2191 } else if (i
== 1) {
2192 si_cs_emit_cache_flush(cs
,
2193 queue
->device
->physical_device
->rad_info
.chip_class
,
2195 queue
->queue_family_index
== RING_COMPUTE
&&
2196 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2197 RADV_CMD_FLAG_INV_ICACHE
|
2198 RADV_CMD_FLAG_INV_SMEM_L1
|
2199 RADV_CMD_FLAG_INV_VMEM_L1
|
2200 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2203 if (!queue
->device
->ws
->cs_finalize(cs
))
2207 if (queue
->initial_full_flush_preamble_cs
)
2208 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2210 if (queue
->initial_preamble_cs
)
2211 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2213 if (queue
->continue_preamble_cs
)
2214 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2216 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2217 queue
->initial_preamble_cs
= dest_cs
[1];
2218 queue
->continue_preamble_cs
= dest_cs
[2];
2220 if (scratch_bo
!= queue
->scratch_bo
) {
2221 if (queue
->scratch_bo
)
2222 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2223 queue
->scratch_bo
= scratch_bo
;
2224 queue
->scratch_size
= scratch_size
;
2227 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2228 if (queue
->compute_scratch_bo
)
2229 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2230 queue
->compute_scratch_bo
= compute_scratch_bo
;
2231 queue
->compute_scratch_size
= compute_scratch_size
;
2234 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2235 if (queue
->esgs_ring_bo
)
2236 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2237 queue
->esgs_ring_bo
= esgs_ring_bo
;
2238 queue
->esgs_ring_size
= esgs_ring_size
;
2241 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2242 if (queue
->gsvs_ring_bo
)
2243 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2244 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2245 queue
->gsvs_ring_size
= gsvs_ring_size
;
2248 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2249 queue
->tess_rings_bo
= tess_rings_bo
;
2250 queue
->has_tess_rings
= true;
2253 if (descriptor_bo
!= queue
->descriptor_bo
) {
2254 if (queue
->descriptor_bo
)
2255 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2257 queue
->descriptor_bo
= descriptor_bo
;
2260 if (add_sample_positions
)
2261 queue
->has_sample_positions
= true;
2263 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2264 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2265 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2266 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2267 *continue_preamble_cs
= NULL
;
2270 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2272 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2273 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2274 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2275 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2276 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2277 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2278 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2279 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2280 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2281 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2282 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2283 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2284 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2285 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2288 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2290 const VkSemaphore
*sems
,
2294 int syncobj_idx
= 0, sem_idx
= 0;
2296 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2299 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2300 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2302 if (sem
->temp_syncobj
|| sem
->syncobj
)
2303 counts
->syncobj_count
++;
2305 counts
->sem_count
++;
2308 if (_fence
!= VK_NULL_HANDLE
) {
2309 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2310 if (fence
->temp_syncobj
|| fence
->syncobj
)
2311 counts
->syncobj_count
++;
2314 if (counts
->syncobj_count
) {
2315 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2316 if (!counts
->syncobj
)
2317 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2320 if (counts
->sem_count
) {
2321 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2323 free(counts
->syncobj
);
2324 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2328 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2329 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2331 if (sem
->temp_syncobj
) {
2332 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2334 else if (sem
->syncobj
)
2335 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2338 counts
->sem
[sem_idx
++] = sem
->sem
;
2342 if (_fence
!= VK_NULL_HANDLE
) {
2343 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2344 if (fence
->temp_syncobj
)
2345 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2346 else if (fence
->syncobj
)
2347 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2353 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2355 free(sem_info
->wait
.syncobj
);
2356 free(sem_info
->wait
.sem
);
2357 free(sem_info
->signal
.syncobj
);
2358 free(sem_info
->signal
.sem
);
2362 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2364 const VkSemaphore
*sems
)
2366 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2367 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2369 if (sem
->temp_syncobj
) {
2370 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2371 sem
->temp_syncobj
= 0;
2376 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2378 const VkSemaphore
*wait_sems
,
2379 int num_signal_sems
,
2380 const VkSemaphore
*signal_sems
,
2384 memset(sem_info
, 0, sizeof(*sem_info
));
2386 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2389 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2391 radv_free_sem_info(sem_info
);
2393 /* caller can override these */
2394 sem_info
->cs_emit_wait
= true;
2395 sem_info
->cs_emit_signal
= true;
2399 /* Signals fence as soon as all the work currently put on queue is done. */
2400 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2401 struct radv_fence
*fence
)
2405 struct radv_winsys_sem_info sem_info
;
2407 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2408 radv_fence_to_handle(fence
));
2409 if (result
!= VK_SUCCESS
)
2412 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2413 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2414 1, NULL
, NULL
, &sem_info
, NULL
,
2415 false, fence
->fence
);
2416 radv_free_sem_info(&sem_info
);
2418 /* TODO: find a better error */
2420 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2425 VkResult
radv_QueueSubmit(
2427 uint32_t submitCount
,
2428 const VkSubmitInfo
* pSubmits
,
2431 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2432 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2433 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2434 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2436 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2437 uint32_t scratch_size
= 0;
2438 uint32_t compute_scratch_size
= 0;
2439 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2440 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2442 bool fence_emitted
= false;
2443 bool tess_rings_needed
= false;
2444 bool sample_positions_needed
= false;
2446 /* Do this first so failing to allocate scratch buffers can't result in
2447 * partially executed submissions. */
2448 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2449 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2450 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2451 pSubmits
[i
].pCommandBuffers
[j
]);
2453 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2454 compute_scratch_size
= MAX2(compute_scratch_size
,
2455 cmd_buffer
->compute_scratch_size_needed
);
2456 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2457 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2458 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2459 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2463 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2464 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2465 sample_positions_needed
, &initial_flush_preamble_cs
,
2466 &initial_preamble_cs
, &continue_preamble_cs
);
2467 if (result
!= VK_SUCCESS
)
2470 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2471 struct radeon_winsys_cs
**cs_array
;
2472 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2473 bool can_patch
= true;
2475 struct radv_winsys_sem_info sem_info
;
2477 result
= radv_alloc_sem_info(&sem_info
,
2478 pSubmits
[i
].waitSemaphoreCount
,
2479 pSubmits
[i
].pWaitSemaphores
,
2480 pSubmits
[i
].signalSemaphoreCount
,
2481 pSubmits
[i
].pSignalSemaphores
,
2483 if (result
!= VK_SUCCESS
)
2486 if (!pSubmits
[i
].commandBufferCount
) {
2487 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2488 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2489 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2494 radv_loge("failed to submit CS %d\n", i
);
2497 fence_emitted
= true;
2499 radv_free_sem_info(&sem_info
);
2503 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2504 (pSubmits
[i
].commandBufferCount
));
2506 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2507 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2508 pSubmits
[i
].pCommandBuffers
[j
]);
2509 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2511 cs_array
[j
] = cmd_buffer
->cs
;
2512 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2515 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2518 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2519 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2520 advance
= MIN2(max_cs_submission
,
2521 pSubmits
[i
].commandBufferCount
- j
);
2523 if (queue
->device
->trace_bo
)
2524 *queue
->device
->trace_id_ptr
= 0;
2526 sem_info
.cs_emit_wait
= j
== 0;
2527 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2529 if (unlikely(queue
->device
->use_global_bo_list
))
2530 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2532 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2533 advance
, initial_preamble
, continue_preamble_cs
,
2534 &sem_info
, &queue
->device
->bo_list
.list
,
2535 can_patch
, base_fence
);
2537 if (unlikely(queue
->device
->use_global_bo_list
))
2538 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2541 radv_loge("failed to submit CS %d\n", i
);
2544 fence_emitted
= true;
2545 if (queue
->device
->trace_bo
) {
2546 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2550 radv_free_temp_syncobjs(queue
->device
,
2551 pSubmits
[i
].waitSemaphoreCount
,
2552 pSubmits
[i
].pWaitSemaphores
);
2553 radv_free_sem_info(&sem_info
);
2558 if (!fence_emitted
) {
2559 radv_signal_fence(queue
, fence
);
2561 fence
->submitted
= true;
2567 VkResult
radv_QueueWaitIdle(
2570 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2572 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2573 radv_queue_family_to_ring(queue
->queue_family_index
),
2578 VkResult
radv_DeviceWaitIdle(
2581 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2583 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2584 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2585 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2591 VkResult
radv_EnumerateInstanceExtensionProperties(
2592 const char* pLayerName
,
2593 uint32_t* pPropertyCount
,
2594 VkExtensionProperties
* pProperties
)
2596 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2598 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2599 if (radv_supported_instance_extensions
.extensions
[i
]) {
2600 vk_outarray_append(&out
, prop
) {
2601 *prop
= radv_instance_extensions
[i
];
2606 return vk_outarray_status(&out
);
2609 VkResult
radv_EnumerateDeviceExtensionProperties(
2610 VkPhysicalDevice physicalDevice
,
2611 const char* pLayerName
,
2612 uint32_t* pPropertyCount
,
2613 VkExtensionProperties
* pProperties
)
2615 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2616 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2618 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2619 if (device
->supported_extensions
.extensions
[i
]) {
2620 vk_outarray_append(&out
, prop
) {
2621 *prop
= radv_device_extensions
[i
];
2626 return vk_outarray_status(&out
);
2629 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2630 VkInstance _instance
,
2633 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2635 return radv_lookup_entrypoint_checked(pName
,
2636 instance
? instance
->apiVersion
: 0,
2637 instance
? &instance
->enabled_extensions
: NULL
,
2641 /* The loader wants us to expose a second GetInstanceProcAddr function
2642 * to work around certain LD_PRELOAD issues seen in apps.
2645 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2646 VkInstance instance
,
2650 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2651 VkInstance instance
,
2654 return radv_GetInstanceProcAddr(instance
, pName
);
2657 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2661 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2663 return radv_lookup_entrypoint_checked(pName
,
2664 device
->instance
->apiVersion
,
2665 &device
->instance
->enabled_extensions
,
2666 &device
->enabled_extensions
);
2669 bool radv_get_memory_fd(struct radv_device
*device
,
2670 struct radv_device_memory
*memory
,
2673 struct radeon_bo_metadata metadata
;
2675 if (memory
->image
) {
2676 radv_init_metadata(device
, memory
->image
, &metadata
);
2677 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2680 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2684 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2685 const VkMemoryAllocateInfo
* pAllocateInfo
,
2686 const VkAllocationCallbacks
* pAllocator
,
2687 VkDeviceMemory
* pMem
)
2689 struct radv_device_memory
*mem
;
2691 enum radeon_bo_domain domain
;
2693 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2695 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2697 if (pAllocateInfo
->allocationSize
== 0) {
2698 /* Apparently, this is allowed */
2699 *pMem
= VK_NULL_HANDLE
;
2703 const VkImportMemoryFdInfoKHR
*import_info
=
2704 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2705 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2706 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2707 const VkExportMemoryAllocateInfoKHR
*export_info
=
2708 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2709 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2710 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2712 const struct wsi_memory_allocate_info
*wsi_info
=
2713 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2715 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2716 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2718 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2720 if (wsi_info
&& wsi_info
->implicit_sync
)
2721 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2723 if (dedicate_info
) {
2724 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2725 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2731 mem
->user_ptr
= NULL
;
2734 assert(import_info
->handleType
==
2735 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2736 import_info
->handleType
==
2737 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2738 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2741 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2744 close(import_info
->fd
);
2746 } else if (host_ptr_info
) {
2747 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2748 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2749 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2750 pAllocateInfo
->allocationSize
);
2752 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2755 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2758 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2759 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2760 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2761 domain
= RADEON_DOMAIN_GTT
;
2763 domain
= RADEON_DOMAIN_VRAM
;
2765 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2766 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2768 flags
|= RADEON_FLAG_CPU_ACCESS
;
2770 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2771 flags
|= RADEON_FLAG_GTT_WC
;
2773 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2774 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2776 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2780 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2783 mem
->type_index
= mem_type_index
;
2786 result
= radv_bo_list_add(device
, mem
->bo
);
2787 if (result
!= VK_SUCCESS
)
2790 *pMem
= radv_device_memory_to_handle(mem
);
2795 device
->ws
->buffer_destroy(mem
->bo
);
2797 vk_free2(&device
->alloc
, pAllocator
, mem
);
2802 VkResult
radv_AllocateMemory(
2804 const VkMemoryAllocateInfo
* pAllocateInfo
,
2805 const VkAllocationCallbacks
* pAllocator
,
2806 VkDeviceMemory
* pMem
)
2808 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2809 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2812 void radv_FreeMemory(
2814 VkDeviceMemory _mem
,
2815 const VkAllocationCallbacks
* pAllocator
)
2817 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2818 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2823 radv_bo_list_remove(device
, mem
->bo
);
2824 device
->ws
->buffer_destroy(mem
->bo
);
2827 vk_free2(&device
->alloc
, pAllocator
, mem
);
2830 VkResult
radv_MapMemory(
2832 VkDeviceMemory _memory
,
2833 VkDeviceSize offset
,
2835 VkMemoryMapFlags flags
,
2838 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2839 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2847 *ppData
= mem
->user_ptr
;
2849 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2856 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2859 void radv_UnmapMemory(
2861 VkDeviceMemory _memory
)
2863 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2864 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2869 if (mem
->user_ptr
== NULL
)
2870 device
->ws
->buffer_unmap(mem
->bo
);
2873 VkResult
radv_FlushMappedMemoryRanges(
2875 uint32_t memoryRangeCount
,
2876 const VkMappedMemoryRange
* pMemoryRanges
)
2881 VkResult
radv_InvalidateMappedMemoryRanges(
2883 uint32_t memoryRangeCount
,
2884 const VkMappedMemoryRange
* pMemoryRanges
)
2889 void radv_GetBufferMemoryRequirements(
2892 VkMemoryRequirements
* pMemoryRequirements
)
2894 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2895 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2897 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2899 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2900 pMemoryRequirements
->alignment
= 4096;
2902 pMemoryRequirements
->alignment
= 16;
2904 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2907 void radv_GetBufferMemoryRequirements2(
2909 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2910 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2912 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2913 &pMemoryRequirements
->memoryRequirements
);
2914 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2915 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2916 switch (ext
->sType
) {
2917 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2918 VkMemoryDedicatedRequirementsKHR
*req
=
2919 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2920 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2921 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2930 void radv_GetImageMemoryRequirements(
2933 VkMemoryRequirements
* pMemoryRequirements
)
2935 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2936 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2938 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2940 pMemoryRequirements
->size
= image
->size
;
2941 pMemoryRequirements
->alignment
= image
->alignment
;
2944 void radv_GetImageMemoryRequirements2(
2946 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2947 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2949 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2950 &pMemoryRequirements
->memoryRequirements
);
2952 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2954 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2955 switch (ext
->sType
) {
2956 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2957 VkMemoryDedicatedRequirementsKHR
*req
=
2958 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2959 req
->requiresDedicatedAllocation
= image
->shareable
;
2960 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2969 void radv_GetImageSparseMemoryRequirements(
2972 uint32_t* pSparseMemoryRequirementCount
,
2973 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2978 void radv_GetImageSparseMemoryRequirements2(
2980 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2981 uint32_t* pSparseMemoryRequirementCount
,
2982 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2987 void radv_GetDeviceMemoryCommitment(
2989 VkDeviceMemory memory
,
2990 VkDeviceSize
* pCommittedMemoryInBytes
)
2992 *pCommittedMemoryInBytes
= 0;
2995 VkResult
radv_BindBufferMemory2(VkDevice device
,
2996 uint32_t bindInfoCount
,
2997 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2999 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3000 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3001 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3004 buffer
->bo
= mem
->bo
;
3005 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3013 VkResult
radv_BindBufferMemory(
3016 VkDeviceMemory memory
,
3017 VkDeviceSize memoryOffset
)
3019 const VkBindBufferMemoryInfoKHR info
= {
3020 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3023 .memoryOffset
= memoryOffset
3026 return radv_BindBufferMemory2(device
, 1, &info
);
3029 VkResult
radv_BindImageMemory2(VkDevice device
,
3030 uint32_t bindInfoCount
,
3031 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3033 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3034 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3035 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3038 image
->bo
= mem
->bo
;
3039 image
->offset
= pBindInfos
[i
].memoryOffset
;
3049 VkResult
radv_BindImageMemory(
3052 VkDeviceMemory memory
,
3053 VkDeviceSize memoryOffset
)
3055 const VkBindImageMemoryInfoKHR info
= {
3056 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3059 .memoryOffset
= memoryOffset
3062 return radv_BindImageMemory2(device
, 1, &info
);
3067 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3068 const VkSparseBufferMemoryBindInfo
*bind
)
3070 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3072 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3073 struct radv_device_memory
*mem
= NULL
;
3075 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3076 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3078 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3079 bind
->pBinds
[i
].resourceOffset
,
3080 bind
->pBinds
[i
].size
,
3081 mem
? mem
->bo
: NULL
,
3082 bind
->pBinds
[i
].memoryOffset
);
3087 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3088 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3090 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3092 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3093 struct radv_device_memory
*mem
= NULL
;
3095 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3096 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3098 device
->ws
->buffer_virtual_bind(image
->bo
,
3099 bind
->pBinds
[i
].resourceOffset
,
3100 bind
->pBinds
[i
].size
,
3101 mem
? mem
->bo
: NULL
,
3102 bind
->pBinds
[i
].memoryOffset
);
3106 VkResult
radv_QueueBindSparse(
3108 uint32_t bindInfoCount
,
3109 const VkBindSparseInfo
* pBindInfo
,
3112 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3113 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3114 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3115 bool fence_emitted
= false;
3117 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3118 struct radv_winsys_sem_info sem_info
;
3119 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3120 radv_sparse_buffer_bind_memory(queue
->device
,
3121 pBindInfo
[i
].pBufferBinds
+ j
);
3124 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3125 radv_sparse_image_opaque_bind_memory(queue
->device
,
3126 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3130 result
= radv_alloc_sem_info(&sem_info
,
3131 pBindInfo
[i
].waitSemaphoreCount
,
3132 pBindInfo
[i
].pWaitSemaphores
,
3133 pBindInfo
[i
].signalSemaphoreCount
,
3134 pBindInfo
[i
].pSignalSemaphores
,
3136 if (result
!= VK_SUCCESS
)
3139 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3140 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3141 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3145 fence_emitted
= true;
3147 fence
->submitted
= true;
3150 radv_free_sem_info(&sem_info
);
3155 if (!fence_emitted
) {
3156 radv_signal_fence(queue
, fence
);
3158 fence
->submitted
= true;
3164 VkResult
radv_CreateFence(
3166 const VkFenceCreateInfo
* pCreateInfo
,
3167 const VkAllocationCallbacks
* pAllocator
,
3170 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3171 const VkExportFenceCreateInfoKHR
*export
=
3172 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3173 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3174 export
? export
->handleTypes
: 0;
3176 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3178 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3181 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3183 fence
->submitted
= false;
3184 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3185 fence
->temp_syncobj
= 0;
3186 if (device
->always_use_syncobj
|| handleTypes
) {
3187 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3189 vk_free2(&device
->alloc
, pAllocator
, fence
);
3190 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3192 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3193 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3195 fence
->fence
= NULL
;
3197 fence
->fence
= device
->ws
->create_fence();
3198 if (!fence
->fence
) {
3199 vk_free2(&device
->alloc
, pAllocator
, fence
);
3200 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3205 *pFence
= radv_fence_to_handle(fence
);
3210 void radv_DestroyFence(
3213 const VkAllocationCallbacks
* pAllocator
)
3215 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3216 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3221 if (fence
->temp_syncobj
)
3222 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3224 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3226 device
->ws
->destroy_fence(fence
->fence
);
3227 vk_free2(&device
->alloc
, pAllocator
, fence
);
3231 static uint64_t radv_get_current_time()
3234 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3235 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3238 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3240 uint64_t current_time
= radv_get_current_time();
3242 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3244 return current_time
+ timeout
;
3248 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3250 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3251 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3252 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3258 VkResult
radv_WaitForFences(
3260 uint32_t fenceCount
,
3261 const VkFence
* pFences
,
3265 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3266 timeout
= radv_get_absolute_timeout(timeout
);
3268 if (device
->always_use_syncobj
) {
3269 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3271 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3273 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3274 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3275 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3278 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3281 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3284 if (!waitAll
&& fenceCount
> 1) {
3285 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3286 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3287 uint32_t wait_count
= 0;
3288 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3290 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3292 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3293 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3295 if (fence
->signalled
) {
3300 fences
[wait_count
++] = fence
->fence
;
3303 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3304 waitAll
, timeout
- radv_get_current_time());
3307 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3310 while(radv_get_current_time() <= timeout
) {
3311 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3312 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3319 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3320 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3321 bool expired
= false;
3323 if (fence
->temp_syncobj
) {
3324 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3329 if (fence
->syncobj
) {
3330 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3335 if (fence
->signalled
)
3338 if (!fence
->submitted
) {
3339 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3342 if (!fence
->submitted
)
3345 /* Recheck as it may have been set by submitting operations. */
3346 if (fence
->signalled
)
3350 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3354 fence
->signalled
= true;
3360 VkResult
radv_ResetFences(VkDevice _device
,
3361 uint32_t fenceCount
,
3362 const VkFence
*pFences
)
3364 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3366 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3367 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3368 fence
->submitted
= fence
->signalled
= false;
3370 /* Per spec, we first restore the permanent payload, and then reset, so
3371 * having a temp syncobj should not skip resetting the permanent syncobj. */
3372 if (fence
->temp_syncobj
) {
3373 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3374 fence
->temp_syncobj
= 0;
3377 if (fence
->syncobj
) {
3378 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3385 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3387 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3388 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3390 if (fence
->temp_syncobj
) {
3391 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3392 return success
? VK_SUCCESS
: VK_NOT_READY
;
3395 if (fence
->syncobj
) {
3396 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3397 return success
? VK_SUCCESS
: VK_NOT_READY
;
3400 if (fence
->signalled
)
3402 if (!fence
->submitted
)
3403 return VK_NOT_READY
;
3404 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3405 return VK_NOT_READY
;
3411 // Queue semaphore functions
3413 VkResult
radv_CreateSemaphore(
3415 const VkSemaphoreCreateInfo
* pCreateInfo
,
3416 const VkAllocationCallbacks
* pAllocator
,
3417 VkSemaphore
* pSemaphore
)
3419 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3420 const VkExportSemaphoreCreateInfoKHR
*export
=
3421 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3422 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3423 export
? export
->handleTypes
: 0;
3425 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3427 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3429 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3431 sem
->temp_syncobj
= 0;
3432 /* create a syncobject if we are going to export this semaphore */
3433 if (device
->always_use_syncobj
|| handleTypes
) {
3434 assert (device
->physical_device
->rad_info
.has_syncobj
);
3435 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3437 vk_free2(&device
->alloc
, pAllocator
, sem
);
3438 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3442 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3444 vk_free2(&device
->alloc
, pAllocator
, sem
);
3445 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3450 *pSemaphore
= radv_semaphore_to_handle(sem
);
3454 void radv_DestroySemaphore(
3456 VkSemaphore _semaphore
,
3457 const VkAllocationCallbacks
* pAllocator
)
3459 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3460 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3465 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3467 device
->ws
->destroy_sem(sem
->sem
);
3468 vk_free2(&device
->alloc
, pAllocator
, sem
);
3471 VkResult
radv_CreateEvent(
3473 const VkEventCreateInfo
* pCreateInfo
,
3474 const VkAllocationCallbacks
* pAllocator
,
3477 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3478 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3480 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3483 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3485 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3487 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3489 vk_free2(&device
->alloc
, pAllocator
, event
);
3490 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3493 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3495 *pEvent
= radv_event_to_handle(event
);
3500 void radv_DestroyEvent(
3503 const VkAllocationCallbacks
* pAllocator
)
3505 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3506 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3510 device
->ws
->buffer_destroy(event
->bo
);
3511 vk_free2(&device
->alloc
, pAllocator
, event
);
3514 VkResult
radv_GetEventStatus(
3518 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3520 if (*event
->map
== 1)
3521 return VK_EVENT_SET
;
3522 return VK_EVENT_RESET
;
3525 VkResult
radv_SetEvent(
3529 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3535 VkResult
radv_ResetEvent(
3539 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3545 VkResult
radv_CreateBuffer(
3547 const VkBufferCreateInfo
* pCreateInfo
,
3548 const VkAllocationCallbacks
* pAllocator
,
3551 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3552 struct radv_buffer
*buffer
;
3554 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3556 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3557 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3559 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3561 buffer
->size
= pCreateInfo
->size
;
3562 buffer
->usage
= pCreateInfo
->usage
;
3565 buffer
->flags
= pCreateInfo
->flags
;
3567 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3568 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3570 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3571 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3572 align64(buffer
->size
, 4096),
3573 4096, 0, RADEON_FLAG_VIRTUAL
);
3575 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3576 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3580 *pBuffer
= radv_buffer_to_handle(buffer
);
3585 void radv_DestroyBuffer(
3588 const VkAllocationCallbacks
* pAllocator
)
3590 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3591 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3596 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3597 device
->ws
->buffer_destroy(buffer
->bo
);
3599 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3602 static inline unsigned
3603 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3606 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3608 return image
->surface
.u
.legacy
.tiling_index
[level
];
3611 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3613 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3617 radv_init_dcc_control_reg(struct radv_device
*device
,
3618 struct radv_image_view
*iview
)
3620 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3621 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3622 unsigned max_compressed_block_size
;
3623 unsigned independent_64b_blocks
;
3625 if (device
->physical_device
->rad_info
.chip_class
< VI
)
3628 if (iview
->image
->info
.samples
> 1) {
3629 if (iview
->image
->surface
.bpe
== 1)
3630 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3631 else if (iview
->image
->surface
.bpe
== 2)
3632 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3635 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3636 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3637 * dGPU and 64 for APU because all of our APUs to date use
3638 * DIMMs which have a request granularity size of 64B while all
3639 * other chips have a 32B request size.
3641 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3644 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3645 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3646 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3647 /* If this DCC image is potentially going to be used in texture
3648 * fetches, we need some special settings.
3650 independent_64b_blocks
= 1;
3651 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3653 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3654 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3655 * big as possible for better compression state.
3657 independent_64b_blocks
= 0;
3658 max_compressed_block_size
= max_uncompressed_block_size
;
3661 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3662 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3663 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3664 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3668 radv_initialise_color_surface(struct radv_device
*device
,
3669 struct radv_color_buffer_info
*cb
,
3670 struct radv_image_view
*iview
)
3672 const struct vk_format_description
*desc
;
3673 unsigned ntype
, format
, swap
, endian
;
3674 unsigned blend_clamp
= 0, blend_bypass
= 0;
3676 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3678 desc
= vk_format_description(iview
->vk_format
);
3680 memset(cb
, 0, sizeof(*cb
));
3682 /* Intensity is implemented as Red, so treat it that way. */
3683 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3685 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3687 cb
->cb_color_base
= va
>> 8;
3689 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3690 struct gfx9_surf_meta_flags meta
;
3691 if (iview
->image
->dcc_offset
)
3692 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3694 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3696 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3697 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3698 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3699 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3701 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3702 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3704 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3705 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3707 cb
->cb_color_base
+= level_info
->offset
>> 8;
3708 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3709 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3711 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3712 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3713 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3715 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3716 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3717 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3719 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3721 if (radv_image_has_fmask(iview
->image
)) {
3722 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3723 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3724 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3725 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3727 /* This must be set for fast clear to work without FMASK. */
3728 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3729 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3730 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3731 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3735 /* CMASK variables */
3736 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3737 va
+= iview
->image
->cmask
.offset
;
3738 cb
->cb_color_cmask
= va
>> 8;
3740 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3741 va
+= iview
->image
->dcc_offset
;
3742 cb
->cb_dcc_base
= va
>> 8;
3743 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3745 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3746 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3747 S_028C6C_SLICE_MAX(max_slice
);
3749 if (iview
->image
->info
.samples
> 1) {
3750 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3752 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3753 S_028C74_NUM_FRAGMENTS(log_samples
);
3756 if (radv_image_has_fmask(iview
->image
)) {
3757 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3758 cb
->cb_color_fmask
= va
>> 8;
3759 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3761 cb
->cb_color_fmask
= cb
->cb_color_base
;
3764 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3766 vk_format_get_first_non_void_channel(iview
->vk_format
));
3767 format
= radv_translate_colorformat(iview
->vk_format
);
3768 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3769 radv_finishme("Illegal color\n");
3770 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3771 endian
= radv_colorformat_endian_swap(format
);
3773 /* blend clamp should be set for all NORM/SRGB types */
3774 if (ntype
== V_028C70_NUMBER_UNORM
||
3775 ntype
== V_028C70_NUMBER_SNORM
||
3776 ntype
== V_028C70_NUMBER_SRGB
)
3779 /* set blend bypass according to docs if SINT/UINT or
3780 8/24 COLOR variants */
3781 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3782 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3783 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3788 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3789 (format
== V_028C70_COLOR_8
||
3790 format
== V_028C70_COLOR_8_8
||
3791 format
== V_028C70_COLOR_8_8_8_8
))
3792 ->color_is_int8
= true;
3794 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3795 S_028C70_COMP_SWAP(swap
) |
3796 S_028C70_BLEND_CLAMP(blend_clamp
) |
3797 S_028C70_BLEND_BYPASS(blend_bypass
) |
3798 S_028C70_SIMPLE_FLOAT(1) |
3799 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3800 ntype
!= V_028C70_NUMBER_SNORM
&&
3801 ntype
!= V_028C70_NUMBER_SRGB
&&
3802 format
!= V_028C70_COLOR_8_24
&&
3803 format
!= V_028C70_COLOR_24_8
) |
3804 S_028C70_NUMBER_TYPE(ntype
) |
3805 S_028C70_ENDIAN(endian
);
3806 if (radv_image_has_fmask(iview
->image
)) {
3807 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3808 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3809 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3810 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3814 if (radv_image_has_cmask(iview
->image
) &&
3815 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3816 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3818 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3819 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3821 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
3823 /* This must be set for fast clear to work without FMASK. */
3824 if (!radv_image_has_fmask(iview
->image
) &&
3825 device
->physical_device
->rad_info
.chip_class
== SI
) {
3826 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3827 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3830 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3831 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3832 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3834 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3835 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3836 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3837 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3838 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3839 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3844 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3845 struct radv_image_view
*iview
)
3847 unsigned max_zplanes
= 0;
3849 assert(radv_image_is_tc_compat_htile(iview
->image
));
3851 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3852 /* Default value for 32-bit depth surfaces. */
3855 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3856 iview
->image
->info
.samples
> 1)
3859 max_zplanes
= max_zplanes
+ 1;
3861 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3862 /* Do not enable Z plane compression for 16-bit depth
3863 * surfaces because isn't supported on GFX8. Only
3864 * 32-bit depth surfaces are supported by the hardware.
3865 * This allows to maintain shader compatibility and to
3866 * reduce the number of depth decompressions.
3870 if (iview
->image
->info
.samples
<= 1)
3872 else if (iview
->image
->info
.samples
<= 4)
3883 radv_initialise_ds_surface(struct radv_device
*device
,
3884 struct radv_ds_buffer_info
*ds
,
3885 struct radv_image_view
*iview
)
3887 unsigned level
= iview
->base_mip
;
3888 unsigned format
, stencil_format
;
3889 uint64_t va
, s_offs
, z_offs
;
3890 bool stencil_only
= false;
3891 memset(ds
, 0, sizeof(*ds
));
3892 switch (iview
->image
->vk_format
) {
3893 case VK_FORMAT_D24_UNORM_S8_UINT
:
3894 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3895 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3896 ds
->offset_scale
= 2.0f
;
3898 case VK_FORMAT_D16_UNORM
:
3899 case VK_FORMAT_D16_UNORM_S8_UINT
:
3900 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3901 ds
->offset_scale
= 4.0f
;
3903 case VK_FORMAT_D32_SFLOAT
:
3904 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3905 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3906 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3907 ds
->offset_scale
= 1.0f
;
3909 case VK_FORMAT_S8_UINT
:
3910 stencil_only
= true;
3916 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3917 stencil_format
= iview
->image
->surface
.has_stencil
?
3918 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3920 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3921 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3922 S_028008_SLICE_MAX(max_slice
);
3924 ds
->db_htile_data_base
= 0;
3925 ds
->db_htile_surface
= 0;
3927 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3928 s_offs
= z_offs
= va
;
3930 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3931 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3932 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3934 ds
->db_z_info
= S_028038_FORMAT(format
) |
3935 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3936 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3937 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3938 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3939 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3941 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3942 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3943 ds
->db_depth_view
|= S_028008_MIPID(level
);
3945 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3946 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3948 if (radv_htile_enabled(iview
->image
, level
)) {
3949 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3951 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3952 unsigned max_zplanes
=
3953 radv_calc_decompress_on_z_planes(device
, iview
);
3955 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3956 S_028038_ITERATE_FLUSH(1);
3957 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3960 if (!iview
->image
->surface
.has_stencil
)
3961 /* Use all of the htile_buffer for depth if there's no stencil. */
3962 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3963 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3964 iview
->image
->htile_offset
;
3965 ds
->db_htile_data_base
= va
>> 8;
3966 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3967 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3968 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3971 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3974 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3976 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3977 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3979 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3980 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3981 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3983 if (iview
->image
->info
.samples
> 1)
3984 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3986 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3987 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3988 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3989 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3990 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3991 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3992 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3993 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3996 tile_mode
= stencil_tile_mode
;
3998 ds
->db_depth_info
|=
3999 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4000 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4001 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4002 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4003 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4004 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4005 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4006 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4008 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4009 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4010 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4011 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4013 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4016 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4017 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4018 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4020 if (radv_htile_enabled(iview
->image
, level
)) {
4021 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4023 if (!iview
->image
->surface
.has_stencil
&&
4024 !radv_image_is_tc_compat_htile(iview
->image
))
4025 /* Use all of the htile_buffer for depth if there's no stencil. */
4026 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4028 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4029 iview
->image
->htile_offset
;
4030 ds
->db_htile_data_base
= va
>> 8;
4031 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4033 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4034 unsigned max_zplanes
=
4035 radv_calc_decompress_on_z_planes(device
, iview
);
4037 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4038 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4043 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4044 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4047 VkResult
radv_CreateFramebuffer(
4049 const VkFramebufferCreateInfo
* pCreateInfo
,
4050 const VkAllocationCallbacks
* pAllocator
,
4051 VkFramebuffer
* pFramebuffer
)
4053 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4054 struct radv_framebuffer
*framebuffer
;
4056 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4058 size_t size
= sizeof(*framebuffer
) +
4059 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4060 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4061 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4062 if (framebuffer
== NULL
)
4063 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4065 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4066 framebuffer
->width
= pCreateInfo
->width
;
4067 framebuffer
->height
= pCreateInfo
->height
;
4068 framebuffer
->layers
= pCreateInfo
->layers
;
4069 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4070 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4071 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4072 framebuffer
->attachments
[i
].attachment
= iview
;
4073 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4074 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4075 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4076 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4078 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4079 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4080 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4083 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4087 void radv_DestroyFramebuffer(
4090 const VkAllocationCallbacks
* pAllocator
)
4092 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4093 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4097 vk_free2(&device
->alloc
, pAllocator
, fb
);
4100 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4102 switch (address_mode
) {
4103 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4104 return V_008F30_SQ_TEX_WRAP
;
4105 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4106 return V_008F30_SQ_TEX_MIRROR
;
4107 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4108 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4109 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4110 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4111 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4112 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4114 unreachable("illegal tex wrap mode");
4120 radv_tex_compare(VkCompareOp op
)
4123 case VK_COMPARE_OP_NEVER
:
4124 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4125 case VK_COMPARE_OP_LESS
:
4126 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4127 case VK_COMPARE_OP_EQUAL
:
4128 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4129 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4130 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4131 case VK_COMPARE_OP_GREATER
:
4132 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4133 case VK_COMPARE_OP_NOT_EQUAL
:
4134 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4135 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4136 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4137 case VK_COMPARE_OP_ALWAYS
:
4138 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4140 unreachable("illegal compare mode");
4146 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4149 case VK_FILTER_NEAREST
:
4150 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4151 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4152 case VK_FILTER_LINEAR
:
4153 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4154 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4155 case VK_FILTER_CUBIC_IMG
:
4157 fprintf(stderr
, "illegal texture filter");
4163 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4166 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4167 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4168 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4169 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4171 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4176 radv_tex_bordercolor(VkBorderColor bcolor
)
4179 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4180 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4181 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4182 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4183 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4184 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4185 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4186 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4187 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4195 radv_tex_aniso_filter(unsigned filter
)
4209 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4212 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4213 return SQ_IMG_FILTER_MODE_BLEND
;
4214 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4215 return SQ_IMG_FILTER_MODE_MIN
;
4216 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4217 return SQ_IMG_FILTER_MODE_MAX
;
4225 radv_init_sampler(struct radv_device
*device
,
4226 struct radv_sampler
*sampler
,
4227 const VkSamplerCreateInfo
*pCreateInfo
)
4229 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4230 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4231 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4232 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4233 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4235 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4236 vk_find_struct_const(pCreateInfo
->pNext
,
4237 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4238 if (sampler_reduction
)
4239 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4241 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4242 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4243 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4244 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4245 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4246 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4247 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4248 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4249 S_008F30_DISABLE_CUBE_WRAP(0) |
4250 S_008F30_COMPAT_MODE(is_vi
) |
4251 S_008F30_FILTER_MODE(filter_mode
));
4252 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4253 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4254 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4255 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4256 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4257 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4258 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4259 S_008F38_MIP_POINT_PRECLAMP(0) |
4260 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4261 S_008F38_FILTER_PREC_FIX(1) |
4262 S_008F38_ANISO_OVERRIDE(is_vi
));
4263 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4264 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4267 VkResult
radv_CreateSampler(
4269 const VkSamplerCreateInfo
* pCreateInfo
,
4270 const VkAllocationCallbacks
* pAllocator
,
4271 VkSampler
* pSampler
)
4273 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4274 struct radv_sampler
*sampler
;
4276 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4278 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4279 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4281 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4283 radv_init_sampler(device
, sampler
, pCreateInfo
);
4284 *pSampler
= radv_sampler_to_handle(sampler
);
4289 void radv_DestroySampler(
4292 const VkAllocationCallbacks
* pAllocator
)
4294 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4295 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4299 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4302 /* vk_icd.h does not declare this function, so we declare it here to
4303 * suppress Wmissing-prototypes.
4305 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4306 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4308 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4309 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4311 /* For the full details on loader interface versioning, see
4312 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4313 * What follows is a condensed summary, to help you navigate the large and
4314 * confusing official doc.
4316 * - Loader interface v0 is incompatible with later versions. We don't
4319 * - In loader interface v1:
4320 * - The first ICD entrypoint called by the loader is
4321 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4323 * - The ICD must statically expose no other Vulkan symbol unless it is
4324 * linked with -Bsymbolic.
4325 * - Each dispatchable Vulkan handle created by the ICD must be
4326 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4327 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4328 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4329 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4330 * such loader-managed surfaces.
4332 * - Loader interface v2 differs from v1 in:
4333 * - The first ICD entrypoint called by the loader is
4334 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4335 * statically expose this entrypoint.
4337 * - Loader interface v3 differs from v2 in:
4338 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4339 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4340 * because the loader no longer does so.
4342 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4346 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4347 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4350 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4351 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4353 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4355 /* At the moment, we support only the below handle types. */
4356 assert(pGetFdInfo
->handleType
==
4357 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4358 pGetFdInfo
->handleType
==
4359 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4361 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4363 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4367 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4368 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4370 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4372 switch (handleType
) {
4373 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4374 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4378 /* The valid usage section for this function says:
4380 * "handleType must not be one of the handle types defined as
4383 * So opaque handle types fall into the default "unsupported" case.
4385 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4389 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4393 uint32_t syncobj_handle
= 0;
4394 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4396 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4399 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4401 *syncobj
= syncobj_handle
;
4407 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4411 /* If we create a syncobj we do it locally so that if we have an error, we don't
4412 * leave a syncobj in an undetermined state in the fence. */
4413 uint32_t syncobj_handle
= *syncobj
;
4414 if (!syncobj_handle
) {
4415 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4417 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4422 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4424 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4426 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4429 *syncobj
= syncobj_handle
;
4436 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4437 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4439 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4440 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4441 uint32_t *syncobj_dst
= NULL
;
4443 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4444 syncobj_dst
= &sem
->temp_syncobj
;
4446 syncobj_dst
= &sem
->syncobj
;
4449 switch(pImportSemaphoreFdInfo
->handleType
) {
4450 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4451 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4452 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4453 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4455 unreachable("Unhandled semaphore handle type");
4459 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4460 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4463 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4464 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4466 uint32_t syncobj_handle
;
4468 if (sem
->temp_syncobj
)
4469 syncobj_handle
= sem
->temp_syncobj
;
4471 syncobj_handle
= sem
->syncobj
;
4473 switch(pGetFdInfo
->handleType
) {
4474 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4475 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4477 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4478 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4480 if (sem
->temp_syncobj
) {
4481 close (sem
->temp_syncobj
);
4482 sem
->temp_syncobj
= 0;
4484 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4489 unreachable("Unhandled semaphore handle type");
4493 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4497 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4498 VkPhysicalDevice physicalDevice
,
4499 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4500 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4502 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4504 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4505 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4506 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4507 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4508 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4509 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4510 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4511 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4512 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4513 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4514 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4515 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4516 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4518 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4519 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4520 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4524 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4525 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4527 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4528 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4529 uint32_t *syncobj_dst
= NULL
;
4532 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4533 syncobj_dst
= &fence
->temp_syncobj
;
4535 syncobj_dst
= &fence
->syncobj
;
4538 switch(pImportFenceFdInfo
->handleType
) {
4539 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4540 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4541 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4542 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4544 unreachable("Unhandled fence handle type");
4548 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4549 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4552 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4553 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4555 uint32_t syncobj_handle
;
4557 if (fence
->temp_syncobj
)
4558 syncobj_handle
= fence
->temp_syncobj
;
4560 syncobj_handle
= fence
->syncobj
;
4562 switch(pGetFdInfo
->handleType
) {
4563 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4564 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4566 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4567 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4569 if (fence
->temp_syncobj
) {
4570 close (fence
->temp_syncobj
);
4571 fence
->temp_syncobj
= 0;
4573 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4578 unreachable("Unhandled fence handle type");
4582 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4586 void radv_GetPhysicalDeviceExternalFenceProperties(
4587 VkPhysicalDevice physicalDevice
,
4588 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4589 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4591 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4593 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4594 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4595 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4596 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4597 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4598 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4599 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4601 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4602 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4603 pExternalFenceProperties
->externalFenceFeatures
= 0;
4608 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4609 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4610 const VkAllocationCallbacks
* pAllocator
,
4611 VkDebugReportCallbackEXT
* pCallback
)
4613 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4614 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4615 pCreateInfo
, pAllocator
, &instance
->alloc
,
4620 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4621 VkDebugReportCallbackEXT _callback
,
4622 const VkAllocationCallbacks
* pAllocator
)
4624 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4625 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4626 _callback
, pAllocator
, &instance
->alloc
);
4630 radv_DebugReportMessageEXT(VkInstance _instance
,
4631 VkDebugReportFlagsEXT flags
,
4632 VkDebugReportObjectTypeEXT objectType
,
4635 int32_t messageCode
,
4636 const char* pLayerPrefix
,
4637 const char* pMessage
)
4639 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4640 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4641 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4645 radv_GetDeviceGroupPeerMemoryFeatures(
4648 uint32_t localDeviceIndex
,
4649 uint32_t remoteDeviceIndex
,
4650 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4652 assert(localDeviceIndex
== remoteDeviceIndex
);
4654 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4655 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4656 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4657 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;