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 "amdgpu_id.h"
43 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
44 #include "ac_llvm_util.h"
45 #include "vk_format.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
53 uint32_t mesa_timestamp
, llvm_timestamp
;
55 memset(uuid
, 0, VK_UUID_SIZE
);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
60 memcpy(uuid
, &mesa_timestamp
, 4);
61 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
62 memcpy((char*)uuid
+ 8, &f
, 2);
63 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
68 radv_get_driver_uuid(void *uuid
)
70 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
74 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
76 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
79 static const VkExtensionProperties instance_extensions
[] = {
81 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
84 #ifdef VK_USE_PLATFORM_XCB_KHR
86 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
90 #ifdef VK_USE_PLATFORM_XLIB_KHR
92 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
96 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
98 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
103 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
107 .extensionName
= VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
,
111 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME
,
116 static const VkExtensionProperties common_device_extensions
[] = {
118 .extensionName
= VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME
,
122 .extensionName
= VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME
,
126 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
130 .extensionName
= VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
,
134 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
138 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
142 .extensionName
= VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
,
146 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
150 .extensionName
= VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
,
154 .extensionName
= VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME
,
158 .extensionName
= VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME
,
162 .extensionName
= VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME
,
166 .extensionName
= VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME
,
170 .extensionName
= VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME
,
174 static const VkExtensionProperties ext_sema_device_extensions
[] = {
176 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME
,
180 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME
,
184 .extensionName
= VK_KHX_MULTIVIEW_EXTENSION_NAME
,
190 radv_extensions_register(struct radv_instance
*instance
,
191 struct radv_extensions
*extensions
,
192 const VkExtensionProperties
*new_ext
,
196 VkExtensionProperties
*new_ptr
;
198 assert(new_ext
&& num_ext
> 0);
201 return VK_ERROR_INITIALIZATION_FAILED
;
203 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
204 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
205 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
207 /* Old array continues to be valid, update nothing */
209 return VK_ERROR_OUT_OF_HOST_MEMORY
;
211 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
212 num_ext
* sizeof(VkExtensionProperties
));
213 extensions
->ext_array
= new_ptr
;
214 extensions
->num_ext
+= num_ext
;
220 radv_extensions_finish(struct radv_instance
*instance
,
221 struct radv_extensions
*extensions
)
226 radv_loge("Attemted to free invalid extension struct\n");
228 if (extensions
->ext_array
)
229 vk_free(&instance
->alloc
, extensions
->ext_array
);
233 is_extension_enabled(const VkExtensionProperties
*extensions
,
237 assert(extensions
&& name
);
239 for (uint32_t i
= 0; i
< num_ext
; i
++) {
240 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
248 get_chip_name(enum radeon_family family
)
251 case CHIP_TAHITI
: return "AMD RADV TAHITI";
252 case CHIP_PITCAIRN
: return "AMD RADV PITCAIRN";
253 case CHIP_VERDE
: return "AMD RADV CAPE VERDE";
254 case CHIP_OLAND
: return "AMD RADV OLAND";
255 case CHIP_HAINAN
: return "AMD RADV HAINAN";
256 case CHIP_BONAIRE
: return "AMD RADV BONAIRE";
257 case CHIP_KAVERI
: return "AMD RADV KAVERI";
258 case CHIP_KABINI
: return "AMD RADV KABINI";
259 case CHIP_HAWAII
: return "AMD RADV HAWAII";
260 case CHIP_MULLINS
: return "AMD RADV MULLINS";
261 case CHIP_TONGA
: return "AMD RADV TONGA";
262 case CHIP_ICELAND
: return "AMD RADV ICELAND";
263 case CHIP_CARRIZO
: return "AMD RADV CARRIZO";
264 case CHIP_FIJI
: return "AMD RADV FIJI";
265 case CHIP_POLARIS10
: return "AMD RADV POLARIS10";
266 case CHIP_POLARIS11
: return "AMD RADV POLARIS11";
267 case CHIP_POLARIS12
: return "AMD RADV POLARIS12";
268 case CHIP_STONEY
: return "AMD RADV STONEY";
269 case CHIP_VEGA10
: return "AMD RADV VEGA";
270 case CHIP_RAVEN
: return "AMD RADV RAVEN";
271 default: return "AMD RADV unknown";
276 radv_physical_device_init(struct radv_physical_device
*device
,
277 struct radv_instance
*instance
,
278 drmDevicePtr drm_device
)
280 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
282 drmVersionPtr version
;
285 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
287 return VK_ERROR_INCOMPATIBLE_DRIVER
;
289 version
= drmGetVersion(fd
);
292 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
293 "failed to get version %s: %m", path
);
296 if (strcmp(version
->name
, "amdgpu")) {
297 drmFreeVersion(version
);
299 return VK_ERROR_INCOMPATIBLE_DRIVER
;
301 drmFreeVersion(version
);
303 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
304 device
->instance
= instance
;
305 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
306 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
308 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
309 instance
->perftest_flags
);
311 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
315 device
->local_fd
= fd
;
316 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
317 result
= radv_init_wsi(device
);
318 if (result
!= VK_SUCCESS
) {
319 device
->ws
->destroy(device
->ws
);
323 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
324 radv_finish_wsi(device
);
325 device
->ws
->destroy(device
->ws
);
326 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
327 "cannot generate UUID");
331 result
= radv_extensions_register(instance
,
333 common_device_extensions
,
334 ARRAY_SIZE(common_device_extensions
));
335 if (result
!= VK_SUCCESS
)
338 if (device
->rad_info
.has_syncobj
) {
339 result
= radv_extensions_register(instance
,
341 ext_sema_device_extensions
,
342 ARRAY_SIZE(ext_sema_device_extensions
));
343 if (result
!= VK_SUCCESS
)
347 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
348 device
->name
= get_chip_name(device
->rad_info
.family
);
350 radv_get_driver_uuid(&device
->device_uuid
);
351 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
353 if (device
->rad_info
.family
== CHIP_STONEY
||
354 device
->rad_info
.chip_class
>= GFX9
) {
355 device
->has_rbplus
= true;
356 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
367 radv_physical_device_finish(struct radv_physical_device
*device
)
369 radv_extensions_finish(device
->instance
, &device
->extensions
);
370 radv_finish_wsi(device
);
371 device
->ws
->destroy(device
->ws
);
372 close(device
->local_fd
);
376 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
377 VkSystemAllocationScope allocationScope
)
383 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
384 size_t align
, VkSystemAllocationScope allocationScope
)
386 return realloc(pOriginal
, size
);
390 default_free_func(void *pUserData
, void *pMemory
)
395 static const VkAllocationCallbacks default_alloc
= {
397 .pfnAllocation
= default_alloc_func
,
398 .pfnReallocation
= default_realloc_func
,
399 .pfnFree
= default_free_func
,
402 static const struct debug_control radv_debug_options
[] = {
403 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
404 {"nodcc", RADV_DEBUG_NO_DCC
},
405 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
406 {"nocache", RADV_DEBUG_NO_CACHE
},
407 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
408 {"nohiz", RADV_DEBUG_NO_HIZ
},
409 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
410 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
411 {"allbos", RADV_DEBUG_ALL_BOS
},
412 {"noibs", RADV_DEBUG_NO_IBS
},
413 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
417 static const struct debug_control radv_perftest_options
[] = {
418 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
419 {"sisched", RADV_PERFTEST_SISCHED
},
423 VkResult
radv_CreateInstance(
424 const VkInstanceCreateInfo
* pCreateInfo
,
425 const VkAllocationCallbacks
* pAllocator
,
426 VkInstance
* pInstance
)
428 struct radv_instance
*instance
;
430 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
432 uint32_t client_version
;
433 if (pCreateInfo
->pApplicationInfo
&&
434 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
435 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
437 client_version
= VK_MAKE_VERSION(1, 0, 0);
440 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
441 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
442 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
443 "Client requested version %d.%d.%d",
444 VK_VERSION_MAJOR(client_version
),
445 VK_VERSION_MINOR(client_version
),
446 VK_VERSION_PATCH(client_version
));
449 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
450 if (!is_extension_enabled(instance_extensions
,
451 ARRAY_SIZE(instance_extensions
),
452 pCreateInfo
->ppEnabledExtensionNames
[i
]))
453 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
456 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
457 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
459 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
461 memset(instance
, 0, sizeof(*instance
));
463 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
466 instance
->alloc
= *pAllocator
;
468 instance
->alloc
= default_alloc
;
470 instance
->apiVersion
= client_version
;
471 instance
->physicalDeviceCount
= -1;
475 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
477 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
480 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
481 radv_perftest_options
);
483 *pInstance
= radv_instance_to_handle(instance
);
488 void radv_DestroyInstance(
489 VkInstance _instance
,
490 const VkAllocationCallbacks
* pAllocator
)
492 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
497 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
498 radv_physical_device_finish(instance
->physicalDevices
+ i
);
501 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
505 vk_free(&instance
->alloc
, instance
);
509 radv_enumerate_devices(struct radv_instance
*instance
)
511 /* TODO: Check for more devices ? */
512 drmDevicePtr devices
[8];
513 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
516 instance
->physicalDeviceCount
= 0;
518 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
520 return VK_ERROR_INCOMPATIBLE_DRIVER
;
522 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
523 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
524 devices
[i
]->bustype
== DRM_BUS_PCI
&&
525 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x1002) {
527 result
= radv_physical_device_init(instance
->physicalDevices
+
528 instance
->physicalDeviceCount
,
531 if (result
== VK_SUCCESS
)
532 ++instance
->physicalDeviceCount
;
533 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
537 drmFreeDevices(devices
, max_devices
);
542 VkResult
radv_EnumeratePhysicalDevices(
543 VkInstance _instance
,
544 uint32_t* pPhysicalDeviceCount
,
545 VkPhysicalDevice
* pPhysicalDevices
)
547 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
550 if (instance
->physicalDeviceCount
< 0) {
551 result
= radv_enumerate_devices(instance
);
552 if (result
!= VK_SUCCESS
&&
553 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
557 if (!pPhysicalDevices
) {
558 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
560 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
561 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
562 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
565 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
569 void radv_GetPhysicalDeviceFeatures(
570 VkPhysicalDevice physicalDevice
,
571 VkPhysicalDeviceFeatures
* pFeatures
)
573 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
574 bool is_gfx9
= pdevice
->rad_info
.chip_class
>= GFX9
;
575 memset(pFeatures
, 0, sizeof(*pFeatures
));
577 *pFeatures
= (VkPhysicalDeviceFeatures
) {
578 .robustBufferAccess
= true,
579 .fullDrawIndexUint32
= true,
580 .imageCubeArray
= true,
581 .independentBlend
= true,
582 .geometryShader
= !is_gfx9
,
583 .tessellationShader
= !is_gfx9
,
584 .sampleRateShading
= true,
585 .dualSrcBlend
= true,
587 .multiDrawIndirect
= true,
588 .drawIndirectFirstInstance
= true,
590 .depthBiasClamp
= true,
591 .fillModeNonSolid
= true,
596 .multiViewport
= true,
597 .samplerAnisotropy
= true,
598 .textureCompressionETC2
= false,
599 .textureCompressionASTC_LDR
= false,
600 .textureCompressionBC
= true,
601 .occlusionQueryPrecise
= true,
602 .pipelineStatisticsQuery
= true,
603 .vertexPipelineStoresAndAtomics
= true,
604 .fragmentStoresAndAtomics
= true,
605 .shaderTessellationAndGeometryPointSize
= true,
606 .shaderImageGatherExtended
= true,
607 .shaderStorageImageExtendedFormats
= true,
608 .shaderStorageImageMultisample
= false,
609 .shaderUniformBufferArrayDynamicIndexing
= true,
610 .shaderSampledImageArrayDynamicIndexing
= true,
611 .shaderStorageBufferArrayDynamicIndexing
= true,
612 .shaderStorageImageArrayDynamicIndexing
= true,
613 .shaderStorageImageReadWithoutFormat
= true,
614 .shaderStorageImageWriteWithoutFormat
= true,
615 .shaderClipDistance
= true,
616 .shaderCullDistance
= true,
617 .shaderFloat64
= true,
619 .shaderInt16
= false,
620 .sparseBinding
= true,
621 .variableMultisampleRate
= true,
622 .inheritedQueries
= true,
626 void radv_GetPhysicalDeviceFeatures2KHR(
627 VkPhysicalDevice physicalDevice
,
628 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
630 vk_foreach_struct(ext
, pFeatures
->pNext
) {
631 switch (ext
->sType
) {
632 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
633 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
634 features
->variablePointersStorageBuffer
= true;
635 features
->variablePointers
= false;
638 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
639 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
640 features
->multiview
= true;
641 features
->multiviewGeometryShader
= true;
642 features
->multiviewTessellationShader
= true;
649 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
652 void radv_GetPhysicalDeviceProperties(
653 VkPhysicalDevice physicalDevice
,
654 VkPhysicalDeviceProperties
* pProperties
)
656 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
657 VkSampleCountFlags sample_counts
= 0xf;
659 /* make sure that the entire descriptor set is addressable with a signed
660 * 32-bit int. So the sum of all limits scaled by descriptor size has to
661 * be at most 2 GiB. the combined image & samples object count as one of
662 * both. This limit is for the pipeline layout, not for the set layout, but
663 * there is no set limit, so we just set a pipeline limit. I don't think
664 * any app is going to hit this soon. */
665 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
666 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
667 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
668 32 /* sampler, largest when combined with image */ +
669 64 /* sampled image */ +
670 64 /* storage image */);
672 VkPhysicalDeviceLimits limits
= {
673 .maxImageDimension1D
= (1 << 14),
674 .maxImageDimension2D
= (1 << 14),
675 .maxImageDimension3D
= (1 << 11),
676 .maxImageDimensionCube
= (1 << 14),
677 .maxImageArrayLayers
= (1 << 11),
678 .maxTexelBufferElements
= 128 * 1024 * 1024,
679 .maxUniformBufferRange
= UINT32_MAX
,
680 .maxStorageBufferRange
= UINT32_MAX
,
681 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
682 .maxMemoryAllocationCount
= UINT32_MAX
,
683 .maxSamplerAllocationCount
= 64 * 1024,
684 .bufferImageGranularity
= 64, /* A cache line */
685 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
686 .maxBoundDescriptorSets
= MAX_SETS
,
687 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
688 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
689 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
690 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
691 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
692 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
693 .maxPerStageResources
= max_descriptor_set_size
,
694 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
695 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
696 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
697 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
698 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
699 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
700 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
701 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
702 .maxVertexInputAttributes
= 32,
703 .maxVertexInputBindings
= 32,
704 .maxVertexInputAttributeOffset
= 2047,
705 .maxVertexInputBindingStride
= 2048,
706 .maxVertexOutputComponents
= 128,
707 .maxTessellationGenerationLevel
= 64,
708 .maxTessellationPatchSize
= 32,
709 .maxTessellationControlPerVertexInputComponents
= 128,
710 .maxTessellationControlPerVertexOutputComponents
= 128,
711 .maxTessellationControlPerPatchOutputComponents
= 120,
712 .maxTessellationControlTotalOutputComponents
= 4096,
713 .maxTessellationEvaluationInputComponents
= 128,
714 .maxTessellationEvaluationOutputComponents
= 128,
715 .maxGeometryShaderInvocations
= 127,
716 .maxGeometryInputComponents
= 64,
717 .maxGeometryOutputComponents
= 128,
718 .maxGeometryOutputVertices
= 256,
719 .maxGeometryTotalOutputComponents
= 1024,
720 .maxFragmentInputComponents
= 128,
721 .maxFragmentOutputAttachments
= 8,
722 .maxFragmentDualSrcAttachments
= 1,
723 .maxFragmentCombinedOutputResources
= 8,
724 .maxComputeSharedMemorySize
= 32768,
725 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
726 .maxComputeWorkGroupInvocations
= 2048,
727 .maxComputeWorkGroupSize
= {
732 .subPixelPrecisionBits
= 4 /* FIXME */,
733 .subTexelPrecisionBits
= 4 /* FIXME */,
734 .mipmapPrecisionBits
= 4 /* FIXME */,
735 .maxDrawIndexedIndexValue
= UINT32_MAX
,
736 .maxDrawIndirectCount
= UINT32_MAX
,
737 .maxSamplerLodBias
= 16,
738 .maxSamplerAnisotropy
= 16,
739 .maxViewports
= MAX_VIEWPORTS
,
740 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
741 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
742 .viewportSubPixelBits
= 13, /* We take a float? */
743 .minMemoryMapAlignment
= 4096, /* A page */
744 .minTexelBufferOffsetAlignment
= 1,
745 .minUniformBufferOffsetAlignment
= 4,
746 .minStorageBufferOffsetAlignment
= 4,
747 .minTexelOffset
= -32,
748 .maxTexelOffset
= 31,
749 .minTexelGatherOffset
= -32,
750 .maxTexelGatherOffset
= 31,
751 .minInterpolationOffset
= -2,
752 .maxInterpolationOffset
= 2,
753 .subPixelInterpolationOffsetBits
= 8,
754 .maxFramebufferWidth
= (1 << 14),
755 .maxFramebufferHeight
= (1 << 14),
756 .maxFramebufferLayers
= (1 << 10),
757 .framebufferColorSampleCounts
= sample_counts
,
758 .framebufferDepthSampleCounts
= sample_counts
,
759 .framebufferStencilSampleCounts
= sample_counts
,
760 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
761 .maxColorAttachments
= MAX_RTS
,
762 .sampledImageColorSampleCounts
= sample_counts
,
763 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
764 .sampledImageDepthSampleCounts
= sample_counts
,
765 .sampledImageStencilSampleCounts
= sample_counts
,
766 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
767 .maxSampleMaskWords
= 1,
768 .timestampComputeAndGraphics
= true,
769 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
770 .maxClipDistances
= 8,
771 .maxCullDistances
= 8,
772 .maxCombinedClipAndCullDistances
= 8,
773 .discreteQueuePriorities
= 1,
774 .pointSizeRange
= { 0.125, 255.875 },
775 .lineWidthRange
= { 0.0, 7.9921875 },
776 .pointSizeGranularity
= (1.0 / 8.0),
777 .lineWidthGranularity
= (1.0 / 128.0),
778 .strictLines
= false, /* FINISHME */
779 .standardSampleLocations
= true,
780 .optimalBufferCopyOffsetAlignment
= 128,
781 .optimalBufferCopyRowPitchAlignment
= 128,
782 .nonCoherentAtomSize
= 64,
785 *pProperties
= (VkPhysicalDeviceProperties
) {
786 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
787 .driverVersion
= vk_get_driver_version(),
789 .deviceID
= pdevice
->rad_info
.pci_id
,
790 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
792 .sparseProperties
= {0},
795 strcpy(pProperties
->deviceName
, pdevice
->name
);
796 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
799 void radv_GetPhysicalDeviceProperties2KHR(
800 VkPhysicalDevice physicalDevice
,
801 VkPhysicalDeviceProperties2KHR
*pProperties
)
803 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
804 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
806 vk_foreach_struct(ext
, pProperties
->pNext
) {
807 switch (ext
->sType
) {
808 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
809 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
810 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
811 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
814 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
815 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
816 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
817 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
818 properties
->deviceLUIDValid
= false;
821 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
822 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
823 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
824 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
833 static void radv_get_physical_device_queue_family_properties(
834 struct radv_physical_device
* pdevice
,
836 VkQueueFamilyProperties
** pQueueFamilyProperties
)
838 int num_queue_families
= 1;
840 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
841 pdevice
->rad_info
.chip_class
>= CIK
&&
842 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
843 num_queue_families
++;
845 if (pQueueFamilyProperties
== NULL
) {
846 *pCount
= num_queue_families
;
855 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
856 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
857 VK_QUEUE_COMPUTE_BIT
|
858 VK_QUEUE_TRANSFER_BIT
|
859 VK_QUEUE_SPARSE_BINDING_BIT
,
861 .timestampValidBits
= 64,
862 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
867 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
868 pdevice
->rad_info
.chip_class
>= CIK
&&
869 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
871 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
872 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
873 VK_QUEUE_TRANSFER_BIT
|
874 VK_QUEUE_SPARSE_BINDING_BIT
,
875 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
876 .timestampValidBits
= 64,
877 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
885 void radv_GetPhysicalDeviceQueueFamilyProperties(
886 VkPhysicalDevice physicalDevice
,
888 VkQueueFamilyProperties
* pQueueFamilyProperties
)
890 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
891 if (!pQueueFamilyProperties
) {
892 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
895 VkQueueFamilyProperties
*properties
[] = {
896 pQueueFamilyProperties
+ 0,
897 pQueueFamilyProperties
+ 1,
898 pQueueFamilyProperties
+ 2,
900 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
901 assert(*pCount
<= 3);
904 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
905 VkPhysicalDevice physicalDevice
,
907 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
909 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
910 if (!pQueueFamilyProperties
) {
911 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
914 VkQueueFamilyProperties
*properties
[] = {
915 &pQueueFamilyProperties
[0].queueFamilyProperties
,
916 &pQueueFamilyProperties
[1].queueFamilyProperties
,
917 &pQueueFamilyProperties
[2].queueFamilyProperties
,
919 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
920 assert(*pCount
<= 3);
923 void radv_GetPhysicalDeviceMemoryProperties(
924 VkPhysicalDevice physicalDevice
,
925 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
927 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
929 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
931 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
932 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
933 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
934 .heapIndex
= RADV_MEM_HEAP_VRAM
,
936 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
937 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
938 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
939 .heapIndex
= RADV_MEM_HEAP_GTT
,
941 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
942 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
943 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
944 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
945 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
947 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
948 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
949 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
950 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
951 .heapIndex
= RADV_MEM_HEAP_GTT
,
954 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
955 uint64_t visible_vram_size
= MIN2(physical_device
->rad_info
.vram_size
,
956 physical_device
->rad_info
.vram_vis_size
);
958 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
959 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
960 .size
= physical_device
->rad_info
.vram_size
-
962 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
964 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
965 .size
= visible_vram_size
,
966 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
968 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
969 .size
= physical_device
->rad_info
.gart_size
,
974 void radv_GetPhysicalDeviceMemoryProperties2KHR(
975 VkPhysicalDevice physicalDevice
,
976 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
978 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
979 &pMemoryProperties
->memoryProperties
);
983 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
984 int queue_family_index
, int idx
)
986 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
987 queue
->device
= device
;
988 queue
->queue_family_index
= queue_family_index
;
989 queue
->queue_idx
= idx
;
991 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
993 return VK_ERROR_OUT_OF_HOST_MEMORY
;
999 radv_queue_finish(struct radv_queue
*queue
)
1002 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1004 if (queue
->initial_full_flush_preamble_cs
)
1005 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1006 if (queue
->initial_preamble_cs
)
1007 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1008 if (queue
->continue_preamble_cs
)
1009 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1010 if (queue
->descriptor_bo
)
1011 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1012 if (queue
->scratch_bo
)
1013 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1014 if (queue
->esgs_ring_bo
)
1015 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1016 if (queue
->gsvs_ring_bo
)
1017 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1018 if (queue
->tess_factor_ring_bo
)
1019 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
1020 if (queue
->tess_offchip_ring_bo
)
1021 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
1022 if (queue
->compute_scratch_bo
)
1023 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1027 radv_device_init_gs_info(struct radv_device
*device
)
1029 switch (device
->physical_device
->rad_info
.family
) {
1038 device
->gs_table_depth
= 16;
1047 case CHIP_POLARIS10
:
1048 case CHIP_POLARIS11
:
1049 case CHIP_POLARIS12
:
1052 device
->gs_table_depth
= 32;
1055 unreachable("unknown GPU");
1059 VkResult
radv_CreateDevice(
1060 VkPhysicalDevice physicalDevice
,
1061 const VkDeviceCreateInfo
* pCreateInfo
,
1062 const VkAllocationCallbacks
* pAllocator
,
1065 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1067 struct radv_device
*device
;
1069 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1070 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
1071 physical_device
->extensions
.num_ext
,
1072 pCreateInfo
->ppEnabledExtensionNames
[i
]))
1073 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1076 /* Check enabled features */
1077 if (pCreateInfo
->pEnabledFeatures
) {
1078 VkPhysicalDeviceFeatures supported_features
;
1079 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1080 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1081 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1082 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1083 for (uint32_t i
= 0; i
< num_features
; i
++) {
1084 if (enabled_feature
[i
] && !supported_feature
[i
])
1085 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1089 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1091 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1093 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1095 memset(device
, 0, sizeof(*device
));
1097 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1098 device
->instance
= physical_device
->instance
;
1099 device
->physical_device
= physical_device
;
1101 device
->debug_flags
= device
->instance
->debug_flags
;
1103 device
->ws
= physical_device
->ws
;
1105 device
->alloc
= *pAllocator
;
1107 device
->alloc
= physical_device
->instance
->alloc
;
1109 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1110 list_inithead(&device
->shader_slabs
);
1112 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1113 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1114 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1116 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1117 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1118 if (!device
->queues
[qfi
]) {
1119 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1123 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1125 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1127 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1128 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
1129 if (result
!= VK_SUCCESS
)
1134 #if HAVE_LLVM < 0x0400
1135 device
->llvm_supports_spill
= false;
1137 device
->llvm_supports_spill
= true;
1140 /* The maximum number of scratch waves. Scratch space isn't divided
1141 * evenly between CUs. The number is only a function of the number of CUs.
1142 * We can decrease the constant to decrease the scratch buffer size.
1144 * sctx->scratch_waves must be >= the maximum posible size of
1145 * 1 threadgroup, so that the hw doesn't hang from being unable
1148 * The recommended value is 4 per CU at most. Higher numbers don't
1149 * bring much benefit, but they still occupy chip resources (think
1150 * async compute). I've seen ~2% performance difference between 4 and 32.
1152 uint32_t max_threads_per_block
= 2048;
1153 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1154 max_threads_per_block
/ 64);
1156 radv_device_init_gs_info(device
);
1158 device
->tess_offchip_block_dw_size
=
1159 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1160 device
->has_distributed_tess
=
1161 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1162 device
->physical_device
->rad_info
.max_se
>= 2;
1164 result
= radv_device_init_meta(device
);
1165 if (result
!= VK_SUCCESS
)
1168 radv_device_init_msaa(device
);
1170 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1171 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1173 case RADV_QUEUE_GENERAL
:
1174 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1175 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1176 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1178 case RADV_QUEUE_COMPUTE
:
1179 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1180 radeon_emit(device
->empty_cs
[family
], 0);
1183 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1186 if (getenv("RADV_TRACE_FILE")) {
1187 if (!radv_init_trace(device
))
1191 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1192 cik_create_gfx_config(device
);
1194 VkPipelineCacheCreateInfo ci
;
1195 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1198 ci
.pInitialData
= NULL
;
1199 ci
.initialDataSize
= 0;
1201 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1203 if (result
!= VK_SUCCESS
)
1206 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1208 *pDevice
= radv_device_to_handle(device
);
1212 if (device
->trace_bo
)
1213 device
->ws
->buffer_destroy(device
->trace_bo
);
1215 if (device
->gfx_init
)
1216 device
->ws
->buffer_destroy(device
->gfx_init
);
1218 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1219 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1220 radv_queue_finish(&device
->queues
[i
][q
]);
1221 if (device
->queue_count
[i
])
1222 vk_free(&device
->alloc
, device
->queues
[i
]);
1225 vk_free(&device
->alloc
, device
);
1229 void radv_DestroyDevice(
1231 const VkAllocationCallbacks
* pAllocator
)
1233 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1238 if (device
->trace_bo
)
1239 device
->ws
->buffer_destroy(device
->trace_bo
);
1241 if (device
->gfx_init
)
1242 device
->ws
->buffer_destroy(device
->gfx_init
);
1244 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1245 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1246 radv_queue_finish(&device
->queues
[i
][q
]);
1247 if (device
->queue_count
[i
])
1248 vk_free(&device
->alloc
, device
->queues
[i
]);
1249 if (device
->empty_cs
[i
])
1250 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1252 radv_device_finish_meta(device
);
1254 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1255 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1257 radv_destroy_shader_slabs(device
);
1259 vk_free(&device
->alloc
, device
);
1262 VkResult
radv_EnumerateInstanceExtensionProperties(
1263 const char* pLayerName
,
1264 uint32_t* pPropertyCount
,
1265 VkExtensionProperties
* pProperties
)
1267 if (pProperties
== NULL
) {
1268 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1272 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1273 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1275 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1276 return VK_INCOMPLETE
;
1281 VkResult
radv_EnumerateDeviceExtensionProperties(
1282 VkPhysicalDevice physicalDevice
,
1283 const char* pLayerName
,
1284 uint32_t* pPropertyCount
,
1285 VkExtensionProperties
* pProperties
)
1287 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1289 if (pProperties
== NULL
) {
1290 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1294 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1295 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1297 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1298 return VK_INCOMPLETE
;
1303 VkResult
radv_EnumerateInstanceLayerProperties(
1304 uint32_t* pPropertyCount
,
1305 VkLayerProperties
* pProperties
)
1307 if (pProperties
== NULL
) {
1308 *pPropertyCount
= 0;
1312 /* None supported at this time */
1313 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1316 VkResult
radv_EnumerateDeviceLayerProperties(
1317 VkPhysicalDevice physicalDevice
,
1318 uint32_t* pPropertyCount
,
1319 VkLayerProperties
* pProperties
)
1321 if (pProperties
== NULL
) {
1322 *pPropertyCount
= 0;
1326 /* None supported at this time */
1327 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1330 void radv_GetDeviceQueue(
1332 uint32_t queueFamilyIndex
,
1333 uint32_t queueIndex
,
1336 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1338 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1342 fill_geom_tess_rings(struct radv_queue
*queue
,
1344 bool add_sample_positions
,
1345 uint32_t esgs_ring_size
,
1346 struct radeon_winsys_bo
*esgs_ring_bo
,
1347 uint32_t gsvs_ring_size
,
1348 struct radeon_winsys_bo
*gsvs_ring_bo
,
1349 uint32_t tess_factor_ring_size
,
1350 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1351 uint32_t tess_offchip_ring_size
,
1352 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1354 uint64_t esgs_va
= 0, gsvs_va
= 0;
1355 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1356 uint32_t *desc
= &map
[4];
1359 esgs_va
= queue
->device
->ws
->buffer_get_va(esgs_ring_bo
);
1361 gsvs_va
= queue
->device
->ws
->buffer_get_va(gsvs_ring_bo
);
1362 if (tess_factor_ring_bo
)
1363 tess_factor_va
= queue
->device
->ws
->buffer_get_va(tess_factor_ring_bo
);
1364 if (tess_offchip_ring_bo
)
1365 tess_offchip_va
= queue
->device
->ws
->buffer_get_va(tess_offchip_ring_bo
);
1367 /* stride 0, num records - size, add tid, swizzle, elsize4,
1370 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1371 S_008F04_STRIDE(0) |
1372 S_008F04_SWIZZLE_ENABLE(true);
1373 desc
[2] = esgs_ring_size
;
1374 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1375 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1376 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1377 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1378 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1379 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1380 S_008F0C_ELEMENT_SIZE(1) |
1381 S_008F0C_INDEX_STRIDE(3) |
1382 S_008F0C_ADD_TID_ENABLE(true);
1385 /* GS entry for ES->GS ring */
1386 /* stride 0, num records - size, elsize0,
1389 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1390 S_008F04_STRIDE(0) |
1391 S_008F04_SWIZZLE_ENABLE(false);
1392 desc
[2] = esgs_ring_size
;
1393 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1394 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1395 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1396 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1397 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1398 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1399 S_008F0C_ELEMENT_SIZE(0) |
1400 S_008F0C_INDEX_STRIDE(0) |
1401 S_008F0C_ADD_TID_ENABLE(false);
1404 /* VS entry for GS->VS ring */
1405 /* stride 0, num records - size, elsize0,
1408 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1409 S_008F04_STRIDE(0) |
1410 S_008F04_SWIZZLE_ENABLE(false);
1411 desc
[2] = gsvs_ring_size
;
1412 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1413 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1414 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1415 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1416 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1417 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1418 S_008F0C_ELEMENT_SIZE(0) |
1419 S_008F0C_INDEX_STRIDE(0) |
1420 S_008F0C_ADD_TID_ENABLE(false);
1423 /* stride gsvs_itemsize, num records 64
1424 elsize 4, index stride 16 */
1425 /* shader will patch stride and desc[2] */
1427 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1428 S_008F04_STRIDE(0) |
1429 S_008F04_SWIZZLE_ENABLE(true);
1431 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1432 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1433 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1434 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1435 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1436 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1437 S_008F0C_ELEMENT_SIZE(1) |
1438 S_008F0C_INDEX_STRIDE(1) |
1439 S_008F0C_ADD_TID_ENABLE(true);
1442 desc
[0] = tess_factor_va
;
1443 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1444 S_008F04_STRIDE(0) |
1445 S_008F04_SWIZZLE_ENABLE(false);
1446 desc
[2] = tess_factor_ring_size
;
1447 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1448 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1449 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1450 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1451 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1452 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1453 S_008F0C_ELEMENT_SIZE(0) |
1454 S_008F0C_INDEX_STRIDE(0) |
1455 S_008F0C_ADD_TID_ENABLE(false);
1458 desc
[0] = tess_offchip_va
;
1459 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1460 S_008F04_STRIDE(0) |
1461 S_008F04_SWIZZLE_ENABLE(false);
1462 desc
[2] = tess_offchip_ring_size
;
1463 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1464 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1465 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1466 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1467 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1468 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1469 S_008F0C_ELEMENT_SIZE(0) |
1470 S_008F0C_INDEX_STRIDE(0) |
1471 S_008F0C_ADD_TID_ENABLE(false);
1474 /* add sample positions after all rings */
1475 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1477 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1479 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1481 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1483 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1487 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1489 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1490 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1491 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1492 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1493 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1494 device
->physical_device
->rad_info
.max_se
;
1495 unsigned offchip_granularity
;
1496 unsigned hs_offchip_param
;
1497 switch (device
->tess_offchip_block_dw_size
) {
1502 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1505 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1509 switch (device
->physical_device
->rad_info
.chip_class
) {
1511 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1517 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1521 *max_offchip_buffers_p
= max_offchip_buffers
;
1522 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1523 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1524 --max_offchip_buffers
;
1526 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1527 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1530 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1532 return hs_offchip_param
;
1536 radv_get_preamble_cs(struct radv_queue
*queue
,
1537 uint32_t scratch_size
,
1538 uint32_t compute_scratch_size
,
1539 uint32_t esgs_ring_size
,
1540 uint32_t gsvs_ring_size
,
1541 bool needs_tess_rings
,
1542 bool needs_sample_positions
,
1543 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1544 struct radeon_winsys_cs
**initial_preamble_cs
,
1545 struct radeon_winsys_cs
**continue_preamble_cs
)
1547 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1548 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1549 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1550 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1551 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1552 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1553 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1554 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1555 bool add_tess_rings
= false, add_sample_positions
= false;
1556 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1557 unsigned max_offchip_buffers
;
1558 unsigned hs_offchip_param
= 0;
1559 if (!queue
->has_tess_rings
) {
1560 if (needs_tess_rings
)
1561 add_tess_rings
= true;
1563 if (!queue
->has_sample_positions
) {
1564 if (needs_sample_positions
)
1565 add_sample_positions
= true;
1567 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1568 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1569 &max_offchip_buffers
);
1570 tess_offchip_ring_size
= max_offchip_buffers
*
1571 queue
->device
->tess_offchip_block_dw_size
* 4;
1573 if (scratch_size
<= queue
->scratch_size
&&
1574 compute_scratch_size
<= queue
->compute_scratch_size
&&
1575 esgs_ring_size
<= queue
->esgs_ring_size
&&
1576 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1577 !add_tess_rings
&& !add_sample_positions
&&
1578 queue
->initial_preamble_cs
) {
1579 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1580 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1581 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1582 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1583 *continue_preamble_cs
= NULL
;
1587 if (scratch_size
> queue
->scratch_size
) {
1588 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1592 RADEON_FLAG_NO_CPU_ACCESS
);
1596 scratch_bo
= queue
->scratch_bo
;
1598 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1599 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1600 compute_scratch_size
,
1603 RADEON_FLAG_NO_CPU_ACCESS
);
1604 if (!compute_scratch_bo
)
1608 compute_scratch_bo
= queue
->compute_scratch_bo
;
1610 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1611 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1615 RADEON_FLAG_NO_CPU_ACCESS
);
1619 esgs_ring_bo
= queue
->esgs_ring_bo
;
1620 esgs_ring_size
= queue
->esgs_ring_size
;
1623 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1624 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1628 RADEON_FLAG_NO_CPU_ACCESS
);
1632 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1633 gsvs_ring_size
= queue
->gsvs_ring_size
;
1636 if (add_tess_rings
) {
1637 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1638 tess_factor_ring_size
,
1641 RADEON_FLAG_NO_CPU_ACCESS
);
1642 if (!tess_factor_ring_bo
)
1644 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1645 tess_offchip_ring_size
,
1648 RADEON_FLAG_NO_CPU_ACCESS
);
1649 if (!tess_offchip_ring_bo
)
1652 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1653 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1656 if (scratch_bo
!= queue
->scratch_bo
||
1657 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1658 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1659 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1660 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1662 if (gsvs_ring_bo
|| esgs_ring_bo
||
1663 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1664 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1665 if (add_sample_positions
)
1666 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1668 else if (scratch_bo
)
1669 size
= 8; /* 2 dword */
1671 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1675 RADEON_FLAG_CPU_ACCESS
);
1679 descriptor_bo
= queue
->descriptor_bo
;
1681 for(int i
= 0; i
< 3; ++i
) {
1682 struct radeon_winsys_cs
*cs
= NULL
;
1683 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1684 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1691 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1694 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1697 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1699 if (tess_factor_ring_bo
)
1700 queue
->device
->ws
->cs_add_buffer(cs
, tess_factor_ring_bo
, 8);
1702 if (tess_offchip_ring_bo
)
1703 queue
->device
->ws
->cs_add_buffer(cs
, tess_offchip_ring_bo
, 8);
1706 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1708 if (descriptor_bo
!= queue
->descriptor_bo
) {
1709 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1712 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(scratch_bo
);
1713 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1714 S_008F04_SWIZZLE_ENABLE(1);
1715 map
[0] = scratch_va
;
1719 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1720 add_sample_positions
)
1721 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1722 esgs_ring_size
, esgs_ring_bo
,
1723 gsvs_ring_size
, gsvs_ring_bo
,
1724 tess_factor_ring_size
, tess_factor_ring_bo
,
1725 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1727 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1730 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1731 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1732 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1733 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1734 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1737 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1738 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1739 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1740 radeon_emit(cs
, esgs_ring_size
>> 8);
1741 radeon_emit(cs
, gsvs_ring_size
>> 8);
1743 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1744 radeon_emit(cs
, esgs_ring_size
>> 8);
1745 radeon_emit(cs
, gsvs_ring_size
>> 8);
1749 if (tess_factor_ring_bo
) {
1750 uint64_t tf_va
= queue
->device
->ws
->buffer_get_va(tess_factor_ring_bo
);
1751 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1752 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1753 S_030938_SIZE(tess_factor_ring_size
/ 4));
1754 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1756 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1757 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1760 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1762 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1763 S_008988_SIZE(tess_factor_ring_size
/ 4));
1764 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1766 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1771 if (descriptor_bo
) {
1772 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1773 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1774 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1775 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1776 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1777 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1779 uint64_t va
= queue
->device
->ws
->buffer_get_va(descriptor_bo
);
1781 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1782 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1783 radeon_emit(cs
, va
);
1784 radeon_emit(cs
, va
>> 32);
1788 if (compute_scratch_bo
) {
1789 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(compute_scratch_bo
);
1790 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1791 S_008F04_SWIZZLE_ENABLE(1);
1793 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1795 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1796 radeon_emit(cs
, scratch_va
);
1797 radeon_emit(cs
, rsrc1
);
1801 si_cs_emit_cache_flush(cs
,
1803 queue
->device
->physical_device
->rad_info
.chip_class
,
1805 queue
->queue_family_index
== RING_COMPUTE
&&
1806 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1807 (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
)) |
1808 RADV_CMD_FLAG_INV_ICACHE
|
1809 RADV_CMD_FLAG_INV_SMEM_L1
|
1810 RADV_CMD_FLAG_INV_VMEM_L1
|
1811 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1812 } else if (i
== 1) {
1813 si_cs_emit_cache_flush(cs
,
1815 queue
->device
->physical_device
->rad_info
.chip_class
,
1817 queue
->queue_family_index
== RING_COMPUTE
&&
1818 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1819 RADV_CMD_FLAG_INV_ICACHE
|
1820 RADV_CMD_FLAG_INV_SMEM_L1
|
1821 RADV_CMD_FLAG_INV_VMEM_L1
|
1822 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1825 if (!queue
->device
->ws
->cs_finalize(cs
))
1829 if (queue
->initial_full_flush_preamble_cs
)
1830 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1832 if (queue
->initial_preamble_cs
)
1833 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1835 if (queue
->continue_preamble_cs
)
1836 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1838 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1839 queue
->initial_preamble_cs
= dest_cs
[1];
1840 queue
->continue_preamble_cs
= dest_cs
[2];
1842 if (scratch_bo
!= queue
->scratch_bo
) {
1843 if (queue
->scratch_bo
)
1844 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1845 queue
->scratch_bo
= scratch_bo
;
1846 queue
->scratch_size
= scratch_size
;
1849 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1850 if (queue
->compute_scratch_bo
)
1851 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1852 queue
->compute_scratch_bo
= compute_scratch_bo
;
1853 queue
->compute_scratch_size
= compute_scratch_size
;
1856 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1857 if (queue
->esgs_ring_bo
)
1858 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1859 queue
->esgs_ring_bo
= esgs_ring_bo
;
1860 queue
->esgs_ring_size
= esgs_ring_size
;
1863 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1864 if (queue
->gsvs_ring_bo
)
1865 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1866 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1867 queue
->gsvs_ring_size
= gsvs_ring_size
;
1870 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1871 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1874 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1875 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1876 queue
->has_tess_rings
= true;
1879 if (descriptor_bo
!= queue
->descriptor_bo
) {
1880 if (queue
->descriptor_bo
)
1881 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1883 queue
->descriptor_bo
= descriptor_bo
;
1886 if (add_sample_positions
)
1887 queue
->has_sample_positions
= true;
1889 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1890 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1891 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1892 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1893 *continue_preamble_cs
= NULL
;
1896 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1898 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1899 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1900 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1901 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1902 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1903 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1904 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1905 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1906 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1907 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1908 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1909 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1910 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1911 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1912 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1913 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1916 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1918 const VkSemaphore
*sems
,
1921 int syncobj_idx
= 0, sem_idx
= 0;
1925 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1926 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1928 if (sem
->temp_syncobj
|| sem
->syncobj
)
1929 counts
->syncobj_count
++;
1931 counts
->sem_count
++;
1934 if (counts
->syncobj_count
) {
1935 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
1936 if (!counts
->syncobj
)
1937 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1940 if (counts
->sem_count
) {
1941 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
1943 free(counts
->syncobj
);
1944 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1948 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1949 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1951 if (sem
->temp_syncobj
) {
1952 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
1954 /* after we wait on a temp import - drop it */
1955 sem
->temp_syncobj
= 0;
1958 else if (sem
->syncobj
)
1959 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
1962 counts
->sem
[sem_idx
++] = sem
->sem
;
1969 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
1971 free(sem_info
->wait
.syncobj
);
1972 free(sem_info
->wait
.sem
);
1973 free(sem_info
->signal
.syncobj
);
1974 free(sem_info
->signal
.sem
);
1977 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
1979 const VkSemaphore
*wait_sems
,
1980 int num_signal_sems
,
1981 const VkSemaphore
*signal_sems
)
1984 memset(sem_info
, 0, sizeof(*sem_info
));
1986 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, true);
1989 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, false);
1991 radv_free_sem_info(sem_info
);
1993 /* caller can override these */
1994 sem_info
->cs_emit_wait
= true;
1995 sem_info
->cs_emit_signal
= true;
1999 VkResult
radv_QueueSubmit(
2001 uint32_t submitCount
,
2002 const VkSubmitInfo
* pSubmits
,
2005 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2006 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2007 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2008 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2010 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2011 uint32_t scratch_size
= 0;
2012 uint32_t compute_scratch_size
= 0;
2013 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2014 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2016 bool fence_emitted
= false;
2017 bool tess_rings_needed
= false;
2018 bool sample_positions_needed
= false;
2020 /* Do this first so failing to allocate scratch buffers can't result in
2021 * partially executed submissions. */
2022 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2023 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2024 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2025 pSubmits
[i
].pCommandBuffers
[j
]);
2027 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2028 compute_scratch_size
= MAX2(compute_scratch_size
,
2029 cmd_buffer
->compute_scratch_size_needed
);
2030 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2031 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2032 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2033 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2037 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2038 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2039 sample_positions_needed
, &initial_flush_preamble_cs
,
2040 &initial_preamble_cs
, &continue_preamble_cs
);
2041 if (result
!= VK_SUCCESS
)
2044 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2045 struct radeon_winsys_cs
**cs_array
;
2046 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2047 bool can_patch
= true;
2049 struct radv_winsys_sem_info sem_info
;
2051 result
= radv_alloc_sem_info(&sem_info
,
2052 pSubmits
[i
].waitSemaphoreCount
,
2053 pSubmits
[i
].pWaitSemaphores
,
2054 pSubmits
[i
].signalSemaphoreCount
,
2055 pSubmits
[i
].pSignalSemaphores
);
2056 if (result
!= VK_SUCCESS
)
2059 if (!pSubmits
[i
].commandBufferCount
) {
2060 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2061 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2062 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2067 radv_loge("failed to submit CS %d\n", i
);
2070 fence_emitted
= true;
2072 radv_free_sem_info(&sem_info
);
2076 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2077 (pSubmits
[i
].commandBufferCount
));
2079 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2080 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2081 pSubmits
[i
].pCommandBuffers
[j
]);
2082 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2084 cs_array
[j
] = cmd_buffer
->cs
;
2085 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2089 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2090 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2091 advance
= MIN2(max_cs_submission
,
2092 pSubmits
[i
].commandBufferCount
- j
);
2094 if (queue
->device
->trace_bo
)
2095 *queue
->device
->trace_id_ptr
= 0;
2097 sem_info
.cs_emit_wait
= j
== 0;
2098 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2100 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2101 advance
, initial_preamble
, continue_preamble_cs
,
2103 can_patch
, base_fence
);
2106 radv_loge("failed to submit CS %d\n", i
);
2109 fence_emitted
= true;
2110 if (queue
->device
->trace_bo
) {
2111 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2115 radv_free_sem_info(&sem_info
);
2120 if (!fence_emitted
) {
2121 struct radv_winsys_sem_info sem_info
= {0};
2122 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2123 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2124 1, NULL
, NULL
, &sem_info
,
2127 fence
->submitted
= true;
2133 VkResult
radv_QueueWaitIdle(
2136 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2138 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2139 radv_queue_family_to_ring(queue
->queue_family_index
),
2144 VkResult
radv_DeviceWaitIdle(
2147 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2149 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2150 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2151 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2157 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2158 VkInstance instance
,
2161 return radv_lookup_entrypoint(pName
);
2164 /* The loader wants us to expose a second GetInstanceProcAddr function
2165 * to work around certain LD_PRELOAD issues seen in apps.
2168 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2169 VkInstance instance
,
2173 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2174 VkInstance instance
,
2177 return radv_GetInstanceProcAddr(instance
, pName
);
2180 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2184 return radv_lookup_entrypoint(pName
);
2187 bool radv_get_memory_fd(struct radv_device
*device
,
2188 struct radv_device_memory
*memory
,
2191 struct radeon_bo_metadata metadata
;
2193 if (memory
->image
) {
2194 radv_init_metadata(device
, memory
->image
, &metadata
);
2195 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2198 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2202 VkResult
radv_AllocateMemory(
2204 const VkMemoryAllocateInfo
* pAllocateInfo
,
2205 const VkAllocationCallbacks
* pAllocator
,
2206 VkDeviceMemory
* pMem
)
2208 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2209 struct radv_device_memory
*mem
;
2211 enum radeon_bo_domain domain
;
2214 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2216 if (pAllocateInfo
->allocationSize
== 0) {
2217 /* Apparently, this is allowed */
2218 *pMem
= VK_NULL_HANDLE
;
2222 const VkImportMemoryFdInfoKHR
*import_info
=
2223 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2224 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2225 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2227 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2228 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2230 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2232 if (dedicate_info
) {
2233 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2234 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2241 assert(import_info
->handleType
==
2242 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2243 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2246 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2249 close(import_info
->fd
);
2254 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2255 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2256 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
2257 domain
= RADEON_DOMAIN_GTT
;
2259 domain
= RADEON_DOMAIN_VRAM
;
2261 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
2262 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2264 flags
|= RADEON_FLAG_CPU_ACCESS
;
2266 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2267 flags
|= RADEON_FLAG_GTT_WC
;
2269 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2273 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2276 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
2278 *pMem
= radv_device_memory_to_handle(mem
);
2283 vk_free2(&device
->alloc
, pAllocator
, mem
);
2288 void radv_FreeMemory(
2290 VkDeviceMemory _mem
,
2291 const VkAllocationCallbacks
* pAllocator
)
2293 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2294 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2299 device
->ws
->buffer_destroy(mem
->bo
);
2302 vk_free2(&device
->alloc
, pAllocator
, mem
);
2305 VkResult
radv_MapMemory(
2307 VkDeviceMemory _memory
,
2308 VkDeviceSize offset
,
2310 VkMemoryMapFlags flags
,
2313 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2314 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2321 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2327 return VK_ERROR_MEMORY_MAP_FAILED
;
2330 void radv_UnmapMemory(
2332 VkDeviceMemory _memory
)
2334 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2335 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2340 device
->ws
->buffer_unmap(mem
->bo
);
2343 VkResult
radv_FlushMappedMemoryRanges(
2345 uint32_t memoryRangeCount
,
2346 const VkMappedMemoryRange
* pMemoryRanges
)
2351 VkResult
radv_InvalidateMappedMemoryRanges(
2353 uint32_t memoryRangeCount
,
2354 const VkMappedMemoryRange
* pMemoryRanges
)
2359 void radv_GetBufferMemoryRequirements(
2362 VkMemoryRequirements
* pMemoryRequirements
)
2364 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2366 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2368 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2369 pMemoryRequirements
->alignment
= 4096;
2371 pMemoryRequirements
->alignment
= 16;
2373 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2376 void radv_GetBufferMemoryRequirements2KHR(
2378 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2379 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2381 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2382 &pMemoryRequirements
->memoryRequirements
);
2384 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2385 switch (ext
->sType
) {
2386 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2387 VkMemoryDedicatedRequirementsKHR
*req
=
2388 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2389 req
->requiresDedicatedAllocation
= false;
2390 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2399 void radv_GetImageMemoryRequirements(
2402 VkMemoryRequirements
* pMemoryRequirements
)
2404 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2406 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 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_BindBufferMemory(
2466 VkDeviceMemory _memory
,
2467 VkDeviceSize memoryOffset
)
2469 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2470 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2473 buffer
->bo
= mem
->bo
;
2474 buffer
->offset
= memoryOffset
;
2483 VkResult
radv_BindImageMemory(
2486 VkDeviceMemory _memory
,
2487 VkDeviceSize memoryOffset
)
2489 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2490 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2493 image
->bo
= mem
->bo
;
2494 image
->offset
= memoryOffset
;
2505 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2506 const VkSparseBufferMemoryBindInfo
*bind
)
2508 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2510 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2511 struct radv_device_memory
*mem
= NULL
;
2513 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2514 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2516 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2517 bind
->pBinds
[i
].resourceOffset
,
2518 bind
->pBinds
[i
].size
,
2519 mem
? mem
->bo
: NULL
,
2520 bind
->pBinds
[i
].memoryOffset
);
2525 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2526 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2528 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2530 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2531 struct radv_device_memory
*mem
= NULL
;
2533 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2534 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2536 device
->ws
->buffer_virtual_bind(image
->bo
,
2537 bind
->pBinds
[i
].resourceOffset
,
2538 bind
->pBinds
[i
].size
,
2539 mem
? mem
->bo
: NULL
,
2540 bind
->pBinds
[i
].memoryOffset
);
2544 VkResult
radv_QueueBindSparse(
2546 uint32_t bindInfoCount
,
2547 const VkBindSparseInfo
* pBindInfo
,
2550 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2551 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2552 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2553 bool fence_emitted
= false;
2555 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2556 struct radv_winsys_sem_info sem_info
;
2557 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2558 radv_sparse_buffer_bind_memory(queue
->device
,
2559 pBindInfo
[i
].pBufferBinds
+ j
);
2562 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2563 radv_sparse_image_opaque_bind_memory(queue
->device
,
2564 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2568 result
= radv_alloc_sem_info(&sem_info
,
2569 pBindInfo
[i
].waitSemaphoreCount
,
2570 pBindInfo
[i
].pWaitSemaphores
,
2571 pBindInfo
[i
].signalSemaphoreCount
,
2572 pBindInfo
[i
].pSignalSemaphores
);
2573 if (result
!= VK_SUCCESS
)
2576 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2577 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2578 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2582 fence_emitted
= true;
2584 fence
->submitted
= true;
2587 radv_free_sem_info(&sem_info
);
2591 if (fence
&& !fence_emitted
) {
2592 fence
->signalled
= true;
2598 VkResult
radv_CreateFence(
2600 const VkFenceCreateInfo
* pCreateInfo
,
2601 const VkAllocationCallbacks
* pAllocator
,
2604 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2605 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2607 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2610 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2612 memset(fence
, 0, sizeof(*fence
));
2613 fence
->submitted
= false;
2614 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2615 fence
->fence
= device
->ws
->create_fence();
2616 if (!fence
->fence
) {
2617 vk_free2(&device
->alloc
, pAllocator
, fence
);
2618 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2621 *pFence
= radv_fence_to_handle(fence
);
2626 void radv_DestroyFence(
2629 const VkAllocationCallbacks
* pAllocator
)
2631 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2632 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2636 device
->ws
->destroy_fence(fence
->fence
);
2637 vk_free2(&device
->alloc
, pAllocator
, fence
);
2640 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2642 uint64_t current_time
;
2645 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2646 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2648 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2650 return current_time
+ timeout
;
2653 VkResult
radv_WaitForFences(
2655 uint32_t fenceCount
,
2656 const VkFence
* pFences
,
2660 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2661 timeout
= radv_get_absolute_timeout(timeout
);
2663 if (!waitAll
&& fenceCount
> 1) {
2664 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2667 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2668 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2669 bool expired
= false;
2671 if (fence
->signalled
)
2674 if (!fence
->submitted
)
2677 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2681 fence
->signalled
= true;
2687 VkResult
radv_ResetFences(VkDevice device
,
2688 uint32_t fenceCount
,
2689 const VkFence
*pFences
)
2691 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2692 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2693 fence
->submitted
= fence
->signalled
= false;
2699 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2701 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2702 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2704 if (fence
->signalled
)
2706 if (!fence
->submitted
)
2707 return VK_NOT_READY
;
2709 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2710 return VK_NOT_READY
;
2716 // Queue semaphore functions
2718 VkResult
radv_CreateSemaphore(
2720 const VkSemaphoreCreateInfo
* pCreateInfo
,
2721 const VkAllocationCallbacks
* pAllocator
,
2722 VkSemaphore
* pSemaphore
)
2724 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2725 const VkExportSemaphoreCreateInfoKHR
*export
=
2726 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2727 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2728 export
? export
->handleTypes
: 0;
2730 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2732 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2734 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2736 sem
->temp_syncobj
= 0;
2737 /* create a syncobject if we are going to export this semaphore */
2739 assert (device
->physical_device
->rad_info
.has_syncobj
);
2740 assert (handleTypes
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2741 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2743 vk_free2(&device
->alloc
, pAllocator
, sem
);
2744 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2748 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2750 vk_free2(&device
->alloc
, pAllocator
, sem
);
2751 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2756 *pSemaphore
= radv_semaphore_to_handle(sem
);
2760 void radv_DestroySemaphore(
2762 VkSemaphore _semaphore
,
2763 const VkAllocationCallbacks
* pAllocator
)
2765 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2766 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2771 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2773 device
->ws
->destroy_sem(sem
->sem
);
2774 vk_free2(&device
->alloc
, pAllocator
, sem
);
2777 VkResult
radv_CreateEvent(
2779 const VkEventCreateInfo
* pCreateInfo
,
2780 const VkAllocationCallbacks
* pAllocator
,
2783 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2784 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2786 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2789 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2791 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2793 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
);
2795 vk_free2(&device
->alloc
, pAllocator
, event
);
2796 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2799 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2801 *pEvent
= radv_event_to_handle(event
);
2806 void radv_DestroyEvent(
2809 const VkAllocationCallbacks
* pAllocator
)
2811 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2812 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2816 device
->ws
->buffer_destroy(event
->bo
);
2817 vk_free2(&device
->alloc
, pAllocator
, event
);
2820 VkResult
radv_GetEventStatus(
2824 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2826 if (*event
->map
== 1)
2827 return VK_EVENT_SET
;
2828 return VK_EVENT_RESET
;
2831 VkResult
radv_SetEvent(
2835 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2841 VkResult
radv_ResetEvent(
2845 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2851 VkResult
radv_CreateBuffer(
2853 const VkBufferCreateInfo
* pCreateInfo
,
2854 const VkAllocationCallbacks
* pAllocator
,
2857 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2858 struct radv_buffer
*buffer
;
2860 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2862 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2863 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2865 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2867 buffer
->size
= pCreateInfo
->size
;
2868 buffer
->usage
= pCreateInfo
->usage
;
2871 buffer
->flags
= pCreateInfo
->flags
;
2873 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2874 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2875 align64(buffer
->size
, 4096),
2876 4096, 0, RADEON_FLAG_VIRTUAL
);
2878 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2879 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2883 *pBuffer
= radv_buffer_to_handle(buffer
);
2888 void radv_DestroyBuffer(
2891 const VkAllocationCallbacks
* pAllocator
)
2893 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2894 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2899 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2900 device
->ws
->buffer_destroy(buffer
->bo
);
2902 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2905 static inline unsigned
2906 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
2909 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
2911 return image
->surface
.u
.legacy
.tiling_index
[level
];
2914 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
2916 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
2920 radv_initialise_color_surface(struct radv_device
*device
,
2921 struct radv_color_buffer_info
*cb
,
2922 struct radv_image_view
*iview
)
2924 const struct vk_format_description
*desc
;
2925 unsigned ntype
, format
, swap
, endian
;
2926 unsigned blend_clamp
= 0, blend_bypass
= 0;
2928 const struct radeon_surf
*surf
= &iview
->image
->surface
;
2930 desc
= vk_format_description(iview
->vk_format
);
2932 memset(cb
, 0, sizeof(*cb
));
2934 /* Intensity is implemented as Red, so treat it that way. */
2935 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
2937 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2939 cb
->cb_color_base
= va
>> 8;
2941 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2942 struct gfx9_surf_meta_flags meta
;
2943 if (iview
->image
->dcc_offset
)
2944 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
2946 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
2948 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
2949 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
2950 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
2951 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
2953 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
2954 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
2956 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
2957 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
2959 cb
->cb_color_base
+= level_info
->offset
>> 8;
2960 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
2961 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
2963 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
2964 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
2965 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
2967 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
2968 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
2969 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
2971 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
2972 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
2974 if (iview
->image
->fmask
.size
) {
2975 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2976 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
2977 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
2978 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
2980 /* This must be set for fast clear to work without FMASK. */
2981 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2982 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
2983 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
2984 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
2988 /* CMASK variables */
2989 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2990 va
+= iview
->image
->cmask
.offset
;
2991 cb
->cb_color_cmask
= va
>> 8;
2993 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2994 va
+= iview
->image
->dcc_offset
;
2995 cb
->cb_dcc_base
= va
>> 8;
2996 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
2998 uint32_t max_slice
= radv_surface_layer_count(iview
);
2999 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3000 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3002 if (iview
->image
->info
.samples
> 1) {
3003 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3005 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3006 S_028C74_NUM_FRAGMENTS(log_samples
);
3009 if (iview
->image
->fmask
.size
) {
3010 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3011 cb
->cb_color_fmask
= va
>> 8;
3012 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3014 cb
->cb_color_fmask
= cb
->cb_color_base
;
3017 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3019 vk_format_get_first_non_void_channel(iview
->vk_format
));
3020 format
= radv_translate_colorformat(iview
->vk_format
);
3021 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3022 radv_finishme("Illegal color\n");
3023 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3024 endian
= radv_colorformat_endian_swap(format
);
3026 /* blend clamp should be set for all NORM/SRGB types */
3027 if (ntype
== V_028C70_NUMBER_UNORM
||
3028 ntype
== V_028C70_NUMBER_SNORM
||
3029 ntype
== V_028C70_NUMBER_SRGB
)
3032 /* set blend bypass according to docs if SINT/UINT or
3033 8/24 COLOR variants */
3034 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3035 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3036 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3041 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3042 (format
== V_028C70_COLOR_8
||
3043 format
== V_028C70_COLOR_8_8
||
3044 format
== V_028C70_COLOR_8_8_8_8
))
3045 ->color_is_int8
= true;
3047 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3048 S_028C70_COMP_SWAP(swap
) |
3049 S_028C70_BLEND_CLAMP(blend_clamp
) |
3050 S_028C70_BLEND_BYPASS(blend_bypass
) |
3051 S_028C70_SIMPLE_FLOAT(1) |
3052 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3053 ntype
!= V_028C70_NUMBER_SNORM
&&
3054 ntype
!= V_028C70_NUMBER_SRGB
&&
3055 format
!= V_028C70_COLOR_8_24
&&
3056 format
!= V_028C70_COLOR_24_8
) |
3057 S_028C70_NUMBER_TYPE(ntype
) |
3058 S_028C70_ENDIAN(endian
);
3059 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3060 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3061 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3062 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3063 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3067 if (iview
->image
->cmask
.size
&&
3068 !(device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3069 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3071 if (iview
->image
->surface
.dcc_size
&& iview
->base_mip
< surf
->num_dcc_levels
)
3072 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3074 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3075 unsigned max_uncompressed_block_size
= 2;
3076 if (iview
->image
->info
.samples
> 1) {
3077 if (iview
->image
->surface
.bpe
== 1)
3078 max_uncompressed_block_size
= 0;
3079 else if (iview
->image
->surface
.bpe
== 2)
3080 max_uncompressed_block_size
= 1;
3083 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3084 S_028C78_INDEPENDENT_64B_BLOCKS(1);
3087 /* This must be set for fast clear to work without FMASK. */
3088 if (!iview
->image
->fmask
.size
&&
3089 device
->physical_device
->rad_info
.chip_class
== SI
) {
3090 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3091 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3094 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3095 uint32_t max_slice
= radv_surface_layer_count(iview
);
3096 unsigned mip0_depth
= iview
->base_layer
+ max_slice
- 1;
3098 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3099 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3100 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3101 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3102 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3103 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3105 cb
->gfx9_epitch
= S_0287A0_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3111 radv_initialise_ds_surface(struct radv_device
*device
,
3112 struct radv_ds_buffer_info
*ds
,
3113 struct radv_image_view
*iview
)
3115 unsigned level
= iview
->base_mip
;
3116 unsigned format
, stencil_format
;
3117 uint64_t va
, s_offs
, z_offs
;
3118 bool stencil_only
= false;
3119 memset(ds
, 0, sizeof(*ds
));
3120 switch (iview
->image
->vk_format
) {
3121 case VK_FORMAT_D24_UNORM_S8_UINT
:
3122 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3123 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3124 ds
->offset_scale
= 2.0f
;
3126 case VK_FORMAT_D16_UNORM
:
3127 case VK_FORMAT_D16_UNORM_S8_UINT
:
3128 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3129 ds
->offset_scale
= 4.0f
;
3131 case VK_FORMAT_D32_SFLOAT
:
3132 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3133 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3134 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3135 ds
->offset_scale
= 1.0f
;
3137 case VK_FORMAT_S8_UINT
:
3138 stencil_only
= true;
3144 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3145 stencil_format
= iview
->image
->surface
.has_stencil
?
3146 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3148 uint32_t max_slice
= radv_surface_layer_count(iview
);
3149 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3150 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3152 ds
->db_htile_data_base
= 0;
3153 ds
->db_htile_surface
= 0;
3155 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3156 s_offs
= z_offs
= va
;
3158 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3159 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3160 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3162 ds
->db_z_info
= S_028038_FORMAT(format
) |
3163 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3164 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3165 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3166 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3167 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3169 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3170 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3171 ds
->db_depth_view
|= S_028008_MIPID(level
);
3173 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3174 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3176 /* Only use HTILE for the first level. */
3177 if (iview
->image
->surface
.htile_size
&& !level
) {
3178 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3180 if (!iview
->image
->surface
.has_stencil
)
3181 /* Use all of the htile_buffer for depth if there's no stencil. */
3182 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3183 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3184 iview
->image
->htile_offset
;
3185 ds
->db_htile_data_base
= va
>> 8;
3186 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3187 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3188 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3191 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3194 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3196 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3197 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3199 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
3200 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3201 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3203 if (iview
->image
->info
.samples
> 1)
3204 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3206 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3207 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3208 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3209 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3210 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3211 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3212 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3213 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3216 tile_mode
= stencil_tile_mode
;
3218 ds
->db_depth_info
|=
3219 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3220 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3221 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3222 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3223 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3224 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3225 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3226 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3228 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3229 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3230 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3231 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3233 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3236 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3237 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3238 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3240 if (iview
->image
->surface
.htile_size
&& !level
) {
3241 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3243 if (!iview
->image
->surface
.has_stencil
)
3244 /* Use all of the htile_buffer for depth if there's no stencil. */
3245 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3247 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3248 iview
->image
->htile_offset
;
3249 ds
->db_htile_data_base
= va
>> 8;
3250 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3254 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3255 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3258 VkResult
radv_CreateFramebuffer(
3260 const VkFramebufferCreateInfo
* pCreateInfo
,
3261 const VkAllocationCallbacks
* pAllocator
,
3262 VkFramebuffer
* pFramebuffer
)
3264 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3265 struct radv_framebuffer
*framebuffer
;
3267 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3269 size_t size
= sizeof(*framebuffer
) +
3270 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3271 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3272 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3273 if (framebuffer
== NULL
)
3274 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3276 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3277 framebuffer
->width
= pCreateInfo
->width
;
3278 framebuffer
->height
= pCreateInfo
->height
;
3279 framebuffer
->layers
= pCreateInfo
->layers
;
3280 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3281 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3282 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3283 framebuffer
->attachments
[i
].attachment
= iview
;
3284 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3285 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3286 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3287 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3289 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3290 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3291 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
3294 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3298 void radv_DestroyFramebuffer(
3301 const VkAllocationCallbacks
* pAllocator
)
3303 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3304 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3308 vk_free2(&device
->alloc
, pAllocator
, fb
);
3311 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3313 switch (address_mode
) {
3314 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3315 return V_008F30_SQ_TEX_WRAP
;
3316 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3317 return V_008F30_SQ_TEX_MIRROR
;
3318 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3319 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3320 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3321 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3322 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3323 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3325 unreachable("illegal tex wrap mode");
3331 radv_tex_compare(VkCompareOp op
)
3334 case VK_COMPARE_OP_NEVER
:
3335 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3336 case VK_COMPARE_OP_LESS
:
3337 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3338 case VK_COMPARE_OP_EQUAL
:
3339 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3340 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3341 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3342 case VK_COMPARE_OP_GREATER
:
3343 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3344 case VK_COMPARE_OP_NOT_EQUAL
:
3345 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3346 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3347 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3348 case VK_COMPARE_OP_ALWAYS
:
3349 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3351 unreachable("illegal compare mode");
3357 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3360 case VK_FILTER_NEAREST
:
3361 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3362 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3363 case VK_FILTER_LINEAR
:
3364 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3365 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3366 case VK_FILTER_CUBIC_IMG
:
3368 fprintf(stderr
, "illegal texture filter");
3374 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3377 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3378 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3379 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3380 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3382 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3387 radv_tex_bordercolor(VkBorderColor bcolor
)
3390 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3391 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3392 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3393 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3394 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3395 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3396 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3397 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3398 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3406 radv_tex_aniso_filter(unsigned filter
)
3420 radv_init_sampler(struct radv_device
*device
,
3421 struct radv_sampler
*sampler
,
3422 const VkSamplerCreateInfo
*pCreateInfo
)
3424 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3425 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3426 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3427 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3429 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3430 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3431 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3432 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3433 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3434 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3435 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3436 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3437 S_008F30_DISABLE_CUBE_WRAP(0) |
3438 S_008F30_COMPAT_MODE(is_vi
));
3439 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3440 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3441 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3442 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3443 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3444 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3445 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3446 S_008F38_MIP_POINT_PRECLAMP(0) |
3447 S_008F38_DISABLE_LSB_CEIL(1) |
3448 S_008F38_FILTER_PREC_FIX(1) |
3449 S_008F38_ANISO_OVERRIDE(is_vi
));
3450 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3451 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3454 VkResult
radv_CreateSampler(
3456 const VkSamplerCreateInfo
* pCreateInfo
,
3457 const VkAllocationCallbacks
* pAllocator
,
3458 VkSampler
* pSampler
)
3460 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3461 struct radv_sampler
*sampler
;
3463 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3465 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3466 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3468 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3470 radv_init_sampler(device
, sampler
, pCreateInfo
);
3471 *pSampler
= radv_sampler_to_handle(sampler
);
3476 void radv_DestroySampler(
3479 const VkAllocationCallbacks
* pAllocator
)
3481 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3482 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3486 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3489 /* vk_icd.h does not declare this function, so we declare it here to
3490 * suppress Wmissing-prototypes.
3492 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3493 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3495 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3496 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3498 /* For the full details on loader interface versioning, see
3499 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3500 * What follows is a condensed summary, to help you navigate the large and
3501 * confusing official doc.
3503 * - Loader interface v0 is incompatible with later versions. We don't
3506 * - In loader interface v1:
3507 * - The first ICD entrypoint called by the loader is
3508 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3510 * - The ICD must statically expose no other Vulkan symbol unless it is
3511 * linked with -Bsymbolic.
3512 * - Each dispatchable Vulkan handle created by the ICD must be
3513 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3514 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3515 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3516 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3517 * such loader-managed surfaces.
3519 * - Loader interface v2 differs from v1 in:
3520 * - The first ICD entrypoint called by the loader is
3521 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3522 * statically expose this entrypoint.
3524 * - Loader interface v3 differs from v2 in:
3525 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3526 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3527 * because the loader no longer does so.
3529 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3533 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3534 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3537 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3538 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3540 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3542 /* We support only one handle type. */
3543 assert(pGetFdInfo
->handleType
==
3544 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3546 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3548 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3552 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3553 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3555 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3557 /* The valid usage section for this function says:
3559 * "handleType must not be one of the handle types defined as opaque."
3561 * Since we only handle opaque handles for now, there are no FD properties.
3563 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3566 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3567 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3569 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3570 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3571 uint32_t syncobj_handle
= 0;
3572 assert(pImportSemaphoreFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3574 int ret
= device
->ws
->import_syncobj(device
->ws
, pImportSemaphoreFdInfo
->fd
, &syncobj_handle
);
3576 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3578 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3579 sem
->temp_syncobj
= syncobj_handle
;
3581 sem
->syncobj
= syncobj_handle
;
3583 close(pImportSemaphoreFdInfo
->fd
);
3587 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3588 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3591 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3592 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3594 uint32_t syncobj_handle
;
3596 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3597 if (sem
->temp_syncobj
)
3598 syncobj_handle
= sem
->temp_syncobj
;
3600 syncobj_handle
= sem
->syncobj
;
3601 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3603 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3607 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3608 VkPhysicalDevice physicalDevice
,
3609 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3610 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3612 if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3613 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3614 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3615 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3616 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3618 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3619 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3620 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;