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 .extensionName
= VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME
,
178 .extensionName
= VK_KHR_BIND_MEMORY_2_EXTENSION_NAME
,
182 static const VkExtensionProperties ext_sema_device_extensions
[] = {
184 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME
,
188 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME
,
192 .extensionName
= VK_KHX_MULTIVIEW_EXTENSION_NAME
,
198 radv_extensions_register(struct radv_instance
*instance
,
199 struct radv_extensions
*extensions
,
200 const VkExtensionProperties
*new_ext
,
204 VkExtensionProperties
*new_ptr
;
206 assert(new_ext
&& num_ext
> 0);
209 return VK_ERROR_INITIALIZATION_FAILED
;
211 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
212 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
213 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
215 /* Old array continues to be valid, update nothing */
217 return VK_ERROR_OUT_OF_HOST_MEMORY
;
219 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
220 num_ext
* sizeof(VkExtensionProperties
));
221 extensions
->ext_array
= new_ptr
;
222 extensions
->num_ext
+= num_ext
;
228 radv_extensions_finish(struct radv_instance
*instance
,
229 struct radv_extensions
*extensions
)
234 radv_loge("Attemted to free invalid extension struct\n");
236 if (extensions
->ext_array
)
237 vk_free(&instance
->alloc
, extensions
->ext_array
);
241 is_extension_enabled(const VkExtensionProperties
*extensions
,
245 assert(extensions
&& name
);
247 for (uint32_t i
= 0; i
< num_ext
; i
++) {
248 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
256 get_chip_name(enum radeon_family family
)
259 case CHIP_TAHITI
: return "AMD RADV TAHITI";
260 case CHIP_PITCAIRN
: return "AMD RADV PITCAIRN";
261 case CHIP_VERDE
: return "AMD RADV CAPE VERDE";
262 case CHIP_OLAND
: return "AMD RADV OLAND";
263 case CHIP_HAINAN
: return "AMD RADV HAINAN";
264 case CHIP_BONAIRE
: return "AMD RADV BONAIRE";
265 case CHIP_KAVERI
: return "AMD RADV KAVERI";
266 case CHIP_KABINI
: return "AMD RADV KABINI";
267 case CHIP_HAWAII
: return "AMD RADV HAWAII";
268 case CHIP_MULLINS
: return "AMD RADV MULLINS";
269 case CHIP_TONGA
: return "AMD RADV TONGA";
270 case CHIP_ICELAND
: return "AMD RADV ICELAND";
271 case CHIP_CARRIZO
: return "AMD RADV CARRIZO";
272 case CHIP_FIJI
: return "AMD RADV FIJI";
273 case CHIP_POLARIS10
: return "AMD RADV POLARIS10";
274 case CHIP_POLARIS11
: return "AMD RADV POLARIS11";
275 case CHIP_POLARIS12
: return "AMD RADV POLARIS12";
276 case CHIP_STONEY
: return "AMD RADV STONEY";
277 case CHIP_VEGA10
: return "AMD RADV VEGA";
278 case CHIP_RAVEN
: return "AMD RADV RAVEN";
279 default: return "AMD RADV unknown";
284 radv_physical_device_init(struct radv_physical_device
*device
,
285 struct radv_instance
*instance
,
286 drmDevicePtr drm_device
)
288 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
290 drmVersionPtr version
;
293 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
295 return VK_ERROR_INCOMPATIBLE_DRIVER
;
297 version
= drmGetVersion(fd
);
300 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
301 "failed to get version %s: %m", path
);
304 if (strcmp(version
->name
, "amdgpu")) {
305 drmFreeVersion(version
);
307 return VK_ERROR_INCOMPATIBLE_DRIVER
;
309 drmFreeVersion(version
);
311 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
312 device
->instance
= instance
;
313 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
314 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
316 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
317 instance
->perftest_flags
);
319 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
323 device
->local_fd
= fd
;
324 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
325 result
= radv_init_wsi(device
);
326 if (result
!= VK_SUCCESS
) {
327 device
->ws
->destroy(device
->ws
);
331 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
332 radv_finish_wsi(device
);
333 device
->ws
->destroy(device
->ws
);
334 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
335 "cannot generate UUID");
339 result
= radv_extensions_register(instance
,
341 common_device_extensions
,
342 ARRAY_SIZE(common_device_extensions
));
343 if (result
!= VK_SUCCESS
)
346 if (device
->rad_info
.has_syncobj
) {
347 result
= radv_extensions_register(instance
,
349 ext_sema_device_extensions
,
350 ARRAY_SIZE(ext_sema_device_extensions
));
351 if (result
!= VK_SUCCESS
)
355 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
356 device
->name
= get_chip_name(device
->rad_info
.family
);
358 radv_get_driver_uuid(&device
->device_uuid
);
359 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
361 if (device
->rad_info
.family
== CHIP_STONEY
||
362 device
->rad_info
.chip_class
>= GFX9
) {
363 device
->has_rbplus
= true;
364 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
375 radv_physical_device_finish(struct radv_physical_device
*device
)
377 radv_extensions_finish(device
->instance
, &device
->extensions
);
378 radv_finish_wsi(device
);
379 device
->ws
->destroy(device
->ws
);
380 close(device
->local_fd
);
384 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
385 VkSystemAllocationScope allocationScope
)
391 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
392 size_t align
, VkSystemAllocationScope allocationScope
)
394 return realloc(pOriginal
, size
);
398 default_free_func(void *pUserData
, void *pMemory
)
403 static const VkAllocationCallbacks default_alloc
= {
405 .pfnAllocation
= default_alloc_func
,
406 .pfnReallocation
= default_realloc_func
,
407 .pfnFree
= default_free_func
,
410 static const struct debug_control radv_debug_options
[] = {
411 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
412 {"nodcc", RADV_DEBUG_NO_DCC
},
413 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
414 {"nocache", RADV_DEBUG_NO_CACHE
},
415 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
416 {"nohiz", RADV_DEBUG_NO_HIZ
},
417 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
418 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
419 {"allbos", RADV_DEBUG_ALL_BOS
},
420 {"noibs", RADV_DEBUG_NO_IBS
},
421 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
422 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
423 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
424 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
429 radv_get_debug_option_name(int id
)
431 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
432 return radv_debug_options
[id
].string
;
435 static const struct debug_control radv_perftest_options
[] = {
436 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
437 {"sisched", RADV_PERFTEST_SISCHED
},
442 radv_get_perftest_option_name(int id
)
444 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
445 return radv_perftest_options
[id
].string
;
448 VkResult
radv_CreateInstance(
449 const VkInstanceCreateInfo
* pCreateInfo
,
450 const VkAllocationCallbacks
* pAllocator
,
451 VkInstance
* pInstance
)
453 struct radv_instance
*instance
;
455 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
457 uint32_t client_version
;
458 if (pCreateInfo
->pApplicationInfo
&&
459 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
460 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
462 client_version
= VK_MAKE_VERSION(1, 0, 0);
465 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
466 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
467 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
468 "Client requested version %d.%d.%d",
469 VK_VERSION_MAJOR(client_version
),
470 VK_VERSION_MINOR(client_version
),
471 VK_VERSION_PATCH(client_version
));
474 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
475 if (!is_extension_enabled(instance_extensions
,
476 ARRAY_SIZE(instance_extensions
),
477 pCreateInfo
->ppEnabledExtensionNames
[i
]))
478 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
481 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
482 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
484 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
486 memset(instance
, 0, sizeof(*instance
));
488 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
491 instance
->alloc
= *pAllocator
;
493 instance
->alloc
= default_alloc
;
495 instance
->apiVersion
= client_version
;
496 instance
->physicalDeviceCount
= -1;
500 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
502 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
505 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
506 radv_perftest_options
);
508 *pInstance
= radv_instance_to_handle(instance
);
513 void radv_DestroyInstance(
514 VkInstance _instance
,
515 const VkAllocationCallbacks
* pAllocator
)
517 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
522 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
523 radv_physical_device_finish(instance
->physicalDevices
+ i
);
526 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
530 vk_free(&instance
->alloc
, instance
);
534 radv_enumerate_devices(struct radv_instance
*instance
)
536 /* TODO: Check for more devices ? */
537 drmDevicePtr devices
[8];
538 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
541 instance
->physicalDeviceCount
= 0;
543 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
545 return VK_ERROR_INCOMPATIBLE_DRIVER
;
547 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
548 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
549 devices
[i
]->bustype
== DRM_BUS_PCI
&&
550 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x1002) {
552 result
= radv_physical_device_init(instance
->physicalDevices
+
553 instance
->physicalDeviceCount
,
556 if (result
== VK_SUCCESS
)
557 ++instance
->physicalDeviceCount
;
558 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
562 drmFreeDevices(devices
, max_devices
);
567 VkResult
radv_EnumeratePhysicalDevices(
568 VkInstance _instance
,
569 uint32_t* pPhysicalDeviceCount
,
570 VkPhysicalDevice
* pPhysicalDevices
)
572 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
575 if (instance
->physicalDeviceCount
< 0) {
576 result
= radv_enumerate_devices(instance
);
577 if (result
!= VK_SUCCESS
&&
578 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
582 if (!pPhysicalDevices
) {
583 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
585 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
586 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
587 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
590 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
594 void radv_GetPhysicalDeviceFeatures(
595 VkPhysicalDevice physicalDevice
,
596 VkPhysicalDeviceFeatures
* pFeatures
)
598 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
599 bool is_gfx9
= pdevice
->rad_info
.chip_class
>= GFX9
;
600 memset(pFeatures
, 0, sizeof(*pFeatures
));
602 *pFeatures
= (VkPhysicalDeviceFeatures
) {
603 .robustBufferAccess
= true,
604 .fullDrawIndexUint32
= true,
605 .imageCubeArray
= true,
606 .independentBlend
= true,
607 .geometryShader
= !is_gfx9
,
608 .tessellationShader
= !is_gfx9
,
609 .sampleRateShading
= true,
610 .dualSrcBlend
= true,
612 .multiDrawIndirect
= true,
613 .drawIndirectFirstInstance
= true,
615 .depthBiasClamp
= true,
616 .fillModeNonSolid
= true,
621 .multiViewport
= true,
622 .samplerAnisotropy
= true,
623 .textureCompressionETC2
= false,
624 .textureCompressionASTC_LDR
= false,
625 .textureCompressionBC
= true,
626 .occlusionQueryPrecise
= true,
627 .pipelineStatisticsQuery
= true,
628 .vertexPipelineStoresAndAtomics
= true,
629 .fragmentStoresAndAtomics
= true,
630 .shaderTessellationAndGeometryPointSize
= true,
631 .shaderImageGatherExtended
= true,
632 .shaderStorageImageExtendedFormats
= true,
633 .shaderStorageImageMultisample
= false,
634 .shaderUniformBufferArrayDynamicIndexing
= true,
635 .shaderSampledImageArrayDynamicIndexing
= true,
636 .shaderStorageBufferArrayDynamicIndexing
= true,
637 .shaderStorageImageArrayDynamicIndexing
= true,
638 .shaderStorageImageReadWithoutFormat
= true,
639 .shaderStorageImageWriteWithoutFormat
= true,
640 .shaderClipDistance
= true,
641 .shaderCullDistance
= true,
642 .shaderFloat64
= true,
644 .shaderInt16
= false,
645 .sparseBinding
= true,
646 .variableMultisampleRate
= true,
647 .inheritedQueries
= true,
651 void radv_GetPhysicalDeviceFeatures2KHR(
652 VkPhysicalDevice physicalDevice
,
653 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
655 vk_foreach_struct(ext
, pFeatures
->pNext
) {
656 switch (ext
->sType
) {
657 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
658 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
659 features
->variablePointersStorageBuffer
= true;
660 features
->variablePointers
= false;
663 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
664 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
665 features
->multiview
= true;
666 features
->multiviewGeometryShader
= true;
667 features
->multiviewTessellationShader
= true;
674 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
677 void radv_GetPhysicalDeviceProperties(
678 VkPhysicalDevice physicalDevice
,
679 VkPhysicalDeviceProperties
* pProperties
)
681 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
682 VkSampleCountFlags sample_counts
= 0xf;
684 /* make sure that the entire descriptor set is addressable with a signed
685 * 32-bit int. So the sum of all limits scaled by descriptor size has to
686 * be at most 2 GiB. the combined image & samples object count as one of
687 * both. This limit is for the pipeline layout, not for the set layout, but
688 * there is no set limit, so we just set a pipeline limit. I don't think
689 * any app is going to hit this soon. */
690 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
691 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
692 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
693 32 /* sampler, largest when combined with image */ +
694 64 /* sampled image */ +
695 64 /* storage image */);
697 VkPhysicalDeviceLimits limits
= {
698 .maxImageDimension1D
= (1 << 14),
699 .maxImageDimension2D
= (1 << 14),
700 .maxImageDimension3D
= (1 << 11),
701 .maxImageDimensionCube
= (1 << 14),
702 .maxImageArrayLayers
= (1 << 11),
703 .maxTexelBufferElements
= 128 * 1024 * 1024,
704 .maxUniformBufferRange
= UINT32_MAX
,
705 .maxStorageBufferRange
= UINT32_MAX
,
706 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
707 .maxMemoryAllocationCount
= UINT32_MAX
,
708 .maxSamplerAllocationCount
= 64 * 1024,
709 .bufferImageGranularity
= 64, /* A cache line */
710 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
711 .maxBoundDescriptorSets
= MAX_SETS
,
712 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
713 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
714 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
715 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
716 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
717 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
718 .maxPerStageResources
= max_descriptor_set_size
,
719 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
720 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
721 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
722 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
723 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
724 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
725 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
726 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
727 .maxVertexInputAttributes
= 32,
728 .maxVertexInputBindings
= 32,
729 .maxVertexInputAttributeOffset
= 2047,
730 .maxVertexInputBindingStride
= 2048,
731 .maxVertexOutputComponents
= 128,
732 .maxTessellationGenerationLevel
= 64,
733 .maxTessellationPatchSize
= 32,
734 .maxTessellationControlPerVertexInputComponents
= 128,
735 .maxTessellationControlPerVertexOutputComponents
= 128,
736 .maxTessellationControlPerPatchOutputComponents
= 120,
737 .maxTessellationControlTotalOutputComponents
= 4096,
738 .maxTessellationEvaluationInputComponents
= 128,
739 .maxTessellationEvaluationOutputComponents
= 128,
740 .maxGeometryShaderInvocations
= 127,
741 .maxGeometryInputComponents
= 64,
742 .maxGeometryOutputComponents
= 128,
743 .maxGeometryOutputVertices
= 256,
744 .maxGeometryTotalOutputComponents
= 1024,
745 .maxFragmentInputComponents
= 128,
746 .maxFragmentOutputAttachments
= 8,
747 .maxFragmentDualSrcAttachments
= 1,
748 .maxFragmentCombinedOutputResources
= 8,
749 .maxComputeSharedMemorySize
= 32768,
750 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
751 .maxComputeWorkGroupInvocations
= 2048,
752 .maxComputeWorkGroupSize
= {
757 .subPixelPrecisionBits
= 4 /* FIXME */,
758 .subTexelPrecisionBits
= 4 /* FIXME */,
759 .mipmapPrecisionBits
= 4 /* FIXME */,
760 .maxDrawIndexedIndexValue
= UINT32_MAX
,
761 .maxDrawIndirectCount
= UINT32_MAX
,
762 .maxSamplerLodBias
= 16,
763 .maxSamplerAnisotropy
= 16,
764 .maxViewports
= MAX_VIEWPORTS
,
765 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
766 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
767 .viewportSubPixelBits
= 13, /* We take a float? */
768 .minMemoryMapAlignment
= 4096, /* A page */
769 .minTexelBufferOffsetAlignment
= 1,
770 .minUniformBufferOffsetAlignment
= 4,
771 .minStorageBufferOffsetAlignment
= 4,
772 .minTexelOffset
= -32,
773 .maxTexelOffset
= 31,
774 .minTexelGatherOffset
= -32,
775 .maxTexelGatherOffset
= 31,
776 .minInterpolationOffset
= -2,
777 .maxInterpolationOffset
= 2,
778 .subPixelInterpolationOffsetBits
= 8,
779 .maxFramebufferWidth
= (1 << 14),
780 .maxFramebufferHeight
= (1 << 14),
781 .maxFramebufferLayers
= (1 << 10),
782 .framebufferColorSampleCounts
= sample_counts
,
783 .framebufferDepthSampleCounts
= sample_counts
,
784 .framebufferStencilSampleCounts
= sample_counts
,
785 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
786 .maxColorAttachments
= MAX_RTS
,
787 .sampledImageColorSampleCounts
= sample_counts
,
788 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
789 .sampledImageDepthSampleCounts
= sample_counts
,
790 .sampledImageStencilSampleCounts
= sample_counts
,
791 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
792 .maxSampleMaskWords
= 1,
793 .timestampComputeAndGraphics
= true,
794 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
795 .maxClipDistances
= 8,
796 .maxCullDistances
= 8,
797 .maxCombinedClipAndCullDistances
= 8,
798 .discreteQueuePriorities
= 1,
799 .pointSizeRange
= { 0.125, 255.875 },
800 .lineWidthRange
= { 0.0, 7.9921875 },
801 .pointSizeGranularity
= (1.0 / 8.0),
802 .lineWidthGranularity
= (1.0 / 128.0),
803 .strictLines
= false, /* FINISHME */
804 .standardSampleLocations
= true,
805 .optimalBufferCopyOffsetAlignment
= 128,
806 .optimalBufferCopyRowPitchAlignment
= 128,
807 .nonCoherentAtomSize
= 64,
810 *pProperties
= (VkPhysicalDeviceProperties
) {
811 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
812 .driverVersion
= vk_get_driver_version(),
814 .deviceID
= pdevice
->rad_info
.pci_id
,
815 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
817 .sparseProperties
= {0},
820 strcpy(pProperties
->deviceName
, pdevice
->name
);
821 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
824 void radv_GetPhysicalDeviceProperties2KHR(
825 VkPhysicalDevice physicalDevice
,
826 VkPhysicalDeviceProperties2KHR
*pProperties
)
828 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
829 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
831 vk_foreach_struct(ext
, pProperties
->pNext
) {
832 switch (ext
->sType
) {
833 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
834 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
835 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
836 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
839 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
840 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
841 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
842 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
843 properties
->deviceLUIDValid
= false;
846 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
847 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
848 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
849 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
858 static void radv_get_physical_device_queue_family_properties(
859 struct radv_physical_device
* pdevice
,
861 VkQueueFamilyProperties
** pQueueFamilyProperties
)
863 int num_queue_families
= 1;
865 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
866 pdevice
->rad_info
.chip_class
>= CIK
&&
867 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
868 num_queue_families
++;
870 if (pQueueFamilyProperties
== NULL
) {
871 *pCount
= num_queue_families
;
880 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
881 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
882 VK_QUEUE_COMPUTE_BIT
|
883 VK_QUEUE_TRANSFER_BIT
|
884 VK_QUEUE_SPARSE_BINDING_BIT
,
886 .timestampValidBits
= 64,
887 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
892 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
893 pdevice
->rad_info
.chip_class
>= CIK
&&
894 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
896 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
897 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
898 VK_QUEUE_TRANSFER_BIT
|
899 VK_QUEUE_SPARSE_BINDING_BIT
,
900 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
901 .timestampValidBits
= 64,
902 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
910 void radv_GetPhysicalDeviceQueueFamilyProperties(
911 VkPhysicalDevice physicalDevice
,
913 VkQueueFamilyProperties
* pQueueFamilyProperties
)
915 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
916 if (!pQueueFamilyProperties
) {
917 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
920 VkQueueFamilyProperties
*properties
[] = {
921 pQueueFamilyProperties
+ 0,
922 pQueueFamilyProperties
+ 1,
923 pQueueFamilyProperties
+ 2,
925 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
926 assert(*pCount
<= 3);
929 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
930 VkPhysicalDevice physicalDevice
,
932 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
934 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
935 if (!pQueueFamilyProperties
) {
936 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
939 VkQueueFamilyProperties
*properties
[] = {
940 &pQueueFamilyProperties
[0].queueFamilyProperties
,
941 &pQueueFamilyProperties
[1].queueFamilyProperties
,
942 &pQueueFamilyProperties
[2].queueFamilyProperties
,
944 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
945 assert(*pCount
<= 3);
948 void radv_GetPhysicalDeviceMemoryProperties(
949 VkPhysicalDevice physicalDevice
,
950 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
952 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
954 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
956 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
957 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
958 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
959 .heapIndex
= RADV_MEM_HEAP_VRAM
,
961 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
962 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
963 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
964 .heapIndex
= RADV_MEM_HEAP_GTT
,
966 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
967 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
968 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
969 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
970 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
972 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
973 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
974 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
975 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
976 .heapIndex
= RADV_MEM_HEAP_GTT
,
979 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
980 uint64_t visible_vram_size
= MIN2(physical_device
->rad_info
.vram_size
,
981 physical_device
->rad_info
.vram_vis_size
);
983 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
984 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
985 .size
= physical_device
->rad_info
.vram_size
-
987 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
989 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
990 .size
= visible_vram_size
,
991 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
993 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
994 .size
= physical_device
->rad_info
.gart_size
,
999 void radv_GetPhysicalDeviceMemoryProperties2KHR(
1000 VkPhysicalDevice physicalDevice
,
1001 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1003 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1004 &pMemoryProperties
->memoryProperties
);
1008 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1009 int queue_family_index
, int idx
)
1011 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1012 queue
->device
= device
;
1013 queue
->queue_family_index
= queue_family_index
;
1014 queue
->queue_idx
= idx
;
1016 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
1018 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1024 radv_queue_finish(struct radv_queue
*queue
)
1027 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1029 if (queue
->initial_full_flush_preamble_cs
)
1030 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1031 if (queue
->initial_preamble_cs
)
1032 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1033 if (queue
->continue_preamble_cs
)
1034 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1035 if (queue
->descriptor_bo
)
1036 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1037 if (queue
->scratch_bo
)
1038 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1039 if (queue
->esgs_ring_bo
)
1040 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1041 if (queue
->gsvs_ring_bo
)
1042 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1043 if (queue
->tess_factor_ring_bo
)
1044 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
1045 if (queue
->tess_offchip_ring_bo
)
1046 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
1047 if (queue
->compute_scratch_bo
)
1048 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1052 radv_device_init_gs_info(struct radv_device
*device
)
1054 switch (device
->physical_device
->rad_info
.family
) {
1063 device
->gs_table_depth
= 16;
1072 case CHIP_POLARIS10
:
1073 case CHIP_POLARIS11
:
1074 case CHIP_POLARIS12
:
1077 device
->gs_table_depth
= 32;
1080 unreachable("unknown GPU");
1084 VkResult
radv_CreateDevice(
1085 VkPhysicalDevice physicalDevice
,
1086 const VkDeviceCreateInfo
* pCreateInfo
,
1087 const VkAllocationCallbacks
* pAllocator
,
1090 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1092 struct radv_device
*device
;
1094 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1095 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
1096 physical_device
->extensions
.num_ext
,
1097 pCreateInfo
->ppEnabledExtensionNames
[i
]))
1098 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1101 /* Check enabled features */
1102 if (pCreateInfo
->pEnabledFeatures
) {
1103 VkPhysicalDeviceFeatures supported_features
;
1104 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1105 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1106 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1107 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1108 for (uint32_t i
= 0; i
< num_features
; i
++) {
1109 if (enabled_feature
[i
] && !supported_feature
[i
])
1110 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1114 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1116 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1118 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1120 memset(device
, 0, sizeof(*device
));
1122 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1123 device
->instance
= physical_device
->instance
;
1124 device
->physical_device
= physical_device
;
1126 device
->debug_flags
= device
->instance
->debug_flags
;
1128 device
->ws
= physical_device
->ws
;
1130 device
->alloc
= *pAllocator
;
1132 device
->alloc
= physical_device
->instance
->alloc
;
1134 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1135 list_inithead(&device
->shader_slabs
);
1137 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1138 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1139 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1141 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1142 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1143 if (!device
->queues
[qfi
]) {
1144 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1148 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1150 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1152 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1153 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
1154 if (result
!= VK_SUCCESS
)
1159 #if HAVE_LLVM < 0x0400
1160 device
->llvm_supports_spill
= false;
1162 device
->llvm_supports_spill
= true;
1165 /* The maximum number of scratch waves. Scratch space isn't divided
1166 * evenly between CUs. The number is only a function of the number of CUs.
1167 * We can decrease the constant to decrease the scratch buffer size.
1169 * sctx->scratch_waves must be >= the maximum posible size of
1170 * 1 threadgroup, so that the hw doesn't hang from being unable
1173 * The recommended value is 4 per CU at most. Higher numbers don't
1174 * bring much benefit, but they still occupy chip resources (think
1175 * async compute). I've seen ~2% performance difference between 4 and 32.
1177 uint32_t max_threads_per_block
= 2048;
1178 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1179 max_threads_per_block
/ 64);
1181 radv_device_init_gs_info(device
);
1183 device
->tess_offchip_block_dw_size
=
1184 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1185 device
->has_distributed_tess
=
1186 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1187 device
->physical_device
->rad_info
.max_se
>= 2;
1189 result
= radv_device_init_meta(device
);
1190 if (result
!= VK_SUCCESS
)
1193 radv_device_init_msaa(device
);
1195 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1196 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1198 case RADV_QUEUE_GENERAL
:
1199 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1200 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1201 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1203 case RADV_QUEUE_COMPUTE
:
1204 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1205 radeon_emit(device
->empty_cs
[family
], 0);
1208 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1211 if (getenv("RADV_TRACE_FILE")) {
1212 if (!radv_init_trace(device
))
1216 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1217 cik_create_gfx_config(device
);
1219 VkPipelineCacheCreateInfo ci
;
1220 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1223 ci
.pInitialData
= NULL
;
1224 ci
.initialDataSize
= 0;
1226 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1228 if (result
!= VK_SUCCESS
)
1231 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1233 *pDevice
= radv_device_to_handle(device
);
1237 if (device
->trace_bo
)
1238 device
->ws
->buffer_destroy(device
->trace_bo
);
1240 if (device
->gfx_init
)
1241 device
->ws
->buffer_destroy(device
->gfx_init
);
1243 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1244 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1245 radv_queue_finish(&device
->queues
[i
][q
]);
1246 if (device
->queue_count
[i
])
1247 vk_free(&device
->alloc
, device
->queues
[i
]);
1250 vk_free(&device
->alloc
, device
);
1254 void radv_DestroyDevice(
1256 const VkAllocationCallbacks
* pAllocator
)
1258 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1263 if (device
->trace_bo
)
1264 device
->ws
->buffer_destroy(device
->trace_bo
);
1266 if (device
->gfx_init
)
1267 device
->ws
->buffer_destroy(device
->gfx_init
);
1269 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1270 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1271 radv_queue_finish(&device
->queues
[i
][q
]);
1272 if (device
->queue_count
[i
])
1273 vk_free(&device
->alloc
, device
->queues
[i
]);
1274 if (device
->empty_cs
[i
])
1275 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1277 radv_device_finish_meta(device
);
1279 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1280 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1282 radv_destroy_shader_slabs(device
);
1284 vk_free(&device
->alloc
, device
);
1287 VkResult
radv_EnumerateInstanceExtensionProperties(
1288 const char* pLayerName
,
1289 uint32_t* pPropertyCount
,
1290 VkExtensionProperties
* pProperties
)
1292 if (pProperties
== NULL
) {
1293 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1297 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1298 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1300 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1301 return VK_INCOMPLETE
;
1306 VkResult
radv_EnumerateDeviceExtensionProperties(
1307 VkPhysicalDevice physicalDevice
,
1308 const char* pLayerName
,
1309 uint32_t* pPropertyCount
,
1310 VkExtensionProperties
* pProperties
)
1312 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1314 if (pProperties
== NULL
) {
1315 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1319 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1320 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1322 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1323 return VK_INCOMPLETE
;
1328 VkResult
radv_EnumerateInstanceLayerProperties(
1329 uint32_t* pPropertyCount
,
1330 VkLayerProperties
* pProperties
)
1332 if (pProperties
== NULL
) {
1333 *pPropertyCount
= 0;
1337 /* None supported at this time */
1338 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1341 VkResult
radv_EnumerateDeviceLayerProperties(
1342 VkPhysicalDevice physicalDevice
,
1343 uint32_t* pPropertyCount
,
1344 VkLayerProperties
* pProperties
)
1346 if (pProperties
== NULL
) {
1347 *pPropertyCount
= 0;
1351 /* None supported at this time */
1352 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1355 void radv_GetDeviceQueue(
1357 uint32_t queueFamilyIndex
,
1358 uint32_t queueIndex
,
1361 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1363 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1367 fill_geom_tess_rings(struct radv_queue
*queue
,
1369 bool add_sample_positions
,
1370 uint32_t esgs_ring_size
,
1371 struct radeon_winsys_bo
*esgs_ring_bo
,
1372 uint32_t gsvs_ring_size
,
1373 struct radeon_winsys_bo
*gsvs_ring_bo
,
1374 uint32_t tess_factor_ring_size
,
1375 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1376 uint32_t tess_offchip_ring_size
,
1377 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1379 uint64_t esgs_va
= 0, gsvs_va
= 0;
1380 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1381 uint32_t *desc
= &map
[4];
1384 esgs_va
= queue
->device
->ws
->buffer_get_va(esgs_ring_bo
);
1386 gsvs_va
= queue
->device
->ws
->buffer_get_va(gsvs_ring_bo
);
1387 if (tess_factor_ring_bo
)
1388 tess_factor_va
= queue
->device
->ws
->buffer_get_va(tess_factor_ring_bo
);
1389 if (tess_offchip_ring_bo
)
1390 tess_offchip_va
= queue
->device
->ws
->buffer_get_va(tess_offchip_ring_bo
);
1392 /* stride 0, num records - size, add tid, swizzle, elsize4,
1395 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1396 S_008F04_STRIDE(0) |
1397 S_008F04_SWIZZLE_ENABLE(true);
1398 desc
[2] = esgs_ring_size
;
1399 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1400 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1401 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1402 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1403 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1404 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1405 S_008F0C_ELEMENT_SIZE(1) |
1406 S_008F0C_INDEX_STRIDE(3) |
1407 S_008F0C_ADD_TID_ENABLE(true);
1410 /* GS entry for ES->GS ring */
1411 /* stride 0, num records - size, elsize0,
1414 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1415 S_008F04_STRIDE(0) |
1416 S_008F04_SWIZZLE_ENABLE(false);
1417 desc
[2] = esgs_ring_size
;
1418 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1419 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1420 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1421 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1422 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1423 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1424 S_008F0C_ELEMENT_SIZE(0) |
1425 S_008F0C_INDEX_STRIDE(0) |
1426 S_008F0C_ADD_TID_ENABLE(false);
1429 /* VS entry for GS->VS ring */
1430 /* stride 0, num records - size, elsize0,
1433 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1434 S_008F04_STRIDE(0) |
1435 S_008F04_SWIZZLE_ENABLE(false);
1436 desc
[2] = gsvs_ring_size
;
1437 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1438 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1439 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1440 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1441 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1442 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1443 S_008F0C_ELEMENT_SIZE(0) |
1444 S_008F0C_INDEX_STRIDE(0) |
1445 S_008F0C_ADD_TID_ENABLE(false);
1448 /* stride gsvs_itemsize, num records 64
1449 elsize 4, index stride 16 */
1450 /* shader will patch stride and desc[2] */
1452 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1453 S_008F04_STRIDE(0) |
1454 S_008F04_SWIZZLE_ENABLE(true);
1456 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1457 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1458 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1459 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1460 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1461 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1462 S_008F0C_ELEMENT_SIZE(1) |
1463 S_008F0C_INDEX_STRIDE(1) |
1464 S_008F0C_ADD_TID_ENABLE(true);
1467 desc
[0] = tess_factor_va
;
1468 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1469 S_008F04_STRIDE(0) |
1470 S_008F04_SWIZZLE_ENABLE(false);
1471 desc
[2] = tess_factor_ring_size
;
1472 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1473 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1474 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1475 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1476 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1477 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1478 S_008F0C_ELEMENT_SIZE(0) |
1479 S_008F0C_INDEX_STRIDE(0) |
1480 S_008F0C_ADD_TID_ENABLE(false);
1483 desc
[0] = tess_offchip_va
;
1484 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1485 S_008F04_STRIDE(0) |
1486 S_008F04_SWIZZLE_ENABLE(false);
1487 desc
[2] = tess_offchip_ring_size
;
1488 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1489 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1490 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1491 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1492 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1493 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1494 S_008F0C_ELEMENT_SIZE(0) |
1495 S_008F0C_INDEX_STRIDE(0) |
1496 S_008F0C_ADD_TID_ENABLE(false);
1499 /* add sample positions after all rings */
1500 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1502 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1504 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1506 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1508 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1512 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1514 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1515 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1516 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1517 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1518 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1519 device
->physical_device
->rad_info
.max_se
;
1520 unsigned offchip_granularity
;
1521 unsigned hs_offchip_param
;
1522 switch (device
->tess_offchip_block_dw_size
) {
1527 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1530 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1534 switch (device
->physical_device
->rad_info
.chip_class
) {
1536 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1542 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1546 *max_offchip_buffers_p
= max_offchip_buffers
;
1547 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1548 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1549 --max_offchip_buffers
;
1551 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1552 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1555 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1557 return hs_offchip_param
;
1561 radv_get_preamble_cs(struct radv_queue
*queue
,
1562 uint32_t scratch_size
,
1563 uint32_t compute_scratch_size
,
1564 uint32_t esgs_ring_size
,
1565 uint32_t gsvs_ring_size
,
1566 bool needs_tess_rings
,
1567 bool needs_sample_positions
,
1568 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1569 struct radeon_winsys_cs
**initial_preamble_cs
,
1570 struct radeon_winsys_cs
**continue_preamble_cs
)
1572 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1573 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1574 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1575 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1576 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1577 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1578 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1579 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1580 bool add_tess_rings
= false, add_sample_positions
= false;
1581 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1582 unsigned max_offchip_buffers
;
1583 unsigned hs_offchip_param
= 0;
1584 if (!queue
->has_tess_rings
) {
1585 if (needs_tess_rings
)
1586 add_tess_rings
= true;
1588 if (!queue
->has_sample_positions
) {
1589 if (needs_sample_positions
)
1590 add_sample_positions
= true;
1592 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1593 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1594 &max_offchip_buffers
);
1595 tess_offchip_ring_size
= max_offchip_buffers
*
1596 queue
->device
->tess_offchip_block_dw_size
* 4;
1598 if (scratch_size
<= queue
->scratch_size
&&
1599 compute_scratch_size
<= queue
->compute_scratch_size
&&
1600 esgs_ring_size
<= queue
->esgs_ring_size
&&
1601 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1602 !add_tess_rings
&& !add_sample_positions
&&
1603 queue
->initial_preamble_cs
) {
1604 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1605 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1606 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1607 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1608 *continue_preamble_cs
= NULL
;
1612 if (scratch_size
> queue
->scratch_size
) {
1613 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1617 RADEON_FLAG_NO_CPU_ACCESS
);
1621 scratch_bo
= queue
->scratch_bo
;
1623 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1624 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1625 compute_scratch_size
,
1628 RADEON_FLAG_NO_CPU_ACCESS
);
1629 if (!compute_scratch_bo
)
1633 compute_scratch_bo
= queue
->compute_scratch_bo
;
1635 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1636 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1640 RADEON_FLAG_NO_CPU_ACCESS
);
1644 esgs_ring_bo
= queue
->esgs_ring_bo
;
1645 esgs_ring_size
= queue
->esgs_ring_size
;
1648 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1649 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1653 RADEON_FLAG_NO_CPU_ACCESS
);
1657 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1658 gsvs_ring_size
= queue
->gsvs_ring_size
;
1661 if (add_tess_rings
) {
1662 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1663 tess_factor_ring_size
,
1666 RADEON_FLAG_NO_CPU_ACCESS
);
1667 if (!tess_factor_ring_bo
)
1669 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1670 tess_offchip_ring_size
,
1673 RADEON_FLAG_NO_CPU_ACCESS
);
1674 if (!tess_offchip_ring_bo
)
1677 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1678 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1681 if (scratch_bo
!= queue
->scratch_bo
||
1682 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1683 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1684 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1685 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1687 if (gsvs_ring_bo
|| esgs_ring_bo
||
1688 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1689 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1690 if (add_sample_positions
)
1691 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1693 else if (scratch_bo
)
1694 size
= 8; /* 2 dword */
1696 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1700 RADEON_FLAG_CPU_ACCESS
);
1704 descriptor_bo
= queue
->descriptor_bo
;
1706 for(int i
= 0; i
< 3; ++i
) {
1707 struct radeon_winsys_cs
*cs
= NULL
;
1708 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1709 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1716 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1719 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1722 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1724 if (tess_factor_ring_bo
)
1725 queue
->device
->ws
->cs_add_buffer(cs
, tess_factor_ring_bo
, 8);
1727 if (tess_offchip_ring_bo
)
1728 queue
->device
->ws
->cs_add_buffer(cs
, tess_offchip_ring_bo
, 8);
1731 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1733 if (descriptor_bo
!= queue
->descriptor_bo
) {
1734 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1737 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(scratch_bo
);
1738 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1739 S_008F04_SWIZZLE_ENABLE(1);
1740 map
[0] = scratch_va
;
1744 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1745 add_sample_positions
)
1746 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1747 esgs_ring_size
, esgs_ring_bo
,
1748 gsvs_ring_size
, gsvs_ring_bo
,
1749 tess_factor_ring_size
, tess_factor_ring_bo
,
1750 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1752 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1755 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1756 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1757 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1758 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1759 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1762 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1763 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1764 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1765 radeon_emit(cs
, esgs_ring_size
>> 8);
1766 radeon_emit(cs
, gsvs_ring_size
>> 8);
1768 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1769 radeon_emit(cs
, esgs_ring_size
>> 8);
1770 radeon_emit(cs
, gsvs_ring_size
>> 8);
1774 if (tess_factor_ring_bo
) {
1775 uint64_t tf_va
= queue
->device
->ws
->buffer_get_va(tess_factor_ring_bo
);
1776 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1777 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1778 S_030938_SIZE(tess_factor_ring_size
/ 4));
1779 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1781 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1782 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1785 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1787 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1788 S_008988_SIZE(tess_factor_ring_size
/ 4));
1789 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1791 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1796 if (descriptor_bo
) {
1797 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1798 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1799 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1800 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1801 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1802 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1804 uint64_t va
= queue
->device
->ws
->buffer_get_va(descriptor_bo
);
1806 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1807 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1808 radeon_emit(cs
, va
);
1809 radeon_emit(cs
, va
>> 32);
1813 if (compute_scratch_bo
) {
1814 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(compute_scratch_bo
);
1815 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1816 S_008F04_SWIZZLE_ENABLE(1);
1818 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1820 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1821 radeon_emit(cs
, scratch_va
);
1822 radeon_emit(cs
, rsrc1
);
1826 si_cs_emit_cache_flush(cs
,
1828 queue
->device
->physical_device
->rad_info
.chip_class
,
1830 queue
->queue_family_index
== RING_COMPUTE
&&
1831 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1832 (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
)) |
1833 RADV_CMD_FLAG_INV_ICACHE
|
1834 RADV_CMD_FLAG_INV_SMEM_L1
|
1835 RADV_CMD_FLAG_INV_VMEM_L1
|
1836 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1837 } else if (i
== 1) {
1838 si_cs_emit_cache_flush(cs
,
1840 queue
->device
->physical_device
->rad_info
.chip_class
,
1842 queue
->queue_family_index
== RING_COMPUTE
&&
1843 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1844 RADV_CMD_FLAG_INV_ICACHE
|
1845 RADV_CMD_FLAG_INV_SMEM_L1
|
1846 RADV_CMD_FLAG_INV_VMEM_L1
|
1847 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1850 if (!queue
->device
->ws
->cs_finalize(cs
))
1854 if (queue
->initial_full_flush_preamble_cs
)
1855 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1857 if (queue
->initial_preamble_cs
)
1858 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1860 if (queue
->continue_preamble_cs
)
1861 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1863 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1864 queue
->initial_preamble_cs
= dest_cs
[1];
1865 queue
->continue_preamble_cs
= dest_cs
[2];
1867 if (scratch_bo
!= queue
->scratch_bo
) {
1868 if (queue
->scratch_bo
)
1869 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1870 queue
->scratch_bo
= scratch_bo
;
1871 queue
->scratch_size
= scratch_size
;
1874 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1875 if (queue
->compute_scratch_bo
)
1876 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1877 queue
->compute_scratch_bo
= compute_scratch_bo
;
1878 queue
->compute_scratch_size
= compute_scratch_size
;
1881 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1882 if (queue
->esgs_ring_bo
)
1883 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1884 queue
->esgs_ring_bo
= esgs_ring_bo
;
1885 queue
->esgs_ring_size
= esgs_ring_size
;
1888 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1889 if (queue
->gsvs_ring_bo
)
1890 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1891 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1892 queue
->gsvs_ring_size
= gsvs_ring_size
;
1895 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1896 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1899 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1900 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1901 queue
->has_tess_rings
= true;
1904 if (descriptor_bo
!= queue
->descriptor_bo
) {
1905 if (queue
->descriptor_bo
)
1906 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1908 queue
->descriptor_bo
= descriptor_bo
;
1911 if (add_sample_positions
)
1912 queue
->has_sample_positions
= true;
1914 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1915 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1916 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1917 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1918 *continue_preamble_cs
= NULL
;
1921 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1923 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1924 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1925 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1926 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1927 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1928 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1929 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1930 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1931 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1932 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1933 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1934 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1935 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1936 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1937 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1938 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1941 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1943 const VkSemaphore
*sems
,
1946 int syncobj_idx
= 0, sem_idx
= 0;
1950 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1951 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1953 if (sem
->temp_syncobj
|| sem
->syncobj
)
1954 counts
->syncobj_count
++;
1956 counts
->sem_count
++;
1959 if (counts
->syncobj_count
) {
1960 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
1961 if (!counts
->syncobj
)
1962 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1965 if (counts
->sem_count
) {
1966 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
1968 free(counts
->syncobj
);
1969 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1973 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1974 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1976 if (sem
->temp_syncobj
) {
1977 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
1979 /* after we wait on a temp import - drop it */
1980 sem
->temp_syncobj
= 0;
1983 else if (sem
->syncobj
)
1984 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
1987 counts
->sem
[sem_idx
++] = sem
->sem
;
1994 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
1996 free(sem_info
->wait
.syncobj
);
1997 free(sem_info
->wait
.sem
);
1998 free(sem_info
->signal
.syncobj
);
1999 free(sem_info
->signal
.sem
);
2002 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2004 const VkSemaphore
*wait_sems
,
2005 int num_signal_sems
,
2006 const VkSemaphore
*signal_sems
)
2009 memset(sem_info
, 0, sizeof(*sem_info
));
2011 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, true);
2014 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, false);
2016 radv_free_sem_info(sem_info
);
2018 /* caller can override these */
2019 sem_info
->cs_emit_wait
= true;
2020 sem_info
->cs_emit_signal
= true;
2024 VkResult
radv_QueueSubmit(
2026 uint32_t submitCount
,
2027 const VkSubmitInfo
* pSubmits
,
2030 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2031 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2032 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2033 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2035 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2036 uint32_t scratch_size
= 0;
2037 uint32_t compute_scratch_size
= 0;
2038 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2039 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2041 bool fence_emitted
= false;
2042 bool tess_rings_needed
= false;
2043 bool sample_positions_needed
= false;
2045 /* Do this first so failing to allocate scratch buffers can't result in
2046 * partially executed submissions. */
2047 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2048 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2049 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2050 pSubmits
[i
].pCommandBuffers
[j
]);
2052 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2053 compute_scratch_size
= MAX2(compute_scratch_size
,
2054 cmd_buffer
->compute_scratch_size_needed
);
2055 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2056 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2057 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2058 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2062 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2063 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2064 sample_positions_needed
, &initial_flush_preamble_cs
,
2065 &initial_preamble_cs
, &continue_preamble_cs
);
2066 if (result
!= VK_SUCCESS
)
2069 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2070 struct radeon_winsys_cs
**cs_array
;
2071 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2072 bool can_patch
= true;
2074 struct radv_winsys_sem_info sem_info
;
2076 result
= radv_alloc_sem_info(&sem_info
,
2077 pSubmits
[i
].waitSemaphoreCount
,
2078 pSubmits
[i
].pWaitSemaphores
,
2079 pSubmits
[i
].signalSemaphoreCount
,
2080 pSubmits
[i
].pSignalSemaphores
);
2081 if (result
!= VK_SUCCESS
)
2084 if (!pSubmits
[i
].commandBufferCount
) {
2085 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2086 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2087 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2092 radv_loge("failed to submit CS %d\n", i
);
2095 fence_emitted
= true;
2097 radv_free_sem_info(&sem_info
);
2101 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2102 (pSubmits
[i
].commandBufferCount
));
2104 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2105 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2106 pSubmits
[i
].pCommandBuffers
[j
]);
2107 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2109 cs_array
[j
] = cmd_buffer
->cs
;
2110 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2114 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2115 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2116 advance
= MIN2(max_cs_submission
,
2117 pSubmits
[i
].commandBufferCount
- j
);
2119 if (queue
->device
->trace_bo
)
2120 *queue
->device
->trace_id_ptr
= 0;
2122 sem_info
.cs_emit_wait
= j
== 0;
2123 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2125 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2126 advance
, initial_preamble
, continue_preamble_cs
,
2128 can_patch
, base_fence
);
2131 radv_loge("failed to submit CS %d\n", i
);
2134 fence_emitted
= true;
2135 if (queue
->device
->trace_bo
) {
2136 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2140 radv_free_sem_info(&sem_info
);
2145 if (!fence_emitted
) {
2146 struct radv_winsys_sem_info sem_info
= {0};
2147 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2148 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2149 1, NULL
, NULL
, &sem_info
,
2152 fence
->submitted
= true;
2158 VkResult
radv_QueueWaitIdle(
2161 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2163 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2164 radv_queue_family_to_ring(queue
->queue_family_index
),
2169 VkResult
radv_DeviceWaitIdle(
2172 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2174 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2175 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2176 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2182 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2183 VkInstance instance
,
2186 return radv_lookup_entrypoint(pName
);
2189 /* The loader wants us to expose a second GetInstanceProcAddr function
2190 * to work around certain LD_PRELOAD issues seen in apps.
2193 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2194 VkInstance instance
,
2198 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2199 VkInstance instance
,
2202 return radv_GetInstanceProcAddr(instance
, pName
);
2205 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2209 return radv_lookup_entrypoint(pName
);
2212 bool radv_get_memory_fd(struct radv_device
*device
,
2213 struct radv_device_memory
*memory
,
2216 struct radeon_bo_metadata metadata
;
2218 if (memory
->image
) {
2219 radv_init_metadata(device
, memory
->image
, &metadata
);
2220 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2223 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2227 VkResult
radv_AllocateMemory(
2229 const VkMemoryAllocateInfo
* pAllocateInfo
,
2230 const VkAllocationCallbacks
* pAllocator
,
2231 VkDeviceMemory
* pMem
)
2233 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2234 struct radv_device_memory
*mem
;
2236 enum radeon_bo_domain domain
;
2239 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2241 if (pAllocateInfo
->allocationSize
== 0) {
2242 /* Apparently, this is allowed */
2243 *pMem
= VK_NULL_HANDLE
;
2247 const VkImportMemoryFdInfoKHR
*import_info
=
2248 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2249 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2250 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2252 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2253 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2255 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2257 if (dedicate_info
) {
2258 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2259 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2266 assert(import_info
->handleType
==
2267 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2268 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2271 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2274 close(import_info
->fd
);
2279 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2280 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2281 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
2282 domain
= RADEON_DOMAIN_GTT
;
2284 domain
= RADEON_DOMAIN_VRAM
;
2286 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
2287 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2289 flags
|= RADEON_FLAG_CPU_ACCESS
;
2291 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2292 flags
|= RADEON_FLAG_GTT_WC
;
2294 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2298 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2301 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
2303 *pMem
= radv_device_memory_to_handle(mem
);
2308 vk_free2(&device
->alloc
, pAllocator
, mem
);
2313 void radv_FreeMemory(
2315 VkDeviceMemory _mem
,
2316 const VkAllocationCallbacks
* pAllocator
)
2318 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2319 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2324 device
->ws
->buffer_destroy(mem
->bo
);
2327 vk_free2(&device
->alloc
, pAllocator
, mem
);
2330 VkResult
radv_MapMemory(
2332 VkDeviceMemory _memory
,
2333 VkDeviceSize offset
,
2335 VkMemoryMapFlags flags
,
2338 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2339 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2346 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2352 return VK_ERROR_MEMORY_MAP_FAILED
;
2355 void radv_UnmapMemory(
2357 VkDeviceMemory _memory
)
2359 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2360 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2365 device
->ws
->buffer_unmap(mem
->bo
);
2368 VkResult
radv_FlushMappedMemoryRanges(
2370 uint32_t memoryRangeCount
,
2371 const VkMappedMemoryRange
* pMemoryRanges
)
2376 VkResult
radv_InvalidateMappedMemoryRanges(
2378 uint32_t memoryRangeCount
,
2379 const VkMappedMemoryRange
* pMemoryRanges
)
2384 void radv_GetBufferMemoryRequirements(
2387 VkMemoryRequirements
* pMemoryRequirements
)
2389 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2391 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2393 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2394 pMemoryRequirements
->alignment
= 4096;
2396 pMemoryRequirements
->alignment
= 16;
2398 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2401 void radv_GetBufferMemoryRequirements2KHR(
2403 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2404 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2406 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2407 &pMemoryRequirements
->memoryRequirements
);
2409 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2410 switch (ext
->sType
) {
2411 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2412 VkMemoryDedicatedRequirementsKHR
*req
=
2413 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2414 req
->requiresDedicatedAllocation
= false;
2415 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2424 void radv_GetImageMemoryRequirements(
2427 VkMemoryRequirements
* pMemoryRequirements
)
2429 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2431 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2433 pMemoryRequirements
->size
= image
->size
;
2434 pMemoryRequirements
->alignment
= image
->alignment
;
2437 void radv_GetImageMemoryRequirements2KHR(
2439 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2440 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2442 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2443 &pMemoryRequirements
->memoryRequirements
);
2445 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2447 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2448 switch (ext
->sType
) {
2449 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2450 VkMemoryDedicatedRequirementsKHR
*req
=
2451 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2452 req
->requiresDedicatedAllocation
= image
->shareable
;
2453 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2462 void radv_GetImageSparseMemoryRequirements(
2465 uint32_t* pSparseMemoryRequirementCount
,
2466 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2471 void radv_GetImageSparseMemoryRequirements2KHR(
2473 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2474 uint32_t* pSparseMemoryRequirementCount
,
2475 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2480 void radv_GetDeviceMemoryCommitment(
2482 VkDeviceMemory memory
,
2483 VkDeviceSize
* pCommittedMemoryInBytes
)
2485 *pCommittedMemoryInBytes
= 0;
2488 VkResult
radv_BindBufferMemory2KHR(VkDevice device
,
2489 uint32_t bindInfoCount
,
2490 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2492 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2493 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2494 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2497 buffer
->bo
= mem
->bo
;
2498 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2506 VkResult
radv_BindBufferMemory(
2509 VkDeviceMemory memory
,
2510 VkDeviceSize memoryOffset
)
2512 const VkBindBufferMemoryInfoKHR info
= {
2513 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2516 .memoryOffset
= memoryOffset
2519 return radv_BindBufferMemory2KHR(device
, 1, &info
);
2522 VkResult
radv_BindImageMemory2KHR(VkDevice device
,
2523 uint32_t bindInfoCount
,
2524 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2526 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2527 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2528 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2531 image
->bo
= mem
->bo
;
2532 image
->offset
= pBindInfos
[i
].memoryOffset
;
2542 VkResult
radv_BindImageMemory(
2545 VkDeviceMemory memory
,
2546 VkDeviceSize memoryOffset
)
2548 const VkBindImageMemoryInfoKHR info
= {
2549 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2552 .memoryOffset
= memoryOffset
2555 return radv_BindImageMemory2KHR(device
, 1, &info
);
2560 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2561 const VkSparseBufferMemoryBindInfo
*bind
)
2563 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2565 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2566 struct radv_device_memory
*mem
= NULL
;
2568 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2569 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2571 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2572 bind
->pBinds
[i
].resourceOffset
,
2573 bind
->pBinds
[i
].size
,
2574 mem
? mem
->bo
: NULL
,
2575 bind
->pBinds
[i
].memoryOffset
);
2580 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2581 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2583 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2585 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2586 struct radv_device_memory
*mem
= NULL
;
2588 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2589 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2591 device
->ws
->buffer_virtual_bind(image
->bo
,
2592 bind
->pBinds
[i
].resourceOffset
,
2593 bind
->pBinds
[i
].size
,
2594 mem
? mem
->bo
: NULL
,
2595 bind
->pBinds
[i
].memoryOffset
);
2599 VkResult
radv_QueueBindSparse(
2601 uint32_t bindInfoCount
,
2602 const VkBindSparseInfo
* pBindInfo
,
2605 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2606 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2607 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2608 bool fence_emitted
= false;
2610 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2611 struct radv_winsys_sem_info sem_info
;
2612 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2613 radv_sparse_buffer_bind_memory(queue
->device
,
2614 pBindInfo
[i
].pBufferBinds
+ j
);
2617 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2618 radv_sparse_image_opaque_bind_memory(queue
->device
,
2619 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2623 result
= radv_alloc_sem_info(&sem_info
,
2624 pBindInfo
[i
].waitSemaphoreCount
,
2625 pBindInfo
[i
].pWaitSemaphores
,
2626 pBindInfo
[i
].signalSemaphoreCount
,
2627 pBindInfo
[i
].pSignalSemaphores
);
2628 if (result
!= VK_SUCCESS
)
2631 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2632 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2633 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2637 fence_emitted
= true;
2639 fence
->submitted
= true;
2642 radv_free_sem_info(&sem_info
);
2646 if (fence
&& !fence_emitted
) {
2647 fence
->signalled
= true;
2653 VkResult
radv_CreateFence(
2655 const VkFenceCreateInfo
* pCreateInfo
,
2656 const VkAllocationCallbacks
* pAllocator
,
2659 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2660 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2662 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2665 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2667 memset(fence
, 0, sizeof(*fence
));
2668 fence
->submitted
= false;
2669 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2670 fence
->fence
= device
->ws
->create_fence();
2671 if (!fence
->fence
) {
2672 vk_free2(&device
->alloc
, pAllocator
, fence
);
2673 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2676 *pFence
= radv_fence_to_handle(fence
);
2681 void radv_DestroyFence(
2684 const VkAllocationCallbacks
* pAllocator
)
2686 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2687 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2691 device
->ws
->destroy_fence(fence
->fence
);
2692 vk_free2(&device
->alloc
, pAllocator
, fence
);
2695 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2697 uint64_t current_time
;
2700 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2701 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2703 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2705 return current_time
+ timeout
;
2708 VkResult
radv_WaitForFences(
2710 uint32_t fenceCount
,
2711 const VkFence
* pFences
,
2715 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2716 timeout
= radv_get_absolute_timeout(timeout
);
2718 if (!waitAll
&& fenceCount
> 1) {
2719 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2722 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2723 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2724 bool expired
= false;
2726 if (fence
->signalled
)
2729 if (!fence
->submitted
)
2732 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2736 fence
->signalled
= true;
2742 VkResult
radv_ResetFences(VkDevice device
,
2743 uint32_t fenceCount
,
2744 const VkFence
*pFences
)
2746 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2747 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2748 fence
->submitted
= fence
->signalled
= false;
2754 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2756 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2757 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2759 if (fence
->signalled
)
2761 if (!fence
->submitted
)
2762 return VK_NOT_READY
;
2764 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2765 return VK_NOT_READY
;
2771 // Queue semaphore functions
2773 VkResult
radv_CreateSemaphore(
2775 const VkSemaphoreCreateInfo
* pCreateInfo
,
2776 const VkAllocationCallbacks
* pAllocator
,
2777 VkSemaphore
* pSemaphore
)
2779 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2780 const VkExportSemaphoreCreateInfoKHR
*export
=
2781 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2782 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2783 export
? export
->handleTypes
: 0;
2785 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2787 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2789 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2791 sem
->temp_syncobj
= 0;
2792 /* create a syncobject if we are going to export this semaphore */
2794 assert (device
->physical_device
->rad_info
.has_syncobj
);
2795 assert (handleTypes
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2796 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2798 vk_free2(&device
->alloc
, pAllocator
, sem
);
2799 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2803 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2805 vk_free2(&device
->alloc
, pAllocator
, sem
);
2806 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2811 *pSemaphore
= radv_semaphore_to_handle(sem
);
2815 void radv_DestroySemaphore(
2817 VkSemaphore _semaphore
,
2818 const VkAllocationCallbacks
* pAllocator
)
2820 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2821 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2826 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2828 device
->ws
->destroy_sem(sem
->sem
);
2829 vk_free2(&device
->alloc
, pAllocator
, sem
);
2832 VkResult
radv_CreateEvent(
2834 const VkEventCreateInfo
* pCreateInfo
,
2835 const VkAllocationCallbacks
* pAllocator
,
2838 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2839 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2841 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2844 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2846 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2848 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
);
2850 vk_free2(&device
->alloc
, pAllocator
, event
);
2851 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2854 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2856 *pEvent
= radv_event_to_handle(event
);
2861 void radv_DestroyEvent(
2864 const VkAllocationCallbacks
* pAllocator
)
2866 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2867 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2871 device
->ws
->buffer_destroy(event
->bo
);
2872 vk_free2(&device
->alloc
, pAllocator
, event
);
2875 VkResult
radv_GetEventStatus(
2879 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2881 if (*event
->map
== 1)
2882 return VK_EVENT_SET
;
2883 return VK_EVENT_RESET
;
2886 VkResult
radv_SetEvent(
2890 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2896 VkResult
radv_ResetEvent(
2900 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2906 VkResult
radv_CreateBuffer(
2908 const VkBufferCreateInfo
* pCreateInfo
,
2909 const VkAllocationCallbacks
* pAllocator
,
2912 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2913 struct radv_buffer
*buffer
;
2915 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2917 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2918 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2920 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2922 buffer
->size
= pCreateInfo
->size
;
2923 buffer
->usage
= pCreateInfo
->usage
;
2926 buffer
->flags
= pCreateInfo
->flags
;
2928 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2929 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2930 align64(buffer
->size
, 4096),
2931 4096, 0, RADEON_FLAG_VIRTUAL
);
2933 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2934 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2938 *pBuffer
= radv_buffer_to_handle(buffer
);
2943 void radv_DestroyBuffer(
2946 const VkAllocationCallbacks
* pAllocator
)
2948 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2949 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2954 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2955 device
->ws
->buffer_destroy(buffer
->bo
);
2957 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2960 static inline unsigned
2961 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
2964 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
2966 return image
->surface
.u
.legacy
.tiling_index
[level
];
2969 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
2971 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
2975 radv_initialise_color_surface(struct radv_device
*device
,
2976 struct radv_color_buffer_info
*cb
,
2977 struct radv_image_view
*iview
)
2979 const struct vk_format_description
*desc
;
2980 unsigned ntype
, format
, swap
, endian
;
2981 unsigned blend_clamp
= 0, blend_bypass
= 0;
2983 const struct radeon_surf
*surf
= &iview
->image
->surface
;
2985 desc
= vk_format_description(iview
->vk_format
);
2987 memset(cb
, 0, sizeof(*cb
));
2989 /* Intensity is implemented as Red, so treat it that way. */
2990 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
2992 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2994 cb
->cb_color_base
= va
>> 8;
2996 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2997 struct gfx9_surf_meta_flags meta
;
2998 if (iview
->image
->dcc_offset
)
2999 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3001 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3003 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3004 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3005 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3006 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3008 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3009 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3011 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3012 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3014 cb
->cb_color_base
+= level_info
->offset
>> 8;
3015 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3016 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3018 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3019 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3020 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3022 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3023 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3024 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3026 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3027 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
3029 if (iview
->image
->fmask
.size
) {
3030 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3031 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3032 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3033 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3035 /* This must be set for fast clear to work without FMASK. */
3036 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3037 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3038 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3039 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3043 /* CMASK variables */
3044 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3045 va
+= iview
->image
->cmask
.offset
;
3046 cb
->cb_color_cmask
= va
>> 8;
3048 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3049 va
+= iview
->image
->dcc_offset
;
3050 cb
->cb_dcc_base
= va
>> 8;
3051 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3053 uint32_t max_slice
= radv_surface_layer_count(iview
);
3054 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3055 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3057 if (iview
->image
->info
.samples
> 1) {
3058 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3060 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3061 S_028C74_NUM_FRAGMENTS(log_samples
);
3064 if (iview
->image
->fmask
.size
) {
3065 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3066 cb
->cb_color_fmask
= va
>> 8;
3067 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3069 cb
->cb_color_fmask
= cb
->cb_color_base
;
3072 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3074 vk_format_get_first_non_void_channel(iview
->vk_format
));
3075 format
= radv_translate_colorformat(iview
->vk_format
);
3076 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3077 radv_finishme("Illegal color\n");
3078 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3079 endian
= radv_colorformat_endian_swap(format
);
3081 /* blend clamp should be set for all NORM/SRGB types */
3082 if (ntype
== V_028C70_NUMBER_UNORM
||
3083 ntype
== V_028C70_NUMBER_SNORM
||
3084 ntype
== V_028C70_NUMBER_SRGB
)
3087 /* set blend bypass according to docs if SINT/UINT or
3088 8/24 COLOR variants */
3089 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3090 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3091 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3096 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3097 (format
== V_028C70_COLOR_8
||
3098 format
== V_028C70_COLOR_8_8
||
3099 format
== V_028C70_COLOR_8_8_8_8
))
3100 ->color_is_int8
= true;
3102 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3103 S_028C70_COMP_SWAP(swap
) |
3104 S_028C70_BLEND_CLAMP(blend_clamp
) |
3105 S_028C70_BLEND_BYPASS(blend_bypass
) |
3106 S_028C70_SIMPLE_FLOAT(1) |
3107 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3108 ntype
!= V_028C70_NUMBER_SNORM
&&
3109 ntype
!= V_028C70_NUMBER_SRGB
&&
3110 format
!= V_028C70_COLOR_8_24
&&
3111 format
!= V_028C70_COLOR_24_8
) |
3112 S_028C70_NUMBER_TYPE(ntype
) |
3113 S_028C70_ENDIAN(endian
);
3114 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3115 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3116 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3117 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3118 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3122 if (iview
->image
->cmask
.size
&&
3123 !(device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3124 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3126 if (iview
->image
->surface
.dcc_size
&& iview
->base_mip
< surf
->num_dcc_levels
)
3127 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3129 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3130 unsigned max_uncompressed_block_size
= 2;
3131 if (iview
->image
->info
.samples
> 1) {
3132 if (iview
->image
->surface
.bpe
== 1)
3133 max_uncompressed_block_size
= 0;
3134 else if (iview
->image
->surface
.bpe
== 2)
3135 max_uncompressed_block_size
= 1;
3138 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3139 S_028C78_INDEPENDENT_64B_BLOCKS(1);
3142 /* This must be set for fast clear to work without FMASK. */
3143 if (!iview
->image
->fmask
.size
&&
3144 device
->physical_device
->rad_info
.chip_class
== SI
) {
3145 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3146 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3149 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3150 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3151 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3153 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3154 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3155 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3156 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3157 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3158 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3160 cb
->gfx9_epitch
= S_0287A0_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3166 radv_initialise_ds_surface(struct radv_device
*device
,
3167 struct radv_ds_buffer_info
*ds
,
3168 struct radv_image_view
*iview
)
3170 unsigned level
= iview
->base_mip
;
3171 unsigned format
, stencil_format
;
3172 uint64_t va
, s_offs
, z_offs
;
3173 bool stencil_only
= false;
3174 memset(ds
, 0, sizeof(*ds
));
3175 switch (iview
->image
->vk_format
) {
3176 case VK_FORMAT_D24_UNORM_S8_UINT
:
3177 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3178 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3179 ds
->offset_scale
= 2.0f
;
3181 case VK_FORMAT_D16_UNORM
:
3182 case VK_FORMAT_D16_UNORM_S8_UINT
:
3183 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3184 ds
->offset_scale
= 4.0f
;
3186 case VK_FORMAT_D32_SFLOAT
:
3187 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3188 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3189 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3190 ds
->offset_scale
= 1.0f
;
3192 case VK_FORMAT_S8_UINT
:
3193 stencil_only
= true;
3199 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3200 stencil_format
= iview
->image
->surface
.has_stencil
?
3201 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3203 uint32_t max_slice
= radv_surface_layer_count(iview
);
3204 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3205 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3207 ds
->db_htile_data_base
= 0;
3208 ds
->db_htile_surface
= 0;
3210 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3211 s_offs
= z_offs
= va
;
3213 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3214 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3215 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3217 ds
->db_z_info
= S_028038_FORMAT(format
) |
3218 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3219 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3220 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3221 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3222 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3224 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3225 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3226 ds
->db_depth_view
|= S_028008_MIPID(level
);
3228 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3229 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3231 /* Only use HTILE for the first level. */
3232 if (iview
->image
->surface
.htile_size
&& !level
) {
3233 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3235 if (!iview
->image
->surface
.has_stencil
)
3236 /* Use all of the htile_buffer for depth if there's no stencil. */
3237 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3238 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3239 iview
->image
->htile_offset
;
3240 ds
->db_htile_data_base
= va
>> 8;
3241 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3242 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3243 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3246 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3249 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3251 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3252 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3254 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
3255 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3256 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3258 if (iview
->image
->info
.samples
> 1)
3259 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3261 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3262 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3263 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3264 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3265 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3266 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3267 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3268 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3271 tile_mode
= stencil_tile_mode
;
3273 ds
->db_depth_info
|=
3274 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3275 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3276 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3277 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3278 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3279 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3280 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3281 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3283 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3284 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3285 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3286 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3288 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3291 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3292 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3293 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3295 if (iview
->image
->surface
.htile_size
&& !level
) {
3296 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3298 if (!iview
->image
->surface
.has_stencil
)
3299 /* Use all of the htile_buffer for depth if there's no stencil. */
3300 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3302 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3303 iview
->image
->htile_offset
;
3304 ds
->db_htile_data_base
= va
>> 8;
3305 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3309 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3310 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3313 VkResult
radv_CreateFramebuffer(
3315 const VkFramebufferCreateInfo
* pCreateInfo
,
3316 const VkAllocationCallbacks
* pAllocator
,
3317 VkFramebuffer
* pFramebuffer
)
3319 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3320 struct radv_framebuffer
*framebuffer
;
3322 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3324 size_t size
= sizeof(*framebuffer
) +
3325 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3326 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3327 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3328 if (framebuffer
== NULL
)
3329 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3331 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3332 framebuffer
->width
= pCreateInfo
->width
;
3333 framebuffer
->height
= pCreateInfo
->height
;
3334 framebuffer
->layers
= pCreateInfo
->layers
;
3335 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3336 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3337 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3338 framebuffer
->attachments
[i
].attachment
= iview
;
3339 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3340 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3341 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3342 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3344 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3345 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3346 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
3349 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3353 void radv_DestroyFramebuffer(
3356 const VkAllocationCallbacks
* pAllocator
)
3358 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3359 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3363 vk_free2(&device
->alloc
, pAllocator
, fb
);
3366 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3368 switch (address_mode
) {
3369 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3370 return V_008F30_SQ_TEX_WRAP
;
3371 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3372 return V_008F30_SQ_TEX_MIRROR
;
3373 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3374 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3375 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3376 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3377 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3378 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3380 unreachable("illegal tex wrap mode");
3386 radv_tex_compare(VkCompareOp op
)
3389 case VK_COMPARE_OP_NEVER
:
3390 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3391 case VK_COMPARE_OP_LESS
:
3392 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3393 case VK_COMPARE_OP_EQUAL
:
3394 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3395 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3396 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3397 case VK_COMPARE_OP_GREATER
:
3398 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3399 case VK_COMPARE_OP_NOT_EQUAL
:
3400 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3401 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3402 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3403 case VK_COMPARE_OP_ALWAYS
:
3404 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3406 unreachable("illegal compare mode");
3412 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3415 case VK_FILTER_NEAREST
:
3416 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3417 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3418 case VK_FILTER_LINEAR
:
3419 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3420 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3421 case VK_FILTER_CUBIC_IMG
:
3423 fprintf(stderr
, "illegal texture filter");
3429 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3432 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3433 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3434 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3435 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3437 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3442 radv_tex_bordercolor(VkBorderColor bcolor
)
3445 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3446 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3447 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3448 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3449 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3450 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3451 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3452 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3453 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3461 radv_tex_aniso_filter(unsigned filter
)
3475 radv_init_sampler(struct radv_device
*device
,
3476 struct radv_sampler
*sampler
,
3477 const VkSamplerCreateInfo
*pCreateInfo
)
3479 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3480 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3481 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3482 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3484 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3485 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3486 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3487 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3488 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3489 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3490 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3491 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3492 S_008F30_DISABLE_CUBE_WRAP(0) |
3493 S_008F30_COMPAT_MODE(is_vi
));
3494 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3495 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3496 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3497 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3498 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3499 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3500 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3501 S_008F38_MIP_POINT_PRECLAMP(0) |
3502 S_008F38_DISABLE_LSB_CEIL(1) |
3503 S_008F38_FILTER_PREC_FIX(1) |
3504 S_008F38_ANISO_OVERRIDE(is_vi
));
3505 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3506 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3509 VkResult
radv_CreateSampler(
3511 const VkSamplerCreateInfo
* pCreateInfo
,
3512 const VkAllocationCallbacks
* pAllocator
,
3513 VkSampler
* pSampler
)
3515 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3516 struct radv_sampler
*sampler
;
3518 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3520 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3521 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3523 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3525 radv_init_sampler(device
, sampler
, pCreateInfo
);
3526 *pSampler
= radv_sampler_to_handle(sampler
);
3531 void radv_DestroySampler(
3534 const VkAllocationCallbacks
* pAllocator
)
3536 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3537 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3541 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3544 /* vk_icd.h does not declare this function, so we declare it here to
3545 * suppress Wmissing-prototypes.
3547 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3548 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3550 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3551 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3553 /* For the full details on loader interface versioning, see
3554 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3555 * What follows is a condensed summary, to help you navigate the large and
3556 * confusing official doc.
3558 * - Loader interface v0 is incompatible with later versions. We don't
3561 * - In loader interface v1:
3562 * - The first ICD entrypoint called by the loader is
3563 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3565 * - The ICD must statically expose no other Vulkan symbol unless it is
3566 * linked with -Bsymbolic.
3567 * - Each dispatchable Vulkan handle created by the ICD must be
3568 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3569 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3570 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3571 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3572 * such loader-managed surfaces.
3574 * - Loader interface v2 differs from v1 in:
3575 * - The first ICD entrypoint called by the loader is
3576 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3577 * statically expose this entrypoint.
3579 * - Loader interface v3 differs from v2 in:
3580 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3581 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3582 * because the loader no longer does so.
3584 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3588 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3589 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3592 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3593 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3595 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3597 /* We support only one handle type. */
3598 assert(pGetFdInfo
->handleType
==
3599 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3601 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3603 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3607 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3608 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3610 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3612 /* The valid usage section for this function says:
3614 * "handleType must not be one of the handle types defined as opaque."
3616 * Since we only handle opaque handles for now, there are no FD properties.
3618 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3621 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3622 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3624 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3625 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3626 uint32_t syncobj_handle
= 0;
3627 assert(pImportSemaphoreFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3629 int ret
= device
->ws
->import_syncobj(device
->ws
, pImportSemaphoreFdInfo
->fd
, &syncobj_handle
);
3631 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3633 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3634 sem
->temp_syncobj
= syncobj_handle
;
3636 sem
->syncobj
= syncobj_handle
;
3638 close(pImportSemaphoreFdInfo
->fd
);
3642 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3643 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3646 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3647 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3649 uint32_t syncobj_handle
;
3651 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3652 if (sem
->temp_syncobj
)
3653 syncobj_handle
= sem
->temp_syncobj
;
3655 syncobj_handle
= sem
->syncobj
;
3656 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3658 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3662 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3663 VkPhysicalDevice physicalDevice
,
3664 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3665 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3667 if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3668 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3669 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3670 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3671 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3673 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3674 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3675 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;