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 .extensionName
= VK_KHR_MAINTENANCE2_EXTENSION_NAME
,
186 .extensionName
= VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME
,
191 static const VkExtensionProperties rasterization_order_extension
[] ={
193 .extensionName
= VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME
,
198 static const VkExtensionProperties ext_sema_device_extensions
[] = {
200 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME
,
204 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME
,
208 .extensionName
= VK_KHX_MULTIVIEW_EXTENSION_NAME
,
214 radv_extensions_register(struct radv_instance
*instance
,
215 struct radv_extensions
*extensions
,
216 const VkExtensionProperties
*new_ext
,
220 VkExtensionProperties
*new_ptr
;
222 assert(new_ext
&& num_ext
> 0);
225 return VK_ERROR_INITIALIZATION_FAILED
;
227 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
228 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
229 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
231 /* Old array continues to be valid, update nothing */
233 return VK_ERROR_OUT_OF_HOST_MEMORY
;
235 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
236 num_ext
* sizeof(VkExtensionProperties
));
237 extensions
->ext_array
= new_ptr
;
238 extensions
->num_ext
+= num_ext
;
244 radv_extensions_finish(struct radv_instance
*instance
,
245 struct radv_extensions
*extensions
)
250 radv_loge("Attemted to free invalid extension struct\n");
252 if (extensions
->ext_array
)
253 vk_free(&instance
->alloc
, extensions
->ext_array
);
257 is_extension_enabled(const VkExtensionProperties
*extensions
,
261 assert(extensions
&& name
);
263 for (uint32_t i
= 0; i
< num_ext
; i
++) {
264 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
272 get_chip_name(enum radeon_family family
)
275 case CHIP_TAHITI
: return "AMD RADV TAHITI";
276 case CHIP_PITCAIRN
: return "AMD RADV PITCAIRN";
277 case CHIP_VERDE
: return "AMD RADV CAPE VERDE";
278 case CHIP_OLAND
: return "AMD RADV OLAND";
279 case CHIP_HAINAN
: return "AMD RADV HAINAN";
280 case CHIP_BONAIRE
: return "AMD RADV BONAIRE";
281 case CHIP_KAVERI
: return "AMD RADV KAVERI";
282 case CHIP_KABINI
: return "AMD RADV KABINI";
283 case CHIP_HAWAII
: return "AMD RADV HAWAII";
284 case CHIP_MULLINS
: return "AMD RADV MULLINS";
285 case CHIP_TONGA
: return "AMD RADV TONGA";
286 case CHIP_ICELAND
: return "AMD RADV ICELAND";
287 case CHIP_CARRIZO
: return "AMD RADV CARRIZO";
288 case CHIP_FIJI
: return "AMD RADV FIJI";
289 case CHIP_POLARIS10
: return "AMD RADV POLARIS10";
290 case CHIP_POLARIS11
: return "AMD RADV POLARIS11";
291 case CHIP_POLARIS12
: return "AMD RADV POLARIS12";
292 case CHIP_STONEY
: return "AMD RADV STONEY";
293 case CHIP_VEGA10
: return "AMD RADV VEGA";
294 case CHIP_RAVEN
: return "AMD RADV RAVEN";
295 default: return "AMD RADV unknown";
300 radv_physical_device_init(struct radv_physical_device
*device
,
301 struct radv_instance
*instance
,
302 drmDevicePtr drm_device
)
304 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
306 drmVersionPtr version
;
309 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
311 return VK_ERROR_INCOMPATIBLE_DRIVER
;
313 version
= drmGetVersion(fd
);
316 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
317 "failed to get version %s: %m", path
);
320 if (strcmp(version
->name
, "amdgpu")) {
321 drmFreeVersion(version
);
323 return VK_ERROR_INCOMPATIBLE_DRIVER
;
325 drmFreeVersion(version
);
327 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
328 device
->instance
= instance
;
329 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
330 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
332 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
333 instance
->perftest_flags
);
335 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
339 device
->local_fd
= fd
;
340 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
341 result
= radv_init_wsi(device
);
342 if (result
!= VK_SUCCESS
) {
343 device
->ws
->destroy(device
->ws
);
347 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
348 radv_finish_wsi(device
);
349 device
->ws
->destroy(device
->ws
);
350 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
351 "cannot generate UUID");
355 result
= radv_extensions_register(instance
,
357 common_device_extensions
,
358 ARRAY_SIZE(common_device_extensions
));
359 if (result
!= VK_SUCCESS
)
362 if (device
->rad_info
.chip_class
>= VI
&& device
->rad_info
.max_se
>= 2) {
363 result
= radv_extensions_register(instance
,
365 rasterization_order_extension
,
366 ARRAY_SIZE(rasterization_order_extension
));
367 if (result
!= VK_SUCCESS
)
371 if (device
->rad_info
.has_syncobj
) {
372 result
= radv_extensions_register(instance
,
374 ext_sema_device_extensions
,
375 ARRAY_SIZE(ext_sema_device_extensions
));
376 if (result
!= VK_SUCCESS
)
380 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
381 device
->name
= get_chip_name(device
->rad_info
.family
);
383 radv_get_driver_uuid(&device
->device_uuid
);
384 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
386 if (device
->rad_info
.family
== CHIP_STONEY
||
387 device
->rad_info
.chip_class
>= GFX9
) {
388 device
->has_rbplus
= true;
389 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
400 radv_physical_device_finish(struct radv_physical_device
*device
)
402 radv_extensions_finish(device
->instance
, &device
->extensions
);
403 radv_finish_wsi(device
);
404 device
->ws
->destroy(device
->ws
);
405 close(device
->local_fd
);
409 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
410 VkSystemAllocationScope allocationScope
)
416 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
417 size_t align
, VkSystemAllocationScope allocationScope
)
419 return realloc(pOriginal
, size
);
423 default_free_func(void *pUserData
, void *pMemory
)
428 static const VkAllocationCallbacks default_alloc
= {
430 .pfnAllocation
= default_alloc_func
,
431 .pfnReallocation
= default_realloc_func
,
432 .pfnFree
= default_free_func
,
435 static const struct debug_control radv_debug_options
[] = {
436 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
437 {"nodcc", RADV_DEBUG_NO_DCC
},
438 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
439 {"nocache", RADV_DEBUG_NO_CACHE
},
440 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
441 {"nohiz", RADV_DEBUG_NO_HIZ
},
442 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
443 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
444 {"allbos", RADV_DEBUG_ALL_BOS
},
445 {"noibs", RADV_DEBUG_NO_IBS
},
446 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
447 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
448 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
449 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
454 radv_get_debug_option_name(int id
)
456 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
457 return radv_debug_options
[id
].string
;
460 static const struct debug_control radv_perftest_options
[] = {
461 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
462 {"sisched", RADV_PERFTEST_SISCHED
},
467 radv_get_perftest_option_name(int id
)
469 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
470 return radv_perftest_options
[id
].string
;
473 VkResult
radv_CreateInstance(
474 const VkInstanceCreateInfo
* pCreateInfo
,
475 const VkAllocationCallbacks
* pAllocator
,
476 VkInstance
* pInstance
)
478 struct radv_instance
*instance
;
480 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
482 uint32_t client_version
;
483 if (pCreateInfo
->pApplicationInfo
&&
484 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
485 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
487 client_version
= VK_MAKE_VERSION(1, 0, 0);
490 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
491 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
492 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
493 "Client requested version %d.%d.%d",
494 VK_VERSION_MAJOR(client_version
),
495 VK_VERSION_MINOR(client_version
),
496 VK_VERSION_PATCH(client_version
));
499 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
500 if (!is_extension_enabled(instance_extensions
,
501 ARRAY_SIZE(instance_extensions
),
502 pCreateInfo
->ppEnabledExtensionNames
[i
]))
503 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
506 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
507 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
509 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
511 memset(instance
, 0, sizeof(*instance
));
513 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
516 instance
->alloc
= *pAllocator
;
518 instance
->alloc
= default_alloc
;
520 instance
->apiVersion
= client_version
;
521 instance
->physicalDeviceCount
= -1;
525 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
527 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
530 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
531 radv_perftest_options
);
533 *pInstance
= radv_instance_to_handle(instance
);
538 void radv_DestroyInstance(
539 VkInstance _instance
,
540 const VkAllocationCallbacks
* pAllocator
)
542 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
547 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
548 radv_physical_device_finish(instance
->physicalDevices
+ i
);
551 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
555 vk_free(&instance
->alloc
, instance
);
559 radv_enumerate_devices(struct radv_instance
*instance
)
561 /* TODO: Check for more devices ? */
562 drmDevicePtr devices
[8];
563 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
566 instance
->physicalDeviceCount
= 0;
568 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
570 return VK_ERROR_INCOMPATIBLE_DRIVER
;
572 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
573 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
574 devices
[i
]->bustype
== DRM_BUS_PCI
&&
575 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
577 result
= radv_physical_device_init(instance
->physicalDevices
+
578 instance
->physicalDeviceCount
,
581 if (result
== VK_SUCCESS
)
582 ++instance
->physicalDeviceCount
;
583 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
587 drmFreeDevices(devices
, max_devices
);
592 VkResult
radv_EnumeratePhysicalDevices(
593 VkInstance _instance
,
594 uint32_t* pPhysicalDeviceCount
,
595 VkPhysicalDevice
* pPhysicalDevices
)
597 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
600 if (instance
->physicalDeviceCount
< 0) {
601 result
= radv_enumerate_devices(instance
);
602 if (result
!= VK_SUCCESS
&&
603 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
607 if (!pPhysicalDevices
) {
608 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
610 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
611 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
612 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
615 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
619 void radv_GetPhysicalDeviceFeatures(
620 VkPhysicalDevice physicalDevice
,
621 VkPhysicalDeviceFeatures
* pFeatures
)
623 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
624 bool is_gfx9
= pdevice
->rad_info
.chip_class
>= GFX9
;
625 memset(pFeatures
, 0, sizeof(*pFeatures
));
627 *pFeatures
= (VkPhysicalDeviceFeatures
) {
628 .robustBufferAccess
= true,
629 .fullDrawIndexUint32
= true,
630 .imageCubeArray
= true,
631 .independentBlend
= true,
632 .geometryShader
= !is_gfx9
,
633 .tessellationShader
= !is_gfx9
,
634 .sampleRateShading
= true,
635 .dualSrcBlend
= true,
637 .multiDrawIndirect
= true,
638 .drawIndirectFirstInstance
= true,
640 .depthBiasClamp
= true,
641 .fillModeNonSolid
= true,
646 .multiViewport
= true,
647 .samplerAnisotropy
= true,
648 .textureCompressionETC2
= false,
649 .textureCompressionASTC_LDR
= false,
650 .textureCompressionBC
= true,
651 .occlusionQueryPrecise
= true,
652 .pipelineStatisticsQuery
= true,
653 .vertexPipelineStoresAndAtomics
= true,
654 .fragmentStoresAndAtomics
= true,
655 .shaderTessellationAndGeometryPointSize
= true,
656 .shaderImageGatherExtended
= true,
657 .shaderStorageImageExtendedFormats
= true,
658 .shaderStorageImageMultisample
= false,
659 .shaderUniformBufferArrayDynamicIndexing
= true,
660 .shaderSampledImageArrayDynamicIndexing
= true,
661 .shaderStorageBufferArrayDynamicIndexing
= true,
662 .shaderStorageImageArrayDynamicIndexing
= true,
663 .shaderStorageImageReadWithoutFormat
= true,
664 .shaderStorageImageWriteWithoutFormat
= true,
665 .shaderClipDistance
= true,
666 .shaderCullDistance
= true,
667 .shaderFloat64
= true,
669 .shaderInt16
= false,
670 .sparseBinding
= true,
671 .variableMultisampleRate
= true,
672 .inheritedQueries
= true,
676 void radv_GetPhysicalDeviceFeatures2KHR(
677 VkPhysicalDevice physicalDevice
,
678 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
680 vk_foreach_struct(ext
, pFeatures
->pNext
) {
681 switch (ext
->sType
) {
682 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
683 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
684 features
->variablePointersStorageBuffer
= true;
685 features
->variablePointers
= false;
688 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
689 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
690 features
->multiview
= true;
691 features
->multiviewGeometryShader
= true;
692 features
->multiviewTessellationShader
= true;
699 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
702 void radv_GetPhysicalDeviceProperties(
703 VkPhysicalDevice physicalDevice
,
704 VkPhysicalDeviceProperties
* pProperties
)
706 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
707 VkSampleCountFlags sample_counts
= 0xf;
709 /* make sure that the entire descriptor set is addressable with a signed
710 * 32-bit int. So the sum of all limits scaled by descriptor size has to
711 * be at most 2 GiB. the combined image & samples object count as one of
712 * both. This limit is for the pipeline layout, not for the set layout, but
713 * there is no set limit, so we just set a pipeline limit. I don't think
714 * any app is going to hit this soon. */
715 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
716 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
717 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
718 32 /* sampler, largest when combined with image */ +
719 64 /* sampled image */ +
720 64 /* storage image */);
722 VkPhysicalDeviceLimits limits
= {
723 .maxImageDimension1D
= (1 << 14),
724 .maxImageDimension2D
= (1 << 14),
725 .maxImageDimension3D
= (1 << 11),
726 .maxImageDimensionCube
= (1 << 14),
727 .maxImageArrayLayers
= (1 << 11),
728 .maxTexelBufferElements
= 128 * 1024 * 1024,
729 .maxUniformBufferRange
= UINT32_MAX
,
730 .maxStorageBufferRange
= UINT32_MAX
,
731 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
732 .maxMemoryAllocationCount
= UINT32_MAX
,
733 .maxSamplerAllocationCount
= 64 * 1024,
734 .bufferImageGranularity
= 64, /* A cache line */
735 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
736 .maxBoundDescriptorSets
= MAX_SETS
,
737 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
738 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
739 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
740 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
741 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
742 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
743 .maxPerStageResources
= max_descriptor_set_size
,
744 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
745 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
746 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
747 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
748 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
749 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
750 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
751 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
752 .maxVertexInputAttributes
= 32,
753 .maxVertexInputBindings
= 32,
754 .maxVertexInputAttributeOffset
= 2047,
755 .maxVertexInputBindingStride
= 2048,
756 .maxVertexOutputComponents
= 128,
757 .maxTessellationGenerationLevel
= 64,
758 .maxTessellationPatchSize
= 32,
759 .maxTessellationControlPerVertexInputComponents
= 128,
760 .maxTessellationControlPerVertexOutputComponents
= 128,
761 .maxTessellationControlPerPatchOutputComponents
= 120,
762 .maxTessellationControlTotalOutputComponents
= 4096,
763 .maxTessellationEvaluationInputComponents
= 128,
764 .maxTessellationEvaluationOutputComponents
= 128,
765 .maxGeometryShaderInvocations
= 127,
766 .maxGeometryInputComponents
= 64,
767 .maxGeometryOutputComponents
= 128,
768 .maxGeometryOutputVertices
= 256,
769 .maxGeometryTotalOutputComponents
= 1024,
770 .maxFragmentInputComponents
= 128,
771 .maxFragmentOutputAttachments
= 8,
772 .maxFragmentDualSrcAttachments
= 1,
773 .maxFragmentCombinedOutputResources
= 8,
774 .maxComputeSharedMemorySize
= 32768,
775 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
776 .maxComputeWorkGroupInvocations
= 2048,
777 .maxComputeWorkGroupSize
= {
782 .subPixelPrecisionBits
= 4 /* FIXME */,
783 .subTexelPrecisionBits
= 4 /* FIXME */,
784 .mipmapPrecisionBits
= 4 /* FIXME */,
785 .maxDrawIndexedIndexValue
= UINT32_MAX
,
786 .maxDrawIndirectCount
= UINT32_MAX
,
787 .maxSamplerLodBias
= 16,
788 .maxSamplerAnisotropy
= 16,
789 .maxViewports
= MAX_VIEWPORTS
,
790 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
791 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
792 .viewportSubPixelBits
= 13, /* We take a float? */
793 .minMemoryMapAlignment
= 4096, /* A page */
794 .minTexelBufferOffsetAlignment
= 1,
795 .minUniformBufferOffsetAlignment
= 4,
796 .minStorageBufferOffsetAlignment
= 4,
797 .minTexelOffset
= -32,
798 .maxTexelOffset
= 31,
799 .minTexelGatherOffset
= -32,
800 .maxTexelGatherOffset
= 31,
801 .minInterpolationOffset
= -2,
802 .maxInterpolationOffset
= 2,
803 .subPixelInterpolationOffsetBits
= 8,
804 .maxFramebufferWidth
= (1 << 14),
805 .maxFramebufferHeight
= (1 << 14),
806 .maxFramebufferLayers
= (1 << 10),
807 .framebufferColorSampleCounts
= sample_counts
,
808 .framebufferDepthSampleCounts
= sample_counts
,
809 .framebufferStencilSampleCounts
= sample_counts
,
810 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
811 .maxColorAttachments
= MAX_RTS
,
812 .sampledImageColorSampleCounts
= sample_counts
,
813 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
814 .sampledImageDepthSampleCounts
= sample_counts
,
815 .sampledImageStencilSampleCounts
= sample_counts
,
816 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
817 .maxSampleMaskWords
= 1,
818 .timestampComputeAndGraphics
= true,
819 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
820 .maxClipDistances
= 8,
821 .maxCullDistances
= 8,
822 .maxCombinedClipAndCullDistances
= 8,
823 .discreteQueuePriorities
= 1,
824 .pointSizeRange
= { 0.125, 255.875 },
825 .lineWidthRange
= { 0.0, 7.9921875 },
826 .pointSizeGranularity
= (1.0 / 8.0),
827 .lineWidthGranularity
= (1.0 / 128.0),
828 .strictLines
= false, /* FINISHME */
829 .standardSampleLocations
= true,
830 .optimalBufferCopyOffsetAlignment
= 128,
831 .optimalBufferCopyRowPitchAlignment
= 128,
832 .nonCoherentAtomSize
= 64,
835 *pProperties
= (VkPhysicalDeviceProperties
) {
836 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
837 .driverVersion
= vk_get_driver_version(),
838 .vendorID
= ATI_VENDOR_ID
,
839 .deviceID
= pdevice
->rad_info
.pci_id
,
840 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
842 .sparseProperties
= {0},
845 strcpy(pProperties
->deviceName
, pdevice
->name
);
846 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
849 void radv_GetPhysicalDeviceProperties2KHR(
850 VkPhysicalDevice physicalDevice
,
851 VkPhysicalDeviceProperties2KHR
*pProperties
)
853 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
854 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
856 vk_foreach_struct(ext
, pProperties
->pNext
) {
857 switch (ext
->sType
) {
858 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
859 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
860 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
861 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
864 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
865 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
866 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
867 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
868 properties
->deviceLUIDValid
= false;
871 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
872 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
873 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
874 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
877 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
878 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
879 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
880 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
889 static void radv_get_physical_device_queue_family_properties(
890 struct radv_physical_device
* pdevice
,
892 VkQueueFamilyProperties
** pQueueFamilyProperties
)
894 int num_queue_families
= 1;
896 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
897 pdevice
->rad_info
.chip_class
>= CIK
&&
898 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
899 num_queue_families
++;
901 if (pQueueFamilyProperties
== NULL
) {
902 *pCount
= num_queue_families
;
911 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
912 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
913 VK_QUEUE_COMPUTE_BIT
|
914 VK_QUEUE_TRANSFER_BIT
|
915 VK_QUEUE_SPARSE_BINDING_BIT
,
917 .timestampValidBits
= 64,
918 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
923 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
924 pdevice
->rad_info
.chip_class
>= CIK
&&
925 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
927 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
928 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
929 VK_QUEUE_TRANSFER_BIT
|
930 VK_QUEUE_SPARSE_BINDING_BIT
,
931 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
932 .timestampValidBits
= 64,
933 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
941 void radv_GetPhysicalDeviceQueueFamilyProperties(
942 VkPhysicalDevice physicalDevice
,
944 VkQueueFamilyProperties
* pQueueFamilyProperties
)
946 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
947 if (!pQueueFamilyProperties
) {
948 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
951 VkQueueFamilyProperties
*properties
[] = {
952 pQueueFamilyProperties
+ 0,
953 pQueueFamilyProperties
+ 1,
954 pQueueFamilyProperties
+ 2,
956 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
957 assert(*pCount
<= 3);
960 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
961 VkPhysicalDevice physicalDevice
,
963 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
965 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
966 if (!pQueueFamilyProperties
) {
967 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
970 VkQueueFamilyProperties
*properties
[] = {
971 &pQueueFamilyProperties
[0].queueFamilyProperties
,
972 &pQueueFamilyProperties
[1].queueFamilyProperties
,
973 &pQueueFamilyProperties
[2].queueFamilyProperties
,
975 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
976 assert(*pCount
<= 3);
979 void radv_GetPhysicalDeviceMemoryProperties(
980 VkPhysicalDevice physicalDevice
,
981 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
983 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
985 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
987 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
988 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
989 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
990 .heapIndex
= RADV_MEM_HEAP_VRAM
,
992 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
993 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
994 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
995 .heapIndex
= RADV_MEM_HEAP_GTT
,
997 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
998 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
999 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1000 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
1001 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
1003 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
1004 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1005 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
1006 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
1007 .heapIndex
= RADV_MEM_HEAP_GTT
,
1010 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
1011 uint64_t visible_vram_size
= MIN2(physical_device
->rad_info
.vram_size
,
1012 physical_device
->rad_info
.vram_vis_size
);
1014 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
1015 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
1016 .size
= physical_device
->rad_info
.vram_size
-
1018 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
1020 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
1021 .size
= visible_vram_size
,
1022 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
1024 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
1025 .size
= physical_device
->rad_info
.gart_size
,
1030 void radv_GetPhysicalDeviceMemoryProperties2KHR(
1031 VkPhysicalDevice physicalDevice
,
1032 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1034 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1035 &pMemoryProperties
->memoryProperties
);
1039 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1040 int queue_family_index
, int idx
)
1042 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1043 queue
->device
= device
;
1044 queue
->queue_family_index
= queue_family_index
;
1045 queue
->queue_idx
= idx
;
1047 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
1049 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1055 radv_queue_finish(struct radv_queue
*queue
)
1058 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1060 if (queue
->initial_full_flush_preamble_cs
)
1061 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1062 if (queue
->initial_preamble_cs
)
1063 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1064 if (queue
->continue_preamble_cs
)
1065 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1066 if (queue
->descriptor_bo
)
1067 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1068 if (queue
->scratch_bo
)
1069 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1070 if (queue
->esgs_ring_bo
)
1071 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1072 if (queue
->gsvs_ring_bo
)
1073 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1074 if (queue
->tess_factor_ring_bo
)
1075 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
1076 if (queue
->tess_offchip_ring_bo
)
1077 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
1078 if (queue
->compute_scratch_bo
)
1079 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1083 radv_device_init_gs_info(struct radv_device
*device
)
1085 switch (device
->physical_device
->rad_info
.family
) {
1094 device
->gs_table_depth
= 16;
1103 case CHIP_POLARIS10
:
1104 case CHIP_POLARIS11
:
1105 case CHIP_POLARIS12
:
1108 device
->gs_table_depth
= 32;
1111 unreachable("unknown GPU");
1115 VkResult
radv_CreateDevice(
1116 VkPhysicalDevice physicalDevice
,
1117 const VkDeviceCreateInfo
* pCreateInfo
,
1118 const VkAllocationCallbacks
* pAllocator
,
1121 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1123 struct radv_device
*device
;
1125 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1126 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
1127 physical_device
->extensions
.num_ext
,
1128 pCreateInfo
->ppEnabledExtensionNames
[i
]))
1129 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1132 /* Check enabled features */
1133 if (pCreateInfo
->pEnabledFeatures
) {
1134 VkPhysicalDeviceFeatures supported_features
;
1135 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1136 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1137 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1138 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1139 for (uint32_t i
= 0; i
< num_features
; i
++) {
1140 if (enabled_feature
[i
] && !supported_feature
[i
])
1141 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1145 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1147 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1149 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1151 memset(device
, 0, sizeof(*device
));
1153 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1154 device
->instance
= physical_device
->instance
;
1155 device
->physical_device
= physical_device
;
1157 device
->debug_flags
= device
->instance
->debug_flags
;
1159 device
->ws
= physical_device
->ws
;
1161 device
->alloc
= *pAllocator
;
1163 device
->alloc
= physical_device
->instance
->alloc
;
1165 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1166 list_inithead(&device
->shader_slabs
);
1168 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1169 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1170 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1172 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1173 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1174 if (!device
->queues
[qfi
]) {
1175 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1179 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1181 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1183 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1184 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
1185 if (result
!= VK_SUCCESS
)
1190 #if HAVE_LLVM < 0x0400
1191 device
->llvm_supports_spill
= false;
1193 device
->llvm_supports_spill
= true;
1196 /* The maximum number of scratch waves. Scratch space isn't divided
1197 * evenly between CUs. The number is only a function of the number of CUs.
1198 * We can decrease the constant to decrease the scratch buffer size.
1200 * sctx->scratch_waves must be >= the maximum posible size of
1201 * 1 threadgroup, so that the hw doesn't hang from being unable
1204 * The recommended value is 4 per CU at most. Higher numbers don't
1205 * bring much benefit, but they still occupy chip resources (think
1206 * async compute). I've seen ~2% performance difference between 4 and 32.
1208 uint32_t max_threads_per_block
= 2048;
1209 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1210 max_threads_per_block
/ 64);
1212 radv_device_init_gs_info(device
);
1214 device
->tess_offchip_block_dw_size
=
1215 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1216 device
->has_distributed_tess
=
1217 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1218 device
->physical_device
->rad_info
.max_se
>= 2;
1220 if (getenv("RADV_TRACE_FILE")) {
1221 if (!radv_init_trace(device
))
1225 result
= radv_device_init_meta(device
);
1226 if (result
!= VK_SUCCESS
)
1229 radv_device_init_msaa(device
);
1231 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1232 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1234 case RADV_QUEUE_GENERAL
:
1235 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1236 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1237 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1239 case RADV_QUEUE_COMPUTE
:
1240 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1241 radeon_emit(device
->empty_cs
[family
], 0);
1244 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1247 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1248 cik_create_gfx_config(device
);
1250 VkPipelineCacheCreateInfo ci
;
1251 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1254 ci
.pInitialData
= NULL
;
1255 ci
.initialDataSize
= 0;
1257 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1259 if (result
!= VK_SUCCESS
)
1262 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1264 *pDevice
= radv_device_to_handle(device
);
1268 if (device
->trace_bo
)
1269 device
->ws
->buffer_destroy(device
->trace_bo
);
1271 if (device
->gfx_init
)
1272 device
->ws
->buffer_destroy(device
->gfx_init
);
1274 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1275 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1276 radv_queue_finish(&device
->queues
[i
][q
]);
1277 if (device
->queue_count
[i
])
1278 vk_free(&device
->alloc
, device
->queues
[i
]);
1281 vk_free(&device
->alloc
, device
);
1285 void radv_DestroyDevice(
1287 const VkAllocationCallbacks
* pAllocator
)
1289 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1294 if (device
->trace_bo
)
1295 device
->ws
->buffer_destroy(device
->trace_bo
);
1297 if (device
->gfx_init
)
1298 device
->ws
->buffer_destroy(device
->gfx_init
);
1300 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1301 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1302 radv_queue_finish(&device
->queues
[i
][q
]);
1303 if (device
->queue_count
[i
])
1304 vk_free(&device
->alloc
, device
->queues
[i
]);
1305 if (device
->empty_cs
[i
])
1306 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1308 radv_device_finish_meta(device
);
1310 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1311 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1313 radv_destroy_shader_slabs(device
);
1315 vk_free(&device
->alloc
, device
);
1318 VkResult
radv_EnumerateInstanceExtensionProperties(
1319 const char* pLayerName
,
1320 uint32_t* pPropertyCount
,
1321 VkExtensionProperties
* pProperties
)
1323 if (pProperties
== NULL
) {
1324 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1328 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1329 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1331 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1332 return VK_INCOMPLETE
;
1337 VkResult
radv_EnumerateDeviceExtensionProperties(
1338 VkPhysicalDevice physicalDevice
,
1339 const char* pLayerName
,
1340 uint32_t* pPropertyCount
,
1341 VkExtensionProperties
* pProperties
)
1343 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1345 if (pProperties
== NULL
) {
1346 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1350 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1351 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1353 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1354 return VK_INCOMPLETE
;
1359 VkResult
radv_EnumerateInstanceLayerProperties(
1360 uint32_t* pPropertyCount
,
1361 VkLayerProperties
* pProperties
)
1363 if (pProperties
== NULL
) {
1364 *pPropertyCount
= 0;
1368 /* None supported at this time */
1369 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1372 VkResult
radv_EnumerateDeviceLayerProperties(
1373 VkPhysicalDevice physicalDevice
,
1374 uint32_t* pPropertyCount
,
1375 VkLayerProperties
* pProperties
)
1377 if (pProperties
== NULL
) {
1378 *pPropertyCount
= 0;
1382 /* None supported at this time */
1383 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1386 void radv_GetDeviceQueue(
1388 uint32_t queueFamilyIndex
,
1389 uint32_t queueIndex
,
1392 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1394 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1398 fill_geom_tess_rings(struct radv_queue
*queue
,
1400 bool add_sample_positions
,
1401 uint32_t esgs_ring_size
,
1402 struct radeon_winsys_bo
*esgs_ring_bo
,
1403 uint32_t gsvs_ring_size
,
1404 struct radeon_winsys_bo
*gsvs_ring_bo
,
1405 uint32_t tess_factor_ring_size
,
1406 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1407 uint32_t tess_offchip_ring_size
,
1408 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1410 uint64_t esgs_va
= 0, gsvs_va
= 0;
1411 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1412 uint32_t *desc
= &map
[4];
1415 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1417 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1418 if (tess_factor_ring_bo
)
1419 tess_factor_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1420 if (tess_offchip_ring_bo
)
1421 tess_offchip_va
= radv_buffer_get_va(tess_offchip_ring_bo
);
1423 /* stride 0, num records - size, add tid, swizzle, elsize4,
1426 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1427 S_008F04_STRIDE(0) |
1428 S_008F04_SWIZZLE_ENABLE(true);
1429 desc
[2] = esgs_ring_size
;
1430 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1431 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1432 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1433 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1434 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1435 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1436 S_008F0C_ELEMENT_SIZE(1) |
1437 S_008F0C_INDEX_STRIDE(3) |
1438 S_008F0C_ADD_TID_ENABLE(true);
1441 /* GS entry for ES->GS ring */
1442 /* stride 0, num records - size, elsize0,
1445 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1446 S_008F04_STRIDE(0) |
1447 S_008F04_SWIZZLE_ENABLE(false);
1448 desc
[2] = esgs_ring_size
;
1449 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1450 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1451 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1452 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1453 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1454 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1455 S_008F0C_ELEMENT_SIZE(0) |
1456 S_008F0C_INDEX_STRIDE(0) |
1457 S_008F0C_ADD_TID_ENABLE(false);
1460 /* VS entry for GS->VS ring */
1461 /* stride 0, num records - size, elsize0,
1464 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1465 S_008F04_STRIDE(0) |
1466 S_008F04_SWIZZLE_ENABLE(false);
1467 desc
[2] = gsvs_ring_size
;
1468 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1469 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1470 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1471 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1472 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1473 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1474 S_008F0C_ELEMENT_SIZE(0) |
1475 S_008F0C_INDEX_STRIDE(0) |
1476 S_008F0C_ADD_TID_ENABLE(false);
1479 /* stride gsvs_itemsize, num records 64
1480 elsize 4, index stride 16 */
1481 /* shader will patch stride and desc[2] */
1483 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1484 S_008F04_STRIDE(0) |
1485 S_008F04_SWIZZLE_ENABLE(true);
1487 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1488 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1489 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1490 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1491 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1492 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1493 S_008F0C_ELEMENT_SIZE(1) |
1494 S_008F0C_INDEX_STRIDE(1) |
1495 S_008F0C_ADD_TID_ENABLE(true);
1498 desc
[0] = tess_factor_va
;
1499 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1500 S_008F04_STRIDE(0) |
1501 S_008F04_SWIZZLE_ENABLE(false);
1502 desc
[2] = tess_factor_ring_size
;
1503 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1504 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1505 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1506 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1507 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1508 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1509 S_008F0C_ELEMENT_SIZE(0) |
1510 S_008F0C_INDEX_STRIDE(0) |
1511 S_008F0C_ADD_TID_ENABLE(false);
1514 desc
[0] = tess_offchip_va
;
1515 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1516 S_008F04_STRIDE(0) |
1517 S_008F04_SWIZZLE_ENABLE(false);
1518 desc
[2] = tess_offchip_ring_size
;
1519 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1520 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1521 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1522 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1523 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1524 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1525 S_008F0C_ELEMENT_SIZE(0) |
1526 S_008F0C_INDEX_STRIDE(0) |
1527 S_008F0C_ADD_TID_ENABLE(false);
1530 /* add sample positions after all rings */
1531 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1533 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1535 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1537 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1539 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1543 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1545 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1546 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1547 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1548 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1549 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1550 device
->physical_device
->rad_info
.max_se
;
1551 unsigned offchip_granularity
;
1552 unsigned hs_offchip_param
;
1553 switch (device
->tess_offchip_block_dw_size
) {
1558 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1561 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1565 switch (device
->physical_device
->rad_info
.chip_class
) {
1567 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1573 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1577 *max_offchip_buffers_p
= max_offchip_buffers
;
1578 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1579 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1580 --max_offchip_buffers
;
1582 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1583 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1586 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1588 return hs_offchip_param
;
1592 radv_get_preamble_cs(struct radv_queue
*queue
,
1593 uint32_t scratch_size
,
1594 uint32_t compute_scratch_size
,
1595 uint32_t esgs_ring_size
,
1596 uint32_t gsvs_ring_size
,
1597 bool needs_tess_rings
,
1598 bool needs_sample_positions
,
1599 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1600 struct radeon_winsys_cs
**initial_preamble_cs
,
1601 struct radeon_winsys_cs
**continue_preamble_cs
)
1603 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1604 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1605 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1606 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1607 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1608 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1609 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1610 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1611 bool add_tess_rings
= false, add_sample_positions
= false;
1612 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1613 unsigned max_offchip_buffers
;
1614 unsigned hs_offchip_param
= 0;
1615 if (!queue
->has_tess_rings
) {
1616 if (needs_tess_rings
)
1617 add_tess_rings
= true;
1619 if (!queue
->has_sample_positions
) {
1620 if (needs_sample_positions
)
1621 add_sample_positions
= true;
1623 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1624 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1625 &max_offchip_buffers
);
1626 tess_offchip_ring_size
= max_offchip_buffers
*
1627 queue
->device
->tess_offchip_block_dw_size
* 4;
1629 if (scratch_size
<= queue
->scratch_size
&&
1630 compute_scratch_size
<= queue
->compute_scratch_size
&&
1631 esgs_ring_size
<= queue
->esgs_ring_size
&&
1632 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1633 !add_tess_rings
&& !add_sample_positions
&&
1634 queue
->initial_preamble_cs
) {
1635 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1636 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1637 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1638 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1639 *continue_preamble_cs
= NULL
;
1643 if (scratch_size
> queue
->scratch_size
) {
1644 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1648 RADEON_FLAG_NO_CPU_ACCESS
);
1652 scratch_bo
= queue
->scratch_bo
;
1654 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1655 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1656 compute_scratch_size
,
1659 RADEON_FLAG_NO_CPU_ACCESS
);
1660 if (!compute_scratch_bo
)
1664 compute_scratch_bo
= queue
->compute_scratch_bo
;
1666 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1667 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1671 RADEON_FLAG_NO_CPU_ACCESS
);
1675 esgs_ring_bo
= queue
->esgs_ring_bo
;
1676 esgs_ring_size
= queue
->esgs_ring_size
;
1679 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1680 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1684 RADEON_FLAG_NO_CPU_ACCESS
);
1688 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1689 gsvs_ring_size
= queue
->gsvs_ring_size
;
1692 if (add_tess_rings
) {
1693 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1694 tess_factor_ring_size
,
1697 RADEON_FLAG_NO_CPU_ACCESS
);
1698 if (!tess_factor_ring_bo
)
1700 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1701 tess_offchip_ring_size
,
1704 RADEON_FLAG_NO_CPU_ACCESS
);
1705 if (!tess_offchip_ring_bo
)
1708 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1709 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1712 if (scratch_bo
!= queue
->scratch_bo
||
1713 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1714 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1715 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1716 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1718 if (gsvs_ring_bo
|| esgs_ring_bo
||
1719 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1720 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1721 if (add_sample_positions
)
1722 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1724 else if (scratch_bo
)
1725 size
= 8; /* 2 dword */
1727 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1731 RADEON_FLAG_CPU_ACCESS
);
1735 descriptor_bo
= queue
->descriptor_bo
;
1737 for(int i
= 0; i
< 3; ++i
) {
1738 struct radeon_winsys_cs
*cs
= NULL
;
1739 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1740 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1747 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1750 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1753 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1755 if (tess_factor_ring_bo
)
1756 queue
->device
->ws
->cs_add_buffer(cs
, tess_factor_ring_bo
, 8);
1758 if (tess_offchip_ring_bo
)
1759 queue
->device
->ws
->cs_add_buffer(cs
, tess_offchip_ring_bo
, 8);
1762 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1764 if (descriptor_bo
!= queue
->descriptor_bo
) {
1765 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1768 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1769 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1770 S_008F04_SWIZZLE_ENABLE(1);
1771 map
[0] = scratch_va
;
1775 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1776 add_sample_positions
)
1777 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1778 esgs_ring_size
, esgs_ring_bo
,
1779 gsvs_ring_size
, gsvs_ring_bo
,
1780 tess_factor_ring_size
, tess_factor_ring_bo
,
1781 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1783 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1786 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1787 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1788 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1789 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1790 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1793 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1794 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1795 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1796 radeon_emit(cs
, esgs_ring_size
>> 8);
1797 radeon_emit(cs
, gsvs_ring_size
>> 8);
1799 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1800 radeon_emit(cs
, esgs_ring_size
>> 8);
1801 radeon_emit(cs
, gsvs_ring_size
>> 8);
1805 if (tess_factor_ring_bo
) {
1806 uint64_t tf_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1807 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1808 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1809 S_030938_SIZE(tess_factor_ring_size
/ 4));
1810 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1812 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1813 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1816 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1818 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1819 S_008988_SIZE(tess_factor_ring_size
/ 4));
1820 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1822 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1827 if (descriptor_bo
) {
1828 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1829 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1830 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1831 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1832 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1833 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1835 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1837 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1838 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1839 radeon_emit(cs
, va
);
1840 radeon_emit(cs
, va
>> 32);
1844 if (compute_scratch_bo
) {
1845 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1846 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1847 S_008F04_SWIZZLE_ENABLE(1);
1849 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1851 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1852 radeon_emit(cs
, scratch_va
);
1853 radeon_emit(cs
, rsrc1
);
1857 si_cs_emit_cache_flush(cs
,
1859 queue
->device
->physical_device
->rad_info
.chip_class
,
1861 queue
->queue_family_index
== RING_COMPUTE
&&
1862 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1863 (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
)) |
1864 RADV_CMD_FLAG_INV_ICACHE
|
1865 RADV_CMD_FLAG_INV_SMEM_L1
|
1866 RADV_CMD_FLAG_INV_VMEM_L1
|
1867 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1868 } else if (i
== 1) {
1869 si_cs_emit_cache_flush(cs
,
1871 queue
->device
->physical_device
->rad_info
.chip_class
,
1873 queue
->queue_family_index
== RING_COMPUTE
&&
1874 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1875 RADV_CMD_FLAG_INV_ICACHE
|
1876 RADV_CMD_FLAG_INV_SMEM_L1
|
1877 RADV_CMD_FLAG_INV_VMEM_L1
|
1878 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1881 if (!queue
->device
->ws
->cs_finalize(cs
))
1885 if (queue
->initial_full_flush_preamble_cs
)
1886 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1888 if (queue
->initial_preamble_cs
)
1889 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1891 if (queue
->continue_preamble_cs
)
1892 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1894 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1895 queue
->initial_preamble_cs
= dest_cs
[1];
1896 queue
->continue_preamble_cs
= dest_cs
[2];
1898 if (scratch_bo
!= queue
->scratch_bo
) {
1899 if (queue
->scratch_bo
)
1900 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1901 queue
->scratch_bo
= scratch_bo
;
1902 queue
->scratch_size
= scratch_size
;
1905 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1906 if (queue
->compute_scratch_bo
)
1907 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1908 queue
->compute_scratch_bo
= compute_scratch_bo
;
1909 queue
->compute_scratch_size
= compute_scratch_size
;
1912 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1913 if (queue
->esgs_ring_bo
)
1914 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1915 queue
->esgs_ring_bo
= esgs_ring_bo
;
1916 queue
->esgs_ring_size
= esgs_ring_size
;
1919 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1920 if (queue
->gsvs_ring_bo
)
1921 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1922 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1923 queue
->gsvs_ring_size
= gsvs_ring_size
;
1926 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1927 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1930 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1931 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1932 queue
->has_tess_rings
= true;
1935 if (descriptor_bo
!= queue
->descriptor_bo
) {
1936 if (queue
->descriptor_bo
)
1937 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1939 queue
->descriptor_bo
= descriptor_bo
;
1942 if (add_sample_positions
)
1943 queue
->has_sample_positions
= true;
1945 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1946 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1947 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1948 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1949 *continue_preamble_cs
= NULL
;
1952 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1954 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1955 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1956 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1957 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1958 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1959 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1960 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1961 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1962 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1963 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1964 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1965 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1966 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1967 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1968 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1969 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1972 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1974 const VkSemaphore
*sems
,
1977 int syncobj_idx
= 0, sem_idx
= 0;
1981 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1982 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1984 if (sem
->temp_syncobj
|| sem
->syncobj
)
1985 counts
->syncobj_count
++;
1987 counts
->sem_count
++;
1990 if (counts
->syncobj_count
) {
1991 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
1992 if (!counts
->syncobj
)
1993 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1996 if (counts
->sem_count
) {
1997 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
1999 free(counts
->syncobj
);
2000 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2004 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2005 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2007 if (sem
->temp_syncobj
) {
2008 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2010 /* after we wait on a temp import - drop it */
2011 sem
->temp_syncobj
= 0;
2014 else if (sem
->syncobj
)
2015 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2018 counts
->sem
[sem_idx
++] = sem
->sem
;
2025 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2027 free(sem_info
->wait
.syncobj
);
2028 free(sem_info
->wait
.sem
);
2029 free(sem_info
->signal
.syncobj
);
2030 free(sem_info
->signal
.sem
);
2033 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2035 const VkSemaphore
*wait_sems
,
2036 int num_signal_sems
,
2037 const VkSemaphore
*signal_sems
)
2040 memset(sem_info
, 0, sizeof(*sem_info
));
2042 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, true);
2045 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, false);
2047 radv_free_sem_info(sem_info
);
2049 /* caller can override these */
2050 sem_info
->cs_emit_wait
= true;
2051 sem_info
->cs_emit_signal
= true;
2055 VkResult
radv_QueueSubmit(
2057 uint32_t submitCount
,
2058 const VkSubmitInfo
* pSubmits
,
2061 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2062 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2063 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2064 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2066 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2067 uint32_t scratch_size
= 0;
2068 uint32_t compute_scratch_size
= 0;
2069 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2070 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2072 bool fence_emitted
= false;
2073 bool tess_rings_needed
= false;
2074 bool sample_positions_needed
= false;
2076 /* Do this first so failing to allocate scratch buffers can't result in
2077 * partially executed submissions. */
2078 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2079 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2080 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2081 pSubmits
[i
].pCommandBuffers
[j
]);
2083 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2084 compute_scratch_size
= MAX2(compute_scratch_size
,
2085 cmd_buffer
->compute_scratch_size_needed
);
2086 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2087 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2088 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2089 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2093 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2094 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2095 sample_positions_needed
, &initial_flush_preamble_cs
,
2096 &initial_preamble_cs
, &continue_preamble_cs
);
2097 if (result
!= VK_SUCCESS
)
2100 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2101 struct radeon_winsys_cs
**cs_array
;
2102 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2103 bool can_patch
= true;
2105 struct radv_winsys_sem_info sem_info
;
2107 result
= radv_alloc_sem_info(&sem_info
,
2108 pSubmits
[i
].waitSemaphoreCount
,
2109 pSubmits
[i
].pWaitSemaphores
,
2110 pSubmits
[i
].signalSemaphoreCount
,
2111 pSubmits
[i
].pSignalSemaphores
);
2112 if (result
!= VK_SUCCESS
)
2115 if (!pSubmits
[i
].commandBufferCount
) {
2116 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2117 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2118 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2123 radv_loge("failed to submit CS %d\n", i
);
2126 fence_emitted
= true;
2128 radv_free_sem_info(&sem_info
);
2132 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2133 (pSubmits
[i
].commandBufferCount
));
2135 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2136 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2137 pSubmits
[i
].pCommandBuffers
[j
]);
2138 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2140 cs_array
[j
] = cmd_buffer
->cs
;
2141 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2145 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2146 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2147 advance
= MIN2(max_cs_submission
,
2148 pSubmits
[i
].commandBufferCount
- j
);
2150 if (queue
->device
->trace_bo
)
2151 *queue
->device
->trace_id_ptr
= 0;
2153 sem_info
.cs_emit_wait
= j
== 0;
2154 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2156 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2157 advance
, initial_preamble
, continue_preamble_cs
,
2159 can_patch
, base_fence
);
2162 radv_loge("failed to submit CS %d\n", i
);
2165 fence_emitted
= true;
2166 if (queue
->device
->trace_bo
) {
2167 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2171 radv_free_sem_info(&sem_info
);
2176 if (!fence_emitted
) {
2177 struct radv_winsys_sem_info sem_info
= {0};
2178 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2179 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2180 1, NULL
, NULL
, &sem_info
,
2183 fence
->submitted
= true;
2189 VkResult
radv_QueueWaitIdle(
2192 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2194 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2195 radv_queue_family_to_ring(queue
->queue_family_index
),
2200 VkResult
radv_DeviceWaitIdle(
2203 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2205 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2206 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2207 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2213 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2214 VkInstance instance
,
2217 return radv_lookup_entrypoint(pName
);
2220 /* The loader wants us to expose a second GetInstanceProcAddr function
2221 * to work around certain LD_PRELOAD issues seen in apps.
2224 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2225 VkInstance instance
,
2229 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2230 VkInstance instance
,
2233 return radv_GetInstanceProcAddr(instance
, pName
);
2236 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2240 return radv_lookup_entrypoint(pName
);
2243 bool radv_get_memory_fd(struct radv_device
*device
,
2244 struct radv_device_memory
*memory
,
2247 struct radeon_bo_metadata metadata
;
2249 if (memory
->image
) {
2250 radv_init_metadata(device
, memory
->image
, &metadata
);
2251 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2254 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2258 VkResult
radv_AllocateMemory(
2260 const VkMemoryAllocateInfo
* pAllocateInfo
,
2261 const VkAllocationCallbacks
* pAllocator
,
2262 VkDeviceMemory
* pMem
)
2264 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2265 struct radv_device_memory
*mem
;
2267 enum radeon_bo_domain domain
;
2270 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2272 if (pAllocateInfo
->allocationSize
== 0) {
2273 /* Apparently, this is allowed */
2274 *pMem
= VK_NULL_HANDLE
;
2278 const VkImportMemoryFdInfoKHR
*import_info
=
2279 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2280 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2281 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2283 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2284 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2286 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2288 if (dedicate_info
) {
2289 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2290 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2297 assert(import_info
->handleType
==
2298 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2299 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2302 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2305 close(import_info
->fd
);
2310 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2311 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2312 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
2313 domain
= RADEON_DOMAIN_GTT
;
2315 domain
= RADEON_DOMAIN_VRAM
;
2317 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
2318 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2320 flags
|= RADEON_FLAG_CPU_ACCESS
;
2322 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2323 flags
|= RADEON_FLAG_GTT_WC
;
2325 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2329 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2332 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
2334 *pMem
= radv_device_memory_to_handle(mem
);
2339 vk_free2(&device
->alloc
, pAllocator
, mem
);
2344 void radv_FreeMemory(
2346 VkDeviceMemory _mem
,
2347 const VkAllocationCallbacks
* pAllocator
)
2349 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2350 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2355 device
->ws
->buffer_destroy(mem
->bo
);
2358 vk_free2(&device
->alloc
, pAllocator
, mem
);
2361 VkResult
radv_MapMemory(
2363 VkDeviceMemory _memory
,
2364 VkDeviceSize offset
,
2366 VkMemoryMapFlags flags
,
2369 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2370 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2377 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2383 return VK_ERROR_MEMORY_MAP_FAILED
;
2386 void radv_UnmapMemory(
2388 VkDeviceMemory _memory
)
2390 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2391 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2396 device
->ws
->buffer_unmap(mem
->bo
);
2399 VkResult
radv_FlushMappedMemoryRanges(
2401 uint32_t memoryRangeCount
,
2402 const VkMappedMemoryRange
* pMemoryRanges
)
2407 VkResult
radv_InvalidateMappedMemoryRanges(
2409 uint32_t memoryRangeCount
,
2410 const VkMappedMemoryRange
* pMemoryRanges
)
2415 void radv_GetBufferMemoryRequirements(
2418 VkMemoryRequirements
* pMemoryRequirements
)
2420 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2422 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2424 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2425 pMemoryRequirements
->alignment
= 4096;
2427 pMemoryRequirements
->alignment
= 16;
2429 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2432 void radv_GetBufferMemoryRequirements2KHR(
2434 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2435 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2437 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2438 &pMemoryRequirements
->memoryRequirements
);
2440 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2441 switch (ext
->sType
) {
2442 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2443 VkMemoryDedicatedRequirementsKHR
*req
=
2444 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2445 req
->requiresDedicatedAllocation
= false;
2446 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2455 void radv_GetImageMemoryRequirements(
2458 VkMemoryRequirements
* pMemoryRequirements
)
2460 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2462 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2464 pMemoryRequirements
->size
= image
->size
;
2465 pMemoryRequirements
->alignment
= image
->alignment
;
2468 void radv_GetImageMemoryRequirements2KHR(
2470 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2471 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2473 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2474 &pMemoryRequirements
->memoryRequirements
);
2476 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2478 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2479 switch (ext
->sType
) {
2480 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2481 VkMemoryDedicatedRequirementsKHR
*req
=
2482 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2483 req
->requiresDedicatedAllocation
= image
->shareable
;
2484 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2493 void radv_GetImageSparseMemoryRequirements(
2496 uint32_t* pSparseMemoryRequirementCount
,
2497 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2502 void radv_GetImageSparseMemoryRequirements2KHR(
2504 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2505 uint32_t* pSparseMemoryRequirementCount
,
2506 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2511 void radv_GetDeviceMemoryCommitment(
2513 VkDeviceMemory memory
,
2514 VkDeviceSize
* pCommittedMemoryInBytes
)
2516 *pCommittedMemoryInBytes
= 0;
2519 VkResult
radv_BindBufferMemory2KHR(VkDevice device
,
2520 uint32_t bindInfoCount
,
2521 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2523 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2524 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2525 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2528 buffer
->bo
= mem
->bo
;
2529 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2537 VkResult
radv_BindBufferMemory(
2540 VkDeviceMemory memory
,
2541 VkDeviceSize memoryOffset
)
2543 const VkBindBufferMemoryInfoKHR info
= {
2544 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2547 .memoryOffset
= memoryOffset
2550 return radv_BindBufferMemory2KHR(device
, 1, &info
);
2553 VkResult
radv_BindImageMemory2KHR(VkDevice device
,
2554 uint32_t bindInfoCount
,
2555 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2557 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2558 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2559 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2562 image
->bo
= mem
->bo
;
2563 image
->offset
= pBindInfos
[i
].memoryOffset
;
2573 VkResult
radv_BindImageMemory(
2576 VkDeviceMemory memory
,
2577 VkDeviceSize memoryOffset
)
2579 const VkBindImageMemoryInfoKHR info
= {
2580 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2583 .memoryOffset
= memoryOffset
2586 return radv_BindImageMemory2KHR(device
, 1, &info
);
2591 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2592 const VkSparseBufferMemoryBindInfo
*bind
)
2594 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2596 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2597 struct radv_device_memory
*mem
= NULL
;
2599 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2600 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2602 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2603 bind
->pBinds
[i
].resourceOffset
,
2604 bind
->pBinds
[i
].size
,
2605 mem
? mem
->bo
: NULL
,
2606 bind
->pBinds
[i
].memoryOffset
);
2611 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2612 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2614 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2616 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2617 struct radv_device_memory
*mem
= NULL
;
2619 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2620 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2622 device
->ws
->buffer_virtual_bind(image
->bo
,
2623 bind
->pBinds
[i
].resourceOffset
,
2624 bind
->pBinds
[i
].size
,
2625 mem
? mem
->bo
: NULL
,
2626 bind
->pBinds
[i
].memoryOffset
);
2630 VkResult
radv_QueueBindSparse(
2632 uint32_t bindInfoCount
,
2633 const VkBindSparseInfo
* pBindInfo
,
2636 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2637 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2638 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2639 bool fence_emitted
= false;
2641 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2642 struct radv_winsys_sem_info sem_info
;
2643 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2644 radv_sparse_buffer_bind_memory(queue
->device
,
2645 pBindInfo
[i
].pBufferBinds
+ j
);
2648 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2649 radv_sparse_image_opaque_bind_memory(queue
->device
,
2650 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2654 result
= radv_alloc_sem_info(&sem_info
,
2655 pBindInfo
[i
].waitSemaphoreCount
,
2656 pBindInfo
[i
].pWaitSemaphores
,
2657 pBindInfo
[i
].signalSemaphoreCount
,
2658 pBindInfo
[i
].pSignalSemaphores
);
2659 if (result
!= VK_SUCCESS
)
2662 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2663 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2664 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2668 fence_emitted
= true;
2670 fence
->submitted
= true;
2673 radv_free_sem_info(&sem_info
);
2677 if (fence
&& !fence_emitted
) {
2678 fence
->signalled
= true;
2684 VkResult
radv_CreateFence(
2686 const VkFenceCreateInfo
* pCreateInfo
,
2687 const VkAllocationCallbacks
* pAllocator
,
2690 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2691 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2693 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2696 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2698 memset(fence
, 0, sizeof(*fence
));
2699 fence
->submitted
= false;
2700 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2701 fence
->fence
= device
->ws
->create_fence();
2702 if (!fence
->fence
) {
2703 vk_free2(&device
->alloc
, pAllocator
, fence
);
2704 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2707 *pFence
= radv_fence_to_handle(fence
);
2712 void radv_DestroyFence(
2715 const VkAllocationCallbacks
* pAllocator
)
2717 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2718 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2722 device
->ws
->destroy_fence(fence
->fence
);
2723 vk_free2(&device
->alloc
, pAllocator
, fence
);
2726 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2728 uint64_t current_time
;
2731 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2732 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2734 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2736 return current_time
+ timeout
;
2739 VkResult
radv_WaitForFences(
2741 uint32_t fenceCount
,
2742 const VkFence
* pFences
,
2746 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2747 timeout
= radv_get_absolute_timeout(timeout
);
2749 if (!waitAll
&& fenceCount
> 1) {
2750 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2753 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2754 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2755 bool expired
= false;
2757 if (fence
->signalled
)
2760 if (!fence
->submitted
)
2763 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2767 fence
->signalled
= true;
2773 VkResult
radv_ResetFences(VkDevice device
,
2774 uint32_t fenceCount
,
2775 const VkFence
*pFences
)
2777 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2778 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2779 fence
->submitted
= fence
->signalled
= false;
2785 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2787 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2788 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2790 if (fence
->signalled
)
2792 if (!fence
->submitted
)
2793 return VK_NOT_READY
;
2795 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2796 return VK_NOT_READY
;
2802 // Queue semaphore functions
2804 VkResult
radv_CreateSemaphore(
2806 const VkSemaphoreCreateInfo
* pCreateInfo
,
2807 const VkAllocationCallbacks
* pAllocator
,
2808 VkSemaphore
* pSemaphore
)
2810 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2811 const VkExportSemaphoreCreateInfoKHR
*export
=
2812 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2813 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2814 export
? export
->handleTypes
: 0;
2816 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2818 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2820 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2822 sem
->temp_syncobj
= 0;
2823 /* create a syncobject if we are going to export this semaphore */
2825 assert (device
->physical_device
->rad_info
.has_syncobj
);
2826 assert (handleTypes
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2827 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2829 vk_free2(&device
->alloc
, pAllocator
, sem
);
2830 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2834 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2836 vk_free2(&device
->alloc
, pAllocator
, sem
);
2837 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2842 *pSemaphore
= radv_semaphore_to_handle(sem
);
2846 void radv_DestroySemaphore(
2848 VkSemaphore _semaphore
,
2849 const VkAllocationCallbacks
* pAllocator
)
2851 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2852 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2857 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2859 device
->ws
->destroy_sem(sem
->sem
);
2860 vk_free2(&device
->alloc
, pAllocator
, sem
);
2863 VkResult
radv_CreateEvent(
2865 const VkEventCreateInfo
* pCreateInfo
,
2866 const VkAllocationCallbacks
* pAllocator
,
2869 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2870 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2872 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2875 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2877 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2879 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
);
2881 vk_free2(&device
->alloc
, pAllocator
, event
);
2882 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2885 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2887 *pEvent
= radv_event_to_handle(event
);
2892 void radv_DestroyEvent(
2895 const VkAllocationCallbacks
* pAllocator
)
2897 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2898 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2902 device
->ws
->buffer_destroy(event
->bo
);
2903 vk_free2(&device
->alloc
, pAllocator
, event
);
2906 VkResult
radv_GetEventStatus(
2910 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2912 if (*event
->map
== 1)
2913 return VK_EVENT_SET
;
2914 return VK_EVENT_RESET
;
2917 VkResult
radv_SetEvent(
2921 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2927 VkResult
radv_ResetEvent(
2931 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2937 VkResult
radv_CreateBuffer(
2939 const VkBufferCreateInfo
* pCreateInfo
,
2940 const VkAllocationCallbacks
* pAllocator
,
2943 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2944 struct radv_buffer
*buffer
;
2946 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2948 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2949 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2951 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2953 buffer
->size
= pCreateInfo
->size
;
2954 buffer
->usage
= pCreateInfo
->usage
;
2957 buffer
->flags
= pCreateInfo
->flags
;
2959 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2960 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2961 align64(buffer
->size
, 4096),
2962 4096, 0, RADEON_FLAG_VIRTUAL
);
2964 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2965 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2969 *pBuffer
= radv_buffer_to_handle(buffer
);
2974 void radv_DestroyBuffer(
2977 const VkAllocationCallbacks
* pAllocator
)
2979 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2980 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2985 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2986 device
->ws
->buffer_destroy(buffer
->bo
);
2988 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2991 static inline unsigned
2992 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
2995 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
2997 return image
->surface
.u
.legacy
.tiling_index
[level
];
3000 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
3002 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
3006 radv_initialise_color_surface(struct radv_device
*device
,
3007 struct radv_color_buffer_info
*cb
,
3008 struct radv_image_view
*iview
)
3010 const struct vk_format_description
*desc
;
3011 unsigned ntype
, format
, swap
, endian
;
3012 unsigned blend_clamp
= 0, blend_bypass
= 0;
3014 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3016 desc
= vk_format_description(iview
->vk_format
);
3018 memset(cb
, 0, sizeof(*cb
));
3020 /* Intensity is implemented as Red, so treat it that way. */
3021 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3023 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3025 cb
->cb_color_base
= va
>> 8;
3027 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3028 struct gfx9_surf_meta_flags meta
;
3029 if (iview
->image
->dcc_offset
)
3030 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3032 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3034 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3035 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3036 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3037 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3039 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3040 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3042 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3043 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3045 cb
->cb_color_base
+= level_info
->offset
>> 8;
3046 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3047 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3049 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3050 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3051 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3053 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3054 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3055 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3057 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3058 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
3060 if (iview
->image
->fmask
.size
) {
3061 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3062 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3063 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3064 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3066 /* This must be set for fast clear to work without FMASK. */
3067 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3068 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3069 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3070 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3074 /* CMASK variables */
3075 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3076 va
+= iview
->image
->cmask
.offset
;
3077 cb
->cb_color_cmask
= va
>> 8;
3079 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3080 va
+= iview
->image
->dcc_offset
;
3081 cb
->cb_dcc_base
= va
>> 8;
3082 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3084 uint32_t max_slice
= radv_surface_layer_count(iview
);
3085 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3086 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3088 if (iview
->image
->info
.samples
> 1) {
3089 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3091 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3092 S_028C74_NUM_FRAGMENTS(log_samples
);
3095 if (iview
->image
->fmask
.size
) {
3096 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3097 cb
->cb_color_fmask
= va
>> 8;
3098 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3100 cb
->cb_color_fmask
= cb
->cb_color_base
;
3103 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3105 vk_format_get_first_non_void_channel(iview
->vk_format
));
3106 format
= radv_translate_colorformat(iview
->vk_format
);
3107 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3108 radv_finishme("Illegal color\n");
3109 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3110 endian
= radv_colorformat_endian_swap(format
);
3112 /* blend clamp should be set for all NORM/SRGB types */
3113 if (ntype
== V_028C70_NUMBER_UNORM
||
3114 ntype
== V_028C70_NUMBER_SNORM
||
3115 ntype
== V_028C70_NUMBER_SRGB
)
3118 /* set blend bypass according to docs if SINT/UINT or
3119 8/24 COLOR variants */
3120 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3121 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3122 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3127 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3128 (format
== V_028C70_COLOR_8
||
3129 format
== V_028C70_COLOR_8_8
||
3130 format
== V_028C70_COLOR_8_8_8_8
))
3131 ->color_is_int8
= true;
3133 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3134 S_028C70_COMP_SWAP(swap
) |
3135 S_028C70_BLEND_CLAMP(blend_clamp
) |
3136 S_028C70_BLEND_BYPASS(blend_bypass
) |
3137 S_028C70_SIMPLE_FLOAT(1) |
3138 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3139 ntype
!= V_028C70_NUMBER_SNORM
&&
3140 ntype
!= V_028C70_NUMBER_SRGB
&&
3141 format
!= V_028C70_COLOR_8_24
&&
3142 format
!= V_028C70_COLOR_24_8
) |
3143 S_028C70_NUMBER_TYPE(ntype
) |
3144 S_028C70_ENDIAN(endian
);
3145 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3146 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3147 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3148 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3149 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3153 if (iview
->image
->cmask
.size
&&
3154 !(device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3155 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3157 if (radv_vi_dcc_enabled(iview
->image
, iview
->base_mip
))
3158 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3160 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3161 unsigned max_uncompressed_block_size
= 2;
3162 if (iview
->image
->info
.samples
> 1) {
3163 if (iview
->image
->surface
.bpe
== 1)
3164 max_uncompressed_block_size
= 0;
3165 else if (iview
->image
->surface
.bpe
== 2)
3166 max_uncompressed_block_size
= 1;
3169 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3170 S_028C78_INDEPENDENT_64B_BLOCKS(1);
3173 /* This must be set for fast clear to work without FMASK. */
3174 if (!iview
->image
->fmask
.size
&&
3175 device
->physical_device
->rad_info
.chip_class
== SI
) {
3176 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3177 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3180 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3181 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3182 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3184 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3185 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3186 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3187 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3188 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3189 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3191 cb
->gfx9_epitch
= S_0287A0_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3197 radv_initialise_ds_surface(struct radv_device
*device
,
3198 struct radv_ds_buffer_info
*ds
,
3199 struct radv_image_view
*iview
)
3201 unsigned level
= iview
->base_mip
;
3202 unsigned format
, stencil_format
;
3203 uint64_t va
, s_offs
, z_offs
;
3204 bool stencil_only
= false;
3205 memset(ds
, 0, sizeof(*ds
));
3206 switch (iview
->image
->vk_format
) {
3207 case VK_FORMAT_D24_UNORM_S8_UINT
:
3208 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3209 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3210 ds
->offset_scale
= 2.0f
;
3212 case VK_FORMAT_D16_UNORM
:
3213 case VK_FORMAT_D16_UNORM_S8_UINT
:
3214 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3215 ds
->offset_scale
= 4.0f
;
3217 case VK_FORMAT_D32_SFLOAT
:
3218 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3219 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3220 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3221 ds
->offset_scale
= 1.0f
;
3223 case VK_FORMAT_S8_UINT
:
3224 stencil_only
= true;
3230 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3231 stencil_format
= iview
->image
->surface
.has_stencil
?
3232 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3234 uint32_t max_slice
= radv_surface_layer_count(iview
);
3235 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3236 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3238 ds
->db_htile_data_base
= 0;
3239 ds
->db_htile_surface
= 0;
3241 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3242 s_offs
= z_offs
= va
;
3244 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3245 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3246 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3248 ds
->db_z_info
= S_028038_FORMAT(format
) |
3249 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3250 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3251 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3252 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3253 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3255 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3256 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3257 ds
->db_depth_view
|= S_028008_MIPID(level
);
3259 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3260 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3262 if (radv_htile_enabled(iview
->image
, level
)) {
3263 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3265 if (iview
->image
->tc_compatible_htile
) {
3266 unsigned max_zplanes
= 4;
3268 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3269 iview
->image
->info
.samples
> 1)
3272 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
+ 1) |
3273 S_028038_ITERATE_FLUSH(1);
3274 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3277 if (!iview
->image
->surface
.has_stencil
)
3278 /* Use all of the htile_buffer for depth if there's no stencil. */
3279 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3280 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3281 iview
->image
->htile_offset
;
3282 ds
->db_htile_data_base
= va
>> 8;
3283 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3284 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3285 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3288 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3291 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3293 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3294 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3296 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!iview
->image
->tc_compatible_htile
);
3297 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3298 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3300 if (iview
->image
->info
.samples
> 1)
3301 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3303 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3304 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3305 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3306 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3307 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3308 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3309 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3310 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3313 tile_mode
= stencil_tile_mode
;
3315 ds
->db_depth_info
|=
3316 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3317 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3318 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3319 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3320 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3321 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3322 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3323 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3325 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3326 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3327 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3328 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3330 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3333 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3334 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3335 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3337 if (radv_htile_enabled(iview
->image
, level
)) {
3338 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3340 if (!iview
->image
->surface
.has_stencil
&&
3341 !iview
->image
->tc_compatible_htile
)
3342 /* Use all of the htile_buffer for depth if there's no stencil. */
3343 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3345 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3346 iview
->image
->htile_offset
;
3347 ds
->db_htile_data_base
= va
>> 8;
3348 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3350 if (iview
->image
->tc_compatible_htile
) {
3351 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3353 if (iview
->image
->info
.samples
<= 1)
3354 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
3355 else if (iview
->image
->info
.samples
<= 4)
3356 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
3358 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
3363 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3364 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3367 VkResult
radv_CreateFramebuffer(
3369 const VkFramebufferCreateInfo
* pCreateInfo
,
3370 const VkAllocationCallbacks
* pAllocator
,
3371 VkFramebuffer
* pFramebuffer
)
3373 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3374 struct radv_framebuffer
*framebuffer
;
3376 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3378 size_t size
= sizeof(*framebuffer
) +
3379 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3380 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3381 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3382 if (framebuffer
== NULL
)
3383 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3385 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3386 framebuffer
->width
= pCreateInfo
->width
;
3387 framebuffer
->height
= pCreateInfo
->height
;
3388 framebuffer
->layers
= pCreateInfo
->layers
;
3389 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3390 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3391 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3392 framebuffer
->attachments
[i
].attachment
= iview
;
3393 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3394 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3395 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3396 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3398 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3399 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3400 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
3403 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3407 void radv_DestroyFramebuffer(
3410 const VkAllocationCallbacks
* pAllocator
)
3412 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3413 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3417 vk_free2(&device
->alloc
, pAllocator
, fb
);
3420 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3422 switch (address_mode
) {
3423 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3424 return V_008F30_SQ_TEX_WRAP
;
3425 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3426 return V_008F30_SQ_TEX_MIRROR
;
3427 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3428 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3429 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3430 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3431 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3432 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3434 unreachable("illegal tex wrap mode");
3440 radv_tex_compare(VkCompareOp op
)
3443 case VK_COMPARE_OP_NEVER
:
3444 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3445 case VK_COMPARE_OP_LESS
:
3446 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3447 case VK_COMPARE_OP_EQUAL
:
3448 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3449 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3450 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3451 case VK_COMPARE_OP_GREATER
:
3452 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3453 case VK_COMPARE_OP_NOT_EQUAL
:
3454 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3455 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3456 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3457 case VK_COMPARE_OP_ALWAYS
:
3458 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3460 unreachable("illegal compare mode");
3466 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3469 case VK_FILTER_NEAREST
:
3470 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3471 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3472 case VK_FILTER_LINEAR
:
3473 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3474 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3475 case VK_FILTER_CUBIC_IMG
:
3477 fprintf(stderr
, "illegal texture filter");
3483 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3486 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3487 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3488 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3489 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3491 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3496 radv_tex_bordercolor(VkBorderColor bcolor
)
3499 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3500 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3501 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3502 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3503 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3504 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3505 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3506 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3507 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3515 radv_tex_aniso_filter(unsigned filter
)
3529 radv_init_sampler(struct radv_device
*device
,
3530 struct radv_sampler
*sampler
,
3531 const VkSamplerCreateInfo
*pCreateInfo
)
3533 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3534 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3535 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3536 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3538 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3539 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3540 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3541 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3542 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3543 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3544 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3545 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3546 S_008F30_DISABLE_CUBE_WRAP(0) |
3547 S_008F30_COMPAT_MODE(is_vi
));
3548 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3549 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3550 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3551 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3552 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3553 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3554 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3555 S_008F38_MIP_POINT_PRECLAMP(0) |
3556 S_008F38_DISABLE_LSB_CEIL(1) |
3557 S_008F38_FILTER_PREC_FIX(1) |
3558 S_008F38_ANISO_OVERRIDE(is_vi
));
3559 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3560 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3563 VkResult
radv_CreateSampler(
3565 const VkSamplerCreateInfo
* pCreateInfo
,
3566 const VkAllocationCallbacks
* pAllocator
,
3567 VkSampler
* pSampler
)
3569 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3570 struct radv_sampler
*sampler
;
3572 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3574 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3575 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3577 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3579 radv_init_sampler(device
, sampler
, pCreateInfo
);
3580 *pSampler
= radv_sampler_to_handle(sampler
);
3585 void radv_DestroySampler(
3588 const VkAllocationCallbacks
* pAllocator
)
3590 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3591 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3595 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3598 /* vk_icd.h does not declare this function, so we declare it here to
3599 * suppress Wmissing-prototypes.
3601 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3602 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3604 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3605 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3607 /* For the full details on loader interface versioning, see
3608 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3609 * What follows is a condensed summary, to help you navigate the large and
3610 * confusing official doc.
3612 * - Loader interface v0 is incompatible with later versions. We don't
3615 * - In loader interface v1:
3616 * - The first ICD entrypoint called by the loader is
3617 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3619 * - The ICD must statically expose no other Vulkan symbol unless it is
3620 * linked with -Bsymbolic.
3621 * - Each dispatchable Vulkan handle created by the ICD must be
3622 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3623 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3624 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3625 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3626 * such loader-managed surfaces.
3628 * - Loader interface v2 differs from v1 in:
3629 * - The first ICD entrypoint called by the loader is
3630 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3631 * statically expose this entrypoint.
3633 * - Loader interface v3 differs from v2 in:
3634 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3635 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3636 * because the loader no longer does so.
3638 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3642 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3643 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3646 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3647 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3649 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3651 /* We support only one handle type. */
3652 assert(pGetFdInfo
->handleType
==
3653 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3655 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3657 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3661 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3662 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3664 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3666 /* The valid usage section for this function says:
3668 * "handleType must not be one of the handle types defined as opaque."
3670 * Since we only handle opaque handles for now, there are no FD properties.
3672 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3675 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3676 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3678 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3679 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3680 uint32_t syncobj_handle
= 0;
3681 assert(pImportSemaphoreFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3683 int ret
= device
->ws
->import_syncobj(device
->ws
, pImportSemaphoreFdInfo
->fd
, &syncobj_handle
);
3685 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3687 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3688 sem
->temp_syncobj
= syncobj_handle
;
3690 sem
->syncobj
= syncobj_handle
;
3692 close(pImportSemaphoreFdInfo
->fd
);
3696 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3697 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3700 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3701 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3703 uint32_t syncobj_handle
;
3705 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3706 if (sem
->temp_syncobj
)
3707 syncobj_handle
= sem
->temp_syncobj
;
3709 syncobj_handle
= sem
->syncobj
;
3710 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3712 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3716 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3717 VkPhysicalDevice physicalDevice
,
3718 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3719 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3721 if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3722 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3723 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3724 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3725 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3727 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3728 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3729 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;