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 "util/debug.h"
50 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
52 uint32_t mesa_timestamp
, llvm_timestamp
;
54 memset(uuid
, 0, VK_UUID_SIZE
);
55 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
56 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
59 memcpy(uuid
, &mesa_timestamp
, 4);
60 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
61 memcpy((char*)uuid
+ 8, &f
, 2);
62 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
67 radv_get_driver_uuid(void *uuid
)
69 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
73 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
75 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
79 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
81 const char *chip_string
;
82 char llvm_string
[32] = {};
85 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
86 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
87 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
88 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
89 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
90 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
91 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
92 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
93 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
94 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
95 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
96 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
97 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
98 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
99 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
100 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
101 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
102 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
103 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA"; break;
104 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
105 default: chip_string
= "AMD RADV unknown"; break;
109 snprintf(llvm_string
, sizeof(llvm_string
),
110 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
111 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
114 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
118 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
120 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
121 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
122 device
->rad_info
.vram_vis_size
);
124 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
125 device
->memory_properties
.memoryHeapCount
= 0;
126 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
127 vram_index
= device
->memory_properties
.memoryHeapCount
++;
128 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
129 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
130 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
133 if (visible_vram_size
) {
134 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
135 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
136 .size
= visible_vram_size
,
137 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
140 if (device
->rad_info
.gart_size
> 0) {
141 gart_index
= device
->memory_properties
.memoryHeapCount
++;
142 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
143 .size
= device
->rad_info
.gart_size
,
148 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
149 unsigned type_count
= 0;
150 if (vram_index
>= 0) {
151 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
152 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
153 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
154 .heapIndex
= vram_index
,
157 if (gart_index
>= 0) {
158 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
159 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
160 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
161 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
162 .heapIndex
= gart_index
,
165 if (visible_vram_index
>= 0) {
166 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
167 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
168 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
169 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
170 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
171 .heapIndex
= visible_vram_index
,
174 if (gart_index
>= 0) {
175 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
176 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
177 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
178 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
179 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
180 .heapIndex
= gart_index
,
183 device
->memory_properties
.memoryTypeCount
= type_count
;
187 radv_physical_device_init(struct radv_physical_device
*device
,
188 struct radv_instance
*instance
,
189 drmDevicePtr drm_device
)
191 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
193 drmVersionPtr version
;
196 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
198 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
200 version
= drmGetVersion(fd
);
203 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
204 "failed to get version %s: %m", path
);
207 if (strcmp(version
->name
, "amdgpu")) {
208 drmFreeVersion(version
);
210 return VK_ERROR_INCOMPATIBLE_DRIVER
;
212 drmFreeVersion(version
);
214 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
215 device
->instance
= instance
;
216 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
217 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
219 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
220 instance
->perftest_flags
);
222 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
226 device
->local_fd
= fd
;
227 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
229 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
231 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
232 device
->ws
->destroy(device
->ws
);
233 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
234 "cannot generate UUID");
238 /* These flags affect shader compilation. */
239 uint64_t shader_env_flags
=
240 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
241 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
243 /* The gpu id is already embeded in the uuid so we just pass "radv"
244 * when creating the cache.
246 char buf
[VK_UUID_SIZE
* 2 + 1];
247 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
248 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
250 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
252 radv_get_driver_uuid(&device
->device_uuid
);
253 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
255 if (device
->rad_info
.family
== CHIP_STONEY
||
256 device
->rad_info
.chip_class
>= GFX9
) {
257 device
->has_rbplus
= true;
258 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
261 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
264 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
266 radv_physical_device_init_mem_types(device
);
268 result
= radv_init_wsi(device
);
269 if (result
!= VK_SUCCESS
) {
270 device
->ws
->destroy(device
->ws
);
282 radv_physical_device_finish(struct radv_physical_device
*device
)
284 radv_finish_wsi(device
);
285 device
->ws
->destroy(device
->ws
);
286 disk_cache_destroy(device
->disk_cache
);
287 close(device
->local_fd
);
291 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
292 VkSystemAllocationScope allocationScope
)
298 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
299 size_t align
, VkSystemAllocationScope allocationScope
)
301 return realloc(pOriginal
, size
);
305 default_free_func(void *pUserData
, void *pMemory
)
310 static const VkAllocationCallbacks default_alloc
= {
312 .pfnAllocation
= default_alloc_func
,
313 .pfnReallocation
= default_realloc_func
,
314 .pfnFree
= default_free_func
,
317 static const struct debug_control radv_debug_options
[] = {
318 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
319 {"nodcc", RADV_DEBUG_NO_DCC
},
320 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
321 {"nocache", RADV_DEBUG_NO_CACHE
},
322 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
323 {"nohiz", RADV_DEBUG_NO_HIZ
},
324 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
325 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
326 {"allbos", RADV_DEBUG_ALL_BOS
},
327 {"noibs", RADV_DEBUG_NO_IBS
},
328 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
329 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
330 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
331 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
332 {"nosisched", RADV_DEBUG_NO_SISCHED
},
337 radv_get_debug_option_name(int id
)
339 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
340 return radv_debug_options
[id
].string
;
343 static const struct debug_control radv_perftest_options
[] = {
344 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
345 {"sisched", RADV_PERFTEST_SISCHED
},
346 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
351 radv_get_perftest_option_name(int id
)
353 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
354 return radv_perftest_options
[id
].string
;
358 radv_handle_per_app_options(struct radv_instance
*instance
,
359 const VkApplicationInfo
*info
)
361 const char *name
= info
? info
->pApplicationName
: NULL
;
366 if (!strcmp(name
, "Talos - Linux - 32bit") ||
367 !strcmp(name
, "Talos - Linux - 64bit")) {
368 /* Force enable LLVM sisched for Talos because it looks safe
369 * and it gives few more FPS.
371 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
375 VkResult
radv_CreateInstance(
376 const VkInstanceCreateInfo
* pCreateInfo
,
377 const VkAllocationCallbacks
* pAllocator
,
378 VkInstance
* pInstance
)
380 struct radv_instance
*instance
;
382 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
384 uint32_t client_version
;
385 if (pCreateInfo
->pApplicationInfo
&&
386 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
387 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
389 client_version
= VK_MAKE_VERSION(1, 0, 0);
392 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
393 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
394 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
395 "Client requested version %d.%d.%d",
396 VK_VERSION_MAJOR(client_version
),
397 VK_VERSION_MINOR(client_version
),
398 VK_VERSION_PATCH(client_version
));
401 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
402 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
403 if (!radv_instance_extension_supported(ext_name
))
404 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
407 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
408 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
410 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
412 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
415 instance
->alloc
= *pAllocator
;
417 instance
->alloc
= default_alloc
;
419 instance
->apiVersion
= client_version
;
420 instance
->physicalDeviceCount
= -1;
424 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
426 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
429 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
430 radv_perftest_options
);
432 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
434 if (instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
) {
435 /* Disable sisched when the user requests it, this is mostly
436 * useful when the driver force-enable sisched for the given
439 instance
->perftest_flags
&= ~RADV_PERFTEST_SISCHED
;
442 *pInstance
= radv_instance_to_handle(instance
);
447 void radv_DestroyInstance(
448 VkInstance _instance
,
449 const VkAllocationCallbacks
* pAllocator
)
451 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
456 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
457 radv_physical_device_finish(instance
->physicalDevices
+ i
);
460 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
464 vk_free(&instance
->alloc
, instance
);
468 radv_enumerate_devices(struct radv_instance
*instance
)
470 /* TODO: Check for more devices ? */
471 drmDevicePtr devices
[8];
472 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
475 instance
->physicalDeviceCount
= 0;
477 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
479 return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER
);
481 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
482 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
483 devices
[i
]->bustype
== DRM_BUS_PCI
&&
484 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
486 result
= radv_physical_device_init(instance
->physicalDevices
+
487 instance
->physicalDeviceCount
,
490 if (result
== VK_SUCCESS
)
491 ++instance
->physicalDeviceCount
;
492 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
496 drmFreeDevices(devices
, max_devices
);
501 VkResult
radv_EnumeratePhysicalDevices(
502 VkInstance _instance
,
503 uint32_t* pPhysicalDeviceCount
,
504 VkPhysicalDevice
* pPhysicalDevices
)
506 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
509 if (instance
->physicalDeviceCount
< 0) {
510 result
= radv_enumerate_devices(instance
);
511 if (result
!= VK_SUCCESS
&&
512 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
516 if (!pPhysicalDevices
) {
517 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
519 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
520 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
521 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
524 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
528 void radv_GetPhysicalDeviceFeatures(
529 VkPhysicalDevice physicalDevice
,
530 VkPhysicalDeviceFeatures
* pFeatures
)
532 memset(pFeatures
, 0, sizeof(*pFeatures
));
534 *pFeatures
= (VkPhysicalDeviceFeatures
) {
535 .robustBufferAccess
= true,
536 .fullDrawIndexUint32
= true,
537 .imageCubeArray
= true,
538 .independentBlend
= true,
539 .geometryShader
= true,
540 .tessellationShader
= true,
541 .sampleRateShading
= true,
542 .dualSrcBlend
= true,
544 .multiDrawIndirect
= true,
545 .drawIndirectFirstInstance
= true,
547 .depthBiasClamp
= true,
548 .fillModeNonSolid
= true,
553 .multiViewport
= true,
554 .samplerAnisotropy
= true,
555 .textureCompressionETC2
= false,
556 .textureCompressionASTC_LDR
= false,
557 .textureCompressionBC
= true,
558 .occlusionQueryPrecise
= true,
559 .pipelineStatisticsQuery
= true,
560 .vertexPipelineStoresAndAtomics
= true,
561 .fragmentStoresAndAtomics
= true,
562 .shaderTessellationAndGeometryPointSize
= true,
563 .shaderImageGatherExtended
= true,
564 .shaderStorageImageExtendedFormats
= true,
565 .shaderStorageImageMultisample
= false,
566 .shaderUniformBufferArrayDynamicIndexing
= true,
567 .shaderSampledImageArrayDynamicIndexing
= true,
568 .shaderStorageBufferArrayDynamicIndexing
= true,
569 .shaderStorageImageArrayDynamicIndexing
= true,
570 .shaderStorageImageReadWithoutFormat
= true,
571 .shaderStorageImageWriteWithoutFormat
= true,
572 .shaderClipDistance
= true,
573 .shaderCullDistance
= true,
574 .shaderFloat64
= true,
576 .shaderInt16
= false,
577 .sparseBinding
= true,
578 .variableMultisampleRate
= true,
579 .inheritedQueries
= true,
583 void radv_GetPhysicalDeviceFeatures2KHR(
584 VkPhysicalDevice physicalDevice
,
585 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
587 vk_foreach_struct(ext
, pFeatures
->pNext
) {
588 switch (ext
->sType
) {
589 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
590 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
591 features
->variablePointersStorageBuffer
= true;
592 features
->variablePointers
= false;
595 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
596 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
597 features
->multiview
= true;
598 features
->multiviewGeometryShader
= true;
599 features
->multiviewTessellationShader
= true;
606 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
609 void radv_GetPhysicalDeviceProperties(
610 VkPhysicalDevice physicalDevice
,
611 VkPhysicalDeviceProperties
* pProperties
)
613 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
614 VkSampleCountFlags sample_counts
= 0xf;
616 /* make sure that the entire descriptor set is addressable with a signed
617 * 32-bit int. So the sum of all limits scaled by descriptor size has to
618 * be at most 2 GiB. the combined image & samples object count as one of
619 * both. This limit is for the pipeline layout, not for the set layout, but
620 * there is no set limit, so we just set a pipeline limit. I don't think
621 * any app is going to hit this soon. */
622 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
623 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
624 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
625 32 /* sampler, largest when combined with image */ +
626 64 /* sampled image */ +
627 64 /* storage image */);
629 VkPhysicalDeviceLimits limits
= {
630 .maxImageDimension1D
= (1 << 14),
631 .maxImageDimension2D
= (1 << 14),
632 .maxImageDimension3D
= (1 << 11),
633 .maxImageDimensionCube
= (1 << 14),
634 .maxImageArrayLayers
= (1 << 11),
635 .maxTexelBufferElements
= 128 * 1024 * 1024,
636 .maxUniformBufferRange
= UINT32_MAX
,
637 .maxStorageBufferRange
= UINT32_MAX
,
638 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
639 .maxMemoryAllocationCount
= UINT32_MAX
,
640 .maxSamplerAllocationCount
= 64 * 1024,
641 .bufferImageGranularity
= 64, /* A cache line */
642 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
643 .maxBoundDescriptorSets
= MAX_SETS
,
644 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
645 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
646 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
647 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
648 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
649 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
650 .maxPerStageResources
= max_descriptor_set_size
,
651 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
652 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
653 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
654 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
655 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
656 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
657 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
658 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
659 .maxVertexInputAttributes
= 32,
660 .maxVertexInputBindings
= 32,
661 .maxVertexInputAttributeOffset
= 2047,
662 .maxVertexInputBindingStride
= 2048,
663 .maxVertexOutputComponents
= 128,
664 .maxTessellationGenerationLevel
= 64,
665 .maxTessellationPatchSize
= 32,
666 .maxTessellationControlPerVertexInputComponents
= 128,
667 .maxTessellationControlPerVertexOutputComponents
= 128,
668 .maxTessellationControlPerPatchOutputComponents
= 120,
669 .maxTessellationControlTotalOutputComponents
= 4096,
670 .maxTessellationEvaluationInputComponents
= 128,
671 .maxTessellationEvaluationOutputComponents
= 128,
672 .maxGeometryShaderInvocations
= 127,
673 .maxGeometryInputComponents
= 64,
674 .maxGeometryOutputComponents
= 128,
675 .maxGeometryOutputVertices
= 256,
676 .maxGeometryTotalOutputComponents
= 1024,
677 .maxFragmentInputComponents
= 128,
678 .maxFragmentOutputAttachments
= 8,
679 .maxFragmentDualSrcAttachments
= 1,
680 .maxFragmentCombinedOutputResources
= 8,
681 .maxComputeSharedMemorySize
= 32768,
682 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
683 .maxComputeWorkGroupInvocations
= 2048,
684 .maxComputeWorkGroupSize
= {
689 .subPixelPrecisionBits
= 4 /* FIXME */,
690 .subTexelPrecisionBits
= 4 /* FIXME */,
691 .mipmapPrecisionBits
= 4 /* FIXME */,
692 .maxDrawIndexedIndexValue
= UINT32_MAX
,
693 .maxDrawIndirectCount
= UINT32_MAX
,
694 .maxSamplerLodBias
= 16,
695 .maxSamplerAnisotropy
= 16,
696 .maxViewports
= MAX_VIEWPORTS
,
697 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
698 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
699 .viewportSubPixelBits
= 13, /* We take a float? */
700 .minMemoryMapAlignment
= 4096, /* A page */
701 .minTexelBufferOffsetAlignment
= 1,
702 .minUniformBufferOffsetAlignment
= 4,
703 .minStorageBufferOffsetAlignment
= 4,
704 .minTexelOffset
= -32,
705 .maxTexelOffset
= 31,
706 .minTexelGatherOffset
= -32,
707 .maxTexelGatherOffset
= 31,
708 .minInterpolationOffset
= -2,
709 .maxInterpolationOffset
= 2,
710 .subPixelInterpolationOffsetBits
= 8,
711 .maxFramebufferWidth
= (1 << 14),
712 .maxFramebufferHeight
= (1 << 14),
713 .maxFramebufferLayers
= (1 << 10),
714 .framebufferColorSampleCounts
= sample_counts
,
715 .framebufferDepthSampleCounts
= sample_counts
,
716 .framebufferStencilSampleCounts
= sample_counts
,
717 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
718 .maxColorAttachments
= MAX_RTS
,
719 .sampledImageColorSampleCounts
= sample_counts
,
720 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
721 .sampledImageDepthSampleCounts
= sample_counts
,
722 .sampledImageStencilSampleCounts
= sample_counts
,
723 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
724 .maxSampleMaskWords
= 1,
725 .timestampComputeAndGraphics
= true,
726 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
727 .maxClipDistances
= 8,
728 .maxCullDistances
= 8,
729 .maxCombinedClipAndCullDistances
= 8,
730 .discreteQueuePriorities
= 1,
731 .pointSizeRange
= { 0.125, 255.875 },
732 .lineWidthRange
= { 0.0, 7.9921875 },
733 .pointSizeGranularity
= (1.0 / 8.0),
734 .lineWidthGranularity
= (1.0 / 128.0),
735 .strictLines
= false, /* FINISHME */
736 .standardSampleLocations
= true,
737 .optimalBufferCopyOffsetAlignment
= 128,
738 .optimalBufferCopyRowPitchAlignment
= 128,
739 .nonCoherentAtomSize
= 64,
742 *pProperties
= (VkPhysicalDeviceProperties
) {
743 .apiVersion
= radv_physical_device_api_version(pdevice
),
744 .driverVersion
= vk_get_driver_version(),
745 .vendorID
= ATI_VENDOR_ID
,
746 .deviceID
= pdevice
->rad_info
.pci_id
,
747 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
749 .sparseProperties
= {0},
752 strcpy(pProperties
->deviceName
, pdevice
->name
);
753 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
756 void radv_GetPhysicalDeviceProperties2KHR(
757 VkPhysicalDevice physicalDevice
,
758 VkPhysicalDeviceProperties2KHR
*pProperties
)
760 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
761 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
763 vk_foreach_struct(ext
, pProperties
->pNext
) {
764 switch (ext
->sType
) {
765 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
766 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
767 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
768 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
771 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
772 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
773 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
774 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
775 properties
->deviceLUIDValid
= false;
778 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
779 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
780 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
781 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
784 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
785 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
786 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
787 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
796 static void radv_get_physical_device_queue_family_properties(
797 struct radv_physical_device
* pdevice
,
799 VkQueueFamilyProperties
** pQueueFamilyProperties
)
801 int num_queue_families
= 1;
803 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
804 pdevice
->rad_info
.chip_class
>= CIK
&&
805 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
806 num_queue_families
++;
808 if (pQueueFamilyProperties
== NULL
) {
809 *pCount
= num_queue_families
;
818 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
819 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
820 VK_QUEUE_COMPUTE_BIT
|
821 VK_QUEUE_TRANSFER_BIT
|
822 VK_QUEUE_SPARSE_BINDING_BIT
,
824 .timestampValidBits
= 64,
825 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
830 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
831 pdevice
->rad_info
.chip_class
>= CIK
&&
832 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
834 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
835 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
836 VK_QUEUE_TRANSFER_BIT
|
837 VK_QUEUE_SPARSE_BINDING_BIT
,
838 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
839 .timestampValidBits
= 64,
840 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
848 void radv_GetPhysicalDeviceQueueFamilyProperties(
849 VkPhysicalDevice physicalDevice
,
851 VkQueueFamilyProperties
* pQueueFamilyProperties
)
853 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
854 if (!pQueueFamilyProperties
) {
855 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
858 VkQueueFamilyProperties
*properties
[] = {
859 pQueueFamilyProperties
+ 0,
860 pQueueFamilyProperties
+ 1,
861 pQueueFamilyProperties
+ 2,
863 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
864 assert(*pCount
<= 3);
867 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
868 VkPhysicalDevice physicalDevice
,
870 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
872 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
873 if (!pQueueFamilyProperties
) {
874 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
877 VkQueueFamilyProperties
*properties
[] = {
878 &pQueueFamilyProperties
[0].queueFamilyProperties
,
879 &pQueueFamilyProperties
[1].queueFamilyProperties
,
880 &pQueueFamilyProperties
[2].queueFamilyProperties
,
882 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
883 assert(*pCount
<= 3);
886 void radv_GetPhysicalDeviceMemoryProperties(
887 VkPhysicalDevice physicalDevice
,
888 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
890 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
892 *pMemoryProperties
= physical_device
->memory_properties
;
895 void radv_GetPhysicalDeviceMemoryProperties2KHR(
896 VkPhysicalDevice physicalDevice
,
897 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
899 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
900 &pMemoryProperties
->memoryProperties
);
903 static enum radeon_ctx_priority
904 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
906 /* Default to MEDIUM when a specific global priority isn't requested */
908 return RADEON_CTX_PRIORITY_MEDIUM
;
910 switch(pObj
->globalPriority
) {
911 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
912 return RADEON_CTX_PRIORITY_REALTIME
;
913 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
914 return RADEON_CTX_PRIORITY_HIGH
;
915 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
916 return RADEON_CTX_PRIORITY_MEDIUM
;
917 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
918 return RADEON_CTX_PRIORITY_LOW
;
920 unreachable("Illegal global priority value");
921 return RADEON_CTX_PRIORITY_INVALID
;
926 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
927 uint32_t queue_family_index
, int idx
,
928 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
930 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
931 queue
->device
= device
;
932 queue
->queue_family_index
= queue_family_index
;
933 queue
->queue_idx
= idx
;
934 queue
->priority
= radv_get_queue_global_priority(global_priority
);
936 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
938 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
944 radv_queue_finish(struct radv_queue
*queue
)
947 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
949 if (queue
->initial_full_flush_preamble_cs
)
950 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
951 if (queue
->initial_preamble_cs
)
952 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
953 if (queue
->continue_preamble_cs
)
954 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
955 if (queue
->descriptor_bo
)
956 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
957 if (queue
->scratch_bo
)
958 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
959 if (queue
->esgs_ring_bo
)
960 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
961 if (queue
->gsvs_ring_bo
)
962 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
963 if (queue
->tess_factor_ring_bo
)
964 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
965 if (queue
->tess_offchip_ring_bo
)
966 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
967 if (queue
->compute_scratch_bo
)
968 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
972 radv_device_init_gs_info(struct radv_device
*device
)
974 switch (device
->physical_device
->rad_info
.family
) {
983 device
->gs_table_depth
= 16;
997 device
->gs_table_depth
= 32;
1000 unreachable("unknown GPU");
1004 VkResult
radv_CreateDevice(
1005 VkPhysicalDevice physicalDevice
,
1006 const VkDeviceCreateInfo
* pCreateInfo
,
1007 const VkAllocationCallbacks
* pAllocator
,
1010 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1012 struct radv_device
*device
;
1014 bool keep_shader_info
= false;
1016 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1017 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1018 if (!radv_physical_device_extension_supported(physical_device
, ext_name
))
1019 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1021 if (strcmp(ext_name
, VK_AMD_SHADER_INFO_EXTENSION_NAME
) == 0)
1022 keep_shader_info
= true;
1025 /* Check enabled features */
1026 if (pCreateInfo
->pEnabledFeatures
) {
1027 VkPhysicalDeviceFeatures supported_features
;
1028 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1029 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1030 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1031 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1032 for (uint32_t i
= 0; i
< num_features
; i
++) {
1033 if (enabled_feature
[i
] && !supported_feature
[i
])
1034 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1038 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1040 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1042 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1044 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1045 device
->instance
= physical_device
->instance
;
1046 device
->physical_device
= physical_device
;
1048 device
->ws
= physical_device
->ws
;
1050 device
->alloc
= *pAllocator
;
1052 device
->alloc
= physical_device
->instance
->alloc
;
1054 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1055 list_inithead(&device
->shader_slabs
);
1057 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1058 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1059 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1060 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1061 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1063 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1065 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1066 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1067 if (!device
->queues
[qfi
]) {
1068 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1072 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1074 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1076 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1077 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
, global_priority
);
1078 if (result
!= VK_SUCCESS
)
1083 #if HAVE_LLVM < 0x0400
1084 device
->llvm_supports_spill
= false;
1086 device
->llvm_supports_spill
= true;
1089 /* The maximum number of scratch waves. Scratch space isn't divided
1090 * evenly between CUs. The number is only a function of the number of CUs.
1091 * We can decrease the constant to decrease the scratch buffer size.
1093 * sctx->scratch_waves must be >= the maximum posible size of
1094 * 1 threadgroup, so that the hw doesn't hang from being unable
1097 * The recommended value is 4 per CU at most. Higher numbers don't
1098 * bring much benefit, but they still occupy chip resources (think
1099 * async compute). I've seen ~2% performance difference between 4 and 32.
1101 uint32_t max_threads_per_block
= 2048;
1102 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1103 max_threads_per_block
/ 64);
1105 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1) |
1106 S_00B800_FORCE_START_AT_000(1);
1108 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1109 /* If the KMD allows it (there is a KMD hw register for it),
1110 * allow launching waves out-of-order.
1112 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1115 radv_device_init_gs_info(device
);
1117 device
->tess_offchip_block_dw_size
=
1118 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1119 device
->has_distributed_tess
=
1120 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1121 device
->physical_device
->rad_info
.max_se
>= 2;
1123 if (getenv("RADV_TRACE_FILE")) {
1124 keep_shader_info
= true;
1126 if (!radv_init_trace(device
))
1130 device
->keep_shader_info
= keep_shader_info
;
1132 result
= radv_device_init_meta(device
);
1133 if (result
!= VK_SUCCESS
)
1136 radv_device_init_msaa(device
);
1138 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1139 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1141 case RADV_QUEUE_GENERAL
:
1142 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1143 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1144 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1146 case RADV_QUEUE_COMPUTE
:
1147 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1148 radeon_emit(device
->empty_cs
[family
], 0);
1151 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1154 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1155 cik_create_gfx_config(device
);
1157 VkPipelineCacheCreateInfo ci
;
1158 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1161 ci
.pInitialData
= NULL
;
1162 ci
.initialDataSize
= 0;
1164 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1166 if (result
!= VK_SUCCESS
)
1169 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1171 *pDevice
= radv_device_to_handle(device
);
1175 if (device
->trace_bo
)
1176 device
->ws
->buffer_destroy(device
->trace_bo
);
1178 if (device
->gfx_init
)
1179 device
->ws
->buffer_destroy(device
->gfx_init
);
1181 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1182 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1183 radv_queue_finish(&device
->queues
[i
][q
]);
1184 if (device
->queue_count
[i
])
1185 vk_free(&device
->alloc
, device
->queues
[i
]);
1188 vk_free(&device
->alloc
, device
);
1192 void radv_DestroyDevice(
1194 const VkAllocationCallbacks
* pAllocator
)
1196 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1201 if (device
->trace_bo
)
1202 device
->ws
->buffer_destroy(device
->trace_bo
);
1204 if (device
->gfx_init
)
1205 device
->ws
->buffer_destroy(device
->gfx_init
);
1207 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1208 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1209 radv_queue_finish(&device
->queues
[i
][q
]);
1210 if (device
->queue_count
[i
])
1211 vk_free(&device
->alloc
, device
->queues
[i
]);
1212 if (device
->empty_cs
[i
])
1213 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1215 radv_device_finish_meta(device
);
1217 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1218 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1220 radv_destroy_shader_slabs(device
);
1222 vk_free(&device
->alloc
, device
);
1225 VkResult
radv_EnumerateInstanceLayerProperties(
1226 uint32_t* pPropertyCount
,
1227 VkLayerProperties
* pProperties
)
1229 if (pProperties
== NULL
) {
1230 *pPropertyCount
= 0;
1234 /* None supported at this time */
1235 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1238 VkResult
radv_EnumerateDeviceLayerProperties(
1239 VkPhysicalDevice physicalDevice
,
1240 uint32_t* pPropertyCount
,
1241 VkLayerProperties
* pProperties
)
1243 if (pProperties
== NULL
) {
1244 *pPropertyCount
= 0;
1248 /* None supported at this time */
1249 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1252 void radv_GetDeviceQueue(
1254 uint32_t queueFamilyIndex
,
1255 uint32_t queueIndex
,
1258 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1260 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1264 fill_geom_tess_rings(struct radv_queue
*queue
,
1266 bool add_sample_positions
,
1267 uint32_t esgs_ring_size
,
1268 struct radeon_winsys_bo
*esgs_ring_bo
,
1269 uint32_t gsvs_ring_size
,
1270 struct radeon_winsys_bo
*gsvs_ring_bo
,
1271 uint32_t tess_factor_ring_size
,
1272 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1273 uint32_t tess_offchip_ring_size
,
1274 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1276 uint64_t esgs_va
= 0, gsvs_va
= 0;
1277 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1278 uint32_t *desc
= &map
[4];
1281 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1283 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1284 if (tess_factor_ring_bo
)
1285 tess_factor_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1286 if (tess_offchip_ring_bo
)
1287 tess_offchip_va
= radv_buffer_get_va(tess_offchip_ring_bo
);
1289 /* stride 0, num records - size, add tid, swizzle, elsize4,
1292 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1293 S_008F04_STRIDE(0) |
1294 S_008F04_SWIZZLE_ENABLE(true);
1295 desc
[2] = esgs_ring_size
;
1296 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1297 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1298 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1299 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1300 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1301 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1302 S_008F0C_ELEMENT_SIZE(1) |
1303 S_008F0C_INDEX_STRIDE(3) |
1304 S_008F0C_ADD_TID_ENABLE(true);
1307 /* GS entry for ES->GS ring */
1308 /* stride 0, num records - size, elsize0,
1311 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1312 S_008F04_STRIDE(0) |
1313 S_008F04_SWIZZLE_ENABLE(false);
1314 desc
[2] = esgs_ring_size
;
1315 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1316 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1317 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1318 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1319 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1320 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1321 S_008F0C_ELEMENT_SIZE(0) |
1322 S_008F0C_INDEX_STRIDE(0) |
1323 S_008F0C_ADD_TID_ENABLE(false);
1326 /* VS entry for GS->VS ring */
1327 /* stride 0, num records - size, elsize0,
1330 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1331 S_008F04_STRIDE(0) |
1332 S_008F04_SWIZZLE_ENABLE(false);
1333 desc
[2] = gsvs_ring_size
;
1334 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1335 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1336 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1337 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1338 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1339 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1340 S_008F0C_ELEMENT_SIZE(0) |
1341 S_008F0C_INDEX_STRIDE(0) |
1342 S_008F0C_ADD_TID_ENABLE(false);
1345 /* stride gsvs_itemsize, num records 64
1346 elsize 4, index stride 16 */
1347 /* shader will patch stride and desc[2] */
1349 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1350 S_008F04_STRIDE(0) |
1351 S_008F04_SWIZZLE_ENABLE(true);
1353 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1354 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1355 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1356 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1357 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1358 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1359 S_008F0C_ELEMENT_SIZE(1) |
1360 S_008F0C_INDEX_STRIDE(1) |
1361 S_008F0C_ADD_TID_ENABLE(true);
1364 desc
[0] = tess_factor_va
;
1365 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1366 S_008F04_STRIDE(0) |
1367 S_008F04_SWIZZLE_ENABLE(false);
1368 desc
[2] = tess_factor_ring_size
;
1369 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1370 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1371 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1372 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1373 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1374 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1375 S_008F0C_ELEMENT_SIZE(0) |
1376 S_008F0C_INDEX_STRIDE(0) |
1377 S_008F0C_ADD_TID_ENABLE(false);
1380 desc
[0] = tess_offchip_va
;
1381 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1382 S_008F04_STRIDE(0) |
1383 S_008F04_SWIZZLE_ENABLE(false);
1384 desc
[2] = tess_offchip_ring_size
;
1385 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1386 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1387 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1388 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1389 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1390 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1391 S_008F0C_ELEMENT_SIZE(0) |
1392 S_008F0C_INDEX_STRIDE(0) |
1393 S_008F0C_ADD_TID_ENABLE(false);
1396 /* add sample positions after all rings */
1397 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1399 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1401 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1403 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1405 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1409 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1411 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1412 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1413 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1414 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1415 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1416 device
->physical_device
->rad_info
.max_se
;
1417 unsigned offchip_granularity
;
1418 unsigned hs_offchip_param
;
1419 switch (device
->tess_offchip_block_dw_size
) {
1424 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1427 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1431 switch (device
->physical_device
->rad_info
.chip_class
) {
1433 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1439 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1443 *max_offchip_buffers_p
= max_offchip_buffers
;
1444 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1445 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1446 --max_offchip_buffers
;
1448 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1449 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1452 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1454 return hs_offchip_param
;
1458 radv_get_preamble_cs(struct radv_queue
*queue
,
1459 uint32_t scratch_size
,
1460 uint32_t compute_scratch_size
,
1461 uint32_t esgs_ring_size
,
1462 uint32_t gsvs_ring_size
,
1463 bool needs_tess_rings
,
1464 bool needs_sample_positions
,
1465 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1466 struct radeon_winsys_cs
**initial_preamble_cs
,
1467 struct radeon_winsys_cs
**continue_preamble_cs
)
1469 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1470 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1471 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1472 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1473 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1474 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1475 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1476 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1477 bool add_tess_rings
= false, add_sample_positions
= false;
1478 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1479 unsigned max_offchip_buffers
;
1480 unsigned hs_offchip_param
= 0;
1481 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
1482 if (!queue
->has_tess_rings
) {
1483 if (needs_tess_rings
)
1484 add_tess_rings
= true;
1486 if (!queue
->has_sample_positions
) {
1487 if (needs_sample_positions
)
1488 add_sample_positions
= true;
1490 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1491 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1492 &max_offchip_buffers
);
1493 tess_offchip_ring_size
= max_offchip_buffers
*
1494 queue
->device
->tess_offchip_block_dw_size
* 4;
1496 if (scratch_size
<= queue
->scratch_size
&&
1497 compute_scratch_size
<= queue
->compute_scratch_size
&&
1498 esgs_ring_size
<= queue
->esgs_ring_size
&&
1499 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1500 !add_tess_rings
&& !add_sample_positions
&&
1501 queue
->initial_preamble_cs
) {
1502 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1503 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1504 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1505 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1506 *continue_preamble_cs
= NULL
;
1510 if (scratch_size
> queue
->scratch_size
) {
1511 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1519 scratch_bo
= queue
->scratch_bo
;
1521 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1522 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1523 compute_scratch_size
,
1527 if (!compute_scratch_bo
)
1531 compute_scratch_bo
= queue
->compute_scratch_bo
;
1533 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1534 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1542 esgs_ring_bo
= queue
->esgs_ring_bo
;
1543 esgs_ring_size
= queue
->esgs_ring_size
;
1546 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1547 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1555 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1556 gsvs_ring_size
= queue
->gsvs_ring_size
;
1559 if (add_tess_rings
) {
1560 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1561 tess_factor_ring_size
,
1565 if (!tess_factor_ring_bo
)
1567 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1568 tess_offchip_ring_size
,
1572 if (!tess_offchip_ring_bo
)
1575 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1576 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1579 if (scratch_bo
!= queue
->scratch_bo
||
1580 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1581 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1582 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1583 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1585 if (gsvs_ring_bo
|| esgs_ring_bo
||
1586 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1587 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1588 if (add_sample_positions
)
1589 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1591 else if (scratch_bo
)
1592 size
= 8; /* 2 dword */
1594 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1598 RADEON_FLAG_CPU_ACCESS
|RADEON_FLAG_NO_INTERPROCESS_SHARING
);
1602 descriptor_bo
= queue
->descriptor_bo
;
1604 for(int i
= 0; i
< 3; ++i
) {
1605 struct radeon_winsys_cs
*cs
= NULL
;
1606 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1607 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1614 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
, 8);
1617 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
, 8);
1620 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
, 8);
1622 if (tess_factor_ring_bo
)
1623 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_factor_ring_bo
, 8);
1625 if (tess_offchip_ring_bo
)
1626 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_offchip_ring_bo
, 8);
1629 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
, 8);
1631 if (descriptor_bo
!= queue
->descriptor_bo
) {
1632 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1635 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1636 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1637 S_008F04_SWIZZLE_ENABLE(1);
1638 map
[0] = scratch_va
;
1642 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1643 add_sample_positions
)
1644 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1645 esgs_ring_size
, esgs_ring_bo
,
1646 gsvs_ring_size
, gsvs_ring_bo
,
1647 tess_factor_ring_size
, tess_factor_ring_bo
,
1648 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1650 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1653 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1654 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1655 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1656 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1657 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1660 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1661 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1662 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1663 radeon_emit(cs
, esgs_ring_size
>> 8);
1664 radeon_emit(cs
, gsvs_ring_size
>> 8);
1666 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1667 radeon_emit(cs
, esgs_ring_size
>> 8);
1668 radeon_emit(cs
, gsvs_ring_size
>> 8);
1672 if (tess_factor_ring_bo
) {
1673 uint64_t tf_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1674 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1675 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1676 S_030938_SIZE(tess_factor_ring_size
/ 4));
1677 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1679 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1680 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1683 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1685 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1686 S_008988_SIZE(tess_factor_ring_size
/ 4));
1687 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1689 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1694 if (descriptor_bo
) {
1695 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1696 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1697 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1698 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1699 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
1700 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
1702 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1703 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1704 radeon_emit(cs
, va
);
1705 radeon_emit(cs
, va
>> 32);
1708 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1709 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1710 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1711 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1712 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1713 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1715 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1716 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1717 radeon_emit(cs
, va
);
1718 radeon_emit(cs
, va
>> 32);
1723 if (compute_scratch_bo
) {
1724 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1725 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1726 S_008F04_SWIZZLE_ENABLE(1);
1728 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
, 8);
1730 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1731 radeon_emit(cs
, scratch_va
);
1732 radeon_emit(cs
, rsrc1
);
1736 si_cs_emit_cache_flush(cs
,
1738 queue
->device
->physical_device
->rad_info
.chip_class
,
1740 queue
->queue_family_index
== RING_COMPUTE
&&
1741 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1742 (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
)) |
1743 RADV_CMD_FLAG_INV_ICACHE
|
1744 RADV_CMD_FLAG_INV_SMEM_L1
|
1745 RADV_CMD_FLAG_INV_VMEM_L1
|
1746 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1747 } else if (i
== 1) {
1748 si_cs_emit_cache_flush(cs
,
1750 queue
->device
->physical_device
->rad_info
.chip_class
,
1752 queue
->queue_family_index
== RING_COMPUTE
&&
1753 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1754 RADV_CMD_FLAG_INV_ICACHE
|
1755 RADV_CMD_FLAG_INV_SMEM_L1
|
1756 RADV_CMD_FLAG_INV_VMEM_L1
|
1757 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1760 if (!queue
->device
->ws
->cs_finalize(cs
))
1764 if (queue
->initial_full_flush_preamble_cs
)
1765 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1767 if (queue
->initial_preamble_cs
)
1768 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1770 if (queue
->continue_preamble_cs
)
1771 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1773 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1774 queue
->initial_preamble_cs
= dest_cs
[1];
1775 queue
->continue_preamble_cs
= dest_cs
[2];
1777 if (scratch_bo
!= queue
->scratch_bo
) {
1778 if (queue
->scratch_bo
)
1779 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1780 queue
->scratch_bo
= scratch_bo
;
1781 queue
->scratch_size
= scratch_size
;
1784 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1785 if (queue
->compute_scratch_bo
)
1786 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1787 queue
->compute_scratch_bo
= compute_scratch_bo
;
1788 queue
->compute_scratch_size
= compute_scratch_size
;
1791 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1792 if (queue
->esgs_ring_bo
)
1793 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1794 queue
->esgs_ring_bo
= esgs_ring_bo
;
1795 queue
->esgs_ring_size
= esgs_ring_size
;
1798 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1799 if (queue
->gsvs_ring_bo
)
1800 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1801 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1802 queue
->gsvs_ring_size
= gsvs_ring_size
;
1805 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1806 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1809 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1810 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1811 queue
->has_tess_rings
= true;
1814 if (descriptor_bo
!= queue
->descriptor_bo
) {
1815 if (queue
->descriptor_bo
)
1816 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1818 queue
->descriptor_bo
= descriptor_bo
;
1821 if (add_sample_positions
)
1822 queue
->has_sample_positions
= true;
1824 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1825 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1826 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1827 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1828 *continue_preamble_cs
= NULL
;
1831 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1833 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1834 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1835 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1836 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1837 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1838 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1839 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1840 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1841 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1842 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1843 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1844 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1845 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1846 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1847 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1848 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
1851 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1853 const VkSemaphore
*sems
,
1857 int syncobj_idx
= 0, sem_idx
= 0;
1859 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
1862 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1863 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1865 if (sem
->temp_syncobj
|| sem
->syncobj
)
1866 counts
->syncobj_count
++;
1868 counts
->sem_count
++;
1871 if (_fence
!= VK_NULL_HANDLE
) {
1872 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1873 if (fence
->temp_syncobj
|| fence
->syncobj
)
1874 counts
->syncobj_count
++;
1877 if (counts
->syncobj_count
) {
1878 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
1879 if (!counts
->syncobj
)
1880 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1883 if (counts
->sem_count
) {
1884 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
1886 free(counts
->syncobj
);
1887 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1891 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1892 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1894 if (sem
->temp_syncobj
) {
1895 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
1897 else if (sem
->syncobj
)
1898 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
1901 counts
->sem
[sem_idx
++] = sem
->sem
;
1905 if (_fence
!= VK_NULL_HANDLE
) {
1906 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1907 if (fence
->temp_syncobj
)
1908 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
1909 else if (fence
->syncobj
)
1910 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
1916 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
1918 free(sem_info
->wait
.syncobj
);
1919 free(sem_info
->wait
.sem
);
1920 free(sem_info
->signal
.syncobj
);
1921 free(sem_info
->signal
.sem
);
1925 static void radv_free_temp_syncobjs(struct radv_device
*device
,
1927 const VkSemaphore
*sems
)
1929 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1930 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1932 if (sem
->temp_syncobj
) {
1933 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
1934 sem
->temp_syncobj
= 0;
1939 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
1941 const VkSemaphore
*wait_sems
,
1942 int num_signal_sems
,
1943 const VkSemaphore
*signal_sems
,
1947 memset(sem_info
, 0, sizeof(*sem_info
));
1949 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
1952 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
1954 radv_free_sem_info(sem_info
);
1956 /* caller can override these */
1957 sem_info
->cs_emit_wait
= true;
1958 sem_info
->cs_emit_signal
= true;
1962 VkResult
radv_QueueSubmit(
1964 uint32_t submitCount
,
1965 const VkSubmitInfo
* pSubmits
,
1968 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1969 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1970 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
1971 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
1973 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
1974 uint32_t scratch_size
= 0;
1975 uint32_t compute_scratch_size
= 0;
1976 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
1977 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
1979 bool fence_emitted
= false;
1980 bool tess_rings_needed
= false;
1981 bool sample_positions_needed
= false;
1983 /* Do this first so failing to allocate scratch buffers can't result in
1984 * partially executed submissions. */
1985 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1986 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1987 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1988 pSubmits
[i
].pCommandBuffers
[j
]);
1990 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
1991 compute_scratch_size
= MAX2(compute_scratch_size
,
1992 cmd_buffer
->compute_scratch_size_needed
);
1993 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
1994 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
1995 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
1996 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2000 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2001 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2002 sample_positions_needed
, &initial_flush_preamble_cs
,
2003 &initial_preamble_cs
, &continue_preamble_cs
);
2004 if (result
!= VK_SUCCESS
)
2007 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2008 struct radeon_winsys_cs
**cs_array
;
2009 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2010 bool can_patch
= true;
2012 struct radv_winsys_sem_info sem_info
;
2014 result
= radv_alloc_sem_info(&sem_info
,
2015 pSubmits
[i
].waitSemaphoreCount
,
2016 pSubmits
[i
].pWaitSemaphores
,
2017 pSubmits
[i
].signalSemaphoreCount
,
2018 pSubmits
[i
].pSignalSemaphores
,
2020 if (result
!= VK_SUCCESS
)
2023 if (!pSubmits
[i
].commandBufferCount
) {
2024 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2025 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2026 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2031 radv_loge("failed to submit CS %d\n", i
);
2034 fence_emitted
= true;
2036 radv_free_sem_info(&sem_info
);
2040 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2041 (pSubmits
[i
].commandBufferCount
));
2043 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2044 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2045 pSubmits
[i
].pCommandBuffers
[j
]);
2046 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2048 cs_array
[j
] = cmd_buffer
->cs
;
2049 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2052 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2055 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2056 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2057 advance
= MIN2(max_cs_submission
,
2058 pSubmits
[i
].commandBufferCount
- j
);
2060 if (queue
->device
->trace_bo
)
2061 *queue
->device
->trace_id_ptr
= 0;
2063 sem_info
.cs_emit_wait
= j
== 0;
2064 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2066 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2067 advance
, initial_preamble
, continue_preamble_cs
,
2069 can_patch
, base_fence
);
2072 radv_loge("failed to submit CS %d\n", i
);
2075 fence_emitted
= true;
2076 if (queue
->device
->trace_bo
) {
2077 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2081 radv_free_temp_syncobjs(queue
->device
,
2082 pSubmits
[i
].waitSemaphoreCount
,
2083 pSubmits
[i
].pWaitSemaphores
);
2084 radv_free_sem_info(&sem_info
);
2089 if (!fence_emitted
) {
2090 struct radv_winsys_sem_info sem_info
;
2092 result
= radv_alloc_sem_info(&sem_info
, 0, NULL
, 0, NULL
,
2094 if (result
!= VK_SUCCESS
)
2097 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2098 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2099 1, NULL
, NULL
, &sem_info
,
2101 radv_free_sem_info(&sem_info
);
2103 fence
->submitted
= true;
2109 VkResult
radv_QueueWaitIdle(
2112 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2114 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2115 radv_queue_family_to_ring(queue
->queue_family_index
),
2120 VkResult
radv_DeviceWaitIdle(
2123 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2125 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2126 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2127 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2133 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2134 VkInstance instance
,
2137 return radv_lookup_entrypoint(pName
);
2140 /* The loader wants us to expose a second GetInstanceProcAddr function
2141 * to work around certain LD_PRELOAD issues seen in apps.
2144 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2145 VkInstance instance
,
2149 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2150 VkInstance instance
,
2153 return radv_GetInstanceProcAddr(instance
, pName
);
2156 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2160 return radv_lookup_entrypoint(pName
);
2163 bool radv_get_memory_fd(struct radv_device
*device
,
2164 struct radv_device_memory
*memory
,
2167 struct radeon_bo_metadata metadata
;
2169 if (memory
->image
) {
2170 radv_init_metadata(device
, memory
->image
, &metadata
);
2171 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2174 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2178 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2179 const VkMemoryAllocateInfo
* pAllocateInfo
,
2180 const VkAllocationCallbacks
* pAllocator
,
2181 VkDeviceMemory
* pMem
)
2183 struct radv_device_memory
*mem
;
2185 enum radeon_bo_domain domain
;
2187 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2189 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2191 if (pAllocateInfo
->allocationSize
== 0) {
2192 /* Apparently, this is allowed */
2193 *pMem
= VK_NULL_HANDLE
;
2197 const VkImportMemoryFdInfoKHR
*import_info
=
2198 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2199 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2200 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2201 const VkExportMemoryAllocateInfoKHR
*export_info
=
2202 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2204 const struct wsi_memory_allocate_info
*wsi_info
=
2205 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2207 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2208 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2210 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2212 if (wsi_info
&& wsi_info
->implicit_sync
)
2213 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2215 if (dedicate_info
) {
2216 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2217 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2224 assert(import_info
->handleType
==
2225 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2226 import_info
->handleType
==
2227 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2228 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2231 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2234 close(import_info
->fd
);
2239 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2240 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2241 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2242 domain
= RADEON_DOMAIN_GTT
;
2244 domain
= RADEON_DOMAIN_VRAM
;
2246 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2247 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2249 flags
|= RADEON_FLAG_CPU_ACCESS
;
2251 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2252 flags
|= RADEON_FLAG_GTT_WC
;
2254 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2255 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2257 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2261 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2264 mem
->type_index
= mem_type_index
;
2266 *pMem
= radv_device_memory_to_handle(mem
);
2271 vk_free2(&device
->alloc
, pAllocator
, mem
);
2276 VkResult
radv_AllocateMemory(
2278 const VkMemoryAllocateInfo
* pAllocateInfo
,
2279 const VkAllocationCallbacks
* pAllocator
,
2280 VkDeviceMemory
* pMem
)
2282 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2283 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
2286 void radv_FreeMemory(
2288 VkDeviceMemory _mem
,
2289 const VkAllocationCallbacks
* pAllocator
)
2291 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2292 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2297 device
->ws
->buffer_destroy(mem
->bo
);
2300 vk_free2(&device
->alloc
, pAllocator
, mem
);
2303 VkResult
radv_MapMemory(
2305 VkDeviceMemory _memory
,
2306 VkDeviceSize offset
,
2308 VkMemoryMapFlags flags
,
2311 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2312 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2319 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2325 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
2328 void radv_UnmapMemory(
2330 VkDeviceMemory _memory
)
2332 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2333 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2338 device
->ws
->buffer_unmap(mem
->bo
);
2341 VkResult
radv_FlushMappedMemoryRanges(
2343 uint32_t memoryRangeCount
,
2344 const VkMappedMemoryRange
* pMemoryRanges
)
2349 VkResult
radv_InvalidateMappedMemoryRanges(
2351 uint32_t memoryRangeCount
,
2352 const VkMappedMemoryRange
* pMemoryRanges
)
2357 void radv_GetBufferMemoryRequirements(
2360 VkMemoryRequirements
* pMemoryRequirements
)
2362 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2363 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2365 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2367 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2368 pMemoryRequirements
->alignment
= 4096;
2370 pMemoryRequirements
->alignment
= 16;
2372 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2375 void radv_GetBufferMemoryRequirements2KHR(
2377 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2378 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2380 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2381 &pMemoryRequirements
->memoryRequirements
);
2382 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
2383 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2384 switch (ext
->sType
) {
2385 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2386 VkMemoryDedicatedRequirementsKHR
*req
=
2387 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2388 req
->requiresDedicatedAllocation
= buffer
->shareable
;
2389 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2398 void radv_GetImageMemoryRequirements(
2401 VkMemoryRequirements
* pMemoryRequirements
)
2403 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2404 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2406 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
2408 pMemoryRequirements
->size
= image
->size
;
2409 pMemoryRequirements
->alignment
= image
->alignment
;
2412 void radv_GetImageMemoryRequirements2KHR(
2414 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2415 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2417 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2418 &pMemoryRequirements
->memoryRequirements
);
2420 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2422 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2423 switch (ext
->sType
) {
2424 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2425 VkMemoryDedicatedRequirementsKHR
*req
=
2426 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2427 req
->requiresDedicatedAllocation
= image
->shareable
;
2428 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2437 void radv_GetImageSparseMemoryRequirements(
2440 uint32_t* pSparseMemoryRequirementCount
,
2441 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2446 void radv_GetImageSparseMemoryRequirements2KHR(
2448 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2449 uint32_t* pSparseMemoryRequirementCount
,
2450 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2455 void radv_GetDeviceMemoryCommitment(
2457 VkDeviceMemory memory
,
2458 VkDeviceSize
* pCommittedMemoryInBytes
)
2460 *pCommittedMemoryInBytes
= 0;
2463 VkResult
radv_BindBufferMemory2KHR(VkDevice device
,
2464 uint32_t bindInfoCount
,
2465 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2467 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2468 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2469 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2472 buffer
->bo
= mem
->bo
;
2473 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2481 VkResult
radv_BindBufferMemory(
2484 VkDeviceMemory memory
,
2485 VkDeviceSize memoryOffset
)
2487 const VkBindBufferMemoryInfoKHR info
= {
2488 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2491 .memoryOffset
= memoryOffset
2494 return radv_BindBufferMemory2KHR(device
, 1, &info
);
2497 VkResult
radv_BindImageMemory2KHR(VkDevice device
,
2498 uint32_t bindInfoCount
,
2499 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2501 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2502 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2503 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2506 image
->bo
= mem
->bo
;
2507 image
->offset
= pBindInfos
[i
].memoryOffset
;
2517 VkResult
radv_BindImageMemory(
2520 VkDeviceMemory memory
,
2521 VkDeviceSize memoryOffset
)
2523 const VkBindImageMemoryInfoKHR info
= {
2524 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2527 .memoryOffset
= memoryOffset
2530 return radv_BindImageMemory2KHR(device
, 1, &info
);
2535 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2536 const VkSparseBufferMemoryBindInfo
*bind
)
2538 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2540 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2541 struct radv_device_memory
*mem
= NULL
;
2543 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2544 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2546 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2547 bind
->pBinds
[i
].resourceOffset
,
2548 bind
->pBinds
[i
].size
,
2549 mem
? mem
->bo
: NULL
,
2550 bind
->pBinds
[i
].memoryOffset
);
2555 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2556 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2558 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2560 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2561 struct radv_device_memory
*mem
= NULL
;
2563 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2564 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2566 device
->ws
->buffer_virtual_bind(image
->bo
,
2567 bind
->pBinds
[i
].resourceOffset
,
2568 bind
->pBinds
[i
].size
,
2569 mem
? mem
->bo
: NULL
,
2570 bind
->pBinds
[i
].memoryOffset
);
2574 VkResult
radv_QueueBindSparse(
2576 uint32_t bindInfoCount
,
2577 const VkBindSparseInfo
* pBindInfo
,
2580 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2581 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2582 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2583 bool fence_emitted
= false;
2585 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2586 struct radv_winsys_sem_info sem_info
;
2587 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2588 radv_sparse_buffer_bind_memory(queue
->device
,
2589 pBindInfo
[i
].pBufferBinds
+ j
);
2592 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2593 radv_sparse_image_opaque_bind_memory(queue
->device
,
2594 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2598 result
= radv_alloc_sem_info(&sem_info
,
2599 pBindInfo
[i
].waitSemaphoreCount
,
2600 pBindInfo
[i
].pWaitSemaphores
,
2601 pBindInfo
[i
].signalSemaphoreCount
,
2602 pBindInfo
[i
].pSignalSemaphores
,
2604 if (result
!= VK_SUCCESS
)
2607 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2608 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2609 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2613 fence_emitted
= true;
2615 fence
->submitted
= true;
2618 radv_free_sem_info(&sem_info
);
2622 if (fence
&& !fence_emitted
) {
2623 fence
->signalled
= true;
2629 VkResult
radv_CreateFence(
2631 const VkFenceCreateInfo
* pCreateInfo
,
2632 const VkAllocationCallbacks
* pAllocator
,
2635 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2636 const VkExportFenceCreateInfoKHR
*export
=
2637 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
2638 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
2639 export
? export
->handleTypes
: 0;
2641 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2643 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2646 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2648 fence
->submitted
= false;
2649 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2650 fence
->temp_syncobj
= 0;
2652 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
2654 vk_free2(&device
->alloc
, pAllocator
, fence
);
2655 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2657 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
2658 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
2660 fence
->fence
= NULL
;
2662 fence
->fence
= device
->ws
->create_fence();
2663 if (!fence
->fence
) {
2664 vk_free2(&device
->alloc
, pAllocator
, fence
);
2665 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2670 *pFence
= radv_fence_to_handle(fence
);
2675 void radv_DestroyFence(
2678 const VkAllocationCallbacks
* pAllocator
)
2680 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2681 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2686 if (fence
->temp_syncobj
)
2687 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
2689 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
2691 device
->ws
->destroy_fence(fence
->fence
);
2692 vk_free2(&device
->alloc
, pAllocator
, fence
);
2695 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2697 uint64_t current_time
;
2700 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2701 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2703 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2705 return current_time
+ timeout
;
2708 VkResult
radv_WaitForFences(
2710 uint32_t fenceCount
,
2711 const VkFence
* pFences
,
2715 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2716 timeout
= radv_get_absolute_timeout(timeout
);
2718 if (!waitAll
&& fenceCount
> 1) {
2719 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2722 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2723 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2724 bool expired
= false;
2726 if (fence
->temp_syncobj
) {
2727 if (!device
->ws
->wait_syncobj(device
->ws
, fence
->temp_syncobj
, timeout
))
2732 if (fence
->syncobj
) {
2733 if (!device
->ws
->wait_syncobj(device
->ws
, fence
->syncobj
, timeout
))
2738 if (fence
->signalled
)
2741 if (!fence
->submitted
)
2744 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2748 fence
->signalled
= true;
2754 VkResult
radv_ResetFences(VkDevice _device
,
2755 uint32_t fenceCount
,
2756 const VkFence
*pFences
)
2758 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2760 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2761 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2762 fence
->submitted
= fence
->signalled
= false;
2764 /* Per spec, we first restore the permanent payload, and then reset, so
2765 * having a temp syncobj should not skip resetting the permanent syncobj. */
2766 if (fence
->temp_syncobj
) {
2767 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
2768 fence
->temp_syncobj
= 0;
2771 if (fence
->syncobj
) {
2772 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
2779 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2781 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2782 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2784 if (fence
->temp_syncobj
) {
2785 bool success
= device
->ws
->wait_syncobj(device
->ws
, fence
->temp_syncobj
, 0);
2786 return success
? VK_SUCCESS
: VK_NOT_READY
;
2789 if (fence
->syncobj
) {
2790 bool success
= device
->ws
->wait_syncobj(device
->ws
, fence
->syncobj
, 0);
2791 return success
? VK_SUCCESS
: VK_NOT_READY
;
2794 if (fence
->signalled
)
2796 if (!fence
->submitted
)
2797 return VK_NOT_READY
;
2798 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2799 return VK_NOT_READY
;
2805 // Queue semaphore functions
2807 VkResult
radv_CreateSemaphore(
2809 const VkSemaphoreCreateInfo
* pCreateInfo
,
2810 const VkAllocationCallbacks
* pAllocator
,
2811 VkSemaphore
* pSemaphore
)
2813 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2814 const VkExportSemaphoreCreateInfoKHR
*export
=
2815 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2816 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2817 export
? export
->handleTypes
: 0;
2819 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2821 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2823 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2825 sem
->temp_syncobj
= 0;
2826 /* create a syncobject if we are going to export this semaphore */
2828 assert (device
->physical_device
->rad_info
.has_syncobj
);
2829 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2831 vk_free2(&device
->alloc
, pAllocator
, sem
);
2832 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2836 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2838 vk_free2(&device
->alloc
, pAllocator
, sem
);
2839 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2844 *pSemaphore
= radv_semaphore_to_handle(sem
);
2848 void radv_DestroySemaphore(
2850 VkSemaphore _semaphore
,
2851 const VkAllocationCallbacks
* pAllocator
)
2853 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2854 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2859 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2861 device
->ws
->destroy_sem(sem
->sem
);
2862 vk_free2(&device
->alloc
, pAllocator
, sem
);
2865 VkResult
radv_CreateEvent(
2867 const VkEventCreateInfo
* pCreateInfo
,
2868 const VkAllocationCallbacks
* pAllocator
,
2871 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2872 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2874 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2877 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2879 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2881 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
2883 vk_free2(&device
->alloc
, pAllocator
, event
);
2884 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2887 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2889 *pEvent
= radv_event_to_handle(event
);
2894 void radv_DestroyEvent(
2897 const VkAllocationCallbacks
* pAllocator
)
2899 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2900 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2904 device
->ws
->buffer_destroy(event
->bo
);
2905 vk_free2(&device
->alloc
, pAllocator
, event
);
2908 VkResult
radv_GetEventStatus(
2912 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2914 if (*event
->map
== 1)
2915 return VK_EVENT_SET
;
2916 return VK_EVENT_RESET
;
2919 VkResult
radv_SetEvent(
2923 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2929 VkResult
radv_ResetEvent(
2933 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2939 VkResult
radv_CreateBuffer(
2941 const VkBufferCreateInfo
* pCreateInfo
,
2942 const VkAllocationCallbacks
* pAllocator
,
2945 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2946 struct radv_buffer
*buffer
;
2948 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2950 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2951 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2953 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2955 buffer
->size
= pCreateInfo
->size
;
2956 buffer
->usage
= pCreateInfo
->usage
;
2959 buffer
->flags
= pCreateInfo
->flags
;
2961 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
2962 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
2964 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2965 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2966 align64(buffer
->size
, 4096),
2967 4096, 0, RADEON_FLAG_VIRTUAL
);
2969 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2970 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2974 *pBuffer
= radv_buffer_to_handle(buffer
);
2979 void radv_DestroyBuffer(
2982 const VkAllocationCallbacks
* pAllocator
)
2984 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2985 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2990 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2991 device
->ws
->buffer_destroy(buffer
->bo
);
2993 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2996 static inline unsigned
2997 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3000 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3002 return image
->surface
.u
.legacy
.tiling_index
[level
];
3005 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3007 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3011 radv_initialise_color_surface(struct radv_device
*device
,
3012 struct radv_color_buffer_info
*cb
,
3013 struct radv_image_view
*iview
)
3015 const struct vk_format_description
*desc
;
3016 unsigned ntype
, format
, swap
, endian
;
3017 unsigned blend_clamp
= 0, blend_bypass
= 0;
3019 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3021 desc
= vk_format_description(iview
->vk_format
);
3023 memset(cb
, 0, sizeof(*cb
));
3025 /* Intensity is implemented as Red, so treat it that way. */
3026 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3028 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3030 cb
->cb_color_base
= va
>> 8;
3032 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3033 struct gfx9_surf_meta_flags meta
;
3034 if (iview
->image
->dcc_offset
)
3035 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3037 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3039 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3040 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3041 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3042 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3044 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3045 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3047 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3048 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3050 cb
->cb_color_base
+= level_info
->offset
>> 8;
3051 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3052 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3054 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3055 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3056 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3058 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3059 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3060 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3062 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3064 if (iview
->image
->fmask
.size
) {
3065 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3066 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3067 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3068 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3070 /* This must be set for fast clear to work without FMASK. */
3071 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3072 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3073 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3074 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3078 /* CMASK variables */
3079 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3080 va
+= iview
->image
->cmask
.offset
;
3081 cb
->cb_color_cmask
= va
>> 8;
3083 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3084 va
+= iview
->image
->dcc_offset
;
3085 cb
->cb_dcc_base
= va
>> 8;
3086 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3088 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3089 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3090 S_028C6C_SLICE_MAX(max_slice
);
3092 if (iview
->image
->info
.samples
> 1) {
3093 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3095 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3096 S_028C74_NUM_FRAGMENTS(log_samples
);
3099 if (iview
->image
->fmask
.size
) {
3100 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3101 cb
->cb_color_fmask
= va
>> 8;
3102 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3104 cb
->cb_color_fmask
= cb
->cb_color_base
;
3107 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3109 vk_format_get_first_non_void_channel(iview
->vk_format
));
3110 format
= radv_translate_colorformat(iview
->vk_format
);
3111 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3112 radv_finishme("Illegal color\n");
3113 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3114 endian
= radv_colorformat_endian_swap(format
);
3116 /* blend clamp should be set for all NORM/SRGB types */
3117 if (ntype
== V_028C70_NUMBER_UNORM
||
3118 ntype
== V_028C70_NUMBER_SNORM
||
3119 ntype
== V_028C70_NUMBER_SRGB
)
3122 /* set blend bypass according to docs if SINT/UINT or
3123 8/24 COLOR variants */
3124 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3125 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3126 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3131 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3132 (format
== V_028C70_COLOR_8
||
3133 format
== V_028C70_COLOR_8_8
||
3134 format
== V_028C70_COLOR_8_8_8_8
))
3135 ->color_is_int8
= true;
3137 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3138 S_028C70_COMP_SWAP(swap
) |
3139 S_028C70_BLEND_CLAMP(blend_clamp
) |
3140 S_028C70_BLEND_BYPASS(blend_bypass
) |
3141 S_028C70_SIMPLE_FLOAT(1) |
3142 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3143 ntype
!= V_028C70_NUMBER_SNORM
&&
3144 ntype
!= V_028C70_NUMBER_SRGB
&&
3145 format
!= V_028C70_COLOR_8_24
&&
3146 format
!= V_028C70_COLOR_24_8
) |
3147 S_028C70_NUMBER_TYPE(ntype
) |
3148 S_028C70_ENDIAN(endian
);
3149 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3150 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3151 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3152 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3153 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3157 if (iview
->image
->cmask
.size
&&
3158 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3159 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3161 if (radv_vi_dcc_enabled(iview
->image
, iview
->base_mip
))
3162 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3164 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3165 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3166 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3167 unsigned independent_64b_blocks
= 0;
3168 unsigned max_compressed_block_size
;
3170 /* amdvlk: [min-compressed-block-size] should be set to 32 for dGPU and
3171 64 for APU because all of our APUs to date use DIMMs which have
3172 a request granularity size of 64B while all other chips have a
3174 if (!device
->physical_device
->rad_info
.has_dedicated_vram
)
3175 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3177 if (iview
->image
->info
.samples
> 1) {
3178 if (iview
->image
->surface
.bpe
== 1)
3179 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3180 else if (iview
->image
->surface
.bpe
== 2)
3181 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3184 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3185 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3186 independent_64b_blocks
= 1;
3187 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3189 max_compressed_block_size
= max_uncompressed_block_size
;
3191 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3192 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3193 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3194 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3197 /* This must be set for fast clear to work without FMASK. */
3198 if (!iview
->image
->fmask
.size
&&
3199 device
->physical_device
->rad_info
.chip_class
== SI
) {
3200 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3201 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3204 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3205 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3206 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3208 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3209 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3210 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3211 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3212 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3213 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3218 radv_initialise_ds_surface(struct radv_device
*device
,
3219 struct radv_ds_buffer_info
*ds
,
3220 struct radv_image_view
*iview
)
3222 unsigned level
= iview
->base_mip
;
3223 unsigned format
, stencil_format
;
3224 uint64_t va
, s_offs
, z_offs
;
3225 bool stencil_only
= false;
3226 memset(ds
, 0, sizeof(*ds
));
3227 switch (iview
->image
->vk_format
) {
3228 case VK_FORMAT_D24_UNORM_S8_UINT
:
3229 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3230 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3231 ds
->offset_scale
= 2.0f
;
3233 case VK_FORMAT_D16_UNORM
:
3234 case VK_FORMAT_D16_UNORM_S8_UINT
:
3235 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3236 ds
->offset_scale
= 4.0f
;
3238 case VK_FORMAT_D32_SFLOAT
:
3239 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3240 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3241 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3242 ds
->offset_scale
= 1.0f
;
3244 case VK_FORMAT_S8_UINT
:
3245 stencil_only
= true;
3251 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3252 stencil_format
= iview
->image
->surface
.has_stencil
?
3253 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3255 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
3256 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3257 S_028008_SLICE_MAX(max_slice
);
3259 ds
->db_htile_data_base
= 0;
3260 ds
->db_htile_surface
= 0;
3262 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3263 s_offs
= z_offs
= va
;
3265 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3266 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3267 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3269 ds
->db_z_info
= S_028038_FORMAT(format
) |
3270 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3271 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3272 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3273 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3274 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3276 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3277 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3278 ds
->db_depth_view
|= S_028008_MIPID(level
);
3280 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3281 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3283 if (radv_htile_enabled(iview
->image
, level
)) {
3284 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3286 if (iview
->image
->tc_compatible_htile
) {
3287 unsigned max_zplanes
= 4;
3289 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3290 iview
->image
->info
.samples
> 1)
3293 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
+ 1) |
3294 S_028038_ITERATE_FLUSH(1);
3295 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3298 if (!iview
->image
->surface
.has_stencil
)
3299 /* Use all of the htile_buffer for depth if there's no stencil. */
3300 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3301 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3302 iview
->image
->htile_offset
;
3303 ds
->db_htile_data_base
= va
>> 8;
3304 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3305 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3306 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3309 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3312 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3314 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3315 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3317 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!iview
->image
->tc_compatible_htile
);
3318 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3319 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3321 if (iview
->image
->info
.samples
> 1)
3322 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3324 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3325 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3326 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3327 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3328 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3329 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3330 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3331 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3334 tile_mode
= stencil_tile_mode
;
3336 ds
->db_depth_info
|=
3337 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3338 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3339 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3340 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3341 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3342 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3343 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3344 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3346 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3347 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3348 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3349 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3351 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3354 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3355 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3356 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3358 if (radv_htile_enabled(iview
->image
, level
)) {
3359 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3361 if (!iview
->image
->surface
.has_stencil
&&
3362 !iview
->image
->tc_compatible_htile
)
3363 /* Use all of the htile_buffer for depth if there's no stencil. */
3364 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3366 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3367 iview
->image
->htile_offset
;
3368 ds
->db_htile_data_base
= va
>> 8;
3369 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3371 if (iview
->image
->tc_compatible_htile
) {
3372 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3374 if (iview
->image
->info
.samples
<= 1)
3375 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
3376 else if (iview
->image
->info
.samples
<= 4)
3377 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
3379 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
3384 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3385 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3388 VkResult
radv_CreateFramebuffer(
3390 const VkFramebufferCreateInfo
* pCreateInfo
,
3391 const VkAllocationCallbacks
* pAllocator
,
3392 VkFramebuffer
* pFramebuffer
)
3394 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3395 struct radv_framebuffer
*framebuffer
;
3397 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3399 size_t size
= sizeof(*framebuffer
) +
3400 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3401 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3402 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3403 if (framebuffer
== NULL
)
3404 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3406 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3407 framebuffer
->width
= pCreateInfo
->width
;
3408 framebuffer
->height
= pCreateInfo
->height
;
3409 framebuffer
->layers
= pCreateInfo
->layers
;
3410 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3411 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3412 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3413 framebuffer
->attachments
[i
].attachment
= iview
;
3414 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3415 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3416 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3417 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3419 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3420 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3421 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
3424 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3428 void radv_DestroyFramebuffer(
3431 const VkAllocationCallbacks
* pAllocator
)
3433 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3434 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3438 vk_free2(&device
->alloc
, pAllocator
, fb
);
3441 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3443 switch (address_mode
) {
3444 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3445 return V_008F30_SQ_TEX_WRAP
;
3446 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3447 return V_008F30_SQ_TEX_MIRROR
;
3448 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3449 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3450 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3451 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3452 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3453 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3455 unreachable("illegal tex wrap mode");
3461 radv_tex_compare(VkCompareOp op
)
3464 case VK_COMPARE_OP_NEVER
:
3465 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3466 case VK_COMPARE_OP_LESS
:
3467 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3468 case VK_COMPARE_OP_EQUAL
:
3469 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3470 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3471 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3472 case VK_COMPARE_OP_GREATER
:
3473 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3474 case VK_COMPARE_OP_NOT_EQUAL
:
3475 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3476 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3477 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3478 case VK_COMPARE_OP_ALWAYS
:
3479 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3481 unreachable("illegal compare mode");
3487 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3490 case VK_FILTER_NEAREST
:
3491 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3492 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3493 case VK_FILTER_LINEAR
:
3494 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3495 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3496 case VK_FILTER_CUBIC_IMG
:
3498 fprintf(stderr
, "illegal texture filter");
3504 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3507 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3508 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3509 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3510 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3512 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3517 radv_tex_bordercolor(VkBorderColor bcolor
)
3520 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3521 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3522 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3523 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3524 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3525 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3526 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3527 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3528 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3536 radv_tex_aniso_filter(unsigned filter
)
3550 radv_init_sampler(struct radv_device
*device
,
3551 struct radv_sampler
*sampler
,
3552 const VkSamplerCreateInfo
*pCreateInfo
)
3554 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3555 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3556 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3557 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3559 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3560 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3561 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3562 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3563 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3564 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3565 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3566 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3567 S_008F30_DISABLE_CUBE_WRAP(0) |
3568 S_008F30_COMPAT_MODE(is_vi
));
3569 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3570 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3571 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3572 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3573 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3574 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3575 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3576 S_008F38_MIP_POINT_PRECLAMP(0) |
3577 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
3578 S_008F38_FILTER_PREC_FIX(1) |
3579 S_008F38_ANISO_OVERRIDE(is_vi
));
3580 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3581 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3584 VkResult
radv_CreateSampler(
3586 const VkSamplerCreateInfo
* pCreateInfo
,
3587 const VkAllocationCallbacks
* pAllocator
,
3588 VkSampler
* pSampler
)
3590 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3591 struct radv_sampler
*sampler
;
3593 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3595 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3596 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3598 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3600 radv_init_sampler(device
, sampler
, pCreateInfo
);
3601 *pSampler
= radv_sampler_to_handle(sampler
);
3606 void radv_DestroySampler(
3609 const VkAllocationCallbacks
* pAllocator
)
3611 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3612 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3616 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3619 /* vk_icd.h does not declare this function, so we declare it here to
3620 * suppress Wmissing-prototypes.
3622 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3623 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3625 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3626 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3628 /* For the full details on loader interface versioning, see
3629 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3630 * What follows is a condensed summary, to help you navigate the large and
3631 * confusing official doc.
3633 * - Loader interface v0 is incompatible with later versions. We don't
3636 * - In loader interface v1:
3637 * - The first ICD entrypoint called by the loader is
3638 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3640 * - The ICD must statically expose no other Vulkan symbol unless it is
3641 * linked with -Bsymbolic.
3642 * - Each dispatchable Vulkan handle created by the ICD must be
3643 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3644 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3645 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3646 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3647 * such loader-managed surfaces.
3649 * - Loader interface v2 differs from v1 in:
3650 * - The first ICD entrypoint called by the loader is
3651 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3652 * statically expose this entrypoint.
3654 * - Loader interface v3 differs from v2 in:
3655 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3656 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3657 * because the loader no longer does so.
3659 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3663 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3664 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3667 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3668 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3670 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3672 /* At the moment, we support only the below handle types. */
3673 assert(pGetFdInfo
->handleType
==
3674 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
3675 pGetFdInfo
->handleType
==
3676 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
3678 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3680 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3684 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3685 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3687 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3689 switch (handleType
) {
3690 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
3691 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
3695 /* The valid usage section for this function says:
3697 * "handleType must not be one of the handle types defined as
3700 * So opaque handle types fall into the default "unsupported" case.
3702 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3706 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
3710 uint32_t syncobj_handle
= 0;
3711 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
3713 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3716 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
3718 *syncobj
= syncobj_handle
;
3724 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
3728 /* If we create a syncobj we do it locally so that if we have an error, we don't
3729 * leave a syncobj in an undetermined state in the fence. */
3730 uint32_t syncobj_handle
= *syncobj
;
3731 if (!syncobj_handle
) {
3732 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
3734 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3739 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
3741 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
3743 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3746 *syncobj
= syncobj_handle
;
3753 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3754 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3756 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3757 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3758 uint32_t *syncobj_dst
= NULL
;
3760 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3761 syncobj_dst
= &sem
->temp_syncobj
;
3763 syncobj_dst
= &sem
->syncobj
;
3766 switch(pImportSemaphoreFdInfo
->handleType
) {
3767 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3768 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
3769 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3770 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
3772 unreachable("Unhandled semaphore handle type");
3776 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3777 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3780 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3781 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3783 uint32_t syncobj_handle
;
3785 if (sem
->temp_syncobj
)
3786 syncobj_handle
= sem
->temp_syncobj
;
3788 syncobj_handle
= sem
->syncobj
;
3790 switch(pGetFdInfo
->handleType
) {
3791 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3792 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3794 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3795 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
3798 unreachable("Unhandled semaphore handle type");
3802 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3806 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3807 VkPhysicalDevice physicalDevice
,
3808 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3809 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3811 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
3813 /* Require has_syncobj_wait for the syncobj signal ioctl introduced at virtually the same time */
3814 if (pdevice
->rad_info
.has_syncobj_wait
&&
3815 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
3816 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
3817 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
3818 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
3819 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3820 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3821 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3822 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3823 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3824 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3825 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3827 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3828 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3829 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
3833 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
3834 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
3836 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3837 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
3838 uint32_t *syncobj_dst
= NULL
;
3841 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
3842 syncobj_dst
= &fence
->temp_syncobj
;
3844 syncobj_dst
= &fence
->syncobj
;
3847 switch(pImportFenceFdInfo
->handleType
) {
3848 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3849 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
3850 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3851 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
3853 unreachable("Unhandled fence handle type");
3857 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
3858 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
3861 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3862 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
3864 uint32_t syncobj_handle
;
3866 if (fence
->temp_syncobj
)
3867 syncobj_handle
= fence
->temp_syncobj
;
3869 syncobj_handle
= fence
->syncobj
;
3871 switch(pGetFdInfo
->handleType
) {
3872 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
3873 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3875 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
3876 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
3879 unreachable("Unhandled fence handle type");
3883 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3887 void radv_GetPhysicalDeviceExternalFencePropertiesKHR(
3888 VkPhysicalDevice physicalDevice
,
3889 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
3890 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
3892 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
3894 if (pdevice
->rad_info
.has_syncobj_wait
&&
3895 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
3896 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
3897 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
3898 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
3899 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
3900 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3902 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
3903 pExternalFenceProperties
->compatibleHandleTypes
= 0;
3904 pExternalFenceProperties
->externalFenceFeatures
= 0;