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_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
105 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
106 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
107 default: chip_string
= "AMD RADV unknown"; break;
111 snprintf(llvm_string
, sizeof(llvm_string
),
112 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
113 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
116 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
120 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
122 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
123 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
124 device
->rad_info
.vram_vis_size
);
126 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
127 device
->memory_properties
.memoryHeapCount
= 0;
128 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
129 vram_index
= device
->memory_properties
.memoryHeapCount
++;
130 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
131 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
132 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
135 if (visible_vram_size
) {
136 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
137 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
138 .size
= visible_vram_size
,
139 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
142 if (device
->rad_info
.gart_size
> 0) {
143 gart_index
= device
->memory_properties
.memoryHeapCount
++;
144 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
145 .size
= device
->rad_info
.gart_size
,
150 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
151 unsigned type_count
= 0;
152 if (vram_index
>= 0) {
153 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
154 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
155 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
156 .heapIndex
= vram_index
,
159 if (gart_index
>= 0) {
160 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
161 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
162 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
163 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
164 .heapIndex
= gart_index
,
167 if (visible_vram_index
>= 0) {
168 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
169 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
170 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
171 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
172 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
173 .heapIndex
= visible_vram_index
,
176 if (gart_index
>= 0) {
177 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
178 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
179 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
181 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
182 .heapIndex
= gart_index
,
185 device
->memory_properties
.memoryTypeCount
= type_count
;
189 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
191 const char *family
= getenv("RADV_FORCE_FAMILY");
197 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
198 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
199 /* Override family and chip_class. */
200 device
->rad_info
.family
= i
;
202 if (i
>= CHIP_VEGA10
)
203 device
->rad_info
.chip_class
= GFX9
;
204 else if (i
>= CHIP_TONGA
)
205 device
->rad_info
.chip_class
= VI
;
206 else if (i
>= CHIP_BONAIRE
)
207 device
->rad_info
.chip_class
= CIK
;
209 device
->rad_info
.chip_class
= SI
;
215 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
220 radv_physical_device_init(struct radv_physical_device
*device
,
221 struct radv_instance
*instance
,
222 drmDevicePtr drm_device
)
224 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
226 drmVersionPtr version
;
229 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
231 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
233 version
= drmGetVersion(fd
);
236 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
237 "failed to get version %s: %m", path
);
240 if (strcmp(version
->name
, "amdgpu")) {
241 drmFreeVersion(version
);
243 return VK_ERROR_INCOMPATIBLE_DRIVER
;
245 drmFreeVersion(version
);
247 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
248 device
->instance
= instance
;
249 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
250 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
252 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
253 instance
->perftest_flags
);
255 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
259 device
->local_fd
= fd
;
260 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
262 radv_handle_env_var_force_family(device
);
264 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
266 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
267 device
->ws
->destroy(device
->ws
);
268 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
269 "cannot generate UUID");
273 /* These flags affect shader compilation. */
274 uint64_t shader_env_flags
=
275 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
276 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
278 /* The gpu id is already embeded in the uuid so we just pass "radv"
279 * when creating the cache.
281 char buf
[VK_UUID_SIZE
* 2 + 1];
282 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
283 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
285 if (device
->rad_info
.chip_class
< VI
||
286 device
->rad_info
.chip_class
> GFX9
)
287 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
289 radv_get_driver_uuid(&device
->device_uuid
);
290 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
292 if (device
->rad_info
.family
== CHIP_STONEY
||
293 device
->rad_info
.chip_class
>= GFX9
) {
294 device
->has_rbplus
= true;
295 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
296 device
->rad_info
.family
== CHIP_VEGA12
;
299 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
302 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
304 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
306 /* Vega10/Raven need a special workaround for a hardware bug. */
307 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
308 device
->rad_info
.family
== CHIP_RAVEN
;
310 /* Out-of-order primitive rasterization. */
311 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
312 device
->rad_info
.max_se
>= 2;
313 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
314 (device
->instance
->perftest_flags
& RADV_PERFTEST_OUT_OF_ORDER
);
316 radv_physical_device_init_mem_types(device
);
317 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
319 result
= radv_init_wsi(device
);
320 if (result
!= VK_SUCCESS
) {
321 device
->ws
->destroy(device
->ws
);
333 radv_physical_device_finish(struct radv_physical_device
*device
)
335 radv_finish_wsi(device
);
336 device
->ws
->destroy(device
->ws
);
337 disk_cache_destroy(device
->disk_cache
);
338 close(device
->local_fd
);
342 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
343 VkSystemAllocationScope allocationScope
)
349 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
350 size_t align
, VkSystemAllocationScope allocationScope
)
352 return realloc(pOriginal
, size
);
356 default_free_func(void *pUserData
, void *pMemory
)
361 static const VkAllocationCallbacks default_alloc
= {
363 .pfnAllocation
= default_alloc_func
,
364 .pfnReallocation
= default_realloc_func
,
365 .pfnFree
= default_free_func
,
368 static const struct debug_control radv_debug_options
[] = {
369 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
370 {"nodcc", RADV_DEBUG_NO_DCC
},
371 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
372 {"nocache", RADV_DEBUG_NO_CACHE
},
373 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
374 {"nohiz", RADV_DEBUG_NO_HIZ
},
375 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
376 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
377 {"allbos", RADV_DEBUG_ALL_BOS
},
378 {"noibs", RADV_DEBUG_NO_IBS
},
379 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
380 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
381 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
382 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
383 {"nosisched", RADV_DEBUG_NO_SISCHED
},
384 {"preoptir", RADV_DEBUG_PREOPTIR
},
389 radv_get_debug_option_name(int id
)
391 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
392 return radv_debug_options
[id
].string
;
395 static const struct debug_control radv_perftest_options
[] = {
396 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
397 {"sisched", RADV_PERFTEST_SISCHED
},
398 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
399 {"binning", RADV_PERFTEST_BINNING
},
400 {"outoforderrast", RADV_PERFTEST_OUT_OF_ORDER
},
405 radv_get_perftest_option_name(int id
)
407 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
408 return radv_perftest_options
[id
].string
;
412 radv_handle_per_app_options(struct radv_instance
*instance
,
413 const VkApplicationInfo
*info
)
415 const char *name
= info
? info
->pApplicationName
: NULL
;
420 if (!strcmp(name
, "Talos - Linux - 32bit") ||
421 !strcmp(name
, "Talos - Linux - 64bit")) {
422 /* Force enable LLVM sisched for Talos because it looks safe
423 * and it gives few more FPS.
425 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
429 static int radv_get_instance_extension_index(const char *name
)
431 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
432 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
439 VkResult
radv_CreateInstance(
440 const VkInstanceCreateInfo
* pCreateInfo
,
441 const VkAllocationCallbacks
* pAllocator
,
442 VkInstance
* pInstance
)
444 struct radv_instance
*instance
;
447 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
449 uint32_t client_version
;
450 if (pCreateInfo
->pApplicationInfo
&&
451 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
452 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
454 client_version
= VK_MAKE_VERSION(1, 0, 0);
457 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
458 client_version
> VK_MAKE_VERSION(1, 1, 0xfff)) {
459 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
460 "Client requested version %d.%d.%d",
461 VK_VERSION_MAJOR(client_version
),
462 VK_VERSION_MINOR(client_version
),
463 VK_VERSION_PATCH(client_version
));
466 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
467 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
469 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
471 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
474 instance
->alloc
= *pAllocator
;
476 instance
->alloc
= default_alloc
;
478 instance
->apiVersion
= client_version
;
479 instance
->physicalDeviceCount
= -1;
481 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
482 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
483 int index
= radv_get_instance_extension_index(ext_name
);
485 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
486 vk_free2(&default_alloc
, pAllocator
, instance
);
487 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
490 instance
->enabled_extensions
.extensions
[index
] = true;
493 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
494 if (result
!= VK_SUCCESS
) {
495 vk_free2(&default_alloc
, pAllocator
, instance
);
496 return vk_error(result
);
501 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
503 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
506 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
507 radv_perftest_options
);
509 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
511 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
512 /* Disable sisched when the user requests it, this is mostly
513 * useful when the driver force-enable sisched for the given
516 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
519 *pInstance
= radv_instance_to_handle(instance
);
524 void radv_DestroyInstance(
525 VkInstance _instance
,
526 const VkAllocationCallbacks
* pAllocator
)
528 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
533 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
534 radv_physical_device_finish(instance
->physicalDevices
+ i
);
537 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
541 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
543 vk_free(&instance
->alloc
, instance
);
547 radv_enumerate_devices(struct radv_instance
*instance
)
549 /* TODO: Check for more devices ? */
550 drmDevicePtr devices
[8];
551 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
554 instance
->physicalDeviceCount
= 0;
556 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
558 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
560 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
561 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
562 devices
[i
]->bustype
== DRM_BUS_PCI
&&
563 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
565 result
= radv_physical_device_init(instance
->physicalDevices
+
566 instance
->physicalDeviceCount
,
569 if (result
== VK_SUCCESS
)
570 ++instance
->physicalDeviceCount
;
571 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
575 drmFreeDevices(devices
, max_devices
);
580 VkResult
radv_EnumeratePhysicalDevices(
581 VkInstance _instance
,
582 uint32_t* pPhysicalDeviceCount
,
583 VkPhysicalDevice
* pPhysicalDevices
)
585 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
588 if (instance
->physicalDeviceCount
< 0) {
589 result
= radv_enumerate_devices(instance
);
590 if (result
!= VK_SUCCESS
&&
591 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
595 if (!pPhysicalDevices
) {
596 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
598 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
599 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
600 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
603 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
607 VkResult
radv_EnumeratePhysicalDeviceGroups(
608 VkInstance _instance
,
609 uint32_t* pPhysicalDeviceGroupCount
,
610 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
612 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
615 if (instance
->physicalDeviceCount
< 0) {
616 result
= radv_enumerate_devices(instance
);
617 if (result
!= VK_SUCCESS
&&
618 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
622 if (!pPhysicalDeviceGroupProperties
) {
623 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
625 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
626 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
627 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
628 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
629 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
632 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
636 void radv_GetPhysicalDeviceFeatures(
637 VkPhysicalDevice physicalDevice
,
638 VkPhysicalDeviceFeatures
* pFeatures
)
640 memset(pFeatures
, 0, sizeof(*pFeatures
));
642 *pFeatures
= (VkPhysicalDeviceFeatures
) {
643 .robustBufferAccess
= true,
644 .fullDrawIndexUint32
= true,
645 .imageCubeArray
= true,
646 .independentBlend
= true,
647 .geometryShader
= true,
648 .tessellationShader
= true,
649 .sampleRateShading
= true,
650 .dualSrcBlend
= true,
652 .multiDrawIndirect
= true,
653 .drawIndirectFirstInstance
= true,
655 .depthBiasClamp
= true,
656 .fillModeNonSolid
= true,
661 .multiViewport
= true,
662 .samplerAnisotropy
= true,
663 .textureCompressionETC2
= false,
664 .textureCompressionASTC_LDR
= false,
665 .textureCompressionBC
= true,
666 .occlusionQueryPrecise
= true,
667 .pipelineStatisticsQuery
= true,
668 .vertexPipelineStoresAndAtomics
= true,
669 .fragmentStoresAndAtomics
= true,
670 .shaderTessellationAndGeometryPointSize
= true,
671 .shaderImageGatherExtended
= true,
672 .shaderStorageImageExtendedFormats
= true,
673 .shaderStorageImageMultisample
= false,
674 .shaderUniformBufferArrayDynamicIndexing
= true,
675 .shaderSampledImageArrayDynamicIndexing
= true,
676 .shaderStorageBufferArrayDynamicIndexing
= true,
677 .shaderStorageImageArrayDynamicIndexing
= true,
678 .shaderStorageImageReadWithoutFormat
= true,
679 .shaderStorageImageWriteWithoutFormat
= true,
680 .shaderClipDistance
= true,
681 .shaderCullDistance
= true,
682 .shaderFloat64
= true,
684 .shaderInt16
= false,
685 .sparseBinding
= true,
686 .variableMultisampleRate
= true,
687 .inheritedQueries
= true,
691 void radv_GetPhysicalDeviceFeatures2(
692 VkPhysicalDevice physicalDevice
,
693 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
695 vk_foreach_struct(ext
, pFeatures
->pNext
) {
696 switch (ext
->sType
) {
697 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
698 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
699 features
->variablePointersStorageBuffer
= true;
700 features
->variablePointers
= false;
703 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
704 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
705 features
->multiview
= true;
706 features
->multiviewGeometryShader
= true;
707 features
->multiviewTessellationShader
= true;
710 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
711 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
712 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
713 features
->shaderDrawParameters
= true;
716 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
717 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
718 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
719 features
->protectedMemory
= false;
722 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
723 VkPhysicalDevice16BitStorageFeatures
*features
=
724 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
725 features
->storageBuffer16BitAccess
= false;
726 features
->uniformAndStorageBuffer16BitAccess
= false;
727 features
->storagePushConstant16
= false;
728 features
->storageInputOutput16
= false;
731 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
732 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
733 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
734 features
->samplerYcbcrConversion
= false;
741 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
744 void radv_GetPhysicalDeviceProperties(
745 VkPhysicalDevice physicalDevice
,
746 VkPhysicalDeviceProperties
* pProperties
)
748 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
749 VkSampleCountFlags sample_counts
= 0xf;
751 /* make sure that the entire descriptor set is addressable with a signed
752 * 32-bit int. So the sum of all limits scaled by descriptor size has to
753 * be at most 2 GiB. the combined image & samples object count as one of
754 * both. This limit is for the pipeline layout, not for the set layout, but
755 * there is no set limit, so we just set a pipeline limit. I don't think
756 * any app is going to hit this soon. */
757 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
758 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
759 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
760 32 /* sampler, largest when combined with image */ +
761 64 /* sampled image */ +
762 64 /* storage image */);
764 VkPhysicalDeviceLimits limits
= {
765 .maxImageDimension1D
= (1 << 14),
766 .maxImageDimension2D
= (1 << 14),
767 .maxImageDimension3D
= (1 << 11),
768 .maxImageDimensionCube
= (1 << 14),
769 .maxImageArrayLayers
= (1 << 11),
770 .maxTexelBufferElements
= 128 * 1024 * 1024,
771 .maxUniformBufferRange
= UINT32_MAX
,
772 .maxStorageBufferRange
= UINT32_MAX
,
773 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
774 .maxMemoryAllocationCount
= UINT32_MAX
,
775 .maxSamplerAllocationCount
= 64 * 1024,
776 .bufferImageGranularity
= 64, /* A cache line */
777 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
778 .maxBoundDescriptorSets
= MAX_SETS
,
779 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
780 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
781 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
782 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
783 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
784 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
785 .maxPerStageResources
= max_descriptor_set_size
,
786 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
787 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
788 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
789 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
790 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
791 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
792 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
793 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
794 .maxVertexInputAttributes
= 32,
795 .maxVertexInputBindings
= 32,
796 .maxVertexInputAttributeOffset
= 2047,
797 .maxVertexInputBindingStride
= 2048,
798 .maxVertexOutputComponents
= 128,
799 .maxTessellationGenerationLevel
= 64,
800 .maxTessellationPatchSize
= 32,
801 .maxTessellationControlPerVertexInputComponents
= 128,
802 .maxTessellationControlPerVertexOutputComponents
= 128,
803 .maxTessellationControlPerPatchOutputComponents
= 120,
804 .maxTessellationControlTotalOutputComponents
= 4096,
805 .maxTessellationEvaluationInputComponents
= 128,
806 .maxTessellationEvaluationOutputComponents
= 128,
807 .maxGeometryShaderInvocations
= 127,
808 .maxGeometryInputComponents
= 64,
809 .maxGeometryOutputComponents
= 128,
810 .maxGeometryOutputVertices
= 256,
811 .maxGeometryTotalOutputComponents
= 1024,
812 .maxFragmentInputComponents
= 128,
813 .maxFragmentOutputAttachments
= 8,
814 .maxFragmentDualSrcAttachments
= 1,
815 .maxFragmentCombinedOutputResources
= 8,
816 .maxComputeSharedMemorySize
= 32768,
817 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
818 .maxComputeWorkGroupInvocations
= 2048,
819 .maxComputeWorkGroupSize
= {
824 .subPixelPrecisionBits
= 4 /* FIXME */,
825 .subTexelPrecisionBits
= 4 /* FIXME */,
826 .mipmapPrecisionBits
= 4 /* FIXME */,
827 .maxDrawIndexedIndexValue
= UINT32_MAX
,
828 .maxDrawIndirectCount
= UINT32_MAX
,
829 .maxSamplerLodBias
= 16,
830 .maxSamplerAnisotropy
= 16,
831 .maxViewports
= MAX_VIEWPORTS
,
832 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
833 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
834 .viewportSubPixelBits
= 13, /* We take a float? */
835 .minMemoryMapAlignment
= 4096, /* A page */
836 .minTexelBufferOffsetAlignment
= 1,
837 .minUniformBufferOffsetAlignment
= 4,
838 .minStorageBufferOffsetAlignment
= 4,
839 .minTexelOffset
= -32,
840 .maxTexelOffset
= 31,
841 .minTexelGatherOffset
= -32,
842 .maxTexelGatherOffset
= 31,
843 .minInterpolationOffset
= -2,
844 .maxInterpolationOffset
= 2,
845 .subPixelInterpolationOffsetBits
= 8,
846 .maxFramebufferWidth
= (1 << 14),
847 .maxFramebufferHeight
= (1 << 14),
848 .maxFramebufferLayers
= (1 << 10),
849 .framebufferColorSampleCounts
= sample_counts
,
850 .framebufferDepthSampleCounts
= sample_counts
,
851 .framebufferStencilSampleCounts
= sample_counts
,
852 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
853 .maxColorAttachments
= MAX_RTS
,
854 .sampledImageColorSampleCounts
= sample_counts
,
855 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
856 .sampledImageDepthSampleCounts
= sample_counts
,
857 .sampledImageStencilSampleCounts
= sample_counts
,
858 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
859 .maxSampleMaskWords
= 1,
860 .timestampComputeAndGraphics
= true,
861 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
862 .maxClipDistances
= 8,
863 .maxCullDistances
= 8,
864 .maxCombinedClipAndCullDistances
= 8,
865 .discreteQueuePriorities
= 1,
866 .pointSizeRange
= { 0.125, 255.875 },
867 .lineWidthRange
= { 0.0, 7.9921875 },
868 .pointSizeGranularity
= (1.0 / 8.0),
869 .lineWidthGranularity
= (1.0 / 128.0),
870 .strictLines
= false, /* FINISHME */
871 .standardSampleLocations
= true,
872 .optimalBufferCopyOffsetAlignment
= 128,
873 .optimalBufferCopyRowPitchAlignment
= 128,
874 .nonCoherentAtomSize
= 64,
877 *pProperties
= (VkPhysicalDeviceProperties
) {
878 .apiVersion
= radv_physical_device_api_version(pdevice
),
879 .driverVersion
= vk_get_driver_version(),
880 .vendorID
= ATI_VENDOR_ID
,
881 .deviceID
= pdevice
->rad_info
.pci_id
,
882 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
884 .sparseProperties
= {0},
887 strcpy(pProperties
->deviceName
, pdevice
->name
);
888 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
891 void radv_GetPhysicalDeviceProperties2(
892 VkPhysicalDevice physicalDevice
,
893 VkPhysicalDeviceProperties2KHR
*pProperties
)
895 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
896 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
898 vk_foreach_struct(ext
, pProperties
->pNext
) {
899 switch (ext
->sType
) {
900 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
901 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
902 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
903 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
906 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
907 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
908 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
909 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
910 properties
->deviceLUIDValid
= false;
913 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
914 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
915 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
916 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
919 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
920 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
921 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
922 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
925 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
926 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
927 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
928 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
931 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
932 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
933 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
934 properties
->minImportedHostPointerAlignment
= 4096;
937 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
938 VkPhysicalDeviceSubgroupProperties
*properties
=
939 (VkPhysicalDeviceSubgroupProperties
*)ext
;
940 properties
->subgroupSize
= 64;
941 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
942 properties
->supportedOperations
= VK_SUBGROUP_FEATURE_BASIC_BIT
;
943 properties
->quadOperationsInAllStages
= false;
946 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
947 VkPhysicalDeviceMaintenance3Properties
*properties
=
948 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
949 /* Make sure everything is addressable by a signed 32-bit int, and
950 * our largest descriptors are 96 bytes. */
951 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
952 /* Our buffer size fields allow only this much */
953 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
956 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
957 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
958 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
959 /* GFX6-8 only support single channel min/max filter. */
960 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
961 properties
->filterMinmaxSingleComponentFormats
= true;
964 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
965 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
966 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
968 /* Shader engines. */
969 properties
->shaderEngineCount
=
970 pdevice
->rad_info
.max_se
;
971 properties
->shaderArraysPerEngineCount
=
972 pdevice
->rad_info
.max_sh_per_se
;
973 properties
->computeUnitsPerShaderArray
=
974 pdevice
->rad_info
.num_good_compute_units
/
975 (pdevice
->rad_info
.max_se
*
976 pdevice
->rad_info
.max_sh_per_se
);
977 properties
->simdPerComputeUnit
= 4;
978 properties
->wavefrontsPerSimd
=
979 pdevice
->rad_info
.family
== CHIP_TONGA
||
980 pdevice
->rad_info
.family
== CHIP_ICELAND
||
981 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
982 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
983 pdevice
->rad_info
.family
== CHIP_POLARIS12
? 8 : 10;
984 properties
->wavefrontSize
= 64;
987 properties
->sgprsPerSimd
=
988 radv_get_num_physical_sgprs(pdevice
);
989 properties
->minSgprAllocation
=
990 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
991 properties
->maxSgprAllocation
=
992 pdevice
->rad_info
.family
== CHIP_TONGA
||
993 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
994 properties
->sgprAllocationGranularity
=
995 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
998 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
999 properties
->minVgprAllocation
= 4;
1000 properties
->maxVgprAllocation
= 256;
1001 properties
->vgprAllocationGranularity
= 4;
1010 static void radv_get_physical_device_queue_family_properties(
1011 struct radv_physical_device
* pdevice
,
1013 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1015 int num_queue_families
= 1;
1017 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1018 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1019 num_queue_families
++;
1021 if (pQueueFamilyProperties
== NULL
) {
1022 *pCount
= num_queue_families
;
1031 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1032 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1033 VK_QUEUE_COMPUTE_BIT
|
1034 VK_QUEUE_TRANSFER_BIT
|
1035 VK_QUEUE_SPARSE_BINDING_BIT
,
1037 .timestampValidBits
= 64,
1038 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1043 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1044 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1045 if (*pCount
> idx
) {
1046 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1047 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1048 VK_QUEUE_TRANSFER_BIT
|
1049 VK_QUEUE_SPARSE_BINDING_BIT
,
1050 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1051 .timestampValidBits
= 64,
1052 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1060 void radv_GetPhysicalDeviceQueueFamilyProperties(
1061 VkPhysicalDevice physicalDevice
,
1063 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1065 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1066 if (!pQueueFamilyProperties
) {
1067 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1070 VkQueueFamilyProperties
*properties
[] = {
1071 pQueueFamilyProperties
+ 0,
1072 pQueueFamilyProperties
+ 1,
1073 pQueueFamilyProperties
+ 2,
1075 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1076 assert(*pCount
<= 3);
1079 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1080 VkPhysicalDevice physicalDevice
,
1082 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1084 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1085 if (!pQueueFamilyProperties
) {
1086 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1089 VkQueueFamilyProperties
*properties
[] = {
1090 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1091 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1092 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1094 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1095 assert(*pCount
<= 3);
1098 void radv_GetPhysicalDeviceMemoryProperties(
1099 VkPhysicalDevice physicalDevice
,
1100 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1102 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1104 *pMemoryProperties
= physical_device
->memory_properties
;
1107 void radv_GetPhysicalDeviceMemoryProperties2(
1108 VkPhysicalDevice physicalDevice
,
1109 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1111 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1112 &pMemoryProperties
->memoryProperties
);
1115 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1117 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1118 const void *pHostPointer
,
1119 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1121 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1125 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1126 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1127 uint32_t memoryTypeBits
= 0;
1128 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1129 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1130 memoryTypeBits
= (1 << i
);
1134 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1138 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1142 static enum radeon_ctx_priority
1143 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1145 /* Default to MEDIUM when a specific global priority isn't requested */
1147 return RADEON_CTX_PRIORITY_MEDIUM
;
1149 switch(pObj
->globalPriority
) {
1150 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1151 return RADEON_CTX_PRIORITY_REALTIME
;
1152 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1153 return RADEON_CTX_PRIORITY_HIGH
;
1154 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1155 return RADEON_CTX_PRIORITY_MEDIUM
;
1156 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1157 return RADEON_CTX_PRIORITY_LOW
;
1159 unreachable("Illegal global priority value");
1160 return RADEON_CTX_PRIORITY_INVALID
;
1165 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1166 uint32_t queue_family_index
, int idx
,
1167 VkDeviceQueueCreateFlags flags
,
1168 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1170 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1171 queue
->device
= device
;
1172 queue
->queue_family_index
= queue_family_index
;
1173 queue
->queue_idx
= idx
;
1174 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1175 queue
->flags
= flags
;
1177 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1179 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1185 radv_queue_finish(struct radv_queue
*queue
)
1188 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1190 if (queue
->initial_full_flush_preamble_cs
)
1191 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1192 if (queue
->initial_preamble_cs
)
1193 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1194 if (queue
->continue_preamble_cs
)
1195 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1196 if (queue
->descriptor_bo
)
1197 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1198 if (queue
->scratch_bo
)
1199 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1200 if (queue
->esgs_ring_bo
)
1201 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1202 if (queue
->gsvs_ring_bo
)
1203 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1204 if (queue
->tess_rings_bo
)
1205 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1206 if (queue
->compute_scratch_bo
)
1207 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1211 radv_device_init_gs_info(struct radv_device
*device
)
1213 switch (device
->physical_device
->rad_info
.family
) {
1222 device
->gs_table_depth
= 16;
1231 case CHIP_POLARIS10
:
1232 case CHIP_POLARIS11
:
1233 case CHIP_POLARIS12
:
1237 device
->gs_table_depth
= 32;
1240 unreachable("unknown GPU");
1244 static int radv_get_device_extension_index(const char *name
)
1246 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1247 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1253 VkResult
radv_CreateDevice(
1254 VkPhysicalDevice physicalDevice
,
1255 const VkDeviceCreateInfo
* pCreateInfo
,
1256 const VkAllocationCallbacks
* pAllocator
,
1259 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1261 struct radv_device
*device
;
1263 bool keep_shader_info
= false;
1265 /* Check enabled features */
1266 if (pCreateInfo
->pEnabledFeatures
) {
1267 VkPhysicalDeviceFeatures supported_features
;
1268 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1269 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1270 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1271 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1272 for (uint32_t i
= 0; i
< num_features
; i
++) {
1273 if (enabled_feature
[i
] && !supported_feature
[i
])
1274 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1278 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1280 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1282 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1284 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1285 device
->instance
= physical_device
->instance
;
1286 device
->physical_device
= physical_device
;
1288 device
->ws
= physical_device
->ws
;
1290 device
->alloc
= *pAllocator
;
1292 device
->alloc
= physical_device
->instance
->alloc
;
1294 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1295 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1296 int index
= radv_get_device_extension_index(ext_name
);
1297 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1298 vk_free(&device
->alloc
, device
);
1299 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1302 device
->enabled_extensions
.extensions
[index
] = true;
1305 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1307 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1308 list_inithead(&device
->shader_slabs
);
1310 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1311 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1312 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1313 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1314 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1316 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1318 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1319 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1320 if (!device
->queues
[qfi
]) {
1321 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1325 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1327 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1329 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1330 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1331 qfi
, q
, queue_create
->flags
,
1333 if (result
!= VK_SUCCESS
)
1338 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1339 (device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
);
1341 /* Disabled and not implemented for now. */
1342 device
->dfsm_allowed
= device
->pbb_allowed
&& false;
1345 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1348 device
->llvm_supports_spill
= true;
1350 /* The maximum number of scratch waves. Scratch space isn't divided
1351 * evenly between CUs. The number is only a function of the number of CUs.
1352 * We can decrease the constant to decrease the scratch buffer size.
1354 * sctx->scratch_waves must be >= the maximum posible size of
1355 * 1 threadgroup, so that the hw doesn't hang from being unable
1358 * The recommended value is 4 per CU at most. Higher numbers don't
1359 * bring much benefit, but they still occupy chip resources (think
1360 * async compute). I've seen ~2% performance difference between 4 and 32.
1362 uint32_t max_threads_per_block
= 2048;
1363 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1364 max_threads_per_block
/ 64);
1366 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1368 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1369 /* If the KMD allows it (there is a KMD hw register for it),
1370 * allow launching waves out-of-order.
1372 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1375 radv_device_init_gs_info(device
);
1377 device
->tess_offchip_block_dw_size
=
1378 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1379 device
->has_distributed_tess
=
1380 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1381 device
->physical_device
->rad_info
.max_se
>= 2;
1383 if (getenv("RADV_TRACE_FILE")) {
1384 const char *filename
= getenv("RADV_TRACE_FILE");
1386 keep_shader_info
= true;
1388 if (!radv_init_trace(device
))
1391 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1392 radv_dump_enabled_options(device
, stderr
);
1395 device
->keep_shader_info
= keep_shader_info
;
1397 result
= radv_device_init_meta(device
);
1398 if (result
!= VK_SUCCESS
)
1401 radv_device_init_msaa(device
);
1403 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1404 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1406 case RADV_QUEUE_GENERAL
:
1407 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1408 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1409 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1411 case RADV_QUEUE_COMPUTE
:
1412 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1413 radeon_emit(device
->empty_cs
[family
], 0);
1416 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1419 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1420 cik_create_gfx_config(device
);
1422 VkPipelineCacheCreateInfo ci
;
1423 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1426 ci
.pInitialData
= NULL
;
1427 ci
.initialDataSize
= 0;
1429 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1431 if (result
!= VK_SUCCESS
)
1434 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1436 *pDevice
= radv_device_to_handle(device
);
1440 radv_device_finish_meta(device
);
1442 if (device
->trace_bo
)
1443 device
->ws
->buffer_destroy(device
->trace_bo
);
1445 if (device
->gfx_init
)
1446 device
->ws
->buffer_destroy(device
->gfx_init
);
1448 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1449 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1450 radv_queue_finish(&device
->queues
[i
][q
]);
1451 if (device
->queue_count
[i
])
1452 vk_free(&device
->alloc
, device
->queues
[i
]);
1455 vk_free(&device
->alloc
, device
);
1459 void radv_DestroyDevice(
1461 const VkAllocationCallbacks
* pAllocator
)
1463 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1468 if (device
->trace_bo
)
1469 device
->ws
->buffer_destroy(device
->trace_bo
);
1471 if (device
->gfx_init
)
1472 device
->ws
->buffer_destroy(device
->gfx_init
);
1474 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1475 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1476 radv_queue_finish(&device
->queues
[i
][q
]);
1477 if (device
->queue_count
[i
])
1478 vk_free(&device
->alloc
, device
->queues
[i
]);
1479 if (device
->empty_cs
[i
])
1480 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1482 radv_device_finish_meta(device
);
1484 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1485 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1487 radv_destroy_shader_slabs(device
);
1489 vk_free(&device
->alloc
, device
);
1492 VkResult
radv_EnumerateInstanceLayerProperties(
1493 uint32_t* pPropertyCount
,
1494 VkLayerProperties
* pProperties
)
1496 if (pProperties
== NULL
) {
1497 *pPropertyCount
= 0;
1501 /* None supported at this time */
1502 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1505 VkResult
radv_EnumerateDeviceLayerProperties(
1506 VkPhysicalDevice physicalDevice
,
1507 uint32_t* pPropertyCount
,
1508 VkLayerProperties
* pProperties
)
1510 if (pProperties
== NULL
) {
1511 *pPropertyCount
= 0;
1515 /* None supported at this time */
1516 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1519 void radv_GetDeviceQueue2(
1521 const VkDeviceQueueInfo2
* pQueueInfo
,
1524 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1525 struct radv_queue
*queue
;
1527 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1528 if (pQueueInfo
->flags
!= queue
->flags
) {
1529 /* From the Vulkan 1.1.70 spec:
1531 * "The queue returned by vkGetDeviceQueue2 must have the same
1532 * flags value from this structure as that used at device
1533 * creation time in a VkDeviceQueueCreateInfo instance. If no
1534 * matching flags were specified at device creation time then
1535 * pQueue will return VK_NULL_HANDLE."
1537 *pQueue
= VK_NULL_HANDLE
;
1541 *pQueue
= radv_queue_to_handle(queue
);
1544 void radv_GetDeviceQueue(
1546 uint32_t queueFamilyIndex
,
1547 uint32_t queueIndex
,
1550 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1551 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1552 .queueFamilyIndex
= queueFamilyIndex
,
1553 .queueIndex
= queueIndex
1556 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1560 fill_geom_tess_rings(struct radv_queue
*queue
,
1562 bool add_sample_positions
,
1563 uint32_t esgs_ring_size
,
1564 struct radeon_winsys_bo
*esgs_ring_bo
,
1565 uint32_t gsvs_ring_size
,
1566 struct radeon_winsys_bo
*gsvs_ring_bo
,
1567 uint32_t tess_factor_ring_size
,
1568 uint32_t tess_offchip_ring_offset
,
1569 uint32_t tess_offchip_ring_size
,
1570 struct radeon_winsys_bo
*tess_rings_bo
)
1572 uint64_t esgs_va
= 0, gsvs_va
= 0;
1573 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1574 uint32_t *desc
= &map
[4];
1577 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1579 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1580 if (tess_rings_bo
) {
1581 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1582 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1585 /* stride 0, num records - size, add tid, swizzle, elsize4,
1588 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1589 S_008F04_STRIDE(0) |
1590 S_008F04_SWIZZLE_ENABLE(true);
1591 desc
[2] = esgs_ring_size
;
1592 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1593 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1594 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1595 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1596 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1597 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1598 S_008F0C_ELEMENT_SIZE(1) |
1599 S_008F0C_INDEX_STRIDE(3) |
1600 S_008F0C_ADD_TID_ENABLE(true);
1603 /* GS entry for ES->GS ring */
1604 /* stride 0, num records - size, elsize0,
1607 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1608 S_008F04_STRIDE(0) |
1609 S_008F04_SWIZZLE_ENABLE(false);
1610 desc
[2] = esgs_ring_size
;
1611 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1612 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1613 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1614 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1615 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1616 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1617 S_008F0C_ELEMENT_SIZE(0) |
1618 S_008F0C_INDEX_STRIDE(0) |
1619 S_008F0C_ADD_TID_ENABLE(false);
1622 /* VS entry for GS->VS ring */
1623 /* stride 0, num records - size, elsize0,
1626 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1627 S_008F04_STRIDE(0) |
1628 S_008F04_SWIZZLE_ENABLE(false);
1629 desc
[2] = gsvs_ring_size
;
1630 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1631 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1632 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1633 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1634 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1635 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1636 S_008F0C_ELEMENT_SIZE(0) |
1637 S_008F0C_INDEX_STRIDE(0) |
1638 S_008F0C_ADD_TID_ENABLE(false);
1641 /* stride gsvs_itemsize, num records 64
1642 elsize 4, index stride 16 */
1643 /* shader will patch stride and desc[2] */
1645 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1646 S_008F04_STRIDE(0) |
1647 S_008F04_SWIZZLE_ENABLE(true);
1649 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1650 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1651 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1652 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1653 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1654 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1655 S_008F0C_ELEMENT_SIZE(1) |
1656 S_008F0C_INDEX_STRIDE(1) |
1657 S_008F0C_ADD_TID_ENABLE(true);
1661 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1662 S_008F04_STRIDE(0) |
1663 S_008F04_SWIZZLE_ENABLE(false);
1664 desc
[2] = tess_factor_ring_size
;
1665 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1666 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1667 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1668 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1669 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1670 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1671 S_008F0C_ELEMENT_SIZE(0) |
1672 S_008F0C_INDEX_STRIDE(0) |
1673 S_008F0C_ADD_TID_ENABLE(false);
1676 desc
[0] = tess_offchip_va
;
1677 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1678 S_008F04_STRIDE(0) |
1679 S_008F04_SWIZZLE_ENABLE(false);
1680 desc
[2] = tess_offchip_ring_size
;
1681 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1682 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1683 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1684 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1685 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1686 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1687 S_008F0C_ELEMENT_SIZE(0) |
1688 S_008F0C_INDEX_STRIDE(0) |
1689 S_008F0C_ADD_TID_ENABLE(false);
1692 /* add sample positions after all rings */
1693 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1695 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1697 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1699 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1701 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1705 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1707 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1708 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1709 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1710 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1711 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1712 device
->physical_device
->rad_info
.max_se
;
1713 unsigned offchip_granularity
;
1714 unsigned hs_offchip_param
;
1715 switch (device
->tess_offchip_block_dw_size
) {
1720 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1723 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1727 switch (device
->physical_device
->rad_info
.chip_class
) {
1729 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1735 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1739 *max_offchip_buffers_p
= max_offchip_buffers
;
1740 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1741 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1742 --max_offchip_buffers
;
1744 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1745 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1748 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1750 return hs_offchip_param
;
1754 radv_get_preamble_cs(struct radv_queue
*queue
,
1755 uint32_t scratch_size
,
1756 uint32_t compute_scratch_size
,
1757 uint32_t esgs_ring_size
,
1758 uint32_t gsvs_ring_size
,
1759 bool needs_tess_rings
,
1760 bool needs_sample_positions
,
1761 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1762 struct radeon_winsys_cs
**initial_preamble_cs
,
1763 struct radeon_winsys_cs
**continue_preamble_cs
)
1765 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1766 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1767 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1768 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1769 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1770 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
1771 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1772 bool add_tess_rings
= false, add_sample_positions
= false;
1773 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1774 unsigned max_offchip_buffers
;
1775 unsigned hs_offchip_param
= 0;
1776 unsigned tess_offchip_ring_offset
;
1777 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1778 if (!queue
->has_tess_rings
) {
1779 if (needs_tess_rings
)
1780 add_tess_rings
= true;
1782 if (!queue
->has_sample_positions
) {
1783 if (needs_sample_positions
)
1784 add_sample_positions
= true;
1786 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1787 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1788 &max_offchip_buffers
);
1789 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
1790 tess_offchip_ring_size
= max_offchip_buffers
*
1791 queue
->device
->tess_offchip_block_dw_size
* 4;
1793 if (scratch_size
<= queue
->scratch_size
&&
1794 compute_scratch_size
<= queue
->compute_scratch_size
&&
1795 esgs_ring_size
<= queue
->esgs_ring_size
&&
1796 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1797 !add_tess_rings
&& !add_sample_positions
&&
1798 queue
->initial_preamble_cs
) {
1799 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1800 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1801 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1802 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1803 *continue_preamble_cs
= NULL
;
1807 if (scratch_size
> queue
->scratch_size
) {
1808 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1816 scratch_bo
= queue
->scratch_bo
;
1818 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1819 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1820 compute_scratch_size
,
1824 if (!compute_scratch_bo
)
1828 compute_scratch_bo
= queue
->compute_scratch_bo
;
1830 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1831 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1839 esgs_ring_bo
= queue
->esgs_ring_bo
;
1840 esgs_ring_size
= queue
->esgs_ring_size
;
1843 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1844 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1852 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1853 gsvs_ring_size
= queue
->gsvs_ring_size
;
1856 if (add_tess_rings
) {
1857 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1858 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
1865 tess_rings_bo
= queue
->tess_rings_bo
;
1868 if (scratch_bo
!= queue
->scratch_bo
||
1869 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1870 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1871 tess_rings_bo
!= queue
->tess_rings_bo
||
1872 add_sample_positions
) {
1874 if (gsvs_ring_bo
|| esgs_ring_bo
||
1875 tess_rings_bo
|| add_sample_positions
) {
1876 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1877 if (add_sample_positions
)
1878 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1880 else if (scratch_bo
)
1881 size
= 8; /* 2 dword */
1883 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1887 RADEON_FLAG_CPU_ACCESS
|
1888 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
1889 RADEON_FLAG_READ_ONLY
);
1893 descriptor_bo
= queue
->descriptor_bo
;
1895 for(int i
= 0; i
< 3; ++i
) {
1896 struct radeon_winsys_cs
*cs
= NULL
;
1897 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1898 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1905 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
1908 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1911 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1914 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
, 8);
1917 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1919 if (descriptor_bo
!= queue
->descriptor_bo
) {
1920 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1923 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1924 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1925 S_008F04_SWIZZLE_ENABLE(1);
1926 map
[0] = scratch_va
;
1930 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
1931 add_sample_positions
)
1932 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1933 esgs_ring_size
, esgs_ring_bo
,
1934 gsvs_ring_size
, gsvs_ring_bo
,
1935 tess_factor_ring_size
,
1936 tess_offchip_ring_offset
,
1937 tess_offchip_ring_size
,
1940 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1943 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
1944 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1945 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1946 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1947 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1950 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1951 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1952 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1953 radeon_emit(cs
, esgs_ring_size
>> 8);
1954 radeon_emit(cs
, gsvs_ring_size
>> 8);
1956 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1957 radeon_emit(cs
, esgs_ring_size
>> 8);
1958 radeon_emit(cs
, gsvs_ring_size
>> 8);
1962 if (tess_rings_bo
) {
1963 uint64_t tf_va
= radv_buffer_get_va(tess_rings_bo
);
1964 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1965 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1966 S_030938_SIZE(tess_factor_ring_size
/ 4));
1967 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1969 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1970 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1971 S_030944_BASE_HI(tf_va
>> 40));
1973 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1975 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1976 S_008988_SIZE(tess_factor_ring_size
/ 4));
1977 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1979 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1984 if (descriptor_bo
) {
1985 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1986 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1987 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1988 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1989 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1990 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1992 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1993 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1994 radeon_emit(cs
, va
);
1995 radeon_emit(cs
, va
>> 32);
1998 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1999 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2000 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2001 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2002 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2003 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2005 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2006 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
2007 radeon_emit(cs
, va
);
2008 radeon_emit(cs
, va
>> 32);
2013 if (compute_scratch_bo
) {
2014 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2015 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2016 S_008F04_SWIZZLE_ENABLE(1);
2018 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
2020 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2021 radeon_emit(cs
, scratch_va
);
2022 radeon_emit(cs
, rsrc1
);
2026 si_cs_emit_cache_flush(cs
,
2027 queue
->device
->physical_device
->rad_info
.chip_class
,
2029 queue
->queue_family_index
== RING_COMPUTE
&&
2030 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2031 (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
)) |
2032 RADV_CMD_FLAG_INV_ICACHE
|
2033 RADV_CMD_FLAG_INV_SMEM_L1
|
2034 RADV_CMD_FLAG_INV_VMEM_L1
|
2035 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2036 } else if (i
== 1) {
2037 si_cs_emit_cache_flush(cs
,
2038 queue
->device
->physical_device
->rad_info
.chip_class
,
2040 queue
->queue_family_index
== RING_COMPUTE
&&
2041 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2042 RADV_CMD_FLAG_INV_ICACHE
|
2043 RADV_CMD_FLAG_INV_SMEM_L1
|
2044 RADV_CMD_FLAG_INV_VMEM_L1
|
2045 RADV_CMD_FLAG_INV_GLOBAL_L2
);
2048 if (!queue
->device
->ws
->cs_finalize(cs
))
2052 if (queue
->initial_full_flush_preamble_cs
)
2053 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2055 if (queue
->initial_preamble_cs
)
2056 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2058 if (queue
->continue_preamble_cs
)
2059 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2061 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2062 queue
->initial_preamble_cs
= dest_cs
[1];
2063 queue
->continue_preamble_cs
= dest_cs
[2];
2065 if (scratch_bo
!= queue
->scratch_bo
) {
2066 if (queue
->scratch_bo
)
2067 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2068 queue
->scratch_bo
= scratch_bo
;
2069 queue
->scratch_size
= scratch_size
;
2072 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2073 if (queue
->compute_scratch_bo
)
2074 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2075 queue
->compute_scratch_bo
= compute_scratch_bo
;
2076 queue
->compute_scratch_size
= compute_scratch_size
;
2079 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2080 if (queue
->esgs_ring_bo
)
2081 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2082 queue
->esgs_ring_bo
= esgs_ring_bo
;
2083 queue
->esgs_ring_size
= esgs_ring_size
;
2086 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2087 if (queue
->gsvs_ring_bo
)
2088 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2089 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2090 queue
->gsvs_ring_size
= gsvs_ring_size
;
2093 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2094 queue
->tess_rings_bo
= tess_rings_bo
;
2095 queue
->has_tess_rings
= true;
2098 if (descriptor_bo
!= queue
->descriptor_bo
) {
2099 if (queue
->descriptor_bo
)
2100 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2102 queue
->descriptor_bo
= descriptor_bo
;
2105 if (add_sample_positions
)
2106 queue
->has_sample_positions
= true;
2108 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2109 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2110 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2111 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2112 *continue_preamble_cs
= NULL
;
2115 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2117 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2118 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2119 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2120 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2121 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2122 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2123 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2124 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2125 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2126 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2127 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2128 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2129 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2130 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2133 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
2135 const VkSemaphore
*sems
,
2139 int syncobj_idx
= 0, sem_idx
= 0;
2141 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2144 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2145 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2147 if (sem
->temp_syncobj
|| sem
->syncobj
)
2148 counts
->syncobj_count
++;
2150 counts
->sem_count
++;
2153 if (_fence
!= VK_NULL_HANDLE
) {
2154 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2155 if (fence
->temp_syncobj
|| fence
->syncobj
)
2156 counts
->syncobj_count
++;
2159 if (counts
->syncobj_count
) {
2160 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2161 if (!counts
->syncobj
)
2162 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2165 if (counts
->sem_count
) {
2166 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2168 free(counts
->syncobj
);
2169 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2173 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2174 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2176 if (sem
->temp_syncobj
) {
2177 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2179 else if (sem
->syncobj
)
2180 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2183 counts
->sem
[sem_idx
++] = sem
->sem
;
2187 if (_fence
!= VK_NULL_HANDLE
) {
2188 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2189 if (fence
->temp_syncobj
)
2190 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2191 else if (fence
->syncobj
)
2192 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2198 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2200 free(sem_info
->wait
.syncobj
);
2201 free(sem_info
->wait
.sem
);
2202 free(sem_info
->signal
.syncobj
);
2203 free(sem_info
->signal
.sem
);
2207 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2209 const VkSemaphore
*sems
)
2211 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2212 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2214 if (sem
->temp_syncobj
) {
2215 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2216 sem
->temp_syncobj
= 0;
2221 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2223 const VkSemaphore
*wait_sems
,
2224 int num_signal_sems
,
2225 const VkSemaphore
*signal_sems
,
2229 memset(sem_info
, 0, sizeof(*sem_info
));
2231 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2234 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2236 radv_free_sem_info(sem_info
);
2238 /* caller can override these */
2239 sem_info
->cs_emit_wait
= true;
2240 sem_info
->cs_emit_signal
= true;
2244 /* Signals fence as soon as all the work currently put on queue is done. */
2245 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2246 struct radv_fence
*fence
)
2250 struct radv_winsys_sem_info sem_info
;
2252 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2253 radv_fence_to_handle(fence
));
2254 if (result
!= VK_SUCCESS
)
2257 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2258 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2259 1, NULL
, NULL
, &sem_info
,
2260 false, fence
->fence
);
2261 radv_free_sem_info(&sem_info
);
2263 /* TODO: find a better error */
2265 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2270 VkResult
radv_QueueSubmit(
2272 uint32_t submitCount
,
2273 const VkSubmitInfo
* pSubmits
,
2276 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2277 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2278 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2279 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2281 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2282 uint32_t scratch_size
= 0;
2283 uint32_t compute_scratch_size
= 0;
2284 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2285 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2287 bool fence_emitted
= false;
2288 bool tess_rings_needed
= false;
2289 bool sample_positions_needed
= false;
2291 /* Do this first so failing to allocate scratch buffers can't result in
2292 * partially executed submissions. */
2293 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2294 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2295 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2296 pSubmits
[i
].pCommandBuffers
[j
]);
2298 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2299 compute_scratch_size
= MAX2(compute_scratch_size
,
2300 cmd_buffer
->compute_scratch_size_needed
);
2301 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2302 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2303 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2304 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2308 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2309 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2310 sample_positions_needed
, &initial_flush_preamble_cs
,
2311 &initial_preamble_cs
, &continue_preamble_cs
);
2312 if (result
!= VK_SUCCESS
)
2315 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2316 struct radeon_winsys_cs
**cs_array
;
2317 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2318 bool can_patch
= true;
2320 struct radv_winsys_sem_info sem_info
;
2322 result
= radv_alloc_sem_info(&sem_info
,
2323 pSubmits
[i
].waitSemaphoreCount
,
2324 pSubmits
[i
].pWaitSemaphores
,
2325 pSubmits
[i
].signalSemaphoreCount
,
2326 pSubmits
[i
].pSignalSemaphores
,
2328 if (result
!= VK_SUCCESS
)
2331 if (!pSubmits
[i
].commandBufferCount
) {
2332 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2333 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2334 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2339 radv_loge("failed to submit CS %d\n", i
);
2342 fence_emitted
= true;
2344 radv_free_sem_info(&sem_info
);
2348 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2349 (pSubmits
[i
].commandBufferCount
));
2351 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2352 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2353 pSubmits
[i
].pCommandBuffers
[j
]);
2354 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2356 cs_array
[j
] = cmd_buffer
->cs
;
2357 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2360 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2363 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2364 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2365 advance
= MIN2(max_cs_submission
,
2366 pSubmits
[i
].commandBufferCount
- j
);
2368 if (queue
->device
->trace_bo
)
2369 *queue
->device
->trace_id_ptr
= 0;
2371 sem_info
.cs_emit_wait
= j
== 0;
2372 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2374 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2375 advance
, initial_preamble
, continue_preamble_cs
,
2377 can_patch
, base_fence
);
2380 radv_loge("failed to submit CS %d\n", i
);
2383 fence_emitted
= true;
2384 if (queue
->device
->trace_bo
) {
2385 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2389 radv_free_temp_syncobjs(queue
->device
,
2390 pSubmits
[i
].waitSemaphoreCount
,
2391 pSubmits
[i
].pWaitSemaphores
);
2392 radv_free_sem_info(&sem_info
);
2397 if (!fence_emitted
) {
2398 radv_signal_fence(queue
, fence
);
2400 fence
->submitted
= true;
2406 VkResult
radv_QueueWaitIdle(
2409 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2411 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2412 radv_queue_family_to_ring(queue
->queue_family_index
),
2417 VkResult
radv_DeviceWaitIdle(
2420 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2422 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2423 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2424 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2430 VkResult
radv_EnumerateInstanceExtensionProperties(
2431 const char* pLayerName
,
2432 uint32_t* pPropertyCount
,
2433 VkExtensionProperties
* pProperties
)
2435 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2437 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2438 if (radv_supported_instance_extensions
.extensions
[i
]) {
2439 vk_outarray_append(&out
, prop
) {
2440 *prop
= radv_instance_extensions
[i
];
2445 return vk_outarray_status(&out
);
2448 VkResult
radv_EnumerateDeviceExtensionProperties(
2449 VkPhysicalDevice physicalDevice
,
2450 const char* pLayerName
,
2451 uint32_t* pPropertyCount
,
2452 VkExtensionProperties
* pProperties
)
2454 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2455 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2457 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2458 if (device
->supported_extensions
.extensions
[i
]) {
2459 vk_outarray_append(&out
, prop
) {
2460 *prop
= radv_device_extensions
[i
];
2465 return vk_outarray_status(&out
);
2468 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2469 VkInstance _instance
,
2472 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2474 return radv_lookup_entrypoint_checked(pName
,
2475 instance
? instance
->apiVersion
: 0,
2476 instance
? &instance
->enabled_extensions
: NULL
,
2480 /* The loader wants us to expose a second GetInstanceProcAddr function
2481 * to work around certain LD_PRELOAD issues seen in apps.
2484 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2485 VkInstance instance
,
2489 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2490 VkInstance instance
,
2493 return radv_GetInstanceProcAddr(instance
, pName
);
2496 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2500 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2502 return radv_lookup_entrypoint_checked(pName
,
2503 device
->instance
->apiVersion
,
2504 &device
->instance
->enabled_extensions
,
2505 &device
->enabled_extensions
);
2508 bool radv_get_memory_fd(struct radv_device
*device
,
2509 struct radv_device_memory
*memory
,
2512 struct radeon_bo_metadata metadata
;
2514 if (memory
->image
) {
2515 radv_init_metadata(device
, memory
->image
, &metadata
);
2516 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2519 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2523 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2524 const VkMemoryAllocateInfo
* pAllocateInfo
,
2525 const VkAllocationCallbacks
* pAllocator
,
2526 VkDeviceMemory
* pMem
)
2528 struct radv_device_memory
*mem
;
2530 enum radeon_bo_domain domain
;
2532 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2534 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2536 if (pAllocateInfo
->allocationSize
== 0) {
2537 /* Apparently, this is allowed */
2538 *pMem
= VK_NULL_HANDLE
;
2542 const VkImportMemoryFdInfoKHR
*import_info
=
2543 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2544 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2545 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2546 const VkExportMemoryAllocateInfoKHR
*export_info
=
2547 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2548 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2549 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2551 const struct wsi_memory_allocate_info
*wsi_info
=
2552 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2554 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2555 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2557 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2559 if (wsi_info
&& wsi_info
->implicit_sync
)
2560 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2562 if (dedicate_info
) {
2563 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2564 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2570 mem
->user_ptr
= NULL
;
2573 assert(import_info
->handleType
==
2574 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2575 import_info
->handleType
==
2576 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2577 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2580 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2583 close(import_info
->fd
);
2588 if (host_ptr_info
) {
2589 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2590 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2591 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2592 pAllocateInfo
->allocationSize
);
2594 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2597 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2602 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2603 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2604 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2605 domain
= RADEON_DOMAIN_GTT
;
2607 domain
= RADEON_DOMAIN_VRAM
;
2609 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2610 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2612 flags
|= RADEON_FLAG_CPU_ACCESS
;
2614 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2615 flags
|= RADEON_FLAG_GTT_WC
;
2617 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2618 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2620 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2624 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2627 mem
->type_index
= mem_type_index
;
2629 *pMem
= radv_device_memory_to_handle(mem
);
2634 vk_free2(&device
->alloc
, pAllocator
, mem
);
2639 VkResult
radv_AllocateMemory(
2641 const VkMemoryAllocateInfo
* pAllocateInfo
,
2642 const VkAllocationCallbacks
* pAllocator
,
2643 VkDeviceMemory
* pMem
)
2645 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2646 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2649 void radv_FreeMemory(
2651 VkDeviceMemory _mem
,
2652 const VkAllocationCallbacks
* pAllocator
)
2654 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2655 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2660 device
->ws
->buffer_destroy(mem
->bo
);
2663 vk_free2(&device
->alloc
, pAllocator
, mem
);
2666 VkResult
radv_MapMemory(
2668 VkDeviceMemory _memory
,
2669 VkDeviceSize offset
,
2671 VkMemoryMapFlags flags
,
2674 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2675 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2683 *ppData
= mem
->user_ptr
;
2685 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2692 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2695 void radv_UnmapMemory(
2697 VkDeviceMemory _memory
)
2699 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2700 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2705 if (mem
->user_ptr
== NULL
)
2706 device
->ws
->buffer_unmap(mem
->bo
);
2709 VkResult
radv_FlushMappedMemoryRanges(
2711 uint32_t memoryRangeCount
,
2712 const VkMappedMemoryRange
* pMemoryRanges
)
2717 VkResult
radv_InvalidateMappedMemoryRanges(
2719 uint32_t memoryRangeCount
,
2720 const VkMappedMemoryRange
* pMemoryRanges
)
2725 void radv_GetBufferMemoryRequirements(
2728 VkMemoryRequirements
* pMemoryRequirements
)
2730 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2731 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2733 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2735 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2736 pMemoryRequirements
->alignment
= 4096;
2738 pMemoryRequirements
->alignment
= 16;
2740 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2743 void radv_GetBufferMemoryRequirements2(
2745 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2746 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2748 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2749 &pMemoryRequirements
->memoryRequirements
);
2750 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2751 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2752 switch (ext
->sType
) {
2753 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2754 VkMemoryDedicatedRequirementsKHR
*req
=
2755 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2756 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2757 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2766 void radv_GetImageMemoryRequirements(
2769 VkMemoryRequirements
* pMemoryRequirements
)
2771 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2772 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2774 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2776 pMemoryRequirements
->size
= image
->size
;
2777 pMemoryRequirements
->alignment
= image
->alignment
;
2780 void radv_GetImageMemoryRequirements2(
2782 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2783 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2785 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2786 &pMemoryRequirements
->memoryRequirements
);
2788 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2790 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2791 switch (ext
->sType
) {
2792 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2793 VkMemoryDedicatedRequirementsKHR
*req
=
2794 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2795 req
->requiresDedicatedAllocation
= image
->shareable
;
2796 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2805 void radv_GetImageSparseMemoryRequirements(
2808 uint32_t* pSparseMemoryRequirementCount
,
2809 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2814 void radv_GetImageSparseMemoryRequirements2(
2816 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2817 uint32_t* pSparseMemoryRequirementCount
,
2818 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2823 void radv_GetDeviceMemoryCommitment(
2825 VkDeviceMemory memory
,
2826 VkDeviceSize
* pCommittedMemoryInBytes
)
2828 *pCommittedMemoryInBytes
= 0;
2831 VkResult
radv_BindBufferMemory2(VkDevice device
,
2832 uint32_t bindInfoCount
,
2833 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2835 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2836 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2837 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2840 buffer
->bo
= mem
->bo
;
2841 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2849 VkResult
radv_BindBufferMemory(
2852 VkDeviceMemory memory
,
2853 VkDeviceSize memoryOffset
)
2855 const VkBindBufferMemoryInfoKHR info
= {
2856 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2859 .memoryOffset
= memoryOffset
2862 return radv_BindBufferMemory2(device
, 1, &info
);
2865 VkResult
radv_BindImageMemory2(VkDevice device
,
2866 uint32_t bindInfoCount
,
2867 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2869 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2870 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2871 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2874 image
->bo
= mem
->bo
;
2875 image
->offset
= pBindInfos
[i
].memoryOffset
;
2885 VkResult
radv_BindImageMemory(
2888 VkDeviceMemory memory
,
2889 VkDeviceSize memoryOffset
)
2891 const VkBindImageMemoryInfoKHR info
= {
2892 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2895 .memoryOffset
= memoryOffset
2898 return radv_BindImageMemory2(device
, 1, &info
);
2903 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2904 const VkSparseBufferMemoryBindInfo
*bind
)
2906 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2908 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2909 struct radv_device_memory
*mem
= NULL
;
2911 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2912 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2914 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2915 bind
->pBinds
[i
].resourceOffset
,
2916 bind
->pBinds
[i
].size
,
2917 mem
? mem
->bo
: NULL
,
2918 bind
->pBinds
[i
].memoryOffset
);
2923 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2924 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2926 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2928 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2929 struct radv_device_memory
*mem
= NULL
;
2931 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2932 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2934 device
->ws
->buffer_virtual_bind(image
->bo
,
2935 bind
->pBinds
[i
].resourceOffset
,
2936 bind
->pBinds
[i
].size
,
2937 mem
? mem
->bo
: NULL
,
2938 bind
->pBinds
[i
].memoryOffset
);
2942 VkResult
radv_QueueBindSparse(
2944 uint32_t bindInfoCount
,
2945 const VkBindSparseInfo
* pBindInfo
,
2948 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2949 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2950 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2951 bool fence_emitted
= false;
2953 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2954 struct radv_winsys_sem_info sem_info
;
2955 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2956 radv_sparse_buffer_bind_memory(queue
->device
,
2957 pBindInfo
[i
].pBufferBinds
+ j
);
2960 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2961 radv_sparse_image_opaque_bind_memory(queue
->device
,
2962 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2966 result
= radv_alloc_sem_info(&sem_info
,
2967 pBindInfo
[i
].waitSemaphoreCount
,
2968 pBindInfo
[i
].pWaitSemaphores
,
2969 pBindInfo
[i
].signalSemaphoreCount
,
2970 pBindInfo
[i
].pSignalSemaphores
,
2972 if (result
!= VK_SUCCESS
)
2975 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2976 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2977 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2981 fence_emitted
= true;
2983 fence
->submitted
= true;
2986 radv_free_sem_info(&sem_info
);
2991 if (!fence_emitted
) {
2992 radv_signal_fence(queue
, fence
);
2994 fence
->submitted
= true;
3000 VkResult
radv_CreateFence(
3002 const VkFenceCreateInfo
* pCreateInfo
,
3003 const VkAllocationCallbacks
* pAllocator
,
3006 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3007 const VkExportFenceCreateInfoKHR
*export
=
3008 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3009 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3010 export
? export
->handleTypes
: 0;
3012 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3014 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3017 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3019 fence
->submitted
= false;
3020 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3021 fence
->temp_syncobj
= 0;
3022 if (device
->always_use_syncobj
|| handleTypes
) {
3023 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3025 vk_free2(&device
->alloc
, pAllocator
, fence
);
3026 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3028 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3029 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3031 fence
->fence
= NULL
;
3033 fence
->fence
= device
->ws
->create_fence();
3034 if (!fence
->fence
) {
3035 vk_free2(&device
->alloc
, pAllocator
, fence
);
3036 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3041 *pFence
= radv_fence_to_handle(fence
);
3046 void radv_DestroyFence(
3049 const VkAllocationCallbacks
* pAllocator
)
3051 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3052 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3057 if (fence
->temp_syncobj
)
3058 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3060 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3062 device
->ws
->destroy_fence(fence
->fence
);
3063 vk_free2(&device
->alloc
, pAllocator
, fence
);
3067 static uint64_t radv_get_current_time()
3070 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3071 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3074 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3076 uint64_t current_time
= radv_get_current_time();
3078 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3080 return current_time
+ timeout
;
3084 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3086 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3087 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3088 if (fence
->syncobj
|| fence
->temp_syncobj
|| (!fence
->signalled
&& !fence
->submitted
))
3094 VkResult
radv_WaitForFences(
3096 uint32_t fenceCount
,
3097 const VkFence
* pFences
,
3101 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3102 timeout
= radv_get_absolute_timeout(timeout
);
3104 if (device
->always_use_syncobj
) {
3105 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3107 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3109 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3110 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3111 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3114 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3117 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3120 if (!waitAll
&& fenceCount
> 1) {
3121 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3122 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3123 uint32_t wait_count
= 0;
3124 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3126 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3128 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3129 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3131 if (fence
->signalled
) {
3136 fences
[wait_count
++] = fence
->fence
;
3139 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3140 waitAll
, timeout
- radv_get_current_time());
3143 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3146 while(radv_get_current_time() <= timeout
) {
3147 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3148 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3155 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3156 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3157 bool expired
= false;
3159 if (fence
->temp_syncobj
) {
3160 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3165 if (fence
->syncobj
) {
3166 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3171 if (fence
->signalled
)
3174 if (!fence
->submitted
) {
3175 while(radv_get_current_time() <= timeout
&& !fence
->submitted
)
3178 if (!fence
->submitted
)
3181 /* Recheck as it may have been set by submitting operations. */
3182 if (fence
->signalled
)
3186 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
3190 fence
->signalled
= true;
3196 VkResult
radv_ResetFences(VkDevice _device
,
3197 uint32_t fenceCount
,
3198 const VkFence
*pFences
)
3200 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3202 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3203 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3204 fence
->submitted
= fence
->signalled
= false;
3206 /* Per spec, we first restore the permanent payload, and then reset, so
3207 * having a temp syncobj should not skip resetting the permanent syncobj. */
3208 if (fence
->temp_syncobj
) {
3209 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3210 fence
->temp_syncobj
= 0;
3213 if (fence
->syncobj
) {
3214 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3221 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3223 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3224 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3226 if (fence
->temp_syncobj
) {
3227 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3228 return success
? VK_SUCCESS
: VK_NOT_READY
;
3231 if (fence
->syncobj
) {
3232 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3233 return success
? VK_SUCCESS
: VK_NOT_READY
;
3236 if (fence
->signalled
)
3238 if (!fence
->submitted
)
3239 return VK_NOT_READY
;
3240 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3241 return VK_NOT_READY
;
3247 // Queue semaphore functions
3249 VkResult
radv_CreateSemaphore(
3251 const VkSemaphoreCreateInfo
* pCreateInfo
,
3252 const VkAllocationCallbacks
* pAllocator
,
3253 VkSemaphore
* pSemaphore
)
3255 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3256 const VkExportSemaphoreCreateInfoKHR
*export
=
3257 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3258 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3259 export
? export
->handleTypes
: 0;
3261 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3263 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3265 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3267 sem
->temp_syncobj
= 0;
3268 /* create a syncobject if we are going to export this semaphore */
3269 if (device
->always_use_syncobj
|| handleTypes
) {
3270 assert (device
->physical_device
->rad_info
.has_syncobj
);
3271 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3273 vk_free2(&device
->alloc
, pAllocator
, sem
);
3274 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3278 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3280 vk_free2(&device
->alloc
, pAllocator
, sem
);
3281 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3286 *pSemaphore
= radv_semaphore_to_handle(sem
);
3290 void radv_DestroySemaphore(
3292 VkSemaphore _semaphore
,
3293 const VkAllocationCallbacks
* pAllocator
)
3295 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3296 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3301 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3303 device
->ws
->destroy_sem(sem
->sem
);
3304 vk_free2(&device
->alloc
, pAllocator
, sem
);
3307 VkResult
radv_CreateEvent(
3309 const VkEventCreateInfo
* pCreateInfo
,
3310 const VkAllocationCallbacks
* pAllocator
,
3313 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3314 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3316 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3319 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3321 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3323 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3325 vk_free2(&device
->alloc
, pAllocator
, event
);
3326 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3329 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3331 *pEvent
= radv_event_to_handle(event
);
3336 void radv_DestroyEvent(
3339 const VkAllocationCallbacks
* pAllocator
)
3341 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3342 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3346 device
->ws
->buffer_destroy(event
->bo
);
3347 vk_free2(&device
->alloc
, pAllocator
, event
);
3350 VkResult
radv_GetEventStatus(
3354 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3356 if (*event
->map
== 1)
3357 return VK_EVENT_SET
;
3358 return VK_EVENT_RESET
;
3361 VkResult
radv_SetEvent(
3365 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3371 VkResult
radv_ResetEvent(
3375 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3381 VkResult
radv_CreateBuffer(
3383 const VkBufferCreateInfo
* pCreateInfo
,
3384 const VkAllocationCallbacks
* pAllocator
,
3387 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3388 struct radv_buffer
*buffer
;
3390 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3392 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3393 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3395 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3397 buffer
->size
= pCreateInfo
->size
;
3398 buffer
->usage
= pCreateInfo
->usage
;
3401 buffer
->flags
= pCreateInfo
->flags
;
3403 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3404 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3406 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3407 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3408 align64(buffer
->size
, 4096),
3409 4096, 0, RADEON_FLAG_VIRTUAL
);
3411 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3412 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3416 *pBuffer
= radv_buffer_to_handle(buffer
);
3421 void radv_DestroyBuffer(
3424 const VkAllocationCallbacks
* pAllocator
)
3426 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3427 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3432 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3433 device
->ws
->buffer_destroy(buffer
->bo
);
3435 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3438 static inline unsigned
3439 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3442 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3444 return image
->surface
.u
.legacy
.tiling_index
[level
];
3447 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3449 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3453 radv_initialise_color_surface(struct radv_device
*device
,
3454 struct radv_color_buffer_info
*cb
,
3455 struct radv_image_view
*iview
)
3457 const struct vk_format_description
*desc
;
3458 unsigned ntype
, format
, swap
, endian
;
3459 unsigned blend_clamp
= 0, blend_bypass
= 0;
3461 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3463 desc
= vk_format_description(iview
->vk_format
);
3465 memset(cb
, 0, sizeof(*cb
));
3467 /* Intensity is implemented as Red, so treat it that way. */
3468 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3470 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3472 cb
->cb_color_base
= va
>> 8;
3474 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3475 struct gfx9_surf_meta_flags meta
;
3476 if (iview
->image
->dcc_offset
)
3477 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3479 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3481 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3482 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3483 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3484 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3486 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3487 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3489 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3490 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3492 cb
->cb_color_base
+= level_info
->offset
>> 8;
3493 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3494 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3496 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3497 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3498 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3500 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3501 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3502 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3504 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3506 if (radv_image_has_fmask(iview
->image
)) {
3507 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3508 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3509 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3510 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3512 /* This must be set for fast clear to work without FMASK. */
3513 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3514 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3515 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3516 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3520 /* CMASK variables */
3521 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3522 va
+= iview
->image
->cmask
.offset
;
3523 cb
->cb_color_cmask
= va
>> 8;
3525 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3526 va
+= iview
->image
->dcc_offset
;
3527 cb
->cb_dcc_base
= va
>> 8;
3528 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3530 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3531 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3532 S_028C6C_SLICE_MAX(max_slice
);
3534 if (iview
->image
->info
.samples
> 1) {
3535 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3537 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3538 S_028C74_NUM_FRAGMENTS(log_samples
);
3541 if (radv_image_has_fmask(iview
->image
)) {
3542 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3543 cb
->cb_color_fmask
= va
>> 8;
3544 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3546 cb
->cb_color_fmask
= cb
->cb_color_base
;
3549 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3551 vk_format_get_first_non_void_channel(iview
->vk_format
));
3552 format
= radv_translate_colorformat(iview
->vk_format
);
3553 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3554 radv_finishme("Illegal color\n");
3555 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3556 endian
= radv_colorformat_endian_swap(format
);
3558 /* blend clamp should be set for all NORM/SRGB types */
3559 if (ntype
== V_028C70_NUMBER_UNORM
||
3560 ntype
== V_028C70_NUMBER_SNORM
||
3561 ntype
== V_028C70_NUMBER_SRGB
)
3564 /* set blend bypass according to docs if SINT/UINT or
3565 8/24 COLOR variants */
3566 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3567 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3568 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3573 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3574 (format
== V_028C70_COLOR_8
||
3575 format
== V_028C70_COLOR_8_8
||
3576 format
== V_028C70_COLOR_8_8_8_8
))
3577 ->color_is_int8
= true;
3579 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3580 S_028C70_COMP_SWAP(swap
) |
3581 S_028C70_BLEND_CLAMP(blend_clamp
) |
3582 S_028C70_BLEND_BYPASS(blend_bypass
) |
3583 S_028C70_SIMPLE_FLOAT(1) |
3584 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3585 ntype
!= V_028C70_NUMBER_SNORM
&&
3586 ntype
!= V_028C70_NUMBER_SRGB
&&
3587 format
!= V_028C70_COLOR_8_24
&&
3588 format
!= V_028C70_COLOR_24_8
) |
3589 S_028C70_NUMBER_TYPE(ntype
) |
3590 S_028C70_ENDIAN(endian
);
3591 if (radv_image_has_fmask(iview
->image
)) {
3592 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3593 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3594 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3595 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3599 if (radv_image_has_cmask(iview
->image
) &&
3600 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3601 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3603 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
3604 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3606 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3607 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3608 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3609 unsigned independent_64b_blocks
= 0;
3610 unsigned max_compressed_block_size
;
3612 /* amdvlk: [min-compressed-block-size] should be set to 32 for dGPU and
3613 64 for APU because all of our APUs to date use DIMMs which have
3614 a request granularity size of 64B while all other chips have a
3616 if (!device
->physical_device
->rad_info
.has_dedicated_vram
)
3617 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3619 if (iview
->image
->info
.samples
> 1) {
3620 if (iview
->image
->surface
.bpe
== 1)
3621 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3622 else if (iview
->image
->surface
.bpe
== 2)
3623 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3626 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3627 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3628 independent_64b_blocks
= 1;
3629 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3631 max_compressed_block_size
= max_uncompressed_block_size
;
3633 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3634 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3635 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3636 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3639 /* This must be set for fast clear to work without FMASK. */
3640 if (!radv_image_has_fmask(iview
->image
) &&
3641 device
->physical_device
->rad_info
.chip_class
== SI
) {
3642 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3643 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3646 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3647 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3648 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3650 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3651 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3652 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3653 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3654 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3655 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3660 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
3661 struct radv_image_view
*iview
)
3663 unsigned max_zplanes
= 0;
3665 assert(radv_image_is_tc_compat_htile(iview
->image
));
3667 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3668 /* Default value for 32-bit depth surfaces. */
3671 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3672 iview
->image
->info
.samples
> 1)
3675 max_zplanes
= max_zplanes
+ 1;
3677 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
3678 /* Do not enable Z plane compression for 16-bit depth
3679 * surfaces because isn't supported on GFX8. Only
3680 * 32-bit depth surfaces are supported by the hardware.
3681 * This allows to maintain shader compatibility and to
3682 * reduce the number of depth decompressions.
3686 if (iview
->image
->info
.samples
<= 1)
3688 else if (iview
->image
->info
.samples
<= 4)
3699 radv_initialise_ds_surface(struct radv_device
*device
,
3700 struct radv_ds_buffer_info
*ds
,
3701 struct radv_image_view
*iview
)
3703 unsigned level
= iview
->base_mip
;
3704 unsigned format
, stencil_format
;
3705 uint64_t va
, s_offs
, z_offs
;
3706 bool stencil_only
= false;
3707 memset(ds
, 0, sizeof(*ds
));
3708 switch (iview
->image
->vk_format
) {
3709 case VK_FORMAT_D24_UNORM_S8_UINT
:
3710 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3711 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3712 ds
->offset_scale
= 2.0f
;
3714 case VK_FORMAT_D16_UNORM
:
3715 case VK_FORMAT_D16_UNORM_S8_UINT
:
3716 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3717 ds
->offset_scale
= 4.0f
;
3719 case VK_FORMAT_D32_SFLOAT
:
3720 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3721 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3722 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3723 ds
->offset_scale
= 1.0f
;
3725 case VK_FORMAT_S8_UINT
:
3726 stencil_only
= true;
3732 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3733 stencil_format
= iview
->image
->surface
.has_stencil
?
3734 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3736 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3737 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3738 S_028008_SLICE_MAX(max_slice
);
3740 ds
->db_htile_data_base
= 0;
3741 ds
->db_htile_surface
= 0;
3743 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3744 s_offs
= z_offs
= va
;
3746 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3747 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3748 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3750 ds
->db_z_info
= S_028038_FORMAT(format
) |
3751 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3752 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3753 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3754 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3755 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3757 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3758 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3759 ds
->db_depth_view
|= S_028008_MIPID(level
);
3761 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3762 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3764 if (radv_htile_enabled(iview
->image
, level
)) {
3765 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3767 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3768 unsigned max_zplanes
=
3769 radv_calc_decompress_on_z_planes(device
, iview
);
3771 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
3772 S_028038_ITERATE_FLUSH(1);
3773 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3776 if (!iview
->image
->surface
.has_stencil
)
3777 /* Use all of the htile_buffer for depth if there's no stencil. */
3778 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3779 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3780 iview
->image
->htile_offset
;
3781 ds
->db_htile_data_base
= va
>> 8;
3782 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3783 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3784 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3787 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3790 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3792 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3793 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3795 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
3796 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3797 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3799 if (iview
->image
->info
.samples
> 1)
3800 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3802 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3803 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3804 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3805 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3806 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3807 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3808 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3809 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3812 tile_mode
= stencil_tile_mode
;
3814 ds
->db_depth_info
|=
3815 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3816 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3817 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3818 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3819 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3820 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3821 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3822 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3824 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3825 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3826 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3827 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3829 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3832 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3833 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3834 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3836 if (radv_htile_enabled(iview
->image
, level
)) {
3837 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3839 if (!iview
->image
->surface
.has_stencil
&&
3840 !radv_image_is_tc_compat_htile(iview
->image
))
3841 /* Use all of the htile_buffer for depth if there's no stencil. */
3842 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3844 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3845 iview
->image
->htile_offset
;
3846 ds
->db_htile_data_base
= va
>> 8;
3847 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3849 if (radv_image_is_tc_compat_htile(iview
->image
)) {
3850 unsigned max_zplanes
=
3851 radv_calc_decompress_on_z_planes(device
, iview
);
3853 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3854 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
3859 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3860 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3863 VkResult
radv_CreateFramebuffer(
3865 const VkFramebufferCreateInfo
* pCreateInfo
,
3866 const VkAllocationCallbacks
* pAllocator
,
3867 VkFramebuffer
* pFramebuffer
)
3869 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3870 struct radv_framebuffer
*framebuffer
;
3872 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3874 size_t size
= sizeof(*framebuffer
) +
3875 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3876 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3877 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3878 if (framebuffer
== NULL
)
3879 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3881 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3882 framebuffer
->width
= pCreateInfo
->width
;
3883 framebuffer
->height
= pCreateInfo
->height
;
3884 framebuffer
->layers
= pCreateInfo
->layers
;
3885 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3886 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3887 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3888 framebuffer
->attachments
[i
].attachment
= iview
;
3889 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3890 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3891 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3892 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3894 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3895 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3896 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
3899 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3903 void radv_DestroyFramebuffer(
3906 const VkAllocationCallbacks
* pAllocator
)
3908 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3909 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3913 vk_free2(&device
->alloc
, pAllocator
, fb
);
3916 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3918 switch (address_mode
) {
3919 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3920 return V_008F30_SQ_TEX_WRAP
;
3921 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3922 return V_008F30_SQ_TEX_MIRROR
;
3923 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3924 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3925 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3926 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3927 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3928 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3930 unreachable("illegal tex wrap mode");
3936 radv_tex_compare(VkCompareOp op
)
3939 case VK_COMPARE_OP_NEVER
:
3940 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3941 case VK_COMPARE_OP_LESS
:
3942 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3943 case VK_COMPARE_OP_EQUAL
:
3944 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3945 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3946 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3947 case VK_COMPARE_OP_GREATER
:
3948 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3949 case VK_COMPARE_OP_NOT_EQUAL
:
3950 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3951 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3952 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3953 case VK_COMPARE_OP_ALWAYS
:
3954 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3956 unreachable("illegal compare mode");
3962 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3965 case VK_FILTER_NEAREST
:
3966 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3967 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3968 case VK_FILTER_LINEAR
:
3969 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3970 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3971 case VK_FILTER_CUBIC_IMG
:
3973 fprintf(stderr
, "illegal texture filter");
3979 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3982 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3983 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3984 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3985 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3987 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3992 radv_tex_bordercolor(VkBorderColor bcolor
)
3995 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3996 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3997 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3998 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3999 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4000 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4001 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4002 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4003 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4011 radv_tex_aniso_filter(unsigned filter
)
4025 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4028 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4029 return SQ_IMG_FILTER_MODE_BLEND
;
4030 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4031 return SQ_IMG_FILTER_MODE_MIN
;
4032 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4033 return SQ_IMG_FILTER_MODE_MAX
;
4041 radv_init_sampler(struct radv_device
*device
,
4042 struct radv_sampler
*sampler
,
4043 const VkSamplerCreateInfo
*pCreateInfo
)
4045 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
4046 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
4047 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4048 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4049 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4051 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4052 vk_find_struct_const(pCreateInfo
->pNext
,
4053 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4054 if (sampler_reduction
)
4055 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4057 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4058 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4059 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4060 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4061 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4062 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4063 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4064 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4065 S_008F30_DISABLE_CUBE_WRAP(0) |
4066 S_008F30_COMPAT_MODE(is_vi
) |
4067 S_008F30_FILTER_MODE(filter_mode
));
4068 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4069 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4070 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4071 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4072 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4073 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4074 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4075 S_008F38_MIP_POINT_PRECLAMP(0) |
4076 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4077 S_008F38_FILTER_PREC_FIX(1) |
4078 S_008F38_ANISO_OVERRIDE(is_vi
));
4079 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4080 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4083 VkResult
radv_CreateSampler(
4085 const VkSamplerCreateInfo
* pCreateInfo
,
4086 const VkAllocationCallbacks
* pAllocator
,
4087 VkSampler
* pSampler
)
4089 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4090 struct radv_sampler
*sampler
;
4092 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4094 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4095 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4097 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
4099 radv_init_sampler(device
, sampler
, pCreateInfo
);
4100 *pSampler
= radv_sampler_to_handle(sampler
);
4105 void radv_DestroySampler(
4108 const VkAllocationCallbacks
* pAllocator
)
4110 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4111 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4115 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4118 /* vk_icd.h does not declare this function, so we declare it here to
4119 * suppress Wmissing-prototypes.
4121 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4122 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4124 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4125 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4127 /* For the full details on loader interface versioning, see
4128 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4129 * What follows is a condensed summary, to help you navigate the large and
4130 * confusing official doc.
4132 * - Loader interface v0 is incompatible with later versions. We don't
4135 * - In loader interface v1:
4136 * - The first ICD entrypoint called by the loader is
4137 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4139 * - The ICD must statically expose no other Vulkan symbol unless it is
4140 * linked with -Bsymbolic.
4141 * - Each dispatchable Vulkan handle created by the ICD must be
4142 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4143 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4144 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4145 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4146 * such loader-managed surfaces.
4148 * - Loader interface v2 differs from v1 in:
4149 * - The first ICD entrypoint called by the loader is
4150 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4151 * statically expose this entrypoint.
4153 * - Loader interface v3 differs from v2 in:
4154 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4155 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4156 * because the loader no longer does so.
4158 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4162 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4163 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4166 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4167 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4169 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4171 /* At the moment, we support only the below handle types. */
4172 assert(pGetFdInfo
->handleType
==
4173 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4174 pGetFdInfo
->handleType
==
4175 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4177 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4179 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4183 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4184 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4186 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4188 switch (handleType
) {
4189 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4190 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4194 /* The valid usage section for this function says:
4196 * "handleType must not be one of the handle types defined as
4199 * So opaque handle types fall into the default "unsupported" case.
4201 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4205 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4209 uint32_t syncobj_handle
= 0;
4210 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4212 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4215 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4217 *syncobj
= syncobj_handle
;
4223 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4227 /* If we create a syncobj we do it locally so that if we have an error, we don't
4228 * leave a syncobj in an undetermined state in the fence. */
4229 uint32_t syncobj_handle
= *syncobj
;
4230 if (!syncobj_handle
) {
4231 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4233 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4238 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4240 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4242 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4245 *syncobj
= syncobj_handle
;
4252 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4253 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4255 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4256 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4257 uint32_t *syncobj_dst
= NULL
;
4259 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4260 syncobj_dst
= &sem
->temp_syncobj
;
4262 syncobj_dst
= &sem
->syncobj
;
4265 switch(pImportSemaphoreFdInfo
->handleType
) {
4266 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4267 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4268 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4269 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4271 unreachable("Unhandled semaphore handle type");
4275 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4276 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4279 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4280 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4282 uint32_t syncobj_handle
;
4284 if (sem
->temp_syncobj
)
4285 syncobj_handle
= sem
->temp_syncobj
;
4287 syncobj_handle
= sem
->syncobj
;
4289 switch(pGetFdInfo
->handleType
) {
4290 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4291 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4293 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4294 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4296 if (sem
->temp_syncobj
) {
4297 close (sem
->temp_syncobj
);
4298 sem
->temp_syncobj
= 0;
4300 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4305 unreachable("Unhandled semaphore handle type");
4309 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4313 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4314 VkPhysicalDevice physicalDevice
,
4315 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4316 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4318 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4320 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4321 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4322 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4323 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4324 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4325 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4326 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4327 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4328 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4329 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4330 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4331 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4332 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4334 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4335 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4336 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4340 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4341 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4343 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4344 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4345 uint32_t *syncobj_dst
= NULL
;
4348 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4349 syncobj_dst
= &fence
->temp_syncobj
;
4351 syncobj_dst
= &fence
->syncobj
;
4354 switch(pImportFenceFdInfo
->handleType
) {
4355 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4356 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4357 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4358 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4360 unreachable("Unhandled fence handle type");
4364 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4365 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4368 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4369 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4371 uint32_t syncobj_handle
;
4373 if (fence
->temp_syncobj
)
4374 syncobj_handle
= fence
->temp_syncobj
;
4376 syncobj_handle
= fence
->syncobj
;
4378 switch(pGetFdInfo
->handleType
) {
4379 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4380 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4382 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4383 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4385 if (fence
->temp_syncobj
) {
4386 close (fence
->temp_syncobj
);
4387 fence
->temp_syncobj
= 0;
4389 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4394 unreachable("Unhandled fence handle type");
4398 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4402 void radv_GetPhysicalDeviceExternalFenceProperties(
4403 VkPhysicalDevice physicalDevice
,
4404 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4405 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4407 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4409 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4410 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4411 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4412 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4413 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4414 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4415 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4417 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4418 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4419 pExternalFenceProperties
->externalFenceFeatures
= 0;
4424 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4425 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4426 const VkAllocationCallbacks
* pAllocator
,
4427 VkDebugReportCallbackEXT
* pCallback
)
4429 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4430 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4431 pCreateInfo
, pAllocator
, &instance
->alloc
,
4436 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4437 VkDebugReportCallbackEXT _callback
,
4438 const VkAllocationCallbacks
* pAllocator
)
4440 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4441 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4442 _callback
, pAllocator
, &instance
->alloc
);
4446 radv_DebugReportMessageEXT(VkInstance _instance
,
4447 VkDebugReportFlagsEXT flags
,
4448 VkDebugReportObjectTypeEXT objectType
,
4451 int32_t messageCode
,
4452 const char* pLayerPrefix
,
4453 const char* pMessage
)
4455 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4456 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4457 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4461 radv_GetDeviceGroupPeerMemoryFeatures(
4464 uint32_t localDeviceIndex
,
4465 uint32_t remoteDeviceIndex
,
4466 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4468 assert(localDeviceIndex
== remoteDeviceIndex
);
4470 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4471 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4472 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4473 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;